Update contrib.
1 // Copyright (c) 1995-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\buffer\t_readar.cpp
16 // Test the CArrayFixFlat, CArrayPakFlat, CArrayVarFlat classes.
18 // CArrayFixFlat, CArrayPakFlat, CArrayVarFlat.
20 // - Create an array of fixed length objects contained within a flat
21 // dynamic buffer, append some elements onto the end of the array,
22 // sort the array into key sequence, check the number of elements
23 // in the array is as expected and read all of elements. Check
24 // whether the heap has been corrupted.
25 // - Create an array of variable length objects implemented using a
26 // flat dynamic buffer, append some elements onto the end of the
27 // array, sort the array into key sequence, check the number of elements
28 // in the array is as expected and read all of elements. Check whether
29 // the heap has been corrupted.
30 // - Create an array of variable length objects packed into a flat buffer,
31 // append some elements onto the end of the array, sort the array into
32 // key sequence and check the number of elements held in the array is
33 // as expected. Read all array elements. Check whether the heap has been
35 // - Check whether the heap has been corrupted by any of the tests.
36 // Platforms/Drives/Compatibility:
38 // Assumptions/Requirement/Pre-requisites:
39 // Failures and causes:
40 // Base Port information:
46 const TInt KMaxStrings=3;
48 LOCAL_D RTest test(_L("T_READAR"));
49 LOCAL_D const TPtrC s1(_L("ZZZZ"));
50 LOCAL_D const TPtrC s2(_L("AAAA"));
51 LOCAL_D const TPtrC s3(_L("MMMM"));
52 LOCAL_D const TPtrC* str[KMaxStrings] = {&s1,&s2,&s3};
53 LOCAL_D const TPtrC* strSorted[KMaxStrings] = {&s2,&s3,&s1};
55 LOCAL_C void testReadAny(const TArray<TBufC<0x20> > anArray)
57 // Test with fixed length arrays.
61 test(anArray.Count()==KMaxStrings);
62 for (TInt i=0;i<KMaxStrings;i++)
63 test(anArray[i]==(*strSorted[i]));
66 LOCAL_C void testFixL()
68 // Test with fixed length arrays.
74 test.Start(_L("Creating Fix array"));
75 CArrayFixFlat<TBufC<0x20> >* pFix=new(ELeave) CArrayFixFlat<TBufC<0x20> >(1);
76 for (TInt i=0;i<KMaxStrings;i++)
78 TBufC<0x20> b=(*str[i]);
82 test.Next(_L("Sorting Fix array"));
83 TKeyArrayFix array(0,ECmpNormal);
86 test.Next(_L("Reading Fix array"));
87 testReadAny(pFix->Array());
89 test.Next(_L("Destroying Fix array"));
96 LOCAL_C void testVarL()
98 // Test with variable length arrays.
104 test.Start(_L("Creating Var array"));
105 CArrayVarFlat<TBufC<0x20> >* pVar=new(ELeave) CArrayVarFlat<TBufC<0x20> >(1);
106 for (TInt i=0;i<KMaxStrings;i++)
108 TBufC<0x20> b=(*str[i]);
109 pVar->AppendL(b,b.Size()+sizeof(TUint));
112 test.Next(_L("Sorting Var array"));
113 TKeyArrayVar array(0,ECmpNormal);
116 test.Next(_L("Reading Var array"));
117 testReadAny(pVar->Array());
119 test.Next(_L("Destroying Var array"));
126 LOCAL_C void testPakL()
128 // Test with variable length packed arrays.
134 test.Start(_L("Creating Pak array"));
135 CArrayPakFlat<TBufC<0x20> >* pPak=new(ELeave) CArrayPakFlat<TBufC<0x20> >(1);
136 for (TInt i=0;i<KMaxStrings;i++)
138 TBufC<0x20> b=(*str[i]);
139 pPak->AppendL(b,b.Size()+sizeof(TUint));
142 test.Next(_L("Sorting Pak array"));
143 TKeyArrayVar array(0,ECmpNormal);
146 test.Next(_L("Reading Pak array"));
147 testReadAny(pPak->Array());
149 test.Next(_L("Destroying Pak array"));
156 GLDEF_C TInt E32Main()
158 // Test the Array classes.
165 test.Start(_L("Testing Fix arrays"));
169 test.Next(_L("Testing Var arrays"));
173 test.Next(_L("Testing Pak arrays"));