Update contrib.
2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 LOCAL_D CTestStep *pTestStep = NULL;
25 TBool __bb = (cond); \
26 pTestStep->TEST(__bb); \
29 pTestStep->ERR_PRINTF1(_L("ERROR: Test Failed")); \
35 // copy from tefexportconst.h
36 #define INFO_PRINTF1(p1) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1))
37 #define INFO_PRINTF2(p1, p2) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2))
40 #define UNUSED_VAR(a) a = a
42 LOCAL_D CTrapCleanup* TheTrapCleanup;
44 template<class S,CEditableText::TDocumentStorage D>
45 class CTestScan : public CPlainText
48 static CTestScan* NewL();
50 void Test1L(); // Tests all operations of the class.
51 void Test2L(); // Test public methods of class.
52 void Test2aL(); // Tests for CountWords
53 void Test2bL(); // Tests for ScanWord
54 void Test2cL(); // Tests for CountParagraphs
55 void Test2dL(); // Tests for ScanParagraph
56 void TestHeapSpace(); // Test for memory leakage
57 void StoreTextL(TBuf<64>&);
58 void DoCountWords(TInt);
59 void DoCountParas(TInt);
60 void DoScanWords(TInt aPos,TUint aFlags,TInt aEndPos,TInt aCharCheck);
61 void DoScanParas(TInt aPos,TUint aFlags,TInt aEndPos,TInt aCharCheck);
62 void InsertL(TInt aPos,const TDesC& aBuf);
64 CPlainText *iDocument;
68 TInt startAvail,endAvail,temp;
70 CTestScan(); // Default constructor
71 CTestScan(const CTestScan& aCTestScan);
72 CTestScan& operator=(const CTestScan& aCTestScan);
76 template<class S,CEditableText::TDocumentStorage D>
77 GLDEF_C CTestScan<S,D>* CTestScan<S,D>::NewL()
79 // constructs a new instance of this class.
82 CTestScan<S,D>* tmp=new(ELeave) CTestScan<S,D>;
88 template<class S,CEditableText::TDocumentStorage D>
89 GLDEF_C CTestScan<S,D>::CTestScan()
91 // Default constructor
93 :iDelimiter(EParagraphDelimiter)
95 TRAPD(ret,iDocument=CPlainText::NewL(D));
100 template<class S,CEditableText::TDocumentStorage D>
101 void CTestScan<S,D>::Destruct()
110 template<class S,CEditableText::TDocumentStorage D>
111 GLDEF_C void CTestScan<S,D>::InsertL(TInt aPos,const TDesC& aBuf)
113 {CPlainText::InsertL(aPos,aBuf);}
117 template<class S,CEditableText::TDocumentStorage D>
118 GLDEF_C void CTestScan<S,D>::StoreTextL(TBuf<64>& aBuf)
120 // Insert from aBuf into document storage at position 0.
123 TInt length=iDocument->DocumentLength();
126 iDocument->DeleteL(0,(length));
129 iDocument->InsertL(0,buf);
134 template<class S,CEditableText::TDocumentStorage D>
135 GLDEF_C void CTestScan<S,D>::DoCountWords(TInt aCount)
137 // Calls CountWords, and checks that number of words
138 // counted, matches the known good value 'count'.
141 iUnitCount=iDocument->WordCount();
142 test(aCount==iUnitCount);
146 template<class S,CEditableText::TDocumentStorage D>
147 GLDEF_C void CTestScan<S,D>::DoCountParas(TInt aCount)
149 // Calls CountParagraphs, and checks that number
150 // counted, matches the known good value 'count'.
153 iUnitCount=iDocument->ParagraphCount();
154 test(aCount==iUnitCount);
158 template<class S,CEditableText::TDocumentStorage D>
159 GLDEF_C void CTestScan<S,D>::DoScanWords(TInt aPos,TUint aFlags,TInt aEndPos,TInt aCharCheck)
161 // Calls ScanWords and tests results are as expected.
164 iCharsSkipped=iDocument->ScanWords(aPos,aFlags);
165 test(iCharsSkipped==aCharCheck);
171 template<class S,CEditableText::TDocumentStorage D>
172 GLDEF_C void CTestScan<S,D>::DoScanParas(TInt aPos,TUint aFlags,TInt aEndPos,TInt aCharCheck)
174 // Calls ScanParas and checks results are as expected.
177 iCharsSkipped=iDocument->ScanParas(aPos,aFlags);
178 test(iCharsSkipped==aCharCheck);
184 template<class S,CEditableText::TDocumentStorage D>
185 GLDEF_C void CTestScan<S,D>::Test1L()
187 // Tests all operations of the class.
191 temp1.Append(_L("The world")); // Create a descriptor over some text
192 temp1.Append(iDelimiter);
193 temp1.Append(iDelimiter);
194 temp1.Append(_L("is a"));
196 iDocument->WordCount();
198 TUint flags=(CPlainText::EScanToUnitStart|CPlainText::EScanJoinDelimiters|CPlainText::EScanStayIfBoundary);
199 ((CTestScan*)iDocument)->ScanWords(pos,flags);
200 TBuf<64> temp2(_L("This is a paragraph"));
201 temp2.Append(iDelimiter);
202 iDocument->DeleteL(0,temp1.Length());
205 flags=(CPlainText::EScanToUnitStart|CPlainText::EScanJoinDelimiters);
206 ((CTestScan*)iDocument)->ScanParas(pos,flags);
207 iDocument->ParagraphCount();
210 template<class S,CEditableText::TDocumentStorage D>
211 GLDEF_C void CTestScan<S,D>::Test2aL()
213 // Tests the CountWords method with different cases
218 //INFO_PRINTF1(_L("0 words"));
219 //iDocument->InsertL(0,buf.Ptr(),buf.Size());
221 // This test has been removed since it is no longer feasible.
222 // The design currently inserts an end of document character
223 // as soon as the document is created, hence, there can not
226 INFO_PRINTF1(_L("0 words, all delimiters"));
227 temp.Append(_L(" "));
228 temp.Append(iDelimiter);
229 temp.Append(_L(" "));
233 INFO_PRINTF1(_L("1 word, no delimiter"));
234 temp.Append(_L("This"));
238 INFO_PRINTF1(_L("1 word, at start, no delimiter"));
239 temp.Delete(0,temp.Size());
240 temp.Append(_L("THIS"));
244 INFO_PRINTF1(_L("1 word, with delimiter"));
249 INFO_PRINTF1(_L("Many words, no delimiter"));
250 temp.Append(_L(" is a wonderful world"));
254 INFO_PRINTF1(_L("Many words with delimiter"));
263 template<class S,CEditableText::TDocumentStorage D>
264 GLDEF_C void CTestScan<S,D>::Test2bL()
266 // Tests the ScanWord method with different flag settings
270 buf.Append(_L(" This tEsT TeXT"));
273 iCharsSkipped=iUnitCount=0;
274 INFO_PRINTF1(_L("Forward scan"));
276 INFO_PRINTF1(_L("Stay at boundary:to unit start"));
277 TUint flags=(CPlainText::EScanStayIfBoundary | CPlainText::EScanToUnitStart);
278 DoScanWords(8,flags,12,4);
279 DoScanWords(7,flags,7,0);
280 DoScanWords(6,flags,6,0);
281 DoScanWords(5,flags,6,1);
283 INFO_PRINTF1(_L("Stay at boundary:to unit end"));
284 flags |= CPlainText::EScanToUnitEnd;
285 flags &=~CPlainText::EScanToUnitStart;
286 DoScanWords(8,flags,11,3);
287 DoScanWords(7,flags,11,4);
288 DoScanWords(6,flags,6,0);
289 DoScanWords(5,flags,5,0);
291 INFO_PRINTF1(_L("Stay at boundary:to unit start:join delimiters"));
292 flags=(CPlainText::EScanStayIfBoundary|CPlainText::EScanToUnitStart|CPlainText::EScanJoinDelimiters);
293 DoScanWords(8,flags,13,5);
294 DoScanWords(7,flags,7,0);
295 DoScanWords(6,flags,7,1);
296 DoScanWords(5,flags,7,2);
298 INFO_PRINTF1(_L("Stay at boundary:to unit end:join delimiters"));
299 flags |= CPlainText::EScanToUnitEnd;
300 flags &=~CPlainText::EScanToUnitStart;
301 DoScanWords(8,flags,11,3);
302 DoScanWords(7,flags,11,4);
303 DoScanWords(6,flags,11,5);
304 DoScanWords(5,flags,5,0);
306 INFO_PRINTF1(_L("To unit start"));
307 flags=CPlainText::EScanToUnitStart;
308 DoScanWords(8,flags,12,4);
309 DoScanWords(7,flags,12,5);
310 DoScanWords(6,flags,7,1);
311 DoScanWords(5,flags,6,1);
313 INFO_PRINTF1(_L("To unit end"));
314 flags |= CPlainText::EScanToUnitEnd;
315 flags &=~CPlainText::EScanToUnitStart;
316 DoScanWords(8,flags,11,3);
317 DoScanWords(7,flags,11,4);
318 DoScanWords(6,flags,11,5);
319 DoScanWords(5,flags,6,1);
321 INFO_PRINTF1(_L("To unit start:join delimiters"));
322 flags=(CPlainText::EScanToUnitStart|CPlainText::EScanJoinDelimiters);
323 DoScanWords(8,flags,13,5);
324 DoScanWords(7,flags,13,6);
325 DoScanWords(6,flags,7,1);
326 DoScanWords(5,flags,7,2);
328 INFO_PRINTF1(_L("To unit end:join delimiters"));
329 flags |= CPlainText::EScanToUnitEnd;
330 flags &=~CPlainText::EScanToUnitStart;
331 DoScanWords(8,flags,11,3);
332 DoScanWords(7,flags,11,4);
333 DoScanWords(6,flags,11,5);
334 DoScanWords(5,flags,11,6);
336 INFO_PRINTF1(_L("Backward scan"));
337 INFO_PRINTF1(_L("Stay at boundary:to unit start"));
338 flags=(CPlainText::EScanBackwards|CPlainText::EScanStayIfBoundary|CPlainText::EScanToUnitStart);
339 DoScanWords(9,flags,7,2);
340 DoScanWords(10,flags,7,3);
341 DoScanWords(11,flags,7,4);
342 DoScanWords(12,flags,12,0);
343 DoScanWords(13,flags,13,0);
345 INFO_PRINTF1(_L("Stay at boundary:to unit end"));
346 flags |= CPlainText::EScanToUnitEnd;
347 flags &=~CPlainText::EScanToUnitStart;
348 DoScanWords(9,flags,6,3);
349 DoScanWords(10,flags,6,4);
350 DoScanWords(11,flags,11,0);
351 DoScanWords(12,flags,12,0);
352 DoScanWords(13,flags,12,1);
354 INFO_PRINTF1(_L("Stay at boundary:to unit start:join delimiters"));
355 flags=CPlainText::EScanBackwards|CPlainText::EScanStayIfBoundary|CPlainText::EScanToUnitStart|CPlainText::EScanJoinDelimiters;
356 DoScanWords(9,flags,7,2);
357 DoScanWords(10,flags,7,3);
358 DoScanWords(11,flags,7,4);
359 DoScanWords(12,flags,7,5);
360 DoScanWords(13,flags,13,0);
362 INFO_PRINTF1(_L("Stay at boundary:to unit end:join delimiters"));
363 flags |= CPlainText::EScanToUnitEnd;
364 flags &=~CPlainText::EScanToUnitStart;
365 DoScanWords(9,flags,5,4);
366 DoScanWords(10,flags,5,5);
367 DoScanWords(11,flags,11,0);
368 DoScanWords(12,flags,11,1);
369 DoScanWords(13,flags,11,2);
371 INFO_PRINTF1(_L("To unit start"));
372 flags=CPlainText::EScanBackwards|CPlainText::EScanToUnitStart;
373 DoScanWords(9,flags,7,2);
374 DoScanWords(10,flags,7,3);
375 DoScanWords(11,flags,7,4);
376 DoScanWords(12,flags,7,5);
377 DoScanWords(13,flags,12,1);
379 INFO_PRINTF1(_L("To unit end"));
380 flags |= CPlainText::EScanToUnitEnd;
381 flags &=~CPlainText::EScanToUnitStart;
382 DoScanWords(9,flags,6,3);
383 DoScanWords(10,flags,6,4);
384 DoScanWords(11,flags,6,5);
385 DoScanWords(12,flags,11,1);
386 DoScanWords(13,flags,12,1);
388 INFO_PRINTF1(_L("To unit start:join delimiters"));
389 flags=CPlainText::EScanBackwards|CPlainText::EScanToUnitStart|CPlainText::EScanJoinDelimiters;
390 DoScanWords(9,flags,7,2);
391 DoScanWords(10,flags,7,3);
392 DoScanWords(11,flags,7,4);
393 DoScanWords(12,flags,7,5);
394 DoScanWords(13,flags,7,6);
396 INFO_PRINTF1(_L("To unit end:join delimiters"));
397 flags=CPlainText::EScanToUnitEnd|CPlainText::EScanJoinDelimiters|CPlainText::EScanBackwards;
398 DoScanWords(9,flags,5,4);
399 DoScanWords(10,flags,5,5);
400 DoScanWords(11,flags,5,6);
401 DoScanWords(12,flags,11,1);
402 DoScanWords(13,flags,11,2);
407 template<class S,CEditableText::TDocumentStorage D>
408 GLDEF_C void CTestScan<S,D>::Test2cL()
410 // Tests the CountParagraphs method with different cases
415 //INFO_PRINTF1(_L("0 paras"));
416 //iDocument->InsertL(0,buf.Ptr(),buf.Size());
417 //DoCountParagraphs(0);
418 // This test no longer applies, since documents are created with
419 // an end of document character. ie, The document can not have
422 INFO_PRINTF1(_L("Empty text source"));
423 // buf.Append(iDelimiter);
424 // buf.Append(iDelimiter);
428 INFO_PRINTF1(_L("1 para. no delimiter"));
429 buf.Append(_L("This"));
433 INFO_PRINTF1(_L("1 para. at start, no delimiter"));
434 buf.Delete(0,buf.Size());
435 buf.Append(_L(" THIS "));
439 INFO_PRINTF1(_L("1 para, with delimiter"));
440 buf.Append(iDelimiter);
444 INFO_PRINTF1(_L("2 paras, no delimiter"));
449 INFO_PRINTF1(_L("2 paras with delimiter"));
450 buf.Append(iDelimiter);
458 template<class S,CEditableText::TDocumentStorage D>
459 GLDEF_C void CTestScan<S,D>::Test2dL()
461 // Tests the ScanParagraph method with different flag settings
465 buf.Append(_L(" This"));
466 buf.Append(iDelimiter);
467 buf.Append(iDelimiter);
468 buf.Append(_L("tEsT"));
469 buf.Append(iDelimiter);
470 buf.Append(iDelimiter);
471 buf.Append(_L("TeXT"));
474 iCharsSkipped=iUnitCount=0;
475 INFO_PRINTF1(_L("Forward scan"));
477 INFO_PRINTF1(_L("Stay at boundary:to unit start"));
478 TUint flags=(CPlainText::EScanStayIfBoundary|CPlainText::EScanToUnitStart);
479 DoScanParas(8,flags,12,4);
480 DoScanParas(7,flags,7,0);
481 DoScanParas(6,flags,6,0);
482 DoScanParas(5,flags,6,1);
484 INFO_PRINTF1(_L("Stay at boundary:to unit end"));
485 flags |= CPlainText::EScanToUnitEnd;
486 flags &=~CPlainText::EScanToUnitStart;
487 DoScanParas(8,flags,11,3);
488 DoScanParas(7,flags,11,4);
489 DoScanParas(6,flags,6,0);
490 DoScanParas(5,flags,5,0);
492 INFO_PRINTF1(_L("Stay at boundary:to unit start:join delimiters"));
493 flags=(CPlainText::EScanStayIfBoundary | CPlainText::EScanToUnitStart | CPlainText::EScanJoinDelimiters);
494 DoScanParas(8,flags,13,5);
495 DoScanParas(7,flags,7,0);
496 DoScanParas(6,flags,7,1);
497 DoScanParas(5,flags,7,2);
499 INFO_PRINTF1(_L("Stay at boundary:to unit end:join delimiters"));
500 flags |= CPlainText::EScanToUnitEnd;
501 flags &=~CPlainText::EScanToUnitStart;
502 DoScanParas(8,flags,11,3);
503 DoScanParas(7,flags,11,4);
504 DoScanParas(6,flags,11,5);
505 DoScanParas(5,flags,5,0);
507 INFO_PRINTF1(_L("To unit start"));
508 flags=CPlainText::EScanToUnitStart;
509 DoScanParas(8,flags,12,4);
510 DoScanParas(7,flags,12,5);
511 DoScanParas(6,flags,7,1);
512 DoScanParas(5,flags,6,1);
514 INFO_PRINTF1(_L("To unit end"));
515 flags |= CPlainText::EScanToUnitEnd;
516 flags &=~CPlainText::EScanToUnitStart;
517 DoScanParas(8,flags,11,3);
518 DoScanParas(7,flags,11,4);
519 DoScanParas(6,flags,11,5);
520 DoScanParas(5,flags,6,1);
522 INFO_PRINTF1(_L("To unit start:join delimiters"));
523 flags=(CPlainText::EScanToUnitStart | CPlainText::EScanJoinDelimiters);
524 DoScanParas(8,flags,13,5);
525 DoScanParas(7,flags,13,6);
526 DoScanParas(6,flags,7,1);
527 DoScanParas(5,flags,7,2);
529 INFO_PRINTF1(_L("To unit end:join delimiters"));
530 flags |= CPlainText::EScanToUnitEnd;
531 flags &=~CPlainText::EScanToUnitStart;
532 DoScanParas(8,flags,11,3);
533 DoScanParas(7,flags,11,4);
534 DoScanParas(6,flags,11,5);
535 DoScanParas(5,flags,11,6);
537 INFO_PRINTF1(_L("Backward scan"));
538 INFO_PRINTF1(_L("Stay at boundary:to unit start"));
539 flags=(CPlainText::EScanBackwards|CPlainText::EScanStayIfBoundary|CPlainText::EScanToUnitStart);
540 DoScanParas(9,flags,7,2);
541 DoScanParas(10,flags,7,3);
542 DoScanParas(11,flags,7,4);
543 DoScanParas(12,flags,12,0);
544 DoScanParas(13,flags,13,0);
545 DoScanParas(7,flags,7,0);
546 DoScanParas(1,flags,0,1);
547 DoScanParas(5,flags,0,5);
548 DoScanParas(4,flags,0,4);
549 DoScanParas(3,flags,0,3);
550 DoScanParas(2,flags,0,2);
551 DoScanParas(1,flags,0,1);
552 INFO_PRINTF1(_L("Testing at buffer boundaries."));
553 DoScanParas(0,flags,0,0);
554 DoScanParas(16,flags,13,3);
557 INFO_PRINTF1(_L("Stay at boundary:to unit end"));
558 flags |= CPlainText::EScanToUnitEnd;
559 flags &=~CPlainText::EScanToUnitStart;
560 DoScanParas(9,flags,6,3);
561 DoScanParas(10,flags,6,4);
562 DoScanParas(11,flags,11,0);
563 DoScanParas(12,flags,12,0);
564 DoScanParas(13,flags,12,1);
566 INFO_PRINTF1(_L("Stay at boundary:to unit start:join delimiters"));
567 flags=CPlainText::EScanBackwards|CPlainText::EScanStayIfBoundary|CPlainText::EScanToUnitStart|CPlainText::EScanJoinDelimiters;
568 DoScanParas(9,flags,7,2);
569 DoScanParas(10,flags,7,3);
570 DoScanParas(11,flags,7,4);
571 DoScanParas(12,flags,7,5);
572 DoScanParas(13,flags,13,0);
574 INFO_PRINTF1(_L("Stay at boundary:to unit end:join delimiters"));
575 flags |= CPlainText::EScanToUnitEnd;
576 flags &=~CPlainText::EScanToUnitStart;
577 DoScanParas(9,flags,5,4);
578 DoScanParas(10,flags,5,5);
579 DoScanParas(11,flags,11,0);
580 DoScanParas(12,flags,11,1);
581 DoScanParas(13,flags,11,2);
583 INFO_PRINTF1(_L("To unit start"));
584 flags=CPlainText::EScanBackwards|CPlainText::EScanToUnitStart;
585 DoScanParas(9,flags,7,2);
586 DoScanParas(10,flags,7,3);
587 DoScanParas(11,flags,7,4);
588 DoScanParas(12,flags,7,5);
589 DoScanParas(13,flags,12,1);
591 INFO_PRINTF1(_L("To unit end"));
592 flags |= CPlainText::EScanToUnitEnd;
593 flags &=~CPlainText::EScanToUnitStart;
594 DoScanParas(9,flags,6,3);
595 DoScanParas(10,flags,6,4);
596 DoScanParas(11,flags,6,5);
597 DoScanParas(12,flags,11,1);
598 DoScanParas(13,flags,12,1);
600 INFO_PRINTF1(_L("To unit start:join delimiters"));
601 flags=CPlainText::EScanBackwards|CPlainText::EScanToUnitStart|CPlainText::EScanJoinDelimiters;
602 DoScanParas(9,flags,7,2);
603 DoScanParas(10,flags,7,3);
604 DoScanParas(11,flags,7,4);
605 DoScanParas(12,flags,7,5);
606 DoScanParas(13,flags,7,6);
608 INFO_PRINTF1(_L("To unit end:join delimiters"));
609 flags |= CPlainText::EScanToUnitEnd;
610 flags &=~CPlainText::EScanToUnitStart;
611 DoScanParas(9,flags,5,4);
612 DoScanParas(10,flags,5,5);
613 DoScanParas(11,flags,5,6);
614 DoScanParas(12,flags,11,1);
615 DoScanParas(13,flags,11,2);
621 template<class S,CEditableText::TDocumentStorage D>
622 GLDEF_C void CTestScan<S,D>::Test2L()
624 // Test all the methods of the class
627 INFO_PRINTF1(_L("CountWords"));
630 INFO_PRINTF1(_L("ScanWord"));
633 INFO_PRINTF1(_L("Count Paragraphs"));
636 INFO_PRINTF1(_L("Scan Paragraph"));
642 CT_SCANDC::CT_SCANDC()
644 SetTestStepName(KTestStep_T_SCANDC);
648 TVerdict CT_SCANDC::doTestStepL()
650 SetTestStepResult(EFail);
652 TheTrapCleanup=CTrapCleanup::New();
654 INFO_PRINTF1(_L("SCANNING OF TEXT DOCUMENTS"));
655 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_SCANDC-0001 CPlainText - Flat "));
656 typedef CTestScan<TText,CEditableText::EFlatStorage> instance1;
657 typedef CTestScan<TText,CEditableText::ESegmentedStorage> instance2;
660 TRAPD(ret1, aa=instance1::NewL());
662 INFO_PRINTF1(_L("Registering all methods"));
664 TRAPD(ret2,aa->Test1L());
666 INFO_PRINTF1(_L("Testing all methods"));
668 TRAPD(ret3,aa->Test2L());
674 INFO_PRINTF1(_L("CPlainText - Segmented"));
677 TRAPD(ret4, bb=instance2::NewL());
680 INFO_PRINTF1(_L("Registering all methods"));
681 TRAPD(ret5,bb->Test1L());
682 INFO_PRINTF1(_L("Testing all methods"));
683 TRAPD(ret6,bb->Test2L());
687 delete TheTrapCleanup;
689 if (ret1 == KErrNone && ret2 == KErrNone && ret3 == KErrNone && ret4 == KErrNone && ret5 == KErrNone && ret6 == KErrNone)
691 SetTestStepResult(EPass);
694 return TestStepResult();