-
Notifications
You must be signed in to change notification settings - Fork 70
/
value_context_test.go
112 lines (81 loc) · 2.01 KB
/
value_context_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package exif
import (
"bytes"
"testing"
"github.com/dsoprea/go-logging"
)
func TestValueContext_ReadAscii(t *testing.T) {
defer func() {
if state := recover(); state != nil {
err := log.Wrap(state.(error))
log.PrintErrorf(err, "Test failure.")
}
}()
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
err = LoadStandardIfds(im)
log.PanicIf(err)
ti := NewTagIndex()
_, index, err := Collect(im, ti, rawExif)
log.PanicIf(err)
ifd := index.RootIfd
var ite *IfdTagEntry
for _, thisIte := range ifd.Entries {
if thisIte.TagId == 0x0110 {
ite = thisIte
break
}
}
if ite == nil {
t.Fatalf("Tag not found.")
}
valueContext := ifd.GetValueContext(ite)
decodedString, err := valueContext.ReadAscii()
log.PanicIf(err)
decodedBytes := []byte(decodedString)
expected := []byte("Canon EOS 5D Mark III")
if bytes.Compare(decodedBytes, expected) != 0 {
t.Fatalf("Decoded bytes not correct.")
}
}
func TestValueContext_Undefined(t *testing.T) {
defer func() {
if state := recover(); state != nil {
err := log.Wrap(state.(error))
log.PrintErrorf(err, "Test failure.")
}
}()
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
err = LoadStandardIfds(im)
log.PanicIf(err)
ti := NewTagIndex()
_, index, err := Collect(im, ti, rawExif)
log.PanicIf(err)
ifdExif := index.Lookup[IfdPathStandardExif][0]
var ite *IfdTagEntry
for _, thisIte := range ifdExif.Entries {
if thisIte.TagId == 0x9000 {
ite = thisIte
break
}
}
if ite == nil {
t.Fatalf("Tag not found.")
}
valueContext := ifdExif.GetValueContext(ite)
value, err := valueContext.Undefined()
log.PanicIf(err)
gs, ok := value.(TagUnknownType_GeneralString)
if ok != true {
t.Fatalf("Undefined value not processed correctly.")
}
decodedBytes, err := gs.ValueBytes()
log.PanicIf(err)
expected := []byte("0230")
if bytes.Compare(decodedBytes, expected) != 0 {
t.Fatalf("Decoded bytes not correct.")
}
}