...
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 TestTag9286UserComment_String(t *testing.T) {
15 comment := "some comment"
16
17 ut := Tag9286UserComment{
18 EncodingType: TagUndefinedType_9286_UserComment_Encoding_ASCII,
19 EncodingBytes: []byte(comment),
20 }
21
22 s := ut.String()
23 if s != "[ASCII] some comment" {
24 t.Fatalf("String not correct: [%s]", s)
25 }
26 }
27
28 func TestCodec9286UserComment_Encode(t *testing.T) {
29 comment := "some comment"
30
31 ut := Tag9286UserComment{
32 EncodingType: TagUndefinedType_9286_UserComment_Encoding_ASCII,
33 EncodingBytes: []byte(comment),
34 }
35
36 codec := Codec9286UserComment{}
37
38 encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder)
39 log.PanicIf(err)
40
41 typeBytes := TagUndefinedType_9286_UserComment_Encodings[TagUndefinedType_9286_UserComment_Encoding_ASCII]
42 if bytes.Equal(encoded[:8], typeBytes) != true {
43 exifcommon.DumpBytesClause(encoded[:8])
44
45 t.Fatalf("Encoding type not correct.")
46 }
47
48 if bytes.Equal(encoded[8:], []byte(comment)) != true {
49 exifcommon.DumpBytesClause(encoded[8:])
50
51 t.Fatalf("Encoded comment not correct.")
52 }
53
54 if unitCount != uint32(len(encoded)) {
55 t.Fatalf("Unit-count not correct: (%d)", unitCount)
56 }
57
58 exifcommon.DumpBytesClause(encoded)
59
60 }
61
62 func TestCodec9286UserComment_Decode(t *testing.T) {
63 encoded := []byte{
64 0x41, 0x53, 0x43, 0x49, 0x49, 0x00, 0x00, 0x00,
65 0x73, 0x6f, 0x6d, 0x65, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74,
66 }
67
68 addressableBytes := encoded
69 sb := rifs.NewSeekableBufferWithBytes(addressableBytes)
70
71 valueContext := exifcommon.NewValueContext(
72 "",
73 0,
74 uint32(len(encoded)),
75 0,
76 nil,
77 sb,
78 exifcommon.TypeUndefined,
79 exifcommon.TestDefaultByteOrder)
80
81 codec := Codec9286UserComment{}
82
83 decoded, err := codec.Decode(valueContext)
84 log.PanicIf(err)
85
86 comment := "some comment"
87
88 expectedUt := Tag9286UserComment{
89 EncodingType: TagUndefinedType_9286_UserComment_Encoding_ASCII,
90 EncodingBytes: []byte(comment),
91 }
92
93 if reflect.DeepEqual(decoded, expectedUt) != true {
94 t.Fatalf("Decoded struct not correct.")
95 }
96 }
97
View as plain text