|
1 // Copyright (c) 2003-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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <ecom/ecom.h> |
|
18 |
|
19 #include <xml/matchdata.h> |
|
20 #include <xml/parserfeature.h> |
|
21 #include <xml/xmlparsererrors.h> |
|
22 |
|
23 #include "t_xmlparser.h" |
|
24 #include "unzip.h" |
|
25 |
|
26 using namespace Xml; |
|
27 |
|
28 RTest test(_L("XML parser tests")); // must be called 'test', as the e32test macros rely on this. |
|
29 |
|
30 // Installed via bld.inf test exports |
|
31 _LIT(KBigTestFile, "c:\\system\\data\\xml\\xml\\networking.xml"); |
|
32 _LIT(KRefFilename, "c:\\system\\data\\xml\\xml\\ref-networking.xml"); |
|
33 _LIT(KSimpleTestFile, "c:\\system\\data\\xml\\xml\\simple.xml"); |
|
34 _LIT(KInvalidTestFile, "c:\\system\\data\\xml\\xml\\invalid.xml"); |
|
35 _LIT(KNamespaceTestFile, "c:\\system\\data\\xml\\xml\\namespace.xml"); |
|
36 _LIT(KEntityTestFile, "c:\\system\\data\\xml\\xml\\entity.xml"); |
|
37 _LIT(KCapsTestFile, "c:\\system\\data\\xml\\xml\\caps.xml"); |
|
38 _LIT(KEncodingTestFile, "c:\\system\\data\\xml\\xml\\doc_jp_utf.xml"); |
|
39 _LIT(KEncodingRefFile, "c:\\system\\data\\xml\\xml\\ref_doc_jp_utf.xml"); |
|
40 |
|
41 _LIT(KZipTestFile, "z:\\system\\data\\xml\\xml.zip"); |
|
42 _LIT(KXmlTestDir, "c:\\system\\data\\xml"); |
|
43 |
|
44 _LIT8(KIncompleteData, "<DIDL-Lite xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\" xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\"><container id=\"1\" parentID=\"0\" child "); |
|
45 |
|
46 _LIT8(KParserDataType, "text/xml"); |
|
47 _LIT8(KParserDataType2, "text/wbxml"); |
|
48 _LIT8(KParserDataType3, "text/unique"); |
|
49 _LIT8(KParserDataType4, "text/same"); |
|
50 |
|
51 |
|
52 // --------------------------------------------------- |
|
53 |
|
54 |
|
55 /** |
|
56 @SYMTestCaseID SYSLIB-XML-CT-3734 |
|
57 @SYMTestCaseDesc Parsing an xml document. |
|
58 @SYMTestPriority Medium |
|
59 @SYMTestActions Takes networking.xml, parses it and reconstitutes it as XML. A comparison |
|
60 between the output in Epocwind.out and networking.xml can be used to show |
|
61 that the parser is doing what it should. |
|
62 The test has now been automated to diff the output with ref-networking.xml. |
|
63 @SYMTestExpectedResults The document is parsed without any issues. |
|
64 @SYMPREQ PREQ230 |
|
65 */ |
|
66 LOCAL_C void BasicParsingTestL() |
|
67 { |
|
68 RFs fs; |
|
69 User::LeaveIfError(fs.Connect()); |
|
70 CleanupClosePushL(fs); |
|
71 |
|
72 RFile result; |
|
73 TFileName filename; |
|
74 User::LeaveIfError(result.Temp(fs, _L("C:\\"), filename, EFileWrite)); |
|
75 CleanupClosePushL(result); |
|
76 |
|
77 TRebuildingContentHandler contentHandler(result); |
|
78 |
|
79 CParser* parser = CParser::NewLC(KParserDataType, contentHandler); |
|
80 |
|
81 ParseL(*parser, fs, KBigTestFile()); |
|
82 test(contentHandler.iError==KErrNone); |
|
83 |
|
84 CleanupStack::PopAndDestroy(2); |
|
85 |
|
86 RFile ref; |
|
87 User::LeaveIfError(ref.Open(fs, KRefFilename, EFileRead)); |
|
88 CleanupClosePushL(ref); |
|
89 User::LeaveIfError(result.Open(fs, filename, EFileRead)); |
|
90 CleanupClosePushL(result); |
|
91 |
|
92 TInt resultSize; |
|
93 User::LeaveIfError(result.Size(resultSize)); |
|
94 TInt refSize; |
|
95 User::LeaveIfError(ref.Size(refSize)); |
|
96 test(resultSize==refSize); |
|
97 |
|
98 TBuf8<256> refBuf; |
|
99 TBuf8<256> resultBuf; |
|
100 |
|
101 while(ref.Read(refBuf)==KErrNone && result.Read(resultBuf)==KErrNone && refBuf.Length()>0) |
|
102 test(refBuf==resultBuf); |
|
103 |
|
104 test(refBuf.Length()==0 && resultBuf.Length()==0); |
|
105 |
|
106 CleanupStack::PopAndDestroy(2); |
|
107 fs.Delete(filename); |
|
108 CleanupStack::PopAndDestroy(&fs); |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------- |
|
113 |
|
114 |
|
115 /** |
|
116 @SYMTestCaseID SYSLIB-XML-CT-1578 |
|
117 @SYMTestCaseDesc SS31 Symbian XML Framework - Symbian SAX Plugin is not returned by default. |
|
118 @SYMTestPriority High |
|
119 @SYMTestActions Create CParser and parse test file. Compare number of elements in output |
|
120 to determine which parser is selected. Create CParser and parse test file |
|
121 with CMatchData API with default supplied parameters. Test for selected parser. |
|
122 @SYMTestExpectedResults Test should not fail. Symbian parser is expected to be selected. |
|
123 @SYMDEF INC073582 |
|
124 */ |
|
125 LOCAL_C void INC073582L() |
|
126 { |
|
127 RFs fs; |
|
128 User::LeaveIfError(fs.Connect()); |
|
129 CleanupClosePushL(fs); |
|
130 |
|
131 TSimpleContentHandler* handler = new (ELeave) TSimpleContentHandler(); |
|
132 CleanupStack::PushL(handler); |
|
133 |
|
134 RFile handle; |
|
135 User::LeaveIfError(handle.Open(fs, KSimpleTestFile, EFileShareReadersOnly)); |
|
136 CleanupClosePushL(handle); |
|
137 |
|
138 // Test default behaviour of text/xml parser (multiple parsers return Symbian) |
|
139 |
|
140 CParser* parser = CParser::NewLC(KParserDataType, *handler); |
|
141 |
|
142 ParseL(*parser, handle); |
|
143 //Expected: handler->iNumElements == 6 |
|
144 // Production, Symbian parser. |
|
145 test(handler->iNumElements==6); |
|
146 |
|
147 CleanupStack::PopAndDestroy(parser); |
|
148 |
|
149 // Test default behaviour with CMatchData supplied version of CParser |
|
150 |
|
151 CMatchData *matchData = CMatchData::NewLC(); |
|
152 |
|
153 matchData->SetMimeTypeL(KParserDataType); |
|
154 matchData->SetVariantL(_L8("")); |
|
155 |
|
156 parser = CParser::NewLC(*matchData, *handler); |
|
157 |
|
158 ParseL(*parser, handle); |
|
159 //Expected: handler->iNumElements == 6 |
|
160 // Production, Symbian parser. |
|
161 test(handler->iNumElements==6); |
|
162 |
|
163 CleanupStack::PopAndDestroy(parser); |
|
164 CleanupStack::PopAndDestroy(matchData); |
|
165 |
|
166 // Test default behaviour of text/wbxml parser (multiple parsers return Symbian-first) |
|
167 |
|
168 parser = CParser::NewLC(KParserDataType2, *handler); |
|
169 |
|
170 ParseL(*parser, handle); |
|
171 //Expected: handler->iNumElements == 6 |
|
172 // Production, Symbian parser. |
|
173 test(handler->iNumElements==6); |
|
174 |
|
175 CleanupStack::PopAndDestroy(parser); |
|
176 |
|
177 // Test default behaviour of text/unique parser (single parser non-Symbian) |
|
178 |
|
179 parser = CParser::NewLC(KParserDataType3, *handler); |
|
180 |
|
181 ParseL(*parser, handle); |
|
182 //Expected: handler->iNumElements == 1 |
|
183 // Test parser1. |
|
184 test(handler->iNumElements==1); |
|
185 |
|
186 CleanupStack::PopAndDestroy(parser); |
|
187 |
|
188 // Test default behaviour of text/same parser (multiple parser non-Symbian, return lowest uid) |
|
189 |
|
190 parser = CParser::NewLC(KParserDataType4, *handler); |
|
191 |
|
192 ParseL(*parser, handle); |
|
193 //Expected: handler->iNumElements == 1 |
|
194 // Test parser1. |
|
195 test(handler->iNumElements==1); |
|
196 |
|
197 CleanupStack::PopAndDestroy(parser); |
|
198 |
|
199 CleanupStack::PopAndDestroy(&handle); |
|
200 CleanupStack::PopAndDestroy(handler); |
|
201 CleanupStack::PopAndDestroy(&fs); |
|
202 } |
|
203 |
|
204 |
|
205 // --------------------------------------------------- |
|
206 |
|
207 |
|
208 /** |
|
209 @SYMTestCaseID SYSLIB-XML-CT-3735 |
|
210 @SYMTestCaseDesc Parsing a document larger than the Expat internal buffer. |
|
211 @SYMTestPriority Medium |
|
212 @SYMTestActions Checks that a descriptor larger than Expats internal buffer can be parsed successfully. |
|
213 @SYMTestExpectedResults The xml document is parsed correctly. |
|
214 @SYMDEF DEF056122 |
|
215 */ |
|
216 LOCAL_C void DEF056122L() |
|
217 { |
|
218 RFs fs; |
|
219 User::LeaveIfError(fs.Connect()); |
|
220 CleanupClosePushL(fs); |
|
221 |
|
222 RFile result; |
|
223 TFileName filename; |
|
224 User::LeaveIfError(result.Temp(fs, _L("C:\\"), filename, EFileWrite)); |
|
225 CleanupClosePushL(result); |
|
226 |
|
227 TRebuildingContentHandler contentHandler(result); |
|
228 |
|
229 CParser* parser = CParser::NewLC(KParserDataType, contentHandler); |
|
230 |
|
231 |
|
232 // Read the test file into a descriptor |
|
233 |
|
234 RFile file; |
|
235 |
|
236 User::LeaveIfError(file.Open (fs, KBigTestFile(), EFileRead|EFileShareReadersOnly)); |
|
237 CleanupClosePushL (file); |
|
238 |
|
239 TInt size = 0; |
|
240 file.Size (size); |
|
241 |
|
242 HBufC8* rawdocheap = HBufC8::NewLC (size); |
|
243 TPtr8 rawdoc(rawdocheap->Des ()); |
|
244 |
|
245 User::LeaveIfError (file.Read (rawdoc, size)); |
|
246 |
|
247 // Parse the descriptor |
|
248 |
|
249 ParseL(*parser, rawdoc); |
|
250 test(contentHandler.iError==KErrNone); |
|
251 |
|
252 CleanupStack::PopAndDestroy(4); |
|
253 |
|
254 // Test everything worked |
|
255 |
|
256 RFile ref; |
|
257 User::LeaveIfError(ref.Open(fs, KRefFilename, EFileRead)); |
|
258 CleanupClosePushL(ref); |
|
259 User::LeaveIfError(result.Open(fs, filename, EFileRead)); |
|
260 CleanupClosePushL(result); |
|
261 |
|
262 TInt resultSize; |
|
263 User::LeaveIfError(result.Size(resultSize)); |
|
264 TInt refSize; |
|
265 User::LeaveIfError(ref.Size(refSize)); |
|
266 test(resultSize==refSize); |
|
267 |
|
268 TBuf8<256> refBuf; |
|
269 TBuf8<256> resultBuf; |
|
270 |
|
271 while(ref.Read(refBuf)==KErrNone && result.Read(resultBuf)==KErrNone && refBuf.Length()>0) |
|
272 test(refBuf==resultBuf); |
|
273 |
|
274 test(refBuf.Length()==0 && resultBuf.Length()==0); |
|
275 |
|
276 CleanupStack::PopAndDestroy(2); |
|
277 fs.Delete(filename); |
|
278 CleanupStack::PopAndDestroy(&fs); |
|
279 } |
|
280 |
|
281 |
|
282 // --------------------------------------------------- |
|
283 |
|
284 |
|
285 /** |
|
286 @SYMTestCaseID SYSLIB-XML-CT-1598 |
|
287 @SYMTestCaseDesc Tests to make sure XML parser does not crash when parsing a message that is not complete. |
|
288 @SYMTestPriority Medium |
|
289 @SYMTestActions Parses the message that is not complete. |
|
290 @SYMTestExpectedResults Test must not fail. |
|
291 @SYMDEF INC073797 |
|
292 */ |
|
293 LOCAL_C void INC073797() |
|
294 { |
|
295 RFs fs; |
|
296 User::LeaveIfError(fs.Connect()); |
|
297 CleanupClosePushL(fs); |
|
298 |
|
299 RFile result; |
|
300 TFileName filename; |
|
301 User::LeaveIfError(result.Temp(fs, _L("C:\\"), filename, EFileWrite)); |
|
302 CleanupClosePushL(result); |
|
303 |
|
304 TRebuildingContentHandler contentHandler(result); |
|
305 |
|
306 CParser* parser = CParser::NewLC(KParserDataType, contentHandler); |
|
307 |
|
308 parser->ParseL(KIncompleteData()); |
|
309 test(contentHandler.iError==KErrNone); |
|
310 |
|
311 CleanupStack::PopAndDestroy(2); |
|
312 |
|
313 fs.Delete(filename); |
|
314 CleanupStack::PopAndDestroy(&fs); |
|
315 } |
|
316 |
|
317 |
|
318 // --------------------------------------------------- |
|
319 |
|
320 |
|
321 /** |
|
322 @SYMTestCaseID SYSLIB-XML-CT-3736 |
|
323 @SYMTestCaseDesc Parsing an xml file with extended character.. |
|
324 @SYMTestPriority Medium |
|
325 @SYMTestActions Checks that the parser can deal with extended characters - locales outside of ascii. |
|
326 Parses doc_jp_utf.xml, reconstitutes it as xml, and compares with ref_doc_jp_utf.xml. |
|
327 @SYMTestExpectedResults The reconstructed document is the same as the original document. |
|
328 @SYMDEF DEF051379 |
|
329 */ |
|
330 LOCAL_C void DEF051379L() |
|
331 { |
|
332 RFs fs; |
|
333 User::LeaveIfError(fs.Connect()); |
|
334 CleanupClosePushL(fs); |
|
335 TInt pos = 0; |
|
336 |
|
337 //open a temporary results file |
|
338 RFile result; |
|
339 TFileName filename; |
|
340 User::LeaveIfError(result.Temp(fs, _L("C:\\"), filename, EFileWrite)); |
|
341 CleanupClosePushL(result); |
|
342 |
|
343 //reconstitutes the xml from parser callbacks |
|
344 TRebuildingContentHandler contentHandler(result); |
|
345 |
|
346 CParser* parser = CParser::NewLC(KParserDataType, contentHandler); |
|
347 |
|
348 //parse the file |
|
349 ParseL(*parser, fs, KEncodingTestFile()); |
|
350 test(contentHandler.iError==KErrNone); |
|
351 |
|
352 //open the reference file, and compare with results file |
|
353 RFile ref; |
|
354 User::LeaveIfError(ref.Open(fs, KEncodingRefFile, EFileRead)); |
|
355 CleanupClosePushL(ref); |
|
356 |
|
357 User::LeaveIfError(result.Seek(ESeekStart,pos)); |
|
358 |
|
359 TInt resultSize; |
|
360 User::LeaveIfError(result.Size(resultSize)); |
|
361 TInt refSize; |
|
362 User::LeaveIfError(ref.Size(refSize)); |
|
363 test(resultSize==refSize); |
|
364 |
|
365 TBuf8<256> refBuf; |
|
366 TBuf8<256> resultBuf; |
|
367 |
|
368 while(ref.Read(refBuf)==KErrNone && result.Read(resultBuf)==KErrNone && refBuf.Length()>0) |
|
369 test(refBuf==resultBuf); |
|
370 |
|
371 //check that RFile::Read has read the entire contents of each file, |
|
372 //so that length (from cursor position to end of file) == 0 |
|
373 test(refBuf.Length()==0 && resultBuf.Length()==0); |
|
374 |
|
375 |
|
376 CleanupStack::PopAndDestroy(&ref); |
|
377 CleanupStack::PopAndDestroy(parser); |
|
378 CleanupStack::PopAndDestroy(&result); |
|
379 fs.Delete(filename); |
|
380 CleanupStack::PopAndDestroy(&fs); |
|
381 } |
|
382 |
|
383 |
|
384 // --------------------------------------------------- |
|
385 |
|
386 |
|
387 /** |
|
388 @SYMTestCaseID SYSLIB-XML-CT-3737 |
|
389 @SYMTestCaseDesc Parsing multiple documents in sequence. |
|
390 @SYMTestPriority Medium |
|
391 @SYMTestActions Checks that the parser can be reset after parsing one document and used to parse another. |
|
392 @SYMTestExpectedResults The contenthandler is able to deal with the parsing of 2 xml documents in sequence. |
|
393 @SYMPREQ PREQ230 |
|
394 */ |
|
395 LOCAL_C void ResetTestL() |
|
396 { |
|
397 RFs fs; |
|
398 User::LeaveIfError(fs.Connect()); |
|
399 CleanupClosePushL(fs); |
|
400 TSimpleContentHandler contentHandler; |
|
401 |
|
402 CParser* parser = CParser::NewLC(KParserDataType, contentHandler); |
|
403 |
|
404 ParseL(*parser, fs, KSimpleTestFile()); |
|
405 |
|
406 test(contentHandler.iNumElements==6); |
|
407 test(contentHandler.iError==KErrNone); |
|
408 |
|
409 ParseL(*parser, fs, KBigTestFile()); |
|
410 |
|
411 test(contentHandler.iNumElements==832); |
|
412 test(contentHandler.iError==KErrNone); |
|
413 |
|
414 CleanupStack::PopAndDestroy(2); |
|
415 } |
|
416 |
|
417 |
|
418 // --------------------------------------------------- |
|
419 |
|
420 |
|
421 /** |
|
422 @SYMTestCaseID SYSLIB-XML-CT-3738 |
|
423 @SYMTestCaseDesc Parser copes with leaving content handler. |
|
424 @SYMTestPriority Medium |
|
425 @SYMTestActions Checks that the parser copes with a leave from a content handler callback. |
|
426 @SYMTestExpectedResults Tests pass. |
|
427 @SYMPREQ PREQ230 |
|
428 */ |
|
429 LOCAL_C void CallbackLeaveTestL() |
|
430 { |
|
431 TSimpleContentHandler contentHandler; |
|
432 contentHandler.iLeaveOnStartElement = ETrue; |
|
433 |
|
434 CParser* parser = CParser::NewLC(KParserDataType, contentHandler); |
|
435 |
|
436 RFs fs; |
|
437 User::LeaveIfError(fs.Connect()); |
|
438 CleanupClosePushL(fs); |
|
439 |
|
440 TRAPD(err, ParseL(*parser, fs, KSimpleTestFile())); |
|
441 |
|
442 User::LeaveIfError(err); // For OOM testing |
|
443 |
|
444 test(contentHandler.iNumElements==1); |
|
445 test(err==TSimpleContentHandler::KExpectedLeaveCode); |
|
446 |
|
447 contentHandler.iLeaveOnStartElement = EFalse; |
|
448 ParseL(*parser, fs, KSimpleTestFile()); |
|
449 test(contentHandler.iNumElements==6); |
|
450 |
|
451 CleanupStack::PopAndDestroy(2); |
|
452 } |
|
453 |
|
454 |
|
455 // --------------------------------------------------- |
|
456 |
|
457 |
|
458 /** |
|
459 @SYMTestCaseID SYSLIB-XML-CT-3739 |
|
460 @SYMTestCaseDesc Well-formedness errors are propagated. |
|
461 @SYMTestPriority Medium |
|
462 @SYMTestActions Checks that well-formedness errors generated by the parser are propagated. |
|
463 @SYMTestExpectedResults content handler reports the error. |
|
464 @SYMPREQ PREQ230 |
|
465 */ |
|
466 LOCAL_C void InvalidXmlTestL() |
|
467 { |
|
468 TSimpleContentHandler contentHandler; |
|
469 |
|
470 CParser* parser = CParser::NewLC(KParserDataType, contentHandler); |
|
471 |
|
472 RFs fs; |
|
473 User::LeaveIfError(fs.Connect()); |
|
474 CleanupClosePushL(fs); |
|
475 ParseL(*parser, fs, KInvalidTestFile()); |
|
476 if(contentHandler.iError!=EXmlInvalidToken) |
|
477 User::Leave(contentHandler.iError); // For OOM testing |
|
478 |
|
479 CleanupStack::PopAndDestroy(2); |
|
480 } |
|
481 |
|
482 |
|
483 // --------------------------------------------------- |
|
484 |
|
485 |
|
486 /** |
|
487 @SYMTestCaseID SYSLIB-XML-CT-3740 |
|
488 @SYMTestCaseDesc Reporting namespace uri's and prefixes. |
|
489 @SYMTestPriority Medium |
|
490 @SYMTestActions Checks that namespace uri's and prefixes are correctly reported. |
|
491 @SYMTestExpectedResults content handler has no errors. |
|
492 @SYMPREQ PREQ230 |
|
493 */ |
|
494 LOCAL_C void NamespaceTestL() |
|
495 { |
|
496 _LIT8(KDefaultUri, "http://www.symbian.com"); |
|
497 _LIT8(KElementPrefix, "elprefix"); |
|
498 _LIT8(KElementUri, "http://element.uri"); |
|
499 _LIT8(KAttributePrefix, "attprefix"); |
|
500 _LIT8(KAttributeUri, "http://attribute.uri"); |
|
501 |
|
502 TNamespaceContentHandler contentHandler(KDefaultUri, KElementPrefix, KElementUri, KAttributePrefix, KAttributeUri); |
|
503 |
|
504 CParser* parser = CParser::NewLC(KParserDataType, contentHandler); |
|
505 |
|
506 RFs fs; |
|
507 User::LeaveIfError(fs.Connect()); |
|
508 CleanupClosePushL(fs); |
|
509 |
|
510 User::LeaveIfError(parser->EnableFeature(EReportNamespaceMapping)); |
|
511 |
|
512 ParseL(*parser, fs, KNamespaceTestFile()); |
|
513 User::LeaveIfError(contentHandler.iError); // For OOM testing |
|
514 |
|
515 test(contentHandler.iError==KErrNone); |
|
516 |
|
517 CleanupStack::PopAndDestroy(2); |
|
518 } |
|
519 |
|
520 |
|
521 // --------------------------------------------------- |
|
522 |
|
523 |
|
524 /** |
|
525 @SYMTestCaseID SYSLIB-XML-CT-3741 |
|
526 @SYMTestCaseDesc Converting character set. |
|
527 @SYMTestPriority Medium |
|
528 @SYMTestActions Checks that skipped entities are reported. |
|
529 @SYMTestExpectedResults The expected conversion result and the actual conversion result match. |
|
530 @SYMPREQ PREQ230 |
|
531 */ |
|
532 LOCAL_C void SkippedEntityTestL() |
|
533 { |
|
534 TSimpleContentHandler contentHandler; |
|
535 |
|
536 CParser* parser = CParser::NewLC(KParserDataType, contentHandler); |
|
537 |
|
538 RFs fs; |
|
539 User::LeaveIfError(fs.Connect()); |
|
540 CleanupClosePushL(fs); |
|
541 |
|
542 ParseL(*parser, fs, KEntityTestFile()); |
|
543 User::LeaveIfError(contentHandler.iError); // For OOM testing |
|
544 |
|
545 test(contentHandler.iError==KErrNone); |
|
546 test(contentHandler.iNumSkippedEntities==2); |
|
547 |
|
548 CleanupStack::PopAndDestroy(2); |
|
549 } |
|
550 |
|
551 |
|
552 // --------------------------------------------------- |
|
553 |
|
554 |
|
555 /** |
|
556 @SYMTestCaseID SYSLIB-XML-CT-3742 |
|
557 @SYMTestCaseDesc Testing the Features functions of CParser, to make sure they work correctly. |
|
558 @SYMTestPriority Medium |
|
559 @SYMTestActions Create the parser object and enable and disable features, testing if they are allowed or not. |
|
560 @SYMTestExpectedResults Enabling and Disabling features return the expected result. |
|
561 @SYMCR CR0000 |
|
562 */ |
|
563 LOCAL_C void ParserFeatureTestL() |
|
564 { |
|
565 RFs fs; |
|
566 User::LeaveIfError(fs.Connect()); |
|
567 CleanupClosePushL(fs); |
|
568 |
|
569 TCapsContentHandler contentHandler; |
|
570 |
|
571 CParser* parser = CParser::NewLC(KParserDataType, contentHandler); |
|
572 |
|
573 // Use a non-existing feature |
|
574 test(parser->EnableFeature(0xFFFFFFFF) == KErrNotSupported); |
|
575 test(parser->DisableFeature(0xFFFFFFFF) == KErrNotSupported); |
|
576 |
|
577 // Enable defined but unsupported features |
|
578 test(parser->EnableFeature(EErrorOnUnrecognisedTags) == KErrNotSupported); |
|
579 test(parser->EnableFeature(EReportUnrecognisedTags) == KErrNotSupported); |
|
580 test(parser->EnableFeature(ESendFullContentInOneChunk) == KErrNotSupported); |
|
581 test(parser->EnableFeature(ERawContent) == KErrNotSupported); |
|
582 |
|
583 // Enable supported features |
|
584 test(parser->EnableFeature(EReportNamespaces) == KErrNone); |
|
585 test(parser->EnableFeature(EReportNamespacePrefixes) == KErrNone); |
|
586 test(parser->EnableFeature(EReportNamespaceMapping) == KErrNone); |
|
587 test(parser->EnableFeature(EConvertTagsToLowerCase) == KErrNone); |
|
588 |
|
589 // Disable mandatory features |
|
590 test(parser->DisableFeature(EReportNamespacePrefixes)==KErrNotSupported); |
|
591 test(parser->DisableFeature(EReportNamespaces)==KErrNotSupported); |
|
592 |
|
593 // Disable optional features |
|
594 test(parser->DisableFeature(EReportNamespaceMapping) == KErrNone); |
|
595 test(parser->DisableFeature(EConvertTagsToLowerCase) == KErrNone); |
|
596 |
|
597 // Re-enable optional features needed for test |
|
598 test(parser->EnableFeature(EConvertTagsToLowerCase | EReportNamespaceMapping) |
|
599 == KErrNone); |
|
600 |
|
601 ParseL(*parser, fs, KCapsTestFile()); |
|
602 |
|
603 test(contentHandler.iNumElements == 1); |
|
604 test(contentHandler.iNumPrefixMappings == 2); |
|
605 test(contentHandler.iNumPrefixUnmappings == 2); |
|
606 test(contentHandler.iError == KErrNone); |
|
607 |
|
608 TSimpleContentHandler contentHandler2; |
|
609 |
|
610 CParser* parser2 = CParser::NewLC(KParserDataType, contentHandler2); |
|
611 |
|
612 parser2->EnableFeature(EReportNamespaceMapping); |
|
613 |
|
614 ParseL(*parser2, fs, KNamespaceTestFile()); |
|
615 |
|
616 test(contentHandler2.iNumElements == 5); |
|
617 test(contentHandler2.iNumPrefixMappings == 3); |
|
618 test(contentHandler2.iNumPrefixUnmappings == 3); |
|
619 test(contentHandler2.iError == KErrNone); |
|
620 |
|
621 User::LeaveIfError(parser2->DisableFeature(EReportNamespaceMapping)); |
|
622 test(!parser2->IsFeatureEnabled(EReportNamespaceMapping)); |
|
623 |
|
624 ParseL(*parser2, fs, KNamespaceTestFile()); |
|
625 |
|
626 test(contentHandler2.iNumElements == 5); |
|
627 test(contentHandler2.iNumPrefixMappings == 0); |
|
628 test(contentHandler2.iNumPrefixUnmappings == 0); |
|
629 test(contentHandler2.iError == KErrNone); |
|
630 |
|
631 CleanupStack::PopAndDestroy(3); |
|
632 } |
|
633 |
|
634 |
|
635 // --------------------------------------------------- |
|
636 |
|
637 |
|
638 /** |
|
639 @SYMTestCaseID SYSLIB-XML-CT-3745 |
|
640 @SYMTestCaseDesc Checks that two parsers can co-exist without interfering with each other. |
|
641 @SYMTestPriority Medium |
|
642 @SYMTestActions Creates 2 content handlers and parsers. Each parser parses a document and checks for errors. |
|
643 @SYMTestExpectedResults The parsers should not affect each other and no errors should be produced. |
|
644 @SYMPREQ PREQ230 |
|
645 */ |
|
646 LOCAL_C void TwoParserTestL() |
|
647 { |
|
648 TSimpleContentHandler contentHandler1, contentHandler2; |
|
649 |
|
650 CParser* parser1 = CParser::NewLC(KParserDataType, contentHandler1); |
|
651 |
|
652 CParser* parser2 = CParser::NewLC(KParserDataType, contentHandler2); |
|
653 |
|
654 RFs fs; |
|
655 User::LeaveIfError(fs.Connect()); |
|
656 CleanupClosePushL(fs); |
|
657 |
|
658 // Parse some of the big test file |
|
659 ParseL(*parser2, fs, KBigTestFile()); |
|
660 |
|
661 // Check we've read what we expect |
|
662 test(contentHandler1.iNumElements==0); |
|
663 test(contentHandler1.iError==KErrNone); |
|
664 |
|
665 test(contentHandler2.iNumElements==832); |
|
666 test(contentHandler2.iError==KErrNone); |
|
667 |
|
668 ParseL(*parser1, fs, KSimpleTestFile()); |
|
669 |
|
670 test(contentHandler1.iNumElements==6); |
|
671 test(contentHandler1.iError==KErrNone); |
|
672 |
|
673 // Stats for big test file shouldn't have changed as RunL was never called |
|
674 test(contentHandler2.iNumElements==832); |
|
675 test(contentHandler2.iError==KErrNone); |
|
676 |
|
677 CleanupStack::PopAndDestroy(&fs); |
|
678 |
|
679 CleanupStack::PopAndDestroy(2); |
|
680 } |
|
681 |
|
682 |
|
683 // --------------------------------------------------- |
|
684 |
|
685 |
|
686 struct TEndHandler : public MContentHandler |
|
687 { |
|
688 // From MContentHandler |
|
689 void OnStartDocumentL(const RDocumentParameters& , TInt ) {}; |
|
690 void OnEndDocumentL(TInt) {}; |
|
691 void OnStartElementL(const RTagInfo& , const RAttributeArray& , TInt ) {}; |
|
692 void OnEndElementL(const RTagInfo& aElement, TInt aErrorCode) |
|
693 { |
|
694 User::LeaveIfError(aErrorCode); |
|
695 |
|
696 const TDesC8& localPart8 = aElement.LocalName().DesC(); |
|
697 const TDesC8& prefix8 = aElement.Prefix().DesC(); |
|
698 |
|
699 iOut.Append(_L8("</")); |
|
700 |
|
701 if(prefix8.Length()) |
|
702 { |
|
703 iOut.Append(prefix8); |
|
704 iOut.Append(_L8(":")); |
|
705 } |
|
706 iOut.Append(localPart8); |
|
707 iOut.Append(_L8(">")); |
|
708 }; |
|
709 void OnContentL(const TDesC8& , TInt ) {}; |
|
710 void OnStartPrefixMappingL(const RString& , const RString& , TInt ) {}; |
|
711 void OnEndPrefixMappingL(const RString& , TInt ) {}; |
|
712 void OnIgnorableWhiteSpaceL(const TDesC8& , TInt ) {}; |
|
713 void OnSkippedEntityL(const RString& , TInt ) {}; |
|
714 void OnProcessingInstructionL(const TDesC8& , const TDesC8& , TInt ) {}; |
|
715 void OnExtensionL(const RString& , TInt , TInt ) {}; |
|
716 void OnError(TInt aErrorCode) { iError = aErrorCode; }; |
|
717 TAny* GetExtendedInterface(const TInt32 ) {return 0;}; |
|
718 |
|
719 TBuf8<0x100> iOut; |
|
720 TInt iError; |
|
721 }; |
|
722 |
|
723 |
|
724 // --------------------------------------------------- |
|
725 |
|
726 |
|
727 /** |
|
728 @SYMTestCaseID SYSLIB-XML-CT-3743 |
|
729 @SYMTestCaseDesc Testing the Expat parser. |
|
730 @SYMTestPriority Medium |
|
731 @SYMTestActions Creating a simple content handler and parser. Parsing strings and checking the return error code what is expected. |
|
732 @SYMTestExpectedResults The results returned by the content handler should be those that are expected. |
|
733 @SYMCR CR0000 |
|
734 */ |
|
735 LOCAL_C void ExpatTestL() |
|
736 { |
|
737 TSimpleContentHandler handler; |
|
738 |
|
739 CParser* parser = CParser::NewLC(KParserDataType, handler); |
|
740 |
|
741 // Here the string is truncated because of the NULL. |
|
742 ParseL(*parser, _L8("<doc>\0</doc>")); |
|
743 test(handler.iError==EXmlNoElements); |
|
744 |
|
745 handler.iError = KErrNone; |
|
746 ParseL(*parser, _L8("<doc></dic>")); |
|
747 test(handler.iError==EXmlTagMismatch); |
|
748 |
|
749 handler.iError = KErrNone; |
|
750 ParseL(*parser, _L8("\n<?xml version='1.0'?>\n<a/>")); |
|
751 test(handler.iError==EXmlMisplacedPi); |
|
752 |
|
753 handler.iError = KErrNone; |
|
754 ParseL(*parser, _L8("<?xml version=\"1.0\" encoding=\"UTF-38x\"?>\n\r<doc></doc>")); |
|
755 test(handler.iError==EXmlUnknownEncoding); |
|
756 |
|
757 handler.iError = KErrNone; |
|
758 ParseL(*parser, _L8("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\r<doc></doc>")); |
|
759 test(handler.iError==KErrNone); |
|
760 |
|
761 handler.iError = KErrNone; |
|
762 ParseL(*parser, _L8("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\r<doc>hello</doc>")); |
|
763 test(handler.iError==KErrNone); |
|
764 |
|
765 handler.iError = KErrNone; |
|
766 ParseL(*parser, _L8("<?xml version=\"1.0\" encoding=\"\"?>\n\r<doc></doc>")); |
|
767 test(handler.iError==EXmlSyntax); |
|
768 |
|
769 handler.iError = KErrNone; |
|
770 ParseL(*parser, _L8("<?xml version=\"1.0\"?>\n\r<doc></doc>")); |
|
771 test(handler.iError==KErrNone); |
|
772 |
|
773 TEndHandler end; |
|
774 end.iError=KErrNone; |
|
775 CleanupStack::PopAndDestroy(parser); |
|
776 parser = CParser::NewLC(KParserDataType, end); |
|
777 |
|
778 ParseL(*parser, _L8("<a><b><c/></b><d><e/></d></a>")); |
|
779 test(end.iError==KErrNone); |
|
780 test(end.iOut==_L8("</c></b></e></d></a>")); |
|
781 |
|
782 CleanupStack::PopAndDestroy(parser); |
|
783 } |
|
784 |
|
785 |
|
786 // --------------------------------------------------- |
|
787 |
|
788 |
|
789 /** |
|
790 @SYMTestCaseID SYSLIB-XML-CT-3744 |
|
791 @SYMTestCaseDesc Function to convert a test into an OOM test. |
|
792 @SYMTestPriority Medium |
|
793 @SYMTestActions Creates a low memory situation and runs the set of tests to make sure the component(s) works in such conditions. |
|
794 @SYMTestExpectedResults Tests continue to pass, even in low memory conditions. |
|
795 @SYMPREQ PREQ230 |
|
796 */ |
|
797 LOCAL_C void OomTest(void (*testFuncL)()) |
|
798 { |
|
799 TInt error; |
|
800 TInt count = 0; |
|
801 |
|
802 do |
|
803 { |
|
804 User::__DbgSetAllocFail(RHeap::EUser, RHeap::EFailNext, ++count); |
|
805 User::__DbgMarkStart(RHeap::EUser); |
|
806 TRAP(error, (testFuncL)()); |
|
807 User::__DbgMarkEnd(RHeap::EUser, 0); |
|
808 } while(error == KErrNoMemory); |
|
809 |
|
810 _LIT(KTestFailed, "Out of memory test failure on iteration %d\n"); |
|
811 __ASSERT_ALWAYS(error==KErrNone, test.Panic(error, KTestFailed, count)); |
|
812 |
|
813 User::__DbgSetAllocFail(RHeap::EUser, RHeap::ENone, 1); |
|
814 } |
|
815 |
|
816 |
|
817 // --------------------------------------------------- |
|
818 |
|
819 |
|
820 // RunTestsL |
|
821 // MainL |
|
822 // E32Main |
|
823 // |
|
824 // Top-level functions |
|
825 |
|
826 LOCAL_C void RunTestsL() |
|
827 { |
|
828 test.Title(); |
|
829 |
|
830 test.Start(_L("Unziping test xml files")); |
|
831 |
|
832 RFs fs; |
|
833 User::LeaveIfError(fs.Connect()); |
|
834 CleanupClosePushL(fs); |
|
835 |
|
836 CUnzip* unzip = CUnzip::NewLC(fs, KZipTestFile); |
|
837 unzip->ExtractL(KXmlTestDir); |
|
838 CleanupStack::PopAndDestroy(unzip); |
|
839 |
|
840 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3734 Basic XML parsing test ")); |
|
841 BasicParsingTestL(); |
|
842 |
|
843 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3735 DEF056122 descriptors greater than 2048 (Expat internal buffer size) ")); |
|
844 DEF056122L(); |
|
845 |
|
846 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3736 DEF051379 parsing encoded characters ")); |
|
847 DEF051379L(); |
|
848 |
|
849 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-1598 INC073797: Stack crashes sometimes in XML parsing in 3.0 platform ")); |
|
850 INC073797(); |
|
851 |
|
852 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3737 Reset mechanism ")); |
|
853 ResetTestL(); |
|
854 |
|
855 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3738 Leave from callback ")); |
|
856 CallbackLeaveTestL(); |
|
857 |
|
858 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3739 Invalid XML handling ")); |
|
859 InvalidXmlTestL(); |
|
860 |
|
861 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3740 Namespace testing ")); |
|
862 NamespaceTestL(); |
|
863 |
|
864 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3741 Skipped entity test ")); |
|
865 SkippedEntityTestL(); |
|
866 |
|
867 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3742 Parser features test ")); |
|
868 ParserFeatureTestL(); |
|
869 |
|
870 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-1578 INC073582: SS31 Symbian XML Framework - Symbian SAX Plugin is not returned by default ")); |
|
871 INC073582L(); |
|
872 |
|
873 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3743 ")); |
|
874 ExpatTestL(); |
|
875 |
|
876 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3744 Out-of-Memory testing ")); |
|
877 OomTest(CallbackLeaveTestL); |
|
878 OomTest(InvalidXmlTestL); |
|
879 OomTest(NamespaceTestL); |
|
880 OomTest(SkippedEntityTestL); |
|
881 test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3745 Two-parser test ")); |
|
882 TwoParserTestL(); |
|
883 |
|
884 |
|
885 test.Next(_L("Finished.")); |
|
886 |
|
887 test.End(); |
|
888 |
|
889 test.Close(); |
|
890 |
|
891 CleanupStack::PopAndDestroy(&fs); |
|
892 |
|
893 REComSession::FinalClose(); |
|
894 } |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 LOCAL_C void Main() |
|
900 { |
|
901 TRAPD(err, RunTestsL()); |
|
902 if (err != KErrNone) |
|
903 User::Panic(_L("Testing failed: "), err); |
|
904 } |
|
905 |
|
906 TInt E32Main() |
|
907 { |
|
908 __UHEAP_MARK; |
|
909 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
910 if(!cleanup) |
|
911 return KErrNoMemory; |
|
912 |
|
913 Main(); |
|
914 |
|
915 delete cleanup; |
|
916 __UHEAP_MARKEND; |
|
917 |
|
918 return 0; |
|
919 } |