First public contribution.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Name : tzlibadvanced.cpp
20 //#include "deflate.h"
22 #define COMPRESSED_DATA_BUFFER_LENGTH 200*sizeof(int)
23 #define FAILURE_RATE_LIMIT 100
24 #define TEST_MID_MEM_LEVEL 5
26 // Add this to the windowBits value to use a GZip header instead of a Zlib header
27 #define TEST_GZIP_HEADER 16
29 // Add this to the windowBits when calling inflateInit2() to use automatic header detection
30 #define TEST_AUTO_HEADER_DETECTION 32
32 #define CHECK_CONDITION0L(condition, leaveErr, errMessage) \
35 ERR_PRINTF1(_L(errMessage)); \
36 User::Leave(leaveErr); \
39 #define CHECK_CONDITION1L(condition, leaveErr, errMessage, p1) \
42 ERR_PRINTF2(_L(errMessage), p1); \
43 User::Leave(leaveErr); \
46 _LIT(KParam1, "Param1");
47 _LIT(KParam2, "Param2");
48 _LIT(KParam3, "Param3");
49 _LIT(KParam4, "Param4");
51 // bufferDescriptor holds extra information required by in_func and out_func to perform their jobs
52 struct bufferDescriptor
60 * Helper member function that sets up the deflate stream for use.
62 void CTestZlib::DeflateInitL(z_stream &aStream, const int aLevel, const int expectedResult)
66 aStream.zalloc = Z_NULL;
67 aStream.zfree = Z_NULL;
68 aStream.opaque = Z_NULL;
70 err = deflateInit(&aStream, aLevel);
71 CHECK_CONDITION1L(err != expectedResult, KErrNoMemory, "deflateInit error: %d", err);
75 * Helper member function that sets up the deflate stream for use.
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)
81 aStream.zalloc = Z_NULL;
82 aStream.zfree = Z_NULL;
83 aStream.opaque = Z_NULL;
85 err = deflateInit2(&aStream, aLevel, aMethod, aWindowBits, aMemLevel, aStrategy);
86 CHECK_CONDITION1L(err != expectedResult, KErrNoMemory, "deflateInit2 error: %d", err);
90 * Helper member function that compresses data using the deflate function.
92 TInt CTestZlib::DeflateCompress(z_stream &aStream, Byte *aInputData, int aInputDataLength, Byte *aCompressedDataBuffer, int aCompressedDataBufferLength)
97 // Compress data in the input buffer and place compressed data in the output buffer
98 aStream.next_in = aInputData;
99 aStream.next_out = aCompressedDataBuffer;
103 if (aStream.total_in < aInputDataLength)
105 aStream.avail_in = 1; // force small buffer
108 flush = (aStream.total_in == aInputDataLength) ? Z_FINISH : Z_NO_FLUSH;
110 // Run deflate() on input until output buffer not full
111 // Finish compression if all of input buffer has been read in
114 if (aStream.total_out < aCompressedDataBufferLength)
116 aStream.avail_out = 1; // force small buffer
119 err = deflate(&aStream, flush);
120 if(err != Z_OK && err != Z_STREAM_END)
124 } while(aStream.avail_out == 0 && err == Z_OK);
125 } while(err != Z_STREAM_END);
131 * Helper member function that cleans up a deflate stream.
133 void CTestZlib::DeflateEnd(TAny *aStream)
135 if(((z_stream *)aStream)->state != NULL)
137 deflateEnd((z_stream *)aStream);
142 * Helper member function that sets up the inflate stream for use.
144 void CTestZlib::InflateInitL(z_stream &aStream, const int expectedResult)
148 aStream.zalloc = Z_NULL;
149 aStream.zfree = Z_NULL;
150 aStream.opaque = Z_NULL;
152 err = inflateInit(&aStream);
153 CHECK_CONDITION1L(err != expectedResult, KErrNoMemory, "inflateInit error: %d", err);
157 * Helper member function that sets up the inflate stream for use.
159 void CTestZlib::InflateInit2L(z_stream &aStream, const int aWindowBits, const int expectedResult)
163 aStream.zalloc = Z_NULL;
164 aStream.zfree = Z_NULL;
165 aStream.opaque = Z_NULL;
167 err = inflateInit2(&aStream, aWindowBits);
168 CHECK_CONDITION1L(err != expectedResult, KErrNoMemory, "inflateInit2 error: %d", err);
171 void CTestZlib::InflateBackInitL(z_stream &aStream, const int aWindowBits, Bytef *aWindow, const int expectedResult)
175 aStream.zalloc = Z_NULL;
176 aStream.zfree = Z_NULL;
177 aStream.opaque = Z_NULL;
179 err = inflateBackInit(&aStream, aWindowBits, aWindow);
180 CHECK_CONDITION1L(err != expectedResult, KErrNoMemory, "inflateBackInit error: %d", err);
184 * Helper member function that decompresses data using the inflate function.
186 TInt CTestZlib::InflateDecompress(z_stream &aStream, Byte *aCompressedDataBuffer, int aCompressedDataLength, Byte *aDecompressedDataBuffer, int aDecompressedDataBufferLength)
190 // Decompress data in the aCompressedDataBuffer and place it in the aDecompressedDataBuffer
191 aStream.next_in = aCompressedDataBuffer;
192 aStream.next_out = aDecompressedDataBuffer;
194 // Keep providing input data and output space for deflate()
197 if(aStream.total_in < aCompressedDataLength)
199 aStream.avail_in = 1; // force small buffer
202 if (aStream.total_out < aDecompressedDataBufferLength)
204 aStream.avail_out = 1; // force small buffer
207 err = inflate(&aStream, Z_NO_FLUSH);
208 if(err != Z_OK && err != Z_STREAM_END)
212 } while(err != Z_STREAM_END);
218 * Helper member function that cleans up a inflate stream.
220 void CTestZlib::InflateEnd(TAny *aStream)
222 if(((z_stream *)aStream)->state != NULL)
224 inflateEnd((z_stream *)aStream);
229 * Helper member function that cleans up an inflate back stream.
231 void CTestZlib::InflateBackEnd(TAny *aStream)
233 if(((z_stream *)aStream)->state != NULL)
235 inflateBackEnd((z_stream *)aStream);
240 * Helper member function that compares the contents of two GZip headers to make
241 * sure they are the same.
243 TBool CTestZlib::GZipHeadersEqual(const gz_header &header1, const gz_header &header2)
245 TBool headersEqual = true;
247 if(header1.text != header2.text)
249 INFO_PRINTF3(_L("readGZipHeader.text - Expected %d and got %d"), header1.text, header2.text);
250 headersEqual = false;
253 if(header1.time != header2.time)
255 INFO_PRINTF3(_L("readGZipHeader.time - Expected %d and got %d"), header1.time, header2.time);
256 headersEqual = false;
259 if(header1.xflags != header2.xflags)
261 INFO_PRINTF3(_L("readGZipHeader.xflags - Expected %d and got %d"), header1.xflags, header2.xflags);
262 headersEqual = false;
265 if(header1.os != header2.os)
267 INFO_PRINTF3(_L("readGZipHeader.os - Expected %d and got %d"), header1.os, header2.os);
268 headersEqual = false;
271 if(header1.extra != NULL & header2.extra != NULL)
273 if(header1.extra_len != header2.extra_len)
275 INFO_PRINTF1(_L("readGZipHeader.extra_len - Unexpected value."));
276 headersEqual = false;
278 else if(memcmp(header1.extra, header2.extra, header1.extra_len) != 0)
280 INFO_PRINTF1(_L("readGZipHeader.extra - Unexpected value."));
281 headersEqual = false;
284 else if(header1.extra == NULL && header2.extra != NULL
285 || header1.extra != NULL && header2.extra == NULL)
287 INFO_PRINTF1(_L("readGZipHeader.extra - Unexpected value."));
288 headersEqual = false;
291 if(header1.name != NULL && header2.name != NULL)
293 if(strcmp((char *)header1.name, (char *)header2.name) != 0)
295 INFO_PRINTF1(_L("readGZipHeader.name - Unexpected value. The headers contained different strings."));
296 headersEqual = false;
299 else if((header1.name == NULL && header2.name != NULL)
300 || (header1.name != NULL && header2.name == NULL))
302 INFO_PRINTF1(_L("readGZipHeader.name - Unexpected value. One of the headers contained a NULL value."));
303 headersEqual = false;
306 if(header1.comment != NULL && header2.comment != NULL)
308 if(strcmp((char *)header1.comment, (char *)header2.comment) != 0)
310 INFO_PRINTF1(_L("readGZipHeader.comment - Unexpected value. The headers contained different strings."));
311 headersEqual = false;
314 else if((header1.comment == NULL && header2.comment != NULL)
315 || (header1.comment != NULL && header2.comment == NULL))
317 INFO_PRINTF1(_L("readGZipHeader.comment - Unexpected value. One of the headers contained a NULL value."));
318 headersEqual = false;
321 if(header1.hcrc != header2.hcrc)
323 INFO_PRINTF3(_L("readGZipHeader.hcrc - Expected %d and got %d"), header1.hcrc, header2.hcrc);
324 headersEqual = false;
327 if(header1.done != header2.done)
329 INFO_PRINTF3(_L("readGZipHeader.done - Expected %d and got %d"), header1.done, header2.done);
330 headersEqual = false;
337 * Helper member function that checks to see if the header is the default GZip header
339 TBool CTestZlib::IsDefaultGZipHeader(const gz_header &header)
341 gz_header defaultHeader;
343 // gz_header default values
344 defaultHeader.text = 0;
345 defaultHeader.time = 0;
346 defaultHeader.xflags = 0;
347 defaultHeader.os = OS_CODE;
348 defaultHeader.extra = NULL;
349 defaultHeader.name = NULL;
350 defaultHeader.comment = NULL;
351 defaultHeader.hcrc = 0;
352 defaultHeader.done = 1;
354 return GZipHeadersEqual(defaultHeader, header);
358 * Helper member function that compresses an input buffer and place it in a compressed output buffer
360 void CTestZlib::CompressDataL(StreamSettings &aStreamSettings, z_stream &aStream, Byte *aInputData, int aInputDataLength, Byte *aCompressedDataBuffer, int aCompressedDataBufferLength, gz_headerp aHeader)
364 // Initialise the deflate stream
365 if(aStreamSettings.deflateInit2 == false)
367 this->DeflateInitL(aStream, aStreamSettings.level);
371 this->DeflateInit2L(aStream, aStreamSettings.level, aStreamSettings.method, aStreamSettings.deflateWindowBits, aStreamSettings.memLevel, aStreamSettings.strategy);
373 CleanupStack::PushL(TCleanupItem(DeflateEnd, &aStream));
375 // If a GZip header is specified insert the gzip header information to the
376 // start of the output when deflate is called
379 err = deflateSetHeader(&aStream, aHeader);
380 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflateSetHeader error: %d", err);
383 // Compress the input
384 err = this->DeflateCompress(aStream, aInputData, aInputDataLength, aCompressedDataBuffer, aCompressedDataBufferLength);
385 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflate error: %d", err);
387 // Clean up the deflateStream
388 err = deflateEnd(&aStream);
389 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflateEnd error: %d", err);
390 CleanupStack::Pop(1);
394 * Helper function that deflates some input data as a gzip stream and then inflates
395 * the compressed data.
397 TVerdict CTestZlib::DefInfGZipHeaderL(const TBool aIgnoreHeader, const TBool aAutoDetectHeader, gz_headerp aSpecifiedGZipHeader)
400 TVerdict verdict = EPass;
403 z_stream deflateStream;
404 z_stream inflateStream;
407 gz_header readGZipHeader;
408 readGZipHeader.extra = NULL;
409 readGZipHeader.name = NULL;
410 readGZipHeader.comment = NULL;
413 const char inputData[] = "This is a piece of data to compress.\0"; // data to compress
414 uLong inputDataLength = (uLong)strlen(inputData) + 1;
415 Byte *compressedDataBuffer = NULL;
416 uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
417 Byte *decompressedDataBuffer = NULL;
418 uLong decompressedDataBufferLength = inputDataLength;
420 // deflateInit2 and inflateInit2 arguments
421 StreamSettings streamSettings;
422 streamSettings.deflateInit2 = true;
423 streamSettings.level = Z_DEFAULT_COMPRESSION;
424 streamSettings.method = Z_DEFLATED;
425 streamSettings.deflateWindowBits = MAX_WBITS + TEST_GZIP_HEADER;
426 streamSettings.inflateWindowBits = MAX_WBITS;
427 streamSettings.memLevel = TEST_MID_MEM_LEVEL;
428 streamSettings.strategy = Z_DEFAULT_STRATEGY;
430 streamSettings.inflateWindowBits += (aAutoDetectHeader == true) ? TEST_AUTO_HEADER_DETECTION : TEST_GZIP_HEADER;
432 compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
433 CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
434 CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
436 decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
437 CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
438 CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
440 // Allocate memory, if required, for readGZipHeader if header data is being
441 // checked and if a specified GZip header has been given. This is because
442 // extra, name and comment may have been set in the specified GZip header.
443 if(aIgnoreHeader == false && aSpecifiedGZipHeader != NULL)
445 if(aSpecifiedGZipHeader->extra != NULL)
447 readGZipHeader.extra_max = aSpecifiedGZipHeader->extra_max;
448 readGZipHeader.extra = (Bytef *)User::AllocZ(aSpecifiedGZipHeader->extra_max * sizeof(Bytef));
449 CHECK_CONDITION0L(readGZipHeader.extra == NULL, KErrNoMemory, "Failed to allocate memory for readGZipHeader.extra.");
450 CleanupStack::PushL(TCleanupItem(User::Free, readGZipHeader.extra));
453 if(aSpecifiedGZipHeader->name != NULL)
455 readGZipHeader.name_max = aSpecifiedGZipHeader->name_max;
456 readGZipHeader.name = (Bytef *)User::AllocZ(aSpecifiedGZipHeader->name_max * sizeof(Bytef));
457 CHECK_CONDITION0L(readGZipHeader.name == NULL, KErrNoMemory, "Failed to allocate memory for readGZipHeader.name.");
458 CleanupStack::PushL(TCleanupItem(User::Free, readGZipHeader.name));
461 if(aSpecifiedGZipHeader->comment != NULL)
463 readGZipHeader.comm_max = aSpecifiedGZipHeader->comm_max;
464 readGZipHeader.comment = (Bytef *)User::AllocZ(aSpecifiedGZipHeader->comm_max * sizeof(Bytef));
465 CHECK_CONDITION0L(readGZipHeader.comment == NULL, KErrNoMemory, "Failed to allocate memory for readGZipHeader.comment.");
466 CleanupStack::PushL(TCleanupItem(User::Free, readGZipHeader.comment));
469 this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength, aSpecifiedGZipHeader);
471 // Initialise the inflateStream
472 this->InflateInit2L(inflateStream, streamSettings.inflateWindowBits);
473 CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
475 // If the header information is not to be ignored get the GZip
476 // header information when inflate is called
477 if(aIgnoreHeader == false)
479 err = inflateGetHeader(&inflateStream, &readGZipHeader);
480 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateGetHeader error: %d", err);
483 err = this->InflateDecompress(inflateStream, compressedDataBuffer, deflateStream.total_out, decompressedDataBuffer, decompressedDataBufferLength);
484 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflate error: %d", err);
486 // Clean up the inflateStream
487 err = inflateEnd(&inflateStream);
488 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateEnd error: %d", err);
489 CleanupStack::Pop(1);
491 // If the header information hasn't been ignored Check the GZip header
492 // contains the expected information
493 if(aIgnoreHeader == false)
495 if(aSpecifiedGZipHeader != NULL)
497 verdict = GZipHeadersEqual(*aSpecifiedGZipHeader, readGZipHeader) ? EPass : EFail;
501 verdict = IsDefaultGZipHeader(readGZipHeader) ? EPass : EFail;
505 if(readGZipHeader.comment != NULL)
507 CleanupStack::PopAndDestroy(1);
510 if(readGZipHeader.name != NULL)
512 CleanupStack::PopAndDestroy(1);
515 if(readGZipHeader.extra != NULL)
517 CleanupStack::PopAndDestroy(1);
521 CleanupStack::PopAndDestroy(2);
527 * Helper function that deflates some input data as a gzip stream with a specified header
528 * and then inflates the compressed data.
530 TVerdict CTestZlib::DefInfGZipSpecifiedHeaderL(TBool aIgnoreHeader, TBool aAutoDetectHeader)
532 gz_header specifiedGZipHeader;
534 Bytef extra[] = "12345";
535 Bytef name[] = "TestDefInfGZipSpecifiedHeaderManual\0";
536 Bytef comment[] = "This is a test comment.\0";
538 // gz_header user specified values. Set the specifiedGZipHeader ready for deflateSetHeader
539 specifiedGZipHeader.text = 1;
540 specifiedGZipHeader.time = 101;
541 specifiedGZipHeader.xflags = 0; // Set so that the value can be compared to the value in the header read from the deflated data
542 specifiedGZipHeader.os = 1; // Amiga
543 specifiedGZipHeader.extra = extra;
544 specifiedGZipHeader.extra_len = TEST_MID_MEM_LEVEL;
545 specifiedGZipHeader.extra_max = specifiedGZipHeader.extra_len + 10; // Add extra 10 to check readGZipHeader.extra_len is set properly
546 specifiedGZipHeader.name = name;
547 specifiedGZipHeader.name_max = strlen((char *)name) + 1;
548 specifiedGZipHeader.comment = comment;
549 specifiedGZipHeader.comm_max = strlen((char *)comment) + 1;
550 specifiedGZipHeader.hcrc = 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
553 return DefInfGZipHeaderL(aIgnoreHeader, aAutoDetectHeader, &specifiedGZipHeader);
557 @SYMTestCaseID SYSLIB-EZLIB2-UT-4259
558 @SYMTestCaseDesc To ensure deflation works after tuning the deflate stream using
560 @SYMTestPriority Medium
561 @SYMTestActions 1. Create a stream and initialise it.
562 2. Call deflateTune() passing it the specified parameters.
563 3. Check the state of the stream to make sure that the values
564 are identical to the specified parameters. Also check that
566 4. Deflate the input and cleanup using deflateEnd(), checking
569 Note: The test should be repeated for deflateInit() parameter values:
572 and for deflateTune() parameter values:
573 • 0 and a high value for good_length
574 • 0 and a high value for max_lazy
575 • 0 and a high value for nice_length
576 • 0 and a high value for max_chain
577 Appropriate high values can be picked based on the global
578 configuration_table array in deflate.cpp.
579 @SYMTestExpectedResults deflateTune() should return Z_OK and the input should be compressed.
582 TVerdict CTestZlib::TestDeflateTuneL()
588 z_stream deflateStream;
591 const char inputData[] = "This is a piece of data to compress.\0";
592 uLong inputDataLength = (uLong)strlen(inputData) + 1;
593 Byte *compressedDataBuffer;
595 // deflateInit arguments
596 uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
597 int level = Z_DEFAULT_COMPRESSION;
603 // Allocate memory for output buffer
604 compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
605 CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for output buffer.");
606 CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
608 // Read in the values for deflate tune from the ini file
609 ret = GetIntFromConfig(ConfigSection(), KParam1, goodLength);
610 CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param1 from ini file");
612 ret = GetIntFromConfig(ConfigSection(), KParam2, maxLazy);
613 CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param2 from ini file");
615 ret = GetIntFromConfig(ConfigSection(), KParam3, niceLength);
616 CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param3 from ini file");
618 ret = GetIntFromConfig(ConfigSection(), KParam4, maxChain);
619 CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param4 from ini file");
621 // Initialise the stream
622 this->DeflateInitL(deflateStream, level);
623 CleanupStack::PushL(TCleanupItem(DeflateEnd, &deflateStream));
625 // Tune the deflate stream
626 err = deflateTune(&deflateStream, goodLength, maxLazy, niceLength, maxChain);
627 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflateTune error: %d", err);
629 // Check deflateTune has set the streams state values correctly
631 internal_state *s = deflateStream.state;
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");
635 err = this->DeflateCompress(deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
636 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflate error: %d", err);
638 // Clean up the deflate stream
639 err = deflateEnd(&deflateStream);
640 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflateEnd error: %d", err);
641 CleanupStack::Pop(1);
644 CleanupStack::PopAndDestroy(1);
650 @SYMTestCaseID SYSLIB-EZLIB2-UT-4260
651 @SYMTestCaseDesc Check deflateTune() fails when given an invalid stream.
652 @SYMTestPriority Medium
653 @SYMTestActions 1. Create a stream and initialise it.
654 2. Call deflateTune() passing it parameter values:
655 a. NULL for the stream argument
656 b. a stream whose state is NULL for the stream argument
657 @SYMTestExpectedResults deflateTune() fails returning Z_STREAM_ERROR in both cases.
661 TVerdict CTestZlib::TestDeflateTuneFailL()
666 z_stream deflateStream;
668 // deflateInit2 arguments
669 int level = Z_DEFAULT_COMPRESSION;
671 // Initialise the stream
672 this->DeflateInitL(deflateStream, level);
673 CleanupStack::PushL(TCleanupItem(DeflateEnd, &deflateStream));
675 // Try tuning a NULL deflate stream
676 err = deflateTune(NULL, 0, 0, 0, 0);
677 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflateTune on a NULL stream returned an unexpected value: %d", err);
679 // Keep a pointer to the streams state so we can clean up properly with deflateEnd()
680 internal_state *deflateState = deflateStream.state;
682 // Try tuning a deflate stream that has a NULL state
683 deflateStream.state = NULL;
684 err = deflateTune(&deflateStream, 0, 0, 0, 0);
685 deflateStream.state = deflateState;
686 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflateTune on a stream with a NULL state returned an unexpected value: %d", err);
688 // Clean up the deflate stream
689 err = deflateEnd(&deflateStream);
690 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflateEnd error: %d", err);
691 CleanupStack::Pop(1);
697 @SYMTestCaseID SYSLIB-EZLIB2-UT-4261
698 @SYMTestCaseDesc Check input can be compressed and decompressed with default gzip
699 header not being read.
700 @SYMTestPriority High
701 @SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
702 adding 16 to windowBits.
703 2. Deflate the input and cleanup using deflateEnd().
704 3. Create an inflate stream and initialise it using inflateInit2(),
705 adding 16 to windowBits.
706 4. Inflate the input and cleanup using inflateEnd().
707 @SYMTestExpectedResults The data should be compressed with deflateEnd() returning Z_OK and
708 decompressed with inflateEnd() returning Z_OK. There should be no
709 header information stored.
713 TVerdict CTestZlib::TestDefInfGZipDefaultHeaderIgnoreL()
715 return DefInfGZipHeaderL(true, false, NULL);
719 @SYMTestCaseID SYSLIB-EZLIB2-UT-4262
720 @SYMTestCaseDesc Check input can be compressed and decompressed with default gzip
721 header being read using automatic header detection.
722 @SYMTestPriority High
723 @SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
724 adding 16 to windowBits.
725 2. Deflate the input and cleanup using deflateEnd().
726 3. Create an inflate stream and initialise it using inflateInit2(),
727 adding 32 to windowBits.
728 4. Use inflateGetHeader() to get the default header information
729 and make sure the gzip header information is set correctly.
730 5. Inflate the input and cleanup using inflateEnd().
731 @SYMTestExpectedResults The data should be compressed with deflateEnd() returning Z_OK and
732 decompressed with inflateEnd() returning Z_OK. There should be
733 correct header information stored.
737 TVerdict CTestZlib::TestDefInfGZipDefaultHeaderAutoL()
739 return DefInfGZipHeaderL(false, true, NULL);
743 @SYMTestCaseID SYSLIB-EZLIB2-UT-4263
744 @SYMTestCaseDesc Check input can be compressed and decompressed with specified gzip
746 @SYMTestPriority High
747 @SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
748 adding 16 to windowBits.
749 2. Use deflateSetHeader() to specify header information and check
750 that the gzip header information is set correctly.
751 3. Deflate the input and cleanup using deflateEnd().
752 4. Create an inflate stream and initialise it using inflateInit2(),
753 adding 16 to windowBits.
754 5. Use inflateGetHeader() to get the header information and make
755 sure that it matches the header information originally entered.
756 6. Inflate the input and cleanup using inflateEnd().
757 @SYMTestExpectedResults The data should be compressed with deflateEnd() returning Z_OK and
758 the header details being set correctly. The data should also be
759 decompressed with inflateEnd() returning Z_OK and the header details
760 matching the original header information. There should also be header
765 TVerdict CTestZlib::TestDefInfGZipSpecifiedHeaderManualL()
767 return DefInfGZipSpecifiedHeaderL(false, false);
771 @SYMTestCaseID SYSLIB-EZLIB2-UT-4264
772 @SYMTestCaseDesc Check input can be compressed and decompressed with specified gzip
773 header being read using automatic header detection.
774 @SYMTestPriority High
775 @SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
776 adding 16 to windowBits.
777 2. Use deflateSetHeader() to specify header information and check
778 that the gzip header information is set correctly.
779 3. Deflate the input and cleanup using deflateEnd().
780 4. Create an inflate stream and initialise it using inflateInit2(),
781 adding 32 to windowBits.
782 5. Use inflateGetHeader() to get the header information and make
783 sure that it matches the header information originally entered.
784 6. Inflate the input and cleanup using inflateEnd().
785 @SYMTestExpectedResults The data should be compressed with deflateEnd() returning Z_OK and
786 the header details being set correctly. The data should also be
787 decompressed with inflateEnd() returning Z_OK and the header details
788 matching the original header information. There should also be header
793 TVerdict CTestZlib::TestDefInfGZipSpecifiedHeaderAutoL()
795 return DefInfGZipSpecifiedHeaderL(false, true);
799 @SYMTestCaseID SYSLIB-EZLIB2-UT-4265
800 @SYMTestCaseDesc Check input can be compressed and decompressed with zlib header
801 using automatic header detection.
802 @SYMTestPriority High
803 @SYMTestActions 1. Create a deflate stream and initialise it.
804 2. Deflate the input and cleanup using deflateEnd().
805 3. Create an inflate stream and initialise it using inflateInit2(),
806 adding 32 to windowBits.
807 4. Inflate the input and cleanup using inflateEnd().
808 @SYMTestExpectedResults The data should be compressed with deflateEnd() returning Z_OK
809 and decompressed with inflateEnd returning Z_OK.
813 TVerdict CTestZlib::TestDefInfZlibHeaderAutoL()
818 z_stream deflateStream;
819 z_stream inflateStream;
822 StreamSettings streamSettings;
823 streamSettings.deflateInit2 = false;
824 streamSettings.level = Z_DEFAULT_COMPRESSION;
825 streamSettings.inflateWindowBits = MAX_WBITS + TEST_AUTO_HEADER_DETECTION;
828 const char inputData[] = "This is a piece of data to compress.\0"; // data to compress
829 uLong inputDataLength = (uLong)strlen(inputData) + 1;
830 Byte *compressedDataBuffer = NULL;
831 uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
832 Byte *decompressedDataBuffer = NULL;
833 uLong decompressedDataBufferLength = inputDataLength;
835 // Allocate memory for buffers
836 compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
837 CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
838 CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
840 decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
841 CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
842 CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
844 this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
846 // Initialise the inflateStream
847 this->InflateInit2L(inflateStream, streamSettings.inflateWindowBits);
848 CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
850 err = this->InflateDecompress(inflateStream, compressedDataBuffer, deflateStream.total_out, decompressedDataBuffer, decompressedDataBufferLength);
851 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflate error: %d", err);
853 // Clean up the inflateStream
854 err = inflateEnd(&inflateStream);
855 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateEnd error: %d", err);
856 CleanupStack::Pop(1);
858 CleanupStack::PopAndDestroy(2);
863 @SYMTestCaseID SYSLIB-EZLIB2-UT-4266
864 @SYMTestCaseDesc Check deflateSetHeader() fails when given an invalid stream.
865 @SYMTestPriority High
866 @SYMTestActions 1. Create a stream and initialise it using deflateInit2(), adding
868 2. Call deflateSetHeader() passing it parameter values:
869 a. NULL for the stream argument
870 b. a stream whose state is set to NULL for the stream argument
871 c. a zlib stream for the stream argument
872 d. a raw stream for the stream argument
873 @SYMTestExpectedResults deflateSetHeader() fails returning Z_STREAM_ERROR in all four cases.
877 TVerdict CTestZlib::TestDeflateSetHeaderFailsL()
882 z_stream gZipDeflateStream;
883 z_stream zLibDeflateStream;
884 z_stream rawDeflateStream;
887 gz_header specifiedGZipHeader;
890 const char inputData[] = "This is a piece of data to compress.\0";
891 uLong inputDataLength = (uLong)strlen(inputData) + 1;
892 Byte *compressedDataBuffer;
893 uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
895 // deflateInit2 arguments
896 int level = Z_DEFAULT_COMPRESSION;
897 int method = Z_DEFLATED;
898 int gZipDeflateWindowBits = MAX_WBITS + TEST_GZIP_HEADER;
899 int memLevel = TEST_MID_MEM_LEVEL;
900 int strategy = Z_DEFAULT_STRATEGY;
902 // GZip header user specified values
903 Bytef extra[] = "12345";
904 Bytef name[] = "TestDefInfGZipSpecifiedHeaderManual\0";
905 Bytef comment[] = "This is a test comment.\0";
907 // Set the specifiedGZipHeader ready for deflateSetHeader
908 specifiedGZipHeader.text = 1;
909 specifiedGZipHeader.time = 101;
910 specifiedGZipHeader.os = 1;
911 specifiedGZipHeader.extra = extra;
912 specifiedGZipHeader.extra_len = 5;
913 specifiedGZipHeader.extra_max = specifiedGZipHeader.extra_len + 10; // Add extra 10 to check readGZipHeader.extra_len is set properly
914 specifiedGZipHeader.name = name;
915 specifiedGZipHeader.name_max = strlen((char *)name) + 1;
916 specifiedGZipHeader.comment = comment;
917 specifiedGZipHeader.comm_max = strlen((char *)comment) + 1;
918 specifiedGZipHeader.hcrc = 0;
920 // Allocate memory for buffers
921 compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
922 CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
923 CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
925 // Initialise the deflate streams
926 this->DeflateInit2L(gZipDeflateStream, level, method, gZipDeflateWindowBits, memLevel, strategy);
927 CleanupStack::PushL(TCleanupItem(DeflateEnd, &gZipDeflateStream));
929 this->DeflateInitL(zLibDeflateStream, level);
930 CleanupStack::PushL(TCleanupItem(DeflateEnd, &zLibDeflateStream));
932 this->DeflateInit2L(rawDeflateStream, level, method, -MAX_WBITS, memLevel, strategy);
933 CleanupStack::PushL(TCleanupItem(DeflateEnd, &rawDeflateStream));
935 // Try setting a NULL streams header
936 err = deflateSetHeader(NULL, &specifiedGZipHeader);
937 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflateSetHeader on a NULL stream returned an unexpected value: %d", err);
939 // Try setting the header for a deflate stream that has a NULL state
940 // we must keep a pointer to the streams state so we can clean up properly with deflateEnd
941 internal_state *deflateState = gZipDeflateStream.state;
942 gZipDeflateStream.state = NULL;
944 err = deflateSetHeader(&gZipDeflateStream, &specifiedGZipHeader);
946 gZipDeflateStream.state = deflateState;
947 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflateSetHeader on a stream with a NULL state returned an unexpected value: %d", err);
949 // Try setting a header for a zlib stream
950 err = deflateSetHeader(&zLibDeflateStream, &specifiedGZipHeader);
951 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflateSetHeader on a zlib stream returned an unexpected value: %d", err);
953 // Try setting a header for a raw stream
954 err = deflateSetHeader(&rawDeflateStream, &specifiedGZipHeader);
955 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflateSetHeader on a raw stream returned an unexpected value: %d", err);
957 // Clean up the deflate streams
958 err = deflateEnd(&gZipDeflateStream);
959 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "gZipDeflateStream - deflateEnd error: %d", err);
961 err = deflateEnd(&zLibDeflateStream);
962 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "zLibDeflateStream - deflateEnd error: %d", err);
964 // deflateInit2() leaves a raw stream in a busy state. This results in deflateEnd()
965 // returning a Z_DATA_ERROR, unless deflate() has been called on the stream.
966 err = deflateEnd(&rawDeflateStream);
967 CHECK_CONDITION1L(err != Z_DATA_ERROR, KErrGeneral, "rawDeflateStream - deflateEnd error: %d", err);
969 CleanupStack::Pop(3);
970 CleanupStack::PopAndDestroy(1);
975 @SYMTestCaseID SYSLIB-EZLIB2-UT-4267
976 @SYMTestCaseDesc Check inflateGetHeader() fails when given an invalid gzip stream.
977 @SYMTestPriority High
978 @SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(), adding 16 to windowBits.
979 2. Deflate the input and cleanup using deflateEnd().
980 3. Create an inflate stream and initialise it using inflateInit2(), adding 16 to windowBits.
981 4. Call inflateGetHeader() passing it parameter values:
982 e. NULL for the stream argument
983 f. a stream whose state is set to NULL for the stream argument
984 g. a zlib stream for the stream argument
985 h. a raw stream for the stream argument
986 @SYMTestExpectedResults inflateGetHeader() should fail returning Z_STREAM_ERROR for the
987 first 2 cases and Z_DATA_ERROR for the second 2 case.
991 TVerdict CTestZlib::TestInflateGetHeaderFailsL()
996 z_stream gZipDeflateStream;
997 z_stream zLibDeflateStream;
998 z_stream rawDeflateStream;
999 z_stream gZipInflateStream;
1000 z_stream zLibInflateStream;
1001 z_stream rawInflateStream;
1004 gz_header gZipHeader;
1007 const char inputData[] = "This is a piece of data to compress.\0";
1008 uLong inputDataLength = (uLong)strlen(inputData) + 1;
1009 Byte *gZipCompressedDataBuffer = NULL;
1010 Byte *zLibCompressedDataBuffer = NULL;
1011 Byte *rawCompressedDataBuffer = NULL;
1012 uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
1014 // deflateInit2 and inflateInit2 arguments
1015 StreamSettings gZipStreamSettings;
1016 gZipStreamSettings.deflateInit2 = true;
1017 gZipStreamSettings.level = Z_DEFAULT_COMPRESSION;
1018 gZipStreamSettings.method = Z_DEFLATED;
1019 gZipStreamSettings.deflateWindowBits = MAX_WBITS + TEST_GZIP_HEADER;
1020 gZipStreamSettings.inflateWindowBits = MAX_WBITS + TEST_GZIP_HEADER;
1021 gZipStreamSettings.memLevel = TEST_MID_MEM_LEVEL;
1022 gZipStreamSettings.strategy = Z_DEFAULT_STRATEGY;
1024 StreamSettings zLibStreamSettings;
1025 zLibStreamSettings.deflateInit2 = false;
1026 zLibStreamSettings.level = Z_DEFAULT_COMPRESSION;
1028 StreamSettings rawStreamSettings;
1029 rawStreamSettings.deflateInit2 = true;
1030 rawStreamSettings.level = Z_DEFAULT_COMPRESSION;
1031 rawStreamSettings.method = Z_DEFLATED;
1032 rawStreamSettings.deflateWindowBits = -MAX_WBITS;
1033 rawStreamSettings.inflateWindowBits = -MAX_WBITS;
1034 rawStreamSettings.memLevel = TEST_MID_MEM_LEVEL;
1035 rawStreamSettings.strategy = Z_DEFAULT_STRATEGY;
1037 // Allocate memory for buffers
1038 gZipCompressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
1039 CHECK_CONDITION0L(gZipCompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for gZipCompressedDataBuffer.");
1040 CleanupStack::PushL(TCleanupItem(User::Free, gZipCompressedDataBuffer));
1042 zLibCompressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
1043 CHECK_CONDITION0L(zLibCompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for zLibCompressedDataBuffer.");
1044 CleanupStack::PushL(TCleanupItem(User::Free, zLibCompressedDataBuffer));
1046 rawCompressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
1047 CHECK_CONDITION0L(rawCompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for rawCompressedDataBuffer.");
1048 CleanupStack::PushL(TCleanupItem(User::Free, rawCompressedDataBuffer));
1051 INFO_PRINTF1(_L("Compress gzip:"));
1052 this->CompressDataL(gZipStreamSettings, gZipDeflateStream, (Byte *)inputData, inputDataLength, gZipCompressedDataBuffer, compressedDataBufferLength);
1053 INFO_PRINTF1(_L("Compress zlib:"));
1054 this->CompressDataL(zLibStreamSettings, zLibDeflateStream, (Byte *)inputData, inputDataLength, zLibCompressedDataBuffer, compressedDataBufferLength);
1055 INFO_PRINTF1(_L("Compress raw:"));
1056 this->CompressDataL(rawStreamSettings, rawDeflateStream, (Byte *)inputData, inputDataLength, rawCompressedDataBuffer, compressedDataBufferLength);
1058 // Initialise the inflateStreams
1059 INFO_PRINTF1(_L("gZipInflateStream:"));
1060 this->InflateInit2L(gZipInflateStream, gZipStreamSettings.inflateWindowBits);
1061 CleanupStack::PushL(TCleanupItem(InflateEnd, &gZipInflateStream));
1063 INFO_PRINTF1(_L("zLibInflateStream:"));
1064 this->InflateInitL(zLibInflateStream);
1065 CleanupStack::PushL(TCleanupItem(InflateEnd, &zLibInflateStream));
1067 INFO_PRINTF1(_L("rawInflateStream:"));
1068 this->InflateInit2L(rawInflateStream, rawStreamSettings.inflateWindowBits);
1069 CleanupStack::PushL(TCleanupItem(InflateEnd, &rawInflateStream));
1071 // Try and get header information from a NULL stream
1072 err = inflateGetHeader(NULL, &gZipHeader);
1073 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateGetHeader on a NULL stream returned an unexpected value: %d", err);
1075 // Try getting the header for a deflate stream that has a NULL state
1076 // we must keep a pointer to the streams state so we can clean up properly with deflateEnd
1077 internal_state *deflateState = gZipDeflateStream.state;
1078 gZipDeflateStream.state = NULL;
1080 err = inflateGetHeader(&gZipDeflateStream, &gZipHeader);
1082 gZipDeflateStream.state = deflateState;
1083 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateGetHeader on a stream with a NULL state returned an unexpected value: %d", err);
1085 // Try and get header information from a zlib stream
1086 err = inflateGetHeader(&zLibDeflateStream, &gZipHeader);
1087 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateGetHeader on a zlib stream returned an unexpected value: %d", err);
1089 // Try and get header information from a raw stream
1090 err = inflateGetHeader(&rawDeflateStream, &gZipHeader);
1091 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateGetHeader on a raw stream returned an unexpected value: %d", err);
1093 // Clean up the inflateStreams
1094 err = inflateEnd(&gZipInflateStream);
1095 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "gZipInflateStream - inflateEnd error: %d", err);
1097 err = inflateEnd(&zLibInflateStream);
1098 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "zLibInflateStream - inflateEnd error: %d", err);
1100 err = inflateEnd(&rawInflateStream);
1101 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "rawInflateStream - inflateEnd error: %d", err);
1103 CleanupStack::Pop(3);
1104 CleanupStack::PopAndDestroy(3);
1109 @SYMTestCaseID SYSLIB-EZLIB2-UT-4268
1110 @SYMTestCaseDesc Check output can be deflated in raw format and inflated.
1111 @SYMTestPriority High
1112 @SYMTestActions 1. Create a stream and initialise it using deflateInit2(),
1113 setting windowBits between -8 and -15.
1114 2. Deflate the input and cleanup using deflateEnd().
1115 3. Create an inflate stream and initialise it using inflateInit2(),
1116 setting windowBits to be equal or less than the windowBits
1117 value used for deflateInit2().
1118 4. Inflate the input using inflate() and cleanup using inflateEnd().
1119 @SYMTestExpectedResults The data should be compressed with deflateEnd returning Z_OK and
1120 decompressed with inflateEnd returning Z_OK.
1124 TVerdict CTestZlib::TestDefInfRawL()
1129 z_stream deflateStream;
1130 z_stream inflateStream;
1133 const char inputData[] = "This is a piece of data to compress.\0";
1134 uLong inputDataLength = (uLong)strlen(inputData) + 1;
1135 Byte *compressedDataBuffer = NULL;
1136 uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
1137 Byte *decompressedDataBuffer = NULL;
1138 uLong decompressedDataBufferLength = inputDataLength;
1140 // deflateInit2 and inflateInit2 arguments
1141 StreamSettings streamSettings;
1142 streamSettings.deflateInit2 = true;
1143 streamSettings.level = Z_DEFAULT_COMPRESSION;
1144 streamSettings.method = Z_DEFLATED;
1145 streamSettings.deflateWindowBits = -MAX_WBITS;
1146 streamSettings.inflateWindowBits = streamSettings.deflateWindowBits;
1147 streamSettings.memLevel = TEST_MID_MEM_LEVEL;
1148 streamSettings.strategy = Z_DEFAULT_STRATEGY;
1150 // Allocate memory for buffers
1151 compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
1152 CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
1153 CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
1155 decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
1156 CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
1157 CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
1159 this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
1161 // Initialise the inflateStream
1162 this->InflateInit2L(inflateStream, streamSettings.inflateWindowBits);
1163 CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
1165 err = this->InflateDecompress(inflateStream, compressedDataBuffer, deflateStream.total_out, decompressedDataBuffer, decompressedDataBufferLength);
1166 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflate error: %d", err);
1168 // Clean up the inflateStream
1169 err = inflateEnd(&inflateStream);
1170 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateEnd error: %d", err);
1172 CleanupStack::Pop(1);
1173 CleanupStack::PopAndDestroy(2);
1178 @SYMTestCaseID SYSLIB-EZLIB2-UT-4269
1179 @SYMTestCaseDesc Check output is not generated in raw format when windowBits < -15
1181 @SYMTestPriority High
1182 @SYMTestActions 1. Create a stream and initialise it using deflateInit2() passing
1183 it the specified parameters.
1185 Note: The test should be repeated for deflateInit2() parameter values:
1186 • < -15 and > -8 for windowBits
1187 @SYMTestExpectedResults deflateInit2() should fail returning Z_STREAM_ERROR. Note: if
1188 windowBits is set between 8-15 and 24-31 there will be no error
1189 as the input will be deflated as a zlib/gzip stream.
1193 TVerdict CTestZlib::TestDefRawFailsL()
1198 z_stream deflateStream;
1200 // deflateInit2 and inflateInit2 arguments
1201 int level = Z_DEFAULT_COMPRESSION;
1202 int method = Z_DEFLATED;
1203 int deflateWindowBits;
1204 int memLevel = TEST_MID_MEM_LEVEL;
1205 int strategy = Z_DEFAULT_STRATEGY;
1207 // Read in the value for windowBits from the ini file
1208 ret = GetIntFromConfig(ConfigSection(), KParam1, deflateWindowBits);
1209 CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param1 from ini file");
1211 // Initialise the deflate stream
1212 this->DeflateInit2L(deflateStream, level, method, deflateWindowBits, memLevel, strategy, Z_STREAM_ERROR);
1218 @SYMTestCaseID SYSLIB-EZLIB2-UT-4270
1219 @SYMTestCaseDesc Check raw input is not inflated when windowBits < -15 or > -8.
1220 @SYMTestPriority High
1221 @SYMTestActions 1. Create a stream and initialise it using deflateInit2(),
1222 setting windowBits between -8 and -15.
1223 2. Deflate the input and cleanup using deflateEnd().
1224 3. Create an inflate stream and initialise it using inflateInit2()
1225 passing it the specified parameters.
1227 Note: The test should be repeated for inflateInit2() parameter values:
1228 • < -15, > -8 & < 8, >= 8 & <= 15 and >= 24 & <= 31 for windowBits
1229 For cases >= 8 & <= 15 and >= 24 & <= 31 inflate the compressed data
1230 and call inflateEnd() to clean up.
1231 @SYMTestExpectedResults inflateInit2() should fail returning Z_STREAM_ERROR. Note: if
1232 windowBits is set between 8-15 and 24-31 a Z_DATA_ERROR will be
1233 given as it will inflate as a zlib/gzip stream.
1237 TVerdict CTestZlib::TestDefInfRawFailsL()
1243 z_stream deflateStream;
1244 z_stream inflateStream;
1247 const char inputData[] = "This is a piece of data to compress.\0";
1248 uLong inputDataLength = (uLong)strlen(inputData) + 1;
1249 Byte *compressedDataBuffer = NULL;
1250 uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
1251 Byte *decompressedDataBuffer = NULL;
1252 uLong decompressedDataBufferLength = inputDataLength;
1254 // deflateInit2 and inflateInit2 arguments
1255 int level = Z_DEFAULT_COMPRESSION;
1256 int method = Z_DEFLATED;
1257 int deflateWindowBits = -MAX_WBITS;
1258 int inflateWindowBits;
1259 int memLevel = TEST_MID_MEM_LEVEL;
1260 int strategy = Z_DEFAULT_STRATEGY;
1262 // Allocate memory for buffers
1263 compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
1264 CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
1265 CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
1267 decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
1268 CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
1269 CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
1271 // Read in the value for windowBits from the ini file
1272 ret = GetIntFromConfig(ConfigSection(), KParam1, inflateWindowBits);
1273 CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param1 from ini file");
1275 // Initialise the deflate stream
1276 this->DeflateInit2L(deflateStream, level, method, deflateWindowBits, memLevel, strategy);
1277 CleanupStack::PushL(TCleanupItem(DeflateEnd, &deflateStream));
1279 // Compress the input
1280 err = this->DeflateCompress(deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
1281 CHECK_CONDITION1L(err!= Z_OK, KErrGeneral, "deflate error: %d", err);
1283 // Clean up the deflate stream
1284 err = deflateEnd(&deflateStream);
1285 CHECK_CONDITION1L(err!= Z_OK, KErrGeneral, "deflateEnd error: %d", err);
1286 CleanupStack::Pop(1);
1288 // Initialise the inflateStream
1289 // If windowBits are used that specify a zlib or gzip stream we get a different error
1290 if((inflateWindowBits >= 8 && inflateWindowBits <= 15) || (inflateWindowBits >= 24 && inflateWindowBits <= 31))
1292 this->InflateInit2L(inflateStream, inflateWindowBits);
1293 CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
1295 err = this->InflateDecompress(inflateStream, compressedDataBuffer, deflateStream.total_out, decompressedDataBuffer, decompressedDataBufferLength);
1296 CHECK_CONDITION1L(err!= Z_DATA_ERROR, KErrGeneral, "inflate error: %d", err);
1298 // Clean up the inflateStream
1299 err = inflateEnd(&inflateStream);
1300 CHECK_CONDITION1L(err!= Z_OK, KErrGeneral, "inflateEnd error: %d", err);
1301 CleanupStack::Pop(1);
1305 this->InflateInit2L(inflateStream, inflateWindowBits, Z_STREAM_ERROR);
1308 CleanupStack::PopAndDestroy(2);
1313 @SYMTestCaseID SYSLIB-EZLIB2-UT-4271
1314 @SYMTestCaseDesc To check the specified bits are added to the start of a raw stream
1315 correctly using deflatePrime().
1316 @SYMTestPriority Low
1317 @SYMTestActions 1. Create a stream and initialise it using deflateInit2(), setting
1318 windowBits between -8 and -15.
1319 2. Call deflatePrime() passing it the specified parameters.
1320 3. Deflate the input and cleanup using deflateEnd().
1321 4. Check the bits at the front of the output are the expected ones.
1323 Note: The test should be repeated for deflatePrime() parameter values:
1324 • 0, 8 and 16 for bits
1325 • 0, 216 and a number between 0 - 216 for value
1326 @SYMTestExpectedResults deflatePrime() should return Z_OK and the bits at the front of the
1327 output are the expected ones.
1331 TVerdict CTestZlib::TestDeflatePrimeL()
1337 z_stream deflateStream;
1340 const char inputData[] = "This is a piece of data to compress.\0";
1341 uLong inputDataLength = (uLong)strlen(inputData) + 1;
1342 Byte *compressedDataBuffer;
1343 uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
1345 // deflateInit2 and inflateInit2 arguments
1346 int level = Z_DEFAULT_COMPRESSION;
1347 int method = Z_DEFLATED;
1348 int deflateWindowBits = -MAX_WBITS;
1349 int memLevel = TEST_MID_MEM_LEVEL;
1350 int strategy = Z_DEFAULT_STRATEGY;
1352 // deflatePrime arguments
1356 // Bits added to the start of the compressed stream
1360 // Allocate memory for buffers
1361 compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
1362 CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
1363 CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
1365 // Read in the values for bits and value from the ini file
1366 ret = GetIntFromConfig(ConfigSection(), KParam1, bits);
1367 CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param1 from ini file.");
1369 ret = GetIntFromConfig(ConfigSection(), KParam2, value);
1370 CHECK_CONDITION0L(!ret, KErrGeneral, "Failed to read Param2 from ini file.");
1372 // Initialise the deflate stream
1373 this->DeflateInit2L(deflateStream, level, method, deflateWindowBits, memLevel, strategy);
1374 CleanupStack::PushL(TCleanupItem(DeflateEnd, &deflateStream));
1376 // Call deflatePrime on the stream
1377 err = deflatePrime(&deflateStream, bits, value);
1378 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflatePrime error: %d", err);
1380 // Compress the input
1381 err = this->DeflateCompress(deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
1382 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflate error: %d", err);
1384 // Clean up the deflate stream
1385 err = deflateEnd(&deflateStream);
1386 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "deflateEnd error: %d", err);
1387 CleanupStack::Pop(1);
1389 // Check the bits at the start of the compressed data are the same as intended
1390 // when using deflatePrime()
1394 bit1 = value & 0xFF;
1395 bit2 = (value >> 8) & 0xFF;
1398 bit1 = value & 0xFF;
1399 bit2 = compressedDataBuffer[1];
1402 bit1 = compressedDataBuffer[0];
1403 bit2 = compressedDataBuffer[1];
1406 INFO_PRINTF1(_L("The test only works with bits set to 0, 8 or 16."));
1407 User::Leave(KErrGeneral);
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.");
1411 CleanupStack::PopAndDestroy(1);
1416 @SYMTestCaseID SYSLIB-EZLIB2-UT-4272
1417 @SYMTestCaseDesc Check deflatePrime() fails when given an invalid stream.
1418 @SYMTestPriority Medium
1419 @SYMTestActions 1. Create a stream and initialise it using deflateInit2(),
1420 setting windowBits between -8 and -15.
1421 2. Call deflatePrime() passing it parameter values:
1422 a. NULL for the stream argument
1423 b. a stream whose state is NULL for the stream argument
1424 @SYMTestExpectedResults deflatePrime() fails returning Z_STREAM_ERROR in both cases.
1428 TVerdict CTestZlib::TestDeflatePrimeFailsL()
1433 z_stream deflateStream;
1435 // deflateInit2 and inflateInit2 arguments
1436 int level = Z_DEFAULT_COMPRESSION;
1437 int method = Z_DEFLATED;
1438 int deflateWindowBits = -MAX_WBITS;
1439 int memLevel = TEST_MID_MEM_LEVEL;
1440 int strategy = Z_DEFAULT_STRATEGY;
1442 // deflatePrime arguments
1446 // Initialise the deflate stream
1447 this->DeflateInit2L(deflateStream, level, method, deflateWindowBits, memLevel, strategy);
1448 CleanupStack::PushL(TCleanupItem(DeflateEnd, &deflateStream));
1450 // Call deflatePrime on a NULL stream
1451 err = deflatePrime(NULL, bits, value);
1452 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflatePrime on a NULL stream returned an unexpected value: %d", err);
1454 // Try calling deflatePrime on a deflate stream that has a NULL state
1455 // We must keep a pointer to the streams state so we can clean up properly with deflateEnd
1456 internal_state *deflateState = deflateStream.state;
1457 deflateStream.state = NULL;
1459 err = deflatePrime(&deflateStream, bits, value);
1461 deflateStream.state = deflateState;
1462 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "deflatePrime on a stream with a NULL state returned an unexpected value: %d", err);
1464 // deflateInit2() leaves a raw stream in a busy state. This results in deflateEnd()
1465 // returning a Z_DATA_ERROR, unless deflate() has been called on the stream,
1466 // meaning we have to set err back to Z_OK for the test to pass
1467 err = deflateEnd(&deflateStream);
1468 CHECK_CONDITION1L(err != Z_DATA_ERROR, KErrGeneral, "deflateEnd error: %d", err);
1469 CleanupStack::Pop(1);
1475 @SYMTestCaseID SYSLIB-EZLIB2-UT-4274
1476 @SYMTestCaseDesc Check inflatePrime() fails when given an invalid stream or parameters.
1477 @SYMTestPriority Medium
1478 @SYMTestActions 1. Create an inflate stream and initialise it using inflateInit2(),
1479 setting windowBits to be equal or less than the windowBits value
1480 used for deflateInit2().
1481 2. Call inflatePrime() passing it parameter values:
1482 a. NULL for the stream argument
1483 b. a stream whose state is NULL for the stream argument
1485 d. (32 – stream->bits) for bits
1486 @SYMTestExpectedResults inflatePrime() fails returning Z_STREAM_ERROR in all cases.
1490 TVerdict CTestZlib::TestInflatePrimeFailsL()
1495 z_stream inflateStream;
1497 // inflateInit2 argument
1498 int inflateWindowBits = -MAX_WBITS;
1500 // deflatePrime arguments
1504 // Initialise the inflate stream
1505 this->InflateInit2L(inflateStream, inflateWindowBits);
1506 CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
1508 // Call inflatePrime on a NULL stream
1509 err = inflatePrime(NULL, bits, value);
1510 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflatePrime on a NULL stream returned an unexpected value: %d", err);
1512 // Try calling inflatePrime on a deflate stream that has a NULL state
1513 // We must keep a pointer to the streams state so we can clean up properly with deflateEnd
1514 struct internal_state FAR *inflateState = inflateStream.state;
1515 inflateStream.state = NULL;
1517 err = inflatePrime(&inflateStream, bits, value);
1519 inflateStream.state = inflateState;
1520 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflatePrime on a stream with a NULL state returned an unexpected value: %d", err);
1522 // Call inflatePrime with bits > 16
1523 err = inflatePrime(&inflateStream, 17, value);
1524 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflatePrime using bits > 16 returned an unexpected value: %d", err);
1526 // Call inflatePrime with inflateStream->state->bits + bits > 32
1527 // This test cannot be implemented due to inflate_state requiring the definition for
1528 // the code struct which is in a header file that is included by one of the zlib
1531 inflateState = inflateStream.state;
1532 inflateState->bits(33 - bits);
1533 err = inflatePrime(&inflateStream, bits, value);
1534 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflatePrime, setting inflateStream->state->bits, returned an unexpected value: %d", err);
1537 // Clean up the inflate stream
1538 err = inflateEnd(&inflateStream);
1539 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateEnd error: %d", err);
1540 CleanupStack::Pop(1);
1546 @SYMTestCaseID SYSLIB-EZLIB2-UT-4275
1547 @SYMTestCaseDesc Check that a stream is duplicated correctly when using inflateCopy().
1548 @SYMTestPriority High
1549 @SYMTestActions 1. Create a stream and initialise it using deflateInit().
1550 2. Deflate the input and cleanup using deflateEnd().
1551 3. Create an inflate stream and initialise it using inflateInit().
1552 4. Create a second inflate stream and copy the first stream to the
1553 second stream using inflateCopy().
1554 5. Call inflate() and inflateEnd() on both streams.
1555 6. Compare the output of both streams.
1556 @SYMTestExpectedResults inflateCopy() should return Z_OK and the output of both streams will
1561 TVerdict CTestZlib::TestInflateCopyL()
1566 z_stream deflateStream;
1567 z_stream inflateStream;
1568 z_stream inflateStreamCopy;
1571 const char inputData[] = "This is a piece of data to compress.\0";
1572 uLong inputDataLength = (uLong)strlen(inputData) + 1;
1573 Byte *compressedDataBuffer = NULL;
1574 uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
1575 Byte *decompressedDataBuffer = NULL;
1576 uLong decompressedDataBufferLength = inputDataLength;
1577 Byte *copiedDecompressedDataBuffer = NULL;
1578 uLong copiedDecompressedDataBufferLength = decompressedDataBufferLength;
1580 // deflateInit argument
1581 StreamSettings streamSettings;
1582 streamSettings.deflateInit2 = false;
1583 streamSettings.level = Z_DEFAULT_COMPRESSION;
1585 // Allocate memory for buffers
1586 compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
1587 CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
1588 CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
1590 decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
1591 CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
1592 CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
1594 copiedDecompressedDataBuffer = (Byte *)User::AllocZ(copiedDecompressedDataBufferLength * sizeof(Byte));
1595 CHECK_CONDITION0L(copiedDecompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for copiedDecompressedDataBuffer.");
1596 CleanupStack::PushL(TCleanupItem(User::Free, copiedDecompressedDataBuffer));
1598 this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
1600 // Initialise the inflate streams
1601 this->InflateInitL(inflateStream);
1602 CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
1604 // Copy the inflateStream
1605 err = inflateCopy(&inflateStreamCopy, &inflateStream);
1606 CHECK_CONDITION1L(err != Z_OK, KErrNoMemory, "inflateCopy error: %d", err);
1607 CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStreamCopy));
1609 // Decompress the data in the compressedDataBuffer
1610 err = this->InflateDecompress(inflateStream, compressedDataBuffer, deflateStream.total_out, decompressedDataBuffer, decompressedDataBufferLength);
1611 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflate error: %d", err);
1613 // Decompress the data in the copiedDecompressedDataBuffer
1614 err = this->InflateDecompress(inflateStreamCopy, compressedDataBuffer, deflateStream.total_out, copiedDecompressedDataBuffer, copiedDecompressedDataBufferLength);
1615 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflate error: %d", err);
1617 // Clean up the inflate streams
1618 err = inflateEnd(&inflateStream);
1619 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateStream - inflateEnd error: %d", err);
1621 err = inflateEnd(&inflateStreamCopy);
1622 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateStreamCopy - inflateEnd error: %d", err);
1623 CleanupStack::Pop(2);
1625 // Check that both inflate streams produced identical output
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.");
1628 CleanupStack::PopAndDestroy(3);
1633 @SYMTestCaseID SYSLIB-EZLIB2-UT-4276
1634 @SYMTestCaseDesc Check inflateCopy() fails when given an invalid stream or parameters.
1635 @SYMTestPriority High
1636 @SYMTestActions 1. Create an inflate stream and initialise it using inflateInit().
1637 2. Create a second inflate stream and call inflateCopy() passing
1638 it parameter values:
1639 a. NULL for the dest stream argument
1640 b. NULL for the source stream argument
1641 c. a stream whose state is NULL for the source stream argument
1642 d. a stream whose zalloc is Z_NULL for the source stream argument
1643 e. a stream whose zfree is Z_NULL for the source stream argument
1644 @SYMTestExpectedResults inflateCopy() fails returning Z_STREAM_ERROR in all cases.
1648 TVerdict CTestZlib::TestInflateCopyFailsParamsL()
1653 z_stream inflateStream;
1654 z_stream inflateStreamCopy;
1656 // Initialise the inflate streams
1657 this->InflateInitL(inflateStream);
1658 CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
1660 // Try to copy from a NULL stream
1661 err = inflateCopy(&inflateStreamCopy, NULL);
1662 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateCopy from a NULL stream returned an unexpected value: %d", err);
1664 // Try to copy to a NULL stream
1665 err = inflateCopy(NULL, &inflateStream);
1666 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateCopy to a NULL stream returned an unexpected value: %d", err);
1668 // Try calling deflateCopy on a deflate stream that has a NULL state
1669 // We must keep a pointer to the streams state so we can clean up properly with deflateEnd
1670 struct internal_state FAR *state = inflateStream.state;
1671 inflateStream.state = NULL;
1673 err = inflateCopy(&inflateStreamCopy, &inflateStream);
1675 inflateStream.state = state;
1676 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateCopy from a stream whose state is NULL returned an unexpected value: %d", err);
1678 // Try to copy from a stream with zalloc set to Z_NULL
1679 inflateStream.zalloc = Z_NULL;
1680 err = inflateCopy(&inflateStreamCopy, &inflateStream);
1681 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateCopy from a stream with zalloc set to NULL returned an unexpected value: %d", err);
1683 // Try to copy from a stream with zfree set to Z_NULL
1684 free_func zfree = inflateStream.zfree;
1685 inflateStream.zfree = Z_NULL;
1687 err = inflateCopy(&inflateStreamCopy, &inflateStream);
1689 inflateStream.zfree = zfree;
1690 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "inflateCopy from a stream with zfree set to NULL returned an unexpected value: %d", err);
1692 // Clean up the inflate streams
1693 err = inflateEnd(&inflateStream);
1694 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateStream - inflateEnd error: %d", err);
1695 CleanupStack::Pop(1);
1701 @SYMTestCaseID SYSLIB-EZLIB2-UT-4277
1702 @SYMTestCaseDesc Check inflateCopy() fails when there is not enough memory to copy
1704 @SYMTestPriority High
1705 @SYMTestActions 1. Create an inflate stream and initialise it using inflateInit().
1706 2. Create a second inflate stream and set memory allocation to
1707 fail on the first attempt.
1708 3. Copy the first stream to the second stream using inflateCopy().
1709 4. Check that the memory is the same before and after calling
1710 inflateCopy(). Note: If Z_OK is returned it will be necessary
1711 to call inflateEnd() before checking the amount of memory.
1712 5. Repeat this process until inflateCopy() returns Z_OK, increasing
1713 the number of allocations that can be performed before failing.
1714 @SYMTestExpectedResults inflateCopy() fails at first, returning Z_MEM_ERROR, and then it
1715 will succeed with Z_OK. No memory should be leaked.
1719 TVerdict CTestZlib::TestInflateCopyFailsMemL()
1722 TVerdict verdict = EPass;
1725 z_stream inflateStream;
1726 z_stream inflateStreamCopy;
1728 // Initialise the inflate streams
1729 this->InflateInitL(inflateStream);
1730 CleanupStack::PushL(TCleanupItem(InflateEnd, &inflateStream));
1733 for(failureRate = 1, err = Z_MEM_ERROR; err != Z_OK && failureRate <= FAILURE_RATE_LIMIT; failureRate++)
1735 __UHEAP_SETFAIL(RHeap::EDeterministic, failureRate);
1738 // Copy the inflateStream
1739 err = inflateCopy(&inflateStreamCopy, &inflateStream);
1741 // Memory has been allocated so we need to clean up
1744 err = inflateEnd(&inflateStreamCopy);
1747 INFO_PRINTF2(_L("inflateStreamCopy - inflateEnd error: %d"), err);
1752 else if(err != Z_MEM_ERROR)
1754 INFO_PRINTF2(_L("inflateStreamCopy - unexpected error: %d"), err);
1765 INFO_PRINTF2(_L("The test succeeded at heap failure rate = %d."), --failureRate);
1767 else if(failureRate > FAILURE_RATE_LIMIT)
1769 INFO_PRINTF1(_L("Exceeded FAILURE_RATE_LIMIT. Either the test has failed or the limit needs increasing."));
1773 CleanupStack::PopAndDestroy(1);
1779 * in function required by inflateBack.
1780 * Provides a pointer to the next piece of input data and returns the length of the data
1782 unsigned in OF((void FAR *in_desc, unsigned char FAR * FAR *in_buf))
1784 struct bufferDescriptor *compressedDataBufferDescriptor = (struct bufferDescriptor *)in_desc;
1785 *in_buf = &compressedDataBufferDescriptor->buffer[compressedDataBufferDescriptor->next];
1787 // Check that there is more input
1788 if(compressedDataBufferDescriptor->next + 1 < compressedDataBufferDescriptor->length)
1790 compressedDataBufferDescriptor->next++;
1798 * out function required by inflateBack.
1799 * Provides a pointer to which the next space in memory data can be output and returns the length of this space
1801 int out OF((void FAR *out_desc, unsigned char FAR *out_buf, unsigned len))
1803 struct bufferDescriptor *decompressedDataBufferDescriptor = (struct bufferDescriptor *)out_desc;
1805 // Make sure there is output space
1806 if(decompressedDataBufferDescriptor->next + len <= decompressedDataBufferDescriptor->length)
1808 memcpy(decompressedDataBufferDescriptor->buffer + decompressedDataBufferDescriptor->next, out_buf, len);
1809 decompressedDataBufferDescriptor->next += len;
1813 int leftOver = decompressedDataBufferDescriptor->length - decompressedDataBufferDescriptor->next;
1814 memcpy(decompressedDataBufferDescriptor->buffer + decompressedDataBufferDescriptor->next, out_buf, leftOver);
1821 @SYMTestCaseID SYSLIB-EZLIB2-UT-4278
1822 @SYMTestCaseDesc Check a stream can be inflated using inflateBackInit(),
1823 inflateBack() and inflateBackEnd().
1824 @SYMTestPriority High
1825 @SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
1826 setting windowBits between -8 and -15.
1827 2. Deflate the input and cleanup using deflateEnd().
1828 3. Create an inflate stream and initialise it using
1829 inflateBackInit() setting windowBits to be equal to or greater
1830 than the windowBits value used for deflateInit2().
1831 4. Call inflateBack() to uncompress the stream and call
1832 inflateBackEnd() to clean up.
1833 5. Compare the original stream with the uncompressed stream.
1834 @SYMTestExpectedResults inflateBackInit() and inflateBackEnd() should both return Z_OK.
1835 inflateBack() should return Z_STREAM_END when it has finished
1836 inflating the input stream. The original stream should be
1837 identical to the final uncompressed stream.
1841 TVerdict CTestZlib::TestInflateBackL()
1846 z_stream deflateStream;
1847 z_stream inflateStream;
1850 const char inputData[] = "This is a piece of data to compress.\0";
1851 uLong inputDataLength = (uLong)strlen(inputData) + 1;
1852 Byte *compressedDataBuffer = NULL;
1853 uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
1854 Byte *decompressedDataBuffer = NULL;
1855 uLong decompressedDataBufferLength = inputDataLength;
1857 // deflateInit2 and inflateBackInit arguments
1858 StreamSettings streamSettings;
1859 streamSettings.deflateInit2 = true;
1860 streamSettings.level = Z_DEFAULT_COMPRESSION;
1861 streamSettings.method = Z_DEFLATED;
1862 streamSettings.deflateWindowBits = -MAX_WBITS;
1863 streamSettings.inflateWindowBits = -streamSettings.deflateWindowBits;
1864 streamSettings.memLevel = TEST_MID_MEM_LEVEL;
1865 streamSettings.strategy = Z_DEFAULT_STRATEGY;
1866 Bytef inflateWindow[32 * 1024];
1868 // Allocate memory for buffers
1869 compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
1870 CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
1871 CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
1873 decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
1874 CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
1875 CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
1877 this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
1879 // Initialise the inflate stream
1880 InflateBackInitL(inflateStream, streamSettings.inflateWindowBits, inflateWindow);
1881 CleanupStack::PushL(TCleanupItem(InflateBackEnd, &inflateStream));
1883 // This must be set to NULL otherwise inflateBack will assume there is input and try to decompress it
1884 inflateStream.next_in = NULL;
1886 struct bufferDescriptor compressedDataBufferDescriptor;
1887 compressedDataBufferDescriptor.buffer = compressedDataBuffer;
1888 compressedDataBufferDescriptor.next = 0;
1889 compressedDataBufferDescriptor.length = compressedDataBufferLength;
1891 struct bufferDescriptor decompressedDataBufferDescriptor;
1892 decompressedDataBufferDescriptor.buffer = decompressedDataBuffer;
1893 decompressedDataBufferDescriptor.next = 0;
1894 decompressedDataBufferDescriptor.length = decompressedDataBufferLength;
1896 // Decompress the input
1897 err = inflateBack(&inflateStream, &in, &compressedDataBufferDescriptor, &out, &decompressedDataBufferDescriptor);
1898 CHECK_CONDITION1L(err != Z_STREAM_END, KErrGeneral, "inflateBack error: %d", err);
1900 // Clean up the inflate stream
1901 err = inflateBackEnd(&inflateStream);
1902 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateBackEnd error: %d", err);
1903 CleanupStack::Pop(1);
1905 // Check that the decompressed data is identical to the original data
1906 CHECK_CONDITION0L(strcmp(inputData, (char *)decompressedDataBuffer) != 0, KErrGeneral, "The deflated data did no match the original data.");
1908 CleanupStack::PopAndDestroy(2);
1913 @SYMTestCaseID SYSLIB-EZLIB2-UT-4279
1914 @SYMTestCaseDesc Check inflateBackEnd() fails when given an invalid stream or parameters.
1915 @SYMTestPriority High
1916 @SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
1917 setting windowBits between -8 and -15.
1918 2. Deflate the input and cleanup using deflateEnd().
1919 3. Create an inflate stream and initialise it using
1920 nflateBackInit() setting windowBits to be equal to or greater
1921 than the windowBits value used for deflateInit2().
1922 4. Call inflateBack() to uncompress the stream.
1923 5. Call inflateBackEnd() passing it parameter values:
1924 a. NULL for the stream argument
1925 b. a stream whose state is NULL for the stream argument
1926 c. a stream whose zfree is Z_NULL for the stream argument
1927 @SYMTestExpectedResults inflateBackEnd() fails returning Z_STREAM_ERROR in all cases.
1931 TVerdict CTestZlib::TestInflateBackEndFailsL()
1936 z_stream deflateStream;
1937 z_stream inflateStream;
1940 const char inputData[] = "This is a piece of data to compress.\0";
1941 uLong inputDataLength = (uLong)strlen(inputData) + 1;
1942 Byte *compressedDataBuffer = NULL;
1943 uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
1944 Byte *decompressedDataBuffer = NULL;
1945 uLong decompressedDataBufferLength = inputDataLength;
1947 // deflateInit2 and inflateBackInit arguments
1948 StreamSettings streamSettings;
1949 streamSettings.deflateInit2 = true;
1950 streamSettings.level = Z_DEFAULT_COMPRESSION;
1951 streamSettings.method = Z_DEFLATED;
1952 streamSettings.deflateWindowBits = -MAX_WBITS;
1953 streamSettings.inflateWindowBits = -streamSettings.deflateWindowBits;
1954 streamSettings.memLevel = TEST_MID_MEM_LEVEL;
1955 streamSettings.strategy = Z_DEFAULT_STRATEGY;
1956 Bytef inflateWindow[32 * 1024];
1958 // Allocate memory for buffers
1959 compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
1960 CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
1961 CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
1963 decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
1964 CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
1965 CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
1967 this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
1969 // Initialise the inflate stream
1970 InflateBackInitL(inflateStream, streamSettings.inflateWindowBits, inflateWindow);
1971 CleanupStack::PushL(TCleanupItem(InflateBackEnd, &inflateStream));
1973 inflateStream.next_in = (unsigned char *)compressedDataBuffer;
1974 inflateStream.avail_in = compressedDataBufferLength;
1975 inflateStream.next_out = (unsigned char *)decompressedDataBuffer;
1976 inflateStream.avail_out = decompressedDataBufferLength;
1978 struct bufferDescriptor compressedDataBufferDescriptor;
1979 compressedDataBufferDescriptor.buffer = compressedDataBuffer;
1980 compressedDataBufferDescriptor.next = 0;
1981 compressedDataBufferDescriptor.length = compressedDataBufferLength;
1983 struct bufferDescriptor decompressedDataBufferDescriptor;
1984 decompressedDataBufferDescriptor.buffer = decompressedDataBuffer;
1985 decompressedDataBufferDescriptor.next = 0;
1986 decompressedDataBufferDescriptor.length = decompressedDataBufferLength;
1988 // Decompress the input
1989 err = inflateBack(&inflateStream, &in, &compressedDataBufferDescriptor, &out, &decompressedDataBufferDescriptor);
1990 CHECK_CONDITION1L(err != Z_STREAM_END, KErrGeneral, "inflateBack error: %d", err);
1992 // Try cleaning up a NULL stream
1993 err = inflateBackEnd(NULL);
1994 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackEnd on a NULL stream returned an unexpected value: %d", err);
1996 // Keep a pointer to the streams state so we can clean up properly with inflateBackEnd()
1997 struct internal_state FAR *inflateState = inflateStream.state;
1999 // Try cleaning up an inflate stream with a NULL state
2000 inflateStream.state = NULL;
2001 err = inflateBackEnd(&inflateStream);
2002 inflateStream.state = inflateState;
2003 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackEnd on a stream with a NULL state returned an unexpected value: %d", err);
2005 // Try cleaning up an inflate stream with no free function
2006 free_func zfree = inflateStream.zfree;
2007 inflateStream.zfree = Z_NULL;
2008 err = inflateBackEnd(NULL);
2009 inflateStream.zfree = zfree;
2010 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackEnd on a stream with zfree set to NULL returned an unexpected value: %d", err);
2012 // Clean up the inflate stream
2013 err = inflateBackEnd(&inflateStream);
2014 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateBackEnd error: %d", err);
2015 CleanupStack::Pop(1);
2017 CleanupStack::PopAndDestroy(2);
2022 * in function required by inflateBack.
2023 * Returning 0 indicates failure.
2025 unsigned inNoInput OF((void FAR *, unsigned char FAR * FAR *))
2031 * out function required by inflateBack.
2032 * Returning non 0 indicates failure.
2034 int outNoOutput OF((void FAR *, unsigned char FAR *, unsigned))
2040 @SYMTestCaseID SYSLIB-EZLIB2-UT-4280
2041 @SYMTestCaseDesc Check inflateBack() fails when given an invalid stream or parameters.
2042 @SYMTestPriority High
2043 @SYMTestActions 1. Create a deflate stream and initialise it using deflateInit2(),
2044 setting windowBits between -8 and-15.
2045 2. Deflate the input and cleanup using deflateEnd().
2046 3. Create an inflate stream and initialise it using
2047 inflateBackInit() setting windowBits to be equal to or greater
2048 than the windowBits value used for deflateInit2().
2049 4. Call inflateBack() passing it parameter values:
2050 a. NULL for the stream argument
2051 b. a stream whose state is NULL for the stream argument
2052 c. an input function that returns 0 for the in argument
2053 d. an output function that doesn’t return 0 for the out argument
2054 e. corrupted deflate output
2055 5. Call inflateBackEnd() to clean up
2056 @SYMTestExpectedResults inflateBack() fails returning Z_STREAM_ERROR for the first two
2057 cases, Z_BUF_ERROR for the second two cases and Z_DATA_ERROR
2062 TVerdict CTestZlib::TestInflateBackFailsL()
2067 z_stream deflateStream;
2068 z_stream inflateStream;
2071 const char inputData[] = "This is a piece of data to compress.\0";
2072 uLong inputDataLength = (uLong)strlen(inputData) + 1;
2073 Byte *compressedDataBuffer = NULL;
2074 uLong compressedDataBufferLength = COMPRESSED_DATA_BUFFER_LENGTH;
2075 Byte *decompressedDataBuffer = NULL;
2076 uLong decompressedDataBufferLength = inputDataLength;
2078 // deflateInit2 and inflateBackInit arguments
2079 StreamSettings streamSettings;
2080 streamSettings.deflateInit2 = true;
2081 streamSettings.level = Z_DEFAULT_COMPRESSION;
2082 streamSettings.method = Z_DEFLATED;
2083 streamSettings.deflateWindowBits = -MAX_WBITS;
2084 streamSettings.inflateWindowBits = -streamSettings.deflateWindowBits; // inflateBackInit expects the positive equivalent of the windowBits used to make a raw stream
2085 streamSettings.memLevel = TEST_MID_MEM_LEVEL;
2086 streamSettings.strategy = Z_DEFAULT_STRATEGY;
2087 Bytef inflateWindow[32 * 1024];
2089 // Allocate memory for buffers
2090 compressedDataBuffer = (Byte *)User::AllocZ(compressedDataBufferLength * sizeof(Byte));
2091 CHECK_CONDITION0L(compressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for compressedDataBuffer.");
2092 CleanupStack::PushL(TCleanupItem(User::Free, compressedDataBuffer));
2094 decompressedDataBuffer = (Byte *)User::AllocZ(decompressedDataBufferLength * sizeof(Byte));
2095 CHECK_CONDITION0L(decompressedDataBuffer == NULL, KErrNoMemory, "Failed to allocate memory for decompressedDataBuffer.");
2096 CleanupStack::PushL(TCleanupItem(User::Free, decompressedDataBuffer));
2098 this->CompressDataL(streamSettings, deflateStream, (Byte *)inputData, inputDataLength, compressedDataBuffer, compressedDataBufferLength);
2100 // Initialise the inflate stream
2101 InflateBackInitL(inflateStream, streamSettings.inflateWindowBits, inflateWindow);
2102 CleanupStack::PushL(TCleanupItem(InflateBackEnd, &inflateStream));
2104 // This must be set to NULL otherwise inflateBack will assume there is input and try to decompress it
2105 inflateStream.next_in = NULL;
2107 struct bufferDescriptor compressedDataBufferDescriptor;
2108 compressedDataBufferDescriptor.buffer = compressedDataBuffer;
2109 compressedDataBufferDescriptor.next = 0;
2110 compressedDataBufferDescriptor.length = compressedDataBufferLength;
2112 struct bufferDescriptor decompressedDataBufferDescriptor;
2113 decompressedDataBufferDescriptor.buffer = decompressedDataBuffer;
2114 decompressedDataBufferDescriptor.next = 0;
2115 decompressedDataBufferDescriptor.length = decompressedDataBufferLength;
2117 // Try inflating a NULL stream
2118 err = inflateBack(NULL, &in, &compressedDataBufferDescriptor, &out, &decompressedDataBufferDescriptor);
2119 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBack on a NULL stream returned an unexpected value: %d", err);
2121 // Try calling inflateBack on a deflate stream that has a NULL state
2122 // We must keep a pointer to the streams state so we can clean up properly with deflateBackEnd
2123 struct internal_state FAR *inflateState = inflateStream.state;
2124 inflateStream.state = NULL;
2126 err = inflateBack(&inflateStream, &in, &compressedDataBufferDescriptor, &out, &decompressedDataBufferDescriptor);
2128 inflateStream.state = inflateState;
2129 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBack on a stream with a NULL state returned an unexpected value: %d", err);
2131 // Try inflating a stream with an in_func that returns no input data
2132 err = inflateBack(&inflateStream, &inNoInput, &compressedDataBufferDescriptor, &out, &decompressedDataBufferDescriptor);
2133 CHECK_CONDITION1L(err != Z_BUF_ERROR, KErrGeneral, "Calling inflateBack with an in function that returns no input returned an unexpected value: %d", err);
2135 // Try inflating a stream with an out_func that does not output any data
2136 err = inflateBack(&inflateStream, &in, &compressedDataBufferDescriptor, &outNoOutput, &decompressedDataBufferDescriptor);
2137 CHECK_CONDITION1L(err != Z_BUF_ERROR, KErrGeneral, "Calling inflateBack with an in function that returns no input returned an unexpected value: %d", err);
2139 // Try inflating a corrupt stream
2140 compressedDataBuffer[1] = 'a';
2141 compressedDataBuffer[2] = 'a';
2142 compressedDataBuffer[3] = 'a';
2143 err = inflateBack(&inflateStream, &in, &compressedDataBufferDescriptor, &out, &decompressedDataBufferDescriptor);
2144 CHECK_CONDITION1L(err != Z_DATA_ERROR, KErrGeneral, "Calling inflateBack on a corrupt stream returned an unexpected value: %d", err);
2146 // Clean up the inflate stream
2147 err = inflateBackEnd(&inflateStream);
2148 CHECK_CONDITION1L(err != Z_OK, KErrGeneral, "inflateBackEnd error: %d", err);
2149 CleanupStack::Pop(1);
2151 CleanupStack::PopAndDestroy(2);
2156 @SYMTestCaseID SYSLIB-EZLIB2-UT-4281
2157 @SYMTestCaseDesc Check inflateBackInit() fails when given an invalid stream or parameters.
2158 @SYMTestPriority High
2159 @SYMTestActions 1. Create an inflate stream and initialise it using
2160 inflateBackInit() passing it parameter values:
2161 a. NULL for the stream argument
2162 b. a stream whose window is NULL for the stream argument
2163 c. < 8 for the windowBits argument
2164 d. > 5 for the windowBits argument
2165 @SYMTestExpectedResults inflateBackInit() should fail returning Z_STREAM_ERROR for all cases.
2169 TVerdict CTestZlib::TestInflateBackInitFailsParamsL()
2174 z_stream inflateStream;
2176 // inflateBackInit arguments
2177 int inflateBackWindowBits = MAX_WBITS;
2178 Bytef inflateWindow[32 * 1024];
2180 // Try initialising a NULL stream
2181 inflateStream.zalloc = Z_NULL;
2182 inflateStream.zfree = Z_NULL;
2183 inflateStream.opaque = Z_NULL;
2185 err = inflateBackInit(NULL, inflateBackWindowBits, inflateWindow);
2186 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackInit on a NULL stream returned an unexpected value: %d", err);
2188 // Try initialising a stream with a NULL inflate window
2189 err = inflateBackInit(&inflateStream, inflateBackWindowBits, NULL);
2190 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackInit on a stream with a NULL window returned an unexpected value: %d", err);
2192 // Try initialising a stream with window bits < 8
2193 err = inflateBackInit(&inflateStream, 7, inflateWindow);
2194 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackInit on a stream with windowBits < 8 returned an unexpected value: %d", err);
2196 // Try initialising a stream with window bits > 15
2197 err = inflateBackInit(&inflateStream, 16, inflateWindow);
2198 CHECK_CONDITION1L(err != Z_STREAM_ERROR, KErrGeneral, "Calling inflateBackInit on a stream with windowBits > 15 returned an unexpected value: %d", err);
2204 @SYMTestCaseID SYSLIB-EZLIB2-UT-4282
2205 @SYMTestCaseDesc Check inflateBackInit() fails when there is not enough memory.
2206 @SYMTestPriority High
2207 @SYMTestActions 1. Create an inflate stream and set the next memory allocation to fail.
2208 2. Initialise the stream using inflateBackInit() setting
2209 windowBits to be between 8 and 15.
2210 3. Check that the memory is the same before and after calling
2211 inflateBackInit(). Note: If Z_OK is returned it will be
2212 necessary to call inflateEnd() before checking the amount of memory.
2213 4. Repeat this process until inflateBackInit() returns Z_OK,
2214 increasing the number of allocations that can be performed before failing.
2215 @SYMTestExpectedResults inflateBackInit () fails at first, returning Z_MEM_ERROR, and then
2216 it will succeed with Z_OK. No memory should be leaked.
2220 TVerdict CTestZlib::TestInflateBackInitFailsMem()
2223 TVerdict verdict = EPass;
2226 z_stream inflateStream;
2228 // inflateBackInit arguments
2229 int inflateBackWindowBits = MAX_WBITS;
2230 Bytef inflateWindow[32 * 1024];
2232 inflateStream.zalloc = Z_NULL;
2233 inflateStream.zfree = Z_NULL;
2234 inflateStream.opaque = Z_NULL;
2237 for(failureRate = 1, err = Z_MEM_ERROR; err != Z_OK && failureRate <= FAILURE_RATE_LIMIT; failureRate++)
2239 __UHEAP_SETFAIL(RHeap::EDeterministic, failureRate);
2242 err = inflateBackInit(&inflateStream, inflateBackWindowBits, inflateWindow);
2244 // Memory has been allocated so we need to clean up
2247 err = inflateBackEnd(&inflateStream);
2250 INFO_PRINTF2(_L("inflateBackInit error: %d"), err);
2255 else if(err != Z_MEM_ERROR)
2257 INFO_PRINTF2(_L("inflateBackInit unexpected error: %d"), err);
2268 INFO_PRINTF2(_L("The test succeeded at heap failure rate = %d."), --failureRate);
2270 else if(failureRate > FAILURE_RATE_LIMIT)
2272 INFO_PRINTF1(_L("Exceeded FAILURE_RATE_LIMIT. Either the test has failed or the limit needs increasing."));
2280 @SYMTestCaseID SYSLIB-EZLIB2-UT-4283
2281 @SYMTestCaseDesc Check adler32_combine() generates the correct adler32 checksum.
2282 @SYMTestPriority High
2283 @SYMTestActions 1. Create two byte buffers, both containing different data, and
2284 use these to create two checksums using adler32().
2285 2. Create a third checksum using adler32_combine(), providing it
2286 with the first two checksums and the length of the second checksum.
2287 3. Concatenate the two byte buffers and create a fourth checksum
2288 using adler32() and the concatenated buffer as input.
2289 4. Compare the third and fourth checksums.
2290 @SYMTestExpectedResults The third and fourth checksums should be identical.
2294 TVerdict CTestZlib::TestAdler32CombineL()
2296 // Byte buffers from which the adler32 checksums will be generated
2297 const Byte *string1 = (Byte *)"Hello";
2298 const Byte *string2 = (Byte *)"World";
2299 const int string1Length = 5;
2300 const int string2Length = 5;
2301 const int string3Length = 10;
2303 // Initialise the adler32 variables
2304 uLong adlerString1 = adler32(0L, NULL, 0);
2305 uLong adlerString2 = adler32(0L, NULL, 0);
2306 uLong adlerString3 = adler32(0L, NULL, 0);
2307 uLong adlerCombined;
2309 // Generate the checksums from the byte buffers
2310 adlerString1 = adler32(adlerString1, string1, string1Length);
2311 adlerString2 = adler32(adlerString2, string2, string2Length);
2313 // Generate the checksum from combining adlerString1 and adlerString2
2314 adlerCombined = adler32_combine(adlerString1, adlerString2, string2Length);
2316 // Concatenate the byte buffers so that a checksum can be generated
2317 Byte string3[string3Length];
2318 memcpy((char *)string3, (char *)string1, string1Length);
2319 memcpy((char *)string3 + string1Length, (char *)string2, string2Length);
2321 // Generate checksum
2322 adlerString3 = adler32(adlerString3, string3, string3Length);
2324 // Compare the checksums to see if they are the same
2325 CHECK_CONDITION0L(adlerString3 != adlerCombined, KErrGeneral, "The combined checksum is not correct.");
2331 @SYMTestCaseID SYSLIB-EZLIB2-UT-4284
2332 @SYMTestCaseDesc Check crc32_combine() generates the correct crc32 checksum.
2333 @SYMTestPriority High
2334 @SYMTestActions 1. Create two byte buffers, both containing different data, and
2335 use these to create two checksums using crc32().
2336 2. Create a third checksum using crc32_combine(), providing it
2337 with the first two checksums and the length of the second checksum.
2338 3. Concatenate the two byte buffers and create a fourth checksum
2339 using crc32() and the concatenated buffer as input.
2340 4. Compare the third and fourth checksums.
2341 @SYMTestExpectedResults The third and fourth checksums should be identical.
2345 TVerdict CTestZlib::TestCrc32CombineL()
2347 // Byte buffers from which the crc32 checksums will be generated
2348 const Byte *string1 = (Byte *)"Hello";
2349 const Byte *string2 = (Byte *)"World";
2350 const int string1Length = 5;
2351 const int string2Length = 5;
2352 const int string3Length = 10;
2354 // Initialise the crc32 variables
2355 uLong crcString1 = crc32(0L, NULL, 0);
2356 uLong crcString2 = crc32(0L, NULL, 0);
2357 uLong crcString3 = crc32(0L, NULL, 0);
2360 // Generate the checksums from the byte buffers
2361 crcString1 = crc32(crcString1, string1, string1Length);
2362 crcString2 = crc32(crcString2, string2, string2Length);
2364 // Generate the checksum from combining adlerString1 and adlerString2
2365 crcCombined = crc32_combine(crcString1, crcString2, string2Length);
2367 // Concatenate the byte buffers so that a checksum can be generated
2368 Byte string3[string3Length];
2369 memcpy((char *)string3, (char *)string1, string1Length);
2370 memcpy((char *)string3 + string1Length, (char *)string2, string2Length);
2372 // Generate checksum
2373 crcString3 = crc32(crcString3, string3, string3Length);
2375 // Compare the checksums to see if they are the same
2376 CHECK_CONDITION0L(crcString3 != crcCombined, KErrGeneral, "The combined checksum is not correct.");
2382 @SYMTestCaseID SYSLIB-EZLIB2-UT-4284
2383 @SYMTestCaseDesc Check zlibCompileFlags() returns a uLong with the correct
2385 @SYMTestPriority Medium
2386 @SYMTestActions 1. Call zlibCompileFlags() and compare the first 2 bits with the
2387 size of uInt, the second 2 bits with the size of uLong and
2388 bits 16 and 17 with 0 (GZip APIs are being used).
2389 @SYMTestExpectedResults zlibCompileFlags() will return a uLong and all the comparisons
2394 TVerdict CTestZlib::TestZlibCompileFlagsL()
2396 // Get the compilerFlags
2397 uLong compileFlags = zlibCompileFlags();
2398 int compileFlagsUInt = compileFlags & 0x3;
2399 int compileFlagsULong = (compileFlags >> 2) & 0x3;
2400 int compileFlagsGZip = (compileFlags >> 15) & 0x3;
2404 // Get the size of uInt
2405 switch(sizeof(uInt))
2407 case 2: machineUInt = 0;
2409 case 4: machineUInt = 1;
2411 case 8: machineUInt = 2;
2413 default: machineUInt = 3;
2416 // Check the compiler flag for uInt is correct
2417 CHECK_CONDITION0L(machineUInt != compileFlagsUInt, KErrGeneral, "zlibCompileFlags reports an incorrect size for uInt.");
2419 // Get the size of uLong
2420 switch(sizeof(uLong))
2422 case 2: machineULong = 0;
2424 case 4: machineULong = 1;
2426 case 8: machineULong = 2;
2428 default: machineULong = 3;
2431 // Check the compiler flag for uLong is correct
2432 CHECK_CONDITION0L(machineULong != compileFlagsULong, KErrGeneral, "zlibCompileFlags reports an incorrect size for uLong.");
2434 // Check the compiler flags for GZip compression are correct
2435 CHECK_CONDITION0L(compileFlagsGZip != 0, KErrGeneral, "zlibCompileFlags reports GZip functionality is disabled.");