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