1 package exifundefined
2
3 import (
4 "bytes"
5 "reflect"
6 "testing"
7
8 "github.com/dsoprea/go-logging"
9 "github.com/dsoprea/go-utility/v2/filesystem"
10
11 "github.com/dsoprea/go-exif/v3/common"
12 )
13
14 func TestTagA20CSpatialFrequencyResponse_String(t *testing.T) {
15 ut := TagA20CSpatialFrequencyResponse{
16 Columns: 2,
17 Rows: 9,
18 ColumnNames: []string{"column1", "column2"},
19 Values: []exifcommon.Rational{
20 {1, 2},
21 {3, 4},
22 },
23 }
24
25 s := ut.String()
26 if s != "CodecA20CSpatialFrequencyResponse<COLUMNS=(2) ROWS=(9)>" {
27 t.Fatalf("String not correct: [%s]", s)
28 }
29 }
30
31 func TestCodecA20CSpatialFrequencyResponse_Encode(t *testing.T) {
32 ut := TagA20CSpatialFrequencyResponse{
33 Columns: 2,
34 Rows: 9,
35 ColumnNames: []string{"column1", "column2"},
36 Values: []exifcommon.Rational{
37 {1, 2},
38 {3, 4},
39 },
40 }
41
42 codec := CodecA20CSpatialFrequencyResponse{}
43
44 encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder)
45 log.PanicIf(err)
46
47 expectedEncoded := []byte{
48 0x00, 0x02,
49 0x00, 0x09,
50 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x31, 0x00,
51 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x32, 0x00,
52 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02,
53 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04,
54 }
55
56 if bytes.Equal(encoded, expectedEncoded) != true {
57 exifcommon.DumpBytesClause(encoded)
58
59 t.Fatalf("Encoding not correct.")
60 } else if unitCount != uint32(len(encoded)) {
61 t.Fatalf("Unit-count not correct: (%d)", unitCount)
62 }
63 }
64
65 func TestCodecA20CSpatialFrequencyResponse_Decode(t *testing.T) {
66 expectedUt := TagA20CSpatialFrequencyResponse{
67 Columns: 2,
68 Rows: 9,
69 ColumnNames: []string{"column1", "column2"},
70 Values: []exifcommon.Rational{
71 {1, 2},
72 {3, 4},
73 },
74 }
75
76 encoded := []byte{
77 0x00, 0x02,
78 0x00, 0x09,
79 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x31, 0x00,
80 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x32, 0x00,
81 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02,
82 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04,
83 }
84
85 addressableBytes := encoded
86 sb := rifs.NewSeekableBufferWithBytes(addressableBytes)
87
88 valueContext := exifcommon.NewValueContext(
89 "",
90 0,
91 uint32(len(encoded)),
92 0,
93 nil,
94 sb,
95 exifcommon.TypeUndefined,
96 exifcommon.TestDefaultByteOrder)
97
98 codec := CodecA20CSpatialFrequencyResponse{}
99
100 decoded, err := codec.Decode(valueContext)
101 log.PanicIf(err)
102
103 if reflect.DeepEqual(decoded, expectedUt) != true {
104 t.Fatalf("Decoded struct not correct.")
105 }
106 }
107
View as plain text