sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Name : tzlibadvanced.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "tzlib.h"
|
sl@0
|
19 |
#include "zutil.h"
|
sl@0
|
20 |
//#include "deflate.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
#define COMPRESSED_DATA_BUFFER_LENGTH 200*sizeof(int)
|
sl@0
|
23 |
#define FAILURE_RATE_LIMIT 100
|
sl@0
|
24 |
#define TEST_MID_MEM_LEVEL 5
|
sl@0
|
25 |
|
sl@0
|
26 |
// Add this to the windowBits value to use a GZip header instead of a Zlib header
|
sl@0
|
27 |
#define TEST_GZIP_HEADER 16
|
sl@0
|
28 |
|
sl@0
|
29 |
// Add this to the windowBits when calling inflateInit2() to use automatic header detection
|
sl@0
|
30 |
#define TEST_AUTO_HEADER_DETECTION 32
|
sl@0
|
31 |
|
sl@0
|
32 |
#define CHECK_CONDITION0L(condition, leaveErr, errMessage) \
|
sl@0
|
33 |
if (condition) \
|
sl@0
|
34 |
{ \
|
sl@0
|
35 |
ERR_PRINTF1(_L(errMessage)); \
|
sl@0
|
36 |
User::Leave(leaveErr); \
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
#define CHECK_CONDITION1L(condition, leaveErr, errMessage, p1) \
|
sl@0
|
40 |
if (condition) \
|
sl@0
|
41 |
{ \
|
sl@0
|
42 |
ERR_PRINTF2(_L(errMessage), p1); \
|
sl@0
|
43 |
User::Leave(leaveErr); \
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
_LIT(KParam1, "Param1");
|
sl@0
|
47 |
_LIT(KParam2, "Param2");
|
sl@0
|
48 |
_LIT(KParam3, "Param3");
|
sl@0
|
49 |
_LIT(KParam4, "Param4");
|
sl@0
|
50 |
|
sl@0
|
51 |
// bufferDescriptor holds extra information required by in_func and out_func to perform their jobs
|
sl@0
|
52 |
struct bufferDescriptor
|
sl@0
|
53 |
{
|
sl@0
|
54 |
Byte *buffer;
|
sl@0
|
55 |
int next;
|
sl@0
|
56 |
int length;
|
sl@0
|
57 |
};
|
sl@0
|
58 |
|
sl@0
|
59 |
/*
|
sl@0
|
60 |
* Helper member function that sets up the deflate stream for use.
|
sl@0
|
61 |
*/
|
sl@0
|
62 |
void CTestZlib::DeflateInitL(z_stream &aStream, const int aLevel, const int expectedResult)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
TInt err = Z_OK;
|
sl@0
|
65 |
|
sl@0
|
66 |
aStream.zalloc = Z_NULL;
|
sl@0
|
67 |
aStream.zfree = Z_NULL;
|
sl@0
|
68 |
aStream.opaque = Z_NULL;
|
sl@0
|
69 |
|
sl@0
|
70 |
err = deflateInit(&aStream, aLevel);
|
sl@0
|
71 |
CHECK_CONDITION1L(err != expectedResult, KErrNoMemory, "deflateInit error: %d", err);
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
/*
|
sl@0
|
75 |
* Helper member function that sets up the deflate stream for use.
|
sl@0
|
76 |
*/
|
sl@0
|
77 |
void CTestZlib::DeflateInit2L(z_stream &aStream, const int aLevel, const int aMethod, const int aWindowBits, const int aMemLevel, const int aStrategy, const int expectedResult)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
int err;
|
sl@0
|
80 |
|
sl@0
|
81 |
aStream.zalloc = Z_NULL;
|
sl@0
|
82 |
aStream.zfree = Z_NULL;
|
sl@0
|
83 |
aStream.opaque = Z_NULL;
|
sl@0
|
84 |
|
sl@0
|
85 |
err = deflateInit2(&aStream, aLevel, aMethod, aWindowBits, aMemLevel, aStrategy);
|
sl@0
|
86 |
CHECK_CONDITION1L(err != expectedResult, KErrNoMemory, "deflateInit2 error: %d", err);
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
/*
|
sl@0
|
90 |
* Helper member function that compresses data using the deflate function.
|
sl@0
|
91 |
*/
|
sl@0
|
92 |
TInt CTestZlib::DeflateCompress(z_stream &aStream, Byte *aInputData, int aInputDataLength, Byte *aCompressedDataBuffer, int aCompressedDataBufferLength)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
int err;
|
sl@0
|
95 |
int flush;
|
sl@0
|
96 |
|
sl@0
|
97 |
// Compress data in the input buffer and place compressed data in the output buffer
|
sl@0
|
98 |
aStream.next_in = aInputData;
|
sl@0
|
99 |
aStream.next_out = aCompressedDataBuffer;
|
sl@0
|
100 |
|
sl@0
|
101 |
do
|
sl@0
|
102 |
{
|
sl@0
|
103 |
if (aStream.total_in < aInputDataLength)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
aStream.avail_in = 1; // force small buffer
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
flush = (aStream.total_in == aInputDataLength) ? Z_FINISH : Z_NO_FLUSH;
|
sl@0
|
109 |
|
sl@0
|
110 |
// Run deflate() on input until output buffer not full
|
sl@0
|
111 |
// Finish compression if all of input buffer has been read in
|
sl@0
|
112 |
do
|
sl@0
|
113 |
{
|
sl@0
|
114 |
if (aStream.total_out < aCompressedDataBufferLength)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
aStream.avail_out = 1; // force small buffer
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
err = deflate(&aStream, flush);
|
sl@0
|
120 |
if(err != Z_OK && err != Z_STREAM_END)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
return err;
|
sl@0
|
123 |
}
|
sl@0
|
124 |
} while(aStream.avail_out == 0 && err == Z_OK);
|
sl@0
|
125 |
} while(err != Z_STREAM_END);
|
sl@0
|
126 |
|
sl@0
|
127 |
return Z_OK;
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
/*
|
sl@0
|
131 |
* Helper member function that cleans up a deflate stream.
|
sl@0
|
132 |
*/
|
sl@0
|
133 |
void CTestZlib::DeflateEnd(TAny *aStream)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
if(((z_stream *)aStream)->state != NULL)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
deflateEnd((z_stream *)aStream);
|
sl@0
|
138 |
}
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
/*
|
sl@0
|
142 |
* Helper member function that sets up the inflate stream for use.
|
sl@0
|
143 |
*/
|
sl@0
|
144 |
void CTestZlib::InflateInitL(z_stream &aStream, const int expectedResult)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
TInt err = Z_OK;
|
sl@0
|
147 |
|
sl@0
|
148 |
aStream.zalloc = Z_NULL;
|
sl@0
|
149 |
aStream.zfree = Z_NULL;
|
sl@0
|
150 |
aStream.opaque = Z_NULL;
|
sl@0
|
151 |
|
sl@0
|
152 |
err = inflateInit(&aStream);
|
sl@0
|
153 |
CHECK_CONDITION1L(err != expectedResult, KErrNoMemory, "inflateInit error: %d", err);
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
/*
|
sl@0
|
157 |
* Helper member function that sets up the inflate stream for use.
|
sl@0
|
158 |
*/
|
sl@0
|
159 |
void CTestZlib::InflateInit2L(z_stream &aStream, const int aWindowBits, const int expectedResult)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
TInt err = Z_OK;
|
sl@0
|
162 |
|
sl@0
|
163 |
aStream.zalloc = Z_NULL;
|
sl@0
|
164 |
aStream.zfree = Z_NULL;
|
sl@0
|
165 |
aStream.opaque = Z_NULL;
|
sl@0
|
166 |
|
sl@0
|
167 |
err = inflateInit2(&aStream, aWindowBits);
|
sl@0
|
168 |
CHECK_CONDITION1L(err != expectedResult, KErrNoMemory, "inflateInit2 error: %d", err);
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
void CTestZlib::InflateBackInitL(z_stream &aStream, const int aWindowBits, Bytef *aWindow, const int expectedResult)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
int err;
|
sl@0
|
174 |
|
sl@0
|
175 |
aStream.zalloc = Z_NULL;
|
sl@0
|
176 |
aStream.zfree = Z_NULL;
|
sl@0
|
177 |
aStream.opaque = Z_NULL;
|
sl@0
|
178 |
|
sl@0
|
179 |
err = inflateBackInit(&aStream, aWindowBits, aWindow);
|
sl@0
|
180 |
CHECK_CONDITION1L(err != expectedResult, KErrNoMemory, "inflateBackInit error: %d", err);
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
/*
|
sl@0
|
184 |
* Helper member function that decompresses data using the inflate function.
|
sl@0
|
185 |
*/
|
sl@0
|
186 |
TInt CTestZlib::InflateDecompress(z_stream &aStream, Byte *aCompressedDataBuffer, int aCompressedDataLength, Byte *aDecompressedDataBuffer, int aDecompressedDataBufferLength)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
int err;
|
sl@0
|
189 |
|
sl@0
|
190 |
// Decompress data in the aCompressedDataBuffer and place it in the aDecompressedDataBuffer
|
sl@0
|
191 |
aStream.next_in = aCompressedDataBuffer;
|
sl@0
|
192 |
aStream.next_out = aDecompressedDataBuffer;
|
sl@0
|
193 |
|
sl@0
|
194 |
// Keep providing input data and output space for deflate()
|
sl@0
|
195 |
do
|
sl@0
|
196 |
{
|
sl@0
|
197 |
if(aStream.total_in < aCompressedDataLength)
|
sl@0
|
198 |
{
|
sl@0
|
199 |
aStream.avail_in = 1; // force small buffer
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
if (aStream.total_out < aDecompressedDataBufferLength)
|
sl@0
|
203 |
{
|
sl@0
|
204 |
aStream.avail_out = 1; // force small buffer
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
err = inflate(&aStream, Z_NO_FLUSH);
|
sl@0
|
208 |
if(err != Z_OK && err != Z_STREAM_END)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
return err;
|
sl@0
|
211 |
}
|
sl@0
|
212 |
} while(err != Z_STREAM_END);
|
sl@0
|
213 |
|
sl@0
|
214 |
return Z_OK;
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|
sl@0
|
217 |
/*
|
sl@0
|
218 |
* Helper member function that cleans up a inflate stream.
|
sl@0
|
219 |
*/
|
sl@0
|
220 |
void CTestZlib::InflateEnd(TAny *aStream)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
if(((z_stream *)aStream)->state != NULL)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
inflateEnd((z_stream *)aStream);
|
sl@0
|
225 |
}
|
sl@0
|
226 |
}
|
sl@0
|
227 |
|
sl@0
|
228 |
/*
|
sl@0
|
229 |
* Helper member function that cleans up an inflate back stream.
|
sl@0
|
230 |
*/
|
sl@0
|
231 |
void CTestZlib::InflateBackEnd(TAny *aStream)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
if(((z_stream *)aStream)->state != NULL)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
inflateBackEnd((z_stream *)aStream);
|
sl@0
|
236 |
}
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
/*
|
sl@0
|
240 |
* Helper member function that compares the contents of two GZip headers to make
|
sl@0
|
241 |
* sure they are the same.
|
sl@0
|
242 |
*/
|
sl@0
|
243 |
TBool CTestZlib::GZipHeadersEqual(const gz_header &header1, const gz_header &header2)
|
sl@0
|
244 |
{
|
sl@0
|
245 |
TBool headersEqual = true;
|
sl@0
|
246 |
|
sl@0
|
247 |
if(header1.text != header2.text)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
INFO_PRINTF3(_L("readGZipHeader.text - Expected %d and got %d"), header1.text, header2.text);
|
sl@0
|
250 |
headersEqual = false;
|
sl@0
|
251 |
}
|
sl@0
|
252 |
|
sl@0
|
253 |
if(header1.time != header2.time)
|
sl@0
|
254 |
{
|
sl@0
|
255 |
INFO_PRINTF3(_L("readGZipHeader.time - Expected %d and got %d"), header1.time, header2.time);
|
sl@0
|
256 |
headersEqual = false;
|
sl@0
|
257 |
}
|
sl@0
|
258 |
|
sl@0
|
259 |
if(header1.xflags != header2.xflags)
|
sl@0
|
260 |
{
|
sl@0
|
261 |
INFO_PRINTF3(_L("readGZipHeader.xflags - Expected %d and got %d"), header1.xflags, header2.xflags);
|
sl@0
|
262 |
headersEqual = false;
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
if(header1.os != header2.os)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
INFO_PRINTF3(_L("readGZipHeader.os - Expected %d and got %d"), header1.os, header2.os);
|
sl@0
|
268 |
headersEqual = false;
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
if(header1.extra != NULL & header2.extra != NULL)
|
sl@0
|
272 |
{
|
sl@0
|
273 |
if(header1.extra_len != header2.extra_len)
|
sl@0
|
274 |
{
|
sl@0
|
275 |
INFO_PRINTF1(_L("readGZipHeader.extra_len - Unexpected value."));
|
sl@0
|
276 |
headersEqual = false;
|
sl@0
|
277 |
}
|
sl@0
|
278 |
else if(memcmp(header1.extra, header2.extra, header1.extra_len) != 0)
|
sl@0
|
279 |
{
|
sl@0
|
280 |
INFO_PRINTF1(_L("readGZipHeader.extra - Unexpected value."));
|
sl@0
|
281 |
headersEqual = false;
|
sl@0
|
282 |
}
|
sl@0
|
283 |
}
|
sl@0
|
284 |
else if(header1.extra == NULL && header2.extra != NULL
|
sl@0
|
285 |
|| header1.extra != NULL && header2.extra == NULL)
|
sl@0
|
286 |
{
|
sl@0
|
287 |
INFO_PRINTF1(_L("readGZipHeader.extra - Unexpected value."));
|
sl@0
|
288 |
headersEqual = false;
|
sl@0
|
289 |
}
|
sl@0
|
290 |
|
sl@0
|
291 |
if(header1.name != NULL && header2.name != NULL)
|
sl@0
|
292 |
{
|
sl@0
|
293 |
if(strcmp((char *)header1.name, (char *)header2.name) != 0)
|
sl@0
|
294 |
{
|
sl@0
|
295 |
INFO_PRINTF1(_L("readGZipHeader.name - Unexpected value. The headers contained different strings."));
|
sl@0
|
296 |
headersEqual = false;
|
sl@0
|
297 |
}
|
sl@0
|
298 |
}
|
sl@0
|
299 |
else if((header1.name == NULL && header2.name != NULL)
|
sl@0
|
300 |
|| (header1.name != NULL && header2.name == NULL))
|
sl@0
|
301 |
{
|
sl@0
|
302 |
INFO_PRINTF1(_L("readGZipHeader.name - Unexpected value. One of the headers contained a NULL value."));
|
sl@0
|
303 |
headersEqual = false;
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
if(header1.comment != NULL && header2.comment != NULL)
|
sl@0
|
307 |
{
|
sl@0
|
308 |
if(strcmp((char *)header1.comment, (char *)header2.comment) != 0)
|
sl@0
|
309 |
{
|
sl@0
|
310 |
INFO_PRINTF1(_L("readGZipHeader.comment - Unexpected value. The headers contained different strings."));
|
sl@0
|
311 |
headersEqual = false;
|
sl@0
|
312 |
}
|
sl@0
|
313 |
}
|
sl@0
|
314 |
else if((header1.comment == NULL && header2.comment != NULL)
|
sl@0
|
315 |
|| (header1.comment != NULL && header2.comment == NULL))
|
sl@0
|
316 |
{
|
sl@0
|
317 |
INFO_PRINTF1(_L("readGZipHeader.comment - Unexpected value. One of the headers contained a NULL value."));
|
sl@0
|
318 |
headersEqual = false;
|
sl@0
|
319 |
}
|
sl@0
|
320 |
|
sl@0
|
321 |
if(header1.hcrc != header2.hcrc)
|
sl@0
|
322 |
{
|
sl@0
|
323 |
INFO_PRINTF3(_L("readGZipHeader.hcrc - Expected %d and got %d"), header1.hcrc, header2.hcrc);
|
sl@0
|
324 |
headersEqual = false;
|
sl@0
|
325 |
}
|
sl@0
|
326 |
|
sl@0
|
327 |
if(header1.done != header2.done)
|
sl@0
|
328 |
{
|
sl@0
|
329 |
INFO_PRINTF3(_L("readGZipHeader.done - Expected %d and got %d"), header1.done, header2.done);
|
sl@0
|
330 |
headersEqual = false;
|
sl@0
|
331 |
}
|
sl@0
|
332 |
|
sl@0
|
333 |
return headersEqual;
|
sl@0
|
334 |
}
|
sl@0
|
335 |
|
sl@0
|
336 |
/*
|
sl@0
|
337 |
* Helper member function that checks to see if the header is the default GZip header
|
sl@0
|
338 |
*/
|
sl@0
|
339 |
TBool CTestZlib::IsDefaultGZipHeader(const gz_header &header)
|
sl@0
|
340 |
{
|
sl@0
|
341 |
gz_header defaultHeader;
|
sl@0
|
342 |
|
sl@0
|
343 |
// gz_header default values
|
sl@0
|
344 |
defaultHeader.text = 0;
|
sl@0
|
345 |
defaultHeader.time = 0;
|
sl@0
|
346 |
defaultHeader.xflags = 0;
|
sl@0
|
347 |
defaultHeader.os = OS_CODE;
|
sl@0
|
348 |
defaultHeader.extra = NULL;
|
sl@0
|
349 |
defaultHeader.name = NULL;
|
sl@0
|
350 |
defaultHeader.comment = NULL;
|
sl@0
|
351 |
defaultHeader.hcrc = 0;
|
sl@0
|
352 |
defaultHeader.done = 1;
|
sl@0
|
353 |
|
sl@0
|
354 |
return GZipHeadersEqual(defaultHeader, header);
|
sl@0
|
355 |
}
|
sl@0
|
356 |
|
sl@0
|
357 |
/*
|
sl@0
|
358 |
* Helper member function that compresses an input buffer and place it in a compressed output buffer
|
sl@0
|
359 |
*/
|
sl@0
|
360 |
void CTestZlib::CompressDataL(StreamSettings &aStreamSettings, z_stream &aStream, Byte *aInputData, int aInputDataLength, Byte *aCompressedDataBuffer, int aCompressedDataBufferLength, gz_headerp aHeader)
|
sl@0
|
361 |
{
|
sl@0
|
362 |
TInt err = Z_OK;
|
sl@0
|
363 |
|
sl@0
|
364 |
// Initialise the deflate stream
|
sl@0
|
365 |
if(aStreamSettings.deflateInit2 == false)
|
sl@0
|
366 |
{
|
sl@0
|
367 |
this->DeflateInitL(aStream, aStreamSettings.level);
|
sl@0
|
368 |
}
|
sl@0
|
369 |
else
|
sl@0
|
370 |
{
|
sl@0
|
371 |
this->DeflateInit2L(aStream, aStreamSettings.level, aStreamSettings.method, aStreamSettings.deflateWindowBits, aStreamSettings.memLevel, aStreamSettings.strategy);
|
sl@0
|
372 |
}
|
sl@0
|
373 |
CleanupStack::PushL(TCleanupItem(DeflateEnd, &aStream));
|
sl@0
|
374 |
|
sl@0
|
375 |
// If a GZip header is specified insert the gzip header information to the
|
sl@0
|
376 |
// start of the output when deflate is called
|
sl@0
|
377 |
if(aHeader != NULL)
|
sl@0
|
378 |
{
|
sl@0
|
379 |
err = deflateSetHeader(&aStream, aHeader);
|
sl@0
|
380 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflateSetHeader error: %d", err);
|
sl@0
|
381 |
}
|
sl@0
|
382 |
|
sl@0
|
383 |
// Compress the input
|
sl@0
|
384 |
err = this->DeflateCompress(aStream, aInputData, aInputDataLength, aCompressedDataBuffer, aCompressedDataBufferLength);
|
sl@0
|
385 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflate error: %d", err);
|
sl@0
|
386 |
|
sl@0
|
387 |
// Clean up the deflateStream
|
sl@0
|
388 |
err = deflateEnd(&aStream);
|
sl@0
|
389 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflateEnd error: %d", err);
|
sl@0
|
390 |
CleanupStack::Pop(1);
|
sl@0
|
391 |
}
|
sl@0
|
392 |
|
sl@0
|
393 |
/*
|
sl@0
|
394 |
* Helper function that deflates some input data as a gzip stream and then inflates
|
sl@0
|
395 |
* the compressed data.
|
sl@0
|
396 |
*/
|
sl@0
|
397 |
TVerdict CTestZlib::DefInfGZipHeaderL(const TBool aIgnoreHeader, const TBool aAutoDetectHeader, gz_headerp aSpecifiedGZipHeader)
|
sl@0
|
398 |
{
|
sl@0
|
399 |
int err = Z_OK;
|
sl@0
|
400 |
TVerdict verdict = EPass;
|
sl@0
|
401 |
|
sl@0
|
402 |
// Streams
|
sl@0
|
403 |
z_stream deflateStream;
|
sl@0
|
404 |
z_stream inflateStream;
|
sl@0
|
405 |
|
sl@0
|
406 |
// Headers
|
sl@0
|
407 |
gz_header readGZipHeader;
|
sl@0
|
408 |
readGZipHeader.extra = NULL;
|
sl@0
|
409 |
readGZipHeader.name = NULL;
|
sl@0
|
410 |
readGZipHeader.comment = NULL;
|
sl@0
|
411 |
|
sl@0
|
412 |
// Buffers
|
sl@0
|
413 |
const char inputData[] = "This is a piece of data to compress.\0"; // data to compress
|
sl@0
|
414 |
uLong inputDataLength = (uLong)strlen(inputData) + 1;
|
sl@0
|
415 |
Byte *compressedDataBuffer = NULL;
|
sl@0
|
416 |
uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
|
sl@0
|
417 |
Byte *decompressedDataBuffer = NULL;
|
sl@0
|
418 |
uLong decompressedDataBufferLength = inputDataLength;
|
sl@0
|
419 |
|
sl@0
|
420 |
// deflateInit2 and inflateInit2 arguments
|
sl@0
|
421 |
StreamSettings streamSettings;
|
sl@0
|
422 |
streamSettings.deflateInit2 = true;
|
sl@0
|
423 |
streamSettings.level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
424 |
streamSettings.method = Z_DEFLATED;
|
sl@0
|
425 |
streamSettings.deflateWindowBits = MAX_WBITS + TEST_GZIP_HEADER;
|
sl@0
|
426 |
streamSettings.inflateWindowBits = MAX_WBITS;
|
sl@0
|
427 |
streamSettings.memLevel = TEST_MID_MEM_LEVEL;
|
sl@0
|
428 |
streamSettings.strategy = Z_DEFAULT_STRATEGY;
|
sl@0
|
429 |
|
sl@0
|
430 |
streamSettings.inflateWindowBits += (aAutoDetectHeader == true) ? TEST_AUTO_HEADER_DETECTION : TEST_GZIP_HEADER;
|
sl@0
|
431 |
|
sl@0
|
432 |
compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
433 |
CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
|
sl@0
|
434 |
CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
|
sl@0
|
435 |
|
sl@0
|
436 |
decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
|
sl@0
|
437 |
CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
|
sl@0
|
438 |
CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
|
sl@0
|
439 |
|
sl@0
|
440 |
// Allocate memory, if required, for readGZipHeader if header data is being
|
sl@0
|
441 |
// checked and if a specified GZip header has been given. This is because
|
sl@0
|
442 |
// extra, name and comment may have been set in the specified GZip header.
|
sl@0
|
443 |
if(aIgnoreHeader == false && aSpecifiedGZipHeader != NULL)
|
sl@0
|
444 |
{
|
sl@0
|
445 |
if(aSpecifiedGZipHeader->extra != NULL)
|
sl@0
|
446 |
{
|
sl@0
|
447 |
readGZipHeader.extra_max = aSpecifiedGZipHeader->extra_max;
|
sl@0
|
448 |
readGZipHeader.extra = (Bytef *)User::AllocZ(aSpecifiedGZipHeader->extra_max * sizeof(Bytef));
|
sl@0
|
449 |
CHECK_CONDITION0L(readGZipHeader.extra == NULL, KErrNoMemory, "Failed to allocate memory for readGZipHeader.extra.");
|
sl@0
|
450 |
CleanupStack::PushL(TCleanupItem(User::Free, readGZipHeader.extra));
|
sl@0
|
451 |
}
|
sl@0
|
452 |
|
sl@0
|
453 |
if(aSpecifiedGZipHeader->name != NULL)
|
sl@0
|
454 |
{
|
sl@0
|
455 |
readGZipHeader.name_max = aSpecifiedGZipHeader->name_max;
|
sl@0
|
456 |
readGZipHeader.name = (Bytef *)User::AllocZ(aSpecifiedGZipHeader->name_max * sizeof(Bytef));
|
sl@0
|
457 |
CHECK_CONDITION0L(readGZipHeader.name == NULL, KErrNoMemory, "Failed to allocate memory for readGZipHeader.name.");
|
sl@0
|
458 |
CleanupStack::PushL(TCleanupItem(User::Free, readGZipHeader.name));
|
sl@0
|
459 |
}
|
sl@0
|
460 |
|
sl@0
|
461 |
if(aSpecifiedGZipHeader->comment != NULL)
|
sl@0
|
462 |
{
|
sl@0
|
463 |
readGZipHeader.comm_max = aSpecifiedGZipHeader->comm_max;
|
sl@0
|
464 |
readGZipHeader.comment = (Bytef *)User::AllocZ(aSpecifiedGZipHeader->comm_max * sizeof(Bytef));
|
sl@0
|
465 |
CHECK_CONDITION0L(readGZipHeader.comment == NULL, KErrNoMemory, "Failed to allocate memory for readGZipHeader.comment.");
|
sl@0
|
466 |
CleanupStack::PushL(TCleanupItem(User::Free, readGZipHeader.comment));
|
sl@0
|
467 |
}
|
sl@0
|
468 |
}
|
sl@0
|
469 |
this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength, aSpecifiedGZipHeader);
|
sl@0
|
470 |
|
sl@0
|
471 |
// Initialise the inflateStream
|
sl@0
|
472 |
this->InflateInit2L(inflateStream, streamSettings.inflateWindowBits);
|
sl@0
|
473 |
CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
|
sl@0
|
474 |
|
sl@0
|
475 |
// If the header information is not to be ignored get the GZip
|
sl@0
|
476 |
// header information when inflate is called
|
sl@0
|
477 |
if(aIgnoreHeader == false)
|
sl@0
|
478 |
{
|
sl@0
|
479 |
err = inflateGetHeader(&inflateStream, &readGZipHeader);
|
sl@0
|
480 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateGetHeader error: %d", err);
|
sl@0
|
481 |
}
|
sl@0
|
482 |
|
sl@0
|
483 |
err = this->InflateDecompress(inflateStream, compressedDataBuffer, deflateStream.total_out, decompressedDataBuffer, decompressedDataBufferLength);
|
sl@0
|
484 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflate error: %d", err);
|
sl@0
|
485 |
|
sl@0
|
486 |
// Clean up the inflateStream
|
sl@0
|
487 |
err = inflateEnd(&inflateStream);
|
sl@0
|
488 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateEnd error: %d", err);
|
sl@0
|
489 |
CleanupStack::Pop(1);
|
sl@0
|
490 |
|
sl@0
|
491 |
// If the header information hasn't been ignored Check the GZip header
|
sl@0
|
492 |
// contains the expected information
|
sl@0
|
493 |
if(aIgnoreHeader == false)
|
sl@0
|
494 |
{
|
sl@0
|
495 |
if(aSpecifiedGZipHeader != NULL)
|
sl@0
|
496 |
{
|
sl@0
|
497 |
verdict = GZipHeadersEqual(*aSpecifiedGZipHeader, readGZipHeader) ? EPass : EFail;
|
sl@0
|
498 |
}
|
sl@0
|
499 |
else
|
sl@0
|
500 |
{
|
sl@0
|
501 |
verdict = IsDefaultGZipHeader(readGZipHeader) ? EPass : EFail;
|
sl@0
|
502 |
}
|
sl@0
|
503 |
}
|
sl@0
|
504 |
|
sl@0
|
505 |
if(readGZipHeader.comment != NULL)
|
sl@0
|
506 |
{
|
sl@0
|
507 |
CleanupStack::PopAndDestroy(1);
|
sl@0
|
508 |
}
|
sl@0
|
509 |
|
sl@0
|
510 |
if(readGZipHeader.name != NULL)
|
sl@0
|
511 |
{
|
sl@0
|
512 |
CleanupStack::PopAndDestroy(1);
|
sl@0
|
513 |
}
|
sl@0
|
514 |
|
sl@0
|
515 |
if(readGZipHeader.extra != NULL)
|
sl@0
|
516 |
{
|
sl@0
|
517 |
CleanupStack::PopAndDestroy(1);
|
sl@0
|
518 |
}
|
sl@0
|
519 |
|
sl@0
|
520 |
// Free buffers
|
sl@0
|
521 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
522 |
|
sl@0
|
523 |
return verdict;
|
sl@0
|
524 |
}
|
sl@0
|
525 |
|
sl@0
|
526 |
/*
|
sl@0
|
527 |
* Helper function that deflates some input data as a gzip stream with a specified header
|
sl@0
|
528 |
* and then inflates the compressed data.
|
sl@0
|
529 |
*/
|
sl@0
|
530 |
TVerdict CTestZlib::DefInfGZipSpecifiedHeaderL(TBool aIgnoreHeader, TBool aAutoDetectHeader)
|
sl@0
|
531 |
{
|
sl@0
|
532 |
gz_header specifiedGZipHeader;
|
sl@0
|
533 |
|
sl@0
|
534 |
Bytef extra[] = "12345";
|
sl@0
|
535 |
Bytef name[] = "TestDefInfGZipSpecifiedHeaderManual\0";
|
sl@0
|
536 |
Bytef comment[] = "This is a test comment.\0";
|
sl@0
|
537 |
|
sl@0
|
538 |
// gz_header user specified values. Set the specifiedGZipHeader ready for deflateSetHeader
|
sl@0
|
539 |
specifiedGZipHeader.text = 1;
|
sl@0
|
540 |
specifiedGZipHeader.time = 101;
|
sl@0
|
541 |
specifiedGZipHeader.xflags = 0; // Set so that the value can be compared to the value in the header read from the deflated data
|
sl@0
|
542 |
specifiedGZipHeader.os = 1; // Amiga
|
sl@0
|
543 |
specifiedGZipHeader.extra = extra;
|
sl@0
|
544 |
specifiedGZipHeader.extra_len = TEST_MID_MEM_LEVEL;
|
sl@0
|
545 |
specifiedGZipHeader.extra_max = specifiedGZipHeader.extra_len + 10; // Add extra 10 to check readGZipHeader.extra_len is set properly
|
sl@0
|
546 |
specifiedGZipHeader.name = name;
|
sl@0
|
547 |
specifiedGZipHeader.name_max = strlen((char *)name) + 1;
|
sl@0
|
548 |
specifiedGZipHeader.comment = comment;
|
sl@0
|
549 |
specifiedGZipHeader.comm_max = strlen((char *)comment) + 1;
|
sl@0
|
550 |
specifiedGZipHeader.hcrc = 0;
|
sl@0
|
551 |
specifiedGZipHeader.done = 1; // Finished reading header. Set so that the value can be compared to the value in the header read from the deflated data
|
sl@0
|
552 |
|
sl@0
|
553 |
return DefInfGZipHeaderL(aIgnoreHeader, aAutoDetectHeader, &specifiedGZipHeader);
|
sl@0
|
554 |
}
|
sl@0
|
555 |
|
sl@0
|
556 |
/**
|
sl@0
|
557 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4259
|
sl@0
|
558 |
@SYMTestCaseDesc To ensure deflation works after tuning the deflate stream using
|
sl@0
|
559 |
deflateTune().
|
sl@0
|
560 |
@SYMTestPriority Medium
|
sl@0
|
561 |
@SYMTestActions 1. Create a stream and initialise it.
|
sl@0
|
562 |
2. Call deflateTune() passing it the specified parameters.
|
sl@0
|
563 |
3. Check the state of the stream to make sure that the values
|
sl@0
|
564 |
are identical to the specified parameters. Also check that
|
sl@0
|
565 |
Z_OK is returned.
|
sl@0
|
566 |
4. Deflate the input and cleanup using deflateEnd(), checking
|
sl@0
|
567 |
Z_OK is returned.
|
sl@0
|
568 |
|
sl@0
|
569 |
Note: The test should be repeated for deflateInit() parameter values:
|
sl@0
|
570 |
• 3 and 4 for level
|
sl@0
|
571 |
|
sl@0
|
572 |
and for deflateTune() parameter values:
|
sl@0
|
573 |
• 0 and a high value for good_length
|
sl@0
|
574 |
• 0 and a high value for max_lazy
|
sl@0
|
575 |
• 0 and a high value for nice_length
|
sl@0
|
576 |
• 0 and a high value for max_chain
|
sl@0
|
577 |
Appropriate high values can be picked based on the global
|
sl@0
|
578 |
configuration_table array in deflate.cpp.
|
sl@0
|
579 |
@SYMTestExpectedResults deflateTune() should return Z_OK and the input should be compressed.
|
sl@0
|
580 |
@SYMDEF REQ7362
|
sl@0
|
581 |
*/
|
sl@0
|
582 |
TVerdict CTestZlib::TestDeflateTuneL()
|
sl@0
|
583 |
{
|
sl@0
|
584 |
int err = Z_OK;
|
sl@0
|
585 |
TBool ret;
|
sl@0
|
586 |
|
sl@0
|
587 |
// Streams
|
sl@0
|
588 |
z_stream deflateStream;
|
sl@0
|
589 |
|
sl@0
|
590 |
// Buffers
|
sl@0
|
591 |
const char inputData[] = "This is a piece of data to compress.\0";
|
sl@0
|
592 |
uLong inputDataLength = (uLong)strlen(inputData) + 1;
|
sl@0
|
593 |
Byte *compressedDataBuffer;
|
sl@0
|
594 |
|
sl@0
|
595 |
// deflateInit arguments
|
sl@0
|
596 |
uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
|
sl@0
|
597 |
int level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
598 |
int goodLength = 0;
|
sl@0
|
599 |
int maxLazy = 0;
|
sl@0
|
600 |
int niceLength = 0;
|
sl@0
|
601 |
int maxChain = 0;
|
sl@0
|
602 |
|
sl@0
|
603 |
// Allocate memory for output buffer
|
sl@0
|
604 |
compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
605 |
CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for output buffer.");
|
sl@0
|
606 |
CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
|
sl@0
|
607 |
|
sl@0
|
608 |
// Read in the values for deflate tune from the ini file
|
sl@0
|
609 |
ret = GetIntFromConfig(ConfigSection(), KParam1, goodLength);
|
sl@0
|
610 |
CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param1 from ini file");
|
sl@0
|
611 |
|
sl@0
|
612 |
ret = GetIntFromConfig(ConfigSection(), KParam2, maxLazy);
|
sl@0
|
613 |
CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param2 from ini file");
|
sl@0
|
614 |
|
sl@0
|
615 |
ret = GetIntFromConfig(ConfigSection(), KParam3, niceLength);
|
sl@0
|
616 |
CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param3 from ini file");
|
sl@0
|
617 |
|
sl@0
|
618 |
ret = GetIntFromConfig(ConfigSection(), KParam4, maxChain);
|
sl@0
|
619 |
CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param4 from ini file");
|
sl@0
|
620 |
|
sl@0
|
621 |
// Initialise the stream
|
sl@0
|
622 |
this->DeflateInitL(deflateStream, level);
|
sl@0
|
623 |
CleanupStack::PushL(TCleanupItem(DeflateEnd, &deflateStream));
|
sl@0
|
624 |
|
sl@0
|
625 |
// Tune the deflate stream
|
sl@0
|
626 |
err = deflateTune(&deflateStream, goodLength, maxLazy, niceLength, maxChain);
|
sl@0
|
627 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflateTune error: %d", err);
|
sl@0
|
628 |
|
sl@0
|
629 |
// Check deflateTune has set the streams state values correctly
|
sl@0
|
630 |
/*
|
sl@0
|
631 |
internal_state *s = deflateStream.state;
|
sl@0
|
632 |
CHECK_CONDITION0L(s->good_match != goodLength || s->max_lazy_match != maxLazy || s->nice_match != niceLength || s->max_chain_length != maxChain, KErrGeneral, "deflateTune did not set the stream->state values correctly");
|
sl@0
|
633 |
*/
|
sl@0
|
634 |
|
sl@0
|
635 |
err = this->DeflateCompress(deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
|
sl@0
|
636 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflate error: %d", err);
|
sl@0
|
637 |
|
sl@0
|
638 |
// Clean up the deflate stream
|
sl@0
|
639 |
err = deflateEnd(&deflateStream);
|
sl@0
|
640 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflateEnd error: %d", err);
|
sl@0
|
641 |
CleanupStack::Pop(1);
|
sl@0
|
642 |
|
sl@0
|
643 |
// Free buffer
|
sl@0
|
644 |
CleanupStack::PopAndDestroy(1);
|
sl@0
|
645 |
|
sl@0
|
646 |
return EPass;
|
sl@0
|
647 |
}
|
sl@0
|
648 |
|
sl@0
|
649 |
/**
|
sl@0
|
650 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4260
|
sl@0
|
651 |
@SYMTestCaseDesc Check deflateTune() fails when given an invalid stream.
|
sl@0
|
652 |
@SYMTestPriority Medium
|
sl@0
|
653 |
@SYMTestActions 1. Create a stream and initialise it.
|
sl@0
|
654 |
2. Call deflateTune() passing it parameter values:
|
sl@0
|
655 |
a. NULL for the stream argument
|
sl@0
|
656 |
b. a stream whose state is NULL for the stream argument
|
sl@0
|
657 |
@SYMTestExpectedResults deflateTune() fails returning Z_STREAM_ERROR in both cases.
|
sl@0
|
658 |
@SYMDEF REQ7362
|
sl@0
|
659 |
*/
|
sl@0
|
660 |
|
sl@0
|
661 |
TVerdict CTestZlib::TestDeflateTuneFailL()
|
sl@0
|
662 |
{
|
sl@0
|
663 |
int err = Z_OK;
|
sl@0
|
664 |
|
sl@0
|
665 |
// Streams
|
sl@0
|
666 |
z_stream deflateStream;
|
sl@0
|
667 |
|
sl@0
|
668 |
// deflateInit2 arguments
|
sl@0
|
669 |
int level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
670 |
|
sl@0
|
671 |
// Initialise the stream
|
sl@0
|
672 |
this->DeflateInitL(deflateStream, level);
|
sl@0
|
673 |
CleanupStack::PushL(TCleanupItem(DeflateEnd, &deflateStream));
|
sl@0
|
674 |
|
sl@0
|
675 |
// Try tuning a NULL deflate stream
|
sl@0
|
676 |
err = deflateTune(NULL, 0, 0, 0, 0);
|
sl@0
|
677 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflateTune on a NULL stream returned an unexpected value: %d", err);
|
sl@0
|
678 |
|
sl@0
|
679 |
// Keep a pointer to the streams state so we can clean up properly with deflateEnd()
|
sl@0
|
680 |
internal_state *deflateState = deflateStream.state;
|
sl@0
|
681 |
|
sl@0
|
682 |
// Try tuning a deflate stream that has a NULL state
|
sl@0
|
683 |
deflateStream.state = NULL;
|
sl@0
|
684 |
err = deflateTune(&deflateStream, 0, 0, 0, 0);
|
sl@0
|
685 |
deflateStream.state = deflateState;
|
sl@0
|
686 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflateTune on a stream with a NULL state returned an unexpected value: %d", err);
|
sl@0
|
687 |
|
sl@0
|
688 |
// Clean up the deflate stream
|
sl@0
|
689 |
err = deflateEnd(&deflateStream);
|
sl@0
|
690 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflateEnd error: %d", err);
|
sl@0
|
691 |
CleanupStack::Pop(1);
|
sl@0
|
692 |
|
sl@0
|
693 |
return EPass;
|
sl@0
|
694 |
}
|
sl@0
|
695 |
|
sl@0
|
696 |
/**
|
sl@0
|
697 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4261
|
sl@0
|
698 |
@SYMTestCaseDesc Check input can be compressed and decompressed with default gzip
|
sl@0
|
699 |
header not being read.
|
sl@0
|
700 |
@SYMTestPriority High
|
sl@0
|
701 |
@SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
|
sl@0
|
702 |
adding 16 to windowBits.
|
sl@0
|
703 |
2. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
704 |
3. Create an inflate stream and initialise it using inflateInit2(),
|
sl@0
|
705 |
adding 16 to windowBits.
|
sl@0
|
706 |
4. Inflate the input and cleanup using inflateEnd().
|
sl@0
|
707 |
@SYMTestExpectedResults The data should be compressed with deflateEnd() returning Z_OK and
|
sl@0
|
708 |
decompressed with inflateEnd() returning Z_OK. There should be no
|
sl@0
|
709 |
header information stored.
|
sl@0
|
710 |
@SYMDEF REQ7362
|
sl@0
|
711 |
*/
|
sl@0
|
712 |
|
sl@0
|
713 |
TVerdict CTestZlib::TestDefInfGZipDefaultHeaderIgnoreL()
|
sl@0
|
714 |
{
|
sl@0
|
715 |
return DefInfGZipHeaderL(true, false, NULL);
|
sl@0
|
716 |
}
|
sl@0
|
717 |
|
sl@0
|
718 |
/**
|
sl@0
|
719 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4262
|
sl@0
|
720 |
@SYMTestCaseDesc Check input can be compressed and decompressed with default gzip
|
sl@0
|
721 |
header being read using automatic header detection.
|
sl@0
|
722 |
@SYMTestPriority High
|
sl@0
|
723 |
@SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
|
sl@0
|
724 |
adding 16 to windowBits.
|
sl@0
|
725 |
2. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
726 |
3. Create an inflate stream and initialise it using inflateInit2(),
|
sl@0
|
727 |
adding 32 to windowBits.
|
sl@0
|
728 |
4. Use inflateGetHeader() to get the default header information
|
sl@0
|
729 |
and make sure the gzip header information is set correctly.
|
sl@0
|
730 |
5. Inflate the input and cleanup using inflateEnd().
|
sl@0
|
731 |
@SYMTestExpectedResults The data should be compressed with deflateEnd() returning Z_OK and
|
sl@0
|
732 |
decompressed with inflateEnd() returning Z_OK. There should be
|
sl@0
|
733 |
correct header information stored.
|
sl@0
|
734 |
@SYMDEF REQ7362
|
sl@0
|
735 |
*/
|
sl@0
|
736 |
|
sl@0
|
737 |
TVerdict CTestZlib::TestDefInfGZipDefaultHeaderAutoL()
|
sl@0
|
738 |
{
|
sl@0
|
739 |
return DefInfGZipHeaderL(false, true, NULL);
|
sl@0
|
740 |
}
|
sl@0
|
741 |
|
sl@0
|
742 |
/**
|
sl@0
|
743 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4263
|
sl@0
|
744 |
@SYMTestCaseDesc Check input can be compressed and decompressed with specified gzip
|
sl@0
|
745 |
header being read.
|
sl@0
|
746 |
@SYMTestPriority High
|
sl@0
|
747 |
@SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
|
sl@0
|
748 |
adding 16 to windowBits.
|
sl@0
|
749 |
2. Use deflateSetHeader() to specify header information and check
|
sl@0
|
750 |
that the gzip header information is set correctly.
|
sl@0
|
751 |
3. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
752 |
4. Create an inflate stream and initialise it using inflateInit2(),
|
sl@0
|
753 |
adding 16 to windowBits.
|
sl@0
|
754 |
5. Use inflateGetHeader() to get the header information and make
|
sl@0
|
755 |
sure that it matches the header information originally entered.
|
sl@0
|
756 |
6. Inflate the input and cleanup using inflateEnd().
|
sl@0
|
757 |
@SYMTestExpectedResults The data should be compressed with deflateEnd() returning Z_OK and
|
sl@0
|
758 |
the header details being set correctly. The data should also be
|
sl@0
|
759 |
decompressed with inflateEnd() returning Z_OK and the header details
|
sl@0
|
760 |
matching the original header information. There should also be header
|
sl@0
|
761 |
information stored.
|
sl@0
|
762 |
@SYMDEF REQ7362
|
sl@0
|
763 |
*/
|
sl@0
|
764 |
|
sl@0
|
765 |
TVerdict CTestZlib::TestDefInfGZipSpecifiedHeaderManualL()
|
sl@0
|
766 |
{
|
sl@0
|
767 |
return DefInfGZipSpecifiedHeaderL(false, false);
|
sl@0
|
768 |
}
|
sl@0
|
769 |
|
sl@0
|
770 |
/**
|
sl@0
|
771 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4264
|
sl@0
|
772 |
@SYMTestCaseDesc Check input can be compressed and decompressed with specified gzip
|
sl@0
|
773 |
header being read using automatic header detection.
|
sl@0
|
774 |
@SYMTestPriority High
|
sl@0
|
775 |
@SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
|
sl@0
|
776 |
adding 16 to windowBits.
|
sl@0
|
777 |
2. Use deflateSetHeader() to specify header information and check
|
sl@0
|
778 |
that the gzip header information is set correctly.
|
sl@0
|
779 |
3. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
780 |
4. Create an inflate stream and initialise it using inflateInit2(),
|
sl@0
|
781 |
adding 32 to windowBits.
|
sl@0
|
782 |
5. Use inflateGetHeader() to get the header information and make
|
sl@0
|
783 |
sure that it matches the header information originally entered.
|
sl@0
|
784 |
6. Inflate the input and cleanup using inflateEnd().
|
sl@0
|
785 |
@SYMTestExpectedResults The data should be compressed with deflateEnd() returning Z_OK and
|
sl@0
|
786 |
the header details being set correctly. The data should also be
|
sl@0
|
787 |
decompressed with inflateEnd() returning Z_OK and the header details
|
sl@0
|
788 |
matching the original header information. There should also be header
|
sl@0
|
789 |
information stored.
|
sl@0
|
790 |
@SYMDEF REQ7362
|
sl@0
|
791 |
*/
|
sl@0
|
792 |
|
sl@0
|
793 |
TVerdict CTestZlib::TestDefInfGZipSpecifiedHeaderAutoL()
|
sl@0
|
794 |
{
|
sl@0
|
795 |
return DefInfGZipSpecifiedHeaderL(false, true);
|
sl@0
|
796 |
}
|
sl@0
|
797 |
|
sl@0
|
798 |
/**
|
sl@0
|
799 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4265
|
sl@0
|
800 |
@SYMTestCaseDesc Check input can be compressed and decompressed with zlib header
|
sl@0
|
801 |
using automatic header detection.
|
sl@0
|
802 |
@SYMTestPriority High
|
sl@0
|
803 |
@SYMTestActions 1. Create a deflate stream and initialise it.
|
sl@0
|
804 |
2. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
805 |
3. Create an inflate stream and initialise it using inflateInit2(),
|
sl@0
|
806 |
adding 32 to windowBits.
|
sl@0
|
807 |
4. Inflate the input and cleanup using inflateEnd().
|
sl@0
|
808 |
@SYMTestExpectedResults The data should be compressed with deflateEnd() returning Z_OK
|
sl@0
|
809 |
and decompressed with inflateEnd returning Z_OK.
|
sl@0
|
810 |
@SYMDEF REQ7362
|
sl@0
|
811 |
*/
|
sl@0
|
812 |
|
sl@0
|
813 |
TVerdict CTestZlib::TestDefInfZlibHeaderAutoL()
|
sl@0
|
814 |
{
|
sl@0
|
815 |
int err = Z_OK;
|
sl@0
|
816 |
|
sl@0
|
817 |
// Streams
|
sl@0
|
818 |
z_stream deflateStream;
|
sl@0
|
819 |
z_stream inflateStream;
|
sl@0
|
820 |
|
sl@0
|
821 |
// Stream settings
|
sl@0
|
822 |
StreamSettings streamSettings;
|
sl@0
|
823 |
streamSettings.deflateInit2 = false;
|
sl@0
|
824 |
streamSettings.level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
825 |
streamSettings.inflateWindowBits = MAX_WBITS + TEST_AUTO_HEADER_DETECTION;
|
sl@0
|
826 |
|
sl@0
|
827 |
// Buffers
|
sl@0
|
828 |
const char inputData[] = "This is a piece of data to compress.\0"; // data to compress
|
sl@0
|
829 |
uLong inputDataLength = (uLong)strlen(inputData) + 1;
|
sl@0
|
830 |
Byte *compressedDataBuffer = NULL;
|
sl@0
|
831 |
uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
|
sl@0
|
832 |
Byte *decompressedDataBuffer = NULL;
|
sl@0
|
833 |
uLong decompressedDataBufferLength = inputDataLength;
|
sl@0
|
834 |
|
sl@0
|
835 |
// Allocate memory for buffers
|
sl@0
|
836 |
compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
837 |
CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
|
sl@0
|
838 |
CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
|
sl@0
|
839 |
|
sl@0
|
840 |
decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
|
sl@0
|
841 |
CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
|
sl@0
|
842 |
CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
|
sl@0
|
843 |
|
sl@0
|
844 |
this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
|
sl@0
|
845 |
|
sl@0
|
846 |
// Initialise the inflateStream
|
sl@0
|
847 |
this->InflateInit2L(inflateStream, streamSettings.inflateWindowBits);
|
sl@0
|
848 |
CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
|
sl@0
|
849 |
|
sl@0
|
850 |
err = this->InflateDecompress(inflateStream, compressedDataBuffer, deflateStream.total_out, decompressedDataBuffer, decompressedDataBufferLength);
|
sl@0
|
851 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflate error: %d", err);
|
sl@0
|
852 |
|
sl@0
|
853 |
// Clean up the inflateStream
|
sl@0
|
854 |
err = inflateEnd(&inflateStream);
|
sl@0
|
855 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateEnd error: %d", err);
|
sl@0
|
856 |
CleanupStack::Pop(1);
|
sl@0
|
857 |
|
sl@0
|
858 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
859 |
return EPass;
|
sl@0
|
860 |
}
|
sl@0
|
861 |
|
sl@0
|
862 |
/**
|
sl@0
|
863 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4266
|
sl@0
|
864 |
@SYMTestCaseDesc Check deflateSetHeader() fails when given an invalid stream.
|
sl@0
|
865 |
@SYMTestPriority High
|
sl@0
|
866 |
@SYMTestActions 1. Create a stream and initialise it using deflateInit2(), adding
|
sl@0
|
867 |
16 to windowBits.
|
sl@0
|
868 |
2. Call deflateSetHeader() passing it parameter values:
|
sl@0
|
869 |
a. NULL for the stream argument
|
sl@0
|
870 |
b. a stream whose state is set to NULL for the stream argument
|
sl@0
|
871 |
c. a zlib stream for the stream argument
|
sl@0
|
872 |
d. a raw stream for the stream argument
|
sl@0
|
873 |
@SYMTestExpectedResults deflateSetHeader() fails returning Z_STREAM_ERROR in all four cases.
|
sl@0
|
874 |
@SYMDEF REQ7362
|
sl@0
|
875 |
*/
|
sl@0
|
876 |
|
sl@0
|
877 |
TVerdict CTestZlib::TestDeflateSetHeaderFailsL()
|
sl@0
|
878 |
{
|
sl@0
|
879 |
int err;
|
sl@0
|
880 |
|
sl@0
|
881 |
// Streams
|
sl@0
|
882 |
z_stream gZipDeflateStream;
|
sl@0
|
883 |
z_stream zLibDeflateStream;
|
sl@0
|
884 |
z_stream rawDeflateStream;
|
sl@0
|
885 |
|
sl@0
|
886 |
// GZip headers
|
sl@0
|
887 |
gz_header specifiedGZipHeader;
|
sl@0
|
888 |
|
sl@0
|
889 |
// Buffers
|
sl@0
|
890 |
const char inputData[] = "This is a piece of data to compress.\0";
|
sl@0
|
891 |
uLong inputDataLength = (uLong)strlen(inputData) + 1;
|
sl@0
|
892 |
Byte *compressedDataBuffer;
|
sl@0
|
893 |
uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
|
sl@0
|
894 |
|
sl@0
|
895 |
// deflateInit2 arguments
|
sl@0
|
896 |
int level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
897 |
int method = Z_DEFLATED;
|
sl@0
|
898 |
int gZipDeflateWindowBits = MAX_WBITS + TEST_GZIP_HEADER;
|
sl@0
|
899 |
int memLevel = TEST_MID_MEM_LEVEL;
|
sl@0
|
900 |
int strategy = Z_DEFAULT_STRATEGY;
|
sl@0
|
901 |
|
sl@0
|
902 |
// GZip header user specified values
|
sl@0
|
903 |
Bytef extra[] = "12345";
|
sl@0
|
904 |
Bytef name[] = "TestDefInfGZipSpecifiedHeaderManual\0";
|
sl@0
|
905 |
Bytef comment[] = "This is a test comment.\0";
|
sl@0
|
906 |
|
sl@0
|
907 |
// Set the specifiedGZipHeader ready for deflateSetHeader
|
sl@0
|
908 |
specifiedGZipHeader.text = 1;
|
sl@0
|
909 |
specifiedGZipHeader.time = 101;
|
sl@0
|
910 |
specifiedGZipHeader.os = 1;
|
sl@0
|
911 |
specifiedGZipHeader.extra = extra;
|
sl@0
|
912 |
specifiedGZipHeader.extra_len = 5;
|
sl@0
|
913 |
specifiedGZipHeader.extra_max = specifiedGZipHeader.extra_len + 10; // Add extra 10 to check readGZipHeader.extra_len is set properly
|
sl@0
|
914 |
specifiedGZipHeader.name = name;
|
sl@0
|
915 |
specifiedGZipHeader.name_max = strlen((char *)name) + 1;
|
sl@0
|
916 |
specifiedGZipHeader.comment = comment;
|
sl@0
|
917 |
specifiedGZipHeader.comm_max = strlen((char *)comment) + 1;
|
sl@0
|
918 |
specifiedGZipHeader.hcrc = 0;
|
sl@0
|
919 |
|
sl@0
|
920 |
// Allocate memory for buffers
|
sl@0
|
921 |
compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
922 |
CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
|
sl@0
|
923 |
CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
|
sl@0
|
924 |
|
sl@0
|
925 |
// Initialise the deflate streams
|
sl@0
|
926 |
this->DeflateInit2L(gZipDeflateStream, level, method, gZipDeflateWindowBits, memLevel, strategy);
|
sl@0
|
927 |
CleanupStack::PushL(TCleanupItem(DeflateEnd, &gZipDeflateStream));
|
sl@0
|
928 |
|
sl@0
|
929 |
this->DeflateInitL(zLibDeflateStream, level);
|
sl@0
|
930 |
CleanupStack::PushL(TCleanupItem(DeflateEnd, &zLibDeflateStream));
|
sl@0
|
931 |
|
sl@0
|
932 |
this->DeflateInit2L(rawDeflateStream, level, method, -MAX_WBITS, memLevel, strategy);
|
sl@0
|
933 |
CleanupStack::PushL(TCleanupItem(DeflateEnd, &rawDeflateStream));
|
sl@0
|
934 |
|
sl@0
|
935 |
// Try setting a NULL streams header
|
sl@0
|
936 |
err = deflateSetHeader(NULL, &specifiedGZipHeader);
|
sl@0
|
937 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflateSetHeader on a NULL stream returned an unexpected value: %d", err);
|
sl@0
|
938 |
|
sl@0
|
939 |
// Try setting the header for a deflate stream that has a NULL state
|
sl@0
|
940 |
// we must keep a pointer to the streams state so we can clean up properly with deflateEnd
|
sl@0
|
941 |
internal_state *deflateState = gZipDeflateStream.state;
|
sl@0
|
942 |
gZipDeflateStream.state = NULL;
|
sl@0
|
943 |
|
sl@0
|
944 |
err = deflateSetHeader(&gZipDeflateStream, &specifiedGZipHeader);
|
sl@0
|
945 |
|
sl@0
|
946 |
gZipDeflateStream.state = deflateState;
|
sl@0
|
947 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflateSetHeader on a stream with a NULL state returned an unexpected value: %d", err);
|
sl@0
|
948 |
|
sl@0
|
949 |
// Try setting a header for a zlib stream
|
sl@0
|
950 |
err = deflateSetHeader(&zLibDeflateStream, &specifiedGZipHeader);
|
sl@0
|
951 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflateSetHeader on a zlib stream returned an unexpected value: %d", err);
|
sl@0
|
952 |
|
sl@0
|
953 |
// Try setting a header for a raw stream
|
sl@0
|
954 |
err = deflateSetHeader(&rawDeflateStream, &specifiedGZipHeader);
|
sl@0
|
955 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflateSetHeader on a raw stream returned an unexpected value: %d", err);
|
sl@0
|
956 |
|
sl@0
|
957 |
// Clean up the deflate streams
|
sl@0
|
958 |
err = deflateEnd(&gZipDeflateStream);
|
sl@0
|
959 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "gZipDeflateStream - deflateEnd error: %d", err);
|
sl@0
|
960 |
|
sl@0
|
961 |
err = deflateEnd(&zLibDeflateStream);
|
sl@0
|
962 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "zLibDeflateStream - deflateEnd error: %d", err);
|
sl@0
|
963 |
|
sl@0
|
964 |
// deflateInit2() leaves a raw stream in a busy state. This results in deflateEnd()
|
sl@0
|
965 |
// returning a Z_DATA_ERROR, unless deflate() has been called on the stream.
|
sl@0
|
966 |
err = deflateEnd(&rawDeflateStream);
|
sl@0
|
967 |
CHECK_CONDITION1L(err != Z_DATA_ERROR, KErrGeneral, "rawDeflateStream - deflateEnd error: %d", err);
|
sl@0
|
968 |
|
sl@0
|
969 |
CleanupStack::Pop(3);
|
sl@0
|
970 |
CleanupStack::PopAndDestroy(1);
|
sl@0
|
971 |
return EPass;
|
sl@0
|
972 |
}
|
sl@0
|
973 |
|
sl@0
|
974 |
/**
|
sl@0
|
975 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4267
|
sl@0
|
976 |
@SYMTestCaseDesc Check inflateGetHeader() fails when given an invalid gzip stream.
|
sl@0
|
977 |
@SYMTestPriority High
|
sl@0
|
978 |
@SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(), adding 16 to windowBits.
|
sl@0
|
979 |
2. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
980 |
3. Create an inflate stream and initialise it using inflateInit2(), adding 16 to windowBits.
|
sl@0
|
981 |
4. Call inflateGetHeader() passing it parameter values:
|
sl@0
|
982 |
e. NULL for the stream argument
|
sl@0
|
983 |
f. a stream whose state is set to NULL for the stream argument
|
sl@0
|
984 |
g. a zlib stream for the stream argument
|
sl@0
|
985 |
h. a raw stream for the stream argument
|
sl@0
|
986 |
@SYMTestExpectedResults inflateGetHeader() should fail returning Z_STREAM_ERROR for the
|
sl@0
|
987 |
first 2 cases and Z_DATA_ERROR for the second 2 case.
|
sl@0
|
988 |
@SYMDEF REQ7362
|
sl@0
|
989 |
*/
|
sl@0
|
990 |
|
sl@0
|
991 |
TVerdict CTestZlib::TestInflateGetHeaderFailsL()
|
sl@0
|
992 |
{
|
sl@0
|
993 |
int err = Z_OK;
|
sl@0
|
994 |
|
sl@0
|
995 |
// Streams
|
sl@0
|
996 |
z_stream gZipDeflateStream;
|
sl@0
|
997 |
z_stream zLibDeflateStream;
|
sl@0
|
998 |
z_stream rawDeflateStream;
|
sl@0
|
999 |
z_stream gZipInflateStream;
|
sl@0
|
1000 |
z_stream zLibInflateStream;
|
sl@0
|
1001 |
z_stream rawInflateStream;
|
sl@0
|
1002 |
|
sl@0
|
1003 |
// GZip headers
|
sl@0
|
1004 |
gz_header gZipHeader;
|
sl@0
|
1005 |
|
sl@0
|
1006 |
// Buffers
|
sl@0
|
1007 |
const char inputData[] = "This is a piece of data to compress.\0";
|
sl@0
|
1008 |
uLong inputDataLength = (uLong)strlen(inputData) + 1;
|
sl@0
|
1009 |
Byte *gZipCompressedDataBuffer = NULL;
|
sl@0
|
1010 |
Byte *zLibCompressedDataBuffer = NULL;
|
sl@0
|
1011 |
Byte *rawCompressedDataBuffer = NULL;
|
sl@0
|
1012 |
uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
|
sl@0
|
1013 |
|
sl@0
|
1014 |
// deflateInit2 and inflateInit2 arguments
|
sl@0
|
1015 |
StreamSettings gZipStreamSettings;
|
sl@0
|
1016 |
gZipStreamSettings.deflateInit2 = true;
|
sl@0
|
1017 |
gZipStreamSettings.level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
1018 |
gZipStreamSettings.method = Z_DEFLATED;
|
sl@0
|
1019 |
gZipStreamSettings.deflateWindowBits = MAX_WBITS + TEST_GZIP_HEADER;
|
sl@0
|
1020 |
gZipStreamSettings.inflateWindowBits = MAX_WBITS + TEST_GZIP_HEADER;
|
sl@0
|
1021 |
gZipStreamSettings.memLevel = TEST_MID_MEM_LEVEL;
|
sl@0
|
1022 |
gZipStreamSettings.strategy = Z_DEFAULT_STRATEGY;
|
sl@0
|
1023 |
|
sl@0
|
1024 |
StreamSettings zLibStreamSettings;
|
sl@0
|
1025 |
zLibStreamSettings.deflateInit2 = false;
|
sl@0
|
1026 |
zLibStreamSettings.level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
1027 |
|
sl@0
|
1028 |
StreamSettings rawStreamSettings;
|
sl@0
|
1029 |
rawStreamSettings.deflateInit2 = true;
|
sl@0
|
1030 |
rawStreamSettings.level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
1031 |
rawStreamSettings.method = Z_DEFLATED;
|
sl@0
|
1032 |
rawStreamSettings.deflateWindowBits = -MAX_WBITS;
|
sl@0
|
1033 |
rawStreamSettings.inflateWindowBits = -MAX_WBITS;
|
sl@0
|
1034 |
rawStreamSettings.memLevel = TEST_MID_MEM_LEVEL;
|
sl@0
|
1035 |
rawStreamSettings.strategy = Z_DEFAULT_STRATEGY;
|
sl@0
|
1036 |
|
sl@0
|
1037 |
// Allocate memory for buffers
|
sl@0
|
1038 |
gZipCompressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1039 |
CHECK_CONDITION0L(gZipCompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for gZipCompressedDataBuffer.");
|
sl@0
|
1040 |
CleanupStack::PushL(TCleanupItem(User::Free, gZipCompressedDataBuffer));
|
sl@0
|
1041 |
|
sl@0
|
1042 |
zLibCompressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1043 |
CHECK_CONDITION0L(zLibCompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for zLibCompressedDataBuffer.");
|
sl@0
|
1044 |
CleanupStack::PushL(TCleanupItem(User::Free, zLibCompressedDataBuffer));
|
sl@0
|
1045 |
|
sl@0
|
1046 |
rawCompressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1047 |
CHECK_CONDITION0L(rawCompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for rawCompressedDataBuffer.");
|
sl@0
|
1048 |
CleanupStack::PushL(TCleanupItem(User::Free, rawCompressedDataBuffer));
|
sl@0
|
1049 |
|
sl@0
|
1050 |
// Compress data
|
sl@0
|
1051 |
INFO_PRINTF1(_L("Compress gzip:"));
|
sl@0
|
1052 |
this->CompressDataL(gZipStreamSettings, gZipDeflateStream, (Byte *)inputData, inputDataLength, gZipCompressedDataBuffer, compressedDataBufferLength);
|
sl@0
|
1053 |
INFO_PRINTF1(_L("Compress zlib:"));
|
sl@0
|
1054 |
this->CompressDataL(zLibStreamSettings, zLibDeflateStream, (Byte *)inputData, inputDataLength, zLibCompressedDataBuffer, compressedDataBufferLength);
|
sl@0
|
1055 |
INFO_PRINTF1(_L("Compress raw:"));
|
sl@0
|
1056 |
this->CompressDataL(rawStreamSettings, rawDeflateStream, (Byte *)inputData, inputDataLength, rawCompressedDataBuffer, compressedDataBufferLength);
|
sl@0
|
1057 |
|
sl@0
|
1058 |
// Initialise the inflateStreams
|
sl@0
|
1059 |
INFO_PRINTF1(_L("gZipInflateStream:"));
|
sl@0
|
1060 |
this->InflateInit2L(gZipInflateStream, gZipStreamSettings.inflateWindowBits);
|
sl@0
|
1061 |
CleanupStack::PushL(TCleanupItem(InflateEnd, &gZipInflateStream));
|
sl@0
|
1062 |
|
sl@0
|
1063 |
INFO_PRINTF1(_L("zLibInflateStream:"));
|
sl@0
|
1064 |
this->InflateInitL(zLibInflateStream);
|
sl@0
|
1065 |
CleanupStack::PushL(TCleanupItem(InflateEnd, &zLibInflateStream));
|
sl@0
|
1066 |
|
sl@0
|
1067 |
INFO_PRINTF1(_L("rawInflateStream:"));
|
sl@0
|
1068 |
this->InflateInit2L(rawInflateStream, rawStreamSettings.inflateWindowBits);
|
sl@0
|
1069 |
CleanupStack::PushL(TCleanupItem(InflateEnd, &rawInflateStream));
|
sl@0
|
1070 |
|
sl@0
|
1071 |
// Try and get header information from a NULL stream
|
sl@0
|
1072 |
err = inflateGetHeader(NULL, &gZipHeader);
|
sl@0
|
1073 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateGetHeader on a NULL stream returned an unexpected value: %d", err);
|
sl@0
|
1074 |
|
sl@0
|
1075 |
// Try getting the header for a deflate stream that has a NULL state
|
sl@0
|
1076 |
// we must keep a pointer to the streams state so we can clean up properly with deflateEnd
|
sl@0
|
1077 |
internal_state *deflateState = gZipDeflateStream.state;
|
sl@0
|
1078 |
gZipDeflateStream.state = NULL;
|
sl@0
|
1079 |
|
sl@0
|
1080 |
err = inflateGetHeader(&gZipDeflateStream, &gZipHeader);
|
sl@0
|
1081 |
|
sl@0
|
1082 |
gZipDeflateStream.state = deflateState;
|
sl@0
|
1083 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateGetHeader on a stream with a NULL state returned an unexpected value: %d", err);
|
sl@0
|
1084 |
|
sl@0
|
1085 |
// Try and get header information from a zlib stream
|
sl@0
|
1086 |
err = inflateGetHeader(&zLibDeflateStream, &gZipHeader);
|
sl@0
|
1087 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateGetHeader on a zlib stream returned an unexpected value: %d", err);
|
sl@0
|
1088 |
|
sl@0
|
1089 |
// Try and get header information from a raw stream
|
sl@0
|
1090 |
err = inflateGetHeader(&rawDeflateStream, &gZipHeader);
|
sl@0
|
1091 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateGetHeader on a raw stream returned an unexpected value: %d", err);
|
sl@0
|
1092 |
|
sl@0
|
1093 |
// Clean up the inflateStreams
|
sl@0
|
1094 |
err = inflateEnd(&gZipInflateStream);
|
sl@0
|
1095 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "gZipInflateStream - inflateEnd error: %d", err);
|
sl@0
|
1096 |
|
sl@0
|
1097 |
err = inflateEnd(&zLibInflateStream);
|
sl@0
|
1098 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "zLibInflateStream - inflateEnd error: %d", err);
|
sl@0
|
1099 |
|
sl@0
|
1100 |
err = inflateEnd(&rawInflateStream);
|
sl@0
|
1101 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "rawInflateStream - inflateEnd error: %d", err);
|
sl@0
|
1102 |
|
sl@0
|
1103 |
CleanupStack::Pop(3);
|
sl@0
|
1104 |
CleanupStack::PopAndDestroy(3);
|
sl@0
|
1105 |
return EPass;
|
sl@0
|
1106 |
}
|
sl@0
|
1107 |
|
sl@0
|
1108 |
/**
|
sl@0
|
1109 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4268
|
sl@0
|
1110 |
@SYMTestCaseDesc Check output can be deflated in raw format and inflated.
|
sl@0
|
1111 |
@SYMTestPriority High
|
sl@0
|
1112 |
@SYMTestActions 1. Create a stream and initialise it using deflateInit2(),
|
sl@0
|
1113 |
setting windowBits between -8 and -15.
|
sl@0
|
1114 |
2. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
1115 |
3. Create an inflate stream and initialise it using inflateInit2(),
|
sl@0
|
1116 |
setting windowBits to be equal or less than the windowBits
|
sl@0
|
1117 |
value used for deflateInit2().
|
sl@0
|
1118 |
4. Inflate the input using inflate() and cleanup using inflateEnd().
|
sl@0
|
1119 |
@SYMTestExpectedResults The data should be compressed with deflateEnd returning Z_OK and
|
sl@0
|
1120 |
decompressed with inflateEnd returning Z_OK.
|
sl@0
|
1121 |
@SYMDEF REQ7362
|
sl@0
|
1122 |
*/
|
sl@0
|
1123 |
|
sl@0
|
1124 |
TVerdict CTestZlib::TestDefInfRawL()
|
sl@0
|
1125 |
{
|
sl@0
|
1126 |
int err = Z_OK;
|
sl@0
|
1127 |
|
sl@0
|
1128 |
// Streams
|
sl@0
|
1129 |
z_stream deflateStream;
|
sl@0
|
1130 |
z_stream inflateStream;
|
sl@0
|
1131 |
|
sl@0
|
1132 |
// Buffers
|
sl@0
|
1133 |
const char inputData[] = "This is a piece of data to compress.\0";
|
sl@0
|
1134 |
uLong inputDataLength = (uLong)strlen(inputData) + 1;
|
sl@0
|
1135 |
Byte *compressedDataBuffer = NULL;
|
sl@0
|
1136 |
uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
|
sl@0
|
1137 |
Byte *decompressedDataBuffer = NULL;
|
sl@0
|
1138 |
uLong decompressedDataBufferLength = inputDataLength;
|
sl@0
|
1139 |
|
sl@0
|
1140 |
// deflateInit2 and inflateInit2 arguments
|
sl@0
|
1141 |
StreamSettings streamSettings;
|
sl@0
|
1142 |
streamSettings.deflateInit2 = true;
|
sl@0
|
1143 |
streamSettings.level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
1144 |
streamSettings.method = Z_DEFLATED;
|
sl@0
|
1145 |
streamSettings.deflateWindowBits = -MAX_WBITS;
|
sl@0
|
1146 |
streamSettings.inflateWindowBits = streamSettings.deflateWindowBits;
|
sl@0
|
1147 |
streamSettings.memLevel = TEST_MID_MEM_LEVEL;
|
sl@0
|
1148 |
streamSettings.strategy = Z_DEFAULT_STRATEGY;
|
sl@0
|
1149 |
|
sl@0
|
1150 |
// Allocate memory for buffers
|
sl@0
|
1151 |
compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1152 |
CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
|
sl@0
|
1153 |
CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
|
sl@0
|
1154 |
|
sl@0
|
1155 |
decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1156 |
CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
|
sl@0
|
1157 |
CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
|
sl@0
|
1158 |
|
sl@0
|
1159 |
this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
|
sl@0
|
1160 |
|
sl@0
|
1161 |
// Initialise the inflateStream
|
sl@0
|
1162 |
this->InflateInit2L(inflateStream, streamSettings.inflateWindowBits);
|
sl@0
|
1163 |
CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
|
sl@0
|
1164 |
|
sl@0
|
1165 |
err = this->InflateDecompress(inflateStream, compressedDataBuffer, deflateStream.total_out, decompressedDataBuffer, decompressedDataBufferLength);
|
sl@0
|
1166 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflate error: %d", err);
|
sl@0
|
1167 |
|
sl@0
|
1168 |
// Clean up the inflateStream
|
sl@0
|
1169 |
err = inflateEnd(&inflateStream);
|
sl@0
|
1170 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateEnd error: %d", err);
|
sl@0
|
1171 |
|
sl@0
|
1172 |
CleanupStack::Pop(1);
|
sl@0
|
1173 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
1174 |
return EPass;
|
sl@0
|
1175 |
}
|
sl@0
|
1176 |
|
sl@0
|
1177 |
/**
|
sl@0
|
1178 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4269
|
sl@0
|
1179 |
@SYMTestCaseDesc Check output is not generated in raw format when windowBits < -15
|
sl@0
|
1180 |
or > -8.
|
sl@0
|
1181 |
@SYMTestPriority High
|
sl@0
|
1182 |
@SYMTestActions 1. Create a stream and initialise it using deflateInit2() passing
|
sl@0
|
1183 |
it the specified parameters.
|
sl@0
|
1184 |
|
sl@0
|
1185 |
Note: The test should be repeated for deflateInit2() parameter values:
|
sl@0
|
1186 |
• < -15 and > -8 for windowBits
|
sl@0
|
1187 |
@SYMTestExpectedResults deflateInit2() should fail returning Z_STREAM_ERROR. Note: if
|
sl@0
|
1188 |
windowBits is set between 8-15 and 24-31 there will be no error
|
sl@0
|
1189 |
as the input will be deflated as a zlib/gzip stream.
|
sl@0
|
1190 |
@SYMDEF REQ7362
|
sl@0
|
1191 |
*/
|
sl@0
|
1192 |
|
sl@0
|
1193 |
TVerdict CTestZlib::TestDefRawFailsL()
|
sl@0
|
1194 |
{
|
sl@0
|
1195 |
TBool ret;
|
sl@0
|
1196 |
|
sl@0
|
1197 |
// Streams
|
sl@0
|
1198 |
z_stream deflateStream;
|
sl@0
|
1199 |
|
sl@0
|
1200 |
// deflateInit2 and inflateInit2 arguments
|
sl@0
|
1201 |
int level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
1202 |
int method = Z_DEFLATED;
|
sl@0
|
1203 |
int deflateWindowBits;
|
sl@0
|
1204 |
int memLevel = TEST_MID_MEM_LEVEL;
|
sl@0
|
1205 |
int strategy = Z_DEFAULT_STRATEGY;
|
sl@0
|
1206 |
|
sl@0
|
1207 |
// Read in the value for windowBits from the ini file
|
sl@0
|
1208 |
ret = GetIntFromConfig(ConfigSection(), KParam1, deflateWindowBits);
|
sl@0
|
1209 |
CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param1 from ini file");
|
sl@0
|
1210 |
|
sl@0
|
1211 |
// Initialise the deflate stream
|
sl@0
|
1212 |
this->DeflateInit2L(deflateStream, level, method, deflateWindowBits, memLevel, strategy, Z_STREAM_ERROR);
|
sl@0
|
1213 |
|
sl@0
|
1214 |
return EPass;
|
sl@0
|
1215 |
}
|
sl@0
|
1216 |
|
sl@0
|
1217 |
/**
|
sl@0
|
1218 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4270
|
sl@0
|
1219 |
@SYMTestCaseDesc Check raw input is not inflated when windowBits < -15 or > -8.
|
sl@0
|
1220 |
@SYMTestPriority High
|
sl@0
|
1221 |
@SYMTestActions 1. Create a stream and initialise it using deflateInit2(),
|
sl@0
|
1222 |
setting windowBits between -8 and -15.
|
sl@0
|
1223 |
2. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
1224 |
3. Create an inflate stream and initialise it using inflateInit2()
|
sl@0
|
1225 |
passing it the specified parameters.
|
sl@0
|
1226 |
|
sl@0
|
1227 |
Note: The test should be repeated for inflateInit2() parameter values:
|
sl@0
|
1228 |
• < -15, > -8 & < 8, >= 8 & <= 15 and >= 24 & <= 31 for windowBits
|
sl@0
|
1229 |
For cases >= 8 & <= 15 and >= 24 & <= 31 inflate the compressed data
|
sl@0
|
1230 |
and call inflateEnd() to clean up.
|
sl@0
|
1231 |
@SYMTestExpectedResults inflateInit2() should fail returning Z_STREAM_ERROR. Note: if
|
sl@0
|
1232 |
windowBits is set between 8-15 and 24-31 a Z_DATA_ERROR will be
|
sl@0
|
1233 |
given as it will inflate as a zlib/gzip stream.
|
sl@0
|
1234 |
@SYMDEF REQ7362
|
sl@0
|
1235 |
*/
|
sl@0
|
1236 |
|
sl@0
|
1237 |
TVerdict CTestZlib::TestDefInfRawFailsL()
|
sl@0
|
1238 |
{
|
sl@0
|
1239 |
int err = Z_OK;
|
sl@0
|
1240 |
TBool ret;
|
sl@0
|
1241 |
|
sl@0
|
1242 |
// Streams
|
sl@0
|
1243 |
z_stream deflateStream;
|
sl@0
|
1244 |
z_stream inflateStream;
|
sl@0
|
1245 |
|
sl@0
|
1246 |
// Buffers
|
sl@0
|
1247 |
const char inputData[] = "This is a piece of data to compress.\0";
|
sl@0
|
1248 |
uLong inputDataLength = (uLong)strlen(inputData) + 1;
|
sl@0
|
1249 |
Byte *compressedDataBuffer = NULL;
|
sl@0
|
1250 |
uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
|
sl@0
|
1251 |
Byte *decompressedDataBuffer = NULL;
|
sl@0
|
1252 |
uLong decompressedDataBufferLength = inputDataLength;
|
sl@0
|
1253 |
|
sl@0
|
1254 |
// deflateInit2 and inflateInit2 arguments
|
sl@0
|
1255 |
int level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
1256 |
int method = Z_DEFLATED;
|
sl@0
|
1257 |
int deflateWindowBits = -MAX_WBITS;
|
sl@0
|
1258 |
int inflateWindowBits;
|
sl@0
|
1259 |
int memLevel = TEST_MID_MEM_LEVEL;
|
sl@0
|
1260 |
int strategy = Z_DEFAULT_STRATEGY;
|
sl@0
|
1261 |
|
sl@0
|
1262 |
// Allocate memory for buffers
|
sl@0
|
1263 |
compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1264 |
CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
|
sl@0
|
1265 |
CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
|
sl@0
|
1266 |
|
sl@0
|
1267 |
decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1268 |
CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
|
sl@0
|
1269 |
CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
|
sl@0
|
1270 |
|
sl@0
|
1271 |
// Read in the value for windowBits from the ini file
|
sl@0
|
1272 |
ret = GetIntFromConfig(ConfigSection(), KParam1, inflateWindowBits);
|
sl@0
|
1273 |
CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param1 from ini file");
|
sl@0
|
1274 |
|
sl@0
|
1275 |
// Initialise the deflate stream
|
sl@0
|
1276 |
this->DeflateInit2L(deflateStream, level, method, deflateWindowBits, memLevel, strategy);
|
sl@0
|
1277 |
CleanupStack::PushL(TCleanupItem(DeflateEnd, &deflateStream));
|
sl@0
|
1278 |
|
sl@0
|
1279 |
// Compress the input
|
sl@0
|
1280 |
err = this->DeflateCompress(deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
|
sl@0
|
1281 |
CHECK_CONDITION1L(err!= Z_OK, KErrGeneral, "deflate error: %d", err);
|
sl@0
|
1282 |
|
sl@0
|
1283 |
// Clean up the deflate stream
|
sl@0
|
1284 |
err = deflateEnd(&deflateStream);
|
sl@0
|
1285 |
CHECK_CONDITION1L(err!= Z_OK, KErrGeneral, "deflateEnd error: %d", err);
|
sl@0
|
1286 |
CleanupStack::Pop(1);
|
sl@0
|
1287 |
|
sl@0
|
1288 |
// Initialise the inflateStream
|
sl@0
|
1289 |
// If windowBits are used that specify a zlib or gzip stream we get a different error
|
sl@0
|
1290 |
if((inflateWindowBits >= 8 && inflateWindowBits <= 15) || (inflateWindowBits >= 24 && inflateWindowBits <= 31))
|
sl@0
|
1291 |
{
|
sl@0
|
1292 |
this->InflateInit2L(inflateStream, inflateWindowBits);
|
sl@0
|
1293 |
CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
|
sl@0
|
1294 |
|
sl@0
|
1295 |
err = this->InflateDecompress(inflateStream, compressedDataBuffer, deflateStream.total_out, decompressedDataBuffer, decompressedDataBufferLength);
|
sl@0
|
1296 |
CHECK_CONDITION1L(err!= Z_DATA_ERROR, KErrGeneral, "inflate error: %d", err);
|
sl@0
|
1297 |
|
sl@0
|
1298 |
// Clean up the inflateStream
|
sl@0
|
1299 |
err = inflateEnd(&inflateStream);
|
sl@0
|
1300 |
CHECK_CONDITION1L(err!= Z_OK, KErrGeneral, "inflateEnd error: %d", err);
|
sl@0
|
1301 |
CleanupStack::Pop(1);
|
sl@0
|
1302 |
}
|
sl@0
|
1303 |
else
|
sl@0
|
1304 |
{
|
sl@0
|
1305 |
this->InflateInit2L(inflateStream, inflateWindowBits, Z_STREAM_ERROR);
|
sl@0
|
1306 |
}
|
sl@0
|
1307 |
|
sl@0
|
1308 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
1309 |
return EPass;
|
sl@0
|
1310 |
}
|
sl@0
|
1311 |
|
sl@0
|
1312 |
/**
|
sl@0
|
1313 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4271
|
sl@0
|
1314 |
@SYMTestCaseDesc To check the specified bits are added to the start of a raw stream
|
sl@0
|
1315 |
correctly using deflatePrime().
|
sl@0
|
1316 |
@SYMTestPriority Low
|
sl@0
|
1317 |
@SYMTestActions 1. Create a stream and initialise it using deflateInit2(), setting
|
sl@0
|
1318 |
windowBits between -8 and -15.
|
sl@0
|
1319 |
2. Call deflatePrime() passing it the specified parameters.
|
sl@0
|
1320 |
3. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
1321 |
4. Check the bits at the front of the output are the expected ones.
|
sl@0
|
1322 |
|
sl@0
|
1323 |
Note: The test should be repeated for deflatePrime() parameter values:
|
sl@0
|
1324 |
• 0, 8 and 16 for bits
|
sl@0
|
1325 |
• 0, 216 and a number between 0 - 216 for value
|
sl@0
|
1326 |
@SYMTestExpectedResults deflatePrime() should return Z_OK and the bits at the front of the
|
sl@0
|
1327 |
output are the expected ones.
|
sl@0
|
1328 |
@SYMDEF REQ7362
|
sl@0
|
1329 |
*/
|
sl@0
|
1330 |
|
sl@0
|
1331 |
TVerdict CTestZlib::TestDeflatePrimeL()
|
sl@0
|
1332 |
{
|
sl@0
|
1333 |
int err = Z_OK;
|
sl@0
|
1334 |
TBool ret;
|
sl@0
|
1335 |
|
sl@0
|
1336 |
// Streams
|
sl@0
|
1337 |
z_stream deflateStream;
|
sl@0
|
1338 |
|
sl@0
|
1339 |
// Buffers
|
sl@0
|
1340 |
const char inputData[] = "This is a piece of data to compress.\0";
|
sl@0
|
1341 |
uLong inputDataLength = (uLong)strlen(inputData) + 1;
|
sl@0
|
1342 |
Byte *compressedDataBuffer;
|
sl@0
|
1343 |
uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
|
sl@0
|
1344 |
|
sl@0
|
1345 |
// deflateInit2 and inflateInit2 arguments
|
sl@0
|
1346 |
int level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
1347 |
int method = Z_DEFLATED;
|
sl@0
|
1348 |
int deflateWindowBits = -MAX_WBITS;
|
sl@0
|
1349 |
int memLevel = TEST_MID_MEM_LEVEL;
|
sl@0
|
1350 |
int strategy = Z_DEFAULT_STRATEGY;
|
sl@0
|
1351 |
|
sl@0
|
1352 |
// deflatePrime arguments
|
sl@0
|
1353 |
int bits;
|
sl@0
|
1354 |
int value;
|
sl@0
|
1355 |
|
sl@0
|
1356 |
// Bits added to the start of the compressed stream
|
sl@0
|
1357 |
Byte bit1 = 0;
|
sl@0
|
1358 |
Byte bit2 = 0;
|
sl@0
|
1359 |
|
sl@0
|
1360 |
// Allocate memory for buffers
|
sl@0
|
1361 |
compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1362 |
CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
|
sl@0
|
1363 |
CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
|
sl@0
|
1364 |
|
sl@0
|
1365 |
// Read in the values for bits and value from the ini file
|
sl@0
|
1366 |
ret = GetIntFromConfig(ConfigSection(), KParam1, bits);
|
sl@0
|
1367 |
CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param1 from ini file.");
|
sl@0
|
1368 |
|
sl@0
|
1369 |
ret = GetIntFromConfig(ConfigSection(), KParam2, value);
|
sl@0
|
1370 |
CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param2 from ini file.");
|
sl@0
|
1371 |
|
sl@0
|
1372 |
// Initialise the deflate stream
|
sl@0
|
1373 |
this->DeflateInit2L(deflateStream, level, method, deflateWindowBits, memLevel, strategy);
|
sl@0
|
1374 |
CleanupStack::PushL(TCleanupItem(DeflateEnd, &deflateStream));
|
sl@0
|
1375 |
|
sl@0
|
1376 |
// Call deflatePrime on the stream
|
sl@0
|
1377 |
err = deflatePrime(&deflateStream, bits, value);
|
sl@0
|
1378 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflatePrime error: %d", err);
|
sl@0
|
1379 |
|
sl@0
|
1380 |
// Compress the input
|
sl@0
|
1381 |
err = this->DeflateCompress(deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
|
sl@0
|
1382 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflate error: %d", err);
|
sl@0
|
1383 |
|
sl@0
|
1384 |
// Clean up the deflate stream
|
sl@0
|
1385 |
err = deflateEnd(&deflateStream);
|
sl@0
|
1386 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflateEnd error: %d", err);
|
sl@0
|
1387 |
CleanupStack::Pop(1);
|
sl@0
|
1388 |
|
sl@0
|
1389 |
// Check the bits at the start of the compressed data are the same as intended
|
sl@0
|
1390 |
// when using deflatePrime()
|
sl@0
|
1391 |
switch(bits)
|
sl@0
|
1392 |
{
|
sl@0
|
1393 |
case 16:
|
sl@0
|
1394 |
bit1 = value & 0xFF;
|
sl@0
|
1395 |
bit2 = (value >> 8) & 0xFF;
|
sl@0
|
1396 |
break;
|
sl@0
|
1397 |
case 8:
|
sl@0
|
1398 |
bit1 = value & 0xFF;
|
sl@0
|
1399 |
bit2 = compressedDataBuffer[1];
|
sl@0
|
1400 |
break;
|
sl@0
|
1401 |
case 0:
|
sl@0
|
1402 |
bit1 = compressedDataBuffer[0];
|
sl@0
|
1403 |
bit2 = compressedDataBuffer[1];
|
sl@0
|
1404 |
break;
|
sl@0
|
1405 |
default:
|
sl@0
|
1406 |
INFO_PRINTF1(_L("The test only works with bits set to 0, 8 or 16."));
|
sl@0
|
1407 |
User::Leave(KErrGeneral);
|
sl@0
|
1408 |
}
|
sl@0
|
1409 |
CHECK_CONDITION0L(compressedDataBuffer[0] != bit1 || compressedDataBuffer[1] != bit2, KErrGeneral, "The bits at the start of the compressed data buffer do not match the specified bits in deflatePrime.");
|
sl@0
|
1410 |
|
sl@0
|
1411 |
CleanupStack::PopAndDestroy(1);
|
sl@0
|
1412 |
return EPass;
|
sl@0
|
1413 |
}
|
sl@0
|
1414 |
|
sl@0
|
1415 |
/**
|
sl@0
|
1416 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4272
|
sl@0
|
1417 |
@SYMTestCaseDesc Check deflatePrime() fails when given an invalid stream.
|
sl@0
|
1418 |
@SYMTestPriority Medium
|
sl@0
|
1419 |
@SYMTestActions 1. Create a stream and initialise it using deflateInit2(),
|
sl@0
|
1420 |
setting windowBits between -8 and -15.
|
sl@0
|
1421 |
2. Call deflatePrime() passing it parameter values:
|
sl@0
|
1422 |
a. NULL for the stream argument
|
sl@0
|
1423 |
b. a stream whose state is NULL for the stream argument
|
sl@0
|
1424 |
@SYMTestExpectedResults deflatePrime() fails returning Z_STREAM_ERROR in both cases.
|
sl@0
|
1425 |
@SYMDEF REQ7362
|
sl@0
|
1426 |
*/
|
sl@0
|
1427 |
|
sl@0
|
1428 |
TVerdict CTestZlib::TestDeflatePrimeFailsL()
|
sl@0
|
1429 |
{
|
sl@0
|
1430 |
int err = Z_OK;
|
sl@0
|
1431 |
|
sl@0
|
1432 |
// Streams
|
sl@0
|
1433 |
z_stream deflateStream;
|
sl@0
|
1434 |
|
sl@0
|
1435 |
// deflateInit2 and inflateInit2 arguments
|
sl@0
|
1436 |
int level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
1437 |
int method = Z_DEFLATED;
|
sl@0
|
1438 |
int deflateWindowBits = -MAX_WBITS;
|
sl@0
|
1439 |
int memLevel = TEST_MID_MEM_LEVEL;
|
sl@0
|
1440 |
int strategy = Z_DEFAULT_STRATEGY;
|
sl@0
|
1441 |
|
sl@0
|
1442 |
// deflatePrime arguments
|
sl@0
|
1443 |
int bits = 0;
|
sl@0
|
1444 |
int value = 0;
|
sl@0
|
1445 |
|
sl@0
|
1446 |
// Initialise the deflate stream
|
sl@0
|
1447 |
this->DeflateInit2L(deflateStream, level, method, deflateWindowBits, memLevel, strategy);
|
sl@0
|
1448 |
CleanupStack::PushL(TCleanupItem(DeflateEnd, &deflateStream));
|
sl@0
|
1449 |
|
sl@0
|
1450 |
// Call deflatePrime on a NULL stream
|
sl@0
|
1451 |
err = deflatePrime(NULL, bits, value);
|
sl@0
|
1452 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflatePrime on a NULL stream returned an unexpected value: %d", err);
|
sl@0
|
1453 |
|
sl@0
|
1454 |
// Try calling deflatePrime on a deflate stream that has a NULL state
|
sl@0
|
1455 |
// We must keep a pointer to the streams state so we can clean up properly with deflateEnd
|
sl@0
|
1456 |
internal_state *deflateState = deflateStream.state;
|
sl@0
|
1457 |
deflateStream.state = NULL;
|
sl@0
|
1458 |
|
sl@0
|
1459 |
err = deflatePrime(&deflateStream, bits, value);
|
sl@0
|
1460 |
|
sl@0
|
1461 |
deflateStream.state = deflateState;
|
sl@0
|
1462 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflatePrime on a stream with a NULL state returned an unexpected value: %d", err);
|
sl@0
|
1463 |
|
sl@0
|
1464 |
// deflateInit2() leaves a raw stream in a busy state. This results in deflateEnd()
|
sl@0
|
1465 |
// returning a Z_DATA_ERROR, unless deflate() has been called on the stream,
|
sl@0
|
1466 |
// meaning we have to set err back to Z_OK for the test to pass
|
sl@0
|
1467 |
err = deflateEnd(&deflateStream);
|
sl@0
|
1468 |
CHECK_CONDITION1L(err != Z_DATA_ERROR, KErrGeneral, "deflateEnd error: %d", err);
|
sl@0
|
1469 |
CleanupStack::Pop(1);
|
sl@0
|
1470 |
|
sl@0
|
1471 |
return EPass;
|
sl@0
|
1472 |
}
|
sl@0
|
1473 |
|
sl@0
|
1474 |
/**
|
sl@0
|
1475 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4274
|
sl@0
|
1476 |
@SYMTestCaseDesc Check inflatePrime() fails when given an invalid stream or parameters.
|
sl@0
|
1477 |
@SYMTestPriority Medium
|
sl@0
|
1478 |
@SYMTestActions 1. Create an inflate stream and initialise it using inflateInit2(),
|
sl@0
|
1479 |
setting windowBits to be equal or less than the windowBits value
|
sl@0
|
1480 |
used for deflateInit2().
|
sl@0
|
1481 |
2. Call inflatePrime() passing it parameter values:
|
sl@0
|
1482 |
a. NULL for the stream argument
|
sl@0
|
1483 |
b. a stream whose state is NULL for the stream argument
|
sl@0
|
1484 |
c. > 16 for bits
|
sl@0
|
1485 |
d. (32 – stream->bits) for bits
|
sl@0
|
1486 |
@SYMTestExpectedResults inflatePrime() fails returning Z_STREAM_ERROR in all cases.
|
sl@0
|
1487 |
@SYMDEF REQ7362
|
sl@0
|
1488 |
*/
|
sl@0
|
1489 |
|
sl@0
|
1490 |
TVerdict CTestZlib::TestInflatePrimeFailsL()
|
sl@0
|
1491 |
{
|
sl@0
|
1492 |
int err = Z_OK;
|
sl@0
|
1493 |
|
sl@0
|
1494 |
// Streams
|
sl@0
|
1495 |
z_stream inflateStream;
|
sl@0
|
1496 |
|
sl@0
|
1497 |
// inflateInit2 argument
|
sl@0
|
1498 |
int inflateWindowBits = -MAX_WBITS;
|
sl@0
|
1499 |
|
sl@0
|
1500 |
// deflatePrime arguments
|
sl@0
|
1501 |
int bits = 0;
|
sl@0
|
1502 |
int value = 0;
|
sl@0
|
1503 |
|
sl@0
|
1504 |
// Initialise the inflate stream
|
sl@0
|
1505 |
this->InflateInit2L(inflateStream, inflateWindowBits);
|
sl@0
|
1506 |
CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
|
sl@0
|
1507 |
|
sl@0
|
1508 |
// Call inflatePrime on a NULL stream
|
sl@0
|
1509 |
err = inflatePrime(NULL, bits, value);
|
sl@0
|
1510 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflatePrime on a NULL stream returned an unexpected value: %d", err);
|
sl@0
|
1511 |
|
sl@0
|
1512 |
// Try calling inflatePrime on a deflate stream that has a NULL state
|
sl@0
|
1513 |
// We must keep a pointer to the streams state so we can clean up properly with deflateEnd
|
sl@0
|
1514 |
struct internal_state FAR *inflateState = inflateStream.state;
|
sl@0
|
1515 |
inflateStream.state = NULL;
|
sl@0
|
1516 |
|
sl@0
|
1517 |
err = inflatePrime(&inflateStream, bits, value);
|
sl@0
|
1518 |
|
sl@0
|
1519 |
inflateStream.state = inflateState;
|
sl@0
|
1520 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflatePrime on a stream with a NULL state returned an unexpected value: %d", err);
|
sl@0
|
1521 |
|
sl@0
|
1522 |
// Call inflatePrime with bits > 16
|
sl@0
|
1523 |
err = inflatePrime(&inflateStream, 17, value);
|
sl@0
|
1524 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflatePrime using bits > 16 returned an unexpected value: %d", err);
|
sl@0
|
1525 |
|
sl@0
|
1526 |
// Call inflatePrime with inflateStream->state->bits + bits > 32
|
sl@0
|
1527 |
// This test cannot be implemented due to inflate_state requiring the definition for
|
sl@0
|
1528 |
// the code struct which is in a header file that is included by one of the zlib
|
sl@0
|
1529 |
// cpp files.
|
sl@0
|
1530 |
/*
|
sl@0
|
1531 |
inflateState = inflateStream.state;
|
sl@0
|
1532 |
inflateState->bits(33 - bits);
|
sl@0
|
1533 |
err = inflatePrime(&inflateStream, bits, value);
|
sl@0
|
1534 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflatePrime, setting inflateStream->state->bits, returned an unexpected value: %d", err);
|
sl@0
|
1535 |
*/
|
sl@0
|
1536 |
|
sl@0
|
1537 |
// Clean up the inflate stream
|
sl@0
|
1538 |
err = inflateEnd(&inflateStream);
|
sl@0
|
1539 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateEnd error: %d", err);
|
sl@0
|
1540 |
CleanupStack::Pop(1);
|
sl@0
|
1541 |
|
sl@0
|
1542 |
return EPass;
|
sl@0
|
1543 |
}
|
sl@0
|
1544 |
|
sl@0
|
1545 |
/**
|
sl@0
|
1546 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4275
|
sl@0
|
1547 |
@SYMTestCaseDesc Check that a stream is duplicated correctly when using inflateCopy().
|
sl@0
|
1548 |
@SYMTestPriority High
|
sl@0
|
1549 |
@SYMTestActions 1. Create a stream and initialise it using deflateInit().
|
sl@0
|
1550 |
2. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
1551 |
3. Create an inflate stream and initialise it using inflateInit().
|
sl@0
|
1552 |
4. Create a second inflate stream and copy the first stream to the
|
sl@0
|
1553 |
second stream using inflateCopy().
|
sl@0
|
1554 |
5. Call inflate() and inflateEnd() on both streams.
|
sl@0
|
1555 |
6. Compare the output of both streams.
|
sl@0
|
1556 |
@SYMTestExpectedResults inflateCopy() should return Z_OK and the output of both streams will
|
sl@0
|
1557 |
be identical.
|
sl@0
|
1558 |
@SYMDEF REQ7362
|
sl@0
|
1559 |
*/
|
sl@0
|
1560 |
|
sl@0
|
1561 |
TVerdict CTestZlib::TestInflateCopyL()
|
sl@0
|
1562 |
{
|
sl@0
|
1563 |
int err = Z_OK;
|
sl@0
|
1564 |
|
sl@0
|
1565 |
// Streams
|
sl@0
|
1566 |
z_stream deflateStream;
|
sl@0
|
1567 |
z_stream inflateStream;
|
sl@0
|
1568 |
z_stream inflateStreamCopy;
|
sl@0
|
1569 |
|
sl@0
|
1570 |
// Buffers
|
sl@0
|
1571 |
const char inputData[] = "This is a piece of data to compress.\0";
|
sl@0
|
1572 |
uLong inputDataLength = (uLong)strlen(inputData) + 1;
|
sl@0
|
1573 |
Byte *compressedDataBuffer = NULL;
|
sl@0
|
1574 |
uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
|
sl@0
|
1575 |
Byte *decompressedDataBuffer = NULL;
|
sl@0
|
1576 |
uLong decompressedDataBufferLength = inputDataLength;
|
sl@0
|
1577 |
Byte *copiedDecompressedDataBuffer = NULL;
|
sl@0
|
1578 |
uLong copiedDecompressedDataBufferLength = decompressedDataBufferLength;
|
sl@0
|
1579 |
|
sl@0
|
1580 |
// deflateInit argument
|
sl@0
|
1581 |
StreamSettings streamSettings;
|
sl@0
|
1582 |
streamSettings.deflateInit2 = false;
|
sl@0
|
1583 |
streamSettings.level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
1584 |
|
sl@0
|
1585 |
// Allocate memory for buffers
|
sl@0
|
1586 |
compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1587 |
CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
|
sl@0
|
1588 |
CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
|
sl@0
|
1589 |
|
sl@0
|
1590 |
decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1591 |
CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
|
sl@0
|
1592 |
CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
|
sl@0
|
1593 |
|
sl@0
|
1594 |
copiedDecompressedDataBuffer = (Byte *)User::AllocZ(copiedDecompressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1595 |
CHECK_CONDITION0L(copiedDecompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for copiedDecompressedDataBuffer.");
|
sl@0
|
1596 |
CleanupStack::PushL(TCleanupItem(User::Free, copiedDecompressedDataBuffer));
|
sl@0
|
1597 |
|
sl@0
|
1598 |
this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
|
sl@0
|
1599 |
|
sl@0
|
1600 |
// Initialise the inflate streams
|
sl@0
|
1601 |
this->InflateInitL(inflateStream);
|
sl@0
|
1602 |
CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
|
sl@0
|
1603 |
|
sl@0
|
1604 |
// Copy the inflateStream
|
sl@0
|
1605 |
err = inflateCopy(&inflateStreamCopy, &inflateStream);
|
sl@0
|
1606 |
CHECK_CONDITION1L(err != Z_OK, KErrNoMemory, "inflateCopy error: %d", err);
|
sl@0
|
1607 |
CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStreamCopy));
|
sl@0
|
1608 |
|
sl@0
|
1609 |
// Decompress the data in the compressedDataBuffer
|
sl@0
|
1610 |
err = this->InflateDecompress(inflateStream, compressedDataBuffer, deflateStream.total_out, decompressedDataBuffer, decompressedDataBufferLength);
|
sl@0
|
1611 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflate error: %d", err);
|
sl@0
|
1612 |
|
sl@0
|
1613 |
// Decompress the data in the copiedDecompressedDataBuffer
|
sl@0
|
1614 |
err = this->InflateDecompress(inflateStreamCopy, compressedDataBuffer, deflateStream.total_out, copiedDecompressedDataBuffer, copiedDecompressedDataBufferLength);
|
sl@0
|
1615 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflate error: %d", err);
|
sl@0
|
1616 |
|
sl@0
|
1617 |
// Clean up the inflate streams
|
sl@0
|
1618 |
err = inflateEnd(&inflateStream);
|
sl@0
|
1619 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateStream - inflateEnd error: %d", err);
|
sl@0
|
1620 |
|
sl@0
|
1621 |
err = inflateEnd(&inflateStreamCopy);
|
sl@0
|
1622 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateStreamCopy - inflateEnd error: %d", err);
|
sl@0
|
1623 |
CleanupStack::Pop(2);
|
sl@0
|
1624 |
|
sl@0
|
1625 |
// Check that both inflate streams produced identical output
|
sl@0
|
1626 |
CHECK_CONDITION0L(memcmp((char *)copiedDecompressedDataBuffer, (char *)decompressedDataBuffer, decompressedDataBufferLength) != 0, KErrGeneral, "The copied stream did not produce the same decompressed output as the original stream.");
|
sl@0
|
1627 |
|
sl@0
|
1628 |
CleanupStack::PopAndDestroy(3);
|
sl@0
|
1629 |
return EPass;
|
sl@0
|
1630 |
}
|
sl@0
|
1631 |
|
sl@0
|
1632 |
/**
|
sl@0
|
1633 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4276
|
sl@0
|
1634 |
@SYMTestCaseDesc Check inflateCopy() fails when given an invalid stream or parameters.
|
sl@0
|
1635 |
@SYMTestPriority High
|
sl@0
|
1636 |
@SYMTestActions 1. Create an inflate stream and initialise it using inflateInit().
|
sl@0
|
1637 |
2. Create a second inflate stream and call inflateCopy() passing
|
sl@0
|
1638 |
it parameter values:
|
sl@0
|
1639 |
a. NULL for the dest stream argument
|
sl@0
|
1640 |
b. NULL for the source stream argument
|
sl@0
|
1641 |
c. a stream whose state is NULL for the source stream argument
|
sl@0
|
1642 |
d. a stream whose zalloc is Z_NULL for the source stream argument
|
sl@0
|
1643 |
e. a stream whose zfree is Z_NULL for the source stream argument
|
sl@0
|
1644 |
@SYMTestExpectedResults inflateCopy() fails returning Z_STREAM_ERROR in all cases.
|
sl@0
|
1645 |
@SYMDEF REQ7362
|
sl@0
|
1646 |
*/
|
sl@0
|
1647 |
|
sl@0
|
1648 |
TVerdict CTestZlib::TestInflateCopyFailsParamsL()
|
sl@0
|
1649 |
{
|
sl@0
|
1650 |
int err = Z_OK;
|
sl@0
|
1651 |
|
sl@0
|
1652 |
// Streams
|
sl@0
|
1653 |
z_stream inflateStream;
|
sl@0
|
1654 |
z_stream inflateStreamCopy;
|
sl@0
|
1655 |
|
sl@0
|
1656 |
// Initialise the inflate streams
|
sl@0
|
1657 |
this->InflateInitL(inflateStream);
|
sl@0
|
1658 |
CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
|
sl@0
|
1659 |
|
sl@0
|
1660 |
// Try to copy from a NULL stream
|
sl@0
|
1661 |
err = inflateCopy(&inflateStreamCopy, NULL);
|
sl@0
|
1662 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateCopy from a NULL stream returned an unexpected value: %d", err);
|
sl@0
|
1663 |
|
sl@0
|
1664 |
// Try to copy to a NULL stream
|
sl@0
|
1665 |
err = inflateCopy(NULL, &inflateStream);
|
sl@0
|
1666 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateCopy to a NULL stream returned an unexpected value: %d", err);
|
sl@0
|
1667 |
|
sl@0
|
1668 |
// Try calling deflateCopy on a deflate stream that has a NULL state
|
sl@0
|
1669 |
// We must keep a pointer to the streams state so we can clean up properly with deflateEnd
|
sl@0
|
1670 |
struct internal_state FAR *state = inflateStream.state;
|
sl@0
|
1671 |
inflateStream.state = NULL;
|
sl@0
|
1672 |
|
sl@0
|
1673 |
err = inflateCopy(&inflateStreamCopy, &inflateStream);
|
sl@0
|
1674 |
|
sl@0
|
1675 |
inflateStream.state = state;
|
sl@0
|
1676 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateCopy from a stream whose state is NULL returned an unexpected value: %d", err);
|
sl@0
|
1677 |
|
sl@0
|
1678 |
// Try to copy from a stream with zalloc set to Z_NULL
|
sl@0
|
1679 |
inflateStream.zalloc = Z_NULL;
|
sl@0
|
1680 |
err = inflateCopy(&inflateStreamCopy, &inflateStream);
|
sl@0
|
1681 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateCopy from a stream with zalloc set to NULL returned an unexpected value: %d", err);
|
sl@0
|
1682 |
|
sl@0
|
1683 |
// Try to copy from a stream with zfree set to Z_NULL
|
sl@0
|
1684 |
free_func zfree = inflateStream.zfree;
|
sl@0
|
1685 |
inflateStream.zfree = Z_NULL;
|
sl@0
|
1686 |
|
sl@0
|
1687 |
err = inflateCopy(&inflateStreamCopy, &inflateStream);
|
sl@0
|
1688 |
|
sl@0
|
1689 |
inflateStream.zfree = zfree;
|
sl@0
|
1690 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateCopy from a stream with zfree set to NULL returned an unexpected value: %d", err);
|
sl@0
|
1691 |
|
sl@0
|
1692 |
// Clean up the inflate streams
|
sl@0
|
1693 |
err = inflateEnd(&inflateStream);
|
sl@0
|
1694 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateStream - inflateEnd error: %d", err);
|
sl@0
|
1695 |
CleanupStack::Pop(1);
|
sl@0
|
1696 |
|
sl@0
|
1697 |
return EPass;
|
sl@0
|
1698 |
}
|
sl@0
|
1699 |
|
sl@0
|
1700 |
/**
|
sl@0
|
1701 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4277
|
sl@0
|
1702 |
@SYMTestCaseDesc Check inflateCopy() fails when there is not enough memory to copy
|
sl@0
|
1703 |
the stream.
|
sl@0
|
1704 |
@SYMTestPriority High
|
sl@0
|
1705 |
@SYMTestActions 1. Create an inflate stream and initialise it using inflateInit().
|
sl@0
|
1706 |
2. Create a second inflate stream and set memory allocation to
|
sl@0
|
1707 |
fail on the first attempt.
|
sl@0
|
1708 |
3. Copy the first stream to the second stream using inflateCopy().
|
sl@0
|
1709 |
4. Check that the memory is the same before and after calling
|
sl@0
|
1710 |
inflateCopy(). Note: If Z_OK is returned it will be necessary
|
sl@0
|
1711 |
to call inflateEnd() before checking the amount of memory.
|
sl@0
|
1712 |
5. Repeat this process until inflateCopy() returns Z_OK, increasing
|
sl@0
|
1713 |
the number of allocations that can be performed before failing.
|
sl@0
|
1714 |
@SYMTestExpectedResults inflateCopy() fails at first, returning Z_MEM_ERROR, and then it
|
sl@0
|
1715 |
will succeed with Z_OK. No memory should be leaked.
|
sl@0
|
1716 |
@SYMDEF REQ7362
|
sl@0
|
1717 |
*/
|
sl@0
|
1718 |
|
sl@0
|
1719 |
TVerdict CTestZlib::TestInflateCopyFailsMemL()
|
sl@0
|
1720 |
{
|
sl@0
|
1721 |
int err;
|
sl@0
|
1722 |
TVerdict verdict = EPass;
|
sl@0
|
1723 |
|
sl@0
|
1724 |
// Streams
|
sl@0
|
1725 |
z_stream inflateStream;
|
sl@0
|
1726 |
z_stream inflateStreamCopy;
|
sl@0
|
1727 |
|
sl@0
|
1728 |
// Initialise the inflate streams
|
sl@0
|
1729 |
this->InflateInitL(inflateStream);
|
sl@0
|
1730 |
CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
|
sl@0
|
1731 |
|
sl@0
|
1732 |
TInt failureRate;
|
sl@0
|
1733 |
for(failureRate = 1, err = Z_MEM_ERROR; err != Z_OK && failureRate <= FAILURE_RATE_LIMIT; failureRate++)
|
sl@0
|
1734 |
{
|
sl@0
|
1735 |
__UHEAP_SETFAIL(RHeap::EDeterministic, failureRate);
|
sl@0
|
1736 |
__UHEAP_MARK;
|
sl@0
|
1737 |
|
sl@0
|
1738 |
// Copy the inflateStream
|
sl@0
|
1739 |
err = inflateCopy(&inflateStreamCopy, &inflateStream);
|
sl@0
|
1740 |
|
sl@0
|
1741 |
// Memory has been allocated so we need to clean up
|
sl@0
|
1742 |
if(err == Z_OK)
|
sl@0
|
1743 |
{
|
sl@0
|
1744 |
err = inflateEnd(&inflateStreamCopy);
|
sl@0
|
1745 |
if(err != Z_OK)
|
sl@0
|
1746 |
{
|
sl@0
|
1747 |
INFO_PRINTF2(_L("inflateStreamCopy - inflateEnd error: %d"), err);
|
sl@0
|
1748 |
verdict = EAbort;
|
sl@0
|
1749 |
break;
|
sl@0
|
1750 |
}
|
sl@0
|
1751 |
}
|
sl@0
|
1752 |
else if(err != Z_MEM_ERROR)
|
sl@0
|
1753 |
{
|
sl@0
|
1754 |
INFO_PRINTF2(_L("inflateStreamCopy - unexpected error: %d"), err);
|
sl@0
|
1755 |
verdict = EFail;
|
sl@0
|
1756 |
break;
|
sl@0
|
1757 |
}
|
sl@0
|
1758 |
|
sl@0
|
1759 |
__UHEAP_MARKEND;
|
sl@0
|
1760 |
__UHEAP_RESET;
|
sl@0
|
1761 |
}
|
sl@0
|
1762 |
|
sl@0
|
1763 |
if(err == Z_OK)
|
sl@0
|
1764 |
{
|
sl@0
|
1765 |
INFO_PRINTF2(_L("The test succeeded at heap failure rate = %d."), --failureRate);
|
sl@0
|
1766 |
}
|
sl@0
|
1767 |
else if(failureRate > FAILURE_RATE_LIMIT)
|
sl@0
|
1768 |
{
|
sl@0
|
1769 |
INFO_PRINTF1(_L("Exceeded FAILURE_RATE_LIMIT. Either the test has failed or the limit needs increasing."));
|
sl@0
|
1770 |
verdict = EFail;
|
sl@0
|
1771 |
}
|
sl@0
|
1772 |
|
sl@0
|
1773 |
CleanupStack::PopAndDestroy(1);
|
sl@0
|
1774 |
|
sl@0
|
1775 |
return verdict;
|
sl@0
|
1776 |
}
|
sl@0
|
1777 |
|
sl@0
|
1778 |
/*
|
sl@0
|
1779 |
* in function required by inflateBack.
|
sl@0
|
1780 |
* Provides a pointer to the next piece of input data and returns the length of the data
|
sl@0
|
1781 |
*/
|
sl@0
|
1782 |
unsigned in OF((void FAR *in_desc, unsigned char FAR * FAR *in_buf))
|
sl@0
|
1783 |
{
|
sl@0
|
1784 |
struct bufferDescriptor *compressedDataBufferDescriptor = (struct bufferDescriptor *)in_desc;
|
sl@0
|
1785 |
*in_buf = &compressedDataBufferDescriptor->buffer[compressedDataBufferDescriptor->next];
|
sl@0
|
1786 |
|
sl@0
|
1787 |
// Check that there is more input
|
sl@0
|
1788 |
if(compressedDataBufferDescriptor->next + 1 < compressedDataBufferDescriptor->length)
|
sl@0
|
1789 |
{
|
sl@0
|
1790 |
compressedDataBufferDescriptor->next++;
|
sl@0
|
1791 |
return 1;
|
sl@0
|
1792 |
}
|
sl@0
|
1793 |
|
sl@0
|
1794 |
return 0;
|
sl@0
|
1795 |
}
|
sl@0
|
1796 |
|
sl@0
|
1797 |
/*
|
sl@0
|
1798 |
* out function required by inflateBack.
|
sl@0
|
1799 |
* Provides a pointer to which the next space in memory data can be output and returns the length of this space
|
sl@0
|
1800 |
*/
|
sl@0
|
1801 |
int out OF((void FAR *out_desc, unsigned char FAR *out_buf, unsigned len))
|
sl@0
|
1802 |
{
|
sl@0
|
1803 |
struct bufferDescriptor *decompressedDataBufferDescriptor = (struct bufferDescriptor *)out_desc;
|
sl@0
|
1804 |
|
sl@0
|
1805 |
// Make sure there is output space
|
sl@0
|
1806 |
if(decompressedDataBufferDescriptor->next + len <= decompressedDataBufferDescriptor->length)
|
sl@0
|
1807 |
{
|
sl@0
|
1808 |
memcpy(decompressedDataBufferDescriptor->buffer + decompressedDataBufferDescriptor->next, out_buf, len);
|
sl@0
|
1809 |
decompressedDataBufferDescriptor->next += len;
|
sl@0
|
1810 |
}
|
sl@0
|
1811 |
else
|
sl@0
|
1812 |
{
|
sl@0
|
1813 |
int leftOver = decompressedDataBufferDescriptor->length - decompressedDataBufferDescriptor->next;
|
sl@0
|
1814 |
memcpy(decompressedDataBufferDescriptor->buffer + decompressedDataBufferDescriptor->next, out_buf, leftOver);
|
sl@0
|
1815 |
}
|
sl@0
|
1816 |
|
sl@0
|
1817 |
return 0;
|
sl@0
|
1818 |
}
|
sl@0
|
1819 |
|
sl@0
|
1820 |
/**
|
sl@0
|
1821 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4278
|
sl@0
|
1822 |
@SYMTestCaseDesc Check a stream can be inflated using inflateBackInit(),
|
sl@0
|
1823 |
inflateBack() and inflateBackEnd().
|
sl@0
|
1824 |
@SYMTestPriority High
|
sl@0
|
1825 |
@SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
|
sl@0
|
1826 |
setting windowBits between -8 and -15.
|
sl@0
|
1827 |
2. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
1828 |
3. Create an inflate stream and initialise it using
|
sl@0
|
1829 |
inflateBackInit() setting windowBits to be equal to or greater
|
sl@0
|
1830 |
than the windowBits value used for deflateInit2().
|
sl@0
|
1831 |
4. Call inflateBack() to uncompress the stream and call
|
sl@0
|
1832 |
inflateBackEnd() to clean up.
|
sl@0
|
1833 |
5. Compare the original stream with the uncompressed stream.
|
sl@0
|
1834 |
@SYMTestExpectedResults inflateBackInit() and inflateBackEnd() should both return Z_OK.
|
sl@0
|
1835 |
inflateBack() should return Z_STREAM_END when it has finished
|
sl@0
|
1836 |
inflating the input stream. The original stream should be
|
sl@0
|
1837 |
identical to the final uncompressed stream.
|
sl@0
|
1838 |
@SYMDEF REQ7362
|
sl@0
|
1839 |
*/
|
sl@0
|
1840 |
|
sl@0
|
1841 |
TVerdict CTestZlib::TestInflateBackL()
|
sl@0
|
1842 |
{
|
sl@0
|
1843 |
int err = Z_OK;
|
sl@0
|
1844 |
|
sl@0
|
1845 |
// Streams
|
sl@0
|
1846 |
z_stream deflateStream;
|
sl@0
|
1847 |
z_stream inflateStream;
|
sl@0
|
1848 |
|
sl@0
|
1849 |
// Buffers
|
sl@0
|
1850 |
const char inputData[] = "This is a piece of data to compress.\0";
|
sl@0
|
1851 |
uLong inputDataLength = (uLong)strlen(inputData) + 1;
|
sl@0
|
1852 |
Byte *compressedDataBuffer = NULL;
|
sl@0
|
1853 |
uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
|
sl@0
|
1854 |
Byte *decompressedDataBuffer = NULL;
|
sl@0
|
1855 |
uLong decompressedDataBufferLength = inputDataLength;
|
sl@0
|
1856 |
|
sl@0
|
1857 |
// deflateInit2 and inflateBackInit arguments
|
sl@0
|
1858 |
StreamSettings streamSettings;
|
sl@0
|
1859 |
streamSettings.deflateInit2 = true;
|
sl@0
|
1860 |
streamSettings.level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
1861 |
streamSettings.method = Z_DEFLATED;
|
sl@0
|
1862 |
streamSettings.deflateWindowBits = -MAX_WBITS;
|
sl@0
|
1863 |
streamSettings.inflateWindowBits = -streamSettings.deflateWindowBits;
|
sl@0
|
1864 |
streamSettings.memLevel = TEST_MID_MEM_LEVEL;
|
sl@0
|
1865 |
streamSettings.strategy = Z_DEFAULT_STRATEGY;
|
sl@0
|
1866 |
Bytef inflateWindow[32 * 1024];
|
sl@0
|
1867 |
|
sl@0
|
1868 |
// Allocate memory for buffers
|
sl@0
|
1869 |
compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1870 |
CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
|
sl@0
|
1871 |
CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
|
sl@0
|
1872 |
|
sl@0
|
1873 |
decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1874 |
CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
|
sl@0
|
1875 |
CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
|
sl@0
|
1876 |
|
sl@0
|
1877 |
this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
|
sl@0
|
1878 |
|
sl@0
|
1879 |
// Initialise the inflate stream
|
sl@0
|
1880 |
InflateBackInitL(inflateStream, streamSettings.inflateWindowBits, inflateWindow);
|
sl@0
|
1881 |
CleanupStack::PushL(TCleanupItem(InflateBackEnd, &inflateStream));
|
sl@0
|
1882 |
|
sl@0
|
1883 |
// This must be set to NULL otherwise inflateBack will assume there is input and try to decompress it
|
sl@0
|
1884 |
inflateStream.next_in = NULL;
|
sl@0
|
1885 |
|
sl@0
|
1886 |
struct bufferDescriptor compressedDataBufferDescriptor;
|
sl@0
|
1887 |
compressedDataBufferDescriptor.buffer = compressedDataBuffer;
|
sl@0
|
1888 |
compressedDataBufferDescriptor.next = 0;
|
sl@0
|
1889 |
compressedDataBufferDescriptor.length = compressedDataBufferLength;
|
sl@0
|
1890 |
|
sl@0
|
1891 |
struct bufferDescriptor decompressedDataBufferDescriptor;
|
sl@0
|
1892 |
decompressedDataBufferDescriptor.buffer = decompressedDataBuffer;
|
sl@0
|
1893 |
decompressedDataBufferDescriptor.next = 0;
|
sl@0
|
1894 |
decompressedDataBufferDescriptor.length = decompressedDataBufferLength;
|
sl@0
|
1895 |
|
sl@0
|
1896 |
// Decompress the input
|
sl@0
|
1897 |
err = inflateBack(&inflateStream, &in, &compressedDataBufferDescriptor, &out, &decompressedDataBufferDescriptor);
|
sl@0
|
1898 |
CHECK_CONDITION1L(err != Z_STREAM_END, KErrGeneral, "inflateBack error: %d", err);
|
sl@0
|
1899 |
|
sl@0
|
1900 |
// Clean up the inflate stream
|
sl@0
|
1901 |
err = inflateBackEnd(&inflateStream);
|
sl@0
|
1902 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateBackEnd error: %d", err);
|
sl@0
|
1903 |
CleanupStack::Pop(1);
|
sl@0
|
1904 |
|
sl@0
|
1905 |
// Check that the decompressed data is identical to the original data
|
sl@0
|
1906 |
CHECK_CONDITION0L(strcmp(inputData, (char *)decompressedDataBuffer) != 0, KErrGeneral, "The deflated data did no match the original data.");
|
sl@0
|
1907 |
|
sl@0
|
1908 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
1909 |
return EPass;
|
sl@0
|
1910 |
}
|
sl@0
|
1911 |
|
sl@0
|
1912 |
/**
|
sl@0
|
1913 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4279
|
sl@0
|
1914 |
@SYMTestCaseDesc Check inflateBackEnd() fails when given an invalid stream or parameters.
|
sl@0
|
1915 |
@SYMTestPriority High
|
sl@0
|
1916 |
@SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
|
sl@0
|
1917 |
setting windowBits between -8 and -15.
|
sl@0
|
1918 |
2. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
1919 |
3. Create an inflate stream and initialise it using
|
sl@0
|
1920 |
nflateBackInit() setting windowBits to be equal to or greater
|
sl@0
|
1921 |
than the windowBits value used for deflateInit2().
|
sl@0
|
1922 |
4. Call inflateBack() to uncompress the stream.
|
sl@0
|
1923 |
5. Call inflateBackEnd() passing it parameter values:
|
sl@0
|
1924 |
a. NULL for the stream argument
|
sl@0
|
1925 |
b. a stream whose state is NULL for the stream argument
|
sl@0
|
1926 |
c. a stream whose zfree is Z_NULL for the stream argument
|
sl@0
|
1927 |
@SYMTestExpectedResults inflateBackEnd() fails returning Z_STREAM_ERROR in all cases.
|
sl@0
|
1928 |
@SYMDEF REQ7362
|
sl@0
|
1929 |
*/
|
sl@0
|
1930 |
|
sl@0
|
1931 |
TVerdict CTestZlib::TestInflateBackEndFailsL()
|
sl@0
|
1932 |
{
|
sl@0
|
1933 |
int err = Z_OK;
|
sl@0
|
1934 |
|
sl@0
|
1935 |
// Streams
|
sl@0
|
1936 |
z_stream deflateStream;
|
sl@0
|
1937 |
z_stream inflateStream;
|
sl@0
|
1938 |
|
sl@0
|
1939 |
// Buffers
|
sl@0
|
1940 |
const char inputData[] = "This is a piece of data to compress.\0";
|
sl@0
|
1941 |
uLong inputDataLength = (uLong)strlen(inputData) + 1;
|
sl@0
|
1942 |
Byte *compressedDataBuffer = NULL;
|
sl@0
|
1943 |
uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
|
sl@0
|
1944 |
Byte *decompressedDataBuffer = NULL;
|
sl@0
|
1945 |
uLong decompressedDataBufferLength = inputDataLength;
|
sl@0
|
1946 |
|
sl@0
|
1947 |
// deflateInit2 and inflateBackInit arguments
|
sl@0
|
1948 |
StreamSettings streamSettings;
|
sl@0
|
1949 |
streamSettings.deflateInit2 = true;
|
sl@0
|
1950 |
streamSettings.level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
1951 |
streamSettings.method = Z_DEFLATED;
|
sl@0
|
1952 |
streamSettings.deflateWindowBits = -MAX_WBITS;
|
sl@0
|
1953 |
streamSettings.inflateWindowBits = -streamSettings.deflateWindowBits;
|
sl@0
|
1954 |
streamSettings.memLevel = TEST_MID_MEM_LEVEL;
|
sl@0
|
1955 |
streamSettings.strategy = Z_DEFAULT_STRATEGY;
|
sl@0
|
1956 |
Bytef inflateWindow[32 * 1024];
|
sl@0
|
1957 |
|
sl@0
|
1958 |
// Allocate memory for buffers
|
sl@0
|
1959 |
compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1960 |
CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
|
sl@0
|
1961 |
CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
|
sl@0
|
1962 |
|
sl@0
|
1963 |
decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
|
sl@0
|
1964 |
CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
|
sl@0
|
1965 |
CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
|
sl@0
|
1966 |
|
sl@0
|
1967 |
this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
|
sl@0
|
1968 |
|
sl@0
|
1969 |
// Initialise the inflate stream
|
sl@0
|
1970 |
InflateBackInitL(inflateStream, streamSettings.inflateWindowBits, inflateWindow);
|
sl@0
|
1971 |
CleanupStack::PushL(TCleanupItem(InflateBackEnd, &inflateStream));
|
sl@0
|
1972 |
|
sl@0
|
1973 |
inflateStream.next_in = (unsigned char *)compressedDataBuffer;
|
sl@0
|
1974 |
inflateStream.avail_in = compressedDataBufferLength;
|
sl@0
|
1975 |
inflateStream.next_out = (unsigned char *)decompressedDataBuffer;
|
sl@0
|
1976 |
inflateStream.avail_out = decompressedDataBufferLength;
|
sl@0
|
1977 |
|
sl@0
|
1978 |
struct bufferDescriptor compressedDataBufferDescriptor;
|
sl@0
|
1979 |
compressedDataBufferDescriptor.buffer = compressedDataBuffer;
|
sl@0
|
1980 |
compressedDataBufferDescriptor.next = 0;
|
sl@0
|
1981 |
compressedDataBufferDescriptor.length = compressedDataBufferLength;
|
sl@0
|
1982 |
|
sl@0
|
1983 |
struct bufferDescriptor decompressedDataBufferDescriptor;
|
sl@0
|
1984 |
decompressedDataBufferDescriptor.buffer = decompressedDataBuffer;
|
sl@0
|
1985 |
decompressedDataBufferDescriptor.next = 0;
|
sl@0
|
1986 |
decompressedDataBufferDescriptor.length = decompressedDataBufferLength;
|
sl@0
|
1987 |
|
sl@0
|
1988 |
// Decompress the input
|
sl@0
|
1989 |
err = inflateBack(&inflateStream, &in, &compressedDataBufferDescriptor, &out, &decompressedDataBufferDescriptor);
|
sl@0
|
1990 |
CHECK_CONDITION1L(err != Z_STREAM_END, KErrGeneral, "inflateBack error: %d", err);
|
sl@0
|
1991 |
|
sl@0
|
1992 |
// Try cleaning up a NULL stream
|
sl@0
|
1993 |
err = inflateBackEnd(NULL);
|
sl@0
|
1994 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackEnd on a NULL stream returned an unexpected value: %d", err);
|
sl@0
|
1995 |
|
sl@0
|
1996 |
// Keep a pointer to the streams state so we can clean up properly with inflateBackEnd()
|
sl@0
|
1997 |
struct internal_state FAR *inflateState = inflateStream.state;
|
sl@0
|
1998 |
|
sl@0
|
1999 |
// Try cleaning up an inflate stream with a NULL state
|
sl@0
|
2000 |
inflateStream.state = NULL;
|
sl@0
|
2001 |
err = inflateBackEnd(&inflateStream);
|
sl@0
|
2002 |
inflateStream.state = inflateState;
|
sl@0
|
2003 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackEnd on a stream with a NULL state returned an unexpected value: %d", err);
|
sl@0
|
2004 |
|
sl@0
|
2005 |
// Try cleaning up an inflate stream with no free function
|
sl@0
|
2006 |
free_func zfree = inflateStream.zfree;
|
sl@0
|
2007 |
inflateStream.zfree = Z_NULL;
|
sl@0
|
2008 |
err = inflateBackEnd(NULL);
|
sl@0
|
2009 |
inflateStream.zfree = zfree;
|
sl@0
|
2010 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackEnd on a stream with zfree set to NULL returned an unexpected value: %d", err);
|
sl@0
|
2011 |
|
sl@0
|
2012 |
// Clean up the inflate stream
|
sl@0
|
2013 |
err = inflateBackEnd(&inflateStream);
|
sl@0
|
2014 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateBackEnd error: %d", err);
|
sl@0
|
2015 |
CleanupStack::Pop(1);
|
sl@0
|
2016 |
|
sl@0
|
2017 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
2018 |
return EPass;
|
sl@0
|
2019 |
}
|
sl@0
|
2020 |
|
sl@0
|
2021 |
/*
|
sl@0
|
2022 |
* in function required by inflateBack.
|
sl@0
|
2023 |
* Returning 0 indicates failure.
|
sl@0
|
2024 |
*/
|
sl@0
|
2025 |
unsigned inNoInput OF((void FAR *, unsigned char FAR * FAR *))
|
sl@0
|
2026 |
{
|
sl@0
|
2027 |
return 0;
|
sl@0
|
2028 |
}
|
sl@0
|
2029 |
|
sl@0
|
2030 |
/*
|
sl@0
|
2031 |
* out function required by inflateBack.
|
sl@0
|
2032 |
* Returning non 0 indicates failure.
|
sl@0
|
2033 |
*/
|
sl@0
|
2034 |
int outNoOutput OF((void FAR *, unsigned char FAR *, unsigned))
|
sl@0
|
2035 |
{
|
sl@0
|
2036 |
return 1;
|
sl@0
|
2037 |
}
|
sl@0
|
2038 |
|
sl@0
|
2039 |
/**
|
sl@0
|
2040 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4280
|
sl@0
|
2041 |
@SYMTestCaseDesc Check inflateBack() fails when given an invalid stream or parameters.
|
sl@0
|
2042 |
@SYMTestPriority High
|
sl@0
|
2043 |
@SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
|
sl@0
|
2044 |
setting windowBits between -8 and-15.
|
sl@0
|
2045 |
2. Deflate the input and cleanup using deflateEnd().
|
sl@0
|
2046 |
3. Create an inflate stream and initialise it using
|
sl@0
|
2047 |
inflateBackInit() setting windowBits to be equal to or greater
|
sl@0
|
2048 |
than the windowBits value used for deflateInit2().
|
sl@0
|
2049 |
4. Call inflateBack() passing it parameter values:
|
sl@0
|
2050 |
a. NULL for the stream argument
|
sl@0
|
2051 |
b. a stream whose state is NULL for the stream argument
|
sl@0
|
2052 |
c. an input function that returns 0 for the in argument
|
sl@0
|
2053 |
d. an output function that doesn’t return 0 for the out argument
|
sl@0
|
2054 |
e. corrupted deflate output
|
sl@0
|
2055 |
5. Call inflateBackEnd() to clean up
|
sl@0
|
2056 |
@SYMTestExpectedResults inflateBack() fails returning Z_STREAM_ERROR for the first two
|
sl@0
|
2057 |
cases, Z_BUF_ERROR for the second two cases and Z_DATA_ERROR
|
sl@0
|
2058 |
for the final case.
|
sl@0
|
2059 |
@SYMDEF REQ7362
|
sl@0
|
2060 |
*/
|
sl@0
|
2061 |
|
sl@0
|
2062 |
TVerdict CTestZlib::TestInflateBackFailsL()
|
sl@0
|
2063 |
{
|
sl@0
|
2064 |
int err = Z_OK;
|
sl@0
|
2065 |
|
sl@0
|
2066 |
// Streams
|
sl@0
|
2067 |
z_stream deflateStream;
|
sl@0
|
2068 |
z_stream inflateStream;
|
sl@0
|
2069 |
|
sl@0
|
2070 |
// Buffers
|
sl@0
|
2071 |
const char inputData[] = "This is a piece of data to compress.\0";
|
sl@0
|
2072 |
uLong inputDataLength = (uLong)strlen(inputData) + 1;
|
sl@0
|
2073 |
Byte *compressedDataBuffer = NULL;
|
sl@0
|
2074 |
uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
|
sl@0
|
2075 |
Byte *decompressedDataBuffer = NULL;
|
sl@0
|
2076 |
uLong decompressedDataBufferLength = inputDataLength;
|
sl@0
|
2077 |
|
sl@0
|
2078 |
// deflateInit2 and inflateBackInit arguments
|
sl@0
|
2079 |
StreamSettings streamSettings;
|
sl@0
|
2080 |
streamSettings.deflateInit2 = true;
|
sl@0
|
2081 |
streamSettings.level = Z_DEFAULT_COMPRESSION;
|
sl@0
|
2082 |
streamSettings.method = Z_DEFLATED;
|
sl@0
|
2083 |
streamSettings.deflateWindowBits = -MAX_WBITS;
|
sl@0
|
2084 |
streamSettings.inflateWindowBits = -streamSettings.deflateWindowBits; // inflateBackInit expects the positive equivalent of the windowBits used to make a raw stream
|
sl@0
|
2085 |
streamSettings.memLevel = TEST_MID_MEM_LEVEL;
|
sl@0
|
2086 |
streamSettings.strategy = Z_DEFAULT_STRATEGY;
|
sl@0
|
2087 |
Bytef inflateWindow[32 * 1024];
|
sl@0
|
2088 |
|
sl@0
|
2089 |
// Allocate memory for buffers
|
sl@0
|
2090 |
compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
|
sl@0
|
2091 |
CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
|
sl@0
|
2092 |
CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
|
sl@0
|
2093 |
|
sl@0
|
2094 |
decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
|
sl@0
|
2095 |
CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
|
sl@0
|
2096 |
CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
|
sl@0
|
2097 |
|
sl@0
|
2098 |
this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
|
sl@0
|
2099 |
|
sl@0
|
2100 |
// Initialise the inflate stream
|
sl@0
|
2101 |
InflateBackInitL(inflateStream, streamSettings.inflateWindowBits, inflateWindow);
|
sl@0
|
2102 |
CleanupStack::PushL(TCleanupItem(InflateBackEnd, &inflateStream));
|
sl@0
|
2103 |
|
sl@0
|
2104 |
// This must be set to NULL otherwise inflateBack will assume there is input and try to decompress it
|
sl@0
|
2105 |
inflateStream.next_in = NULL;
|
sl@0
|
2106 |
|
sl@0
|
2107 |
struct bufferDescriptor compressedDataBufferDescriptor;
|
sl@0
|
2108 |
compressedDataBufferDescriptor.buffer = compressedDataBuffer;
|
sl@0
|
2109 |
compressedDataBufferDescriptor.next = 0;
|
sl@0
|
2110 |
compressedDataBufferDescriptor.length = compressedDataBufferLength;
|
sl@0
|
2111 |
|
sl@0
|
2112 |
struct bufferDescriptor decompressedDataBufferDescriptor;
|
sl@0
|
2113 |
decompressedDataBufferDescriptor.buffer = decompressedDataBuffer;
|
sl@0
|
2114 |
decompressedDataBufferDescriptor.next = 0;
|
sl@0
|
2115 |
decompressedDataBufferDescriptor.length = decompressedDataBufferLength;
|
sl@0
|
2116 |
|
sl@0
|
2117 |
// Try inflating a NULL stream
|
sl@0
|
2118 |
err = inflateBack(NULL, &in, &compressedDataBufferDescriptor, &out, &decompressedDataBufferDescriptor);
|
sl@0
|
2119 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBack on a NULL stream returned an unexpected value: %d", err);
|
sl@0
|
2120 |
|
sl@0
|
2121 |
// Try calling inflateBack on a deflate stream that has a NULL state
|
sl@0
|
2122 |
// We must keep a pointer to the streams state so we can clean up properly with deflateBackEnd
|
sl@0
|
2123 |
struct internal_state FAR *inflateState = inflateStream.state;
|
sl@0
|
2124 |
inflateStream.state = NULL;
|
sl@0
|
2125 |
|
sl@0
|
2126 |
err = inflateBack(&inflateStream, &in, &compressedDataBufferDescriptor, &out, &decompressedDataBufferDescriptor);
|
sl@0
|
2127 |
|
sl@0
|
2128 |
inflateStream.state = inflateState;
|
sl@0
|
2129 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBack on a stream with a NULL state returned an unexpected value: %d", err);
|
sl@0
|
2130 |
|
sl@0
|
2131 |
// Try inflating a stream with an in_func that returns no input data
|
sl@0
|
2132 |
err = inflateBack(&inflateStream, &inNoInput, &compressedDataBufferDescriptor, &out, &decompressedDataBufferDescriptor);
|
sl@0
|
2133 |
CHECK_CONDITION1L(err != Z_BUF_ERROR, KErrGeneral, "Calling inflateBack with an in function that returns no input returned an unexpected value: %d", err);
|
sl@0
|
2134 |
|
sl@0
|
2135 |
// Try inflating a stream with an out_func that does not output any data
|
sl@0
|
2136 |
err = inflateBack(&inflateStream, &in, &compressedDataBufferDescriptor, &outNoOutput, &decompressedDataBufferDescriptor);
|
sl@0
|
2137 |
CHECK_CONDITION1L(err != Z_BUF_ERROR, KErrGeneral, "Calling inflateBack with an in function that returns no input returned an unexpected value: %d", err);
|
sl@0
|
2138 |
|
sl@0
|
2139 |
// Try inflating a corrupt stream
|
sl@0
|
2140 |
compressedDataBuffer[1] = 'a';
|
sl@0
|
2141 |
compressedDataBuffer[2] = 'a';
|
sl@0
|
2142 |
compressedDataBuffer[3] = 'a';
|
sl@0
|
2143 |
err = inflateBack(&inflateStream, &in, &compressedDataBufferDescriptor, &out, &decompressedDataBufferDescriptor);
|
sl@0
|
2144 |
CHECK_CONDITION1L(err != Z_DATA_ERROR, KErrGeneral, "Calling inflateBack on a corrupt stream returned an unexpected value: %d", err);
|
sl@0
|
2145 |
|
sl@0
|
2146 |
// Clean up the inflate stream
|
sl@0
|
2147 |
err = inflateBackEnd(&inflateStream);
|
sl@0
|
2148 |
CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateBackEnd error: %d", err);
|
sl@0
|
2149 |
CleanupStack::Pop(1);
|
sl@0
|
2150 |
|
sl@0
|
2151 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
2152 |
return EPass;
|
sl@0
|
2153 |
}
|
sl@0
|
2154 |
|
sl@0
|
2155 |
/**
|
sl@0
|
2156 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4281
|
sl@0
|
2157 |
@SYMTestCaseDesc Check inflateBackInit() fails when given an invalid stream or parameters.
|
sl@0
|
2158 |
@SYMTestPriority High
|
sl@0
|
2159 |
@SYMTestActions 1. Create an inflate stream and initialise it using
|
sl@0
|
2160 |
inflateBackInit() passing it parameter values:
|
sl@0
|
2161 |
a. NULL for the stream argument
|
sl@0
|
2162 |
b. a stream whose window is NULL for the stream argument
|
sl@0
|
2163 |
c. < 8 for the windowBits argument
|
sl@0
|
2164 |
d. > 5 for the windowBits argument
|
sl@0
|
2165 |
@SYMTestExpectedResults inflateBackInit() should fail returning Z_STREAM_ERROR for all cases.
|
sl@0
|
2166 |
@SYMDEF REQ7362
|
sl@0
|
2167 |
*/
|
sl@0
|
2168 |
|
sl@0
|
2169 |
TVerdict CTestZlib::TestInflateBackInitFailsParamsL()
|
sl@0
|
2170 |
{
|
sl@0
|
2171 |
int err = Z_OK;
|
sl@0
|
2172 |
|
sl@0
|
2173 |
// Streams
|
sl@0
|
2174 |
z_stream inflateStream;
|
sl@0
|
2175 |
|
sl@0
|
2176 |
// inflateBackInit arguments
|
sl@0
|
2177 |
int inflateBackWindowBits = MAX_WBITS;
|
sl@0
|
2178 |
Bytef inflateWindow[32 * 1024];
|
sl@0
|
2179 |
|
sl@0
|
2180 |
// Try initialising a NULL stream
|
sl@0
|
2181 |
inflateStream.zalloc = Z_NULL;
|
sl@0
|
2182 |
inflateStream.zfree = Z_NULL;
|
sl@0
|
2183 |
inflateStream.opaque = Z_NULL;
|
sl@0
|
2184 |
|
sl@0
|
2185 |
err = inflateBackInit(NULL, inflateBackWindowBits, inflateWindow);
|
sl@0
|
2186 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackInit on a NULL stream returned an unexpected value: %d", err);
|
sl@0
|
2187 |
|
sl@0
|
2188 |
// Try initialising a stream with a NULL inflate window
|
sl@0
|
2189 |
err = inflateBackInit(&inflateStream, inflateBackWindowBits, NULL);
|
sl@0
|
2190 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackInit on a stream with a NULL window returned an unexpected value: %d", err);
|
sl@0
|
2191 |
|
sl@0
|
2192 |
// Try initialising a stream with window bits < 8
|
sl@0
|
2193 |
err = inflateBackInit(&inflateStream, 7, inflateWindow);
|
sl@0
|
2194 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackInit on a stream with windowBits < 8 returned an unexpected value: %d", err);
|
sl@0
|
2195 |
|
sl@0
|
2196 |
// Try initialising a stream with window bits > 15
|
sl@0
|
2197 |
err = inflateBackInit(&inflateStream, 16, inflateWindow);
|
sl@0
|
2198 |
CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackInit on a stream with windowBits > 15 returned an unexpected value: %d", err);
|
sl@0
|
2199 |
|
sl@0
|
2200 |
return EPass;
|
sl@0
|
2201 |
}
|
sl@0
|
2202 |
|
sl@0
|
2203 |
/**
|
sl@0
|
2204 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4282
|
sl@0
|
2205 |
@SYMTestCaseDesc Check inflateBackInit() fails when there is not enough memory.
|
sl@0
|
2206 |
@SYMTestPriority High
|
sl@0
|
2207 |
@SYMTestActions 1. Create an inflate stream and set the next memory allocation to fail.
|
sl@0
|
2208 |
2. Initialise the stream using inflateBackInit() setting
|
sl@0
|
2209 |
windowBits to be between 8 and 15.
|
sl@0
|
2210 |
3. Check that the memory is the same before and after calling
|
sl@0
|
2211 |
inflateBackInit(). Note: If Z_OK is returned it will be
|
sl@0
|
2212 |
necessary to call inflateEnd() before checking the amount of memory.
|
sl@0
|
2213 |
4. Repeat this process until inflateBackInit() returns Z_OK,
|
sl@0
|
2214 |
increasing the number of allocations that can be performed before failing.
|
sl@0
|
2215 |
@SYMTestExpectedResults inflateBackInit () fails at first, returning Z_MEM_ERROR, and then
|
sl@0
|
2216 |
it will succeed with Z_OK. No memory should be leaked.
|
sl@0
|
2217 |
@SYMDEF REQ7362
|
sl@0
|
2218 |
*/
|
sl@0
|
2219 |
|
sl@0
|
2220 |
TVerdict CTestZlib::TestInflateBackInitFailsMem()
|
sl@0
|
2221 |
{
|
sl@0
|
2222 |
TInt err;
|
sl@0
|
2223 |
TVerdict verdict = EPass;
|
sl@0
|
2224 |
|
sl@0
|
2225 |
// Streams
|
sl@0
|
2226 |
z_stream inflateStream;
|
sl@0
|
2227 |
|
sl@0
|
2228 |
// inflateBackInit arguments
|
sl@0
|
2229 |
int inflateBackWindowBits = MAX_WBITS;
|
sl@0
|
2230 |
Bytef inflateWindow[32 * 1024];
|
sl@0
|
2231 |
|
sl@0
|
2232 |
inflateStream.zalloc = Z_NULL;
|
sl@0
|
2233 |
inflateStream.zfree = Z_NULL;
|
sl@0
|
2234 |
inflateStream.opaque = Z_NULL;
|
sl@0
|
2235 |
|
sl@0
|
2236 |
TInt failureRate;
|
sl@0
|
2237 |
for(failureRate = 1, err = Z_MEM_ERROR; err != Z_OK && failureRate <= FAILURE_RATE_LIMIT; failureRate++)
|
sl@0
|
2238 |
{
|
sl@0
|
2239 |
__UHEAP_SETFAIL(RHeap::EDeterministic, failureRate);
|
sl@0
|
2240 |
__UHEAP_MARK;
|
sl@0
|
2241 |
|
sl@0
|
2242 |
err = inflateBackInit(&inflateStream, inflateBackWindowBits, inflateWindow);
|
sl@0
|
2243 |
|
sl@0
|
2244 |
// Memory has been allocated so we need to clean up
|
sl@0
|
2245 |
if(err == Z_OK)
|
sl@0
|
2246 |
{
|
sl@0
|
2247 |
err = inflateBackEnd(&inflateStream);
|
sl@0
|
2248 |
if(err != Z_OK)
|
sl@0
|
2249 |
{
|
sl@0
|
2250 |
INFO_PRINTF2(_L("inflateBackInit error: %d"), err);
|
sl@0
|
2251 |
verdict = EAbort;
|
sl@0
|
2252 |
break;
|
sl@0
|
2253 |
}
|
sl@0
|
2254 |
}
|
sl@0
|
2255 |
else if(err != Z_MEM_ERROR)
|
sl@0
|
2256 |
{
|
sl@0
|
2257 |
INFO_PRINTF2(_L("inflateBackInit unexpected error: %d"), err);
|
sl@0
|
2258 |
verdict = EFail;
|
sl@0
|
2259 |
break;
|
sl@0
|
2260 |
}
|
sl@0
|
2261 |
|
sl@0
|
2262 |
__UHEAP_MARKEND;
|
sl@0
|
2263 |
__UHEAP_RESET;
|
sl@0
|
2264 |
}
|
sl@0
|
2265 |
|
sl@0
|
2266 |
if(err == Z_OK)
|
sl@0
|
2267 |
{
|
sl@0
|
2268 |
INFO_PRINTF2(_L("The test succeeded at heap failure rate = %d."), --failureRate);
|
sl@0
|
2269 |
}
|
sl@0
|
2270 |
else if(failureRate > FAILURE_RATE_LIMIT)
|
sl@0
|
2271 |
{
|
sl@0
|
2272 |
INFO_PRINTF1(_L("Exceeded FAILURE_RATE_LIMIT. Either the test has failed or the limit needs increasing."));
|
sl@0
|
2273 |
verdict = EFail;
|
sl@0
|
2274 |
}
|
sl@0
|
2275 |
|
sl@0
|
2276 |
return verdict;
|
sl@0
|
2277 |
}
|
sl@0
|
2278 |
|
sl@0
|
2279 |
/**
|
sl@0
|
2280 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4283
|
sl@0
|
2281 |
@SYMTestCaseDesc Check adler32_combine() generates the correct adler32 checksum.
|
sl@0
|
2282 |
@SYMTestPriority High
|
sl@0
|
2283 |
@SYMTestActions 1. Create two byte buffers, both containing different data, and
|
sl@0
|
2284 |
use these to create two checksums using adler32().
|
sl@0
|
2285 |
2. Create a third checksum using adler32_combine(), providing it
|
sl@0
|
2286 |
with the first two checksums and the length of the second checksum.
|
sl@0
|
2287 |
3. Concatenate the two byte buffers and create a fourth checksum
|
sl@0
|
2288 |
using adler32() and the concatenated buffer as input.
|
sl@0
|
2289 |
4. Compare the third and fourth checksums.
|
sl@0
|
2290 |
@SYMTestExpectedResults The third and fourth checksums should be identical.
|
sl@0
|
2291 |
@SYMDEF REQ7362
|
sl@0
|
2292 |
*/
|
sl@0
|
2293 |
|
sl@0
|
2294 |
TVerdict CTestZlib::TestAdler32CombineL()
|
sl@0
|
2295 |
{
|
sl@0
|
2296 |
// Byte buffers from which the adler32 checksums will be generated
|
sl@0
|
2297 |
const Byte *string1 = (Byte *)"Hello";
|
sl@0
|
2298 |
const Byte *string2 = (Byte *)"World";
|
sl@0
|
2299 |
const int string1Length = 5;
|
sl@0
|
2300 |
const int string2Length = 5;
|
sl@0
|
2301 |
const int string3Length = 10;
|
sl@0
|
2302 |
|
sl@0
|
2303 |
// Initialise the adler32 variables
|
sl@0
|
2304 |
uLong adlerString1 = adler32(0L, NULL, 0);
|
sl@0
|
2305 |
uLong adlerString2 = adler32(0L, NULL, 0);
|
sl@0
|
2306 |
uLong adlerString3 = adler32(0L, NULL, 0);
|
sl@0
|
2307 |
uLong adlerCombined;
|
sl@0
|
2308 |
|
sl@0
|
2309 |
// Generate the checksums from the byte buffers
|
sl@0
|
2310 |
adlerString1 = adler32(adlerString1, string1, string1Length);
|
sl@0
|
2311 |
adlerString2 = adler32(adlerString2, string2, string2Length);
|
sl@0
|
2312 |
|
sl@0
|
2313 |
// Generate the checksum from combining adlerString1 and adlerString2
|
sl@0
|
2314 |
adlerCombined = adler32_combine(adlerString1, adlerString2, string2Length);
|
sl@0
|
2315 |
|
sl@0
|
2316 |
// Concatenate the byte buffers so that a checksum can be generated
|
sl@0
|
2317 |
Byte string3[string3Length];
|
sl@0
|
2318 |
memcpy((char *)string3, (char *)string1, string1Length);
|
sl@0
|
2319 |
memcpy((char *)string3 + string1Length, (char *)string2, string2Length);
|
sl@0
|
2320 |
|
sl@0
|
2321 |
// Generate checksum
|
sl@0
|
2322 |
adlerString3 = adler32(adlerString3, string3, string3Length);
|
sl@0
|
2323 |
|
sl@0
|
2324 |
// Compare the checksums to see if they are the same
|
sl@0
|
2325 |
CHECK_CONDITION0L(adlerString3 != adlerCombined, KErrGeneral, "The combined checksum is not correct.");
|
sl@0
|
2326 |
|
sl@0
|
2327 |
return EPass;
|
sl@0
|
2328 |
}
|
sl@0
|
2329 |
|
sl@0
|
2330 |
/**
|
sl@0
|
2331 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4284
|
sl@0
|
2332 |
@SYMTestCaseDesc Check crc32_combine() generates the correct crc32 checksum.
|
sl@0
|
2333 |
@SYMTestPriority High
|
sl@0
|
2334 |
@SYMTestActions 1. Create two byte buffers, both containing different data, and
|
sl@0
|
2335 |
use these to create two checksums using crc32().
|
sl@0
|
2336 |
2. Create a third checksum using crc32_combine(), providing it
|
sl@0
|
2337 |
with the first two checksums and the length of the second checksum.
|
sl@0
|
2338 |
3. Concatenate the two byte buffers and create a fourth checksum
|
sl@0
|
2339 |
using crc32() and the concatenated buffer as input.
|
sl@0
|
2340 |
4. Compare the third and fourth checksums.
|
sl@0
|
2341 |
@SYMTestExpectedResults The third and fourth checksums should be identical.
|
sl@0
|
2342 |
@SYMDEF REQ7362
|
sl@0
|
2343 |
*/
|
sl@0
|
2344 |
|
sl@0
|
2345 |
TVerdict CTestZlib::TestCrc32CombineL()
|
sl@0
|
2346 |
{
|
sl@0
|
2347 |
// Byte buffers from which the crc32 checksums will be generated
|
sl@0
|
2348 |
const Byte *string1 = (Byte *)"Hello";
|
sl@0
|
2349 |
const Byte *string2 = (Byte *)"World";
|
sl@0
|
2350 |
const int string1Length = 5;
|
sl@0
|
2351 |
const int string2Length = 5;
|
sl@0
|
2352 |
const int string3Length = 10;
|
sl@0
|
2353 |
|
sl@0
|
2354 |
// Initialise the crc32 variables
|
sl@0
|
2355 |
uLong crcString1 = crc32(0L, NULL, 0);
|
sl@0
|
2356 |
uLong crcString2 = crc32(0L, NULL, 0);
|
sl@0
|
2357 |
uLong crcString3 = crc32(0L, NULL, 0);
|
sl@0
|
2358 |
uLong crcCombined;
|
sl@0
|
2359 |
|
sl@0
|
2360 |
// Generate the checksums from the byte buffers
|
sl@0
|
2361 |
crcString1 = crc32(crcString1, string1, string1Length);
|
sl@0
|
2362 |
crcString2 = crc32(crcString2, string2, string2Length);
|
sl@0
|
2363 |
|
sl@0
|
2364 |
// Generate the checksum from combining adlerString1 and adlerString2
|
sl@0
|
2365 |
crcCombined = crc32_combine(crcString1, crcString2, string2Length);
|
sl@0
|
2366 |
|
sl@0
|
2367 |
// Concatenate the byte buffers so that a checksum can be generated
|
sl@0
|
2368 |
Byte string3[string3Length];
|
sl@0
|
2369 |
memcpy((char *)string3, (char *)string1, string1Length);
|
sl@0
|
2370 |
memcpy((char *)string3 + string1Length, (char *)string2, string2Length);
|
sl@0
|
2371 |
|
sl@0
|
2372 |
// Generate checksum
|
sl@0
|
2373 |
crcString3 = crc32(crcString3, string3, string3Length);
|
sl@0
|
2374 |
|
sl@0
|
2375 |
// Compare the checksums to see if they are the same
|
sl@0
|
2376 |
CHECK_CONDITION0L(crcString3 != crcCombined, KErrGeneral, "The combined checksum is not correct.");
|
sl@0
|
2377 |
|
sl@0
|
2378 |
return EPass;
|
sl@0
|
2379 |
}
|
sl@0
|
2380 |
|
sl@0
|
2381 |
/**
|
sl@0
|
2382 |
@SYMTestCaseID SYSLIB-EZLIB2-UT-4284
|
sl@0
|
2383 |
@SYMTestCaseDesc Check zlibCompileFlags() returns a uLong with the correct
|
sl@0
|
2384 |
compile flags set.
|
sl@0
|
2385 |
@SYMTestPriority Medium
|
sl@0
|
2386 |
@SYMTestActions 1. Call zlibCompileFlags() and compare the first 2 bits with the
|
sl@0
|
2387 |
size of uInt, the second 2 bits with the size of uLong and
|
sl@0
|
2388 |
bits 16 and 17 with 0 (GZip APIs are being used).
|
sl@0
|
2389 |
@SYMTestExpectedResults zlibCompileFlags() will return a uLong and all the comparisons
|
sl@0
|
2390 |
will return true.
|
sl@0
|
2391 |
@SYMDEF REQ7362
|
sl@0
|
2392 |
*/
|
sl@0
|
2393 |
|
sl@0
|
2394 |
TVerdict CTestZlib::TestZlibCompileFlagsL()
|
sl@0
|
2395 |
{
|
sl@0
|
2396 |
// Get the compilerFlags
|
sl@0
|
2397 |
uLong compileFlags = zlibCompileFlags();
|
sl@0
|
2398 |
int compileFlagsUInt = compileFlags & 0x3;
|
sl@0
|
2399 |
int compileFlagsULong = (compileFlags >> 2) & 0x3;
|
sl@0
|
2400 |
int compileFlagsGZip = (compileFlags >> 15) & 0x3;
|
sl@0
|
2401 |
int machineUInt;
|
sl@0
|
2402 |
int machineULong;
|
sl@0
|
2403 |
|
sl@0
|
2404 |
// Get the size of uInt
|
sl@0
|
2405 |
switch(sizeof(uInt))
|
sl@0
|
2406 |
{
|
sl@0
|
2407 |
case 2: machineUInt = 0;
|
sl@0
|
2408 |
break;
|
sl@0
|
2409 |
case 4: machineUInt = 1;
|
sl@0
|
2410 |
break;
|
sl@0
|
2411 |
case 8: machineUInt = 2;
|
sl@0
|
2412 |
break;
|
sl@0
|
2413 |
default: machineUInt = 3;
|
sl@0
|
2414 |
}
|
sl@0
|
2415 |
|
sl@0
|
2416 |
// Check the compiler flag for uInt is correct
|
sl@0
|
2417 |
CHECK_CONDITION0L(machineUInt != compileFlagsUInt, KErrGeneral, "zlibCompileFlags reports an incorrect size for uInt.");
|
sl@0
|
2418 |
|
sl@0
|
2419 |
// Get the size of uLong
|
sl@0
|
2420 |
switch(sizeof(uLong))
|
sl@0
|
2421 |
{
|
sl@0
|
2422 |
case 2: machineULong = 0;
|
sl@0
|
2423 |
break;
|
sl@0
|
2424 |
case 4: machineULong = 1;
|
sl@0
|
2425 |
break;
|
sl@0
|
2426 |
case 8: machineULong = 2;
|
sl@0
|
2427 |
break;
|
sl@0
|
2428 |
default: machineULong = 3;
|
sl@0
|
2429 |
}
|
sl@0
|
2430 |
|
sl@0
|
2431 |
// Check the compiler flag for uLong is correct
|
sl@0
|
2432 |
CHECK_CONDITION0L(machineULong != compileFlagsULong, KErrGeneral, "zlibCompileFlags reports an incorrect size for uLong.");
|
sl@0
|
2433 |
|
sl@0
|
2434 |
// Check the compiler flags for GZip compression are correct
|
sl@0
|
2435 |
CHECK_CONDITION0L(compileFlagsGZip != 0, KErrGeneral, "zlibCompileFlags reports GZip functionality is disabled.");
|
sl@0
|
2436 |
|
sl@0
|
2437 |
return EPass;
|
sl@0
|
2438 |
}
|