lowlevellibsandfws/apputils/tsrc/T_DESCA.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 DWW, April 1996
       
    15 // Tests descriptor arrays
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <e32test.h>
       
    20 #include <badesca.h>
       
    21 
       
    22 LOCAL_D RTest test(_L("T_DESCA"));
       
    23 
       
    24 class TestDesca
       
    25 	{
       
    26 public:
       
    27 	void MainTestL(CDesCArray* aDescA);
       
    28 	void ComparisonTest(CDesCArray* aDescA1,CDesCArray* aDescA2);
       
    29 	void FoldTestL(CDesCArray* aDescA);
       
    30 	void MixableTestL();
       
    31 	void DoMixableTest(MDesCArray* aDescA);
       
    32 	void InSequenceTestL(CDesCArray* aDescA);
       
    33     };
       
    34 
       
    35 /**
       
    36 @SYMTestCaseID          SYSLIB-BAFL-CT-0408
       
    37 @SYMTestCaseDesc        Tests for folded and non-folded find
       
    38 @SYMTestPriority        Medium
       
    39 @SYMTestActions         Tests by appending few descriptors and find the position for the target.
       
    40 @SYMTestExpectedResults Tests must not fail
       
    41 @SYMREQ                 REQ0000
       
    42 */
       
    43 void TestDesca::FoldTestL(CDesCArray* aDescA)
       
    44 	{
       
    45 	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0408 Test folded and non-folded find "));
       
    46 	TPtrC target=_L("abcdefg");
       
    47 	aDescA->AppendL(target);
       
    48 	aDescA->AppendL(_L("aBcDeFg"));
       
    49 	aDescA->InsertL(0,_L("ABCDEFG"));
       
    50 	test(aDescA->Count()==3);
       
    51 	TInt pos=(-1);
       
    52     aDescA->Find(target,pos);
       
    53     test(pos==0);
       
    54     aDescA->Find(target,pos,ECmpNormal);
       
    55     test(pos==1);
       
    56 	test.Next(_L("Test reset"));
       
    57 	aDescA->Reset();
       
    58 	test(!aDescA->Count());
       
    59 	}
       
    60 
       
    61 /**
       
    62 @SYMTestCaseID          SYSLIB-BAFL-CT-0409
       
    63 @SYMTestCaseDesc        CDesCArray class functionality test
       
    64 @SYMTestPriority        Medium
       
    65 @SYMTestActions         Add month names to the descriptor array and tests with the find.
       
    66 @SYMTestExpectedResults Tests must not fail
       
    67 @SYMREQ                 REQ0000
       
    68 */
       
    69 void TestDesca::MainTestL(CDesCArray* aDescA)
       
    70 	{
       
    71     TMonthName name;
       
    72     test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0409 Add 12 month names "));
       
    73     for (TInt ii=0; ii<12; ii++)
       
    74         {
       
    75         name.Set((TMonth)ii);
       
    76         aDescA->AppendL(name);
       
    77         }
       
    78     test.Next(_L("Check 12 names exist"));
       
    79     test(aDescA->Count()==12);
       
    80     test.Next(_L("Print the 12 names"));
       
    81     for (TInt jj=0; jj<12; jj++)
       
    82         test.Printf((*aDescA)[jj]);
       
    83     test.Printf(_L("\r\n"));
       
    84     test.Next(_L("Find"));
       
    85     for (TInt kk=3; kk<12; kk+=3)
       
    86         {
       
    87         name.Set((TMonth)kk);
       
    88         TInt pos=0;
       
    89         aDescA->Find(name,pos);
       
    90         test(pos==kk);
       
    91         }
       
    92     test.Next(_L("Delete"));
       
    93     aDescA->Delete(2);
       
    94     aDescA->Delete(4);
       
    95     aDescA->Delete(6);
       
    96     test(aDescA->Count()==9);
       
    97     test((*aDescA)[6]==name);
       
    98     test.Next(_L("Sort"));
       
    99     aDescA->Sort();
       
   100     test(aDescA->Count()==9);
       
   101     for (TInt ll=0; ll<9; ll++)
       
   102         test.Printf((*aDescA)[ll]);
       
   103     test.Printf(_L("\r\n"));
       
   104 	test.End();
       
   105     }
       
   106 
       
   107 /**
       
   108 @SYMTestCaseID          SYSLIB-BAFL-CT-0410
       
   109 @SYMTestCaseDesc        Comparision of two CDesCArray objects test
       
   110 @SYMTestPriority        Medium
       
   111 @SYMTestActions         Check if two descriptor arrays are equal.
       
   112 @SYMTestExpectedResults Tests must not fail
       
   113 @SYMREQ                 REQ0000
       
   114 */
       
   115 void TestDesca::ComparisonTest(CDesCArray* aDescA1,CDesCArray* aDescA2)
       
   116 	{
       
   117 	test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0410 Test comparisons "));
       
   118     TInt count=aDescA1->Count();
       
   119     test(aDescA2->Count()==count);
       
   120     for (TInt ii=0; ii<count; ii++)
       
   121         test((*aDescA1)[ii]==(*aDescA2)[ii]);
       
   122     test.End();
       
   123     }
       
   124 
       
   125 /**
       
   126 @SYMTestCaseID          SYSLIB-BAFL-CT-0411
       
   127 @SYMTestCaseDesc        MDesCArray class functionality test
       
   128 @SYMTestPriority        Medium
       
   129 @SYMTestActions         Checks for the existence of 12 names
       
   130 @SYMTestExpectedResults Tests must not fail
       
   131 @SYMREQ                 REQ0000
       
   132 */
       
   133 void TestDesca::DoMixableTest(MDesCArray* aDescA)
       
   134 	{
       
   135     test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0411 Check 12 names exist "));
       
   136     test(aDescA->MdcaCount()==12);
       
   137     test.Next(_L("Print the 12 names"));
       
   138     for (TInt jj=0; jj<12; jj++)
       
   139         test.Printf(aDescA->MdcaPoint(jj));
       
   140     test.Printf(_L("\r\n"));
       
   141 	delete(aDescA);
       
   142     }
       
   143 
       
   144 /**
       
   145 @SYMTestCaseID          SYSLIB-BAFL-CT-0412
       
   146 @SYMTestCaseDesc        Tests for CDesCArray sequences
       
   147 @SYMTestPriority        Medium
       
   148 @SYMTestActions         Checks for the sequence of the literals.
       
   149 @SYMTestExpectedResults Tests must not fail
       
   150 @SYMREQ                 REQ0000
       
   151 */
       
   152 void TestDesca::InSequenceTestL(CDesCArray* aDescA)
       
   153 	{
       
   154     test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0412 In Sequence Tests "));
       
   155 	aDescA->Reset();
       
   156 	TPtrC hello(_S("Hello"));
       
   157 	TPtrC bye(_S("Bye"));
       
   158 	TPtrC world(_S("World"));
       
   159 	TPtrC middle(_S("middle"));
       
   160 	TPtrC extra(_S("extra"));
       
   161 	TBuf<32> buffer;
       
   162 	TInt pos;
       
   163 	aDescA->AppendL(hello);
       
   164 	aDescA->AppendL(bye);
       
   165 	aDescA->AppendL(world);
       
   166 	aDescA->AppendL(middle);
       
   167     test(aDescA->MdcaPoint(0)==hello);
       
   168     test(aDescA->MdcaPoint(2)==world);
       
   169 	//
       
   170 	aDescA->Sort(ECmpFolded);
       
   171 	buffer=aDescA->MdcaPoint(2);
       
   172     test(buffer==middle);
       
   173 	test(aDescA->Find(middle,pos,ECmpFolded)==KErrNone);
       
   174 	test(pos==2);
       
   175 	test(aDescA->FindIsq(middle,pos,ECmpFolded)==KErrNone);
       
   176 	test(pos==2);
       
   177 	test(aDescA->FindIsq(middle,pos,ECmpNormal)==KErrNone); // !! should this fail for non-sorted array??
       
   178 //	test(pos==??);
       
   179 	pos=aDescA->InsertIsqL(extra,ECmpFolded);
       
   180 	test(pos==1);
       
   181 	TRAP(pos,aDescA->InsertIsqL(extra,ECmpFolded));
       
   182 	test(pos==KErrAlreadyExists);
       
   183 	pos=aDescA->InsertIsqAllowDuplicatesL(extra,ECmpFolded);
       
   184 	test(pos==2);
       
   185 	aDescA->Delete(pos--);
       
   186 	aDescA->Delete(pos);
       
   187 	test(aDescA->MdcaCount()==4);
       
   188 	//
       
   189 	//	Different sort order because of case
       
   190 	aDescA->Sort(ECmpNormal);
       
   191 	buffer=aDescA->MdcaPoint(2);
       
   192     test(buffer==world);
       
   193 	test(aDescA->Find(world,pos,ECmpNormal)==KErrNone);
       
   194 	test(pos==2);
       
   195 	test(aDescA->FindIsq(world,pos,ECmpNormal)==KErrNone);
       
   196 	test(pos==2);
       
   197     }
       
   198 
       
   199 class CMonthNameArray : public CArrayFixFlat<TMonthName>, public MDesCArray
       
   200 	{
       
   201 public:
       
   202 	CMonthNameArray() :CArrayFixFlat<TMonthName>(4) { }
       
   203 private:
       
   204 	TInt MdcaCount() const { return(Count()); }
       
   205 	TPtrC MdcaPoint(TInt aIndex) const { return((*this)[aIndex]); }
       
   206 	};
       
   207 
       
   208 /**
       
   209 @SYMTestCaseID          SYSLIB-BAFL-CT-0413
       
   210 @SYMTestCaseDesc        Tests for mixability
       
   211 @SYMTestPriority        Medium
       
   212 @SYMTestActions         Tests the mix of setting and appending of month names to the descriptor array
       
   213 @SYMTestExpectedResults Tests must not fail
       
   214 @SYMREQ                 REQ0000
       
   215 */
       
   216 void TestDesca::MixableTestL()
       
   217 	{
       
   218 	test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0413 Test mixability "));
       
   219 	CMonthNameArray* array=new(ELeave) CMonthNameArray;
       
   220     TMonthName name;
       
   221     test.Next(_L("Add 12 month names"));
       
   222     for (TInt ii=0; ii<12; ii++)
       
   223         {
       
   224         name.Set((TMonth)ii);
       
   225         array->AppendL(name);
       
   226         }
       
   227 	DoMixableTest(array);
       
   228 	test.End();
       
   229 	}
       
   230 
       
   231 /**
       
   232 @SYMTestCaseID          SYSLIB-BAFL-CT-0414
       
   233 @SYMTestCaseDesc        Descriptor arrays tests
       
   234 @SYMTestPriority        Medium
       
   235 @SYMTestActions         Executes all the CDesCArray tests
       
   236 @SYMTestExpectedResults Tests must not fail
       
   237 @SYMREQ                 REQ0000
       
   238 */
       
   239 void DoTestsL()
       
   240     {
       
   241 	TestDesca t;
       
   242 	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0414 Test CDesCArrayFlat "));
       
   243     CDesCArrayFlat* descFlatArray=new(ELeave) CDesCArrayFlat(4);
       
   244 	TRAPD(errCode, t.FoldTestL(descFlatArray));
       
   245 	test(errCode==KErrNone);
       
   246 	TRAP(errCode, t.MainTestL(descFlatArray));
       
   247 	test(errCode==KErrNone);
       
   248 	test.Start(_L("Test CDesCArraySeg"));
       
   249     CDesCArraySeg* descSegArray=new(ELeave) CDesCArraySeg(3);
       
   250 	TRAP(errCode, t.FoldTestL(descSegArray));
       
   251 	test(errCode==KErrNone);
       
   252 	TRAP(errCode, t.MainTestL(descSegArray));
       
   253 	test(errCode==KErrNone);
       
   254     t.ComparisonTest(descFlatArray,descSegArray);
       
   255 	TRAP(errCode, t.InSequenceTestL(descSegArray));
       
   256 	test(errCode==KErrNone);
       
   257 	TRAP(errCode, t.InSequenceTestL(descFlatArray));
       
   258 	test(errCode==KErrNone);
       
   259     delete(descFlatArray);
       
   260     delete(descSegArray);
       
   261 	t.MixableTestL();
       
   262     }
       
   263 
       
   264 GLDEF_C TInt E32Main()
       
   265 	{
       
   266     __UHEAP_MARK;
       
   267     CTrapCleanup *cleanup=CTrapCleanup::New();
       
   268 	test.Title();
       
   269 	test.Start(_L(" Testing descriptor arrays "));
       
   270     TRAPD(err,DoTestsL());
       
   271     test(err==KErrNone);
       
   272 	test.End();
       
   273     test.Close();
       
   274     delete cleanup;
       
   275     __UHEAP_MARKEND;
       
   276 	return(0);
       
   277     }