|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "TestContentHandler.h" |
|
19 #include "TestBufferManager.h" |
|
20 #include "xmlengtester.h" |
|
21 |
|
22 #include <e32svr.h> |
|
23 #include <domain/osextensions/StifParser.h> |
|
24 #include <domain/osextensions/Stiftestinterface.h> |
|
25 |
|
26 #include <XmlEngSerializer.h> |
|
27 #include <XmlEngBinaryContainer.h> |
|
28 #include "xmlengtesterdef.h" |
|
29 |
|
30 #include <InetProtTextUtils.h> |
|
31 #include <libc\string.h> |
|
32 #include <charconv.h> |
|
33 #include <UTF.H> |
|
34 |
|
35 #include <EZDecompressor.h> |
|
36 #include <EZCompressor.h> |
|
37 #include <EZGzip.h> |
|
38 |
|
39 |
|
40 /************************************** SerGZIP ***************************************/ |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CLibxml2Tester::SerializeGZIPL |
|
43 // test GZIP Serialize |
|
44 // (other items were commented in a header). |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 TInt CLibxml2Tester::SerializeGZIPL(CStifItemParser& aItem) |
|
48 { |
|
49 TInt error(KErrGeneral); |
|
50 |
|
51 //get test controls, input&output paths |
|
52 TPtrC pControl; |
|
53 aItem.GetNextString( pControl ); |
|
54 |
|
55 TPtrC pBinary; |
|
56 aItem.GetNextString( pBinary ); |
|
57 |
|
58 TPtrC pXml; |
|
59 aItem.GetNextString( pXml ); |
|
60 |
|
61 TPtrC pSerialized; |
|
62 aItem.GetNextString( pSerialized ); |
|
63 |
|
64 TPtrC pGzipSerialized; |
|
65 aItem.GetNextString( pGzipSerialized ); |
|
66 |
|
67 TPtrC pOptions; |
|
68 aItem.GetNextString( pOptions ); |
|
69 |
|
70 // saves xml file with binary data added ( default serialize ) |
|
71 RXmlEngDocument iDocument; |
|
72 CleanupClosePushL( iDocument ); |
|
73 if( pControl.FindF( SINGLE ) != KErrNotFound ) |
|
74 { |
|
75 error = SaveXmlWithBinaryDataL( iDocument, pOptions, pBinary, pXml, EMPTY_STRING() ); |
|
76 } |
|
77 else if ( pControl.FindF( MULTI ) != KErrNotFound ) |
|
78 { |
|
79 error = SaveXmlWithBinaryDataL( iDocument, pOptions, pBinary, pXml, EMPTY_STRING(), TRUE ); |
|
80 } |
|
81 else |
|
82 { |
|
83 User::Leave(KErrArgument); |
|
84 } |
|
85 |
|
86 if ( pControl.FindF( ONE_PARA ) != KErrNotFound ) |
|
87 { |
|
88 User::LeaveIfError( TestSerialize1paraToFileL( iDocument, pGzipSerialized, pOptions, ESerializerGZip ) ); |
|
89 } |
|
90 |
|
91 if ( pControl.FindF( THREE_PARA ) != KErrNotFound ) |
|
92 { |
|
93 User::LeaveIfError ( TestSerialize3paraToFileL( iDocument, pGzipSerialized, pOptions, ESerializerGZip ) ); |
|
94 } |
|
95 |
|
96 if ( pControl.FindF( TO_RFS ) != KErrNotFound ) |
|
97 { |
|
98 User::LeaveIfError( TestSerializeRFsL( iDocument, pGzipSerialized, pOptions, ESerializerGZip ) ); |
|
99 } |
|
100 |
|
101 if ( pControl.FindF( BUFFER ) != KErrNotFound ) |
|
102 { |
|
103 User::LeaveIfError( TestSerializeToBufferL( iDocument, pGzipSerialized, pOptions, ESerializerGZip ) ); |
|
104 } |
|
105 CleanupStack::PopAndDestroy( 1 ); |
|
106 return error; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CLibxml2Tester::DecompressGZIPL |
|
111 // test GZIP Decompress |
|
112 // (other items were commented in a header). |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 TInt CLibxml2Tester::DecompressGZIPL(CStifItemParser& aItem) |
|
116 { |
|
117 TBool unzipLoop = TRUE; |
|
118 |
|
119 TPtrC pInput; |
|
120 aItem.GetNextString( pInput ); |
|
121 |
|
122 TPtrC pOutput; |
|
123 aItem.GetNextString( pOutput ); |
|
124 HBufC8* bufferOutput = CnvUtfConverter::ConvertFromUnicodeToUtf8L(pOutput); |
|
125 CleanupStack::PushL( bufferOutput ); |
|
126 TPtr8 pOutput8 = bufferOutput->Des(); |
|
127 |
|
128 RFs aRFs; |
|
129 User::LeaveIfError(aRFs.Connect()); |
|
130 CleanupClosePushL(aRFs); |
|
131 |
|
132 RFile fileHandle; |
|
133 User::LeaveIfError(fileHandle.Replace(aRFs, pOutput, EFileRead | EFileWrite)); |
|
134 CleanupClosePushL(fileHandle); |
|
135 |
|
136 |
|
137 CEZGZipToFile* decompressFile = CEZGZipToFile::NewLC(aRFs, pInput, fileHandle); |
|
138 |
|
139 while ( unzipLoop ) |
|
140 { |
|
141 unzipLoop = decompressFile->InflateL(); |
|
142 } |
|
143 |
|
144 |
|
145 CleanupStack::PopAndDestroy( 4 ); |
|
146 return KErrNone; |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CLibxml2Tester::DecompressBufferGZIPL |
|
151 // test GZIP Decompress |
|
152 // (other items were commented in a header). |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 TInt CLibxml2Tester::DecompressBufferGZIPL(CStifItemParser& aItem) |
|
156 { |
|
157 TPtrC pInput; |
|
158 aItem.GetNextString( pInput ); |
|
159 |
|
160 TPtrC pOutput; |
|
161 aItem.GetNextString( pOutput ); |
|
162 HBufC8* bufferOutput = CnvUtfConverter::ConvertFromUnicodeToUtf8L(pOutput); |
|
163 CleanupStack::PushL( bufferOutput ); |
|
164 TPtr8 pOutput8 = bufferOutput->Des(); |
|
165 |
|
166 |
|
167 HBufC8* buffer = ReadFileToBufferL( pInput ); |
|
168 CleanupStack::PushL( buffer ); |
|
169 |
|
170 // CVtcpBufferManager::NewL( in.Ptr() ,in.Length()); |
|
171 |
|
172 |
|
173 CTestBufferManager* bm = CTestBufferManager::NewLC( buffer->Ptr(), buffer->Size() ); |
|
174 CEZDecompressor* decompressor = CEZDecompressor::NewLC( *bm ); |
|
175 |
|
176 // decompressor->DecompressL( pOutput8, buffer->Des() ); |
|
177 |
|
178 while ( decompressor->InflateL() ) |
|
179 { |
|
180 /* empty */ |
|
181 } |
|
182 |
|
183 TPtrC8 out=bm->OutputData(); |
|
184 |
|
185 RFs aRFs; |
|
186 User::LeaveIfError(aRFs.Connect()); |
|
187 CleanupClosePushL(aRFs); |
|
188 |
|
189 RFile fOut; |
|
190 User::LeaveIfError ( fOut.Replace( aRFs, pOutput, EFileWrite ) ); |
|
191 CleanupClosePushL( fOut ); |
|
192 User::LeaveIfError ( fOut.Write(out ) ); |
|
193 |
|
194 |
|
195 //WriteFileFromBufferL(pOutput,out) |
|
196 |
|
197 CleanupStack::PopAndDestroy( 6 ); |
|
198 return KErrNone; |
|
199 } |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CLibxml2Tester::CompressBufferGZIPL |
|
202 // test GZIP Compress to buffer |
|
203 // (other items were commented in a header). |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 TInt CLibxml2Tester::CompressBufferGZIPL(CStifItemParser& aItem) |
|
207 { |
|
208 _LIT(tem,"Error in code"); |
|
209 |
|
210 // resize heap |
|
211 he = UserHeap::ChunkHeap(&KNullDesC(), 0, 20000000); |
|
212 if(!he) |
|
213 { |
|
214 User::Leave(100); |
|
215 } |
|
216 oldHeap = User::SwitchHeap(he);// Change heaps |
|
217 cleanup=CTrapCleanup::New(); |
|
218 //-- |
|
219 TInt trapResult; |
|
220 |
|
221 // start trap |
|
222 TRAP(trapResult, |
|
223 |
|
224 TPtrC pInput; |
|
225 aItem.GetNextString( pInput ); |
|
226 |
|
227 TPtrC pOutput; |
|
228 aItem.GetNextString( pOutput ); |
|
229 HBufC8* bufferOutput = CnvUtfConverter::ConvertFromUnicodeToUtf8L(pOutput); |
|
230 CleanupStack::PushL( bufferOutput ); |
|
231 TPtr8 pOutput8 = bufferOutput->Des(); |
|
232 |
|
233 |
|
234 HBufC8* buffer = ReadFileToBufferL( pInput ); |
|
235 CleanupStack::PushL( buffer ); |
|
236 |
|
237 // CVtcpBufferManager::NewL( in.Ptr() ,in.Length()); |
|
238 |
|
239 |
|
240 CTestBufferManager* bm = CTestBufferManager::NewLC( buffer->Ptr(), buffer->Size() ); |
|
241 CEZCompressor* compressor = CEZCompressor::NewLC( *bm ); |
|
242 |
|
243 // decompressor->DecompressL( pOutput8, buffer->Des() ); |
|
244 |
|
245 while ( compressor->DeflateL() ) |
|
246 { |
|
247 /* empty */ |
|
248 } |
|
249 |
|
250 TPtrC8 out=bm->OutputData(); |
|
251 |
|
252 RFs aRFs; |
|
253 User::LeaveIfError(aRFs.Connect()); |
|
254 CleanupClosePushL(aRFs); |
|
255 |
|
256 RFile fOut; |
|
257 User::LeaveIfError ( fOut.Replace( aRFs, pOutput, EFileWrite ) ); |
|
258 CleanupClosePushL( fOut ); |
|
259 User::LeaveIfError ( fOut.Write(out ) ); |
|
260 |
|
261 |
|
262 //WriteFileFromBufferL(pOutput,out) |
|
263 |
|
264 CleanupStack::PopAndDestroy( 6 ); |
|
265 ); |
|
266 // end trap |
|
267 |
|
268 |
|
269 if (trapResult) |
|
270 User::Panic(tem,trapResult); |
|
271 |
|
272 |
|
273 // delete cheap |
|
274 delete cleanup; // destroy clean-up stack |
|
275 User::SwitchHeap(oldHeap); // Change to old heap |
|
276 he->Close(); |
|
277 he = NULL; |
|
278 // -- |
|
279 return KErrNone; |
|
280 } |
|
281 |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CLibxml2Tester::SerializeDirtyGzipL |
|
285 // test serialize to file GZIP, error code trapping |
|
286 // (other items were commented in a header). |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 TInt CLibxml2Tester::SerializeDirtyGzipL(CStifItemParser& aItem) |
|
290 { |
|
291 TInt nResult = KErrNone; |
|
292 |
|
293 TPtrC pDocument; |
|
294 aItem.GetNextString(pDocument); |
|
295 |
|
296 TPtrC pOut; |
|
297 aItem.GetNextString(pOut); |
|
298 |
|
299 TPtrC pDirtyReturn; |
|
300 aItem.GetNextString(pDirtyReturn); |
|
301 |
|
302 TLex inputNum (pDirtyReturn); |
|
303 TInt dirtyReturn; |
|
304 inputNum.Val(dirtyReturn); |
|
305 |
|
306 |
|
307 TRAPD(trapResult, |
|
308 iDoc = parser.ParseFileL(pDocument); |
|
309 |
|
310 // procesing |
|
311 // create serializer |
|
312 CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(ESerializerGZip); |
|
313 CleanupStack::PushL(serializer); |
|
314 |
|
315 // set output |
|
316 TFileName srcFileName( pOut ); |
|
317 serializer->SetOutputL( srcFileName ); |
|
318 |
|
319 // set serialization options |
|
320 TXmlEngSerializationOptions options ( TXmlEngSerializationOptions::KOptionStandalone ); |
|
321 serializer->SetSerializationOptions( options ); |
|
322 |
|
323 // serialize |
|
324 serializer->SerializeL( iDoc ); |
|
325 CleanupStack::PopAndDestroy( 1 ); |
|
326 ); |
|
327 |
|
328 if (trapResult == dirtyReturn ) nResult = KErrNone; |
|
329 else if (trapResult != KErrNone) nResult = trapResult; |
|
330 else nResult = KErrGeneral; |
|
331 |
|
332 |
|
333 |
|
334 return nResult; |
|
335 } |
|
336 // End of file |