sl@0: // Copyright (c) 1995-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 the License "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: // e32test\buffer\t_readar.cpp sl@0: // Overview: sl@0: // Test the CArrayFixFlat, CArrayPakFlat, CArrayVarFlat classes. sl@0: // API Information: sl@0: // CArrayFixFlat, CArrayPakFlat, CArrayVarFlat. sl@0: // Details: sl@0: // - Create an array of fixed length objects contained within a flat sl@0: // dynamic buffer, append some elements onto the end of the array, sl@0: // sort the array into key sequence, check the number of elements sl@0: // in the array is as expected and read all of elements. Check sl@0: // whether the heap has been corrupted. sl@0: // - Create an array of variable length objects implemented using a sl@0: // flat dynamic buffer, append some elements onto the end of the sl@0: // array, sort the array into key sequence, check the number of elements sl@0: // in the array is as expected and read all of elements. Check whether sl@0: // the heap has been corrupted. sl@0: // - Create an array of variable length objects packed into a flat buffer, sl@0: // append some elements onto the end of the array, sort the array into sl@0: // key sequence and check the number of elements held in the array is sl@0: // as expected. Read all array elements. Check whether the heap has been sl@0: // corrupted. sl@0: // - Check whether the heap has been corrupted by any of the tests. sl@0: // Platforms/Drives/Compatibility: sl@0: // All sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: sl@0: const TInt KMaxStrings=3; sl@0: sl@0: LOCAL_D RTest test(_L("T_READAR")); sl@0: LOCAL_D const TPtrC s1(_L("ZZZZ")); sl@0: LOCAL_D const TPtrC s2(_L("AAAA")); sl@0: LOCAL_D const TPtrC s3(_L("MMMM")); sl@0: LOCAL_D const TPtrC* str[KMaxStrings] = {&s1,&s2,&s3}; sl@0: LOCAL_D const TPtrC* strSorted[KMaxStrings] = {&s2,&s3,&s1}; sl@0: sl@0: LOCAL_C void testReadAny(const TArray > anArray) sl@0: // sl@0: // Test with fixed length arrays. sl@0: // sl@0: { sl@0: sl@0: test(anArray.Count()==KMaxStrings); sl@0: for (TInt i=0;i >* pFix=new(ELeave) CArrayFixFlat >(1); sl@0: for (TInt i=0;i b=(*str[i]); sl@0: pFix->AppendL(b); sl@0: } sl@0: // sl@0: test.Next(_L("Sorting Fix array")); sl@0: TKeyArrayFix array(0,ECmpNormal); sl@0: pFix->Sort(array); sl@0: // sl@0: test.Next(_L("Reading Fix array")); sl@0: testReadAny(pFix->Array()); sl@0: // sl@0: test.Next(_L("Destroying Fix array")); sl@0: delete pFix; sl@0: __UHEAP_MARKEND; sl@0: // sl@0: test.End(); sl@0: } sl@0: sl@0: LOCAL_C void testVarL() sl@0: // sl@0: // Test with variable length arrays. sl@0: // sl@0: { sl@0: sl@0: __UHEAP_MARK; sl@0: // sl@0: test.Start(_L("Creating Var array")); sl@0: CArrayVarFlat >* pVar=new(ELeave) CArrayVarFlat >(1); sl@0: for (TInt i=0;i b=(*str[i]); sl@0: pVar->AppendL(b,b.Size()+sizeof(TUint)); sl@0: } sl@0: // sl@0: test.Next(_L("Sorting Var array")); sl@0: TKeyArrayVar array(0,ECmpNormal); sl@0: pVar->Sort(array); sl@0: // sl@0: test.Next(_L("Reading Var array")); sl@0: testReadAny(pVar->Array()); sl@0: // sl@0: test.Next(_L("Destroying Var array")); sl@0: delete pVar; sl@0: __UHEAP_MARKEND; sl@0: // sl@0: test.End(); sl@0: } sl@0: sl@0: LOCAL_C void testPakL() sl@0: // sl@0: // Test with variable length packed arrays. sl@0: // sl@0: { sl@0: sl@0: __UHEAP_MARK; sl@0: // sl@0: test.Start(_L("Creating Pak array")); sl@0: CArrayPakFlat >* pPak=new(ELeave) CArrayPakFlat >(1); sl@0: for (TInt i=0;i b=(*str[i]); sl@0: pPak->AppendL(b,b.Size()+sizeof(TUint)); sl@0: } sl@0: // sl@0: test.Next(_L("Sorting Pak array")); sl@0: TKeyArrayVar array(0,ECmpNormal); sl@0: pPak->SortL(array); sl@0: // sl@0: test.Next(_L("Reading Pak array")); sl@0: testReadAny(pPak->Array()); sl@0: // sl@0: test.Next(_L("Destroying Pak array")); sl@0: delete pPak; sl@0: __UHEAP_MARKEND; sl@0: // sl@0: test.End(); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: // sl@0: // Test the Array classes. sl@0: // sl@0: { sl@0: sl@0: test.Title(); sl@0: __UHEAP_MARK; sl@0: // sl@0: test.Start(_L("Testing Fix arrays")); sl@0: TRAPD(r,testFixL()); sl@0: test(r==KErrNone); sl@0: // sl@0: test.Next(_L("Testing Var arrays")); sl@0: TRAP(r,testVarL()); sl@0: test(r==KErrNone); sl@0: // sl@0: test.Next(_L("Testing Pak arrays")); sl@0: TRAP(r,testPakL()); sl@0: test(r==KErrNone); sl@0: // sl@0: __UHEAP_MARKEND; sl@0: test.End(); sl@0: return(0); sl@0: } sl@0: