Browse Source

Script test should also run with older zlib on Travis

Thomas Buck 10 years ago
parent
commit
10fb294dca
4 changed files with 1018 additions and 1012 deletions
  1. 27
    14
      test/Script.cpp
  2. 987
    995
      test/ScriptPayload.h
  3. 2
    2
      test/ScriptTest.h
  4. 2
    1
      test/binary.cpp

+ 27
- 14
test/Script.cpp View File

@@ -128,27 +128,38 @@ namespace {
128 128
         return 0;
129 129
     }
130 130
 
131
-    void readPayloadChunk(const unsigned char *data, unsigned int size, const char *file) {
131
+    int readPayloadChunk(const unsigned char *data, unsigned int size, const char *file) {
132 132
         static const unsigned int bufferSize = 16384; // 16K should be enough for everybody :)
133 133
         unsigned char buffer[bufferSize];
134 134
 
135
+        // Initialize decompression
135 136
         z_stream stream;
136 137
         stream.zalloc = Z_NULL;
137 138
         stream.zfree =  Z_NULL;
138 139
         stream.opaque = Z_NULL;
139
-        assertEqual(inflateInit2(&stream, 16), Z_OK); // 16 -> gzip header
140
+        int error = inflateInit(&stream);
141
+        if (error != Z_OK) {
142
+            std::cout << "inflateInit() Error " << error << std::endl;
143
+            return 1;
144
+        }
140 145
 
141 146
         // Inflate data in one go
142 147
         stream.avail_in = size;
143 148
         stream.next_in = const_cast<unsigned char *>(data);
144 149
         stream.avail_out = bufferSize;
145 150
         stream.next_out = buffer;
146
-        assertEqual(inflate(&stream, Z_FINISH), Z_STREAM_END);
151
+        error = inflate(&stream, Z_FINISH);
152
+        if (error != Z_STREAM_END) {
153
+            std::cout << "inflate() Error " << error << std::endl;
154
+            return 2;
155
+        }
147 156
         inflateEnd(&stream);
148 157
 
149 158
         // Write buffer to file
150 159
         std::ofstream s(file, std::ios_base::out | std::ios_base::binary);
151 160
         s.write(reinterpret_cast<const char *>(buffer), bufferSize - stream.avail_out);
161
+
162
+        return 0;
152 163
     }
153 164
 
154 165
     int runForPayload(unsigned int n, bool print, bool printData) {
@@ -158,21 +169,23 @@ namespace {
158 169
         FILE *f;
159 170
         while ((f = fopen(tmpFile, "r")) != NULL) {
160 171
             fclose(f);
161
-            tmpFile[25]++;
172
+            tmpFile[26]++;
162 173
         }
163 174
 
164 175
         std::cout << "Temporary test file: " << tmpFile << std::endl;
165 176
 
166
-        readPayloadChunk(testPayloads[n], testSizes[n], tmpFile);
167
-
168
-        int error = 0;
169
-        if (print) {
170
-            Script s;
171
-            error = s.load(tmpFile);
172
-            if (error == 0)
173
-                error = printDataScript(s, printData);
174
-        } else {
175
-            error = test(tmpFile, n);
177
+        int error = readPayloadChunk(testPayloads[n], testSizes[n], tmpFile);
178
+        if (error == 0) {
179
+            if (print) {
180
+                Script s;
181
+                error = s.load(tmpFile);
182
+                if (error == 0)
183
+                    error = printDataScript(s, printData);
184
+                else
185
+                    std::cout << "Error loading script!" << std::endl;
186
+            } else {
187
+                error = test(tmpFile, n);
188
+            }
176 189
         }
177 190
 
178 191
         remove(tmpFile);

+ 987
- 995
test/ScriptPayload.h
File diff suppressed because it is too large
View File


+ 2
- 2
test/ScriptTest.h View File

@@ -17,11 +17,11 @@ static const char *testDescription[testPayloadCount] = {
17 17
 };
18 18
 
19 19
 static const unsigned char *testPayloads[testPayloadCount] = {
20
-    tr2_pc_dat_gz, tr2_psx_dat_gz, tr3_pc_dat_gz, tr3_psx_dat_gz
20
+    tr2_pc_dat_z, tr2_psx_dat_z, tr3_pc_dat_z, tr3_psx_dat_z
21 21
 };
22 22
 
23 23
 static const unsigned int testSizes[testPayloadCount] = {
24
-    sizeof(tr2_pc_dat_gz), sizeof(tr2_psx_dat_gz), sizeof(tr3_pc_dat_gz), sizeof(tr3_psx_dat_gz)
24
+    sizeof(tr2_pc_dat_z), sizeof(tr2_psx_dat_z), sizeof(tr3_pc_dat_z), sizeof(tr3_psx_dat_z)
25 25
 };
26 26
 
27 27
 static const unsigned int testExpectedGameStringCount[testPayloadCount] = {

+ 2
- 1
test/binary.cpp View File

@@ -38,6 +38,7 @@ namespace {
38 38
         file.write(reinterpret_cast<char *>(&f2), sizeof(f2));
39 39
     }
40 40
 
41
+    //! \fixme Don't use assert(), as it will prevent removing the created test file!
41 42
     int test(const char *name) {
42 43
         BinaryFile file;
43 44
         assertEqual(file.open(name), 0);
@@ -67,7 +68,7 @@ int main() {
67 68
     FILE *f;
68 69
     while ((f = fopen(tmpFile, "r")) != NULL) {
69 70
         fclose(f);
70
-        tmpFile[25]++;
71
+        tmpFile[26]++;
71 72
     }
72 73
 
73 74
     fillFile(tmpFile);

Loading…
Cancel
Save