First public contribution.
1 // Copyright (c) 2005-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.
20 LOCAL_D RTest test(_L("ezdefect.exe"));
22 LOCAL_D CTrapCleanup* TheTrapCleanup = NULL;
24 #if !defined(__WINS__)
25 _LIT(KPath, "Z:\\test\\zip\\");
27 _LIT(KPath, "C:\\test\\zip\\");
32 void ExtractFileL(const CZipFileMember* aMember, CZipFile* aZip)
34 HBufC* name = aMember->Name()->AllocLC();
35 for (TInt i = 0; i<name->Length(); i++)
37 if ((*name)[i] == '/')
39 name->Des()[i] = '\\';
43 RZipFileMemberReaderStream* fileStream;
44 User::LeaveIfError(aZip->GetInputStreamL(aMember, fileStream));
45 CleanupStack::PushL(fileStream);
47 TUint32 size = aMember->UncompressedSize();
48 HBufC8* bytes = HBufC8::New(size);
49 CleanupStack::PushL(bytes);
50 TPtr8 ptr = bytes->Des();
51 User::LeaveIfError(fileStream->Read(ptr,size));
52 CleanupStack::PopAndDestroy(3,name); // bytes, fileStream and name
55 // Extract all members from the zip.
56 // These files are non compressed, i.e. EStored.
57 void ExtractMembersL(CZipFile* aZip)
59 test.Next(_L("DEF057916: Getting Corrupt file error when reading wav-file from Zip - PART 2"));
61 CZipFileMemberIterator* members = aZip->GetMembersL();
62 CleanupStack::PushL(members);
64 CZipFileMember* member = members->NextL();
67 CleanupStack::PushL(member);
68 ExtractFileL(member, aZip);
69 CleanupStack::PopAndDestroy(member);
70 member = members->NextL();
73 CleanupStack::PopAndDestroy(members);
76 // Extract the specified files from the zip.
77 // These files are non compressed, i.e. EStored.
80 test.Next(_L("DEF057916: Getting Corrupt file error when reading wav-file from Zip - PART 1"));
82 User::LeaveIfError(TheFs.Connect()); //Connect to file session
83 User::LeaveIfError(TheFs.SetSessionPath(KPath)); //Set Session Path to direcrt containing test zip files
84 CleanupClosePushL(TheFs);
86 const TUint KDataChunk = 2048;
87 _LIT(tmpFileName, "\\Test\\Zip\\compression_estored.zip");
88 _LIT(testFile1, "zip\\test.wav");
89 _LIT(testFile2, "zip\\rfc2459.zip");
90 _LIT(testFile3, "zip\\META-INF\\MANIFEST.MF");
92 CZipFile* iZipFile = CZipFile::NewL(TheFs, tmpFileName);
93 CleanupStack::PushL(iZipFile);
97 CZipFileMember* zipMember1 = iZipFile->CaseSensitiveOrCaseInsensitiveMemberL(testFile1);
100 CleanupStack::PushL(zipMember1);
102 RZipFileMemberReaderStream* iZipStream;
103 iZipFile->GetInputStreamL(zipMember1, iZipStream);
104 CleanupStack::PushL(iZipStream);
106 HBufC8* data = HBufC8::NewLC(KDataChunk);
107 TPtr8 ptr = data->Des();
110 err = iZipStream->Read(ptr,KDataChunk);
111 test (err == KErrNone);
113 err = iZipStream->Read(ptr,KDataChunk);
114 test (err == KErrEof);
116 CleanupStack::PopAndDestroy(data);
117 CleanupStack::PopAndDestroy(iZipStream);
118 CleanupStack::PopAndDestroy(zipMember1);
122 CZipFileMember* zipMember2 = iZipFile->CaseSensitiveOrCaseInsensitiveMemberL(testFile2);
125 CleanupStack::PushL(zipMember2);
127 RZipFileMemberReaderStream* iZipStream;
128 iZipFile->GetInputStreamL(zipMember2, iZipStream);
129 CleanupStack::PushL(iZipStream);
131 HBufC8* data = HBufC8::NewLC(KDataChunk*65);
132 TPtr8 ptr = data->Des();
135 err = iZipStream->Read(ptr,KDataChunk*65);
136 test (err == KErrNone); // file is very very large
138 err = iZipStream->Read(ptr,KDataChunk);
139 test (err == KErrEof);
141 CleanupStack::PopAndDestroy(data);
142 CleanupStack::PopAndDestroy(iZipStream);
143 CleanupStack::PopAndDestroy(zipMember2);
147 CZipFileMember* zipMember3 = iZipFile->CaseSensitiveOrCaseInsensitiveMemberL(testFile3);
150 CleanupStack::PushL(zipMember3);
152 RZipFileMemberReaderStream* iZipStream;
153 iZipFile->GetInputStreamL(zipMember3, iZipStream);
154 CleanupStack::PushL(iZipStream);
156 HBufC8* data = HBufC8::NewLC(KDataChunk);
157 TPtr8 ptr = data->Des();
160 err = iZipStream->Read(ptr,KDataChunk);
161 test (err == KErrNone);
163 err = iZipStream->Read(ptr,KDataChunk);
164 test (err == KErrEof);
166 CleanupStack::PopAndDestroy(data);
167 CleanupStack::PopAndDestroy(iZipStream);
168 CleanupStack::PopAndDestroy(zipMember3);
171 ExtractMembersL (iZipFile);
173 CleanupStack::PopAndDestroy(iZipFile);
174 CleanupStack::PopAndDestroy(&TheFs);
178 @SYMTestCaseID SYSLIB-EZLIB-CT-3464
179 @SYMTestCaseDesc RZipFileMemberReaderStream::Read returns incorrect error code under OOM
180 @SYMTestPriority High
181 @SYMTestActions Tries to read zipfile stream with heap allocation set to fail on all following
182 allocations. Check result returned from Read(TDes16&, TInt) and Read(TDes8&, TInt)
183 is KErrNoMemory. Note that zip file contents must be compressed, otherwise no
184 allocations are performed and Read() function returns KErrNone.
185 @SYMTestExpectedResults Read() function should return KErrNoMemory
190 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-3464 DEF103961: RZipFileMemberReaderStream::Read returns incorrect error code under OOM "));
192 User::LeaveIfError(TheFs.Connect()); //Connect to file session
193 User::LeaveIfError(TheFs.SetSessionPath(KPath)); //Set Session Path to directory containing test zip files
194 CleanupClosePushL(TheFs);
196 const TUint KDataChunk = 512;
197 _LIT(testFile1, "zip_archive2_with_comments.zip");
198 _LIT(internalFile, "doorslam.wav");
201 CZipFile* zipFile = CZipFile::NewL(TheFs, testFile1);
202 CleanupStack::PushL(zipFile);
204 // get input stream for a file contained in the zip archive
205 CZipFileMember* zipMember = zipFile->CaseSensitiveOrCaseInsensitiveMemberL(internalFile);
206 test(zipMember!=NULL);
207 CleanupStack::PushL(zipMember);
208 RZipFileMemberReaderStream* zipStream;
209 zipFile->GetInputStreamL(zipMember, zipStream);
210 CleanupStack::PushL(zipStream);
212 // some descriptors to hold stream data...
213 HBufC8* data8 = HBufC8::NewLC(KDataChunk);
214 TPtr8 ptr8 = data8->Des();
215 HBufC16* data16 = HBufC16::NewLC(KDataChunk);
216 TPtr16 ptr16 = data16->Des();
218 // do memory tests for RZipFileMemberReaderStream::Read() and its overloaded brother
219 __UHEAP_SETFAIL(RHeap::EDeterministic,1);
220 TInt error = zipStream->Read(ptr8, KDataChunk);
221 test (error == KErrNoMemory);
222 error = zipStream->Read(ptr16, KDataChunk);
223 test (error == KErrNoMemory);
224 __UHEAP_SETFAIL(RHeap::ENone,0);
226 CleanupStack::PopAndDestroy(data16);
227 CleanupStack::PopAndDestroy(data8);
228 CleanupStack::PopAndDestroy(zipStream);
229 CleanupStack::PopAndDestroy(zipMember);
230 CleanupStack::PopAndDestroy(zipFile);
231 CleanupStack::PopAndDestroy(&TheFs);
235 @SYMTestCaseID SYSLIB-EZLIB-CT-3475
236 @SYMTestCaseDesc RZipFileMemberReaderStream constructor ignores errors under OOM
237 @SYMTestPriority High
238 @SYMTestActions Construct RZipFileMemberReaderStream under OOM conditions. Check the Leave code.
239 @SYMTestExpectedResults Should Leave with KErrNoMemory
244 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-3475 DEF105995: RZipFileMemberReaderStream constructor not checking OOM conditions "));
246 User::LeaveIfError(TheFs.Connect()); //Connect to file session
247 User::LeaveIfError(TheFs.SetSessionPath(KPath)); //Set Session Path to directory containing test zip files
248 CleanupClosePushL(TheFs);
250 _LIT(testFile1, "zip_archive2_with_comments.zip");
251 _LIT(internalFile, "doorslam.wav");
254 CZipFile* zipFile = CZipFile::NewL(TheFs, testFile1);
255 CleanupStack::PushL(zipFile);
257 // get input stream for a file contained in the zip archive
258 CZipFileMember* zipMember = zipFile->CaseSensitiveOrCaseInsensitiveMemberL(internalFile);
259 test(zipMember!=NULL);
260 CleanupStack::PushL(zipMember);
262 __UHEAP_SETFAIL(RHeap::EDeterministic,2); // so memory allocation in inflateInit2() fails
264 RZipFileMemberReaderStream* zipStream;
265 TRAPD(err, zipFile->GetInputStreamL(zipMember, zipStream));
266 test(err == KErrNoMemory);
268 __UHEAP_SETFAIL(RHeap::ENone,0);
270 CleanupStack::PopAndDestroy(zipMember);
271 CleanupStack::PopAndDestroy(zipFile);
272 CleanupStack::PopAndDestroy(&TheFs);
277 DEF057916L(); // Getting Corrupt file error when reading wav-file from Zip
278 #if defined(_DEBUG) // OOM tests are only run on Debug builds
279 DEF103961L(); // RZipFileMemberReaderStream::Read returns incorrect error code under OOM
280 DEF105995L(); // inflateInit2 is not checked for errors in RZipFileMemberReaderStream constructor
284 GLDEF_C TInt E32Main()
288 test.Printf(_L("\n"));
290 test.Start( _L("EZlib defect Tests.") );
292 TheTrapCleanup=CTrapCleanup::New();
294 TRAPD(err,RunTestL());
295 test (err==KErrNone);
299 delete TheTrapCleanup;