forked from chai2010/tiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header_test.go
79 lines (74 loc) · 1.79 KB
/
header_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
// Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tiff
import (
"bytes"
"io/ioutil"
"reflect"
"testing"
)
func TestHeader_decodeAndEncode_files(t *testing.T) {
files := []string{
"BigTIFF.tif",
"BigTIFFLong.tif",
"BigTIFFLong8.tif",
"BigTIFFLong8Tiles.tif",
"BigTIFFMotorola.tif",
"BigTIFFMotorolaLongStrips.tif",
"BigTIFFSubIFD4.tif",
"BigTIFFSubIFD8.tif",
}
for i := 0; i < len(files); i++ {
data, err := ioutil.ReadFile("./testdata/BigTIFFSamples/" + files[i])
if err != nil {
t.Fatalf("%d: %v", i, err)
}
h0, err := ReadHeader(bytes.NewReader(data))
if err != nil {
t.Fatalf("%d: %v", i, err)
}
h1, err := ReadHeader(bytes.NewReader(h0.Bytes()))
if err != nil {
t.Fatalf("%d: %v", i, err)
}
if !reflect.DeepEqual(h0, h1) {
t.Fatalf("%d: not equal: %v != %v", i, h0, h1)
}
}
}
func TestHeader_decodeAndEncode(t *testing.T) {
headers := []*Header{
NewHeader(true, 9527),
NewHeader(false, 9527),
NewHeader(true, 9527),
NewHeader(false, 8),
NewHeader(true, 16),
}
for i := 0; i < len(headers); i++ {
h, err := ReadHeader(bytes.NewReader(headers[i].Bytes()))
if err != nil {
t.Fatalf("%d: %v", i, err)
}
if !reflect.DeepEqual(headers[i], h) {
t.Fatalf("%d: not equal: %v != %v", i, headers[i], h)
}
}
}
func TestHeader_decodeAndEncode_bad(t *testing.T) {
headers := []*Header{
NewHeader(true, 15),
NewHeader(true, 8),
NewHeader(true, 7),
NewHeader(true, 0),
NewHeader(false, 7),
NewHeader(false, 6),
NewHeader(false, 0),
}
for i := 0; i < len(headers); i++ {
_, err := ReadHeader(bytes.NewReader(headers[i].Bytes()))
if err == nil {
t.Fatalf("%d: expect err, got %v", i, err)
}
}
}