-
Notifications
You must be signed in to change notification settings - Fork 0
/
nsf_test.go
57 lines (44 loc) · 2.1 KB
/
nsf_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
package main
import (
"bytes"
"encoding/binary"
"testing"
)
// tests here are aimed against the methods in nsf.go
var validHeader = []byte{
0x4E, 0x45, 0x53, 0x4D, 0x1A, 0x01, 0x08, 0x01, 0x60, 0x8D, 0x03, 0xA0, 0x00, 0xA0, 0x54, 0x68,
0x65, 0x20, 0x4C, 0x65, 0x67, 0x65, 0x6E, 0x64, 0x20, 0x6F, 0x66, 0x20, 0x5A, 0x65, 0x6C, 0x64,
0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4B, 0x6F,
0x6A, 0x69, 0x20, 0x4B, 0x6F, 0x6E, 0x64, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x39,
0x38, 0x37, 0x20, 0x4E, 0x69, 0x6E, 0x74, 0x65, 0x6E, 0x64, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x41,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
var getIsValidError = func(h *nsfHeader) string { _, e := h.isValid(); return e.Error() }
var getString = func(h *nsfHeader) string { return h.String() }
func TestIsValidWithInvalidFourCC(t *testing.T) {
testHeader(t, 1, 0x55, "invalid FourCC", getIsValidError)
}
func TestIsValidWithInvalidChips(t *testing.T) {
testHeader(t, 123, 1<<7 /* "future chip" bit that must never be set */, "extra sound chip section contains unsupported values", getIsValidError)
}
func TestStringWithMultiChipsFile(t *testing.T) {
testHeader(t, 123, 1<<1|1<<3, ": VRC7, MMC5", getString)
}
func TestStringWithValidPALFile(t *testing.T) {
testHeader(t, 122, 1<<0, ": PAL", getString)
}
func TestStringWithValidDualRegionFile(t *testing.T) {
testHeader(t, 122, 1<<1, ": dual PAL/NTSC", getString)
}
func testHeader(t *testing.T, newValIdx uint8, newVal byte, expectedContent string, fn func(*nsfHeader) string) {
var newHeader = append([]byte(nil), validHeader...)
newHeader[newValIdx] = newVal
h := new(nsfHeader)
e := binary.Read(bytes.NewReader(newHeader), binary.LittleEndian, h)
if e != nil {
t.Fatal(e)
}
s := fn(h) // calls the actual operation on the header: IsValid(), String(), etc.
mustContain(t, s, expectedContent)
}