-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathifd_tag_entry_test.go
210 lines (169 loc) · 4.86 KB
/
ifd_tag_entry_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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package exif
import (
"bytes"
"testing"
"github.com/dsoprea/go-logging"
)
func TestIfdTagEntry_ValueString_Allocated(t *testing.T) {
ite := IfdTagEntry{
TagId: 0x1,
TagIndex: 0,
TagType: TypeByte,
UnitCount: 6,
ValueOffset: 0x0,
RawValueOffset: []byte{0x0, 0x0, 0x0, 0x0},
IfdPath: IfdPathStandard,
}
data := []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}
value, err := ite.ValueString(data, TestDefaultByteOrder)
log.PanicIf(err)
expected := "11 22 33 44 55 66"
if value != expected {
t.Fatalf("Value not expected: [%s] != [%s]", value, expected)
}
}
func TestIfdTagEntry_ValueString_Embedded(t *testing.T) {
data := []byte{0x11, 0x22, 0x33, 0x44}
ite := IfdTagEntry{
TagId: 0x1,
TagIndex: 0,
TagType: TypeByte,
UnitCount: 4,
ValueOffset: 0,
RawValueOffset: data,
IfdPath: IfdPathStandard,
}
value, err := ite.ValueString(nil, TestDefaultByteOrder)
log.PanicIf(err)
expected := "11 22 33 44"
if value != expected {
t.Fatalf("Value not expected: [%s] != [%s]", value, expected)
}
}
func TestIfdTagEntry_ValueString_Unknown(t *testing.T) {
data := []uint8{'0', '2', '3', '0'}
ite := IfdTagEntry{
TagId: 0x9000,
TagIndex: 0,
TagType: TypeUndefined,
UnitCount: 4,
ValueOffset: 0x0,
RawValueOffset: data,
IfdPath: IfdPathStandardExif,
}
value, err := ite.ValueString(nil, TestDefaultByteOrder)
log.PanicIf(err)
expected := "0230"
if value != expected {
t.Fatalf("Value not expected: [%s] != [%s]", value, expected)
}
}
func TestIfdTagEntry_ValueBytes_Allocated(t *testing.T) {
ite := IfdTagEntry{
TagId: 0x1,
TagIndex: 0,
TagType: TypeByte,
UnitCount: 6,
ValueOffset: 0x0,
RawValueOffset: []byte{0x0, 0x0, 0x0, 0x0},
IfdPath: IfdPathStandard,
}
data := []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}
value, err := ite.ValueBytes(data, TestDefaultByteOrder)
log.PanicIf(err)
if bytes.Compare(value, data) != 0 {
t.Fatalf("Value not expected: [%s] != [%s]", value, data)
}
}
func TestIfdTagEntry_ValueBytes_Embedded(t *testing.T) {
data := []byte{0x11, 0x22, 0x33, 0x44}
ite := IfdTagEntry{
TagId: 0x1,
TagIndex: 0,
TagType: TypeByte,
UnitCount: 4,
ValueOffset: 0x0,
RawValueOffset: data,
IfdPath: IfdPathStandard,
}
value, err := ite.ValueBytes(nil, TestDefaultByteOrder)
log.PanicIf(err)
if bytes.Compare(value, data) != 0 {
t.Fatalf("Value not expected: [%s] != [%s]", value, data)
}
}
func TestIfdTagEntry_Value_Normal(t *testing.T) {
data := []byte{0x11, 0x22, 0x33, 0x44}
ite := IfdTagEntry{
TagId: 0x1,
TagIndex: 0,
TagType: TypeByte,
UnitCount: 4,
ValueOffset: 0x0,
RawValueOffset: data,
IfdPath: IfdPathStandard,
}
value, err := ite.Value(nil, TestDefaultByteOrder)
log.PanicIf(err)
if bytes.Compare(value.([]byte), data) != 0 {
t.Fatalf("Value not expected: [%s] != [%s]", value, data)
}
}
func TestIfdTagEntry_Value_Unknown(t *testing.T) {
data := []uint8{'0', '2', '3', '0'}
ite := IfdTagEntry{
TagId: 0x9000,
TagIndex: 0,
TagType: TypeUndefined,
UnitCount: 4,
ValueOffset: 0x0,
RawValueOffset: data,
IfdPath: IfdPathStandardExif,
}
value, err := ite.Value(nil, TestDefaultByteOrder)
log.PanicIf(err)
gs := value.(TagUnknownType_GeneralString)
vb, err := gs.ValueBytes()
log.PanicIf(err)
if bytes.Compare(vb, data) != 0 {
t.Fatalf("Value not expected: [%s] != [%s]", value, data)
}
}
func TestIfdTagEntry_String(t *testing.T) {
ite := IfdTagEntry{
TagId: 0x1,
TagIndex: 0,
TagType: TypeByte,
UnitCount: 6,
ValueOffset: 0x0,
RawValueOffset: []byte{0x0, 0x0, 0x0, 0x0},
IfdPath: IfdPathStandard,
}
expected := "IfdTagEntry<TAG-IFD-PATH=[IFD] TAG-ID=(0x0001) TAG-TYPE=[BYTE] UNIT-COUNT=(6)>"
if ite.String() != expected {
t.Fatalf("string representation not expected: [%s] != [%s]", ite.String(), expected)
}
}
func TestIfdTagEntryValueResolver_ValueBytes(t *testing.T) {
allocatedData := []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}
ite := IfdTagEntry{
TagId: 0x1,
TagIndex: 0,
TagType: TypeByte,
UnitCount: uint32(len(allocatedData)),
ValueOffset: 0x8,
RawValueOffset: []byte{0x0, 0x0, 0x0, 0x0},
IfdPath: IfdPathStandard,
}
headerBytes, err := BuildExifHeader(TestDefaultByteOrder, uint32(0))
log.PanicIf(err)
exifData := make([]byte, len(headerBytes)+len(allocatedData))
copy(exifData[0:], headerBytes)
copy(exifData[len(headerBytes):], allocatedData)
itevr := NewIfdTagEntryValueResolver(exifData, TestDefaultByteOrder)
value, err := itevr.ValueBytes(&ite)
log.PanicIf(err)
if bytes.Compare(value, allocatedData) != 0 {
t.Fatalf("bytes not expected: %v != %v", value, allocatedData)
}
}