forked from Galaco/bsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsp_test.go
82 lines (69 loc) · 1.67 KB
/
bsp_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
package bsp
import (
"bytes"
"github.com/galaco/bsp/lumps"
"log"
"testing"
)
// Test that resultant lump data matches expected.
func TestLumpExports(t *testing.T) {
t.Skip()
file, err := ReadFromFile("maps/v20/de_dust2.bsp")
if err != nil {
t.Error(err)
}
// Verify lump lengths
lumpIndex := 0
for lumpIndex < 64 {
lump := file.Lump(LumpId(lumpIndex))
rawLump := file.RawLump(LumpId(lumpIndex))
lumpBytes, err := lump.Marshall()
if err != nil {
t.Error(err)
}
if len(lumpBytes) != int(file.Header().Lumps[lumpIndex].Length) {
t.Errorf("Lump: %d length mismatch. Got: %dbytes, expected: %dbytes", lumpIndex, len(lumpBytes), file.header.Lumps[lumpIndex].Length)
} else {
log.Printf("Index: %d, Expected: %d, Actual: %d\n", lumpIndex, len(rawLump.RawContents()), len(lumpBytes))
if !bytes.Equal(lumpBytes, rawLump.RawContents()) {
t.Errorf("Lump: %d data mismatch", lumpIndex)
}
}
lumpIndex += 1
}
}
func TestBsp_Header(t *testing.T) {
sut := new(Bsp)
header := new(Header)
header.Id = 564
sut.header = *header
if sut.Header().Id != header.Id {
t.Error("unexpected header struct returned")
}
}
func TestBsp_Lump(t *testing.T) {
sut := new(Bsp)
l := new(lumps.Generic)
sut.lumps[0].data = l
if sut.Lump(0) != l {
t.Error("unexpected lump returned")
}
}
func TestBsp_RawLump(t *testing.T) {
sut := new(Bsp)
l := new(lumps.Generic)
sut.lumps[0].data = l
if sut.RawLump(0).data != l {
t.Error("unexpected lump returned")
}
}
func TestBsp_SetLump(t *testing.T) {
sut := new(Bsp)
ld := new(lumps.Generic)
l := new(Lump)
l.data = ld
sut.SetLump(0, *l)
if sut.RawLump(0).data != ld {
t.Error("unexpected lump returned")
}
}