-
Notifications
You must be signed in to change notification settings - Fork 0
/
filetype_test.go
66 lines (54 loc) · 1.47 KB
/
filetype_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
// Copyright (c) 2013, Jan Voung
// All rights reserved.
// Test for file-type detection utilities for ELF linker.
package main
import (
"os"
"path"
"testing"
)
func CheckFiles(t *testing.T, fnames []string, expected FileType) {
fhandles := make(map[string] *os.File, len(fnames))
for _, fname := range fnames {
f, err := os.Open(fname)
if err != nil {
t.Fatal("Failed to open file:", fname, "error:", err)
}
defer f.Close()
fhandles[fname] = f
}
file_map := ValidateFiles(fhandles)
for fname, typ := range file_map {
ExpectEqM(t, expected, typ, fname + "should be")
}
}
func CheckARFiles(t *testing.T, base_dir string) {
fnames := []string{
path.Join(base_dir, "libcrt_platform.a"),
path.Join(base_dir, "libgcc.a"),
path.Join(base_dir, "libpnacl_irt_shim.a") }
CheckFiles(t, fnames, AR_FILE)
}
func CheckELFFiles(t *testing.T, base_dir string) {
fnames := []string{
path.Join(base_dir, "crtbegin.o"),
path.Join(base_dir, "crtend.o")}
CheckFiles(t, fnames, ELF_FILE)
}
func CheckBaseDirs(t *testing.T, check_func func(*testing.T, string)) {
base_dirs := []string{
TestX8632BaseDir(), TestX8664BaseDir(), TestARMBaseDir()}
for _, b := range base_dirs {
check_func(t, b)
}
}
func TestARFile(t *testing.T) {
CheckBaseDirs(t, CheckARFiles)
}
func TestELFFile(t *testing.T) {
CheckBaseDirs(t, CheckELFFiles)
}
func TestThinARFile(t *testing.T) {
fnames := []string{path.Join(TestX8632BaseDir(), "libthin_all.a")}
CheckFiles(t, fnames, THIN_AR_FILE)
}