1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/buffer/t_key.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,744 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\buffer\t_key.cpp
1.18 +// Overview:
1.19 +// Test arrays keys against flat and segmented arrays of characters (8 and 16 bit) and records.
1.20 +// API Information:
1.21 +// TKeyArrayFix, TKeyArrayVar.
1.22 +// Details:
1.23 +// - Create flat and segmented array of TText8, TText16, TText. Append some text to the
1.24 +// arrays and test the functions of the TKeyArrayFix class using the Find method which
1.25 +// calls SetPtr, Set, Compare methods with ECmpNormal8, ECmpFolded8, ECmpCollated8,
1.26 +// ECmpNormal16, ECmpFolded16, ECmpCollated16, ECmpNormal, ECmpFolded, ECmpCollated key types.
1.27 +// - Test the functions of the TKeyArrayVar class using the Find method which calls SetPtr, Set,
1.28 +// Compare methods with ECmpNormal8, ECmpFolded8, ECmpCollated8, ECmpNormal16, ECmpFolded16,
1.29 +// ECmpCollated16, ECmpNormal, ECmpFolded, ECmpCollated key types.
1.30 +// - Create flat and segmented array of TText, append some structures with different values.
1.31 +// - Test the functions of the TKeyArrayFix, TKeyArrayVar classes by searching the values using
1.32 +// sequential search technique with ECmpNormal, ECmpTInt32 key type and verifying that it is
1.33 +// found at correct position.
1.34 +// - For TKeyArrayFix and TKeyArrayVar class, create a flat array of TText, append some structures
1.35 +// with different numeric values, sort the array, search the values using ECmpTInt, ECmpTUint,
1.36 +// ECmpTint8, ECmpTUint8, ECmpTint16, ECmpTUint16, ECmpTint32, ECmpTUint32 key types and verify
1.37 +// that values are found in order as expected.
1.38 +// Platforms/Drives/Compatibility:
1.39 +// All
1.40 +// Assumptions/Requirement/Pre-requisites:
1.41 +// Failures and causes:
1.42 +// Base Port information:
1.43 +//
1.44 +//
1.45 +
1.46 +#include <e32std.h>
1.47 +#include <e32std_private.h>
1.48 +#include <e32base.h>
1.49 +#include <e32base_private.h>
1.50 +#include <e32test.h>
1.51 +#include <e32svr.h>
1.52 +#include <e32ver.h>
1.53 +
1.54 +#ifdef __VC32__
1.55 +#pragma warning (disable:4710) // Function not expanded
1.56 +#pragma warning (disable:4702) // Unreachable code
1.57 +#endif
1.58 +
1.59 +const TInt KTestGranularity=0x02;
1.60 +
1.61 +LOCAL_D RTest test(_L("T_KEY"));
1.62 +
1.63 +template <class T,TInt S>
1.64 +class TArr
1.65 + {
1.66 +public:
1.67 + TArr() {}
1.68 + TInt Count() const {return S;}
1.69 + T& operator[](TInt anIndex) {return iArr[anIndex];}
1.70 + const T& operator[](TInt anIndex) const {return iArr[anIndex];}
1.71 +private:
1.72 + T iArr[S];
1.73 + };
1.74 +
1.75 +//#if defined(_DEBUG)
1.76 +struct Record
1.77 + {
1.78 + TBuf<0x10> name;
1.79 + TInt32 age;
1.80 + TText8 code;
1.81 + };
1.82 +
1.83 +struct Record2
1.84 + {
1.85 + TInt tint;
1.86 + TUint tuint;
1.87 + TInt8 tint8;
1.88 + TUint8 tuint8;
1.89 + TInt16 tint16;
1.90 + TUint16 tuint16;
1.91 + TInt32 tint32;
1.92 + TUint32 tuint32;
1.93 + }Rec1, Rec2, Rec3, Rec4;
1.94 +
1.95 +LOCAL_C void SetRecordData(void)
1.96 + {
1.97 + Rec1.tint=KMaxTInt;
1.98 + Rec2.tint=0;
1.99 + Rec3.tint=-KMaxTInt;
1.100 + Rec4.tint=KMinTInt;
1.101 + Rec1.tint8=KMaxTInt8;
1.102 + Rec2.tint8=0;
1.103 + Rec3.tint8=-KMaxTInt8;
1.104 + Rec4.tint8=(TInt8)KMinTInt8;
1.105 + Rec1.tint16=KMaxTInt16;
1.106 + Rec2.tint16=0;
1.107 + Rec3.tint16=-KMaxTInt16;
1.108 + Rec4.tint16=(TInt16)KMinTInt16;
1.109 + Rec1.tint32=KMaxTInt32;
1.110 + Rec2.tint32=0;
1.111 + Rec3.tint32=-KMaxTInt32;
1.112 + Rec4.tint32=(TInt32)KMinTInt32;
1.113 + Rec1.tuint=0;
1.114 + Rec2.tuint=1;
1.115 + Rec3.tuint=KMaxTUint-1;
1.116 + Rec4.tuint=KMaxTUint;
1.117 + Rec1.tuint8=0;
1.118 + Rec2.tuint8=1;
1.119 + Rec3.tuint8=(TUint8)(KMaxTUint8-1);
1.120 + Rec4.tuint8=(TUint8)KMaxTUint8;
1.121 + Rec1.tuint16=0;
1.122 + Rec2.tuint16=1;
1.123 + Rec3.tuint16=(TUint16)(KMaxTUint16-1);
1.124 + Rec4.tuint16=(TUint16)KMaxTUint16;
1.125 + Rec1.tuint32=0;
1.126 + Rec2.tuint32=1;
1.127 + Rec3.tuint32=(TUint32)(KMaxTUint32-1);
1.128 + Rec4.tuint32=KMaxTUint32;
1.129 + }
1.130 +
1.131 +typedef enum {eEight, eSixteen} TMode;
1.132 +
1.133 +template<class KeyType, class ArrayType, class S> // S is TText8, TTExt etc. called S as _TL requires S in e32test.h
1.134 +class TestTKey
1.135 + {
1.136 +public:
1.137 + void Test1(TKeyCmpText, TKeyCmpText, TKeyCmpText);
1.138 + void Test2(TKeyCmpText, TKeyCmpText, TKeyCmpText);
1.139 + void Test3(void);
1.140 + void Test4(void);
1.141 + void Test5(void);
1.142 + void Test6(void);
1.143 + };
1.144 +
1.145 +template<class KeyType, class ArrayType, class S>
1.146 +GLDEF_C void TestTKey<KeyType, ArrayType, S>::Test1(TKeyCmpText N, TKeyCmpText F, TKeyCmpText C)
1.147 + {
1.148 + // This tests the functions of the TKey classes indirectly - mostly using the Find method
1.149 + // which calls SetPtr(), Set() (both trivial) and more importantly Compare(),
1.150 +
1.151 + ArrayType* pArray=new ArrayType(KTestGranularity);
1.152 + pArray->AppendL(*(const TArr<S,5>*)_TL("aa cc"));
1.153 + pArray->AppendL(*(const TArr<S,5>*)_TL("bb bb"));
1.154 + pArray->AppendL(*(const TArr<S,5>*)_TL("cc aa"));
1.155 +
1.156 + KeyType NormalKey(0,N,5);
1.157 + KeyType NormalKeyOffset(sizeof(S)*3,N,2) ;
1.158 + KeyType FoldedKey(0,F,5);
1.159 + KeyType FoldedKeyOffset(sizeof(S)*3,F,2);
1.160 + KeyType CollatedKey(0,C,5);
1.161 + KeyType CollatedKeyOffset(sizeof(S)*3,C,2);
1.162 +
1.163 + TInt pos;
1.164 + test(pArray->Find(*(const TArr<S,5>*)_TL("aa cc"), NormalKey, pos)==0);
1.165 + test(pos==0);
1.166 + test(pArray->Find(*(const TArr<S,5>*)_TL("bb bb"), NormalKey, pos)==0);
1.167 + test(pos==1);
1.168 + test(pArray->Find(*(const TArr<S,5>*)_TL("cc aa"), NormalKey, pos)==0);
1.169 + test(pos==2);
1.170 + test(pArray->Find(*(const TArr<S,5>*)_TL("BB BB"), NormalKey, pos)!=0);
1.171 +
1.172 +
1.173 + test(pArray->Find(*(const TArr<S,5>*)_TL("___cc"), NormalKeyOffset, pos)==0);
1.174 + test(pos==0);
1.175 + test(pArray->Find(*(const TArr<S,5>*)_TL("___bb"), NormalKeyOffset, pos)==0);
1.176 + test(pos==1);
1.177 + test(pArray->Find(*(const TArr<S,5>*)_TL("___aa"), NormalKeyOffset, pos)==0);
1.178 + test(pos==2);
1.179 + test(pArray->Find(*(const TArr<S,5>*)_TL("___ax"), NormalKeyOffset, pos)!=0);
1.180 +
1.181 +
1.182 + test(pArray->Find(*(const TArr<S,5>*)_TL("aa cc"), FoldedKey, pos)==0);
1.183 + test(pos==0);
1.184 + test(pArray->Find(*(const TArr<S,5>*)_TL("bb bb"), FoldedKey, pos)==0);
1.185 + test(pos==1);
1.186 + test(pArray->Find(*(const TArr<S,5>*)_TL("cc aa"), FoldedKey, pos)==0);
1.187 + test(pos==2);
1.188 +
1.189 +
1.190 + test(pArray->Find(*(const TArr<S,5>*)_TL("___CC"), FoldedKeyOffset, pos)==0);
1.191 + test(pos==0);
1.192 + test(pArray->Find(*(const TArr<S,5>*)_TL("___bB"), FoldedKeyOffset, pos)==0);
1.193 + test(pos==1);
1.194 + test(pArray->Find(*(const TArr<S,5>*)_TL("___Aa"), FoldedKeyOffset, pos)==0);
1.195 + test(pos==2);
1.196 + test(pArray->Find(*(const TArr<S,5>*)_TL("___ax"), FoldedKeyOffset, pos)!=0);
1.197 +
1.198 +
1.199 + test(pArray->Find(*(const TArr<S,5>*)_TL("aa cc"), CollatedKey, pos)==0);
1.200 + test(pos==0);
1.201 + test(pArray->Find(*(const TArr<S,5>*)_TL("bb bb"), CollatedKey, pos)==0);
1.202 + test(pos==1);
1.203 + test(pArray->Find(*(const TArr<S,5>*)_TL("cc aa"), CollatedKey, pos)==0);
1.204 + test(pos==2);
1.205 +
1.206 +
1.207 + test(pArray->Find(*(const TArr<S,5>*)_TL("___cc"), CollatedKeyOffset, pos)==0);
1.208 + test(pos==0);
1.209 + test(pArray->Find(*(const TArr<S,5>*)_TL("___bb"), CollatedKeyOffset, pos)==0);
1.210 + test(pos==1);
1.211 + test(pArray->Find(*(const TArr<S,5>*)_TL("___aa"), CollatedKeyOffset, pos)==0);
1.212 + test(pos==2);
1.213 + test(pArray->Find(*(const TArr<S,5>*)_TL("___ax"), CollatedKeyOffset, pos)!=0);
1.214 +
1.215 + delete pArray;
1.216 + }
1.217 +
1.218 +
1.219 +template<class KeyType, class ArrayType, class S>
1.220 +GLDEF_C void TestTKey<KeyType, ArrayType, S>::Test2(TKeyCmpText N, TKeyCmpText F, TKeyCmpText C)
1.221 + {
1.222 + // This tests the functions of the TKey classes indirectly - mostly using the Find method
1.223 + // which calls SetPtr(), Set() (both trivial) and more importantly Compare(),
1.224 +
1.225 + ArrayType* pArray=new ArrayType(KTestGranularity);
1.226 + pArray->AppendL(*(S(*))_TL("aa cc"), 5*sizeof(S));
1.227 + pArray->AppendL(*(S(*))_TL("bb bbb"), 6*sizeof(S));
1.228 + pArray->AppendL(*(S(*))_TL("cc aaaa"), 7*sizeof(S));
1.229 +
1.230 + KeyType NormalKey5(0,N,5);
1.231 + KeyType NormalKey6(0,N,6);
1.232 + KeyType NormalKey7(0,N,7);
1.233 + KeyType NormalKeyOffset(sizeof(S)*3,N,2);
1.234 +
1.235 + KeyType FoldedKey5(0,F,5);
1.236 + KeyType FoldedKey6(0,F,6);
1.237 + KeyType FoldedKey7(0,F,7);
1.238 + KeyType FoldedKeyOffset(sizeof(S)*3,F,2);
1.239 +
1.240 + KeyType CollatedKey5(0,C,5);
1.241 + KeyType CollatedKey6(0,C,6);
1.242 + KeyType CollatedKey7(0,C,7);
1.243 + KeyType CollatedKeyOffset(sizeof(S)*3,C,2);
1.244 +
1.245 + TInt pos;
1.246 + test(pArray->Find(*(S(*))_TL("aa cc"), NormalKey5, pos)==0);
1.247 + test(pos==0);
1.248 + test(pArray->Find(*(S(*))_TL("bb bbb"), NormalKey6, pos)==0);
1.249 + test(pos==1);
1.250 + test(pArray->Find(*(S(*))_TL("cc aaaa"), NormalKey7, pos)==0);
1.251 + test(pos==2);
1.252 + test(pArray->Find(*(S(*))_TL("BB BB"), NormalKey5, pos)!=0);
1.253 +
1.254 +
1.255 + test(pArray->Find(*(S(*))_TL("___cc"), NormalKeyOffset, pos)==0);
1.256 + test(pos==0);
1.257 + test(pArray->Find(*(S(*))_TL("___bb"), NormalKeyOffset, pos)==0);
1.258 + test(pos==1);
1.259 + test(pArray->Find(*(S(*))_TL("___aa"), NormalKeyOffset, pos)==0);
1.260 + test(pos==2);
1.261 + test(pArray->Find(*(S(*))_TL("___ax"), NormalKeyOffset, pos)!=0);
1.262 +
1.263 +
1.264 + test(pArray->Find(*(S(*))_TL("aa cc"), FoldedKey5, pos)==0);
1.265 + test(pos==0);
1.266 + test(pArray->Find(*(S(*))_TL("bb bbb"), FoldedKey6, pos)==0);
1.267 + test(pos==1);
1.268 + test(pArray->Find(*(S(*))_TL("cc aaaa"), FoldedKey7, pos)==0);
1.269 + test(pos==2);
1.270 +
1.271 +
1.272 + test(pArray->Find(*(S(*))_TL("___CC"), FoldedKeyOffset, pos)==0);
1.273 + test(pos==0);
1.274 + test(pArray->Find(*(S(*))_TL("___bB"), FoldedKeyOffset, pos)==0);
1.275 + test(pos==1);
1.276 + test(pArray->Find(*(S(*))_TL("___Aa"), FoldedKeyOffset, pos)==0);
1.277 + test(pos==2);
1.278 + test(pArray->Find(*(S(*))_TL("___ax"), FoldedKeyOffset, pos)!=0);
1.279 +
1.280 +
1.281 + test(pArray->Find(*(S(*))_TL("aa cc"), CollatedKey5, pos)==0);
1.282 + test(pos==0);
1.283 + test(pArray->Find(*(S(*))_TL("bb bbb"), CollatedKey6, pos)==0);
1.284 + test(pos==1);
1.285 + test(pArray->Find(*(S(*))_TL("cc aaaa"), CollatedKey7, pos)==0);
1.286 + test(pos==2);
1.287 +
1.288 +
1.289 + test(pArray->Find(*(S(*))_TL("___cc"), CollatedKeyOffset, pos)==0);
1.290 + test(pos==0);
1.291 + test(pArray->Find(*(S(*))_TL("___bb"), CollatedKeyOffset, pos)==0);
1.292 + test(pos==1);
1.293 + test(pArray->Find(*(S(*))_TL("___aa"), CollatedKeyOffset, pos)==0);
1.294 + test(pos==2);
1.295 + test(pArray->Find(*(S(*))_TL("___ax"), CollatedKeyOffset, pos)!=0);
1.296 +
1.297 + delete pArray;
1.298 + }
1.299 +
1.300 +
1.301 +template<class KeyType, class ArrayType, class S>
1.302 +GLDEF_C void TestTKey<KeyType, ArrayType, S>::Test3(void)
1.303 + {
1.304 + ArrayType* pArray=new ArrayType(KTestGranularity);
1.305 + Record rec1, rec2, rec3;
1.306 +
1.307 + rec1.name=(_TL("fred"));
1.308 + rec1.age=5;
1.309 + rec1.code='A';
1.310 +
1.311 + rec2.name=(_TL("bill"));
1.312 + rec2.age=0x7fffffff;
1.313 + rec2.code='Z';
1.314 +
1.315 + rec3.name=(_TL("bert"));
1.316 + rec3.age=-5;
1.317 + rec3.code='X';
1.318 +
1.319 + pArray->AppendL(rec1);
1.320 + pArray->AppendL(rec2);
1.321 + pArray->AppendL(rec3);
1.322 +
1.323 + TInt pos;
1.324 +
1.325 + KeyType codekey(_FOFF(Record, code),ECmpNormal,1);
1.326 + test(pArray->Find(rec1, codekey, pos)==0);
1.327 + test(pos==0);
1.328 + test(pArray->Find(rec2, codekey, pos)==0);
1.329 + test(pos==1);
1.330 + test(pArray->Find(rec3, codekey, pos)==0);
1.331 + test(pos==2);
1.332 +
1.333 + KeyType agekey(_FOFF(Record, age), ECmpTInt32);
1.334 + test(pArray->Find(rec1, agekey, pos)==0);
1.335 + test(pos==0);
1.336 + test(pArray->Find(rec2, agekey, pos)==0);
1.337 + test(pos==1);
1.338 + test(pArray->Find(rec3, agekey, pos)==0);
1.339 + test(pos==2);
1.340 +
1.341 + rec1.age=-50; // march 95 - this isn't allowed , lucky that it works
1.342 + test(pArray->Find(rec1, agekey, pos)!=0);
1.343 + rec1.age=5;
1.344 +
1.345 + pArray->Sort(agekey);
1.346 + test(pArray->Find(rec1, agekey, pos)==0);
1.347 + test(pos==1);
1.348 + test(pArray->Find(rec2, agekey, pos)==0);
1.349 + test(pos==2);
1.350 + test(pArray->Find(rec3, agekey, pos)==0);
1.351 + test(pos==0);
1.352 +
1.353 + delete pArray;
1.354 + }
1.355 +
1.356 +template<class KeyType, class ArrayType, class S>
1.357 +GLDEF_C void TestTKey<KeyType, ArrayType, S>::Test4(void)
1.358 + {
1.359 + ArrayType* pArray=new ArrayType(KTestGranularity);
1.360 + Record rec1, rec2, rec3;
1.361 +
1.362 + rec1.name=(_TL("fred"));
1.363 + rec1.age=5;
1.364 + rec1.code='A';
1.365 + rec2.name=(_TL("bill"));
1.366 + rec2.age=0x7fffffff;
1.367 + rec2.code='Z';
1.368 + rec3.name=(_TL("bert"));
1.369 + rec3.age=-5;
1.370 + rec3.code='X';
1.371 +
1.372 + pArray->AppendL(rec1, sizeof(Record));
1.373 + pArray->AppendL(rec2, sizeof(Record));
1.374 + pArray->AppendL(rec3, sizeof(Record));
1.375 +
1.376 + TInt pos;
1.377 + KeyType codekey(_FOFF(Record, code),ECmpNormal,1);
1.378 + test(pArray->Find(rec1, codekey, pos)==0);
1.379 + test(pos==0);
1.380 + test(pArray->Find(rec2, codekey, pos)==0);
1.381 + test(pos==1);
1.382 + test(pArray->Find(rec3, codekey, pos)==0);
1.383 + test(pos==2);
1.384 +
1.385 + KeyType agekey(_FOFF(Record, age), ECmpTInt32);
1.386 + test(pArray->Find(rec1, agekey, pos)==0);
1.387 + test(pos==0);
1.388 + test(pArray->Find(rec2, agekey, pos)==0);
1.389 + test(pos==1);
1.390 + test(pArray->Find(rec3, agekey, pos)==0);
1.391 + test(pos==2);
1.392 + rec1.age=-50; // march 95 - this isn't allowed - lucky to get away with it
1.393 + test(pArray->Find(rec1, agekey, pos)!=0);
1.394 + rec1.age=5;
1.395 +
1.396 + pArray->Sort(agekey);
1.397 + test(pArray->Find(rec1, agekey, pos)==0);
1.398 + test(pos==1);
1.399 + test(pArray->Find(rec2, agekey, pos)==0);
1.400 + test(pos==2);
1.401 + test(pArray->Find(rec3, agekey, pos)==0);
1.402 + test(pos==0);
1.403 +
1.404 + delete pArray;
1.405 + }
1.406 +
1.407 +template<class KeyType, class ArrayType, class S>
1.408 +GLDEF_C void TestTKey<KeyType, ArrayType, S>::Test5(void)
1.409 + {
1.410 + // test the numeric enumeration types
1.411 + ArrayType* pArray=new ArrayType(KTestGranularity);
1.412 + TInt pos;
1.413 +
1.414 + KeyType TIntKey(_FOFF(Record2, tint), ECmpTInt);
1.415 + KeyType TUintKey(_FOFF(Record2, tuint), ECmpTUint);
1.416 + KeyType TInt8Key(_FOFF(Record2, tint8), ECmpTInt8);
1.417 + KeyType TUint8Key(_FOFF(Record2, tuint8), ECmpTUint8);
1.418 + KeyType TInt16Key(_FOFF(Record2, tint16), ECmpTInt16);
1.419 + KeyType TUint16Key(_FOFF(Record2, tuint16), ECmpTUint16);
1.420 + KeyType TInt32Key(_FOFF(Record2, tint32), ECmpTInt32);
1.421 + KeyType TUint32Key(_FOFF(Record2, tuint32), ECmpTUint32);
1.422 +
1.423 + SetRecordData();
1.424 +
1.425 + pArray->AppendL(Rec1);
1.426 + pArray->AppendL(Rec2);
1.427 + pArray->AppendL(Rec3);
1.428 + pArray->AppendL(Rec4);
1.429 +
1.430 + pArray->Sort(TIntKey);
1.431 + // order should be 4,3,2,1
1.432 + test(pArray->Find(Rec4, TIntKey, pos)==0);
1.433 + test(pos==0);
1.434 + test(pArray->Find(Rec3, TIntKey, pos)==0);
1.435 + test(pos==1);
1.436 + test(pArray->Find(Rec2, TIntKey, pos)==0);
1.437 + test(pos==2);
1.438 + test(pArray->Find(Rec1, TIntKey, pos)==0);
1.439 + test(pos==3);
1.440 +
1.441 + pArray->Sort(TUintKey);
1.442 + // order should be 1,2,3,4
1.443 + test(pArray->Find(Rec1, TUintKey, pos)==0);
1.444 + test(pos==0);
1.445 + test(pArray->Find(Rec2, TUintKey, pos)==0);
1.446 + test(pos==1);
1.447 + test(pArray->Find(Rec3, TUintKey, pos)==0);
1.448 + test(pos==2);
1.449 + test(pArray->Find(Rec4, TUintKey, pos)==0);
1.450 + test(pos==3);
1.451 +
1.452 + pArray->Sort(TInt8Key);
1.453 + // order should be 4,3,2,1
1.454 + test(pArray->Find(Rec4, TInt8Key, pos)==0);
1.455 + test(pos==0);
1.456 + test(pArray->Find(Rec3, TInt8Key, pos)==0);
1.457 + test(pos==1);
1.458 + test(pArray->Find(Rec2, TInt8Key, pos)==0);
1.459 + test(pos==2);
1.460 + test(pArray->Find(Rec1, TInt8Key, pos)==0);
1.461 + test(pos==3);
1.462 +
1.463 + pArray->Sort(TUint8Key);
1.464 + // order should be 1,2,3,4
1.465 + test(pArray->Find(Rec1, TUint8Key, pos)==0);
1.466 + test(pos==0);
1.467 + test(pArray->Find(Rec2, TUint8Key, pos)==0);
1.468 + test(pos==1);
1.469 + test(pArray->Find(Rec3, TUint8Key, pos)==0);
1.470 + test(pos==2);
1.471 + test(pArray->Find(Rec4, TUint8Key, pos)==0);
1.472 + test(pos==3);
1.473 +
1.474 + pArray->Sort(TInt16Key);
1.475 + // order should be 4,3,2,1
1.476 + test(pArray->Find(Rec4, TInt16Key, pos)==0);
1.477 + test(pos==0);
1.478 + test(pArray->Find(Rec3, TInt16Key, pos)==0);
1.479 + test(pos==1);
1.480 + test(pArray->Find(Rec2, TInt16Key, pos)==0);
1.481 + test(pos==2);
1.482 + test(pArray->Find(Rec1, TInt16Key, pos)==0);
1.483 + test(pos==3);
1.484 +
1.485 + pArray->Sort(TUintKey);
1.486 + // order should be 1,2,3,4
1.487 + test(pArray->Find(Rec1, TUint16Key, pos)==0);
1.488 + test(pos==0);
1.489 + test(pArray->Find(Rec2, TUint16Key, pos)==0);
1.490 + test(pos==1);
1.491 + test(pArray->Find(Rec3, TUint16Key, pos)==0);
1.492 + test(pos==2);
1.493 + test(pArray->Find(Rec4, TUint16Key, pos)==0);
1.494 + test(pos==3);
1.495 +
1.496 + pArray->Sort(TInt32Key);
1.497 + // order should be 4,3,2,1
1.498 + test(pArray->Find(Rec4, TInt32Key, pos)==0);
1.499 + test(pos==0);
1.500 + test(pArray->Find(Rec3, TInt32Key, pos)==0);
1.501 + test(pos==1);
1.502 + test(pArray->Find(Rec2, TInt32Key, pos)==0);
1.503 + test(pos==2);
1.504 + test(pArray->Find(Rec1, TInt32Key, pos)==0);
1.505 + test(pos==3);
1.506 +
1.507 + pArray->Sort(TUint32Key);
1.508 + // order should be 1,2,3,4
1.509 + test(pArray->Find(Rec1, TUint32Key, pos)==0);
1.510 + test(pos==0);
1.511 + test(pArray->Find(Rec2, TUint32Key, pos)==0);
1.512 + test(pos==1);
1.513 + test(pArray->Find(Rec3, TUint32Key, pos)==0);
1.514 + test(pos==2);
1.515 + test(pArray->Find(Rec4, TUint32Key, pos)==0);
1.516 + test(pos==3);
1.517 +
1.518 + delete pArray;
1.519 + }
1.520 +
1.521 +template<class KeyType, class ArrayType, class S>
1.522 +GLDEF_C void TestTKey<KeyType, ArrayType, S>::Test6(void)
1.523 + {
1.524 + // test the numeric enumeration types
1.525 + ArrayType* pArray=new ArrayType(KTestGranularity);
1.526 + TInt pos;
1.527 +
1.528 + KeyType TIntKey(_FOFF(Record2, tint), ECmpTInt);
1.529 + KeyType TUintKey(_FOFF(Record2, tuint), ECmpTUint);
1.530 + KeyType TInt8Key(_FOFF(Record2, tint8), ECmpTInt8);
1.531 + KeyType TUint8Key(_FOFF(Record2, tuint8), ECmpTUint8);
1.532 + KeyType TInt16Key(_FOFF(Record2, tint16), ECmpTInt16);
1.533 + KeyType TUint16Key(_FOFF(Record2, tuint16), ECmpTUint16);
1.534 + KeyType TInt32Key(_FOFF(Record2, tint32), ECmpTInt32);
1.535 + KeyType TUint32Key(_FOFF(Record2, tuint32), ECmpTUint32);
1.536 +
1.537 + SetRecordData();
1.538 +
1.539 + pArray->AppendL(Rec1, sizeof(Record2));
1.540 + pArray->AppendL(Rec2, sizeof(Record2));
1.541 + pArray->AppendL(Rec3, sizeof(Record2));
1.542 + pArray->AppendL(Rec4, sizeof(Record2));
1.543 +
1.544 + pArray->Sort(TIntKey);
1.545 + // order should be 4,3,2,1
1.546 + test(pArray->Find(Rec4, TIntKey, pos)==0);
1.547 + test(pos==0);
1.548 + test(pArray->Find(Rec3, TIntKey, pos)==0);
1.549 + test(pos==1);
1.550 + test(pArray->Find(Rec2, TIntKey, pos)==0);
1.551 + test(pos==2);
1.552 + test(pArray->Find(Rec1, TIntKey, pos)==0);
1.553 + test(pos==3);
1.554 +
1.555 + pArray->Sort(TUintKey);
1.556 + // order should be 1,2,3,4
1.557 + test(pArray->Find(Rec1, TUintKey, pos)==0);
1.558 + test(pos==0);
1.559 + test(pArray->Find(Rec2, TUintKey, pos)==0);
1.560 + test(pos==1);
1.561 + test(pArray->Find(Rec3, TUintKey, pos)==0);
1.562 + test(pos==2);
1.563 + test(pArray->Find(Rec4, TUintKey, pos)==0);
1.564 + test(pos==3);
1.565 +
1.566 + pArray->Sort(TInt8Key);
1.567 + // order should be 4,3,2,1
1.568 + test(pArray->Find(Rec4, TInt8Key, pos)==0);
1.569 + test(pos==0);
1.570 + test(pArray->Find(Rec3, TInt8Key, pos)==0);
1.571 + test(pos==1);
1.572 + test(pArray->Find(Rec2, TInt8Key, pos)==0);
1.573 + test(pos==2);
1.574 + test(pArray->Find(Rec1, TInt8Key, pos)==0);
1.575 + test(pos==3);
1.576 +
1.577 + pArray->Sort(TUint8Key);
1.578 + // order should be 1,2,3,4
1.579 + test(pArray->Find(Rec1, TUint8Key, pos)==0);
1.580 + test(pos==0);
1.581 + test(pArray->Find(Rec2, TUint8Key, pos)==0);
1.582 + test(pos==1);
1.583 + test(pArray->Find(Rec3, TUint8Key, pos)==0);
1.584 + test(pos==2);
1.585 + test(pArray->Find(Rec4, TUint8Key, pos)==0);
1.586 + test(pos==3);
1.587 +
1.588 + pArray->Sort(TInt16Key);
1.589 + // order should be 4,3,2,1
1.590 + test(pArray->Find(Rec4, TInt16Key, pos)==0);
1.591 + test(pos==0);
1.592 + test(pArray->Find(Rec3, TInt16Key, pos)==0);
1.593 + test(pos==1);
1.594 + test(pArray->Find(Rec2, TInt16Key, pos)==0);
1.595 + test(pos==2);
1.596 + test(pArray->Find(Rec1, TInt16Key, pos)==0);
1.597 + test(pos==3);
1.598 +
1.599 + pArray->Sort(TUintKey);
1.600 + // order should be 1,2,3,4
1.601 + test(pArray->Find(Rec1, TUint16Key, pos)==0);
1.602 + test(pos==0);
1.603 + test(pArray->Find(Rec2, TUint16Key, pos)==0);
1.604 + test(pos==1);
1.605 + test(pArray->Find(Rec3, TUint16Key, pos)==0);
1.606 + test(pos==2);
1.607 + test(pArray->Find(Rec4, TUint16Key, pos)==0);
1.608 + test(pos==3);
1.609 +
1.610 + pArray->Sort(TInt32Key);
1.611 + // order should be 4,3,2,1
1.612 + test(pArray->Find(Rec4, TInt32Key, pos)==0);
1.613 + test(pos==0);
1.614 + test(pArray->Find(Rec3, TInt32Key, pos)==0);
1.615 + test(pos==1);
1.616 + test(pArray->Find(Rec2, TInt32Key, pos)==0);
1.617 + test(pos==2);
1.618 + test(pArray->Find(Rec1, TInt32Key, pos)==0);
1.619 + test(pos==3);
1.620 +
1.621 + pArray->Sort(TUint32Key);
1.622 + // order should be 1,2,3,4
1.623 + test(pArray->Find(Rec1, TUint32Key, pos)==0);
1.624 + test(pos==0);
1.625 + test(pArray->Find(Rec2, TUint32Key, pos)==0);
1.626 + test(pos==1);
1.627 + test(pArray->Find(Rec3, TUint32Key, pos)==0);
1.628 + test(pos==2);
1.629 + test(pArray->Find(Rec4, TUint32Key, pos)==0);
1.630 + test(pos==3);
1.631 +
1.632 + delete pArray;
1.633 + }
1.634 +
1.635 +GLDEF_C TInt E32Main()
1.636 + {
1.637 +
1.638 + test.Title();
1.639 + test.Start(_L("Fixed key class with a flat array of TText8"));
1.640 + typedef CArrayFixFlat<TArr<TText8,5> > aFixedFlatArrayOfTText8;
1.641 + TestTKey<TKeyArrayFix, aFixedFlatArrayOfTText8, TText8> T1;
1.642 + T1.Test1(ECmpNormal8, ECmpFolded8, ECmpCollated8);
1.643 +
1.644 + test.Next(_L("Fixed key class with a flat array of TText16"));
1.645 + typedef CArrayFixFlat<TArr<TText16,5> > aFixedFlatArrayOfTText16;
1.646 + TestTKey<TKeyArrayFix, aFixedFlatArrayOfTText16, TText16> T2;
1.647 + T2.Test1(ECmpNormal16, ECmpFolded16, ECmpCollated16);
1.648 +
1.649 + test.Next(_L("Fixed key class with a flat array of TText"));
1.650 + typedef CArrayFixFlat<TArr<TText,5> > aFixedFlatArrayOfTText;
1.651 + TestTKey<TKeyArrayFix, aFixedFlatArrayOfTText, TText> T3;
1.652 + T3.Test1(ECmpNormal, ECmpFolded, ECmpCollated);
1.653 +
1.654 + test.Next(_L("Fixed key class with a segmented array of TText8"));
1.655 + typedef CArrayFixSeg<TArr<TText8,5> > aFixedSegmentedArrayOfTText8;
1.656 + TestTKey<TKeyArrayFix, aFixedSegmentedArrayOfTText8, TText8> T4;
1.657 + T4.Test1(ECmpNormal8, ECmpFolded8, ECmpCollated8);
1.658 +
1.659 + test.Next(_L("Fixed key class with a segmented array of TText16"));
1.660 + typedef CArrayFixSeg<TArr<TText16,5> > aFixedSegmentedArrayOfTText16;
1.661 + TestTKey<TKeyArrayFix, aFixedSegmentedArrayOfTText16, TText16> T5;
1.662 + T5.Test1(ECmpNormal16, ECmpFolded16, ECmpCollated16);
1.663 +
1.664 + test.Next(_L("Fixed key class with a segmented array of TText"));
1.665 + typedef CArrayFixSeg<TArr<TText,5> > aFixedSegmentedArrayOfTText;
1.666 + TestTKey<TKeyArrayFix, aFixedSegmentedArrayOfTText, TText> T6;
1.667 + T6.Test1(ECmpNormal, ECmpFolded, ECmpCollated);
1.668 +
1.669 + test.Next(_L("Var key with a flat array of TText8"));
1.670 + typedef CArrayVarFlat<TText8> aVarFlatArrayOfTText8;
1.671 + TestTKey<TKeyArrayVar, aVarFlatArrayOfTText8, TText8> T7;
1.672 + T7.Test2(ECmpNormal8, ECmpFolded8, ECmpCollated8);
1.673 +
1.674 + test.Next(_L("Var key with a flat array of TText16"));
1.675 + typedef CArrayVarFlat<TText16> aVarFlatArrayOfTText16;
1.676 + TestTKey<TKeyArrayVar, aVarFlatArrayOfTText16, TText16> T8;
1.677 + T8.Test2(ECmpNormal16, ECmpFolded16, ECmpCollated16);
1.678 +
1.679 + test.Next(_L("Var key with a flat array of TText"));
1.680 + typedef CArrayVarFlat<TText> aVarFlatArrayOfTText;
1.681 + TestTKey<TKeyArrayVar, aVarFlatArrayOfTText, TText> T9;
1.682 + T9.Test2(ECmpNormal, ECmpFolded, ECmpCollated);
1.683 +
1.684 + test.Next(_L("Var key with a segmented array of TText8"));
1.685 + typedef CArrayVarSeg<TText8> aVarSegmentedArrayOfTText8;
1.686 + TestTKey<TKeyArrayVar, aVarSegmentedArrayOfTText8, TText8> T10;
1.687 + T10.Test2(ECmpNormal8, ECmpFolded8, ECmpCollated8);
1.688 +
1.689 + test.Next(_L("Var key with a segmented array of TText16"));
1.690 + typedef CArrayVarSeg<TText16> aVarSegmentedArrayOfTText16;
1.691 + TestTKey<TKeyArrayVar, aVarSegmentedArrayOfTText16, TText16> T11;
1.692 + T11.Test2(ECmpNormal16, ECmpFolded16, ECmpCollated16);
1.693 +
1.694 + test.Next(_L("Var key with a segmented array of TText"));
1.695 + typedef CArrayVarSeg<TText> aVarSegmentedArrayOfTText;
1.696 + TestTKey<TKeyArrayVar, aVarSegmentedArrayOfTText, TText> T12;
1.697 + T12.Test2(ECmpNormal, ECmpFolded, ECmpCollated);
1.698 +
1.699 + test.Next(_L("Fixed key with a flat array of structs"));
1.700 + typedef CArrayFixFlat<Record> aFixedFlatArrayOfRecord;
1.701 + TestTKey<TKeyArrayFix, aFixedFlatArrayOfRecord, TText> T13;
1.702 + T13.Test3();
1.703 +
1.704 + test.Next(_L("Fixed key with a segmented array of structs"));
1.705 + typedef CArrayFixSeg<Record> aFixedSegmentedArrayOfRecord;
1.706 + TestTKey<TKeyArrayFix, aFixedSegmentedArrayOfRecord, TText> T14;
1.707 + T14.Test3();
1.708 +
1.709 + test.Next(_L("Var key with a flat array of structs"));
1.710 + typedef CArrayVarFlat<Record> aVarFlatArrayOfRecord;
1.711 + TestTKey<TKeyArrayVar, aVarFlatArrayOfRecord, TText> T15;
1.712 + T15.Test4();
1.713 +
1.714 + test.Next(_L("Var key with a segmented array of structs"));
1.715 + typedef CArrayVarSeg<Record> aVarSegmentedArrayOfRecord;
1.716 + TestTKey<TKeyArrayVar, aVarSegmentedArrayOfRecord, TText> T16;
1.717 + T16.Test4();
1.718 +
1.719 + test.Next(_L("Fixed key with a flat array of structs testing numeric types"));
1.720 + typedef CArrayFixFlat<Record2> aFixedFlatArrayOfRecord2;
1.721 + TestTKey<TKeyArrayFix, aFixedFlatArrayOfRecord2, TText> T17;
1.722 + T17.Test5();
1.723 +
1.724 + test.Next(_L("Var key with a flat array of structs testing numeric types"));
1.725 + typedef CArrayVarFlat<Record2> aVarFlatArrayOfRecord2;
1.726 + TestTKey<TKeyArrayVar, aVarFlatArrayOfRecord2, TText> T18;
1.727 + T18.Test6();
1.728 + test.End();
1.729 + return(KErrNone);
1.730 + }
1.731 +
1.732 +/*#else
1.733 +GLDEF_C TInt E32Main()
1.734 +//
1.735 +// Test unavailable in release build.
1.736 +//
1.737 + {
1.738 +
1.739 + test.Title();
1.740 + test.Start(_L("No tests for release builds"));
1.741 + test.End();
1.742 + return(0);
1.743 + }
1.744 +#endif
1.745 +
1.746 +*/
1.747 +