0
|
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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\buffer\t_readar.cpp
|
|
15 |
// Overview:
|
|
16 |
// Test the CArrayFixFlat, CArrayPakFlat, CArrayVarFlat classes.
|
|
17 |
// API Information:
|
|
18 |
// CArrayFixFlat, CArrayPakFlat, CArrayVarFlat.
|
|
19 |
// Details:
|
|
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
|
|
34 |
// corrupted.
|
|
35 |
// - Check whether the heap has been corrupted by any of the tests.
|
|
36 |
// Platforms/Drives/Compatibility:
|
|
37 |
// All
|
|
38 |
// Assumptions/Requirement/Pre-requisites:
|
|
39 |
// Failures and causes:
|
|
40 |
// Base Port information:
|
|
41 |
//
|
|
42 |
//
|
|
43 |
|
|
44 |
#include <e32test.h>
|
|
45 |
|
|
46 |
const TInt KMaxStrings=3;
|
|
47 |
|
|
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};
|
|
54 |
|
|
55 |
LOCAL_C void testReadAny(const TArray<TBufC<0x20> > anArray)
|
|
56 |
//
|
|
57 |
// Test with fixed length arrays.
|
|
58 |
//
|
|
59 |
{
|
|
60 |
|
|
61 |
test(anArray.Count()==KMaxStrings);
|
|
62 |
for (TInt i=0;i<KMaxStrings;i++)
|
|
63 |
test(anArray[i]==(*strSorted[i]));
|
|
64 |
}
|
|
65 |
|
|
66 |
LOCAL_C void testFixL()
|
|
67 |
//
|
|
68 |
// Test with fixed length arrays.
|
|
69 |
//
|
|
70 |
{
|
|
71 |
|
|
72 |
__UHEAP_MARK;
|
|
73 |
//
|
|
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++)
|
|
77 |
{
|
|
78 |
TBufC<0x20> b=(*str[i]);
|
|
79 |
pFix->AppendL(b);
|
|
80 |
}
|
|
81 |
//
|
|
82 |
test.Next(_L("Sorting Fix array"));
|
|
83 |
TKeyArrayFix array(0,ECmpNormal);
|
|
84 |
pFix->Sort(array);
|
|
85 |
//
|
|
86 |
test.Next(_L("Reading Fix array"));
|
|
87 |
testReadAny(pFix->Array());
|
|
88 |
//
|
|
89 |
test.Next(_L("Destroying Fix array"));
|
|
90 |
delete pFix;
|
|
91 |
__UHEAP_MARKEND;
|
|
92 |
//
|
|
93 |
test.End();
|
|
94 |
}
|
|
95 |
|
|
96 |
LOCAL_C void testVarL()
|
|
97 |
//
|
|
98 |
// Test with variable length arrays.
|
|
99 |
//
|
|
100 |
{
|
|
101 |
|
|
102 |
__UHEAP_MARK;
|
|
103 |
//
|
|
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++)
|
|
107 |
{
|
|
108 |
TBufC<0x20> b=(*str[i]);
|
|
109 |
pVar->AppendL(b,b.Size()+sizeof(TUint));
|
|
110 |
}
|
|
111 |
//
|
|
112 |
test.Next(_L("Sorting Var array"));
|
|
113 |
TKeyArrayVar array(0,ECmpNormal);
|
|
114 |
pVar->Sort(array);
|
|
115 |
//
|
|
116 |
test.Next(_L("Reading Var array"));
|
|
117 |
testReadAny(pVar->Array());
|
|
118 |
//
|
|
119 |
test.Next(_L("Destroying Var array"));
|
|
120 |
delete pVar;
|
|
121 |
__UHEAP_MARKEND;
|
|
122 |
//
|
|
123 |
test.End();
|
|
124 |
}
|
|
125 |
|
|
126 |
LOCAL_C void testPakL()
|
|
127 |
//
|
|
128 |
// Test with variable length packed arrays.
|
|
129 |
//
|
|
130 |
{
|
|
131 |
|
|
132 |
__UHEAP_MARK;
|
|
133 |
//
|
|
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++)
|
|
137 |
{
|
|
138 |
TBufC<0x20> b=(*str[i]);
|
|
139 |
pPak->AppendL(b,b.Size()+sizeof(TUint));
|
|
140 |
}
|
|
141 |
//
|
|
142 |
test.Next(_L("Sorting Pak array"));
|
|
143 |
TKeyArrayVar array(0,ECmpNormal);
|
|
144 |
pPak->SortL(array);
|
|
145 |
//
|
|
146 |
test.Next(_L("Reading Pak array"));
|
|
147 |
testReadAny(pPak->Array());
|
|
148 |
//
|
|
149 |
test.Next(_L("Destroying Pak array"));
|
|
150 |
delete pPak;
|
|
151 |
__UHEAP_MARKEND;
|
|
152 |
//
|
|
153 |
test.End();
|
|
154 |
}
|
|
155 |
|
|
156 |
GLDEF_C TInt E32Main()
|
|
157 |
//
|
|
158 |
// Test the Array classes.
|
|
159 |
//
|
|
160 |
{
|
|
161 |
|
|
162 |
test.Title();
|
|
163 |
__UHEAP_MARK;
|
|
164 |
//
|
|
165 |
test.Start(_L("Testing Fix arrays"));
|
|
166 |
TRAPD(r,testFixL());
|
|
167 |
test(r==KErrNone);
|
|
168 |
//
|
|
169 |
test.Next(_L("Testing Var arrays"));
|
|
170 |
TRAP(r,testVarL());
|
|
171 |
test(r==KErrNone);
|
|
172 |
//
|
|
173 |
test.Next(_L("Testing Pak arrays"));
|
|
174 |
TRAP(r,testPakL());
|
|
175 |
test(r==KErrNone);
|
|
176 |
//
|
|
177 |
__UHEAP_MARKEND;
|
|
178 |
test.End();
|
|
179 |
return(0);
|
|
180 |
}
|
|
181 |
|