-
Notifications
You must be signed in to change notification settings - Fork 4
/
lump_test.go
149 lines (137 loc) · 3.13 KB
/
lump_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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package bsp
import (
"github.com/galaco/bsp/lumps"
"reflect"
"testing"
)
func TestGetReferenceLumpByIndex(t *testing.T) {
for i := 0; i < 64; i++ {
lump, _ := getReferenceLumpByIndex(i, 20)
if reflect.TypeOf(lump) != reflect.TypeOf(getExpectedLump(i)) {
t.Errorf("Lump type does not match expected for identifer: %d\n", i)
}
}
_, err := getReferenceLumpByIndex(65, 20)
if err == nil {
t.Error("invalid lump provided, but no error returned")
}
}
func TestLump_Contents(t *testing.T) {
sut := new(Lump)
l := new(lumps.Generic)
l.SetLength(654)
sut.SetContents(l)
if sut.Contents() != l {
t.Error("unexpected lump data returned")
}
}
func TestLump_Length(t *testing.T) {
sut := Lump{}
sut.length = 32
if sut.Length() != 32 {
t.Error("incorrect length returned for lump")
}
}
func TestLump_RawContents(t *testing.T) {
sut := new(Lump)
data := []byte{0,1,3,4,5,6}
sut.SetRawContents(data)
if len(sut.RawContents()) != len(data) {
t.Error("unexpected lump data returned")
}
}
func TestLump_SetContents(t *testing.T) {
sut := new(Lump)
l := new(lumps.Generic)
l.SetLength(654)
sut.SetContents(l)
if sut.Contents() != l {
t.Error("unexpected lump data returned")
}
}
func TestLump_SetId(t *testing.T) {
sut := Lump{}
sut.SetId(LumpPakfile)
if sut.id != LumpPakfile {
t.Error("incorrect lump id")
}
}
func TestLump_SetRawContents(t *testing.T) {
sut := Lump{}
data := []byte{0, 1, 4, 3, 2}
sut.SetRawContents(data)
for idx, b := range sut.RawContents() {
if data[idx] != b {
t.Error("raw lump data mismatch")
}
}
}
func getExpectedLump(index int) lumps.ILump {
lMap := [64]lumps.ILump{
&lumps.EntData{},
&lumps.Planes{},
&lumps.TexData{},
&lumps.Vertex{},
&lumps.Visibility{},
&lumps.Node{},
&lumps.TexInfo{},
&lumps.Face{},
&lumps.Lighting{},
&lumps.Occlusion{},
&lumps.Leaf{},
&lumps.FaceId{},
&lumps.Edge{},
&lumps.Surfedge{},
&lumps.Model{},
&lumps.WorldLight{},
&lumps.LeafFace{},
&lumps.LeafBrush{},
&lumps.Brush{},
&lumps.BrushSide{},
&lumps.Area{},
&lumps.AreaPortal{},
&lumps.Unimplemented{},
&lumps.Unimplemented{},
&lumps.Unimplemented{},
&lumps.Unimplemented{},
&lumps.DispInfo{},
&lumps.Face{},
&lumps.PhysDisp{},
&lumps.Unimplemented{},
&lumps.VertNormal{},
&lumps.VertNormalIndice{},
&lumps.Unimplemented{},
&lumps.DispVert{},
&lumps.DispLightmapSamplePosition{},
&lumps.Game{},
&lumps.LeafWaterData{},
&lumps.Unimplemented{},
&lumps.PrimVert{},
&lumps.PrimIndice{},
&lumps.Pakfile{},
&lumps.ClipPortalVerts{},
&lumps.Cubemap{},
&lumps.TexDataStringData{},
&lumps.TexDataStringTable{},
&lumps.Overlay{},
&lumps.LeafMinDistToWater{},
&lumps.FaceMacroTextureInfo{},
&lumps.DispTris{},
&lumps.Unimplemented{},
&lumps.Unimplemented{},
&lumps.LeafAmbientIndexHDR{},
&lumps.LeafAmbientIndex{},
&lumps.Lighting{},
&lumps.WorldLightHDR{},
&lumps.LeafAmbientLightingHDR{},
&lumps.LeafAmbientLighting{},
&lumps.Unimplemented{},
&lumps.FaceHDR{},
&lumps.MapFlags{},
&lumps.OverlayFade{},
&lumps.Unimplemented{},
&lumps.Unimplemented{},
&lumps.Unimplemented{}, //disp multiblend
}
return lMap[index]
}