Update contrib.
1 // Copyright (c) 1998-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 the License "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 // e32test\misc\t_unzip.cpp
22 RTest test(_L("T_UNZIP"));
27 GLDEF_C void AcceptUnzippedBlock(TZipInfo& /*aInfo*/, TUint8*& aOutPtr, TInt aError)
33 GLDEF_C TInt ReadInputData(TUint8* aDest, TInt& aLength)
35 TPtr8 ptr(aDest,0,aLength);
36 return TheInputFile.Read(ptr);
39 GLDEF_C TInt UnzipComplete(TZipInfo& /*a*/, TUint8* /*aOutPtr*/, TInt /*aError*/)
44 _LIT(KLitThreadName,"Unzip");
45 TInt Initialise(TZipInfo& a)
50 a.iFileBufSize=4*a.iInBufSize;
51 TAny* pFileBuf=MALLOC(a.iFileBufSize);
54 a.iFileBuf=(TUint8*)pFileBuf;
56 r=t.Create(KLitThreadName,UnzipThread,0x2000,NULL,&a);
63 t.SetPriority(EPriorityLess);
64 t.Logon(a.iThreadStatus);
66 a.iThreadHandle=t.Handle();
70 void ProcessHeader(TZipInfo& a)
72 test.Printf(_L("Flags=%d\n"),a.iFlags);
73 test.Printf(_L("Method=%d\n"),a.iMethod);
74 test.Printf(_L("Crc=%d\n"),a.iCrc);
75 test.Printf(_L("Compressed size=%d\n"),a.iCompressedSize);
76 test.Printf(_L("Uncompressed size=%d\n"),a.iUncompressedSize);
77 test.Printf(_L("File name %S\n"),&a.iName);
78 test.Printf(_L("Data offset %d\n\n"),a.iDataOffset);
80 test.Next(_L("Allocate memory for unzipped file"));
81 a.iOutBuf=(TUint8*)User::Alloc(a.iUncompressedSize);
82 test(a.iOutBuf!=NULL);
83 test.Next(_L("Begin unzipping"));
85 TRequestStatus* pS=&a.iProcessedHeader;
87 t.SetHandle(a.iThreadHandle);
88 t.RequestComplete(pS,0);
91 void Cleanup(TZipInfo& a)
97 RThread& t=*(RThread*)&a.iThreadHandle;
101 GLDEF_C TInt E32Main()
104 TFileName inputFileName;
105 User::CommandLine(inputFileName);
106 test.Start(_L("Connect to file server"));
110 test.Printf(_L("Open file %S\n"),&inputFileName);
111 r=TheInputFile.Open(fs,inputFileName,EFileRead);
114 r=TheInputFile.Size(z.iRemain);
116 test.Printf(_L("File size %d\n"),z.iRemain);
118 test.Next(_L("Initialise"));
122 test.Next(_L("Read header"));
125 t.SetHandle(z.iThreadHandle);
126 while (z.iRemain && z.iThreadStatus==KRequestPending)
128 TRequestStatus dummy;
129 TRequestStatus* pS=&dummy;
130 r=ReadBlockToBuffer(z);
132 t.RequestComplete(pS,0); // same process
133 // test.Printf(_L("."));
134 while(z.iHeaderDone==0 && z.iThreadStatus==KRequestPending)
136 if (z.iHeaderDone==1 && z.iThreadStatus==KRequestPending)
138 // after reading first block, process the header
140 c=User::NTickCount();
144 test.Next(_L("\nWait for thread to exit"));
145 User::WaitForRequest(z.iThreadStatus);
146 if (z.iRemain || t.ExitReason()!=KErrNone)
148 test.Printf(_L("Error %d\n"),t.ExitReason());
151 TUint c2=User::NTickCount();
152 test.Printf(_L("Took %dms\n"),c2-c);
153 TheInputFile.Close();
156 TInt unc_size=OutPtr-z.iOutBuf;
157 test.Printf(_L("Recovered size %d\n"),unc_size);
158 test.Printf(_L("Writing to file\n"));
160 r=file.Replace(fs,z.iName,EFileWrite);
162 TPtrC8 ptr(z.iOutBuf,unc_size);