-
Notifications
You must be signed in to change notification settings - Fork 1
/
reader_test.go
124 lines (100 loc) · 2.09 KB
/
reader_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package rvz_test
import (
"crypto/sha1" //nolint:gosec
"encoding/xml"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"
"github.com/bodgit/rom/dat"
"github.com/bodgit/rvz"
"github.com/stretchr/testify/assert"
)
const (
gamecube = "Nintendo - GameCube - Datfile (1942) (2022-05-22 04-27-22).dat"
wii = "Nintendo - Wii - Datfile (3647) (2022-01-07 22-05-54).dat"
)
//nolint:cyclop,funlen
func TestReader(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip()
}
tables := []struct {
name, dat, file string
}{
{
name: "GameCube",
dat: gamecube,
file: "Gekkan Nintendo Tentou Demo 2003.9.1 (Japan)",
},
{
name: "Wii",
dat: wii,
file: "Metal Slug Anthology (USA)",
},
}
for _, table := range tables {
table := table
t.Run(table.name, func(t *testing.T) {
t.Parallel()
b, err := os.ReadFile(filepath.Join("testdata", table.dat))
if err != nil {
t.Fatal(err)
}
d := new(dat.File)
if err := xml.Unmarshal(b, d); err != nil {
t.Fatal(err)
}
f, err := os.Open(filepath.Join("testdata", table.file+rvz.Extension))
if err != nil {
t.Fatal(err)
}
defer f.Close()
r, err := rvz.NewReader(f)
if err != nil {
t.Fatal(err)
}
h := sha1.New() //nolint:gosec
if _, err := io.Copy(h, r); err != nil {
t.Fatal(err)
}
var g *dat.Game
for i := range d.Game {
if d.Game[i].Name == table.file {
g = &d.Game[i]
break
}
}
if g == nil || g.ROM[0].Name != table.file+".iso" {
t.Fatal(errors.New("no such disc"))
}
assert.Equal(t, fmt.Sprintf("%02x", h.Sum(nil)), strings.ToLower(g.ROM[0].SHA1))
})
}
}
func benchmarkReader(file string) error {
f, err := os.Open(filepath.Join("testdata", file))
if err != nil {
return err
}
defer f.Close()
r, err := rvz.NewReader(f)
if err != nil {
return err
}
if _, err := io.Copy(io.Discard, r); err != nil {
return err
}
return nil
}
func BenchmarkReader(b *testing.B) {
for n := 0; n < b.N; n++ {
if err := benchmarkReader("Metal Slug Anthology (USA).rvz"); err != nil {
b.Fatal(err)
}
}
}