lowlevellibsandfws/apputils/tsrc/T_MATCH.CPP
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 1997-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 // Started by Brendan, January 1996
       
    15 // test code for RIncrMatcher
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <bamatch.h>
       
    20 #include <badesca.h>
       
    21 #include <e32test.h>
       
    22 
       
    23 RTest test(_L("Testing RIncrMatcher"));
       
    24 
       
    25 /**
       
    26 @SYMTestCaseID          SYSLIB-BAFL-CT-0421
       
    27 @SYMTestCaseDesc        RIncrMatcherBase class test
       
    28                         Tests for RIncrMatcherBase::MatchText() function
       
    29 @SYMTestPriority        Medium
       
    30 @SYMTestActions         Compare two text buffers
       
    31 @SYMTestExpectedResults Test must not fail
       
    32 @SYMREQ                 REQ0000
       
    33 */
       
    34 void MatcherManip(RIncrMatcherBase &aMatcher)
       
    35 	{
       
    36 	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0421 Manipulation "));
       
    37 	aMatcher.SetMatchText(_L("Hello"));
       
    38 	test(aMatcher.MatchText()==_L("Hello"));
       
    39 	test(aMatcher.MatchText()!=_L("Hell"));
       
    40 	aMatcher.AppendChar('w');
       
    41 	test(aMatcher.MatchText()==_L("Hellow"));
       
    42 	aMatcher.DeleteLastChar();
       
    43 	test(aMatcher.MatchText()==_L("Hello"));
       
    44 	aMatcher.DeleteLastChar();
       
    45 	test(aMatcher.MatchText()==_L("Hell"));
       
    46 	aMatcher.Clear();
       
    47 	test(aMatcher.MatchText()==_L(""));
       
    48 	}
       
    49 
       
    50 /**
       
    51 @SYMTestCaseID          SYSLIB-BAFL-CT-0422
       
    52 @SYMTestCaseDesc        Tests for RIncrMatcherBase::SetMatchText(),RIncrMatcherBase::SetBestMatch()
       
    53                         RIncrMatcherBase::SetBestMatchF() functions
       
    54 @SYMTestPriority        Medium
       
    55 @SYMTestActions         Attempt to set the best match
       
    56 @SYMTestExpectedResults Tests must not fail
       
    57 @SYMREQ                 REQ0000
       
    58 */
       
    59 void MatcherBest(RIncrMatcherBase &aMatcher)
       
    60 	{
       
    61 	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0422 SetBest "));
       
    62 	aMatcher.SetMatchText(_L("Hello"));
       
    63 	test(aMatcher.MatchText()==_L("Hello"));
       
    64 	aMatcher.SetBestMatch(_L("Hell"));
       
    65 	test(aMatcher.MatchText()==_L("Hell"));
       
    66 	aMatcher.SetBestMatch(_L("HelL"));
       
    67 	test(aMatcher.MatchText()==_L("Hel"));
       
    68 	aMatcher.SetBestMatchF(_L("HEL"));
       
    69 	test(aMatcher.MatchText()==_L("Hel"));
       
    70 	}
       
    71 
       
    72 /**
       
    73 @SYMTestCaseID          SYSLIB-BAFL-CT-0423
       
    74 @SYMTestCaseDesc        Tests for RIncrMatcherBase::FirstMatchingIndex()
       
    75                         RIncrMatcherBase::FirstMatchingIndexF(),RIncrMatcherBase::FirstMatchingIndexC() functions
       
    76 @SYMTestPriority        Medium
       
    77 @SYMTestActions         Attempt to find correct array entry
       
    78 @SYMTestExpectedResults Tests must not fail
       
    79 @SYMREQ                 REQ0000
       
    80 */
       
    81 void MatcherArray(RIncrMatcherBase &aMatcher)
       
    82 	{
       
    83 	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0423 "));
       
    84 	TPtrC KArrayZero(_S("Hel"));
       
    85 	TPtrC KArrayOne(_S("heLLo"));
       
    86 	TPtrC KArrayTwo(_S("Hello"));
       
    87 	TPtrC KArrayThree(_S("Bye"));
       
    88 //
       
    89 	CDesCArray* array=new CDesCArrayFlat(5);
       
    90 	array->Reset();
       
    91 	TRAPD(trapVal,array->AppendL(KArrayZero));
       
    92 	test(trapVal==KErrNone);
       
    93 	TRAP(trapVal,array->AppendL(KArrayOne));
       
    94 	test(trapVal==KErrNone);
       
    95 	TRAP(trapVal,array->AppendL(KArrayTwo));
       
    96 	test(trapVal==KErrNone);
       
    97 	TRAP(trapVal,array->AppendL(KArrayThree));
       
    98 	test(trapVal==KErrNone);
       
    99 //
       
   100 	aMatcher.SetMatchText(_L("Bye"));
       
   101 	TInt result;
       
   102 	test(aMatcher.FirstMatchingIndex(result,*array)==KErrNone);
       
   103 	test(result==3);
       
   104 //
       
   105 	aMatcher.SetMatchText(_L("Hello"));
       
   106 	test(aMatcher.FirstMatchingIndex(result,*array)==KErrNone);
       
   107 	test(result==2);
       
   108 	test(aMatcher.FirstMatchingIndexF(result,*array)==KErrNone);
       
   109 	test(result==1);
       
   110 //
       
   111 	aMatcher.SetMatchText(_L("heLL"));
       
   112 	test(aMatcher.FirstMatchingIndexC(result,*array)==KErrNone);
       
   113 	test(result==1);
       
   114 //
       
   115 	delete(array);
       
   116 	}
       
   117 
       
   118 /**
       
   119 @SYMTestCaseID          SYSLIB-BAFL-CT-0424
       
   120 @SYMTestCaseDesc        Tests for RIncrMatcherBase::IsMatchF() function
       
   121 @SYMTestPriority        Medium
       
   122 @SYMTestActions         Tests for maximum length match
       
   123 @SYMTestExpectedResults Tests must not fail
       
   124 @SYMREQ                 REQ0000
       
   125 */
       
   126 void MatcherMax(RIncrMatcherBase& aMatcher,TInt aMax)
       
   127 	{
       
   128 	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0424 Max length "));
       
   129 	HBufC* buf=HBufC::NewL(aMax);
       
   130 	buf->Des().SetLength(aMax);
       
   131 	buf->Des().Fill('a');
       
   132 	aMatcher.SetMatchText(buf->Left(aMax-1));
       
   133 	test(aMatcher.IsMatchF(*buf));
       
   134 	aMatcher.AppendChar('a');
       
   135 	test(aMatcher.IsMatchF(*buf));
       
   136 	aMatcher.DeleteLastChar();
       
   137 	test(aMatcher.IsMatchF(*buf));
       
   138 	aMatcher.AppendChar('w');
       
   139 	test(!aMatcher.IsMatchF(*buf));
       
   140 	aMatcher.DeleteLastChar();
       
   141 	test(aMatcher.IsMatchF(*buf));
       
   142 	delete(buf);
       
   143 	}
       
   144 
       
   145 TInt E32Main()
       
   146     {
       
   147 	test.Title();
       
   148 	test.Start(_L("Incremental Matcher "));
       
   149 //
       
   150 	const TInt KMaxMatchLength=10;
       
   151 	RIncrMatcherBuf<KMaxMatchLength> matcherBuf;
       
   152 	TBuf<KMaxMatchLength> buf;
       
   153 	RIncrMatcherPtr matcherPtr;
       
   154 	matcherPtr.SetMatcherPtr(buf);
       
   155 	RIncrMatcherTextBuf matcherText;
       
   156 	matcherText.SetMatcherLengthL(KMaxMatchLength);
       
   157 	CTrapCleanup *trapCleanup=CTrapCleanup::New();
       
   158 //
       
   159 	__UHEAP_MARK;
       
   160 	MatcherManip(matcherBuf);
       
   161 	MatcherManip(matcherPtr);
       
   162 	MatcherManip(matcherText);
       
   163 	MatcherBest(matcherBuf);
       
   164 	MatcherBest(matcherPtr);
       
   165 	MatcherBest(matcherText);
       
   166 	MatcherArray(matcherBuf);
       
   167 	MatcherArray(matcherPtr);
       
   168 	MatcherArray(matcherText);
       
   169 	MatcherMax(matcherBuf,KMaxMatchLength);
       
   170 	MatcherMax(matcherPtr,KMaxMatchLength);
       
   171 	MatcherMax(matcherText,KMaxMatchLength);
       
   172 	__UHEAP_MARKEND;
       
   173 //
       
   174 	delete(trapCleanup);
       
   175 	test.End();
       
   176     return(KErrNone);
       
   177     }