sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Started by DWW, April 1996 sl@0: // Tests TPtrC arrays sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: LOCAL_D RTest test(_L("T_PTRCA")); sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0425 sl@0: @SYMTestCaseDesc Testing descriptor arrays sl@0: Tests for CPtrCArray::MdcaPoint(),CPtrCArray::MdcaCount() functions sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Tests by adding descriptors to the arrays and then comparing both CPtrCArray & CDesCArray arrays sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testPtrCDesC() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0425 PtrC and DesC ")); sl@0: CPtrCArray* ptrA=new(ELeave) CPtrCArray(8); sl@0: CDesCArray* desA=new(ELeave) CDesCArrayFlat(8); sl@0: desA->AppendL(_L("one")); sl@0: ptrA->AppendL(desA->MdcaPoint(0)); sl@0: test(ptrA->MdcaPoint(0)==desA->MdcaPoint(0)); sl@0: TBuf<32> buffer=_L("two"); sl@0: ptrA->InsertL(0,buffer); sl@0: test(ptrA->MdcaPoint(0)!=desA->MdcaPoint(0)); sl@0: buffer=_L("onetwothree"); sl@0: test(ptrA->MdcaPoint(0)==desA->MdcaPoint(0)); // TPtrC length is unchanged sl@0: // sl@0: desA->AppendL(_L("two")); sl@0: desA->AppendL(_L("three")); sl@0: test(ptrA->MdcaPoint(1)!=desA->MdcaPoint(1)); sl@0: *ptrA=*desA; sl@0: test(ptrA->MdcaCount()==desA->MdcaCount()); sl@0: test(ptrA->MdcaPoint(1)==desA->MdcaPoint(1)); sl@0: buffer=ptrA->MdcaPoint(0); sl@0: test(buffer==_L("one")); sl@0: // sl@0: ptrA->Reset(); sl@0: desA->Reset(); sl@0: buffer=_L("new test"); sl@0: desA->AppendL(buffer); sl@0: ptrA->AppendL(buffer); sl@0: test(ptrA->MdcaPoint(0)==buffer); sl@0: test(desA->MdcaPoint(0)==buffer); sl@0: buffer=_L("hello"); sl@0: desA->AppendL(buffer); sl@0: ptrA->AppendL(buffer); sl@0: test(ptrA->MdcaPoint(0)==_L("helloest")); sl@0: test(ptrA->MdcaPoint(1)==buffer); sl@0: test(desA->MdcaPoint(1)==buffer); sl@0: // sl@0: delete(ptrA); sl@0: delete(desA); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-0426 sl@0: @SYMTestCaseDesc CPtrCArray class functionality test sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Tests for CPtrCArray::InsertIsqL(),CPtrCArray::InsertIsqAllowDuplicatesL() functions sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testFindIsq() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0426 Findin in sequence ")); sl@0: CPtrCArray* ptrA=new(ELeave) CPtrCArray(8); sl@0: // sl@0: TPtrC hello(_S("Hello")); sl@0: TPtrC bye(_S("Bye")); sl@0: TPtrC world(_S("World")); sl@0: TPtrC middle(_S("middle")); sl@0: TPtrC extra(_S("extra")); sl@0: TInt pos; sl@0: ptrA->AppendL(hello); sl@0: ptrA->AppendL(bye); sl@0: ptrA->AppendL(world); sl@0: ptrA->AppendL(middle); sl@0: // sl@0: TKeyArrayFix key(0,ECmpFolded); sl@0: // sl@0: ptrA->Find(world,key,pos); sl@0: test(pos==2); sl@0: ptrA->Sort(key); sl@0: ptrA->Find(world,key,pos); sl@0: test(pos==3); sl@0: // sl@0: pos=ptrA->InsertIsqL(extra,key); sl@0: test(pos==1); sl@0: TRAP(pos,ptrA->InsertIsqL(extra,key)); sl@0: test(pos==KErrAlreadyExists); sl@0: pos=ptrA->InsertIsqAllowDuplicatesL(extra,key); sl@0: test(pos==2); sl@0: // sl@0: delete(ptrA); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: CTrapCleanup *cleanup=CTrapCleanup::New(); sl@0: test.Title(); sl@0: test.Start(_L("Testing descriptor arrays ")); sl@0: __UHEAP_MARK; sl@0: TRAPD(err,testPtrCDesC()); sl@0: test(err==KErrNone); sl@0: TRAP(err,testFindIsq()); sl@0: test(err==KErrNone); sl@0: __UHEAP_MARKEND; sl@0: test.End(); sl@0: test.Close(); sl@0: delete cleanup; sl@0: return(0); sl@0: }