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 TestTag927CMakerNote_String(t *testing.T) {
15 ut := Tag927CMakerNote{
16 MakerNoteType: []byte{0, 1, 2, 3, 4},
17 MakerNoteBytes: []byte{5, 6, 7, 8, 9},
18 }
19
20 s := ut.String()
21 if s != "MakerNote<TYPE-ID=[00 01 02 03 04] LEN=(5) SHA1=[bdb42cb7eb76e64efe49b22369b404c67b0af55a]>" {
22 t.Fatalf("String not correct: [%s]", s)
23 }
24 }
25
26 func TestCodec927CMakerNote_Encode(t *testing.T) {
27 codec := Codec927CMakerNote{}
28
29 prefix := []byte{0, 1, 2, 3, 4}
30 b := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
31
32 ut := Tag927CMakerNote{
33 MakerNoteType: prefix,
34 MakerNoteBytes: b,
35 }
36
37 encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder)
38 log.PanicIf(err)
39
40 if bytes.Equal(encoded, b) != true {
41 t.Fatalf("Encoding not correct: %v", encoded)
42 } else if unitCount != uint32(len(b)) {
43 t.Fatalf("Unit-count not correct: (%d)", len(b))
44 }
45 }
46
47 func TestCodec927CMakerNote_Decode(t *testing.T) {
48 b := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
49
50 ut := Tag927CMakerNote{
51 MakerNoteType: b,
52 MakerNoteBytes: b,
53 }
54
55 sb := rifs.NewSeekableBufferWithBytes(b)
56
57 valueContext := exifcommon.NewValueContext(
58 "",
59 0,
60 uint32(len(b)),
61 0,
62 nil,
63 sb,
64 exifcommon.TypeUndefined,
65 exifcommon.TestDefaultByteOrder)
66
67 codec := Codec927CMakerNote{}
68
69 value, err := codec.Decode(valueContext)
70 log.PanicIf(err)
71
72 if reflect.DeepEqual(value, ut) != true {
73 t.Fatalf("Decoded value not correct: %s != %s", value, ut)
74 }
75 }
76
View as plain text