author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
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_parray.cpp |
|
15 |
// Overview: |
|
16 |
// Test the variable record length array classes. |
|
17 |
// Test only covers the Flat type implementation. |
|
18 |
// API Information: |
|
19 |
// CArrayPakFlat. |
|
20 |
// Details: |
|
21 |
// - Create an array of variable length text character objects packed into a flat buffer. |
|
22 |
// - check the number of elements held in the array is 0. |
|
23 |
// - test that Compress and Reset methods are as expected. |
|
24 |
// - sort the array and check that no error is returned. |
|
25 |
// - insert an element and check the length is as expected. |
|
26 |
// - search for the inserted element and check it is found successfully. |
|
27 |
// - remove all the elements, append an element and verify that number of elements |
|
28 |
// held in the array is 1. |
|
29 |
// - insert an element into the array, search for that element using sequential, |
|
30 |
// binary search technique and verify that it is found at the expected position. |
|
31 |
// - insert another element with the same key and check that KErrAlreadyExists is |
|
32 |
// returned. |
|
33 |
// - Create an array of variable length text character objects packed into a flat buffer. |
|
34 |
// - append some strings at the end, insert some strings at the specified location and |
|
35 |
// verify that the length of each string and number of strings held in the array are |
|
36 |
// as expected. |
|
37 |
// - delete some strings and check the remaining strings in the array are as expected. |
|
38 |
// - Create an array of variable length text character objects packed into a flat buffer. |
|
39 |
// - append some strings at the end and insert some stings at specified location. |
|
40 |
// - compress the array and verify strings and the number of strings held in the |
|
41 |
// array are as expected. |
|
42 |
// - reset the array and verify the number of elements held in the array is 0. |
|
43 |
// - sort the array and check that array is sorted as expected. |
|
44 |
// - test that KErrAlreadyExists is returned if another element with the same key |
|
45 |
// type is inserted. |
|
46 |
// - search for strings using sequential, binary search and verify that 0 is returned |
|
47 |
// if found else nonzero. |
|
48 |
// - delete some text from the array and check the results are as expected. |
|
49 |
// - Create an array of variable length integer objects packed into a flat buffer. |
|
50 |
// - Insert some elements with same key which already exists within the array and |
|
51 |
// check that KErrAlreadyExists is returned. |
|
52 |
// - Test whether the heap has been corrupted by all the tests. |
|
53 |
// Platforms/Drives/Compatibility: |
|
54 |
// All |
|
55 |
// Assumptions/Requirement/Pre-requisites: |
|
56 |
// Failures and causes: |
|
57 |
// Base Port information: |
|
58 |
// |
|
59 |
// |
|
60 |
||
61 |
#include <e32std.h> |
|
62 |
#include <e32std_private.h> |
|
63 |
#include <e32base.h> |
|
64 |
#include <e32base_private.h> |
|
65 |
#include <e32test.h> |
|
66 |
#include <e32svr.h> |
|
67 |
#include <e32ver.h> |
|
68 |
||
69 |
const TInt KTestGranularity=0x10; |
|
70 |
||
71 |
LOCAL_D RTest test(_L("T_PARRAY")); |
|
72 |
||
73 |
LOCAL_C void testAllMethods(CArrayPak<TText>& aPakVar) |
|
74 |
{ |
|
75 |
test.Next(_L("Test all methods")); |
|
76 |
test(aPakVar.Count()==0); |
|
77 |
aPakVar.Compress(); |
|
78 |
test(TRUE); |
|
79 |
aPakVar.Reset(); |
|
80 |
test(TRUE); |
|
81 |
TKeyArrayPak kk(sizeof(TText),ECmpNormal,0); |
|
82 |
TKeyArrayVar vv(sizeof(TText),ECmpNormal,0); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
TKeyArrayPak hh(sizeof(TText),ECmpNormal); |
0 | 84 |
test(TRUE); |
85 |
TRAPD(res,aPakVar.SortL(vv)); |
|
86 |
test(res==KErrNone); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
TRAPD(err,aPakVar.SortL(hh)); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
test(err==KErrNone); |
0 | 89 |
const TText* aa=_S("a"); |
90 |
aPakVar.InsertL(0,*aa,sizeof(TText)); |
|
91 |
TBuf<0x10> des1(1); |
|
92 |
des1[0]=aPakVar[0]; |
|
93 |
test(des1==_L("a")); |
|
94 |
test(aPakVar.Length(0)==sizeof(TText)); |
|
95 |
test(TRUE); |
|
96 |
TInt pp; |
|
97 |
test(aPakVar.Find(*aa,kk,pp)==0); |
|
98 |
test(pp==0); |
|
99 |
aPakVar.Delete(0); |
|
100 |
aPakVar.AppendL(*aa,1); |
|
101 |
test(aPakVar.Count()==1); |
|
102 |
aPakVar.InsertIsqAllowDuplicatesL(*aa,0,kk); |
|
103 |
test(TRUE); |
|
104 |
test(aPakVar.FindIsq(*aa,kk,pp)==0); |
|
105 |
test(pp==0); |
|
106 |
TRAPD(r,aPakVar.InsertIsqL(*aa,0,kk)); |
|
107 |
test(r==KErrAlreadyExists); |
|
108 |
} |
|
109 |
||
110 |
LOCAL_C void test1(CArrayPak<TText>& aPakVar) |
|
111 |
// |
|
112 |
{ |
|
113 |
test.Next(_L("AppendL and InsertL chars")); |
|
114 |
aPakVar.AppendL(*_S("abcd"),5*sizeof(TText)); // abcd |
|
115 |
TBuf<0x10> des1(&aPakVar[0]); |
|
116 |
test(des1==_L("abcd")); |
|
117 |
test(aPakVar.Count()==1); |
|
118 |
aPakVar.AppendL(*_S("wxyz"),5*sizeof(TText)); // abcd wxyz |
|
119 |
des1=&aPakVar[1]; |
|
120 |
test(des1==_L("wxyz")); |
|
121 |
test(aPakVar.Count()==2); |
|
122 |
aPakVar.InsertL(1,*_S("ef"),3*sizeof(TText)); // abcd ef wxyz |
|
123 |
des1=&aPakVar[1]; |
|
124 |
test(des1==_L("ef")); |
|
125 |
test(aPakVar.Count()==3); |
|
126 |
aPakVar.AppendL(*_S("z"),2*sizeof(TText)); // abcd ef wxyz z |
|
127 |
des1=&aPakVar[3]; |
|
128 |
test(des1==_L("z")); |
|
129 |
aPakVar.InsertL(0,*_S("y"),2*sizeof(TText)); // y abcd ef wxyz z |
|
130 |
des1=&aPakVar[0]; |
|
131 |
test(des1==_L("y")); |
|
132 |
test(aPakVar.Length(0)==2*sizeof(TText)); |
|
133 |
test(aPakVar.Length(1)==5*sizeof(TText)); |
|
134 |
test(aPakVar.Length(2)==3*sizeof(TText)); |
|
135 |
test(aPakVar.Length(3)==5*sizeof(TText)); |
|
136 |
test(aPakVar.Length(4)==2*sizeof(TText)); |
|
137 |
des1=&aPakVar[1]; |
|
138 |
test(des1==_L("abcd")); |
|
139 |
test(aPakVar.Count()==5); |
|
140 |
// |
|
141 |
test.Next(_L("Delete chars")); |
|
142 |
aPakVar.Delete(3,1); // y abcd ef z |
|
143 |
des1=&aPakVar[2]; |
|
144 |
test(des1==_L("ef")); |
|
145 |
des1=&aPakVar[1]; |
|
146 |
test(des1==_L("abcd")); |
|
147 |
des1=&aPakVar[3]; |
|
148 |
test(des1==_L("z")); |
|
149 |
aPakVar.Delete(1,2); // y z |
|
150 |
des1=&aPakVar[0]; |
|
151 |
test(des1==_L("y")); |
|
152 |
des1=&aPakVar[1]; |
|
153 |
test(des1==_L("z")); |
|
154 |
test(aPakVar.Count()==2); |
|
155 |
} |
|
156 |
||
157 |
LOCAL_C void test2(CArrayPak<TText>& aPakVar) |
|
158 |
// |
|
159 |
{ |
|
160 |
test.Next(_L("Reset and Compress")); |
|
161 |
TBuf<0x10> des1(_L("abcde")); |
|
162 |
TBuf<0x10> des2(_L("fgh")); |
|
163 |
TBuf<0x10> des3(_L("wxyz")); |
|
164 |
aPakVar.AppendL(*(TText*)des1.Ptr(),des1.Size()); |
|
165 |
aPakVar.AppendL(*(TText*)des2.Ptr(),des2.Size()); |
|
166 |
aPakVar.Compress(); |
|
167 |
test(aPakVar.Count()==2); |
|
168 |
TPtrC des4((TText*)&aPakVar[0],des1.Length()); |
|
169 |
test(des1==des4); |
|
170 |
TPtrC des5((TText*)&aPakVar[1],des2.Length()); |
|
171 |
test(des2==des5); |
|
172 |
aPakVar.InsertL(1,*(TText*)des3.Ptr(),des3.Size()); |
|
173 |
test(aPakVar.Count()==3); |
|
174 |
TPtrC des6((TText*)&aPakVar[0],des1.Length()); |
|
175 |
test(des1==des6); |
|
176 |
TPtrC des7((TText*)&aPakVar[2],des2.Length()); |
|
177 |
test(des2==des7); |
|
178 |
TPtrC des8((TText*)&aPakVar[1],des3.Length()); |
|
179 |
test(des3==des8); |
|
180 |
aPakVar.Reset(); |
|
181 |
// So nothing in this array |
|
182 |
test(aPakVar.Count()==0); |
|
183 |
TKeyArrayPak kk(0,ECmpNormal,3); // Compare 3 characters |
|
184 |
TKeyArrayPak kk1(0,ECmpNormal,2); // Compare 2 characters |
|
185 |
TKeyArrayVar vv(0,ECmpNormal,3); // Compare 3 characters |
|
186 |
TBuf<0x10> buf1=_L("abcdef"); |
|
187 |
TBuf<0x10> buf2=_L("wxyz"); |
|
188 |
TBuf<0x10> buf3=_L("lmnop"); |
|
189 |
TBuf<0x10> buf4=_L("aa"); |
|
190 |
aPakVar.AppendL(*buf1.Ptr(),buf1.Size()); |
|
191 |
aPakVar.InsertL(0,*buf2.Ptr(),buf2.Size()); |
|
192 |
aPakVar.AppendL(*buf3.Ptr(),buf3.Size()); |
|
193 |
aPakVar.InsertL(1,*buf4.Ptr(),buf4.Size()); |
|
194 |
aPakVar.Compress(); |
|
195 |
TPtrC rd1((TText*)&aPakVar[2],buf1.Length()); |
|
196 |
test(buf1==rd1); |
|
197 |
TPtrC rd2((TText*)&aPakVar[0],buf2.Length()); |
|
198 |
test(buf2==rd2); |
|
199 |
TPtrC rd3((TText*)&aPakVar[3],buf3.Length()); |
|
200 |
test(buf3==rd3); |
|
201 |
TPtrC rd4((TText*)&aPakVar[1],buf4.Length()); |
|
202 |
test(buf4==rd4); |
|
203 |
test(aPakVar.Count()==4); |
|
204 |
||
205 |
test.Next(_L("Sort")); |
|
206 |
TRAPD(res,aPakVar.SortL(vv)); |
|
207 |
test(res==KErrNone); |
|
208 |
/**/ |
|
209 |
TPtrC rd5((TText*)&aPakVar[1],buf1.Length()); |
|
210 |
test(buf1==rd5); |
|
211 |
TPtrC rd6((TText*)&aPakVar[3],buf2.Length()); |
|
212 |
test(buf2==rd6); |
|
213 |
TPtrC rd7((TText*)&aPakVar[2],buf3.Length()); |
|
214 |
test(buf3==rd7); |
|
215 |
TPtrC rd8((TText*)&aPakVar[0],buf4.Length()); |
|
216 |
test(buf4==rd8); |
|
217 |
test(aPakVar.Count()==4); |
|
218 |
/**/ |
|
219 |
test.Next(_L("Find and FindIsq")); |
|
220 |
TBuf<0x10> buf5=_L("ffff"); |
|
221 |
test(aPakVar.InsertIsqL(*(TText*)buf5.Ptr(),buf5.Size(),kk)==2); |
|
222 |
TRAPD(r,aPakVar.InsertIsqL(*(TText*)buf5.Ptr(),buf5.Size(),kk)) |
|
223 |
test(r==KErrAlreadyExists); |
|
224 |
test(aPakVar.InsertIsqAllowDuplicatesL(*(TText*)buf5.Ptr(),buf5.Size(),kk)==3); |
|
225 |
TInt aPos; |
|
226 |
test(aPakVar.Find(*_S("abc"),kk,aPos)==0); // Second parameter 'aLength' is unused. |
|
227 |
test(aPos==1); |
|
228 |
test(aPakVar.Find(*_S("aa"),kk1,aPos)==0); |
|
229 |
test(aPos==0); |
|
230 |
test(aPakVar.Find(*_S("wxyz"),kk,aPos)==0); |
|
231 |
test(aPos==5); |
|
232 |
test(aPakVar.Find(*_S("fgh"),kk,aPos)!=0); // Returns non zero if string not found. |
|
233 |
test(aPos==6); // Not present in list, aPos set to last position |
|
234 |
test(aPakVar.Find(*_S("ffff"),kk,aPos)==0); |
|
235 |
test(aPos==2); |
|
236 |
test(aPakVar.Find(*_S("lmn"),kk,aPos)==0); |
|
237 |
test(aPos==4); //15 |
|
238 |
test(aPakVar.FindIsq(*_S("abc"),kk,aPos)==0); |
|
239 |
test(aPos==1); |
|
240 |
test(aPakVar.FindIsq(*_S("aa"),kk1,aPos)==0); |
|
241 |
test(aPos==0); |
|
242 |
test(aPakVar.FindIsq(*_S("wxyz"),kk,aPos)==0); |
|
243 |
test(aPakVar.FindIsq(*_S("fgh"),kk,aPos)!=0); // 22 Returns result of last test |
|
244 |
test(aPos==4); // Not present in list, aPos set to last position tested |
|
245 |
//This test shows problem with BinarySearch |
|
246 |
TBuf<0x10> buf7=_L("fghij"); |
|
247 |
test(aPakVar.InsertIsqL(*(TText*)buf7.Ptr(),buf7.Size(),kk)==4); |
|
248 |
test(aPakVar.FindIsq(*_S("fgh"),kk,aPos)==0); // Returns result of last test |
|
249 |
test(aPos==4); |
|
250 |
test(aPakVar.FindIsq(*_S("ffff"),kk,aPos)==0); |
|
251 |
test(aPos==3); |
|
252 |
test(aPakVar.FindIsq(*_S("lmn"),kk,aPos)==0); |
|
253 |
test(aPos==5); |
|
254 |
aPakVar.Delete(4,1); |
|
255 |
test(aPakVar.Find(*_S("wxyz"),kk,aPos)==0); |
|
256 |
test(aPos==5); |
|
257 |
} |
|
258 |
||
259 |
LOCAL_C void test3(CArrayPak<TInt>& aPak) |
|
260 |
||
261 |
{ |
|
262 |
test.Next(_L("InsertIsqL")); |
|
263 |
TKeyArrayPak kk(0,ECmpTInt); |
|
264 |
||
265 |
TInt pos=0; |
|
266 |
TInt mod=47; |
|
267 |
TInt inc=23; |
|
268 |
||
269 |
TInt i=0; |
|
270 |
FOREVER |
|
271 |
{ |
|
272 |
TInt ret; |
|
273 |
if (i&1) |
|
274 |
TRAP(ret,aPak.InsertIsqL(i,sizeof(TInt),kk)) |
|
275 |
else |
|
276 |
{ |
|
277 |
TRAP(ret,pos=aPak.InsertIsqL(i,sizeof(TInt),kk)) |
|
278 |
if (ret==KErrNone) |
|
279 |
test(aPak[pos]==i); |
|
280 |
} |
|
281 |
if (ret==KErrAlreadyExists) |
|
282 |
break; |
|
283 |
i=(i+inc)%mod; |
|
284 |
} |
|
285 |
for(i=0;i<mod;i++) |
|
286 |
{ |
|
287 |
pos=(-1); |
|
288 |
test(aPak.FindIsq(i,kk,pos)==0); |
|
289 |
test(pos==i); |
|
290 |
TRAPD(r,aPak.InsertIsqL(i,sizeof(TInt),kk)) |
|
291 |
test(r==KErrAlreadyExists); |
|
292 |
} |
|
293 |
} |
|
294 |
||
295 |
GLDEF_C TInt E32Main() |
|
296 |
// |
|
297 |
// Test the variable record length array classes. |
|
298 |
// Initially test only covers the Flat type implementation. |
|
299 |
// |
|
300 |
{ |
|
301 |
test.Title(); |
|
302 |
__UHEAP_MARK; |
|
303 |
test.Start(_L("class CArrayPakFlat")); |
|
304 |
// |
|
305 |
CArrayPakFlat<TText>* pPakFlat=new CArrayPakFlat<TText>(KTestGranularity); |
|
306 |
testAllMethods(*pPakFlat); |
|
307 |
delete pPakFlat; |
|
308 |
// |
|
309 |
CArrayPakFlat<TText>* pPakFlatChar=new CArrayPakFlat<TText>(KTestGranularity); |
|
310 |
test1(*pPakFlatChar); |
|
311 |
delete pPakFlatChar; |
|
312 |
// |
|
313 |
CArrayPakFlat<TText>* pPakFlatArr=new CArrayPakFlat<TText>(KTestGranularity); |
|
314 |
test2(*pPakFlatArr); |
|
315 |
delete pPakFlatArr; |
|
316 |
// |
|
317 |
CArrayPakFlat<TInt>* pPakFlatInt=new CArrayPakFlat<TInt>(KTestGranularity); |
|
318 |
test3(*pPakFlatInt); |
|
319 |
delete pPakFlatInt; |
|
320 |
// |
|
321 |
test.End(); |
|
322 |
__UHEAP_MARKEND; |
|
323 |
return(0); |
|
324 |
} |
|
325 |