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 TestTag8828Oecf_String(t *testing.T) {
15 ut := Tag8828Oecf{
16 Columns: 11,
17 Rows: 22,
18 }
19
20 s := ut.String()
21
22 if s != "Tag8828Oecf<COLUMNS=(11) ROWS=(22)>" {
23 t.Fatalf("String not correct: [%s]", s)
24 }
25 }
26
27 func TestCodec8828Oecf_Encode(t *testing.T) {
28 ut := Tag8828Oecf{
29 Columns: 2,
30 Rows: 22,
31 ColumnNames: []string{"aa", "bb"},
32 Values: []exifcommon.SignedRational{{11, 22}},
33 }
34
35 codec := Codec8828Oecf{}
36
37 encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder)
38 log.PanicIf(err)
39
40 expectedBytes := []byte{
41 0x00, 0x02,
42 0x00, 0x16,
43 0x61, 0x61, 0x00, 0x62, 0x62, 0x00,
44 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x16}
45
46 if bytes.Equal(encoded, expectedBytes) != true {
47 exifcommon.DumpBytesClause(encoded)
48
49 t.Fatalf("Encoded bytes not correct.")
50 } else if unitCount != 18 {
51 t.Fatalf("Unit-count not correct: (%d)", unitCount)
52 }
53 }
54
55 func TestCodec8828Oecf_Decode(t *testing.T) {
56 encoded := []byte{
57 0x00, 0x02,
58 0x00, 0x16,
59 0x61, 0x61, 0x00, 0x62, 0x62, 0x00,
60 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x16}
61
62 addressableData := encoded
63 sb := rifs.NewSeekableBufferWithBytes(addressableData)
64
65 valueContext := exifcommon.NewValueContext(
66 "",
67 0,
68 uint32(len(encoded)),
69 0,
70 nil,
71 sb,
72 exifcommon.TypeUndefined,
73 exifcommon.TestDefaultByteOrder)
74
75 codec := Codec8828Oecf{}
76
77 value, err := codec.Decode(valueContext)
78 log.PanicIf(err)
79
80 expectedValue := Tag8828Oecf{
81 Columns: 2,
82 Rows: 22,
83 ColumnNames: []string{"aa", "bb"},
84 Values: []exifcommon.SignedRational{{11, 22}},
85 }
86
87 if reflect.DeepEqual(value, expectedValue) != true {
88 t.Fatalf("Decoded value not correct: %s", value)
89 }
90 }
91
View as plain text