forked from dotabuff/manta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_table_test.go
168 lines (145 loc) · 4.48 KB
/
string_table_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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package manta
import (
"testing"
"github.com/dotabuff/manta/dota"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
)
func TestParseStringTableCreate(t *testing.T) {
// XXX: string tables changed, skipping for now.
t.Skip()
assert := assert.New(t)
scenarios := []struct {
fixturePath string
tableName string
itemCount int
firstItem *stringTableItem
lastItem *stringTableItem
}{
// CombatLogNames is uncompressed and has 24 entries (working)
{
"17_335_uncompressed.pbmsg",
"CombatLogNames",
24,
&stringTableItem{0, "dota_unknown", []byte{}},
&stringTableItem{23, "item_flask", []byte{}},
},
// downloadables is uncompressed and has no entries (working)
{
"01_29_uncompressed.pbmsg",
"downloadables",
0,
nil,
nil,
},
// ResponseKeys is uncompressed and has 15 entries (working)
{
"18_175_uncompressed.pbmsg",
"ResponseKeys",
15,
&stringTableItem{0, "concept", []byte{}},
&stringTableItem{14, "game_start_time", []byte{}},
},
// server_query_info is uncompressed and has 1 entry
{
"07_50_uncompressed.pbmsg",
"server_query_info",
1,
&stringTableItem{0, "QueryPort", []byte{0x0, 0x0, 0x0, 0x0}},
&stringTableItem{0, "QueryPort", []byte{0x0, 0x0, 0x0, 0x0}},
},
// lightstyles is compressed and has NNNNNNN entries with values
{
"05_590_compressed.pbmsg",
"lightstyles",
64,
&stringTableItem{0, "0", []byte{0x6D, 0x00}},
&stringTableItem{63, "63", []byte{0x61, 0x00}},
},
// instancebaseline is compressed and has 75 entries with values
// XXX TODO: I'm suspicious about the last keys having no values... make sure a delta matches the update!
{
"04_22356_compressed.pbmsg",
"instancebaseline",
75,
&stringTableItem{0, "664", _read_fixture("string_tables/instancebaseline/0000_664_414")},
&stringTableItem{74, "387", []byte{}},
},
// EntityNames is compressed and has 123 entries
{
"08_4162_compressed.pbmsg",
"EntityNames",
350,
&stringTableItem{0, "kobold_taskmaster_speed_aura", []byte{}},
&stringTableItem{349, "item_flask", []byte{}},
},
// EntityNames is compressed and has 123 entries
{
"13_18726_compressed.pbmsg",
"ModifierNames",
1274,
&stringTableItem{0, "modifier_disabled_invulnerable", []byte{}},
&stringTableItem{1273, "modifier_item_yasha", []byte{}},
},
// EconItems is not compressed and fails on values
// XXX TODO: I'm suspicious about the last keys having no values... make sure a delta matches the update!
{
"16_559_uncompressed.pbmsg",
"EconItems",
57,
&stringTableItem{0, "6498667144", []byte{}},
&stringTableItem{56, "422364528", []byte{}},
},
// GenericPrecache is uncompressed with a fixed data (bit) length
{
"02_33_uncompressed.pbmsg",
"genericprecache",
1,
&stringTableItem{0, "", []byte{0x00}},
&stringTableItem{0, "", []byte{0x00}},
},
}
// Iterate through test scenarios
for _, s := range scenarios {
// Load the message from the fixture
m := &dota.CSVCMsg_CreateStringTable{}
err := proto.Unmarshal(_read_fixture(_sprintf("string_tables/%s", s.fixturePath)), m)
if err != nil {
t.Errorf("unable to decode %s: %s", s.fixturePath, err)
continue
}
// Decompress the data if need be
buf := m.GetStringData()
if m.GetDataCompressed() {
buf, err = unlzss(buf)
if err != nil {
t.Errorf("unable to decompress %s: %s", s.fixturePath, err)
continue
}
}
// Make sure we're looking at the right table
assert.Equal(s.tableName, m.GetName(), s.tableName)
// Parse the table data
items := parseStringTable(buf, m.GetNumEntries(), "", m.GetUserDataFixedSize(), m.GetUserDataSize(), m.GetFlags())
// Make sure we have the correct number of entries
assert.Equal(s.itemCount, len(items), s.tableName)
// Verify the first and last entries
if s.firstItem != nil {
assert.Equal(s.firstItem, items[0], s.tableName)
}
if s.lastItem != nil {
assert.Equal(s.lastItem, items[len(items)-1], s.tableName)
}
}
}
func TestParseStringTableUpdate(t *testing.T) {
assert := assert.New(t)
buf := _read_fixture("string_tables/updates/tick_03960_table_7_items_13_size_208")
items := parseStringTable(buf, 13, "", false, 0, 0)
assert.Equal(int32(261), items[0].Index)
assert.Equal("broodmother_spawn_spiderlings", items[0].Key)
assert.Equal(int32(262), items[1].Index)
assert.Equal("broodmother_spin_web", items[1].Key)
assert.Equal(int32(263), items[2].Index)
assert.Equal("broodmother_incapacitating_bite", items[2].Key)
}