-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgssad_test.go
235 lines (174 loc) · 6.51 KB
/
rgssad_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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package rpgo
import (
"bytes"
_ "crypto/md5"
"errors"
"os"
"path/filepath"
"testing"
)
func TestExtractAllFiles_XP(t *testing.T) {
extracted_answers := "./test-rsrc/extracted/xp/"
var goat *RGSSADv1
testArchive := "./test-rsrc/Game.rgssad"
if _, err := os.Stat(testArchive); errors.Is(err, os.ErrNotExist) {
t.Error("test/ExtractAllFiles_XP: test config fail, archive doesn't exist")
t.FailNow()
}
goat, err := NewRGSSADv1(testArchive)
if err != nil {
t.Errorf("test/ExtractAllFiles_XP: make rgssad err not nil:\n%s", err.Error())
t.FailNow()
}
extractTo, err := os.MkdirTemp(os.TempDir(), "rpgo-testsuite-*")
if err != nil {
t.Errorf("test/ExtractAllFiles_XP: mkdir temp err not nil:\n%s", err.Error())
t.FailNow()
}
err = goat.ExtractAllFiles(extractTo, true)
if err != nil {
t.Errorf("test/ExtractAllFiles_XP: extract err not nil:\n%s", err.Error())
t.FailNow()
}
// use os.SameFile(os.Stat(question), os.Stat(answer))
all_questions, err := os.ReadDir(filepath.Join(extractTo, "Data"))
if err != nil {
t.Errorf("test/ExtractAllFiles_XP: readdir for questions err not nil:\n%s", err.Error())
t.FailNow()
}
all_answers, err := os.ReadDir(filepath.Join(extracted_answers, "Data"))
if err != nil {
t.Errorf("test/ExtractAllFiles_XP: readdir for answers err not nil:\n%s", err.Error())
t.FailNow()
}
if len(all_questions) != len(all_answers) {
t.Errorf("test/ExtractAllFiles_XP: file count mismatch; expected %d, got %d", len(all_answers), len(all_questions))
t.FailNow()
}
for idx := range all_questions {
question_data, err := os.ReadFile(filepath.Join(extractTo, "Data", all_questions[idx].Name()))
if err != nil {
t.Errorf("test/ExtractAllFiles_XP: err getting question data at index %d (sorted alphabetically):\n%s", idx, err.Error())
t.FailNow()
}
answer_data, err := os.ReadFile(filepath.Join(extracted_answers, "Data", all_answers[idx].Name()))
if err != nil {
t.Errorf("test/ExtractAllFiles_XP: err getting answer data at index %d (sorted alphabetically):\n%s", idx, err.Error())
t.FailNow()
}
if !bytes.Equal(question_data, answer_data) {
t.Errorf("test/ExtractAllFiles_XP: file data mismath at index %d (sorted alphabetically)", idx)
t.FailNow()
}
}
}
func TestExtractAllFiles_VX(t *testing.T) {
extracted_answers := "./test-rsrc/extracted/vx/"
var goat *RGSSADv1
testArchive := "./test-rsrc/Game.rgss2a"
if _, err := os.Stat(testArchive); errors.Is(err, os.ErrNotExist) {
t.Error("test/ExtractAllFiles_VX: test config fail, archive doesn't exist")
t.FailNow()
}
goat, err := NewRGSSADv1(testArchive)
if err != nil {
t.Errorf("test/ExtractAllFiles_VX: make rgssad err not nil:\n%s", err.Error())
t.FailNow()
}
extractTo, err := os.MkdirTemp(os.TempDir(), "rpgo-testsuite-*")
if err != nil {
t.Errorf("test/ExtractAllFiles_VX: mkdir temp err not nil:\n%s", err.Error())
t.FailNow()
}
err = goat.ExtractAllFiles(extractTo, true)
if err != nil {
t.Errorf("test/ExtractAllFiles_VX: extract err not nil:\n%s", err.Error())
t.FailNow()
}
// use os.SameFile(os.Stat(question), os.Stat(answer))
all_questions, err := os.ReadDir(filepath.Join(extractTo, "Data"))
if err != nil {
t.Errorf("test/ExtractAllFiles_VX: readdir for questions err not nil:\n%s", err.Error())
t.FailNow()
}
all_answers, err := os.ReadDir(filepath.Join(extracted_answers, "Data"))
if err != nil {
t.Errorf("test/ExtractAllFiles_VX: readdir for answers err not nil:\n%s", err.Error())
t.FailNow()
}
if len(all_questions) != len(all_answers) {
t.Errorf("test/ExtractAllFiles_VX: file count mismatch; expected %d, got %d", len(all_answers), len(all_questions))
t.FailNow()
}
for idx := range all_questions {
question_data, err := os.ReadFile(filepath.Join(extractTo, "Data", all_questions[idx].Name()))
if err != nil {
t.Errorf("test/ExtractAllFiles_VX: err getting question data at index %d (sorted alphabetically):\n%s", idx, err.Error())
t.FailNow()
}
answer_data, err := os.ReadFile(filepath.Join(extracted_answers, "Data", all_answers[idx].Name()))
if err != nil {
t.Errorf("test/ExtractAllFiles_VX: err getting answer data at index %d (sorted alphabetically):\n%s", idx, err.Error())
t.FailNow()
}
if !bytes.Equal(question_data, answer_data) {
t.Errorf("test/ExtractAllFiles_VX: file data mismath at index %d (sorted alphabetically)", idx)
t.FailNow()
}
}
}
func TestExtractAllFiles_VXAce(t *testing.T) {
extracted_answers := "./test-rsrc/extracted/vxa/"
var goat *RGSSADv3
testArchive := "./test-rsrc/Game.rgss3a"
if _, err := os.Stat(testArchive); errors.Is(err, os.ErrNotExist) {
t.Error("test/ExtractAllFiles_VXAce: test config fail, archive doesn't exist")
t.FailNow()
}
goat, err := NewRGSSADv3(testArchive)
if err != nil {
t.Errorf("test/ExtractAllFiles_VXAce: make rgssad err not nil:\n%s", err.Error())
t.FailNow()
}
extractTo, err := os.MkdirTemp(os.TempDir(), "rpgo-testsuite-*")
if err != nil {
t.Errorf("test/ExtractAllFiles_VXAce: mkdir temp err not nil:\n%s", err.Error())
t.FailNow()
}
err = goat.ExtractAllFiles(extractTo, true)
if err != nil {
t.Errorf("test/ExtractAllFiles_VXAce: extract err not nil:\n%s", err.Error())
t.FailNow()
}
// use os.SameFile(os.Stat(question), os.Stat(answer))
all_questions, err := os.ReadDir(filepath.Join(extractTo, "Data"))
if err != nil {
t.Errorf("test/ExtractAllFiles_VXAce: readdir for questions err not nil:\n%s", err.Error())
t.FailNow()
}
all_answers, err := os.ReadDir(filepath.Join(extracted_answers, "Data"))
if err != nil {
t.Errorf("test/ExtractAllFiles_VXAce: readdir for answers err not nil:\n%s", err.Error())
t.FailNow()
}
if len(all_questions) != len(all_answers) {
t.Errorf("test/ExtractAllFiles_VXAce: file count mismatch; expected %d, got %d", len(all_answers), len(all_questions))
t.FailNow()
}
for idx := range all_questions {
question_data, err := os.ReadFile(filepath.Join(extractTo, "Data", all_questions[idx].Name()))
if err != nil {
t.Errorf("test/ExtractAllFiles_VXAce: err getting question data at index %d (sorted alphabetically):\n%s", idx, err.Error())
t.FailNow()
}
answer_data, err := os.ReadFile(filepath.Join(extracted_answers, "Data", all_answers[idx].Name()))
if err != nil {
t.Errorf("test/ExtractAllFiles_VXAce: err getting answer data at index %d (sorted alphabetically):\n%s", idx, err.Error())
t.FailNow()
}
if !bytes.Equal(question_data, answer_data) {
t.Errorf("test/ExtractAllFiles_VXAce: file data mismath at index %d (sorted alphabetically)", idx)
t.FailNow()
}
}
}