summaryrefslogtreecommitdiffstats
path: root/src/internal/xcoff/ar_test.go
blob: 83333d6d0e523d4f66abc0c796d52280562793d8 (plain)
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 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package xcoff

import (
	"reflect"
	"testing"
)

type archiveTest struct {
	file              string
	hdr               ArchiveHeader
	members           []*MemberHeader
	membersFileHeader []FileHeader
}

var archTest = []archiveTest{
	{
		"testdata/bigar-ppc64",
		ArchiveHeader{AIAMAGBIG},
		[]*MemberHeader{
			{"printbye.o", 836},
			{"printhello.o", 860},
		},
		[]FileHeader{
			{U64_TOCMAGIC},
			{U64_TOCMAGIC},
		},
	},
	{
		"testdata/bigar-empty",
		ArchiveHeader{AIAMAGBIG},
		[]*MemberHeader{},
		[]FileHeader{},
	},
}

func TestOpenArchive(t *testing.T) {
	for i := range archTest {
		tt := &archTest[i]
		arch, err := OpenArchive(tt.file)
		if err != nil {
			t.Error(err)
			continue
		}
		if !reflect.DeepEqual(arch.ArchiveHeader, tt.hdr) {
			t.Errorf("open archive %s:\n\thave %#v\n\twant %#v\n", tt.file, arch.ArchiveHeader, tt.hdr)
			continue
		}

		for i, mem := range arch.Members {
			if i >= len(tt.members) {
				break
			}
			have := &mem.MemberHeader
			want := tt.members[i]
			if !reflect.DeepEqual(have, want) {
				t.Errorf("open %s, member %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want)
			}

			f, err := arch.GetFile(mem.Name)
			if err != nil {
				t.Error(err)
				continue
			}
			if !reflect.DeepEqual(f.FileHeader, tt.membersFileHeader[i]) {
				t.Errorf("open %s, member file header %d:\n\thave %#v\n\twant %#v\n", tt.file, i, f.FileHeader, tt.membersFileHeader[i])
			}
		}
		tn := len(tt.members)
		an := len(arch.Members)
		if tn != an {
			t.Errorf("open %s: len(Members) = %d, want %d", tt.file, an, tn)
		}

	}
}