-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathase_test.go
287 lines (237 loc) · 6.42 KB
/
ase_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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package ase
import (
"bytes"
"testing"
)
var testColors = []Color{
Color{
Name: "RGB",
Model: "RGB",
Values: []float32{1, 1, 1},
Type: "Normal",
},
Color{
Name: "Grayscale",
Model: "CMYK",
Values: []float32{0, 0, 0, 0.47},
Type: "Spot",
},
Color{
Name: "cmyk",
Model: "CMYK",
Values: []float32{0, 1, 0, 0},
Type: "Spot",
},
Color{
Name: "LAB",
Model: "RGB",
Values: []float32{0, 0.6063648, 0.524658},
Type: "Global",
},
Color{
Name: "PANTONE P 1-8 C",
Model: "LAB",
Values: []float32{0.9137255, -5, 94},
Type: "Spot",
},
}
var testGroup = Group{
Name: "A Color Group",
Colors: []Color{
Color{
Name: "Red",
Model: "RGB",
Values: []float32{1, 0, 0},
Type: "Global",
},
Color{
Name: "Green",
Model: "RGB",
Values: []float32{0, 1, 0},
Type: "Global",
},
Color{
Name: "Blue",
Model: "RGB",
Values: []float32{0, 0, 1},
Type: "Global",
},
},
}
func TestSignature(t *testing.T) {
testFile := "samples/test.ase"
ase, err := DecodeFile(testFile)
if err != nil {
t.Error(err)
}
expectedSignature := "ASEF"
if ase.Signature() != expectedSignature {
t.Error("expected signature of", expectedSignature, ", got:", ase.Signature())
}
}
func TestVersion(t *testing.T) {
testFile := "samples/test.ase"
ase, err := DecodeFile(testFile)
if err != nil {
t.Error(err)
}
expectedVersion := "1.0"
if ase.Version() != expectedVersion {
t.Error("expected version of", expectedVersion, ", got:", ase.Version())
}
}
func TestDecode(t *testing.T) {
testFile := "samples/test.ase"
ase, err := DecodeFile(testFile)
if err != nil {
t.Error(err)
}
// Check ASE's metadata (Signature and Version tested in separate functions)
expectedNumBlocks := int32(10)
if ase.numBlocks != expectedNumBlocks {
t.Error("expected ", expectedNumBlocks, " numBlocks, got ", ase.numBlocks)
}
// Check the ASE's Colors
expectedColors := testColors
expectedNumColors := len(expectedColors)
actualNumColors := len(ase.Colors)
if actualNumColors != expectedNumColors {
t.Error("expected number of colors to be", expectedNumColors,
"got ", actualNumColors)
}
for i, color := range ase.Colors {
expectedColor := expectedColors[i]
if color.Name != expectedColor.Name {
t.Error("expected initial color with name ", expectedColor.Name,
"got ", color.Name)
}
if color.Model != expectedColor.Model {
t.Error("expected initial color of Model ", expectedColor.Model,
"got ", color.Model)
}
for j, _ := range expectedColor.Values {
if color.Values[j] != expectedColor.Values[j] {
t.Error("expected color value ", expectedColor.Values[j],
"got ", color.Values[j])
}
}
if color.Type != expectedColor.Type {
t.Error("expected color type ", expectedColor.Type,
"got ", color.Type)
}
}
// Check the ASE's Groups' data
expectedGroupsLen := 1
actualGroupLen := len(ase.Groups)
if actualGroupLen != expectedGroupsLen {
t.Error("expected group length of ", expectedGroupsLen,
"got ", actualGroupLen)
}
group := ase.Groups[0]
if group.Name != testGroup.Name {
t.Error("expected group name to be ", testGroup.Name,
", got: ", group.Name)
}
// Check the ASE's Groups' Color Data
for i, color := range group.Colors {
expectedColor := testGroup.Colors[i]
if color.Name != expectedColor.Name {
t.Error("expected initial color with name ", expectedColor.Name,
"got ", color.Name)
}
if color.Model != expectedColor.Model {
t.Error("expected initial color of Model ", expectedColor.Model,
"got ", color.Model)
}
for j, _ := range expectedColor.Values {
if color.Values[j] != expectedColor.Values[j] {
t.Error("expected color value ", expectedColor.Values[j],
"got ", color.Values[j])
}
}
if color.Type != expectedColor.Type {
t.Error("expected color type ", expectedColor.Type,
"got ", color.Type)
}
}
}
func TestEncode(t *testing.T) {
// Initialize a sample ASE
sampleAse := ASE{}
sampleAse.Colors = testColors
sampleAse.Groups = append(sampleAse.Groups, testGroup)
// Encode the sampleAse into the buffer and immediately decode it.
b := new(bytes.Buffer)
Encode(sampleAse, b)
ase, _ := Decode(b)
// Check the ASE's decoded values.
if string(ase.signature[0:]) != "ASEF" {
t.Error("ase: file not an ASE file")
}
if ase.version[0] != 1 && ase.version[1] != 0 {
t.Error("ase: version is not 1.0")
}
expectedNumBlocks := int32(10)
actualNumBlocks := ase.numBlocks
if actualNumBlocks != expectedNumBlocks {
t.Error("ase: expected", expectedNumBlocks,
" blocks to be present, got: ", actualNumBlocks)
}
expectedAmountOfColors := 5
if len(ase.Colors) != expectedAmountOfColors {
t.Error("ase: expected", expectedAmountOfColors, " colors to be present")
}
for i, color := range ase.Colors {
expectedColor := testColors[i]
if color.Name != expectedColor.Name {
t.Error("expected initial color with name ", expectedColor.Name,
"got ", color.Name)
}
if color.Model != expectedColor.Model {
t.Error("expected initial color of Model ", expectedColor.Model,
"got ", color.Model)
}
for j, _ := range expectedColor.Values {
if color.Values[j] != expectedColor.Values[j] {
t.Error("expected color value ", expectedColor.Values[j],
"got ", color.Values[j])
}
}
if color.Type != expectedColor.Type {
t.Error("expected color type ", expectedColor.Type,
"got ", color.Type)
}
}
expectedAmountOfGroups := 1
actualAmountOfGroups := len(ase.Groups)
if actualAmountOfGroups != expectedAmountOfGroups {
t.Error("expected ", expectedAmountOfGroups,
"amount of groups, got: ", actualAmountOfGroups)
}
group := ase.Groups[0]
if group.Name != testGroup.Name {
t.Error("expected group name to be ", testGroup.Name,
", got: ", group.Name)
}
for i, color := range group.Colors {
expectedColor := testGroup.Colors[i]
if color.Name != expectedColor.Name {
t.Error("expected initial color with name ", expectedColor.Name,
"got ", color.Name)
}
if color.Model != expectedColor.Model {
t.Error("expected initial color of Model ", expectedColor.Model,
"got ", color.Model)
}
for j, _ := range expectedColor.Values {
if color.Values[j] != expectedColor.Values[j] {
t.Error("expected color value ", expectedColor.Values[j],
"got ", color.Values[j])
}
}
if color.Type != expectedColor.Type {
t.Error("expected color type ", expectedColor.Type,
"got ", color.Type)
}
}
}