...
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 TestTagA000FlashpixVersion_String(t *testing.T) {
15 versionPhrase := "some version"
16
17 ut := TagA000FlashpixVersion{versionPhrase}
18
19 s := ut.String()
20 if s != versionPhrase {
21 t.Fatalf("String not correct: [%s]", s)
22 }
23 }
24
25 func TestCodecA000FlashpixVersion_Encode(t *testing.T) {
26 versionPhrase := "some version"
27
28 ut := TagA000FlashpixVersion{versionPhrase}
29
30 codec := CodecA000FlashpixVersion{}
31
32 encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder)
33 log.PanicIf(err)
34
35 if bytes.Equal(encoded, []byte(versionPhrase)) != true {
36 exifcommon.DumpBytesClause(encoded)
37
38 t.Fatalf("Encoding not correct.")
39 } else if unitCount != uint32(len(encoded)) {
40 t.Fatalf("Unit-count not correct: (%d)", unitCount)
41 }
42 }
43
44 func TestCodecA000FlashpixVersion_Decode(t *testing.T) {
45 versionPhrase := "some version"
46
47 expectedUt := TagA000FlashpixVersion{versionPhrase}
48
49 encoded := []byte(versionPhrase)
50
51 addressableBytes := encoded
52 sb := rifs.NewSeekableBufferWithBytes(addressableBytes)
53
54 valueContext := exifcommon.NewValueContext(
55 "",
56 0,
57 uint32(len(encoded)),
58 0,
59 nil,
60 sb,
61 exifcommon.TypeUndefined,
62 exifcommon.TestDefaultByteOrder)
63
64 codec := CodecA000FlashpixVersion{}
65
66 decoded, err := codec.Decode(valueContext)
67 log.PanicIf(err)
68
69 if reflect.DeepEqual(decoded, expectedUt) != true {
70 t.Fatalf("Decoded struct not correct.")
71 }
72 }
73
View as plain text