|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 // INCLUDE FILES |
|
18 #include "TestContentHandler.h" |
|
19 #include "xmlengtester.h" |
|
20 |
|
21 #include <e32svr.h> |
|
22 #include <domain/osextensions/StifParser.h> |
|
23 #include <domain/osextensions/Stiftestinterface.h> |
|
24 |
|
25 #include <Xml\Parser.h> |
|
26 #include <Xml\ParserFeature.h> |
|
27 #include <XmlEngNodeFilter.h> |
|
28 |
|
29 #include <libc\string.h> |
|
30 #include <charconv.h> |
|
31 #include <UTF.H> |
|
32 |
|
33 #include "xmlengtesterdef.h" |
|
34 #include "TestUserData.h" |
|
35 using namespace Xml; |
|
36 |
|
37 |
|
38 class MXmlEngTestNodeFilter : public MXmlEngNodeFilter |
|
39 { |
|
40 public: |
|
41 |
|
42 TXmlEngNodeFilterResult AcceptNode(TXmlEngNode aNode) |
|
43 { |
|
44 _LIT8(KNodeName1,"name"); |
|
45 _LIT8(KNodeName2,"phone"); |
|
46 _LIT8(KNodeName3,"title"); |
|
47 |
|
48 |
|
49 TPtrC8 node1=aNode.AsElement().Name(); |
|
50 |
|
51 if (!aNode.AsElement().Name().Compare(KNodeName2)) |
|
52 { |
|
53 return EReject; |
|
54 } |
|
55 |
|
56 else if (!aNode.AsElement().Name().Compare(KNodeName1)) |
|
57 { |
|
58 return ESkip; |
|
59 } |
|
60 |
|
61 else if (!aNode.AsElement().Name().Compare(KNodeName3)) |
|
62 { |
|
63 return ESkipContents; |
|
64 } |
|
65 else |
|
66 return EAccept; |
|
67 } |
|
68 |
|
69 }; |
|
70 |
|
71 |
|
72 |
|
73 /************************************** DOM ****************************************/ |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CLibxml2Tester::ParseFileDOML |
|
77 // test method function. |
|
78 // (other items were commented in a header). |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 TInt CLibxml2Tester::ParseFileDomL( CStifItemParser& aItem ) |
|
82 { |
|
83 |
|
84 _LIT(KSourceFileErrorName,"No source file name."); |
|
85 _LIT(KEndParsing,"Parsing end."); |
|
86 |
|
87 TPtrC SrcFile; |
|
88 TPtrC tmp; |
|
89 TBool map = TRUE; |
|
90 if ( aItem.GetNextString(SrcFile) != KErrNone ) |
|
91 { |
|
92 TestModuleIf().Printf( infoNum++,KTEST_NAME,KSourceFileErrorName); |
|
93 iLog->Log((TDesC)KSourceFileErrorName); |
|
94 return KErrGeneral; |
|
95 } |
|
96 |
|
97 if ( aItem.GetNextString(tmp) == KErrNone ) |
|
98 { |
|
99 map = FALSE; |
|
100 } |
|
101 TFileName srcFileName; |
|
102 srcFileName.Copy(SrcFile); |
|
103 |
|
104 TInt err; |
|
105 TRAP(err, iDoc = parser.ParseFileL(srcFileName)); |
|
106 |
|
107 if(map && err == KXmlEngErrParsing) |
|
108 { |
|
109 iLastError = parser.GetLastParsingError(); |
|
110 } |
|
111 else |
|
112 { |
|
113 iLastError = err; |
|
114 } |
|
115 TestModuleIf().Printf( infoNum++,KTEST_NAME,KEndParsing); |
|
116 iLog->Log((TDesC)KEndParsing); |
|
117 |
|
118 return KErrNone; |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CLibxml2Tester::SaveXMLtoFileDomL |
|
123 // test method function. |
|
124 // (other items were commented in a header). |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 TInt CLibxml2Tester::SaveXmlToFileDomL( CStifItemParser& aItem ) |
|
128 { |
|
129 |
|
130 _LIT(KOutputFileErrorName,"No output file name."); |
|
131 _LIT(KOutputFileError,"Output file error. Error code: %d"); |
|
132 _LIT(KRootError,"Document has no root element. Error code: %d"); |
|
133 _LIT(KSaveEnd,"File saved."); |
|
134 |
|
135 |
|
136 |
|
137 TPtrC OutputFile; |
|
138 if ( aItem.GetNextString(OutputFile) != KErrNone ) |
|
139 { |
|
140 TestModuleIf().Printf( infoNum++,KTEST_NAME,KOutputFileErrorName); |
|
141 iLog->Log((TDesC)KOutputFileErrorName); |
|
142 return KErrGeneral; |
|
143 } |
|
144 |
|
145 TXmlEngElement root = iDoc.DocumentElement(); |
|
146 if(root.NotNull()) |
|
147 { |
|
148 iDoc.SaveL(OutputFile); |
|
149 } |
|
150 else |
|
151 { |
|
152 TestModuleIf().Printf( infoNum++, KTEST_NAME,KRootError,iLastError); |
|
153 iLog->Log(KRootError, iLastError); |
|
154 |
|
155 RFs fs; |
|
156 User::LeaveIfError(fs.Connect()); |
|
157 CleanupClosePushL(fs); |
|
158 |
|
159 RFile outputFile; |
|
160 TFileName outFileName; |
|
161 outFileName.Copy(OutputFile); |
|
162 |
|
163 // Open output file |
|
164 TInt err = outputFile.Replace(fs,outFileName,EFileShareAny|EFileWrite); |
|
165 |
|
166 // If output file is correct |
|
167 if (err == KErrNone) |
|
168 { |
|
169 outFileName.Format(KRootError,iLastError); |
|
170 |
|
171 HBufC8* buf = NULL; |
|
172 buf = HBufC8::NewLC(outFileName.Length()); |
|
173 buf->Des().Copy(outFileName); |
|
174 |
|
175 outputFile.Write(buf->Des()); |
|
176 outputFile.Close(); |
|
177 |
|
178 CleanupStack::PopAndDestroy(buf); |
|
179 } |
|
180 else |
|
181 { |
|
182 TestModuleIf().Printf( infoNum++,KTEST_NAME, KOutputFileError, err); |
|
183 iLog->Log(KOutputFileError, err); |
|
184 } |
|
185 |
|
186 CleanupStack::PopAndDestroy(&fs); |
|
187 } |
|
188 |
|
189 TestModuleIf().Printf( infoNum++,KTEST_NAME,KSaveEnd); |
|
190 iLog->Log((TDesC)KSaveEnd); |
|
191 |
|
192 return KErrNone; |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CLibxml2Tester::SaveXMLtoBufferUTF16L |
|
197 // test method function. |
|
198 // (other items were commented in a header). |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 TInt CLibxml2Tester::SaveXmlToBufferUTF16L( CStifItemParser& aItem ) |
|
202 { |
|
203 _LIT(KOutputFileErrorName,"No output file name."); |
|
204 _LIT(KOutputFileError,"Output file error. Error code: %d"); |
|
205 _LIT(KRootError,"Document has no root element. Error code: %d"); |
|
206 _LIT(KSaveEnd,"File saved."); |
|
207 |
|
208 _LIT8(enc,"UTF-16"); |
|
209 |
|
210 TPtrC OutputFile; |
|
211 if ( aItem.GetNextString(OutputFile) != KErrNone ) |
|
212 { |
|
213 TestModuleIf().Printf( infoNum++,KTEST_NAME,KOutputFileErrorName); |
|
214 iLog->Log((TDesC)KOutputFileErrorName); |
|
215 return KErrGeneral; |
|
216 } |
|
217 |
|
218 TPtrC flag; |
|
219 TBool useFlag = EFalse; |
|
220 if ( aItem.GetNextString(flag) == KErrNone ) |
|
221 { |
|
222 useFlag = ETrue; |
|
223 } |
|
224 |
|
225 RBuf8 buf; |
|
226 |
|
227 TXmlEngElement root = iDoc.DocumentElement(); |
|
228 if(root.NotNull()) |
|
229 { |
|
230 if(useFlag) |
|
231 { |
|
232 TXmlEngSerializationOptions opt(TXmlEngSerializationOptions::KOptionEncoding | TXmlEngSerializationOptions::KOptionStandalone,enc); |
|
233 iDoc.SaveL(buf,iDoc,opt); |
|
234 CleanupClosePushL( buf ); |
|
235 } |
|
236 else |
|
237 { |
|
238 TXmlEngSerializationOptions opt(0,enc); |
|
239 iDoc.SaveL(buf,iDoc,opt); |
|
240 CleanupClosePushL( buf ); |
|
241 } |
|
242 } |
|
243 else |
|
244 { |
|
245 TestModuleIf().Printf( infoNum++, KTEST_NAME,KRootError,iLastError); |
|
246 iLog->Log(KRootError,iLastError); |
|
247 |
|
248 TBuf<256> buffer; |
|
249 buffer.Format(KRootError,iLastError); |
|
250 TBuf8<256> buffer8; |
|
251 buffer8.Copy(buffer); |
|
252 |
|
253 buf.CreateL(buffer8); |
|
254 CleanupClosePushL(buf); |
|
255 } |
|
256 |
|
257 RFs fs; |
|
258 User::LeaveIfError(fs.Connect()); |
|
259 CleanupClosePushL(fs); |
|
260 |
|
261 RFile outputFile; |
|
262 TFileName outFileName; |
|
263 outFileName.Copy(OutputFile); |
|
264 |
|
265 // Open output file |
|
266 TInt err = outputFile.Replace(fs,outFileName,EFileShareAny|EFileWrite); |
|
267 |
|
268 // If output file is correct |
|
269 if (err == KErrNone) |
|
270 { |
|
271 outputFile.Write(buf); |
|
272 outputFile.Close(); |
|
273 } |
|
274 else |
|
275 { |
|
276 TestModuleIf().Printf( infoNum++,KTEST_NAME, KOutputFileError, err); |
|
277 iLog->Log(KOutputFileError, err); |
|
278 } |
|
279 |
|
280 CleanupStack::PopAndDestroy(&fs); |
|
281 CleanupStack::PopAndDestroy(&buf); |
|
282 |
|
283 TestModuleIf().Printf( infoNum++,KTEST_NAME,KSaveEnd); |
|
284 iLog->Log((TDesC)KSaveEnd); |
|
285 |
|
286 return KErrNone; |
|
287 } |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CLibxml2Tester::TestNodeFilterL |
|
290 // test method function. |
|
291 // (other items were commented in a header). |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 TInt CLibxml2Tester::TestNodeFilterL( CStifItemParser& aItem ) |
|
295 { |
|
296 _LIT(KOutputFileErrorName,"No output file name."); |
|
297 _LIT(KOutputFileError,"Output file error. Error code: %d"); |
|
298 // _LIT(KRootError,"Document has no root element. Error code: %d"); |
|
299 _LIT(KSaveEnd,"File saved."); |
|
300 |
|
301 TPtrC InputFile; |
|
302 if ( aItem.GetNextString(InputFile) != KErrNone ) |
|
303 { |
|
304 TestModuleIf().Printf( infoNum++,KTEST_NAME,KOutputFileErrorName); |
|
305 iLog->Log((TDesC)KOutputFileErrorName); |
|
306 return KErrGeneral; |
|
307 } |
|
308 |
|
309 TPtrC OutputFile; |
|
310 if ( aItem.GetNextString(OutputFile) != KErrNone ) |
|
311 { |
|
312 TestModuleIf().Printf( infoNum++,KTEST_NAME,KOutputFileErrorName); |
|
313 iLog->Log((TDesC)KOutputFileErrorName); |
|
314 return KErrGeneral; |
|
315 } |
|
316 TFileName srcFileName; |
|
317 srcFileName.Copy( InputFile); |
|
318 |
|
319 RBuf8 buf; |
|
320 RXmlEngDocument doc; |
|
321 doc=parser.ParseFileL( srcFileName ); |
|
322 |
|
323 MXmlEngTestNodeFilter* nodefilter = new (ELeave) MXmlEngTestNodeFilter(); |
|
324 CleanupStack::PushL(nodefilter); |
|
325 TXmlEngSerializationOptions options(0); |
|
326 |
|
327 TXmlEngElement root = doc.DocumentElement(); |
|
328 if(root.NotNull()) |
|
329 { |
|
330 |
|
331 options.SetNodeFilter(nodefilter); |
|
332 |
|
333 doc.SaveL(buf,doc,options); |
|
334 CleanupClosePushL( buf ); |
|
335 } |
|
336 |
|
337 RFs fs; |
|
338 User::LeaveIfError(fs.Connect()); |
|
339 CleanupClosePushL(fs); |
|
340 |
|
341 RFile outputFile; |
|
342 TFileName outFileName; |
|
343 outFileName.Copy(OutputFile); |
|
344 |
|
345 // Open output file |
|
346 TInt err = outputFile.Replace(fs,outFileName,EFileShareAny|EFileWrite); |
|
347 |
|
348 // If output file is correct |
|
349 if (err == KErrNone) |
|
350 { |
|
351 outputFile.Write(buf); |
|
352 outputFile.Close(); |
|
353 } |
|
354 else |
|
355 { |
|
356 TestModuleIf().Printf( infoNum++,KTEST_NAME, KOutputFileError, err); |
|
357 iLog->Log(KOutputFileError, err); |
|
358 } |
|
359 |
|
360 CleanupStack::PopAndDestroy(&fs); |
|
361 CleanupStack::PopAndDestroy(&buf); |
|
362 doc.Close(); |
|
363 CleanupStack::PopAndDestroy(); //nodefilter |
|
364 TestModuleIf().Printf( infoNum++,KTEST_NAME,KSaveEnd); |
|
365 iLog->Log((TDesC)KSaveEnd); |
|
366 |
|
367 return KErrNone; |
|
368 } |
|
369 |
|
370 |
|
371 // ----------------------------------------------------------------------------- |
|
372 // CLibxml2Tester::CreateDocumentL |
|
373 // test method function. |
|
374 // (other items were commented in a header). |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 TInt CLibxml2Tester::CreateDocumentL( CStifItemParser& /*aItem*/ ) |
|
378 { |
|
379 _LIT8(name,"doc"); |
|
380 _LIT8(uri,"http://test.com"); |
|
381 _LIT8(arg1,"1.1"); |
|
382 _LIT8(arg2,"http://test2.org"); |
|
383 |
|
384 iDoc.OpenL(DOM_impl); |
|
385 iDoc.CreateDocumentElementL(name); |
|
386 iDoc.DocumentElement().SetDefaultNamespaceL(uri); |
|
387 iDoc.SetStandalone(TRUE); |
|
388 iDoc.SetXmlVersionL(arg1); |
|
389 iDoc.SetDocumentUriL(arg2); |
|
390 return KErrNone; |
|
391 } |
|
392 |
|
393 // ----------------------------------------------------------------------------- |
|
394 // CLibxml2Tester::CheckDocumentParametersL |
|
395 // test method function. |
|
396 // (other items were commented in a header). |
|
397 // ----------------------------------------------------------------------------- |
|
398 // |
|
399 TInt CLibxml2Tester::CheckDocumentParametersL( CStifItemParser& /*aItem*/ ) |
|
400 { |
|
401 _LIT(KStandaloneError,"Standalone checking error."); |
|
402 _LIT(KEncodingError,"Encoding checking error"); |
|
403 _LIT(KVersionError,"Version checking error"); |
|
404 _LIT(KUriError,"Uri checking error"); |
|
405 |
|
406 _LIT8(arg,"1.0"); |
|
407 _LIT8(arg2,"UTF-8"); |
|
408 _LIT8(KDesNull,""); |
|
409 |
|
410 _LIT(KTypeError,"Node type checking error."); |
|
411 if(!(iDoc.NodeType() == TXmlEngNode::EDocument)) |
|
412 { |
|
413 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTypeError); |
|
414 iLog->Log((TDesC)KTypeError); |
|
415 return KErrGeneral; |
|
416 } |
|
417 |
|
418 if(!(iDoc.IsStandalone() == TRUE)) |
|
419 { |
|
420 TestModuleIf().Printf( infoNum++,KTEST_NAME, KStandaloneError); |
|
421 iLog->Log((TDesC)KStandaloneError); |
|
422 return KErrGeneral; |
|
423 } |
|
424 |
|
425 if(iDoc.XmlVersion().Compare(arg)) |
|
426 { |
|
427 TestModuleIf().Printf( infoNum++,KTEST_NAME, KVersionError); |
|
428 iLog->Log((TDesC)KVersionError); |
|
429 return KErrGeneral; |
|
430 } |
|
431 if(iDoc.XmlEncoding().Compare(arg2)) |
|
432 { |
|
433 TestModuleIf().Printf( infoNum++,KTEST_NAME, KEncodingError); |
|
434 iLog->Log((TDesC)KEncodingError); |
|
435 return KErrGeneral; |
|
436 } |
|
437 |
|
438 //if(iDoc.DocumentUri().Compare(NULL) ) |
|
439 if(iDoc.DocumentUri().Compare(KDesNull )) |
|
440 { |
|
441 TestModuleIf().Printf( infoNum++,KTEST_NAME, KUriError); |
|
442 iLog->Log((TDesC)KUriError); |
|
443 return KErrGeneral; |
|
444 } |
|
445 |
|
446 return KErrNone; |
|
447 } |
|
448 |
|
449 // ----------------------------------------------------------------------------- |
|
450 // CLibxml2Tester::CheckNotNullElementL |
|
451 // test method function. |
|
452 // (other items were commented in a header). |
|
453 // ----------------------------------------------------------------------------- |
|
454 // |
|
455 TInt CLibxml2Tester::CheckNotNullElementL( CStifItemParser& /*aItem*/ ) |
|
456 { |
|
457 _LIT8(name,"test"); |
|
458 |
|
459 TXmlEngElement elem; |
|
460 |
|
461 _LIT(KNullError,"Is node null checking error."); |
|
462 |
|
463 if(!elem.IsNull()) |
|
464 { |
|
465 TestModuleIf().Printf( infoNum++,KTEST_NAME, KNullError); |
|
466 iLog->Log((TDesC) KNullError); |
|
467 return KErrGeneral; |
|
468 } |
|
469 |
|
470 iDoc.OpenL(DOM_impl); |
|
471 elem = iDoc.CreateElementL(name); |
|
472 |
|
473 _LIT(KNotNullError,"Is node not null checking error."); |
|
474 |
|
475 if(!elem.NotNull()) |
|
476 { |
|
477 TestModuleIf().Printf( infoNum++,KTEST_NAME, KNotNullError); |
|
478 iLog->Log((TDesC) KNotNullError); |
|
479 return KErrGeneral; |
|
480 } |
|
481 |
|
482 iDoc.Close(); |
|
483 return KErrNone; |
|
484 } |
|
485 |
|
486 // ----------------------------------------------------------------------------- |
|
487 // CLibxml2Tester::CreateDocumentElementL |
|
488 // test method function. |
|
489 // (other items were commented in a header). |
|
490 // ----------------------------------------------------------------------------- |
|
491 // |
|
492 TInt CLibxml2Tester::CreateDocumentElementL( CStifItemParser& /*aItem*/ ) |
|
493 { |
|
494 _LIT8(name, "doc"); |
|
495 _LIT8(uri, "http://test.com"); |
|
496 // _LIT8(arg, ""); |
|
497 _LIT8(ver, "1.0"); |
|
498 |
|
499 iDoc.OpenL(DOM_impl); |
|
500 TXmlEngElement root = iDoc.CreateElementL(name); |
|
501 root.SetDefaultNamespaceL(uri); |
|
502 iDoc.SetStandalone(TRUE); |
|
503 iDoc.SetXmlVersionL(ver); |
|
504 iDoc.SetDocumentElement(root); |
|
505 |
|
506 _LIT(KNamespaceError,"Namespace checking error."); |
|
507 |
|
508 if(iDoc.DocumentElement().DefaultNamespaceL().Uri().Compare(uri)) |
|
509 { |
|
510 TestModuleIf().Printf( infoNum++,KTEST_NAME, KNamespaceError); |
|
511 iLog->Log((TDesC)KNamespaceError); |
|
512 return KErrGeneral; |
|
513 } |
|
514 |
|
515 return KErrNone; |
|
516 } |
|
517 |
|
518 // ----------------------------------------------------------------------------- |
|
519 // CLibxml2Tester::CreateDocumentFromNodeL |
|
520 // test method function. |
|
521 // (other items were commented in a header). |
|
522 // ----------------------------------------------------------------------------- |
|
523 // |
|
524 TInt CLibxml2Tester::CreateDocumentFromNodeL( CStifItemParser& /*aItem*/ ) |
|
525 { |
|
526 _LIT8(name,"doc"); |
|
527 _LIT8(tekst,"test content"); |
|
528 _LIT8(value,"ATTR_value"); |
|
529 _LIT8(cdata,"test < test2 & \r\n> ;"); |
|
530 |
|
531 iDoc.OpenL(DOM_impl); |
|
532 |
|
533 TXmlEngTextNode teNode = iDoc.CreateTextNodeL(tekst); |
|
534 TXmlEngElement elem = iDoc.CreateElementL(name); |
|
535 elem.AppendChildL(teNode); |
|
536 |
|
537 TXmlEngCDATASection cdNode = iDoc.CreateCDATASectionL(cdata); |
|
538 elem.AppendChildL(cdNode); |
|
539 |
|
540 TXmlEngAttr atNode = iDoc.CreateAttributeL(name,value); |
|
541 elem.AppendChildL(atNode); |
|
542 |
|
543 iDoc.SetDocumentElement(elem); |
|
544 |
|
545 RXmlEngDocument doc;// = DOM_impl.CreateDocumentFromNodeL(elem); |
|
546 doc.OpenL(DOM_impl,elem); |
|
547 iDoc.Close(); |
|
548 iDoc = doc.CloneDocumentL(); |
|
549 doc.Close(); |
|
550 |
|
551 TXmlEngProcessingInstruction pcNode = iDoc.CreateProcessingInstructionL(name,value); |
|
552 iDoc.AppendChildL(pcNode); |
|
553 |
|
554 return KErrNone; |
|
555 } |
|
556 |
|
557 // ----------------------------------------------------------------------------- |
|
558 // CLibxml2Tester::CloneDocumentL |
|
559 // test method function. |
|
560 // (other items were commented in a header). |
|
561 // ----------------------------------------------------------------------------- |
|
562 // |
|
563 TInt CLibxml2Tester::CloneDocumentL( CStifItemParser& /*aItem*/ ) |
|
564 { |
|
565 _LIT8(name,"testdoc"); |
|
566 |
|
567 RXmlEngDocument doc = iDoc.CloneDocumentL(); |
|
568 iDoc.Close(); |
|
569 //doc.DocumentElement().SetNameL(name); |
|
570 doc.DocumentElement().AddNewElementL(name); |
|
571 iDoc = doc.CloneDocumentL(); |
|
572 doc.Close(); |
|
573 return KErrNone; |
|
574 } |
|
575 |
|
576 // ----------------------------------------------------------------------------- |
|
577 // CLibxml2Tester::CheckSiblingFunctionsL |
|
578 // test method function. |
|
579 // (other items were commented in a header). |
|
580 // ----------------------------------------------------------------------------- |
|
581 // |
|
582 TInt CLibxml2Tester::CheckSiblingFunctionsL( CStifItemParser& /*aItem*/ ) |
|
583 { |
|
584 TXmlEngElement tmp = iDoc.DocumentElement(); |
|
585 tmp.FirstChild().SetAsLastSibling(); |
|
586 |
|
587 tmp.LastChild().PreviousSibling().SetAsFirstSibling(); |
|
588 |
|
589 tmp.LastChild().PreviousSibling().MoveBeforeSibling(tmp.FirstChild().NextSibling()); |
|
590 |
|
591 tmp.FirstChild().NextSibling().NextSibling().MoveAfterSibling(tmp.LastChild().PreviousSibling()); |
|
592 |
|
593 return KErrNone; |
|
594 } |
|
595 |
|
596 // ----------------------------------------------------------------------------- |
|
597 // CLibxml2Tester::CheckInnerXmlL |
|
598 // test method function. |
|
599 // (other items were commented in a header). |
|
600 // ----------------------------------------------------------------------------- |
|
601 // |
|
602 TInt CLibxml2Tester::CheckInnerXmlL( CStifItemParser& aItem ) |
|
603 { |
|
604 _LIT(KOutputFileErrorName,"No output file name"); |
|
605 |
|
606 TPtrC OutputFile; |
|
607 if ( aItem.GetNextString(OutputFile) != KErrNone ) |
|
608 { |
|
609 TestModuleIf().Printf( infoNum++,KTEST_NAME,KOutputFileErrorName); |
|
610 iLog->Log((TDesC)KOutputFileErrorName); |
|
611 return KErrGeneral; |
|
612 } |
|
613 |
|
614 RBuf8 str; |
|
615 iDoc.DocumentElement().InnerXmlL(str); |
|
616 |
|
617 RFs fs; |
|
618 User::LeaveIfError(fs.Connect()); |
|
619 CleanupClosePushL(fs); |
|
620 |
|
621 RFile outputFile; |
|
622 TFileName outFileName; |
|
623 outFileName.Copy(OutputFile); |
|
624 |
|
625 // Open output file |
|
626 TInt err = outputFile.Replace(fs,outFileName,EFileShareAny|EFileWrite); |
|
627 |
|
628 // If output file is correct |
|
629 if (err == KErrNone) |
|
630 { |
|
631 outputFile.Write(str); |
|
632 outputFile.Close(); |
|
633 } |
|
634 |
|
635 if ( aItem.GetNextString(OutputFile) != KErrNone ) |
|
636 { |
|
637 TestModuleIf().Printf( infoNum++,KTEST_NAME,KOutputFileErrorName); |
|
638 iLog->Log((TDesC)KOutputFileErrorName); |
|
639 return KErrGeneral; |
|
640 } |
|
641 |
|
642 outFileName.Copy(OutputFile); |
|
643 err = outputFile.Replace(fs,outFileName,EFileShareAny|EFileWrite); |
|
644 |
|
645 // If output file is correct |
|
646 if (err == KErrNone) |
|
647 { |
|
648 iDoc.DocumentElement().FirstChild().NextSibling().InnerXmlL(str); |
|
649 outputFile.Write(str); |
|
650 outputFile.Close(); |
|
651 } |
|
652 |
|
653 if ( aItem.GetNextString(OutputFile) != KErrNone ) |
|
654 { |
|
655 TestModuleIf().Printf( infoNum++,KTEST_NAME,KOutputFileErrorName); |
|
656 iLog->Log((TDesC)KOutputFileErrorName); |
|
657 return KErrGeneral; |
|
658 } |
|
659 |
|
660 outFileName.Copy(OutputFile); |
|
661 err = outputFile.Replace(fs,outFileName,EFileShareAny|EFileWrite); |
|
662 |
|
663 // If output file is correct |
|
664 if (err == KErrNone) |
|
665 { |
|
666 iDoc.DocumentElement().FirstChild().NextSibling().NextSibling().FirstChild().InnerXmlL(str); |
|
667 outputFile.Write(str); |
|
668 outputFile.Close(); |
|
669 } |
|
670 if ( aItem.GetNextString(OutputFile) != KErrNone ) |
|
671 { |
|
672 TestModuleIf().Printf( infoNum++,KTEST_NAME,KOutputFileErrorName); |
|
673 iLog->Log((TDesC)KOutputFileErrorName); |
|
674 return KErrGeneral; |
|
675 } |
|
676 |
|
677 outFileName.Copy(OutputFile); |
|
678 err = outputFile.Replace(fs,outFileName,EFileShareAny|EFileWrite); |
|
679 |
|
680 // If output file is correct |
|
681 if (err == KErrNone) |
|
682 { |
|
683 iDoc.DocumentElement().FirstChild().NextSibling().NextSibling().LastChild().InnerXmlL(str); |
|
684 outputFile.Write(str); |
|
685 outputFile.Close(); |
|
686 } |
|
687 |
|
688 str.Close(); |
|
689 CleanupStack::PopAndDestroy(); |
|
690 |
|
691 return KErrNone; |
|
692 } |
|
693 |
|
694 // ----------------------------------------------------------------------------- |
|
695 // CLibxml2Tester::CheckOuterXmlL |
|
696 // test method function. |
|
697 // (other items were commented in a header). |
|
698 // ----------------------------------------------------------------------------- |
|
699 // |
|
700 TInt CLibxml2Tester::CheckOuterXmlL( CStifItemParser& aItem ) |
|
701 { |
|
702 _LIT(KOutputFileErrorName,"No output file name"); |
|
703 |
|
704 TPtrC OutputFile; |
|
705 if ( aItem.GetNextString(OutputFile) != KErrNone ) |
|
706 { |
|
707 TestModuleIf().Printf( infoNum++,KTEST_NAME,KOutputFileErrorName); |
|
708 iLog->Log((TDesC)KOutputFileErrorName); |
|
709 return KErrGeneral; |
|
710 } |
|
711 |
|
712 RBuf8 str; |
|
713 iDoc.DocumentElement().OuterXmlL(str); |
|
714 |
|
715 RFs fs; |
|
716 User::LeaveIfError(fs.Connect()); |
|
717 CleanupClosePushL(fs); |
|
718 |
|
719 RFile outputFile; |
|
720 TFileName outFileName; |
|
721 outFileName.Copy(OutputFile); |
|
722 |
|
723 // Open output file |
|
724 TInt err = outputFile.Replace(fs,outFileName,EFileShareAny|EFileWrite); |
|
725 |
|
726 // If output file is correct |
|
727 if (err == KErrNone) |
|
728 { |
|
729 outputFile.Write(str); |
|
730 outputFile.Close(); |
|
731 } |
|
732 |
|
733 if ( aItem.GetNextString(OutputFile) != KErrNone ) |
|
734 { |
|
735 TestModuleIf().Printf( infoNum++,KTEST_NAME,KOutputFileErrorName); |
|
736 iLog->Log((TDesC)KOutputFileErrorName); |
|
737 return KErrGeneral; |
|
738 } |
|
739 |
|
740 outFileName.Copy(OutputFile); |
|
741 err = outputFile.Replace(fs,outFileName,EFileShareAny|EFileWrite); |
|
742 |
|
743 // If output file is correct |
|
744 if (err == KErrNone) |
|
745 { |
|
746 iDoc.DocumentElement().FirstChild().NextSibling().OuterXmlL(str); |
|
747 outputFile.Write(str); |
|
748 outputFile.Close(); |
|
749 } |
|
750 |
|
751 if ( aItem.GetNextString(OutputFile) != KErrNone ) |
|
752 { |
|
753 TestModuleIf().Printf( infoNum++,KTEST_NAME,KOutputFileErrorName); |
|
754 iLog->Log((TDesC)KOutputFileErrorName); |
|
755 return KErrGeneral; |
|
756 } |
|
757 |
|
758 outFileName.Copy(OutputFile); |
|
759 err = outputFile.Replace(fs,outFileName,EFileShareAny|EFileWrite); |
|
760 |
|
761 // If output file is correct |
|
762 if (err == KErrNone) |
|
763 { |
|
764 iDoc.DocumentElement().FirstChild().NextSibling().NextSibling().FirstChild().OuterXmlL(str); |
|
765 outputFile.Write(str); |
|
766 outputFile.Close(); |
|
767 } |
|
768 if ( aItem.GetNextString(OutputFile) != KErrNone ) |
|
769 { |
|
770 TestModuleIf().Printf( infoNum++,KTEST_NAME,KOutputFileErrorName); |
|
771 iLog->Log((TDesC)KOutputFileErrorName); |
|
772 return KErrGeneral; |
|
773 } |
|
774 |
|
775 outFileName.Copy(OutputFile); |
|
776 err = outputFile.Replace(fs,outFileName,EFileShareAny|EFileWrite); |
|
777 |
|
778 // If output file is correct |
|
779 if (err == KErrNone) |
|
780 { |
|
781 iDoc.DocumentElement().FirstChild().NextSibling().NextSibling().LastChild().OuterXmlL(str); |
|
782 outputFile.Write(str); |
|
783 outputFile.Close(); |
|
784 } |
|
785 |
|
786 str.Close(); |
|
787 CleanupStack::PopAndDestroy(); |
|
788 |
|
789 return KErrNone; |
|
790 } |
|
791 |
|
792 // ----------------------------------------------------------------------------- |
|
793 // CLibxml2Tester::CheckNodeParametersL |
|
794 // test method function. |
|
795 // (other items were commented in a header). |
|
796 // ----------------------------------------------------------------------------- |
|
797 // |
|
798 TInt CLibxml2Tester::CheckNodeParametersL( CStifItemParser& /*aItem*/) |
|
799 { |
|
800 |
|
801 TXmlEngNode tmp = iDoc.DocumentElement(); |
|
802 |
|
803 _LIT8(str,"doc"); |
|
804 _LIT(KNameError,"Name checking error."); |
|
805 if(tmp.Name().Compare(str)) |
|
806 { |
|
807 TestModuleIf().Printf( infoNum++,KTEST_NAME, KNameError); |
|
808 iLog->Log((TDesC)KNameError); |
|
809 return KErrGeneral; |
|
810 } |
|
811 |
|
812 _LIT(KChildError,"Has child nodes checking error."); |
|
813 if(!(tmp.HasChildNodes())) |
|
814 { |
|
815 TestModuleIf().Printf( infoNum++,KTEST_NAME, KChildError); |
|
816 iLog->Log((TDesC)KChildError); |
|
817 return KErrGeneral; |
|
818 } |
|
819 |
|
820 _LIT(KAttrError,"Has attributes checking error."); |
|
821 if(!(tmp.HasAttributes())) |
|
822 { |
|
823 TestModuleIf().Printf( infoNum++,KTEST_NAME, KAttrError); |
|
824 iLog->Log((TDesC)KAttrError); |
|
825 return KErrGeneral; |
|
826 } |
|
827 |
|
828 _LIT8(uri,"http://test.pl"); |
|
829 _LIT(KNamespaceError,"Namespace uri checking error."); |
|
830 if(tmp.NamespaceUri().Compare(uri)) |
|
831 { |
|
832 TestModuleIf().Printf( infoNum++,KTEST_NAME, KNamespaceError); |
|
833 iLog->Log((TDesC)KNamespaceError); |
|
834 return KErrGeneral; |
|
835 } |
|
836 |
|
837 _LIT(KPrefError,"Namespace prefix checking error."); |
|
838 if(tmp.Prefix().Compare(KNullDesC8)) |
|
839 { |
|
840 TestModuleIf().Printf( infoNum++,KTEST_NAME, KPrefError); |
|
841 iLog->Log((TDesC)KPrefError); |
|
842 return KErrGeneral; |
|
843 } |
|
844 |
|
845 tmp = iDoc.DocumentElement().FirstChild().NextSibling(); |
|
846 |
|
847 _LIT8(str2,"test2"); |
|
848 if(tmp.Name().Compare(str2)) |
|
849 { |
|
850 TestModuleIf().Printf( infoNum++,KTEST_NAME, KNameError); |
|
851 iLog->Log((TDesC)KNameError); |
|
852 return KErrGeneral; |
|
853 } |
|
854 |
|
855 if(tmp.HasChildNodes()) |
|
856 { |
|
857 TestModuleIf().Printf( infoNum++,KTEST_NAME, KChildError); |
|
858 iLog->Log((TDesC)KChildError); |
|
859 return KErrGeneral; |
|
860 } |
|
861 |
|
862 if(tmp.HasAttributes()) |
|
863 { |
|
864 TestModuleIf().Printf( infoNum++,KTEST_NAME, KAttrError); |
|
865 iLog->Log((TDesC)KAttrError); |
|
866 return KErrGeneral; |
|
867 } |
|
868 |
|
869 _LIT8(uri2,"http://test.com"); |
|
870 if(tmp.NamespaceUri().Compare(uri2)) |
|
871 { |
|
872 TestModuleIf().Printf( infoNum++,KTEST_NAME, KNamespaceError); |
|
873 iLog->Log((TDesC)KNamespaceError); |
|
874 return KErrGeneral; |
|
875 } |
|
876 |
|
877 _LIT8(pref,"testns"); |
|
878 if(tmp.Prefix().Compare(pref)) |
|
879 { |
|
880 TestModuleIf().Printf( infoNum++,KTEST_NAME, KPrefError); |
|
881 iLog->Log((TDesC)KPrefError); |
|
882 return KErrGeneral; |
|
883 } |
|
884 |
|
885 return KErrNone; |
|
886 } |
|
887 |
|
888 |
|
889 // ----------------------------------------------------------------------------- |
|
890 // CLibxml2Tester::ParentNodesL |
|
891 // test method function. |
|
892 // (other items were commented in a header). |
|
893 // ----------------------------------------------------------------------------- |
|
894 // |
|
895 TInt CLibxml2Tester::ParentNodesL( CStifItemParser& /*aItem*/ ) |
|
896 { |
|
897 TXmlEngNode tmp = iDoc.DocumentElement(); |
|
898 |
|
899 _LIT(KDocError,"Document element checking error."); |
|
900 if(!(tmp.OwnerDocument().IsSameNode(iDoc))) |
|
901 { |
|
902 TestModuleIf().Printf( infoNum++,KTEST_NAME, KDocError); |
|
903 iLog->Log((TDesC)KDocError); |
|
904 return KErrGeneral; |
|
905 } |
|
906 |
|
907 tmp = tmp.FirstChild().NextSibling(); |
|
908 |
|
909 _LIT(KParError,"Parent element checking error."); |
|
910 if(!(tmp.ParentNode().IsSameNode(iDoc.DocumentElement()))) |
|
911 { |
|
912 TestModuleIf().Printf( infoNum++,KTEST_NAME, KParError); |
|
913 iLog->Log((TDesC)KParError); |
|
914 return KErrGeneral; |
|
915 } |
|
916 |
|
917 return KErrNone; |
|
918 } |
|
919 |
|
920 // ----------------------------------------------------------------------------- |
|
921 // CLibxml2Tester::NameModificationL |
|
922 // test method function. |
|
923 // (other items were commented in a header). |
|
924 // ----------------------------------------------------------------------------- |
|
925 // |
|
926 //TInt CLibxml2Tester::NameModificationL( CStifItemParser& /*aItem*/ ) |
|
927 /* { |
|
928 TXmlEngElement tmp = iDoc.DocumentElement().FirstChild().AsElement(); |
|
929 |
|
930 _LIT8(name,"testX"); |
|
931 _LIT8(uri,"c:\testX"); |
|
932 _LIT8(pref,"testXns"); |
|
933 |
|
934 tmp.RenameNodeL(name,uri,pref); |
|
935 |
|
936 tmp = iDoc.DocumentElement().LastChild().PreviousSibling().AsElement(); |
|
937 |
|
938 RXmlEngNodeList<TXmlEngAttr> attrList; |
|
939 tmp.GetAttributes(attrList); |
|
940 |
|
941 TXmlEngAttr attr = attrList.Next(); |
|
942 |
|
943 _LIT(KTypeError,"Node type checking error."); |
|
944 if(!(attr.NodeType() == TXmlEngNode::EAttribute)) |
|
945 { |
|
946 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTypeError); |
|
947 iLog->Log((TDesC)KTypeError); |
|
948 return KErrGeneral; |
|
949 } |
|
950 |
|
951 _LIT8(prevValue,"1"); |
|
952 |
|
953 _LIT(KAttrError,"Attribute value checking error."); |
|
954 if(attr.Value().Compare(prevValue)) |
|
955 { |
|
956 TestModuleIf().Printf( infoNum++,KTEST_NAME, KAttrError); |
|
957 iLog->Log((TDesC)KAttrError); |
|
958 return KErrGeneral; |
|
959 } |
|
960 |
|
961 //_LIT8(attName,"testAttr"); |
|
962 _LIT8(attValue,"testAttrValue"); |
|
963 //attr.SetNameL(attName); |
|
964 attr.SetValueL(attValue); |
|
965 |
|
966 attrList.Close(); |
|
967 |
|
968 return KErrNone; |
|
969 } |
|
970 */ |
|
971 // ----------------------------------------------------------------------------- |
|
972 // CLibxml2Tester::CheckNamespacesL |
|
973 // test method function. |
|
974 // (other items were commented in a header). |
|
975 // ----------------------------------------------------------------------------- |
|
976 // |
|
977 TInt CLibxml2Tester::CheckNamespacesL( CStifItemParser& /*aItem*/ ) |
|
978 { |
|
979 TXmlEngNode tmp = iDoc.DocumentElement(); |
|
980 TXmlEngNamespace nam = tmp.NamespaceDeclaration(); |
|
981 |
|
982 _LIT8(arg,"http://test.pl"); |
|
983 _LIT(KUriError,"Namespace uri checking error."); |
|
984 if(nam.Uri().Compare(arg)) |
|
985 { |
|
986 TestModuleIf().Printf( infoNum++,KTEST_NAME, KUriError); |
|
987 iLog->Log((TDesC)KUriError); |
|
988 return KErrGeneral; |
|
989 } |
|
990 |
|
991 _LIT(KPrefError,"Namespace prefix checking error."); |
|
992 if(nam.Prefix().Compare(KNullDesC8)) |
|
993 { |
|
994 TestModuleIf().Printf( infoNum++,KTEST_NAME, KPrefError); |
|
995 iLog->Log((TDesC)KPrefError); |
|
996 return KErrGeneral; |
|
997 } |
|
998 |
|
999 _LIT(KDefError,"Is default checking error."); |
|
1000 if(!nam.IsDefault()) |
|
1001 { |
|
1002 TestModuleIf().Printf( infoNum++,KTEST_NAME, KDefError); |
|
1003 iLog->Log((TDesC)KDefError); |
|
1004 return KErrGeneral; |
|
1005 } |
|
1006 |
|
1007 _LIT(KDecError,"Is declared checking error."); |
|
1008 if(nam.IsUndefined()) |
|
1009 { |
|
1010 TestModuleIf().Printf( infoNum++,KTEST_NAME, KDecError); |
|
1011 iLog->Log((TDesC)KDecError); |
|
1012 return KErrGeneral; |
|
1013 } |
|
1014 |
|
1015 _LIT(KTypeError,"Node type checking error."); |
|
1016 if(!(nam.NodeType() == TXmlEngNode::ENamespaceDeclaration)) |
|
1017 { |
|
1018 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTypeError); |
|
1019 iLog->Log((TDesC)KTypeError); |
|
1020 return KErrGeneral; |
|
1021 } |
|
1022 |
|
1023 return KErrNone; |
|
1024 } |
|
1025 |
|
1026 // ----------------------------------------------------------------------------- |
|
1027 // CLibxml2Tester::CheckProcessingInstructionL |
|
1028 // test method function. |
|
1029 // (other items were commented in a header). |
|
1030 // ----------------------------------------------------------------------------- |
|
1031 // |
|
1032 TInt CLibxml2Tester::CheckProcessingInstructionL( CStifItemParser& /*aItem*/ ) |
|
1033 { |
|
1034 _LIT8(target,"testtarget"); |
|
1035 _LIT8(data,"data test data"); |
|
1036 |
|
1037 TXmlEngNode tmp = iDoc.DocumentElement(); |
|
1038 TBool i = tmp.HasChildNodes(); |
|
1039 |
|
1040 tmp = tmp.FirstChild(); |
|
1041 |
|
1042 _LIT(KTypeError,"Node type checking error."); |
|
1043 if(!(tmp.NodeType() == TXmlEngNode::EProcessingInstruction)) |
|
1044 { |
|
1045 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTypeError); |
|
1046 iLog->Log((TDesC)KTypeError); |
|
1047 return KErrGeneral; |
|
1048 } |
|
1049 |
|
1050 _LIT(KTargetError,"Target checking error."); |
|
1051 if(tmp.AsProcessingInstruction().Target().Compare(target)) |
|
1052 { |
|
1053 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTargetError); |
|
1054 iLog->Log((TDesC)KTargetError); |
|
1055 return KErrGeneral; |
|
1056 } |
|
1057 |
|
1058 _LIT(KDataError,"Data checking error."); |
|
1059 if(tmp.AsProcessingInstruction().Data().Compare(data)) |
|
1060 { |
|
1061 TestModuleIf().Printf( infoNum++,KTEST_NAME, KDataError); |
|
1062 iLog->Log((TDesC)KDataError); |
|
1063 return KErrGeneral; |
|
1064 } |
|
1065 |
|
1066 _LIT8(arg, "new data"); |
|
1067 tmp.AsProcessingInstruction().SetDataL(arg); |
|
1068 |
|
1069 return KErrNone; |
|
1070 } |
|
1071 |
|
1072 |
|
1073 // ----------------------------------------------------------------------------- |
|
1074 // CLibxml2Tester::CheckCommentsL |
|
1075 // test method function. |
|
1076 // (other items were commented in a header). |
|
1077 // ----------------------------------------------------------------------------- |
|
1078 // |
|
1079 TInt CLibxml2Tester::CheckCommentsL( CStifItemParser& /*aItem*/ ) |
|
1080 { |
|
1081 |
|
1082 TText * text = (TText*) L" new comment 1 "; |
|
1083 TPtrC ptr(text); |
|
1084 |
|
1085 _LIT8(com1, " new comment 1 "); |
|
1086 _LIT8(com2, "added comment 2 "); |
|
1087 |
|
1088 TXmlEngNode tmp = iDoc.FirstChild(); |
|
1089 |
|
1090 _LIT(KTypeError,"Node type checking error."); |
|
1091 if(!(tmp.NodeType() == TXmlEngNode::EComment)) |
|
1092 { |
|
1093 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTypeError); |
|
1094 iLog->Log((TDesC)KTypeError); |
|
1095 return KErrGeneral; |
|
1096 } |
|
1097 |
|
1098 _LIT8(com3, " comment 1 "); |
|
1099 |
|
1100 _LIT(KContentError,"Content checking error."); |
|
1101 if(tmp.AsComment().Contents().Compare(com3)) |
|
1102 { |
|
1103 TestModuleIf().Printf( infoNum++,KTEST_NAME, KContentError); |
|
1104 iLog->Log((TDesC)KContentError); |
|
1105 return KErrGeneral; |
|
1106 } |
|
1107 |
|
1108 tmp.AsComment().SetContentsL(com1); |
|
1109 |
|
1110 |
|
1111 _LIT(KLengthError,"Length checking error."); |
|
1112 if(!(tmp.AsComment().Length() == ptr.Length())) |
|
1113 { |
|
1114 TestModuleIf().Printf( infoNum++,KTEST_NAME, KLengthError); |
|
1115 iLog->Log((TDesC)KLengthError); |
|
1116 return KErrGeneral; |
|
1117 } |
|
1118 |
|
1119 TXmlEngComment com = iDoc.DocumentElement().LastChild().AsComment(); |
|
1120 |
|
1121 if(!(com.NodeType() == TXmlEngNode::EComment)) |
|
1122 { |
|
1123 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTypeError); |
|
1124 iLog->Log((TDesC)KTypeError); |
|
1125 return KErrGeneral; |
|
1126 } |
|
1127 |
|
1128 _LIT8(com4, " comment 2 "); |
|
1129 if(com.AsComment().Contents().Compare(com4)) |
|
1130 { |
|
1131 TestModuleIf().Printf( infoNum++,KTEST_NAME, KContentError); |
|
1132 iLog->Log((TDesC)KContentError); |
|
1133 return KErrGeneral; |
|
1134 } |
|
1135 |
|
1136 com.AppendContentsL(com2); |
|
1137 |
|
1138 // _LIT8(com5, " created comment 3 "); |
|
1139 TXmlEngComment comm; |
|
1140 comm = iDoc.CreateCommentL(); |
|
1141 iDoc.AppendChildL(comm); |
|
1142 |
|
1143 return KErrNone; |
|
1144 } |
|
1145 |
|
1146 |
|
1147 // ----------------------------------------------------------------------------- |
|
1148 // CLibxml2Tester::CheckCDATAL |
|
1149 // test method function. |
|
1150 // (other items were commented in a header). |
|
1151 // ----------------------------------------------------------------------------- |
|
1152 // |
|
1153 TInt CLibxml2Tester::CheckCDATAL( CStifItemParser& /*aItem*/) |
|
1154 { |
|
1155 TXmlEngCDATASection tmp; |
|
1156 tmp = iDoc.DocumentElement().FirstChild().NextSibling().AsCDATASection(); |
|
1157 |
|
1158 _LIT8(data, " < & test cdata > --> "); |
|
1159 |
|
1160 _LIT(KTypeError,"Node type checking error."); |
|
1161 if(!(tmp.NodeType() == TXmlEngNode::ECDATASection)) |
|
1162 { |
|
1163 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTypeError); |
|
1164 iLog->Log((TDesC)KTypeError); |
|
1165 return KErrGeneral; |
|
1166 } |
|
1167 |
|
1168 _LIT(KContentError,"Content checking error."); |
|
1169 if(tmp.Contents().Compare(data)) |
|
1170 { |
|
1171 TestModuleIf().Printf( infoNum++,KTEST_NAME, KContentError); |
|
1172 iLog->Log((TDesC)KContentError); |
|
1173 return KErrGeneral; |
|
1174 } |
|
1175 |
|
1176 _LIT8(com2, "added comment 2 "); |
|
1177 tmp.AppendContentsL(com2); |
|
1178 |
|
1179 return KErrNone; |
|
1180 } |
|
1181 |
|
1182 // ----------------------------------------------------------------------------- |
|
1183 // CLibxml2Tester::CheckTextNodeL |
|
1184 // test method function. |
|
1185 // (other items were commented in a header). |
|
1186 // ----------------------------------------------------------------------------- |
|
1187 // |
|
1188 TInt CLibxml2Tester::CheckTextNodeL( CStifItemParser& /*aItem*/) |
|
1189 { |
|
1190 TXmlEngNode tmp; |
|
1191 tmp = iDoc.DocumentElement().FirstChild(); |
|
1192 |
|
1193 _LIT8(data, "\nline content"); |
|
1194 |
|
1195 _LIT(KTypeError,"Node type checking error."); |
|
1196 if(!(tmp.NodeType() == TXmlEngNode::EText)) |
|
1197 { |
|
1198 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTypeError); |
|
1199 iLog->Log((TDesC)KTypeError); |
|
1200 return KErrGeneral; |
|
1201 } |
|
1202 |
|
1203 _LIT(KWhiteError,"Is whitespace checking error."); |
|
1204 if(!(tmp.AsText().IsElementContentWhitespace())) |
|
1205 { |
|
1206 TestModuleIf().Printf( infoNum++,KTEST_NAME, KWhiteError); |
|
1207 iLog->Log((TDesC)KWhiteError); |
|
1208 return KErrGeneral; |
|
1209 } |
|
1210 |
|
1211 tmp = iDoc.DocumentElement().LastChild(); |
|
1212 TXmlEngTextNode text = tmp.AsText(); |
|
1213 |
|
1214 _LIT(KContentError,"Content checking error."); |
|
1215 TPtrC8 st = text.Contents(); |
|
1216 if(text.Contents().Compare(data)) |
|
1217 { |
|
1218 TestModuleIf().Printf( infoNum++,KTEST_NAME, KContentError); |
|
1219 iLog->Log((TDesC)KContentError); |
|
1220 return KErrGeneral; |
|
1221 } |
|
1222 |
|
1223 _LIT(KLengthError,"Length checking error."); |
|
1224 if(!(text.Length() == data().Length())) |
|
1225 { |
|
1226 TestModuleIf().Printf( infoNum++,KTEST_NAME, KLengthError); |
|
1227 iLog->Log((TDesC)KLengthError); |
|
1228 return KErrGeneral; |
|
1229 } |
|
1230 |
|
1231 _LIT8(com2, " added comment 2 "); |
|
1232 text.AppendContentsL(com2); |
|
1233 |
|
1234 return KErrNone; |
|
1235 } |
|
1236 |
|
1237 |
|
1238 // ----------------------------------------------------------------------------- |
|
1239 // CLibxml2Tester::CloneDocumentL |
|
1240 // test method function. |
|
1241 // (other items were commented in a header). |
|
1242 // ----------------------------------------------------------------------------- |
|
1243 // |
|
1244 //TInt CLibxml2Tester::CheckDocumentFragmentL( CStifItemParser& /*aItem*/ ) |
|
1245 /* { |
|
1246 TXmlEngNode tmp; |
|
1247 tmp = iDoc.DocumentElement().FirstChild(); |
|
1248 |
|
1249 _LIT(KTypeError,"Node type checking error."); |
|
1250 if(!(tmp.AsDocumentFragment().NodeType() == TXmlEngNode::EDocumentFragment)) |
|
1251 { |
|
1252 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTypeError); |
|
1253 iLog->Log((TDesC)KTypeError); |
|
1254 return KErrGeneral; |
|
1255 } |
|
1256 |
|
1257 TXmlEngDocumentFragment docF; |
|
1258 docF = iDoc.CreateDocumentFragmentL(); |
|
1259 if(!(docF.NodeType() == TXmlEngNode::EDocumentFragment)) |
|
1260 { |
|
1261 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTypeError); |
|
1262 iLog->Log((TDesC)KTypeError); |
|
1263 return KErrGeneral; |
|
1264 } |
|
1265 |
|
1266 return KErrNone; |
|
1267 } |
|
1268 */ |
|
1269 |
|
1270 // ----------------------------------------------------------------------------- |
|
1271 // CLibxml2Tester::NodeNamespacePocessingL |
|
1272 // test method function. |
|
1273 // (other items were commented in a header). |
|
1274 // ----------------------------------------------------------------------------- |
|
1275 // |
|
1276 TInt CLibxml2Tester::NodeNamespacePocessingL( CStifItemParser& /*aItem*/ ) |
|
1277 { |
|
1278 TXmlEngNode tmp = iDoc.DocumentElement().FirstChild(); |
|
1279 |
|
1280 _LIT8(uri, "http://test.com"); |
|
1281 _LIT8(uriD, "http://test.pl"); |
|
1282 _LIT8(pref, "testns"); |
|
1283 _LIT(KUriError,"Namespace finding for prefix error."); |
|
1284 if(tmp.LookupNamespaceUriL(pref).Compare(uri)) |
|
1285 { |
|
1286 TestModuleIf().Printf( infoNum++,KTEST_NAME, KUriError); |
|
1287 iLog->Log((TDesC)KUriError); |
|
1288 return KErrGeneral; |
|
1289 } |
|
1290 |
|
1291 _LIT(KPrefError,"Prefix finding for uri error."); |
|
1292 if(tmp.LookupPrefixL(uri).Compare(pref)) |
|
1293 { |
|
1294 TestModuleIf().Printf( infoNum++,KTEST_NAME, KPrefError); |
|
1295 iLog->Log((TDesC)KPrefError); |
|
1296 return KErrGeneral; |
|
1297 } |
|
1298 |
|
1299 _LIT(KDefError,"Is default checking error."); |
|
1300 if(tmp.IsDefaultNamespaceL(uri)) |
|
1301 { |
|
1302 TestModuleIf().Printf( infoNum++,KTEST_NAME, KDefError); |
|
1303 iLog->Log((TDesC)KDefError); |
|
1304 return KErrGeneral; |
|
1305 } |
|
1306 |
|
1307 if(!tmp.IsDefaultNamespaceL(uriD)) |
|
1308 { |
|
1309 TestModuleIf().Printf( infoNum++,KTEST_NAME, KDefError); |
|
1310 iLog->Log((TDesC)KDefError); |
|
1311 return KErrGeneral; |
|
1312 } |
|
1313 return KErrNone; |
|
1314 } |
|
1315 |
|
1316 // ----------------------------------------------------------------------------- |
|
1317 // CLibxml2Tester::ElementNamespacePocessingL |
|
1318 // test method function. |
|
1319 // (other items were commented in a header). |
|
1320 // ----------------------------------------------------------------------------- |
|
1321 // |
|
1322 TInt CLibxml2Tester::ElementNamespacePocessingL( CStifItemParser& /*aItem*/ ) |
|
1323 { |
|
1324 TXmlEngElement tmp = iDoc.DocumentElement().FirstChild().AsElement(); |
|
1325 |
|
1326 _LIT8(uri, "http://test.com"); |
|
1327 _LIT8(uriD, "http://test.pl"); |
|
1328 _LIT8(pref, "testns"); |
|
1329 _LIT(KUriError,"Namespace finding for prefix error."); |
|
1330 if(tmp.LookupNamespaceUriL(pref).Compare(uri)) |
|
1331 { |
|
1332 TestModuleIf().Printf( infoNum++,KTEST_NAME, KUriError); |
|
1333 iLog->Log((TDesC)KUriError); |
|
1334 return KErrGeneral; |
|
1335 } |
|
1336 |
|
1337 _LIT(KPrefError,"Prefix finding for uri error."); |
|
1338 if(tmp.LookupPrefixL(uri).Compare(pref)) |
|
1339 { |
|
1340 TestModuleIf().Printf( infoNum++,KTEST_NAME, KPrefError); |
|
1341 iLog->Log((TDesC)KPrefError); |
|
1342 return KErrGeneral; |
|
1343 } |
|
1344 |
|
1345 _LIT(KDefError,"Default namespace checking error."); |
|
1346 if(tmp.DefaultNamespaceL().Uri().Compare(uriD)) |
|
1347 { |
|
1348 TestModuleIf().Printf( infoNum++,KTEST_NAME, KDefError); |
|
1349 iLog->Log((TDesC)KDefError); |
|
1350 return KErrGeneral; |
|
1351 } |
|
1352 |
|
1353 _LIT8(xmlU,"http://www.w3.org/XML/1998/namespace"); |
|
1354 _LIT8(xmlP,"xml"); |
|
1355 _LIT(KXMLError,"XML namespace checking error."); |
|
1356 if(!(!tmp.TheXMLNamespaceL().Uri().Compare(xmlU) && !tmp.TheXMLNamespaceL().Prefix().Compare(xmlP))) |
|
1357 { |
|
1358 TestModuleIf().Printf( infoNum++,KTEST_NAME, KXMLError); |
|
1359 iLog->Log((TDesC)KXMLError); |
|
1360 return KErrGeneral; |
|
1361 } |
|
1362 |
|
1363 _LIT(KDeclError,"Has namespace declaration function checking error."); |
|
1364 if(!iDoc.DocumentElement().AsElement().HasNsDeclarationForPrefixL(pref)) |
|
1365 { |
|
1366 TestModuleIf().Printf( infoNum++,KTEST_NAME, KDeclError); |
|
1367 iLog->Log((TDesC)KDeclError); |
|
1368 return KErrGeneral; |
|
1369 } |
|
1370 |
|
1371 _LIT8(str,"wrong"); |
|
1372 _LIT8(str2,"http://wrong.com"); |
|
1373 if(tmp.HasNsDeclarationForPrefixL(str)) |
|
1374 { |
|
1375 TestModuleIf().Printf( infoNum++,KTEST_NAME, KDeclError); |
|
1376 iLog->Log((TDesC)KDeclError); |
|
1377 return KErrGeneral; |
|
1378 } |
|
1379 |
|
1380 tmp.FindOrCreateNsDeclL(str2,str); |
|
1381 tmp.FindOrCreateNsDeclL(uri); |
|
1382 _LIT8(str3,"newns"); |
|
1383 _LIT8(str4,"http://newns.com"); |
|
1384 tmp = tmp.NextSibling().AsElement(); |
|
1385 tmp.AddNamespaceDeclarationL (str4,str3); |
|
1386 tmp.SetNoDefaultNamespaceL(); |
|
1387 |
|
1388 return KErrNone; |
|
1389 } |
|
1390 |
|
1391 |
|
1392 // ----------------------------------------------------------------------------- |
|
1393 // CLibxml2Tester::CheckEntityRefL |
|
1394 // test method function. |
|
1395 // (other items were commented in a header). |
|
1396 // ----------------------------------------------------------------------------- |
|
1397 // |
|
1398 TInt CLibxml2Tester::CheckEntityRefL( CStifItemParser& /*aItem*/ ) |
|
1399 { |
|
1400 TXmlEngNode tmp = iDoc.DocumentElement().FirstChild(); |
|
1401 |
|
1402 _LIT(KSimTextError,"Is simple text checking error."); |
|
1403 if(!tmp.IsSimpleTextContents()) |
|
1404 { |
|
1405 TestModuleIf().Printf( infoNum++,KTEST_NAME, KSimTextError); |
|
1406 iLog->Log((TDesC)KSimTextError); |
|
1407 return KErrGeneral; |
|
1408 } |
|
1409 |
|
1410 tmp = iDoc.DocumentElement().LastChild(); |
|
1411 if(tmp.IsSimpleTextContents()) |
|
1412 { |
|
1413 TestModuleIf().Printf( infoNum++,KTEST_NAME, KSimTextError); |
|
1414 iLog->Log((TDesC)KSimTextError); |
|
1415 return KErrGeneral; |
|
1416 } |
|
1417 |
|
1418 TXmlEngEntityReference ref; |
|
1419 ref = tmp.FirstChild().AsEntityReference(); |
|
1420 _LIT(KTypeError,"Node type checking error."); |
|
1421 if(!(ref.NodeType() == TXmlEngNode::EEntityReference)) |
|
1422 { |
|
1423 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTypeError); |
|
1424 iLog->Log((TDesC)KTypeError); |
|
1425 return KErrGeneral; |
|
1426 } |
|
1427 |
|
1428 _LIT8(str, "1.1 test"); |
|
1429 RBuf8 str2; |
|
1430 tmp.WholeTextContentsCopyL(str2); |
|
1431 |
|
1432 _LIT(KContentError,"Content checking error."); |
|
1433 if(str2.Compare(str)) |
|
1434 { |
|
1435 TestModuleIf().Printf( infoNum++,KTEST_NAME, KContentError); |
|
1436 iLog->Log((TDesC)KContentError); |
|
1437 return KErrGeneral; |
|
1438 } |
|
1439 |
|
1440 str2.Close(); |
|
1441 |
|
1442 tmp = tmp.PreviousSibling(); |
|
1443 _LIT8(str3, "test 1.1 test"); |
|
1444 RBuf8 str4; |
|
1445 tmp.WholeTextContentsCopyL(str4); |
|
1446 |
|
1447 if(str4.Compare(str3)) |
|
1448 { |
|
1449 TestModuleIf().Printf( infoNum++,KTEST_NAME, KContentError); |
|
1450 iLog->Log((TDesC)KContentError); |
|
1451 return KErrGeneral; |
|
1452 } |
|
1453 |
|
1454 str4.Close(); |
|
1455 |
|
1456 return KErrNone; |
|
1457 } |
|
1458 |
|
1459 // ----------------------------------------------------------------------------- |
|
1460 // CLibxml2Tester::NodeTreeModificationL |
|
1461 // test method function. |
|
1462 // (other items were commented in a header). |
|
1463 // ----------------------------------------------------------------------------- |
|
1464 // |
|
1465 TInt CLibxml2Tester::NodeTreeModificationL( CStifItemParser& /*aItem*/) |
|
1466 { |
|
1467 TXmlEngNode tmp = iDoc.DocumentElement(); |
|
1468 |
|
1469 TXmlEngNode tmp2 = tmp.FirstChild().CopyL(); |
|
1470 tmp.AppendChildL(tmp2); |
|
1471 |
|
1472 tmp.FirstChild().NextSibling().CopyToL(tmp.LastChild()); |
|
1473 |
|
1474 tmp.LastChild().PreviousSibling().ReplaceWith(tmp.FirstChild().NextSibling()); |
|
1475 |
|
1476 tmp.FirstChild().MoveTo(tmp.FirstChild().NextSibling()); |
|
1477 |
|
1478 return KErrNone; |
|
1479 } |
|
1480 |
|
1481 // ----------------------------------------------------------------------------- |
|
1482 // CLibxml2Tester::NodeTreeDeletingL |
|
1483 // test method function. |
|
1484 // (other items were commented in a header). |
|
1485 // ----------------------------------------------------------------------------- |
|
1486 // |
|
1487 TInt CLibxml2Tester::NodeTreeDeletingL( CStifItemParser& /*aItem*/) |
|
1488 { |
|
1489 TXmlEngNode tmp = iDoc.DocumentElement(); |
|
1490 |
|
1491 TXmlEngNode tmp2 = tmp.FirstChild().Unlink(); |
|
1492 |
|
1493 tmp2 = tmp.LastChild().SubstituteForL(tmp2); |
|
1494 |
|
1495 tmp2.Remove(); |
|
1496 |
|
1497 tmp.FirstChild().Remove(); |
|
1498 |
|
1499 return KErrNone; |
|
1500 } |
|
1501 |
|
1502 // ----------------------------------------------------------------------------- |
|
1503 // CLibxml2Tester::CheckNodeListL |
|
1504 // test method function. |
|
1505 // (other items were commented in a header). |
|
1506 // ----------------------------------------------------------------------------- |
|
1507 // |
|
1508 TInt CLibxml2Tester::CheckNodeListL( CStifItemParser& /*aItem*/ ) |
|
1509 { |
|
1510 TXmlEngNode tmp; |
|
1511 tmp = iDoc.DocumentElement(); |
|
1512 |
|
1513 RXmlEngNodeList<TXmlEngElement> nodeList; |
|
1514 tmp.AsElement().GetChildElements(nodeList); |
|
1515 |
|
1516 _LIT(KChildError,"Child count checking error."); |
|
1517 if(nodeList.Count() != 4) |
|
1518 { |
|
1519 TestModuleIf().Printf( infoNum++,KTEST_NAME, KChildError); |
|
1520 iLog->Log((TDesC)KChildError); |
|
1521 return KErrGeneral; |
|
1522 } |
|
1523 |
|
1524 _LIT(KHasNextError,"Has next checking error."); |
|
1525 if (!nodeList.HasNext()) |
|
1526 { |
|
1527 TestModuleIf().Printf( infoNum++,KTEST_NAME, KHasNextError); |
|
1528 iLog->Log((TDesC)KHasNextError); |
|
1529 return KErrGeneral; |
|
1530 } |
|
1531 |
|
1532 TXmlEngElement tmpE; |
|
1533 tmpE = nodeList.Next(); |
|
1534 |
|
1535 /* _LIT8(name,"elem1"); |
|
1536 _LIT(KNameError,"Has next checking error."); |
|
1537 if (tmpE.TagName().Compare(name)) |
|
1538 { |
|
1539 TestModuleIf().Printf( infoNum++,KTEST_NAME, KNameError); |
|
1540 iLog->Log((TDesC)KNameError); |
|
1541 return KErrGeneral; |
|
1542 } |
|
1543 */ |
|
1544 nodeList.Next(); |
|
1545 nodeList.Next(); |
|
1546 tmpE = nodeList.Next(); |
|
1547 |
|
1548 /* _LIT8(name1,"elem4"); |
|
1549 if (tmpE.TagName().Compare(name1)) |
|
1550 { |
|
1551 TestModuleIf().Printf( infoNum++,KTEST_NAME, KNameError); |
|
1552 iLog->Log((TDesC)KNameError); |
|
1553 return KErrGeneral; |
|
1554 } |
|
1555 */ |
|
1556 nodeList.Next(); |
|
1557 |
|
1558 if (nodeList.HasNext()) |
|
1559 { |
|
1560 TestModuleIf().Printf( infoNum++,KTEST_NAME, KHasNextError); |
|
1561 iLog->Log((TDesC)KHasNextError); |
|
1562 return KErrGeneral; |
|
1563 } |
|
1564 |
|
1565 nodeList.Close(); |
|
1566 |
|
1567 return KErrNone; |
|
1568 } |
|
1569 |
|
1570 // ----------------------------------------------------------------------------- |
|
1571 // CLibxml2Tester::CheckAttributesL |
|
1572 // test method function. |
|
1573 // (other items were commented in a header). |
|
1574 // ----------------------------------------------------------------------------- |
|
1575 // |
|
1576 TInt CLibxml2Tester::CheckAttributesL( CStifItemParser& /*aItem*/ ) |
|
1577 { |
|
1578 TXmlEngElement tmp = iDoc.DocumentElement().FirstChild().AsElement(); |
|
1579 |
|
1580 RXmlEngNodeList<TXmlEngAttr> attrList; |
|
1581 tmp.GetAttributes(attrList); |
|
1582 |
|
1583 TXmlEngAttr tmpA; |
|
1584 tmpA = attrList.Next(); |
|
1585 |
|
1586 _LIT(KTypeError,"Node type checking error."); |
|
1587 if(!(tmpA.NodeType() == TXmlEngNode::EAttribute)) |
|
1588 { |
|
1589 TestModuleIf().Printf( infoNum++,KTEST_NAME, KTypeError); |
|
1590 iLog->Log((TDesC)KTypeError); |
|
1591 return KErrGeneral; |
|
1592 } |
|
1593 |
|
1594 tmpA = tmpA.CopyL(); |
|
1595 tmp.NextSibling().AppendChildL(tmpA); |
|
1596 |
|
1597 tmpA = attrList.Next(); |
|
1598 tmpA.Remove(); |
|
1599 |
|
1600 tmpA = attrList.Next(); |
|
1601 |
|
1602 _LIT(KParError,"Parent element checking error."); |
|
1603 if(!(tmpA.OwnerElement().IsSameNode(tmp))) |
|
1604 { |
|
1605 TestModuleIf().Printf( infoNum++,KTEST_NAME, KParError); |
|
1606 iLog->Log((TDesC)KParError); |
|
1607 return KErrGeneral; |
|
1608 } |
|
1609 |
|
1610 _LIT8(str,"attr3"); |
|
1611 _LIT8(str1,"test"); |
|
1612 _LIT8(str2,"test&test1;test"); |
|
1613 _LIT(KNameError,"Attribute name checking error."); |
|
1614 if(tmpA.Name().Compare(str)) |
|
1615 { |
|
1616 TestModuleIf().Printf( infoNum++,KTEST_NAME, KNameError); |
|
1617 iLog->Log((TDesC)KNameError); |
|
1618 return KErrGeneral; |
|
1619 } |
|
1620 |
|
1621 _LIT(KAttrError,"Attribute value checking error."); |
|
1622 if(tmpA.Value().Compare(str1)) |
|
1623 { |
|
1624 TestModuleIf().Printf( infoNum++,KTEST_NAME, KAttrError); |
|
1625 iLog->Log((TDesC)KAttrError); |
|
1626 return KErrGeneral; |
|
1627 } |
|
1628 |
|
1629 tmpA.SetEscapedValueL(str2); |
|
1630 |
|
1631 tmpA = attrList.Next(); |
|
1632 _LIT8(str3,"1.1tekst"); |
|
1633 RBuf8 tmpS; |
|
1634 tmpA.WholeValueCopyL(tmpS); |
|
1635 _LIT(KAttr2Error,"Attribute value with entity checking error."); |
|
1636 if(tmpS.Compare(str3)) |
|
1637 { |
|
1638 TestModuleIf().Printf( infoNum++,KTEST_NAME, KAttr2Error); |
|
1639 iLog->Log((TDesC)KAttr2Error); |
|
1640 return KErrGeneral; |
|
1641 } |
|
1642 tmpS.Close(); |
|
1643 attrList.Close(); |
|
1644 |
|
1645 return KErrNone; |
|
1646 } |
|
1647 |
|
1648 // ----------------------------------------------------------------------------- |
|
1649 // CLibxml2Tester::CheckElementAttributesL |
|
1650 // test method function. |
|
1651 // (other items were commented in a header). |
|
1652 // ----------------------------------------------------------------------------- |
|
1653 // |
|
1654 TInt CLibxml2Tester::CheckElementAttributesL( CStifItemParser& /*aItem*/ ) |
|
1655 { |
|
1656 TXmlEngElement tmp = iDoc.DocumentElement().FirstChild().AsElement(); |
|
1657 |
|
1658 _LIT8(str,"attr2"); |
|
1659 _LIT8(str2,"wrong"); |
|
1660 |
|
1661 _LIT(KHasAttError,"Has attribute checking error."); |
|
1662 if(!(tmp.HasAttributeL(str,KNullDesC8))) |
|
1663 { |
|
1664 TestModuleIf().Printf( infoNum++,KTEST_NAME, KHasAttError); |
|
1665 iLog->Log((TDesC)KHasAttError); |
|
1666 return KErrGeneral; |
|
1667 } |
|
1668 |
|
1669 if(tmp.HasAttributeL(str,str2)) |
|
1670 { |
|
1671 TestModuleIf().Printf( infoNum++,KTEST_NAME, KHasAttError); |
|
1672 iLog->Log((TDesC)KHasAttError); |
|
1673 return KErrGeneral; |
|
1674 } |
|
1675 |
|
1676 if(tmp.HasAttributeL(str2,KNullDesC8)) |
|
1677 { |
|
1678 TestModuleIf().Printf( infoNum++,KTEST_NAME, KHasAttError); |
|
1679 iLog->Log((TDesC)KHasAttError); |
|
1680 return KErrGeneral; |
|
1681 } |
|
1682 |
|
1683 _LIT8(str3,"tewt"); |
|
1684 _LIT(KAttError,"Attribute node function checking error."); |
|
1685 if(tmp.AttributeNodeL(str,KNullDesC8).Value().Compare(str3)) |
|
1686 { |
|
1687 TestModuleIf().Printf( infoNum++,KTEST_NAME, KAttError); |
|
1688 iLog->Log((TDesC)KAttError); |
|
1689 return KErrGeneral; |
|
1690 } |
|
1691 |
|
1692 _LIT(KAttVError,"Attribute value function checking error."); |
|
1693 if(tmp.AttributeValueL(str,KNullDesC8).Compare(str3)) |
|
1694 { |
|
1695 TestModuleIf().Printf( infoNum++,KTEST_NAME, KAttVError); |
|
1696 iLog->Log((TDesC)KAttVError); |
|
1697 return KErrGeneral; |
|
1698 } |
|
1699 |
|
1700 if(tmp.AttributeValueL(str2,KNullDesC8).Compare(KNullDesC8)) |
|
1701 { |
|
1702 TestModuleIf().Printf( infoNum++,KTEST_NAME, KAttVError); |
|
1703 iLog->Log((TDesC)KAttVError); |
|
1704 return KErrGeneral; |
|
1705 } |
|
1706 |
|
1707 return KErrNone; |
|
1708 } |
|
1709 |
|
1710 // ----------------------------------------------------------------------------- |
|
1711 // CLibxml2Tester::CheckModifAttributesL |
|
1712 // test method function. |
|
1713 // (other items were commented in a header). |
|
1714 // ----------------------------------------------------------------------------- |
|
1715 // |
|
1716 TInt CLibxml2Tester::CheckModifAttributesL( CStifItemParser& /*aItem*/ ) |
|
1717 { |
|
1718 TXmlEngElement tmp = iDoc.DocumentElement().FirstChild().AsElement(); |
|
1719 |
|
1720 _LIT8(str,"attr2"); |
|
1721 _LIT8(str2,"wrong"); |
|
1722 |
|
1723 _LIT8(str4,"attr3"); |
|
1724 tmp.RemoveAttributeL(str4,KNullDesC8); |
|
1725 tmp.SetAttributeL(str,str2); |
|
1726 |
|
1727 tmp = tmp.NextSibling().AsElement(); |
|
1728 _LIT8(uri,"test.com"); |
|
1729 _LIT8(pref,"testns"); |
|
1730 tmp.SetAttributeL(str,str2,uri,pref); |
|
1731 TXmlEngAttr tmpA = iDoc.CreateAttributeL(str4); |
|
1732 tmpA.SetValueL(str4); |
|
1733 tmp.SetAttributeNodeL(tmpA); |
|
1734 |
|
1735 return KErrNone; |
|
1736 } |
|
1737 |
|
1738 // ----------------------------------------------------------------------------- |
|
1739 // CLibxml2Tester::AddingAttributesL |
|
1740 // test method function. |
|
1741 // (other items were commented in a header). |
|
1742 // ----------------------------------------------------------------------------- |
|
1743 // |
|
1744 TInt CLibxml2Tester::AddingAttributesL( CStifItemParser& /*aItem*/ ) |
|
1745 { |
|
1746 TXmlEngElement tmp = iDoc.DocumentElement().FirstChild().AsElement(); |
|
1747 |
|
1748 _LIT8(str,"attr2"); |
|
1749 _LIT8(str2,"wrong"); |
|
1750 _LIT8(pref,"testns"); |
|
1751 _LIT8(uri, "http://test.com"); |
|
1752 |
|
1753 tmp.AddNewAttributeL(str,str2); |
|
1754 tmp.AddNewAttributeWithNsL(str,str2,uri); |
|
1755 |
|
1756 tmp = tmp.NextSibling().AsElement(); |
|
1757 tmp.AddNewAttributeSameNsL(str,str2); |
|
1758 tmp.AddNewAttributeUsePrefixL(str2,str,pref); |
|
1759 |
|
1760 _LIT8(str4,"attr3"); |
|
1761 _LIT8(pref2,"testns2"); |
|
1762 _LIT8(uri2, "http://test.com.pl"); |
|
1763 tmp.AddNewAttributeL(str4,str2,uri2,pref2); |
|
1764 |
|
1765 tmp = tmp.NextSibling().NextSibling().AsElement(); |
|
1766 tmp.RemoveAttributes(); |
|
1767 tmp.CopyAttributesL(iDoc.DocumentElement().FirstChild().AsElement()); |
|
1768 |
|
1769 tmp = tmp.NextSibling().AsElement(); |
|
1770 TXmlEngNamespace tmpNs = tmp.FindOrCreateNsDeclL(uri2,pref2); |
|
1771 tmp.AddNewAttributeL(str4,str,tmpNs); |
|
1772 |
|
1773 return KErrNone; |
|
1774 } |
|
1775 |
|
1776 // ----------------------------------------------------------------------------- |
|
1777 // CLibxml2Tester::AddingElementsL |
|
1778 // test method function. |
|
1779 // (other items were commented in a header). |
|
1780 // ----------------------------------------------------------------------------- |
|
1781 // |
|
1782 TInt CLibxml2Tester::AddingElementsL( CStifItemParser& /*aItem*/ ) |
|
1783 { |
|
1784 TXmlEngElement tmp = iDoc.DocumentElement().FirstChild().AsElement(); |
|
1785 |
|
1786 _LIT8(str,"element"); |
|
1787 _LIT8(str2,"wrong"); |
|
1788 _LIT8(pref,"testns"); |
|
1789 _LIT8(uri, "http://test.com"); |
|
1790 |
|
1791 tmp.AddNewElementL(str); |
|
1792 tmp.AddNewElementWithNsL(str,uri); |
|
1793 |
|
1794 tmp = tmp.NextSibling().AsElement(); |
|
1795 tmp.AddNewElementSameNsL(str); |
|
1796 tmp.AddNewElementUsePrefixL(str2,pref); |
|
1797 |
|
1798 _LIT8(str4,"element3"); |
|
1799 _LIT8(pref2,"testns2"); |
|
1800 _LIT8(uri2, "http://test.com.pl"); |
|
1801 tmp.AddNewElementL(str4,uri2,pref2); |
|
1802 |
|
1803 tmp = tmp.NextSibling().NextSibling().AsElement(); |
|
1804 tmp.CopyChildrenL(iDoc.DocumentElement().FirstChild().AsElement()); |
|
1805 |
|
1806 tmp = tmp.NextSibling().AsElement(); |
|
1807 TXmlEngNamespace tmpNs = tmp.FindOrCreateNsDeclL(uri2,pref2); |
|
1808 tmp.AddNewElementL(str4,tmpNs); |
|
1809 |
|
1810 _LIT8(uri3, "http://test.test.pl"); |
|
1811 tmp.AddNewElementAutoPrefixL(str4,uri3,iDoc.DocumentElement()); |
|
1812 |
|
1813 return KErrNone; |
|
1814 } |
|
1815 |
|
1816 // ----------------------------------------------------------------------------- |
|
1817 // CLibxml2Tester::CheckModifElementL |
|
1818 // test method function. |
|
1819 // (other items were commented in a header). |
|
1820 // ----------------------------------------------------------------------------- |
|
1821 // |
|
1822 TInt CLibxml2Tester::CheckModifElementL( CStifItemParser& /*aItem*/ ) |
|
1823 { |
|
1824 TXmlEngElement tmp = iDoc.DocumentElement().FirstChild().NextSibling().AsElement().CopyL(); |
|
1825 iDoc.DocumentElement().AppendChildL(tmp); |
|
1826 tmp = iDoc.DocumentElement().FirstChild().NextSibling().AsElement().ElementCopyNoChildrenL(FALSE); |
|
1827 iDoc.DocumentElement().AppendChildL(tmp); |
|
1828 iDoc.DocumentElement().FirstChild().NextSibling().AsElement().ClearElement(); |
|
1829 |
|
1830 _LIT8(str,"elem1"); |
|
1831 iDoc.DocumentElement().RemoveChildElementsL(str,KNullDesC8); |
|
1832 |
|
1833 return KErrNone; |
|
1834 } |
|
1835 |
|
1836 // ----------------------------------------------------------------------------- |
|
1837 // CLibxml2Tester::CheckModifElementL |
|
1838 // test method function. |
|
1839 // (other items were commented in a header). |
|
1840 // ----------------------------------------------------------------------------- |
|
1841 // |
|
1842 TInt CLibxml2Tester::CheckNextL( CStifItemParser& /*aItem*/ ) |
|
1843 { |
|
1844 //TDOMString tmp = iDoc.DocumentElement().FirstChild().FirstChild().FirstChild().FirstChild().AsText().Contents(); |
|
1845 //TDOMString tmp = iDoc.DocumentElement().FirstChild().FirstChild().FirstChild().WholeTextValueContextL(); |
|
1846 TPtrC8 tmp = iDoc.DocumentElement().FirstChild().FirstChild().FirstChild().FirstChild().AsCDATASection().Contents(); |
|
1847 HBufC8* test = tmp.AllocL(); //pjj18 leak!!! |
|
1848 return KErrNone; |
|
1849 } |
|
1850 |
|
1851 // ----------------------------------------------------------------------------- |
|
1852 // CLibxml2Tester::SetElementTextL |
|
1853 // test method function. |
|
1854 // (other items were commented in a header). |
|
1855 // ----------------------------------------------------------------------------- |
|
1856 // |
|
1857 TInt CLibxml2Tester::SetElementTextL( CStifItemParser& /*aItem*/ ) |
|
1858 { |
|
1859 TXmlEngElement tmp = iDoc.DocumentElement().FirstChild().AsElement(); |
|
1860 |
|
1861 _LIT8(str4,"test"); |
|
1862 _LIT(KContentError,"Content checking error."); |
|
1863 if(tmp.Text().Compare(str4)) |
|
1864 { |
|
1865 TestModuleIf().Printf( infoNum++,KTEST_NAME, KContentError); |
|
1866 iLog->Log((TDesC)KContentError); |
|
1867 return KErrGeneral; |
|
1868 } |
|
1869 |
|
1870 _LIT8(str,"new text"); |
|
1871 _LIT8(str2," new added text"); |
|
1872 _LIT8(str3,"test&test1;test"); |
|
1873 tmp.SetTextL(str); |
|
1874 tmp.AddTextL(str2); |
|
1875 tmp = tmp.NextSibling().AsElement(); |
|
1876 tmp.SetEscapedTextL(str3); |
|
1877 |
|
1878 _LIT8(name,"elem1"); |
|
1879 _LIT8(uri,"http://test.com"); |
|
1880 RXmlEngNodeList<TXmlEngElement> nodeList; |
|
1881 iDoc.DocumentElement().AsElement().GetElementsByTagNameL(nodeList,name,uri); |
|
1882 |
|
1883 _LIT(KChildError,"GetElementsByTagName checking error."); |
|
1884 if(nodeList.Count() != 2) |
|
1885 { |
|
1886 TestModuleIf().Printf( infoNum++,KTEST_NAME, KChildError); |
|
1887 iLog->Log((TDesC)KChildError); |
|
1888 return KErrGeneral; |
|
1889 } |
|
1890 nodeList.Close(); |
|
1891 |
|
1892 iDoc.DocumentElement().AsElement().GetElementsByTagNameL(nodeList,name, |
|
1893 iDoc.DocumentElement().AsElement().DefaultNamespaceL().Uri()); |
|
1894 if(nodeList.Count() != 1) |
|
1895 { |
|
1896 TestModuleIf().Printf( infoNum++,KTEST_NAME, KChildError); |
|
1897 iLog->Log((TDesC)KChildError); |
|
1898 return KErrGeneral; |
|
1899 } |
|
1900 |
|
1901 iDoc.DocumentElement().AsElement().RemoveNamespaceDeclarations(); |
|
1902 iDoc.DocumentElement().ReconcileNamespacesL(); |
|
1903 nodeList.Close(); |
|
1904 |
|
1905 return KErrNone; |
|
1906 } |
|
1907 |
|
1908 // ----------------------------------------------------------------------------- |
|
1909 // CLibxml2Tester::AddXmlIdL |
|
1910 // test method function. |
|
1911 // (other items were commented in a header). |
|
1912 // ----------------------------------------------------------------------------- |
|
1913 // |
|
1914 TInt CLibxml2Tester::AddXmlIdL( CStifItemParser& aItem ) |
|
1915 { |
|
1916 TXmlEngElement root = iDoc.DocumentElement(); |
|
1917 |
|
1918 RBuf8 nameS; |
|
1919 CleanupClosePushL(nameS); |
|
1920 RBuf8 uriS; |
|
1921 CleanupClosePushL(uriS); |
|
1922 |
|
1923 TPtrC name; |
|
1924 User::LeaveIfError( aItem.GetNextString(name) ); |
|
1925 nameS.CreateL( name.Length() ); |
|
1926 nameS.Copy( name ); |
|
1927 |
|
1928 |
|
1929 TPtrC uri; |
|
1930 if (aItem.GetNextString(uri) == KErrNone) |
|
1931 { |
|
1932 uriS.CreateL( uri.Length() ); |
|
1933 uriS.Copy( uri ); |
|
1934 } |
|
1935 |
|
1936 iDoc.RegisterXmlIdL(nameS,uriS); |
|
1937 CleanupStack::PopAndDestroy(&uriS); |
|
1938 CleanupStack::PopAndDestroy(&nameS); |
|
1939 |
|
1940 return KErrNone; |
|
1941 } |
|
1942 |
|
1943 // ----------------------------------------------------------------------------- |
|
1944 // CLibxml2Tester::AddXmlId2L |
|
1945 // test method function. |
|
1946 // (other items were commented in a header). |
|
1947 // ----------------------------------------------------------------------------- |
|
1948 // |
|
1949 TInt CLibxml2Tester::AddXmlId2L( CStifItemParser& aItem ) |
|
1950 { |
|
1951 TXmlEngElement root = iDoc.DocumentElement(); |
|
1952 |
|
1953 RBuf8 nameS; |
|
1954 CleanupClosePushL(nameS); |
|
1955 RBuf8 uriS; |
|
1956 CleanupClosePushL(uriS); |
|
1957 RBuf8 valueS; |
|
1958 CleanupClosePushL(valueS); |
|
1959 |
|
1960 TPtrC name; |
|
1961 User::LeaveIfError( aItem.GetNextString(name) ); |
|
1962 nameS.CreateL( name.Length() ); |
|
1963 nameS.Copy( name ); |
|
1964 |
|
1965 |
|
1966 TPtrC uri; |
|
1967 aItem.GetNextString(uri); |
|
1968 uriS.CreateL( uri.Length() ); |
|
1969 uriS.Copy( uri ); |
|
1970 |
|
1971 TPtrC value; |
|
1972 aItem.GetNextString(value); |
|
1973 valueS.CreateL( value.Length() ); |
|
1974 valueS.Copy( value ); |
|
1975 |
|
1976 iDoc.RegisterXmlIdL(root.FirstChild().NextSibling().AsElement(),nameS,uriS); |
|
1977 TXmlEngElement element = iDoc.FindElementByXmlIdL(valueS); |
|
1978 |
|
1979 CleanupStack::PopAndDestroy(&valueS); |
|
1980 CleanupStack::PopAndDestroy(&uriS); |
|
1981 CleanupStack::PopAndDestroy(&nameS); |
|
1982 if ( element.NotNull() ) |
|
1983 { |
|
1984 return KErrNone; |
|
1985 } |
|
1986 else |
|
1987 { |
|
1988 return KErrNotFound; |
|
1989 } |
|
1990 } |
|
1991 |
|
1992 // ----------------------------------------------------------------------------- |
|
1993 // CLibxml2Tester::AddXmlId3L |
|
1994 // test method function. |
|
1995 // (other items were commented in a header). |
|
1996 // ----------------------------------------------------------------------------- |
|
1997 // |
|
1998 TInt CLibxml2Tester::AddXmlId3L( CStifItemParser& aItem ) |
|
1999 { |
|
2000 TInt nResult = KErrNone; |
|
2001 TXmlEngElement root = iDoc.DocumentElement(); |
|
2002 |
|
2003 RBuf8 uriS; |
|
2004 CleanupClosePushL(uriS); |
|
2005 |
|
2006 TPtrC uri; |
|
2007 aItem.GetNextString(uri); |
|
2008 uriS.CreateL( uri.Length() ); |
|
2009 uriS.Copy( uri ); |
|
2010 |
|
2011 TPtrC pDirtyReturn; |
|
2012 aItem.GetNextString( pDirtyReturn ); |
|
2013 |
|
2014 TLex inputNum (pDirtyReturn); |
|
2015 TInt dirtyReturn; |
|
2016 inputNum.Val(dirtyReturn); |
|
2017 |
|
2018 TRAPD(trapResult, |
|
2019 iDoc.RegisterXmlIdL(KNullDesC8,uriS); |
|
2020 ); |
|
2021 if (trapResult == dirtyReturn ) nResult = KErrNone; |
|
2022 else if (trapResult != KErrNone) nResult = trapResult; |
|
2023 else nResult = KErrGeneral; |
|
2024 |
|
2025 CleanupStack::PopAndDestroy(&uriS); |
|
2026 return nResult; |
|
2027 } |
|
2028 // ----------------------------------------------------------------------------- |
|
2029 // CLibxml2Tester::FindXmlIdL |
|
2030 // test method function. |
|
2031 // (other items were commented in a header). |
|
2032 // ----------------------------------------------------------------------------- |
|
2033 // |
|
2034 TInt CLibxml2Tester::FindXmlIdL( CStifItemParser& aItem ) |
|
2035 { |
|
2036 TBool shouldFind; |
|
2037 RBuf8 valueS; |
|
2038 CleanupClosePushL( valueS ); |
|
2039 |
|
2040 TPtrC value; |
|
2041 User::LeaveIfError( aItem.GetNextString(value) ); |
|
2042 valueS.CreateL( value.Length() ); |
|
2043 valueS.Copy(value); |
|
2044 |
|
2045 TPtrC ptr; |
|
2046 shouldFind = (aItem.GetNextString(ptr)!=KErrNone); |
|
2047 |
|
2048 TXmlEngElement element = iDoc.FindElementByXmlIdL(valueS); |
|
2049 |
|
2050 CleanupStack::PopAndDestroy( &valueS ); |
|
2051 if ( shouldFind!=(element.IsNull()) ) |
|
2052 { |
|
2053 return KErrNone; |
|
2054 } |
|
2055 else |
|
2056 { |
|
2057 return KErrNotFound; |
|
2058 } |
|
2059 } |
|
2060 |
|
2061 |
|
2062 // ----------------------------------------------------------------------------- |
|
2063 // CLibxml2Tester::SetTextNoEncTestL(CStifItemParser& aItem) |
|
2064 // test method function. |
|
2065 // (other items were commented in a header). |
|
2066 // ----------------------------------------------------------------------------- |
|
2067 // |
|
2068 TInt CLibxml2Tester::SetTextNoEncTestL(CStifItemParser& aItem) |
|
2069 { |
|
2070 TPtrC pDoc; |
|
2071 aItem.GetNextString(pDoc); |
|
2072 |
|
2073 TPtrC pData; |
|
2074 aItem.GetNextString(pData); |
|
2075 |
|
2076 TPtrC pOut; |
|
2077 aItem.GetNextString(pOut); |
|
2078 |
|
2079 iDoc = parser.ParseFileL(pDoc); |
|
2080 |
|
2081 HBufC8* dataBuffer = ReadFileToBufferL(pData); |
|
2082 CleanupStack::PushL( dataBuffer ); |
|
2083 |
|
2084 RXmlEngNodeList<TXmlEngNode> aList; |
|
2085 iDoc.GetChildNodes(aList); |
|
2086 TXmlEngNode current = aList.Next(); |
|
2087 |
|
2088 while( current.NotNull() ) |
|
2089 { |
|
2090 if(current.NodeType() == 1 ) |
|
2091 { |
|
2092 current.AsElement().SetTextNoEncL(dataBuffer->Des()); |
|
2093 } |
|
2094 current = aList.Next(); |
|
2095 } |
|
2096 |
|
2097 iDoc.SaveL(pOut); |
|
2098 |
|
2099 CleanupStack::PopAndDestroy( 1 ); |
|
2100 return KErrNone; |
|
2101 } |
|
2102 |
|
2103 // ----------------------------------------------------------------------------- |
|
2104 // CLibxml2Tester::AppendTextNoEncTestL(CStifItemParser& aItem) |
|
2105 // test method function. |
|
2106 // (other items were commented in a header). |
|
2107 // ----------------------------------------------------------------------------- |
|
2108 // |
|
2109 |
|
2110 TInt CLibxml2Tester::AppendTextNoEncTestL(CStifItemParser& aItem) |
|
2111 { |
|
2112 TPtrC pDoc; |
|
2113 aItem.GetNextString(pDoc); |
|
2114 |
|
2115 TPtrC pData; |
|
2116 aItem.GetNextString(pData); |
|
2117 |
|
2118 TPtrC pOut; |
|
2119 aItem.GetNextString(pOut); |
|
2120 |
|
2121 iDoc = parser.ParseFileL(pDoc); |
|
2122 |
|
2123 HBufC8* dataBuffer = ReadFileToBufferL(pData); |
|
2124 CleanupStack::PushL( dataBuffer ); |
|
2125 |
|
2126 RXmlEngNodeList<TXmlEngNode> aList; |
|
2127 iDoc.GetChildNodes(aList); |
|
2128 TXmlEngNode current = aList.Next(); |
|
2129 |
|
2130 while( current.NotNull() ) |
|
2131 { |
|
2132 if(current.NodeType() == 1 ) |
|
2133 { |
|
2134 current.AsElement().AppendTextNoEncL(dataBuffer->Des()); |
|
2135 break; |
|
2136 } |
|
2137 current = aList.Next(); |
|
2138 } |
|
2139 |
|
2140 iDoc.SaveL(pOut); |
|
2141 |
|
2142 CleanupStack::PopAndDestroy( 1 ); |
|
2143 return KErrNone; |
|
2144 } |
|
2145 // ----------------------------------------------------------------------------- |
|
2146 // CLibxml2Tester::SetValueNoEncTestL(CStifItemParser& aItem) |
|
2147 // Check if predefined entities are not converted into characters they represent |
|
2148 // (other items were commented in a header). |
|
2149 // ----------------------------------------------------------------------------- |
|
2150 // |
|
2151 TInt CLibxml2Tester::SetValueNoEncTestL(CStifItemParser& aItem) |
|
2152 { |
|
2153 TPtrC pDoc; |
|
2154 aItem.GetNextString(pDoc); |
|
2155 |
|
2156 TPtrC pOut; |
|
2157 aItem.GetNextString(pOut); |
|
2158 |
|
2159 iDoc = parser.ParseFileL(pDoc); |
|
2160 // SetupDocumentL(); |
|
2161 TXmlEngElement tmp = iDoc.DocumentElement(); |
|
2162 |
|
2163 _LIT8(str,"attr2"); |
|
2164 _LIT8(str2,"wrong"); |
|
2165 _LIT8(uri, "http://test.com"); |
|
2166 |
|
2167 tmp.AddNewAttributeL(str,str2); |
|
2168 tmp.AddNewAttributeWithNsL(str,str2,uri); |
|
2169 |
|
2170 |
|
2171 TPtrC8 noEnc = _L8("³ ³ ³ < > ! @ $ &"); |
|
2172 |
|
2173 TXmlEngAttr attr; |
|
2174 |
|
2175 if( tmp.HasAttributeL(str)) |
|
2176 { |
|
2177 attr = tmp.AttributeNodeL(str); |
|
2178 } |
|
2179 else |
|
2180 { |
|
2181 return KErrNotFound; |
|
2182 } |
|
2183 |
|
2184 attr.SetValueNoEncL(noEnc); |
|
2185 |
|
2186 iDoc.SaveL(pOut); |
|
2187 |
|
2188 return KErrNone; |
|
2189 } |
|
2190 |
|
2191 // ----------------------------------------------------------------------------- |
|
2192 // CLibxml2Tester::CreateDocument2L |
|
2193 // test method function. |
|
2194 // (other items were commented in a header). |
|
2195 // ----------------------------------------------------------------------------- |
|
2196 // |
|
2197 TInt CLibxml2Tester::CreateDocument2L( CStifItemParser& aItem ) |
|
2198 { |
|
2199 TPtrC pOut; |
|
2200 aItem.GetNextString( pOut ); |
|
2201 |
|
2202 _LIT8(name,"doc"); |
|
2203 _LIT8(uri,"http://test.com"); |
|
2204 _LIT8(arg1,"1.1"); |
|
2205 _LIT8(arg2,"http://test2.org"); |
|
2206 |
|
2207 iDoc.OpenL(DOM_impl); |
|
2208 iDoc.CreateDocumentElementL(name); |
|
2209 iDoc.DocumentElement().SetDefaultNamespaceL(uri); |
|
2210 iDoc.SetStandalone(TRUE); |
|
2211 iDoc.SetXmlVersionL(arg1); |
|
2212 iDoc.SetDocumentUriL(arg2); |
|
2213 |
|
2214 // test function Implementation() |
|
2215 RXmlEngDOMImplementation DOM_impl_2 = iDoc.Implementation(); |
|
2216 RXmlEngDocument iDoc2; |
|
2217 |
|
2218 iDoc2.OpenL(DOM_impl_2, iDoc.DocumentElement()); |
|
2219 iDoc2.SaveL(pOut); |
|
2220 |
|
2221 |
|
2222 return KErrNone; |
|
2223 } |
|
2224 // ----------------------------------------------------------------------------- |
|
2225 // CLibxml2Tester::CreateEntityReferenceTestL |
|
2226 // Check if entity reference is created correctly |
|
2227 // (other items were commented in a header). |
|
2228 // ----------------------------------------------------------------------------- |
|
2229 // |
|
2230 TInt CLibxml2Tester::CreateEntityReferenceTestL(CStifItemParser& aItem) |
|
2231 { |
|
2232 TPtrC pDoc; |
|
2233 aItem.GetNextString(pDoc); |
|
2234 |
|
2235 TPtrC pOut; |
|
2236 aItem.GetNextString(pOut); |
|
2237 |
|
2238 TPtrC8 entity = _L8("#xB3"); |
|
2239 |
|
2240 iDoc = parser.ParseFileL(pDoc); |
|
2241 |
|
2242 TXmlEngEntityReference entref = iDoc.CreateEntityReferenceL(entity); |
|
2243 iDoc.DocumentElement().AppendChildL(entref); |
|
2244 iDoc.SaveL(pOut); |
|
2245 |
|
2246 return KErrNone; |
|
2247 } |
|
2248 |
|
2249 // ----------------------------------------------------------------------------- |
|
2250 // CLibxml2Tester::ParseFileDOM2L |
|
2251 // Parse file with a handle to a file server session |
|
2252 // (other items were commented in a header). |
|
2253 // ----------------------------------------------------------------------------- |
|
2254 // |
|
2255 TInt CLibxml2Tester::ParseFileDom2L( CStifItemParser& aItem ) |
|
2256 { |
|
2257 |
|
2258 _LIT(KSourceFileErrorName,"No source file name."); |
|
2259 _LIT(KEndParsing,"Parsing end."); |
|
2260 |
|
2261 TPtrC SrcFile; |
|
2262 TPtrC tmp; |
|
2263 TBool map = TRUE; |
|
2264 if ( aItem.GetNextString(SrcFile) != KErrNone ) |
|
2265 { |
|
2266 TestModuleIf().Printf( infoNum++,KTEST_NAME,KSourceFileErrorName); |
|
2267 iLog->Log((TDesC)KSourceFileErrorName); |
|
2268 return KErrGeneral; |
|
2269 } |
|
2270 |
|
2271 if ( aItem.GetNextString(tmp) == KErrNone ) |
|
2272 { |
|
2273 map = FALSE; |
|
2274 } |
|
2275 TFileName srcFileName; |
|
2276 srcFileName.Copy(SrcFile); |
|
2277 |
|
2278 RFs aRFs; |
|
2279 aRFs.Connect(); |
|
2280 CleanupClosePushL( aRFs ); |
|
2281 |
|
2282 |
|
2283 TInt err; |
|
2284 TRAP(err, iDoc = parser.ParseFileL(aRFs,srcFileName)); |
|
2285 |
|
2286 if(map && err == KXmlEngErrParsing) |
|
2287 { |
|
2288 iLastError = parser.GetLastParsingError(); |
|
2289 } |
|
2290 else |
|
2291 { |
|
2292 iLastError = err; |
|
2293 } |
|
2294 TestModuleIf().Printf( infoNum++,KTEST_NAME,KEndParsing); |
|
2295 iLog->Log((TDesC)KEndParsing); |
|
2296 |
|
2297 CleanupStack::PopAndDestroy( &aRFs ); |
|
2298 return KErrNone; |
|
2299 } |
|
2300 |
|
2301 // ----------------------------------------------------------------------------- |
|
2302 // CLibxml2Tester::ParseFileDOM3L |
|
2303 // test parse from buffer |
|
2304 // (other items were commented in a header). |
|
2305 // ----------------------------------------------------------------------------- |
|
2306 // |
|
2307 TInt CLibxml2Tester::ParseFileDom3L( CStifItemParser& aItem ) |
|
2308 { |
|
2309 |
|
2310 _LIT(KSourceFileErrorName,"No source file name."); |
|
2311 _LIT(KEndParsing,"Parsing end."); |
|
2312 |
|
2313 TPtrC SrcFile; |
|
2314 TPtrC tmp; |
|
2315 TBool map = TRUE; |
|
2316 if ( aItem.GetNextString(SrcFile) != KErrNone ) |
|
2317 { |
|
2318 TestModuleIf().Printf( infoNum++,KTEST_NAME,KSourceFileErrorName); |
|
2319 iLog->Log((TDesC)KSourceFileErrorName); |
|
2320 return KErrGeneral; |
|
2321 } |
|
2322 |
|
2323 if ( aItem.GetNextString(tmp) == KErrNone ) |
|
2324 { |
|
2325 map = FALSE; |
|
2326 } |
|
2327 HBufC8* buffer = ReadFileL(SrcFile); |
|
2328 CleanupStack::PushL(buffer); |
|
2329 |
|
2330 |
|
2331 TInt err; |
|
2332 TRAP(err, iDoc = parser.ParseL(buffer->Des())); |
|
2333 |
|
2334 if(map && err == KXmlEngErrParsing) |
|
2335 { |
|
2336 iLastError = parser.GetLastParsingError(); |
|
2337 } |
|
2338 else |
|
2339 { |
|
2340 iLastError = err; |
|
2341 } |
|
2342 TestModuleIf().Printf( infoNum++,KTEST_NAME,KEndParsing); |
|
2343 iLog->Log((TDesC)KEndParsing); |
|
2344 |
|
2345 CleanupStack::PopAndDestroy( buffer ); |
|
2346 return KErrNone; |
|
2347 } |
|
2348 |
|
2349 // ----------------------------------------------------------------------------- |
|
2350 // CLibxml2Tester::LookupNamespaceByPrefixTestL |
|
2351 // lookup namespace in node |
|
2352 // (other items were commented in a header). |
|
2353 // ----------------------------------------------------------------------------- |
|
2354 // |
|
2355 TInt CLibxml2Tester::LookupNamespaceByPrefixTestL( CStifItemParser& aItem ) |
|
2356 { |
|
2357 TPtrC pDoc; |
|
2358 aItem.GetNextString(pDoc); |
|
2359 |
|
2360 |
|
2361 TPtrC8 pref = _L8("sip"); |
|
2362 TPtrC8 uri = _L8("http://schemas.live.com/mws/2005/08/messaging"); |
|
2363 |
|
2364 iDoc = parser.ParseFileL( pDoc ); |
|
2365 RXmlEngNodeList<TXmlEngElement> aList; |
|
2366 iDoc.DocumentElement().FirstChild().NextSibling().LastChild().AsElement().GetChildElements(aList); |
|
2367 TXmlEngNamespace found; |
|
2368 TXmlEngElement elem; |
|
2369 for(TInt i = 0; i < aList.Count(); i++) |
|
2370 { |
|
2371 elem = aList.Next(); |
|
2372 found = elem.LookupNamespaceByPrefixL(pref); |
|
2373 if(found.NotNull()) break; |
|
2374 } |
|
2375 |
|
2376 TPtrC8 testPtr = found.Uri(); |
|
2377 return found.Uri().Compare(uri); |
|
2378 } |
|
2379 |
|
2380 // ----------------------------------------------------------------------------- |
|
2381 // CLibxml2Tester::LookupNamespaceByUriTestL |
|
2382 // lookup namespace in node |
|
2383 // (other items were commented in a header). |
|
2384 // ----------------------------------------------------------------------------- |
|
2385 // |
|
2386 TInt CLibxml2Tester::LookupNamespaceByUriTestL( CStifItemParser& aItem ) |
|
2387 { |
|
2388 TPtrC pDoc; |
|
2389 aItem.GetNextString(pDoc); |
|
2390 |
|
2391 |
|
2392 TPtrC8 pref = _L8("sip"); |
|
2393 TPtrC8 uri = _L8("http://schemas.live.com/mws/2005/08/messaging"); |
|
2394 |
|
2395 iDoc = parser.ParseFileL( pDoc ); |
|
2396 RXmlEngNodeList<TXmlEngElement> aList; |
|
2397 iDoc.DocumentElement().FirstChild().NextSibling().LastChild().AsElement().GetChildElements(aList); |
|
2398 TXmlEngNamespace found; |
|
2399 TXmlEngElement elem; |
|
2400 for(TInt i = 0; i < aList.Count(); i++) |
|
2401 { |
|
2402 elem = aList.Next(); |
|
2403 found = elem.LookupNamespaceByUriL(uri); |
|
2404 if(found.NotNull()) break; |
|
2405 } |
|
2406 |
|
2407 TPtrC8 testPtr = found.Uri(); |
|
2408 return found.Prefix().Compare(pref); |
|
2409 } |
|
2410 // ----------------------------------------------------------------------------- |
|
2411 // CLibxml2Tester::LookupNamespaceByPrefixTest2L |
|
2412 // lookup namespace in parent |
|
2413 // (other items were commented in a header). |
|
2414 // ----------------------------------------------------------------------------- |
|
2415 // |
|
2416 TInt CLibxml2Tester::LookupNamespaceByPrefixTest2L( CStifItemParser& aItem ) |
|
2417 { |
|
2418 TPtrC pDoc; |
|
2419 aItem.GetNextString(pDoc); |
|
2420 |
|
2421 |
|
2422 TPtrC8 pref = _L8("S"); |
|
2423 TPtrC8 uri = _L8("http://www.w3.org/2003/05/soap-envelope"); |
|
2424 |
|
2425 iDoc = parser.ParseFileL( pDoc ); |
|
2426 |
|
2427 TXmlEngElement elem = iDoc.DocumentElement().FirstChild().NextSibling().LastChild().AsElement(); |
|
2428 TXmlEngNamespace found = elem.LookupNamespaceByPrefixL(pref); |
|
2429 |
|
2430 |
|
2431 TPtrC8 testPtr = found.Uri(); |
|
2432 return found.Uri().Compare(uri); |
|
2433 } |
|
2434 |
|
2435 // ----------------------------------------------------------------------------- |
|
2436 // CLibxml2Tester::LookupNamespaceByUriTest2L |
|
2437 // lookup namespace in parent |
|
2438 // (other items were commented in a header). |
|
2439 // ----------------------------------------------------------------------------- |
|
2440 // |
|
2441 TInt CLibxml2Tester::LookupNamespaceByUriTest2L( CStifItemParser& aItem ) |
|
2442 { |
|
2443 TPtrC pDoc; |
|
2444 aItem.GetNextString(pDoc); |
|
2445 |
|
2446 |
|
2447 TPtrC8 pref = _L8("S"); |
|
2448 TPtrC8 uri = _L8("http://www.w3.org/2003/05/soap-envelope"); |
|
2449 |
|
2450 iDoc = parser.ParseFileL( pDoc ); |
|
2451 |
|
2452 TXmlEngElement elem = iDoc.DocumentElement().FirstChild().NextSibling().LastChild().AsElement(); |
|
2453 TXmlEngNamespace found = elem.LookupNamespaceByUriL(uri); |
|
2454 |
|
2455 TPtrC8 testPtr = found.Uri(); |
|
2456 return found.Prefix().Compare(pref); |
|
2457 } |
|
2458 // ----------------------------------------------------------------------------- |
|
2459 // CLibxml2Tester::RemoveChildrenTestL |
|
2460 // test parse from buffer |
|
2461 // (other items were commented in a header). |
|
2462 // ----------------------------------------------------------------------------- |
|
2463 // |
|
2464 |
|
2465 TInt CLibxml2Tester::RemoveChildrenTestL( CStifItemParser& aItem) |
|
2466 { |
|
2467 TPtrC pDoc; |
|
2468 aItem.GetNextString(pDoc); |
|
2469 |
|
2470 TPtrC pOut; |
|
2471 aItem.GetNextString( pOut ); |
|
2472 |
|
2473 iDoc = parser.ParseFileL( pDoc ); |
|
2474 iDoc.DocumentElement().FirstChild().NextSibling().LastChild().AsElement().RemoveChildren(); |
|
2475 iDoc.SaveL( pOut ); |
|
2476 |
|
2477 return KErrNone; |
|
2478 |
|
2479 } |
|
2480 // ----------------------------------------------------------------------------- |
|
2481 // CLibxml2Tester::UserDataTestL |
|
2482 // test parse from buffer |
|
2483 // (other items were commented in a header). |
|
2484 // ----------------------------------------------------------------------------- |
|
2485 // |
|
2486 TInt CLibxml2Tester::UserDataTestL( CStifItemParser& aItem ) |
|
2487 { |
|
2488 TPtrC pDoc; |
|
2489 aItem.GetNextString( pDoc ); |
|
2490 |
|
2491 TPtrC pData; |
|
2492 aItem.GetNextString(pData); |
|
2493 |
|
2494 HBufC8* buffer = ReadFileL(pData); |
|
2495 CleanupStack::PushL(buffer); |
|
2496 |
|
2497 iDoc = parser.ParseFileL( pDoc ); |
|
2498 |
|
2499 CTestUserData* data1 = new CTestUserData(); |
|
2500 data1->str.Create(buffer->Des()); |
|
2501 iDoc.DocumentElement().AddUserData(data1); |
|
2502 |
|
2503 |
|
2504 CTestUserData* data2 = (CTestUserData*)iDoc.DocumentElement().UserData(); |
|
2505 if(buffer->Des().Compare(data2->str)) |
|
2506 { |
|
2507 return KErrGeneral; |
|
2508 } |
|
2509 iDoc.DocumentElement().RemoveUserData(); |
|
2510 if(iDoc.DocumentElement().UserData()) |
|
2511 { |
|
2512 return KErrGeneral; |
|
2513 } |
|
2514 |
|
2515 data1->str.Close(); |
|
2516 delete data1; |
|
2517 |
|
2518 CleanupStack::PopAndDestroy( buffer ); |
|
2519 return KErrNone; |
|
2520 } |
|
2521 |
|
2522 // ----------------------------------------------------------------------------- |
|
2523 // CLibxml2Tester::BaseUriTestL |
|
2524 // test base uri |
|
2525 // (other items were commented in a header). |
|
2526 // ----------------------------------------------------------------------------- |
|
2527 // |
|
2528 TInt CLibxml2Tester::BaseUriTestL( CStifItemParser& /*aItem*/) |
|
2529 { |
|
2530 SetupDocumentL(); |
|
2531 TInt nResult; |
|
2532 RBuf8 baseuri; |
|
2533 iElement.LastChild().BaseUriL(baseuri); |
|
2534 if(baseuri.Compare(KNullDesC8)) nResult = KErrGeneral; |
|
2535 else nResult = KErrNone; |
|
2536 baseuri.Close(); |
|
2537 return nResult; |
|
2538 } |
|
2539 |
|
2540 // ----------------------------------------------------------------------------- |
|
2541 // CLibxml2Tester::AddXmlIdTestL |
|
2542 // test base uri |
|
2543 // (other items were commented in a header). |
|
2544 // ----------------------------------------------------------------------------- |
|
2545 // |
|
2546 TInt CLibxml2Tester::AddXmlIdTestL( CStifItemParser& aItem) |
|
2547 { |
|
2548 TPtrC pOut; |
|
2549 aItem.GetNextString( pOut ); |
|
2550 |
|
2551 TPtrC8 pName = _L8("ID"); |
|
2552 TPtrC8 pValue = _L8("1"); |
|
2553 |
|
2554 SetupDocumentL(); |
|
2555 iDoc.DocumentElement().AddXmlIdL(pName , pValue); |
|
2556 |
|
2557 |
|
2558 if ( iDoc.FindElementByXmlIdL(pValue).NotNull() ) |
|
2559 { |
|
2560 iDoc.SaveL( pOut ); |
|
2561 return KErrNone; |
|
2562 } |
|
2563 else |
|
2564 { |
|
2565 return KErrNotFound; |
|
2566 } |
|
2567 } |
|
2568 |
|
2569 // End of file |