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_key.cpp
|
|
15 |
// Overview:
|
|
16 |
// Test arrays keys against flat and segmented arrays of characters (8 and 16 bit) and records.
|
|
17 |
// API Information:
|
|
18 |
// TKeyArrayFix, TKeyArrayVar.
|
|
19 |
// Details:
|
|
20 |
// - Create flat and segmented array of TText8, TText16, TText. Append some text to the
|
|
21 |
// arrays and test the functions of the TKeyArrayFix class using the Find method which
|
|
22 |
// calls SetPtr, Set, Compare methods with ECmpNormal8, ECmpFolded8, ECmpCollated8,
|
|
23 |
// ECmpNormal16, ECmpFolded16, ECmpCollated16, ECmpNormal, ECmpFolded, ECmpCollated key types.
|
|
24 |
// - Test the functions of the TKeyArrayVar class using the Find method which calls SetPtr, Set,
|
|
25 |
// Compare methods with ECmpNormal8, ECmpFolded8, ECmpCollated8, ECmpNormal16, ECmpFolded16,
|
|
26 |
// ECmpCollated16, ECmpNormal, ECmpFolded, ECmpCollated key types.
|
|
27 |
// - Create flat and segmented array of TText, append some structures with different values.
|
|
28 |
// - Test the functions of the TKeyArrayFix, TKeyArrayVar classes by searching the values using
|
|
29 |
// sequential search technique with ECmpNormal, ECmpTInt32 key type and verifying that it is
|
|
30 |
// found at correct position.
|
|
31 |
// - For TKeyArrayFix and TKeyArrayVar class, create a flat array of TText, append some structures
|
|
32 |
// with different numeric values, sort the array, search the values using ECmpTInt, ECmpTUint,
|
|
33 |
// ECmpTint8, ECmpTUint8, ECmpTint16, ECmpTUint16, ECmpTint32, ECmpTUint32 key types and verify
|
|
34 |
// that values are found in order as expected.
|
|
35 |
// Platforms/Drives/Compatibility:
|
|
36 |
// All
|
|
37 |
// Assumptions/Requirement/Pre-requisites:
|
|
38 |
// Failures and causes:
|
|
39 |
// Base Port information:
|
|
40 |
//
|
|
41 |
//
|
|
42 |
|
|
43 |
#include <e32std.h>
|
|
44 |
#include <e32std_private.h>
|
|
45 |
#include <e32base.h>
|
|
46 |
#include <e32base_private.h>
|
|
47 |
#include <e32test.h>
|
|
48 |
#include <e32svr.h>
|
|
49 |
#include <e32ver.h>
|
|
50 |
|
|
51 |
#ifdef __VC32__
|
|
52 |
#pragma warning (disable:4710) // Function not expanded
|
|
53 |
#pragma warning (disable:4702) // Unreachable code
|
|
54 |
#endif
|
|
55 |
|
|
56 |
const TInt KTestGranularity=0x02;
|
|
57 |
|
|
58 |
LOCAL_D RTest test(_L("T_KEY"));
|
|
59 |
|
|
60 |
template <class T,TInt S>
|
|
61 |
class TArr
|
|
62 |
{
|
|
63 |
public:
|
|
64 |
TArr() {}
|
|
65 |
TInt Count() const {return S;}
|
|
66 |
T& operator[](TInt anIndex) {return iArr[anIndex];}
|
|
67 |
const T& operator[](TInt anIndex) const {return iArr[anIndex];}
|
|
68 |
private:
|
|
69 |
T iArr[S];
|
|
70 |
};
|
|
71 |
|
|
72 |
//#if defined(_DEBUG)
|
|
73 |
struct Record
|
|
74 |
{
|
|
75 |
TBuf<0x10> name;
|
|
76 |
TInt32 age;
|
|
77 |
TText8 code;
|
|
78 |
};
|
|
79 |
|
|
80 |
struct Record2
|
|
81 |
{
|
|
82 |
TInt tint;
|
|
83 |
TUint tuint;
|
|
84 |
TInt8 tint8;
|
|
85 |
TUint8 tuint8;
|
|
86 |
TInt16 tint16;
|
|
87 |
TUint16 tuint16;
|
|
88 |
TInt32 tint32;
|
|
89 |
TUint32 tuint32;
|
|
90 |
}Rec1, Rec2, Rec3, Rec4;
|
|
91 |
|
|
92 |
LOCAL_C void SetRecordData(void)
|
|
93 |
{
|
|
94 |
Rec1.tint=KMaxTInt;
|
|
95 |
Rec2.tint=0;
|
|
96 |
Rec3.tint=-KMaxTInt;
|
|
97 |
Rec4.tint=KMinTInt;
|
|
98 |
Rec1.tint8=KMaxTInt8;
|
|
99 |
Rec2.tint8=0;
|
|
100 |
Rec3.tint8=-KMaxTInt8;
|
|
101 |
Rec4.tint8=(TInt8)KMinTInt8;
|
|
102 |
Rec1.tint16=KMaxTInt16;
|
|
103 |
Rec2.tint16=0;
|
|
104 |
Rec3.tint16=-KMaxTInt16;
|
|
105 |
Rec4.tint16=(TInt16)KMinTInt16;
|
|
106 |
Rec1.tint32=KMaxTInt32;
|
|
107 |
Rec2.tint32=0;
|
|
108 |
Rec3.tint32=-KMaxTInt32;
|
|
109 |
Rec4.tint32=(TInt32)KMinTInt32;
|
|
110 |
Rec1.tuint=0;
|
|
111 |
Rec2.tuint=1;
|
|
112 |
Rec3.tuint=KMaxTUint-1;
|
|
113 |
Rec4.tuint=KMaxTUint;
|
|
114 |
Rec1.tuint8=0;
|
|
115 |
Rec2.tuint8=1;
|
|
116 |
Rec3.tuint8=(TUint8)(KMaxTUint8-1);
|
|
117 |
Rec4.tuint8=(TUint8)KMaxTUint8;
|
|
118 |
Rec1.tuint16=0;
|
|
119 |
Rec2.tuint16=1;
|
|
120 |
Rec3.tuint16=(TUint16)(KMaxTUint16-1);
|
|
121 |
Rec4.tuint16=(TUint16)KMaxTUint16;
|
|
122 |
Rec1.tuint32=0;
|
|
123 |
Rec2.tuint32=1;
|
|
124 |
Rec3.tuint32=(TUint32)(KMaxTUint32-1);
|
|
125 |
Rec4.tuint32=KMaxTUint32;
|
|
126 |
}
|
|
127 |
|
|
128 |
typedef enum {eEight, eSixteen} TMode;
|
|
129 |
|
|
130 |
template<class KeyType, class ArrayType, class S> // S is TText8, TTExt etc. called S as _TL requires S in e32test.h
|
|
131 |
class TestTKey
|
|
132 |
{
|
|
133 |
public:
|
|
134 |
void Test1(TKeyCmpText, TKeyCmpText, TKeyCmpText);
|
|
135 |
void Test2(TKeyCmpText, TKeyCmpText, TKeyCmpText);
|
|
136 |
void Test3(void);
|
|
137 |
void Test4(void);
|
|
138 |
void Test5(void);
|
|
139 |
void Test6(void);
|
|
140 |
};
|
|
141 |
|
|
142 |
template<class KeyType, class ArrayType, class S>
|
|
143 |
GLDEF_C void TestTKey<KeyType, ArrayType, S>::Test1(TKeyCmpText N, TKeyCmpText F, TKeyCmpText C)
|
|
144 |
{
|
|
145 |
// This tests the functions of the TKey classes indirectly - mostly using the Find method
|
|
146 |
// which calls SetPtr(), Set() (both trivial) and more importantly Compare(),
|
|
147 |
|
|
148 |
ArrayType* pArray=new ArrayType(KTestGranularity);
|
|
149 |
pArray->AppendL(*(const TArr<S,5>*)_TL("aa cc"));
|
|
150 |
pArray->AppendL(*(const TArr<S,5>*)_TL("bb bb"));
|
|
151 |
pArray->AppendL(*(const TArr<S,5>*)_TL("cc aa"));
|
|
152 |
|
|
153 |
KeyType NormalKey(0,N,5);
|
|
154 |
KeyType NormalKeyOffset(sizeof(S)*3,N,2) ;
|
|
155 |
KeyType FoldedKey(0,F,5);
|
|
156 |
KeyType FoldedKeyOffset(sizeof(S)*3,F,2);
|
|
157 |
KeyType CollatedKey(0,C,5);
|
|
158 |
KeyType CollatedKeyOffset(sizeof(S)*3,C,2);
|
|
159 |
|
|
160 |
TInt pos;
|
|
161 |
test(pArray->Find(*(const TArr<S,5>*)_TL("aa cc"), NormalKey, pos)==0);
|
|
162 |
test(pos==0);
|
|
163 |
test(pArray->Find(*(const TArr<S,5>*)_TL("bb bb"), NormalKey, pos)==0);
|
|
164 |
test(pos==1);
|
|
165 |
test(pArray->Find(*(const TArr<S,5>*)_TL("cc aa"), NormalKey, pos)==0);
|
|
166 |
test(pos==2);
|
|
167 |
test(pArray->Find(*(const TArr<S,5>*)_TL("BB BB"), NormalKey, pos)!=0);
|
|
168 |
|
|
169 |
|
|
170 |
test(pArray->Find(*(const TArr<S,5>*)_TL("___cc"), NormalKeyOffset, pos)==0);
|
|
171 |
test(pos==0);
|
|
172 |
test(pArray->Find(*(const TArr<S,5>*)_TL("___bb"), NormalKeyOffset, pos)==0);
|
|
173 |
test(pos==1);
|
|
174 |
test(pArray->Find(*(const TArr<S,5>*)_TL("___aa"), NormalKeyOffset, pos)==0);
|
|
175 |
test(pos==2);
|
|
176 |
test(pArray->Find(*(const TArr<S,5>*)_TL("___ax"), NormalKeyOffset, pos)!=0);
|
|
177 |
|
|
178 |
|
|
179 |
test(pArray->Find(*(const TArr<S,5>*)_TL("aa cc"), FoldedKey, pos)==0);
|
|
180 |
test(pos==0);
|
|
181 |
test(pArray->Find(*(const TArr<S,5>*)_TL("bb bb"), FoldedKey, pos)==0);
|
|
182 |
test(pos==1);
|
|
183 |
test(pArray->Find(*(const TArr<S,5>*)_TL("cc aa"), FoldedKey, pos)==0);
|
|
184 |
test(pos==2);
|
|
185 |
|
|
186 |
|
|
187 |
test(pArray->Find(*(const TArr<S,5>*)_TL("___CC"), FoldedKeyOffset, pos)==0);
|
|
188 |
test(pos==0);
|
|
189 |
test(pArray->Find(*(const TArr<S,5>*)_TL("___bB"), FoldedKeyOffset, pos)==0);
|
|
190 |
test(pos==1);
|
|
191 |
test(pArray->Find(*(const TArr<S,5>*)_TL("___Aa"), FoldedKeyOffset, pos)==0);
|
|
192 |
test(pos==2);
|
|
193 |
test(pArray->Find(*(const TArr<S,5>*)_TL("___ax"), FoldedKeyOffset, pos)!=0);
|
|
194 |
|
|
195 |
|
|
196 |
test(pArray->Find(*(const TArr<S,5>*)_TL("aa cc"), CollatedKey, pos)==0);
|
|
197 |
test(pos==0);
|
|
198 |
test(pArray->Find(*(const TArr<S,5>*)_TL("bb bb"), CollatedKey, pos)==0);
|
|
199 |
test(pos==1);
|
|
200 |
test(pArray->Find(*(const TArr<S,5>*)_TL("cc aa"), CollatedKey, pos)==0);
|
|
201 |
test(pos==2);
|
|
202 |
|
|
203 |
|
|
204 |
test(pArray->Find(*(const TArr<S,5>*)_TL("___cc"), CollatedKeyOffset, pos)==0);
|
|
205 |
test(pos==0);
|
|
206 |
test(pArray->Find(*(const TArr<S,5>*)_TL("___bb"), CollatedKeyOffset, pos)==0);
|
|
207 |
test(pos==1);
|
|
208 |
test(pArray->Find(*(const TArr<S,5>*)_TL("___aa"), CollatedKeyOffset, pos)==0);
|
|
209 |
test(pos==2);
|
|
210 |
test(pArray->Find(*(const TArr<S,5>*)_TL("___ax"), CollatedKeyOffset, pos)!=0);
|
|
211 |
|
|
212 |
delete pArray;
|
|
213 |
}
|
|
214 |
|
|
215 |
|
|
216 |
template<class KeyType, class ArrayType, class S>
|
|
217 |
GLDEF_C void TestTKey<KeyType, ArrayType, S>::Test2(TKeyCmpText N, TKeyCmpText F, TKeyCmpText C)
|
|
218 |
{
|
|
219 |
// This tests the functions of the TKey classes indirectly - mostly using the Find method
|
|
220 |
// which calls SetPtr(), Set() (both trivial) and more importantly Compare(),
|
|
221 |
|
|
222 |
ArrayType* pArray=new ArrayType(KTestGranularity);
|
|
223 |
pArray->AppendL(*(S(*))_TL("aa cc"), 5*sizeof(S));
|
|
224 |
pArray->AppendL(*(S(*))_TL("bb bbb"), 6*sizeof(S));
|
|
225 |
pArray->AppendL(*(S(*))_TL("cc aaaa"), 7*sizeof(S));
|
|
226 |
|
|
227 |
KeyType NormalKey5(0,N,5);
|
|
228 |
KeyType NormalKey6(0,N,6);
|
|
229 |
KeyType NormalKey7(0,N,7);
|
|
230 |
KeyType NormalKeyOffset(sizeof(S)*3,N,2);
|
|
231 |
|
|
232 |
KeyType FoldedKey5(0,F,5);
|
|
233 |
KeyType FoldedKey6(0,F,6);
|
|
234 |
KeyType FoldedKey7(0,F,7);
|
|
235 |
KeyType FoldedKeyOffset(sizeof(S)*3,F,2);
|
|
236 |
|
|
237 |
KeyType CollatedKey5(0,C,5);
|
|
238 |
KeyType CollatedKey6(0,C,6);
|
|
239 |
KeyType CollatedKey7(0,C,7);
|
|
240 |
KeyType CollatedKeyOffset(sizeof(S)*3,C,2);
|
|
241 |
|
|
242 |
TInt pos;
|
|
243 |
test(pArray->Find(*(S(*))_TL("aa cc"), NormalKey5, pos)==0);
|
|
244 |
test(pos==0);
|
|
245 |
test(pArray->Find(*(S(*))_TL("bb bbb"), NormalKey6, pos)==0);
|
|
246 |
test(pos==1);
|
|
247 |
test(pArray->Find(*(S(*))_TL("cc aaaa"), NormalKey7, pos)==0);
|
|
248 |
test(pos==2);
|
|
249 |
test(pArray->Find(*(S(*))_TL("BB BB"), NormalKey5, pos)!=0);
|
|
250 |
|
|
251 |
|
|
252 |
test(pArray->Find(*(S(*))_TL("___cc"), NormalKeyOffset, pos)==0);
|
|
253 |
test(pos==0);
|
|
254 |
test(pArray->Find(*(S(*))_TL("___bb"), NormalKeyOffset, pos)==0);
|
|
255 |
test(pos==1);
|
|
256 |
test(pArray->Find(*(S(*))_TL("___aa"), NormalKeyOffset, pos)==0);
|
|
257 |
test(pos==2);
|
|
258 |
test(pArray->Find(*(S(*))_TL("___ax"), NormalKeyOffset, pos)!=0);
|
|
259 |
|
|
260 |
|
|
261 |
test(pArray->Find(*(S(*))_TL("aa cc"), FoldedKey5, pos)==0);
|
|
262 |
test(pos==0);
|
|
263 |
test(pArray->Find(*(S(*))_TL("bb bbb"), FoldedKey6, pos)==0);
|
|
264 |
test(pos==1);
|
|
265 |
test(pArray->Find(*(S(*))_TL("cc aaaa"), FoldedKey7, pos)==0);
|
|
266 |
test(pos==2);
|
|
267 |
|
|
268 |
|
|
269 |
test(pArray->Find(*(S(*))_TL("___CC"), FoldedKeyOffset, pos)==0);
|
|
270 |
test(pos==0);
|
|
271 |
test(pArray->Find(*(S(*))_TL("___bB"), FoldedKeyOffset, pos)==0);
|
|
272 |
test(pos==1);
|
|
273 |
test(pArray->Find(*(S(*))_TL("___Aa"), FoldedKeyOffset, pos)==0);
|
|
274 |
test(pos==2);
|
|
275 |
test(pArray->Find(*(S(*))_TL("___ax"), FoldedKeyOffset, pos)!=0);
|
|
276 |
|
|
277 |
|
|
278 |
test(pArray->Find(*(S(*))_TL("aa cc"), CollatedKey5, pos)==0);
|
|
279 |
test(pos==0);
|
|
280 |
test(pArray->Find(*(S(*))_TL("bb bbb"), CollatedKey6, pos)==0);
|
|
281 |
test(pos==1);
|
|
282 |
test(pArray->Find(*(S(*))_TL("cc aaaa"), CollatedKey7, pos)==0);
|
|
283 |
test(pos==2);
|
|
284 |
|
|
285 |
|
|
286 |
test(pArray->Find(*(S(*))_TL("___cc"), CollatedKeyOffset, pos)==0);
|
|
287 |
test(pos==0);
|
|
288 |
test(pArray->Find(*(S(*))_TL("___bb"), CollatedKeyOffset, pos)==0);
|
|
289 |
test(pos==1);
|
|
290 |
test(pArray->Find(*(S(*))_TL("___aa"), CollatedKeyOffset, pos)==0);
|
|
291 |
test(pos==2);
|
|
292 |
test(pArray->Find(*(S(*))_TL("___ax"), CollatedKeyOffset, pos)!=0);
|
|
293 |
|
|
294 |
delete pArray;
|
|
295 |
}
|
|
296 |
|
|
297 |
|
|
298 |
template<class KeyType, class ArrayType, class S>
|
|
299 |
GLDEF_C void TestTKey<KeyType, ArrayType, S>::Test3(void)
|
|
300 |
{
|
|
301 |
ArrayType* pArray=new ArrayType(KTestGranularity);
|
|
302 |
Record rec1, rec2, rec3;
|
|
303 |
|
|
304 |
rec1.name=(_TL("fred"));
|
|
305 |
rec1.age=5;
|
|
306 |
rec1.code='A';
|
|
307 |
|
|
308 |
rec2.name=(_TL("bill"));
|
|
309 |
rec2.age=0x7fffffff;
|
|
310 |
rec2.code='Z';
|
|
311 |
|
|
312 |
rec3.name=(_TL("bert"));
|
|
313 |
rec3.age=-5;
|
|
314 |
rec3.code='X';
|
|
315 |
|
|
316 |
pArray->AppendL(rec1);
|
|
317 |
pArray->AppendL(rec2);
|
|
318 |
pArray->AppendL(rec3);
|
|
319 |
|
|
320 |
TInt pos;
|
|
321 |
|
|
322 |
KeyType codekey(_FOFF(Record, code),ECmpNormal,1);
|
|
323 |
test(pArray->Find(rec1, codekey, pos)==0);
|
|
324 |
test(pos==0);
|
|
325 |
test(pArray->Find(rec2, codekey, pos)==0);
|
|
326 |
test(pos==1);
|
|
327 |
test(pArray->Find(rec3, codekey, pos)==0);
|
|
328 |
test(pos==2);
|
|
329 |
|
|
330 |
KeyType agekey(_FOFF(Record, age), ECmpTInt32);
|
|
331 |
test(pArray->Find(rec1, agekey, pos)==0);
|
|
332 |
test(pos==0);
|
|
333 |
test(pArray->Find(rec2, agekey, pos)==0);
|
|
334 |
test(pos==1);
|
|
335 |
test(pArray->Find(rec3, agekey, pos)==0);
|
|
336 |
test(pos==2);
|
|
337 |
|
|
338 |
rec1.age=-50; // march 95 - this isn't allowed , lucky that it works
|
|
339 |
test(pArray->Find(rec1, agekey, pos)!=0);
|
|
340 |
rec1.age=5;
|
|
341 |
|
|
342 |
pArray->Sort(agekey);
|
|
343 |
test(pArray->Find(rec1, agekey, pos)==0);
|
|
344 |
test(pos==1);
|
|
345 |
test(pArray->Find(rec2, agekey, pos)==0);
|
|
346 |
test(pos==2);
|
|
347 |
test(pArray->Find(rec3, agekey, pos)==0);
|
|
348 |
test(pos==0);
|
|
349 |
|
|
350 |
delete pArray;
|
|
351 |
}
|
|
352 |
|
|
353 |
template<class KeyType, class ArrayType, class S>
|
|
354 |
GLDEF_C void TestTKey<KeyType, ArrayType, S>::Test4(void)
|
|
355 |
{
|
|
356 |
ArrayType* pArray=new ArrayType(KTestGranularity);
|
|
357 |
Record rec1, rec2, rec3;
|
|
358 |
|
|
359 |
rec1.name=(_TL("fred"));
|
|
360 |
rec1.age=5;
|
|
361 |
rec1.code='A';
|
|
362 |
rec2.name=(_TL("bill"));
|
|
363 |
rec2.age=0x7fffffff;
|
|
364 |
rec2.code='Z';
|
|
365 |
rec3.name=(_TL("bert"));
|
|
366 |
rec3.age=-5;
|
|
367 |
rec3.code='X';
|
|
368 |
|
|
369 |
pArray->AppendL(rec1, sizeof(Record));
|
|
370 |
pArray->AppendL(rec2, sizeof(Record));
|
|
371 |
pArray->AppendL(rec3, sizeof(Record));
|
|
372 |
|
|
373 |
TInt pos;
|
|
374 |
KeyType codekey(_FOFF(Record, code),ECmpNormal,1);
|
|
375 |
test(pArray->Find(rec1, codekey, pos)==0);
|
|
376 |
test(pos==0);
|
|
377 |
test(pArray->Find(rec2, codekey, pos)==0);
|
|
378 |
test(pos==1);
|
|
379 |
test(pArray->Find(rec3, codekey, pos)==0);
|
|
380 |
test(pos==2);
|
|
381 |
|
|
382 |
KeyType agekey(_FOFF(Record, age), ECmpTInt32);
|
|
383 |
test(pArray->Find(rec1, agekey, pos)==0);
|
|
384 |
test(pos==0);
|
|
385 |
test(pArray->Find(rec2, agekey, pos)==0);
|
|
386 |
test(pos==1);
|
|
387 |
test(pArray->Find(rec3, agekey, pos)==0);
|
|
388 |
test(pos==2);
|
|
389 |
rec1.age=-50; // march 95 - this isn't allowed - lucky to get away with it
|
|
390 |
test(pArray->Find(rec1, agekey, pos)!=0);
|
|
391 |
rec1.age=5;
|
|
392 |
|
|
393 |
pArray->Sort(agekey);
|
|
394 |
test(pArray->Find(rec1, agekey, pos)==0);
|
|
395 |
test(pos==1);
|
|
396 |
test(pArray->Find(rec2, agekey, pos)==0);
|
|
397 |
test(pos==2);
|
|
398 |
test(pArray->Find(rec3, agekey, pos)==0);
|
|
399 |
test(pos==0);
|
|
400 |
|
|
401 |
delete pArray;
|
|
402 |
}
|
|
403 |
|
|
404 |
template<class KeyType, class ArrayType, class S>
|
|
405 |
GLDEF_C void TestTKey<KeyType, ArrayType, S>::Test5(void)
|
|
406 |
{
|
|
407 |
// test the numeric enumeration types
|
|
408 |
ArrayType* pArray=new ArrayType(KTestGranularity);
|
|
409 |
TInt pos;
|
|
410 |
|
|
411 |
KeyType TIntKey(_FOFF(Record2, tint), ECmpTInt);
|
|
412 |
KeyType TUintKey(_FOFF(Record2, tuint), ECmpTUint);
|
|
413 |
KeyType TInt8Key(_FOFF(Record2, tint8), ECmpTInt8);
|
|
414 |
KeyType TUint8Key(_FOFF(Record2, tuint8), ECmpTUint8);
|
|
415 |
KeyType TInt16Key(_FOFF(Record2, tint16), ECmpTInt16);
|
|
416 |
KeyType TUint16Key(_FOFF(Record2, tuint16), ECmpTUint16);
|
|
417 |
KeyType TInt32Key(_FOFF(Record2, tint32), ECmpTInt32);
|
|
418 |
KeyType TUint32Key(_FOFF(Record2, tuint32), ECmpTUint32);
|
|
419 |
|
|
420 |
SetRecordData();
|
|
421 |
|
|
422 |
pArray->AppendL(Rec1);
|
|
423 |
pArray->AppendL(Rec2);
|
|
424 |
pArray->AppendL(Rec3);
|
|
425 |
pArray->AppendL(Rec4);
|
|
426 |
|
|
427 |
pArray->Sort(TIntKey);
|
|
428 |
// order should be 4,3,2,1
|
|
429 |
test(pArray->Find(Rec4, TIntKey, pos)==0);
|
|
430 |
test(pos==0);
|
|
431 |
test(pArray->Find(Rec3, TIntKey, pos)==0);
|
|
432 |
test(pos==1);
|
|
433 |
test(pArray->Find(Rec2, TIntKey, pos)==0);
|
|
434 |
test(pos==2);
|
|
435 |
test(pArray->Find(Rec1, TIntKey, pos)==0);
|
|
436 |
test(pos==3);
|
|
437 |
|
|
438 |
pArray->Sort(TUintKey);
|
|
439 |
// order should be 1,2,3,4
|
|
440 |
test(pArray->Find(Rec1, TUintKey, pos)==0);
|
|
441 |
test(pos==0);
|
|
442 |
test(pArray->Find(Rec2, TUintKey, pos)==0);
|
|
443 |
test(pos==1);
|
|
444 |
test(pArray->Find(Rec3, TUintKey, pos)==0);
|
|
445 |
test(pos==2);
|
|
446 |
test(pArray->Find(Rec4, TUintKey, pos)==0);
|
|
447 |
test(pos==3);
|
|
448 |
|
|
449 |
pArray->Sort(TInt8Key);
|
|
450 |
// order should be 4,3,2,1
|
|
451 |
test(pArray->Find(Rec4, TInt8Key, pos)==0);
|
|
452 |
test(pos==0);
|
|
453 |
test(pArray->Find(Rec3, TInt8Key, pos)==0);
|
|
454 |
test(pos==1);
|
|
455 |
test(pArray->Find(Rec2, TInt8Key, pos)==0);
|
|
456 |
test(pos==2);
|
|
457 |
test(pArray->Find(Rec1, TInt8Key, pos)==0);
|
|
458 |
test(pos==3);
|
|
459 |
|
|
460 |
pArray->Sort(TUint8Key);
|
|
461 |
// order should be 1,2,3,4
|
|
462 |
test(pArray->Find(Rec1, TUint8Key, pos)==0);
|
|
463 |
test(pos==0);
|
|
464 |
test(pArray->Find(Rec2, TUint8Key, pos)==0);
|
|
465 |
test(pos==1);
|
|
466 |
test(pArray->Find(Rec3, TUint8Key, pos)==0);
|
|
467 |
test(pos==2);
|
|
468 |
test(pArray->Find(Rec4, TUint8Key, pos)==0);
|
|
469 |
test(pos==3);
|
|
470 |
|
|
471 |
pArray->Sort(TInt16Key);
|
|
472 |
// order should be 4,3,2,1
|
|
473 |
test(pArray->Find(Rec4, TInt16Key, pos)==0);
|
|
474 |
test(pos==0);
|
|
475 |
test(pArray->Find(Rec3, TInt16Key, pos)==0);
|
|
476 |
test(pos==1);
|
|
477 |
test(pArray->Find(Rec2, TInt16Key, pos)==0);
|
|
478 |
test(pos==2);
|
|
479 |
test(pArray->Find(Rec1, TInt16Key, pos)==0);
|
|
480 |
test(pos==3);
|
|
481 |
|
|
482 |
pArray->Sort(TUintKey);
|
|
483 |
// order should be 1,2,3,4
|
|
484 |
test(pArray->Find(Rec1, TUint16Key, pos)==0);
|
|
485 |
test(pos==0);
|
|
486 |
test(pArray->Find(Rec2, TUint16Key, pos)==0);
|
|
487 |
test(pos==1);
|
|
488 |
test(pArray->Find(Rec3, TUint16Key, pos)==0);
|
|
489 |
test(pos==2);
|
|
490 |
test(pArray->Find(Rec4, TUint16Key, pos)==0);
|
|
491 |
test(pos==3);
|
|
492 |
|
|
493 |
pArray->Sort(TInt32Key);
|
|
494 |
// order should be 4,3,2,1
|
|
495 |
test(pArray->Find(Rec4, TInt32Key, pos)==0);
|
|
496 |
test(pos==0);
|
|
497 |
test(pArray->Find(Rec3, TInt32Key, pos)==0);
|
|
498 |
test(pos==1);
|
|
499 |
test(pArray->Find(Rec2, TInt32Key, pos)==0);
|
|
500 |
test(pos==2);
|
|
501 |
test(pArray->Find(Rec1, TInt32Key, pos)==0);
|
|
502 |
test(pos==3);
|
|
503 |
|
|
504 |
pArray->Sort(TUint32Key);
|
|
505 |
// order should be 1,2,3,4
|
|
506 |
test(pArray->Find(Rec1, TUint32Key, pos)==0);
|
|
507 |
test(pos==0);
|
|
508 |
test(pArray->Find(Rec2, TUint32Key, pos)==0);
|
|
509 |
test(pos==1);
|
|
510 |
test(pArray->Find(Rec3, TUint32Key, pos)==0);
|
|
511 |
test(pos==2);
|
|
512 |
test(pArray->Find(Rec4, TUint32Key, pos)==0);
|
|
513 |
test(pos==3);
|
|
514 |
|
|
515 |
delete pArray;
|
|
516 |
}
|
|
517 |
|
|
518 |
template<class KeyType, class ArrayType, class S>
|
|
519 |
GLDEF_C void TestTKey<KeyType, ArrayType, S>::Test6(void)
|
|
520 |
{
|
|
521 |
// test the numeric enumeration types
|
|
522 |
ArrayType* pArray=new ArrayType(KTestGranularity);
|
|
523 |
TInt pos;
|
|
524 |
|
|
525 |
KeyType TIntKey(_FOFF(Record2, tint), ECmpTInt);
|
|
526 |
KeyType TUintKey(_FOFF(Record2, tuint), ECmpTUint);
|
|
527 |
KeyType TInt8Key(_FOFF(Record2, tint8), ECmpTInt8);
|
|
528 |
KeyType TUint8Key(_FOFF(Record2, tuint8), ECmpTUint8);
|
|
529 |
KeyType TInt16Key(_FOFF(Record2, tint16), ECmpTInt16);
|
|
530 |
KeyType TUint16Key(_FOFF(Record2, tuint16), ECmpTUint16);
|
|
531 |
KeyType TInt32Key(_FOFF(Record2, tint32), ECmpTInt32);
|
|
532 |
KeyType TUint32Key(_FOFF(Record2, tuint32), ECmpTUint32);
|
|
533 |
|
|
534 |
SetRecordData();
|
|
535 |
|
|
536 |
pArray->AppendL(Rec1, sizeof(Record2));
|
|
537 |
pArray->AppendL(Rec2, sizeof(Record2));
|
|
538 |
pArray->AppendL(Rec3, sizeof(Record2));
|
|
539 |
pArray->AppendL(Rec4, sizeof(Record2));
|
|
540 |
|
|
541 |
pArray->Sort(TIntKey);
|
|
542 |
// order should be 4,3,2,1
|
|
543 |
test(pArray->Find(Rec4, TIntKey, pos)==0);
|
|
544 |
test(pos==0);
|
|
545 |
test(pArray->Find(Rec3, TIntKey, pos)==0);
|
|
546 |
test(pos==1);
|
|
547 |
test(pArray->Find(Rec2, TIntKey, pos)==0);
|
|
548 |
test(pos==2);
|
|
549 |
test(pArray->Find(Rec1, TIntKey, pos)==0);
|
|
550 |
test(pos==3);
|
|
551 |
|
|
552 |
pArray->Sort(TUintKey);
|
|
553 |
// order should be 1,2,3,4
|
|
554 |
test(pArray->Find(Rec1, TUintKey, pos)==0);
|
|
555 |
test(pos==0);
|
|
556 |
test(pArray->Find(Rec2, TUintKey, pos)==0);
|
|
557 |
test(pos==1);
|
|
558 |
test(pArray->Find(Rec3, TUintKey, pos)==0);
|
|
559 |
test(pos==2);
|
|
560 |
test(pArray->Find(Rec4, TUintKey, pos)==0);
|
|
561 |
test(pos==3);
|
|
562 |
|
|
563 |
pArray->Sort(TInt8Key);
|
|
564 |
// order should be 4,3,2,1
|
|
565 |
test(pArray->Find(Rec4, TInt8Key, pos)==0);
|
|
566 |
test(pos==0);
|
|
567 |
test(pArray->Find(Rec3, TInt8Key, pos)==0);
|
|
568 |
test(pos==1);
|
|
569 |
test(pArray->Find(Rec2, TInt8Key, pos)==0);
|
|
570 |
test(pos==2);
|
|
571 |
test(pArray->Find(Rec1, TInt8Key, pos)==0);
|
|
572 |
test(pos==3);
|
|
573 |
|
|
574 |
pArray->Sort(TUint8Key);
|
|
575 |
// order should be 1,2,3,4
|
|
576 |
test(pArray->Find(Rec1, TUint8Key, pos)==0);
|
|
577 |
test(pos==0);
|
|
578 |
test(pArray->Find(Rec2, TUint8Key, pos)==0);
|
|
579 |
test(pos==1);
|
|
580 |
test(pArray->Find(Rec3, TUint8Key, pos)==0);
|
|
581 |
test(pos==2);
|
|
582 |
test(pArray->Find(Rec4, TUint8Key, pos)==0);
|
|
583 |
test(pos==3);
|
|
584 |
|
|
585 |
pArray->Sort(TInt16Key);
|
|
586 |
// order should be 4,3,2,1
|
|
587 |
test(pArray->Find(Rec4, TInt16Key, pos)==0);
|
|
588 |
test(pos==0);
|
|
589 |
test(pArray->Find(Rec3, TInt16Key, pos)==0);
|
|
590 |
test(pos==1);
|
|
591 |
test(pArray->Find(Rec2, TInt16Key, pos)==0);
|
|
592 |
test(pos==2);
|
|
593 |
test(pArray->Find(Rec1, TInt16Key, pos)==0);
|
|
594 |
test(pos==3);
|
|
595 |
|
|
596 |
pArray->Sort(TUintKey);
|
|
597 |
// order should be 1,2,3,4
|
|
598 |
test(pArray->Find(Rec1, TUint16Key, pos)==0);
|
|
599 |
test(pos==0);
|
|
600 |
test(pArray->Find(Rec2, TUint16Key, pos)==0);
|
|
601 |
test(pos==1);
|
|
602 |
test(pArray->Find(Rec3, TUint16Key, pos)==0);
|
|
603 |
test(pos==2);
|
|
604 |
test(pArray->Find(Rec4, TUint16Key, pos)==0);
|
|
605 |
test(pos==3);
|
|
606 |
|
|
607 |
pArray->Sort(TInt32Key);
|
|
608 |
// order should be 4,3,2,1
|
|
609 |
test(pArray->Find(Rec4, TInt32Key, pos)==0);
|
|
610 |
test(pos==0);
|
|
611 |
test(pArray->Find(Rec3, TInt32Key, pos)==0);
|
|
612 |
test(pos==1);
|
|
613 |
test(pArray->Find(Rec2, TInt32Key, pos)==0);
|
|
614 |
test(pos==2);
|
|
615 |
test(pArray->Find(Rec1, TInt32Key, pos)==0);
|
|
616 |
test(pos==3);
|
|
617 |
|
|
618 |
pArray->Sort(TUint32Key);
|
|
619 |
// order should be 1,2,3,4
|
|
620 |
test(pArray->Find(Rec1, TUint32Key, pos)==0);
|
|
621 |
test(pos==0);
|
|
622 |
test(pArray->Find(Rec2, TUint32Key, pos)==0);
|
|
623 |
test(pos==1);
|
|
624 |
test(pArray->Find(Rec3, TUint32Key, pos)==0);
|
|
625 |
test(pos==2);
|
|
626 |
test(pArray->Find(Rec4, TUint32Key, pos)==0);
|
|
627 |
test(pos==3);
|
|
628 |
|
|
629 |
delete pArray;
|
|
630 |
}
|
|
631 |
|
|
632 |
GLDEF_C TInt E32Main()
|
|
633 |
{
|
|
634 |
|
|
635 |
test.Title();
|
|
636 |
test.Start(_L("Fixed key class with a flat array of TText8"));
|
|
637 |
typedef CArrayFixFlat<TArr<TText8,5> > aFixedFlatArrayOfTText8;
|
|
638 |
TestTKey<TKeyArrayFix, aFixedFlatArrayOfTText8, TText8> T1;
|
|
639 |
T1.Test1(ECmpNormal8, ECmpFolded8, ECmpCollated8);
|
|
640 |
|
|
641 |
test.Next(_L("Fixed key class with a flat array of TText16"));
|
|
642 |
typedef CArrayFixFlat<TArr<TText16,5> > aFixedFlatArrayOfTText16;
|
|
643 |
TestTKey<TKeyArrayFix, aFixedFlatArrayOfTText16, TText16> T2;
|
|
644 |
T2.Test1(ECmpNormal16, ECmpFolded16, ECmpCollated16);
|
|
645 |
|
|
646 |
test.Next(_L("Fixed key class with a flat array of TText"));
|
|
647 |
typedef CArrayFixFlat<TArr<TText,5> > aFixedFlatArrayOfTText;
|
|
648 |
TestTKey<TKeyArrayFix, aFixedFlatArrayOfTText, TText> T3;
|
|
649 |
T3.Test1(ECmpNormal, ECmpFolded, ECmpCollated);
|
|
650 |
|
|
651 |
test.Next(_L("Fixed key class with a segmented array of TText8"));
|
|
652 |
typedef CArrayFixSeg<TArr<TText8,5> > aFixedSegmentedArrayOfTText8;
|
|
653 |
TestTKey<TKeyArrayFix, aFixedSegmentedArrayOfTText8, TText8> T4;
|
|
654 |
T4.Test1(ECmpNormal8, ECmpFolded8, ECmpCollated8);
|
|
655 |
|
|
656 |
test.Next(_L("Fixed key class with a segmented array of TText16"));
|
|
657 |
typedef CArrayFixSeg<TArr<TText16,5> > aFixedSegmentedArrayOfTText16;
|
|
658 |
TestTKey<TKeyArrayFix, aFixedSegmentedArrayOfTText16, TText16> T5;
|
|
659 |
T5.Test1(ECmpNormal16, ECmpFolded16, ECmpCollated16);
|
|
660 |
|
|
661 |
test.Next(_L("Fixed key class with a segmented array of TText"));
|
|
662 |
typedef CArrayFixSeg<TArr<TText,5> > aFixedSegmentedArrayOfTText;
|
|
663 |
TestTKey<TKeyArrayFix, aFixedSegmentedArrayOfTText, TText> T6;
|
|
664 |
T6.Test1(ECmpNormal, ECmpFolded, ECmpCollated);
|
|
665 |
|
|
666 |
test.Next(_L("Var key with a flat array of TText8"));
|
|
667 |
typedef CArrayVarFlat<TText8> aVarFlatArrayOfTText8;
|
|
668 |
TestTKey<TKeyArrayVar, aVarFlatArrayOfTText8, TText8> T7;
|
|
669 |
T7.Test2(ECmpNormal8, ECmpFolded8, ECmpCollated8);
|
|
670 |
|
|
671 |
test.Next(_L("Var key with a flat array of TText16"));
|
|
672 |
typedef CArrayVarFlat<TText16> aVarFlatArrayOfTText16;
|
|
673 |
TestTKey<TKeyArrayVar, aVarFlatArrayOfTText16, TText16> T8;
|
|
674 |
T8.Test2(ECmpNormal16, ECmpFolded16, ECmpCollated16);
|
|
675 |
|
|
676 |
test.Next(_L("Var key with a flat array of TText"));
|
|
677 |
typedef CArrayVarFlat<TText> aVarFlatArrayOfTText;
|
|
678 |
TestTKey<TKeyArrayVar, aVarFlatArrayOfTText, TText> T9;
|
|
679 |
T9.Test2(ECmpNormal, ECmpFolded, ECmpCollated);
|
|
680 |
|
|
681 |
test.Next(_L("Var key with a segmented array of TText8"));
|
|
682 |
typedef CArrayVarSeg<TText8> aVarSegmentedArrayOfTText8;
|
|
683 |
TestTKey<TKeyArrayVar, aVarSegmentedArrayOfTText8, TText8> T10;
|
|
684 |
T10.Test2(ECmpNormal8, ECmpFolded8, ECmpCollated8);
|
|
685 |
|
|
686 |
test.Next(_L("Var key with a segmented array of TText16"));
|
|
687 |
typedef CArrayVarSeg<TText16> aVarSegmentedArrayOfTText16;
|
|
688 |
TestTKey<TKeyArrayVar, aVarSegmentedArrayOfTText16, TText16> T11;
|
|
689 |
T11.Test2(ECmpNormal16, ECmpFolded16, ECmpCollated16);
|
|
690 |
|
|
691 |
test.Next(_L("Var key with a segmented array of TText"));
|
|
692 |
typedef CArrayVarSeg<TText> aVarSegmentedArrayOfTText;
|
|
693 |
TestTKey<TKeyArrayVar, aVarSegmentedArrayOfTText, TText> T12;
|
|
694 |
T12.Test2(ECmpNormal, ECmpFolded, ECmpCollated);
|
|
695 |
|
|
696 |
test.Next(_L("Fixed key with a flat array of structs"));
|
|
697 |
typedef CArrayFixFlat<Record> aFixedFlatArrayOfRecord;
|
|
698 |
TestTKey<TKeyArrayFix, aFixedFlatArrayOfRecord, TText> T13;
|
|
699 |
T13.Test3();
|
|
700 |
|
|
701 |
test.Next(_L("Fixed key with a segmented array of structs"));
|
|
702 |
typedef CArrayFixSeg<Record> aFixedSegmentedArrayOfRecord;
|
|
703 |
TestTKey<TKeyArrayFix, aFixedSegmentedArrayOfRecord, TText> T14;
|
|
704 |
T14.Test3();
|
|
705 |
|
|
706 |
test.Next(_L("Var key with a flat array of structs"));
|
|
707 |
typedef CArrayVarFlat<Record> aVarFlatArrayOfRecord;
|
|
708 |
TestTKey<TKeyArrayVar, aVarFlatArrayOfRecord, TText> T15;
|
|
709 |
T15.Test4();
|
|
710 |
|
|
711 |
test.Next(_L("Var key with a segmented array of structs"));
|
|
712 |
typedef CArrayVarSeg<Record> aVarSegmentedArrayOfRecord;
|
|
713 |
TestTKey<TKeyArrayVar, aVarSegmentedArrayOfRecord, TText> T16;
|
|
714 |
T16.Test4();
|
|
715 |
|
|
716 |
test.Next(_L("Fixed key with a flat array of structs testing numeric types"));
|
|
717 |
typedef CArrayFixFlat<Record2> aFixedFlatArrayOfRecord2;
|
|
718 |
TestTKey<TKeyArrayFix, aFixedFlatArrayOfRecord2, TText> T17;
|
|
719 |
T17.Test5();
|
|
720 |
|
|
721 |
test.Next(_L("Var key with a flat array of structs testing numeric types"));
|
|
722 |
typedef CArrayVarFlat<Record2> aVarFlatArrayOfRecord2;
|
|
723 |
TestTKey<TKeyArrayVar, aVarFlatArrayOfRecord2, TText> T18;
|
|
724 |
T18.Test6();
|
|
725 |
test.End();
|
|
726 |
return(KErrNone);
|
|
727 |
}
|
|
728 |
|
|
729 |
/*#else
|
|
730 |
GLDEF_C TInt E32Main()
|
|
731 |
//
|
|
732 |
// Test unavailable in release build.
|
|
733 |
//
|
|
734 |
{
|
|
735 |
|
|
736 |
test.Title();
|
|
737 |
test.Start(_L("No tests for release builds"));
|
|
738 |
test.End();
|
|
739 |
return(0);
|
|
740 |
}
|
|
741 |
#endif
|
|
742 |
|
|
743 |
*/
|
|
744 |
|