|
@@ -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);
|