...
1
2
3
4
5 package xcoff
6
7 import (
8 "reflect"
9 "testing"
10 )
11
12 type archiveTest struct {
13 file string
14 hdr ArchiveHeader
15 members []*MemberHeader
16 membersFileHeader []FileHeader
17 }
18
19 var archTest = []archiveTest{
20 {
21 "testdata/bigar-ppc64",
22 ArchiveHeader{AIAMAGBIG},
23 []*MemberHeader{
24 {"printbye.o", 836},
25 {"printhello.o", 860},
26 },
27 []FileHeader{
28 {U64_TOCMAGIC},
29 {U64_TOCMAGIC},
30 },
31 },
32 {
33 "testdata/bigar-empty",
34 ArchiveHeader{AIAMAGBIG},
35 []*MemberHeader{},
36 []FileHeader{},
37 },
38 }
39
40 func TestOpenArchive(t *testing.T) {
41 for i := range archTest {
42 tt := &archTest[i]
43 arch, err := OpenArchive(tt.file)
44 if err != nil {
45 t.Error(err)
46 continue
47 }
48 if !reflect.DeepEqual(arch.ArchiveHeader, tt.hdr) {
49 t.Errorf("open archive %s:\n\thave %#v\n\twant %#v\n", tt.file, arch.ArchiveHeader, tt.hdr)
50 continue
51 }
52
53 for i, mem := range arch.Members {
54 if i >= len(tt.members) {
55 break
56 }
57 have := &mem.MemberHeader
58 want := tt.members[i]
59 if !reflect.DeepEqual(have, want) {
60 t.Errorf("open %s, member %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want)
61 }
62
63 f, err := arch.GetFile(mem.Name)
64 if err != nil {
65 t.Error(err)
66 continue
67 }
68 if !reflect.DeepEqual(f.FileHeader, tt.membersFileHeader[i]) {
69 t.Errorf("open %s, member file header %d:\n\thave %#v\n\twant %#v\n", tt.file, i, f.FileHeader, tt.membersFileHeader[i])
70 }
71 }
72 tn := len(tt.members)
73 an := len(arch.Members)
74 if tn != an {
75 t.Errorf("open %s: len(Members) = %d, want %d", tt.file, an, tn)
76 }
77
78 }
79 }
80
View as plain text