forked from mefistotelis/psx_mnd_sym
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsym_test.go
58 lines (54 loc) · 1.33 KB
/
sym_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
package sym_test
import (
"crypto/sha1"
"fmt"
"os"
"testing"
"github.com/mefistotelis/psx_mnd_sym"
)
func TestParseFile(t *testing.T) {
// Hash sums based on the output of DUMPSYM.EXE from the Psy-Q SDK, as
// contained in https://github.com/diasurgical/scalpel, with the last line
// removed and with line endings converted to UNIX format.
golden := []struct {
path string
want string // SHA1 hash of output in Psy-Q format.
}{
// psx/symbols/jap_05291998.out
{
path: "testdata/DIABPSX_SLPS-01416.sym",
want: "19f823986500a369f60e78406fada915a1d18aca",
},
// psx/symbols/pal_12121997.out
{
path: "testdata/DIABPSX_easy_as_pie.sym",
want: "ef1e5d733560794b66cc5710d2e6211a24afab7c",
},
}
for _, g := range golden {
if !exists(g.path) {
t.Skip()
continue
}
f, err := sym.ParseFile(g.path)
if err != nil {
t.Errorf("unable to parse %q; %v", g.path, err)
continue
}
got := fmt.Sprintf("%040x", sha1.Sum([]byte(f.String())))
if g.want != got {
t.Errorf("%q: SHA1 hash mismatch; expected %v, got %v", g.path, g.want, got)
}
}
}
// exists reports whether the given file or directory exists.
func exists(path string) bool {
_, err := os.Stat(path)
if err == nil {
return true
}
if os.IsNotExist(err) {
return false
}
panic(fmt.Errorf("unable to stat path %q; %v", path, err))
}