1 /* |
1 /* |
2 * Copyright (c) 1999-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
15 * TPARSE.CPP |
15 * TPARSE.CPP |
16 * |
16 * |
17 */ |
17 */ |
18 |
18 |
19 |
19 |
|
20 #include <e32test.h> |
20 #include <txtrich.h> |
21 #include <txtrich.h> |
21 #include <e32math.h> |
22 #include <e32math.h> |
22 #include "T_parse.h" |
23 #include "T_parse.h" |
23 #include "T_PARSE_for_TEF.h" |
|
24 |
|
25 LOCAL_D CTestStep *pTestStep = NULL; |
|
26 #define test(cond) \ |
|
27 { \ |
|
28 TBool __bb = (cond); \ |
|
29 pTestStep->TEST(__bb); \ |
|
30 if (!__bb) \ |
|
31 { \ |
|
32 pTestStep->ERR_PRINTF1(_L("ERROR: Test Failed")); \ |
|
33 User::Leave(1); \ |
|
34 } \ |
|
35 } |
|
36 #undef INFO_PRINTF1 |
|
37 #undef INFO_PRINTF2 |
|
38 #undef INFO_PRINTF3 |
|
39 // copy from tefexportconst.h |
|
40 #define INFO_PRINTF1(p1) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1)) |
|
41 #define INFO_PRINTF2(p1, p2) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2)) |
|
42 #define INFO_PRINTF3(p1, p2, p3) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3)) |
|
43 |
|
44 |
24 |
45 LOCAL_D CTrapCleanup* TrapCleanup; |
25 LOCAL_D CTrapCleanup* TrapCleanup; |
|
26 LOCAL_D RTest test(_L("Testing EText parser system")); |
46 LOCAL_D const TInt KTestCleanupStack=0x200; |
27 LOCAL_D const TInt KTestCleanupStack=0x200; |
47 |
28 |
48 |
29 |
49 CTestParser* CTestParser::NewL() |
30 CTestParser* CTestParser::NewL() |
50 { |
31 { |
333 } |
314 } |
334 |
315 |
335 |
316 |
336 void Test1() |
317 void Test1() |
337 { |
318 { |
338 INFO_PRINTF1(_L("Install 5, deinstall in reverse order")); |
319 test.Next(_L("Install 5, deinstall in reverse order")); |
339 CTestParser* parser1 = CTestParser::NewL(); |
320 CTestParser* parser1 = CTestParser::NewL(); |
340 CTestParser* parser2 = CTestParser::NewL(); |
321 CTestParser* parser2 = CTestParser::NewL(); |
341 CTestParser* parser3 = CTestParser::NewL(); |
322 CTestParser* parser3 = CTestParser::NewL(); |
342 CTestParser* parser4 = CTestParser::NewL(); |
323 CTestParser* parser4 = CTestParser::NewL(); |
343 CTestParser* parser5 = CTestParser::NewL(); |
324 CTestParser* parser5 = CTestParser::NewL(); |
360 } |
341 } |
361 |
342 |
362 |
343 |
363 void Test2() |
344 void Test2() |
364 { |
345 { |
365 INFO_PRINTF1(_L("Install, deinstall in interleaved order")); |
346 test.Next(_L("Install, deinstall in interleaved order")); |
366 CTestParser* parser1 = CTestParser::NewL(); |
347 CTestParser* parser1 = CTestParser::NewL(); |
367 CRichText::ActivateParserL(parser1); // List 1 |
348 CRichText::ActivateParserL(parser1); // List 1 |
368 CTestParser* parser2 = CTestParser::NewL(); |
349 CTestParser* parser2 = CTestParser::NewL(); |
369 CRichText::ActivateParserL(parser2); // List 1, 2 |
350 CRichText::ActivateParserL(parser2); // List 1, 2 |
370 // Remove first in list |
351 // Remove first in list |
527 // Randomly insert a target string and check: |
508 // Randomly insert a target string and check: |
528 // - Can't find target that is not complete |
509 // - Can't find target that is not complete |
529 // - Does find complete target in right place |
510 // - Does find complete target in right place |
530 // - Once target is removed, can't find it |
511 // - Once target is removed, can't find it |
531 // repeat x 100 |
512 // repeat x 100 |
532 INFO_PRINTF1(_L("Testing EText behaviour with active parsers and single target")); |
513 test.Next(_L("Testing EText behaviour with active parsers and single target")); |
533 // Create and activate a parser |
514 // Create and activate a parser |
534 CTestParser* parser1 = CTestParser::NewL(); |
515 CTestParser* parser1 = CTestParser::NewL(); |
535 CRichText::ActivateParserL(parser1); |
516 CRichText::ActivateParserL(parser1); |
536 // Create a CRichText |
517 // Create a CRichText |
537 CParaFormatLayer* GlobalParaFormatLayer = CParaFormatLayer::NewL(); |
518 CParaFormatLayer* GlobalParaFormatLayer = CParaFormatLayer::NewL(); |
549 TInt64 seed = 314159; |
530 TInt64 seed = 314159; |
550 TInt startTags; |
531 TInt startTags; |
551 TInt lengthTags; |
532 TInt lengthTags; |
552 for (i = 0; i < 100; i++) |
533 for (i = 0; i < 100; i++) |
553 { |
534 { |
554 #if 0 |
|
555 INFO_PRINTF2(_L("i=%d"), i); |
|
556 #endif |
|
557 // Get a random in range 0-999 |
535 // Get a random in range 0-999 |
558 TInt random = Math::Rand(seed) % 1000; |
536 TInt random = Math::Rand(seed) % 1000; |
559 // "Randomly" insert target string that is not complete |
537 // "Randomly" insert target string that is not complete |
560 richText->InsertL(random, _L("TARGE")); |
538 richText->InsertL(random, _L("TARGE")); |
561 test(!richText->ParseText(startTags, lengthTags, EFalse)); |
539 test(!richText->ParseText(startTags, lengthTags, EFalse)); |
562 test(!richText->ParseText(startTags, lengthTags, ETrue)); |
540 test(!richText->ParseText(startTags, lengthTags, ETrue)); |
563 // Complete target string and check we find single target where we expect |
541 // Complete target string and check we find single target where we expect |
564 richText->InsertL(random + 5, 'T'); |
542 richText->InsertL(random + 5, 'T'); |
565 #if 1 |
|
566 test(richText->ParseText(startTags, lengthTags, EFalse)); |
543 test(richText->ParseText(startTags, lengthTags, EFalse)); |
567 #else |
|
568 TBool b = richText->ParseText(startTags, lengthTags, EFalse); |
|
569 INFO_PRINTF2(_L(" b=%d"), b); |
|
570 test(b); |
|
571 #endif |
|
572 test((startTags == random) && (lengthTags == 6)); |
544 test((startTags == random) && (lengthTags == 6)); |
573 test(richText->ParseText(startTags, lengthTags, ETrue)); |
545 test(richText->ParseText(startTags, lengthTags, ETrue)); |
574 test((startTags == random) && (lengthTags == 6)); |
546 test((startTags == random) && (lengthTags == 6)); |
575 // Completely remove target string |
547 // Completely remove target string |
576 richText->DeleteL(random, 6); |
548 richText->DeleteL(random, 6); |
596 // Randomly insert two target strings and check: |
568 // Randomly insert two target strings and check: |
597 // - Can't find targets that are not complete |
569 // - Can't find targets that are not complete |
598 // - Does find complete targets with exact range covered |
570 // - Does find complete targets with exact range covered |
599 // - Once targets are removed, can't find it |
571 // - Once targets are removed, can't find it |
600 // repeat x 100 |
572 // repeat x 100 |
601 INFO_PRINTF1(_L("Testing EText behaviour with active parsers and double target")); |
573 test.Next(_L("Testing EText behaviour with active parsers and double target")); |
602 // Create and activate a parser |
574 // Create and activate a parser |
603 CTestParser* parser1 = CTestParser::NewL(); |
575 CTestParser* parser1 = CTestParser::NewL(); |
604 CRichText::ActivateParserL(parser1); |
576 CRichText::ActivateParserL(parser1); |
605 // Create a CRichText |
577 // Create a CRichText |
606 CParaFormatLayer* GlobalParaFormatLayer = CParaFormatLayer::NewL(); |
578 CParaFormatLayer* GlobalParaFormatLayer = CParaFormatLayer::NewL(); |
618 TInt64 seed1 = 314159; |
590 TInt64 seed1 = 314159; |
619 TInt startTags; |
591 TInt startTags; |
620 TInt lengthTags; |
592 TInt lengthTags; |
621 for (i = 0; i < 100; i++) |
593 for (i = 0; i < 100; i++) |
622 { |
594 { |
623 #if 0 |
|
624 INFO_PRINTF2(_L("i=%d"), i); |
|
625 #endif |
|
626 // Get a random in range 0-999 |
595 // Get a random in range 0-999 |
627 TInt random1 = Math::Rand(seed1) % 1000; |
596 TInt random1 = Math::Rand(seed1) % 1000; |
628 TInt random2 = Math::Rand(seed1) % 1000; |
597 TInt random2 = Math::Rand(seed1) % 1000; |
629 TInt rlow = (random1 < random2) ? random1 : random2; |
598 TInt rlow = (random1 < random2) ? random1 : random2; |
630 TInt rhigh = (random1 > random2) ? random1 : random2; |
599 TInt rhigh = (random1 > random2) ? random1 : random2; |
641 test(!richText->ParseText(startTags, lengthTags, EFalse)); |
610 test(!richText->ParseText(startTags, lengthTags, EFalse)); |
642 test(!richText->ParseText(startTags, lengthTags, ETrue)); |
611 test(!richText->ParseText(startTags, lengthTags, ETrue)); |
643 // Complete target string and check we find single target where we expect |
612 // Complete target string and check we find single target where we expect |
644 richText->InsertL(rlow + 5, 'T'); |
613 richText->InsertL(rlow + 5, 'T'); |
645 richText->InsertL(rhigh + 5, 'T'); |
614 richText->InsertL(rhigh + 5, 'T'); |
646 #if 1 |
|
647 test(richText->ParseText(startTags, lengthTags, EFalse)); |
615 test(richText->ParseText(startTags, lengthTags, EFalse)); |
648 #else |
|
649 TBool bb = richText->ParseText(startTags, lengthTags, EFalse); |
|
650 test(bb); |
|
651 #endif |
|
652 test((startTags == rlow) && (lengthTags == rhigh + 6 - rlow)); |
616 test((startTags == rlow) && (lengthTags == rhigh + 6 - rlow)); |
653 test(richText->ParseText(startTags, lengthTags, ETrue)); |
617 test(richText->ParseText(startTags, lengthTags, ETrue)); |
654 test((startTags == rlow) && (lengthTags == rhigh + 6 - rlow)); |
618 test((startTags == rlow) && (lengthTags == rhigh + 6 - rlow)); |
655 // Completely remove target string |
619 // Completely remove target string |
656 richText->DeleteL(rhigh, 6); |
620 richText->DeleteL(rhigh, 6); |
679 @SYMDEF PDEF102494 |
643 @SYMDEF PDEF102494 |
680 */ |
644 */ |
681 |
645 |
682 void Test6() |
646 void Test6() |
683 { |
647 { |
684 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-ETEXT-UT-3405 Calling PositionOfNextTag on an empty document ")); |
648 test.Next(_L(" @SYMTestCaseID:SYSLIB-ETEXT-UT-3405 Calling PositionOfNextTag on an empty document ")); |
685 |
649 |
686 // Create and activate a parser |
650 // Create and activate a parser |
687 CTestParser* parser1 = CTestParser::NewL(); |
651 CTestParser* parser1 = CTestParser::NewL(); |
688 CRichText::ActivateParserL(parser1); |
652 CRichText::ActivateParserL(parser1); |
689 // Create a CRichText |
653 // Create a CRichText |
735 @SYMTestExpectedResults Test must be able to call PositionOfNextTag on the end of document positions |
699 @SYMTestExpectedResults Test must be able to call PositionOfNextTag on the end of document positions |
736 @SYMDEF PDEF102494 |
700 @SYMDEF PDEF102494 |
737 */ |
701 */ |
738 void Test7() |
702 void Test7() |
739 { |
703 { |
740 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-ETEXT-UT-3406 Testing EText behaviour with active parsers and single target ")); |
704 test.Next(_L(" @SYMTestCaseID:SYSLIB-ETEXT-UT-3406 Testing EText behaviour with active parsers and single target ")); |
741 |
705 |
742 // Create and activate a parser |
706 // Create and activate a parser |
743 CTestParser* parser1 = CTestParser::NewL(); |
707 CTestParser* parser1 = CTestParser::NewL(); |
744 CRichText::ActivateParserL(parser1); |
708 CRichText::ActivateParserL(parser1); |
745 CTestParser2* parser2 = CTestParser2::NewL(); |
709 CTestParser2* parser2 = CTestParser2::NewL(); |
809 delete parser2; |
773 delete parser2; |
810 CRichText::DeactivateParserDefaults(); |
774 CRichText::DeactivateParserDefaults(); |
811 delete editObserver; |
775 delete editObserver; |
812 } |
776 } |
813 |
777 |
814 CT_PARSE::CT_PARSE() |
778 |
815 { |
779 TInt E32Main() |
816 SetTestStepName(KTestStep_T_PARSE); |
780 { |
817 pTestStep = this; |
781 TrapCleanup = CTrapCleanup::New(); |
818 } |
782 TRAPD(r,\ |
819 |
783 {\ |
820 TVerdict CT_PARSE::doTestStepL() |
784 for (TInt i=KTestCleanupStack;i>0;i--)\ |
821 { |
785 CleanupStack::PushL((TAny*)1);\ |
822 SetTestStepResult(EFail); |
786 test(r==KErrNone);\ |
823 |
787 CleanupStack::Pop(KTestCleanupStack);\ |
824 TrapCleanup = CTrapCleanup::New(); |
788 }); |
825 TRAPD(r,\ |
789 test(r == KErrNone); |
826 {\ |
790 test.Title(); |
827 for (TInt i=KTestCleanupStack;i>0;i--)\ |
791 |
828 CleanupStack::PushL((TAny*)1);\ |
792 test.Start(_L("Testing memory under normal conditions")); |
829 test(r==KErrNone);\ |
793 TInt ret; |
830 CleanupStack::Pop(KTestCleanupStack);\ |
794 |
831 }); |
795 __UHEAP_MARK; |
832 |
796 TRAP(ret, Test1()); |
833 INFO_PRINTF1(_L("Testing EText parser system")); |
797 test(ret == KErrNone); |
834 |
798 __UHEAP_MARKEND; |
835 INFO_PRINTF1(_L("Testing memory under normal conditions")); |
799 |
836 |
800 __UHEAP_MARK; |
837 __UHEAP_MARK; |
801 TRAP(ret, Test2()); |
838 TRAPD(ret1, Test1()); |
802 test(ret == KErrNone); |
839 __UHEAP_MARKEND; |
803 __UHEAP_MARKEND; |
840 |
804 |
841 __UHEAP_MARK; |
805 __UHEAP_MARK; |
842 TRAPD(ret2, Test2()); |
806 TRAP(ret, Test3()); |
843 __UHEAP_MARKEND; |
807 test(ret == KErrNone); |
844 |
808 __UHEAP_MARKEND; |
845 __UHEAP_MARK; |
809 |
846 TRAPD(ret3, Test3()); |
810 __UHEAP_MARK; |
847 __UHEAP_MARKEND; |
811 TRAP(ret, Test4()); |
848 |
812 test(ret == KErrNone); |
849 __UHEAP_MARK; |
813 __UHEAP_MARKEND; |
850 TRAPD(ret4, Test4()); |
814 |
851 __UHEAP_MARKEND; |
815 __UHEAP_MARK; |
852 |
816 TRAP(ret, Test5()); |
853 __UHEAP_MARK; |
817 test(ret == KErrNone); |
854 TRAPD(ret5, Test5()); |
818 __UHEAP_MARKEND; |
855 __UHEAP_MARKEND; |
819 |
856 |
820 __UHEAP_MARK; |
857 __UHEAP_MARK; |
821 TRAP(ret, Test6()); |
858 TRAPD(ret6, Test6()); |
822 test(ret == KErrNone); |
859 __UHEAP_MARKEND; |
823 __UHEAP_MARKEND; |
860 |
824 |
861 __UHEAP_MARK; |
825 __UHEAP_MARK; |
862 TRAPD(ret7, Test7()); |
826 TRAP(ret, Test7()); |
863 __UHEAP_MARKEND; |
827 test(ret == KErrNone); |
864 |
828 __UHEAP_MARKEND; |
865 delete TrapCleanup; |
829 |
866 |
830 delete TrapCleanup; |
867 if (r == KErrNone && ret1 == KErrNone && ret2 == KErrNone && ret3 == KErrNone && ret4 == KErrNone && ret5 == KErrNone && ret6 == KErrNone && ret7 == KErrNone) |
831 |
868 { |
832 test.End(); |
869 SetTestStepResult(EPass); |
833 test.Close(); |
870 } |
834 return 0; |
871 |
835 } |
872 return TestStepResult(); |
|
873 } |
|