os/kernelhwsrv/kerneltest/e32test/buffer/smpl_arr.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1994-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\smpl_arr.cpp
    15 // 
    16 //
    17 
    18 #include <e32test.h>
    19 #include <e32math.h>
    20 #include <e32std.h>
    21 #include <e32std_private.h>
    22 
    23 #define NUM_TESTS 200
    24 
    25 GLREF_D RTest test;
    26 GLREF_C TInt Random();
    27 
    28 struct SEntry
    29 	{
    30 	TInt iKey;
    31 	TInt iValue;
    32 	inline TBool operator!=(const SEntry& anEntry) const
    33 		{return (iValue!=anEntry.iValue || iKey!=anEntry.iKey);}
    34 	inline TBool operator==(const SEntry& anEntry) const
    35 		{return (iValue==anEntry.iValue && iKey==anEntry.iKey);}
    36 	};
    37 
    38 struct SArray
    39 	{
    40 	TInt iCount;
    41 	TAny* iEntries;
    42 	TInt iEntrySize;
    43 	TInt iKeyOffset;
    44 	TInt iAllocated;
    45 	TInt iGranularity;
    46 	};
    47 
    48 GLREF_C TInt OrderSEntry(const SEntry& aLeft, const SEntry& aRight);
    49 GLREF_C TInt OrderSEntryU(const SEntry& aLeft, const SEntry& aRight);
    50 GLREF_C TInt OrderSEntry2(const SEntry& aLeft, const SEntry& aRight);
    51 GLREF_C TInt OrderSEntryU2(const SEntry& aLeft, const SEntry& aRight);
    52 GLREF_C TBool CompareSEntryByKeyKey(const TInt* aKey, const SEntry& aRight);
    53 GLREF_C TBool CompareSEntryByKeyValue(const TInt* aValue, const SEntry& aRight);
    54 
    55 GLREF_D TLinearOrder<TInt64> Int64Order;
    56 GLREF_D TIdentityRelation<TInt64> Int64Identity;
    57 GLREF_D TLinearOrder<SEntry> SEntryOrder;
    58 GLREF_D TIdentityRelation<SEntry> SEntryKeyIdentity;
    59 GLREF_D TIdentityRelation<SEntry> SEntryIdentity;
    60 
    61 LOCAL_C TInt64 Random64(TInt64& aMask)
    62 	{
    63 	TInt64 x = MAKE_TINT64(Random()&I64HIGH(aMask), Random()&I64LOW(aMask));
    64 	return x;
    65 	}
    66 
    67 LOCAL_C TInt IntAppendAndAccessTest(TInt aCount, TInt aNumTests, TInt64 aMask)
    68 	{
    69 	TInt n;
    70 	for (n=0; n<aNumTests; n++)
    71 		{
    72 		RArray<TInt64> a(aCount);
    73 		TInt64 *pA=new TInt64[aCount];
    74 		if (!pA)
    75 			{
    76 			a.Close();
    77 			return -65535;
    78 			}
    79 		TInt i;
    80 		for (i=0; i<aCount; i++)
    81 			{
    82 			TInt64 x=Random64(aMask);
    83 			pA[i]=x;
    84 			a.Append(x);
    85 			}
    86 		if (a.Count()!=aCount)
    87 			{
    88 			a.Close();
    89 			return -1;
    90 			}
    91 		for (i=0; i<aCount; i++)
    92 			{
    93 			if (a[i]!=pA[i])
    94 				{
    95 				a.Close();
    96 				return -2;
    97 				}
    98 			pA[i]=Random64(aMask);
    99 			a[i]=pA[i];
   100 			}
   101 		if (a.Count()!=aCount)
   102 			{
   103 			a.Close();
   104 			return -3;
   105 			}
   106 		for (i=0; i<aCount; i++)
   107 			{
   108 			if (a[i]!=pA[i])
   109 				{
   110 				a.Close();
   111 				return -4;
   112 				}
   113 			}
   114 		delete[] pA;
   115 		a.Close();
   116 		}
   117 	return KErrNone;
   118 	}
   119 
   120 LOCAL_C TInt IntRemoveTest()
   121 	{
   122 	TInt m=32;
   123 	TInt n=m*m+1;
   124 	RArray<TInt64> a(n);
   125 	TInt i;
   126 	for (i=0; i<n; i++)
   127 		{
   128 		TInt64 x = MAKE_TINT64(i*i,i);
   129 		a.Append(x);
   130 		}
   131 	TInt p=2;
   132 	for (i=2; i<=m; i++)
   133 		{
   134 		TInt j;
   135 		for (j=0; j<(2*i-2); j++)
   136 			{
   137 			a.Remove(p);
   138 			}
   139 		p++;
   140 		}
   141 	if (a.Count()!=m+1)
   142 		{
   143 		a.Close();
   144 		return -1;
   145 		}
   146 	for (i=0; i<m; i++)
   147 		{
   148 		TInt64 x = MAKE_TINT64(i*i*i*i,i*i);
   149 		if (a[i]!=x)
   150 			{
   151 			a.Close();
   152 			return -2;
   153 			}
   154 		}
   155 	a.Close();
   156 	return KErrNone;
   157 	}
   158 
   159 LOCAL_C TInt IntFindTest(TInt aCount, TInt aNumTests, TInt64 aMask)
   160 	{
   161 	TInt n;
   162 	for (n=0; n<aNumTests; n++)
   163 		{
   164 		RArray<TInt64> a(aCount);
   165 		TInt64 *pA=new TInt64[aCount];
   166 		if (!pA)
   167 			{
   168 			a.Close();
   169 			return -65535;
   170 			}
   171 		TInt i;
   172 		for (i=0; i<aCount; i++)
   173 			{
   174 			pA[i]=Random64(aMask);
   175 			a.Append(pA[i]);
   176 			}
   177 		if (a.Count()!=aCount)
   178 			{
   179 			a.Close();
   180 			return -1;
   181 			}
   182 		for (i=0; i<aCount; i++)
   183 			{
   184 			TInt r=a.Find(pA[i],Int64Identity);
   185 			if (r<0 || pA[i]!=pA[r] || r>i)
   186 				{
   187 				a.Close();
   188 				return -2;
   189 				}
   190 			}
   191 		delete[] pA;
   192 		a.Close();
   193 		}
   194 	return KErrNone;
   195 	}
   196 
   197 template <class XTestInput>
   198 LOCAL_C TInt FindWithEqualityOp(XTestInput &aObject1, XTestInput &aObject2)
   199 	{
   200 	//Construct a suitable RArray
   201 	RArray<XTestInput> testRArray;
   202 
   203 	//Append the test objects to the RArray
   204 	testRArray.AppendL(aObject1);
   205 	testRArray.AppendL(aObject2);
   206 	testRArray.AppendL(aObject1);
   207 	testRArray.AppendL(aObject2);
   208 	
   209 	//Demonstrate that "regular" Find() method returns incorrect result
   210 	TInt pos = KErrNotFound;
   211 	pos = testRArray.Find(aObject1);
   212 	if(pos!=0)
   213 		return KErrNotFound;
   214 	pos = testRArray.Find(aObject2);
   215 	if(pos!=0)
   216 		return KErrNotFound;
   217 
   218 	//Test the Find() method using TIdentityRelation default CTOR
   219 	pos = testRArray.Find(aObject1, TIdentityRelation<XTestInput>());
   220 	if(pos!=0)
   221 		return KErrNotFound;
   222 	pos = testRArray.Find(aObject2, TIdentityRelation<XTestInput>());
   223 	if(pos!=1)
   224 		return KErrNotFound;
   225 	
   226 	//Test the FindReverse() method using TIdentityRelation default CTOR
   227 	pos = testRArray.FindReverse(aObject1, TIdentityRelation<XTestInput>());
   228 	if(pos!=2)
   229 		return KErrNotFound;
   230 	pos = testRArray.FindReverse(aObject2, TIdentityRelation<XTestInput>());
   231 	if(pos!=3)
   232 		return KErrNotFound;
   233 	
   234 	//Objects have been found correctly if this point reached
   235 	testRArray.Close();
   236 	
   237 	return KErrNone;
   238 	}
   239 
   240 LOCAL_C TInt FindWithEqualityOpTest()
   241 	{
   242 	//Test "complex" objects which would work incorrectly with the regular Find() method
   243 
   244 	TPoint p1(0,0);
   245     TPoint p2(0,1);
   246     TPoint p3(0,2);
   247 	test(FindWithEqualityOp(p1, p2) == KErrNone);
   248 
   249     TRect rect1(p1,p2);
   250     TRect rect2(p1,p3);
   251 	test(FindWithEqualityOp(rect1, rect2) == KErrNone);
   252 
   253     TBuf<5> buf1(_L("test1"));
   254 	TBuf<5> buf2(_L("test2"));
   255 	test(FindWithEqualityOp(buf1, buf2) == KErrNone);
   256 
   257 	return KErrNone;
   258 	}
   259 
   260 LOCAL_C TInt EntryFindTest(TInt aCount, TInt aNumTests)
   261 	{
   262 	TInt n;
   263 	for (n=0; n<aNumTests; n++)
   264 		{
   265 		RArray<SEntry> a(aCount,0);	// keyed on iKey
   266 		RArray<SEntry> b(aCount,4);	// keyed on iValue
   267 		SEntry *pE=new SEntry[aCount];
   268 		if (!pE)
   269 			{
   270 			a.Close();
   271 			b.Close();
   272 			return -65535;
   273 			}
   274 		TInt i;
   275 		for (i=0; i<aCount; i++)
   276 			{
   277 			pE[i].iValue=Random();
   278 			pE[i].iKey=Random();
   279 			a.Append(pE[i]);
   280 			b.Append(pE[i]);
   281 			}
   282 		if (a.Count()!=aCount)
   283 			{
   284 			a.Close();
   285 			b.Close();
   286 			return -1;
   287 			}
   288 		if (b.Count()!=aCount)
   289 			{
   290 			a.Close();
   291 			b.Close();
   292 			return -1;
   293 			}
   294 		for (i=0; i<aCount; i++)
   295 			{
   296 			SEntry e1=pE[i];
   297 			SEntry e2=pE[i];
   298 			e2.iValue=~e2.iValue;
   299 			SEntry e3=pE[i];
   300 			e3.iKey=~e3.iKey;
   301 			TInt r=a.Find(e1);
   302 			if (r!=i)
   303 				{
   304 				a.Close();
   305 				b.Close();
   306 				return -2;
   307 				}
   308 			r=a.Find(e2);
   309 			if (r!=i)
   310 				{
   311 				a.Close();
   312 				b.Close();
   313 				return -3;
   314 				}
   315 			r=a.Find(e3);
   316 			if (r>=0 && pE[r].iKey!=e3.iKey)
   317 				{
   318 				a.Close();
   319 				b.Close();
   320 				return -4;
   321 				}
   322 			r=b.Find(e1);
   323 			if (r!=i)
   324 				{
   325 				a.Close();
   326 				b.Close();
   327 				return -5;
   328 				}
   329 			r=b.Find(e3);
   330 			if (r!=i)
   331 				{
   332 				a.Close();
   333 				b.Close();
   334 				return -6;
   335 				}
   336 			r=b.Find(e2);
   337 			if (r>=0 && pE[r].iValue!=e3.iValue)
   338 				{
   339 				a.Close();
   340 				b.Close();
   341 				return -7;
   342 				}
   343 			r=a.Find(e1,SEntryIdentity);
   344 			if (r!=i)
   345 				{
   346 				a.Close();
   347 				b.Close();
   348 				return -8;
   349 				}
   350 			r=a.Find(e2,SEntryIdentity);
   351 			if (r>=0 && pE[r]!=e3)
   352 				{
   353 				a.Close();
   354 				b.Close();
   355 				return -9;
   356 				}
   357 			r=a.Find(e3,SEntryIdentity);
   358 			if (r>=0 && pE[r]!=e3)
   359 				{
   360 				a.Close();
   361 				b.Close();
   362 				return -10;
   363 				}
   364 			r=b.Find(e1,SEntryIdentity);
   365 			if (r!=i)
   366 				{
   367 				a.Close();
   368 				b.Close();
   369 				return -11;
   370 				}
   371 			r=b.Find(e3,SEntryIdentity);
   372 			if (r>=0 && pE[r]!=e3)
   373 				{
   374 				a.Close();
   375 				b.Close();
   376 				return -12;
   377 				}
   378 			r=b.Find(e2,SEntryIdentity);
   379 			if (r>=0 && pE[r]!=e3)
   380 				{
   381 				a.Close();
   382 				b.Close();
   383 				return -13;
   384 				}
   385 			r=a.Find(e1.iValue,CompareSEntryByKeyValue);
   386 			if (r!=i)
   387 				{
   388 				a.Close();
   389 				b.Close();
   390 				return -14;
   391 				}
   392 			r=a.Find(e2.iValue,CompareSEntryByKeyValue);
   393 			if (r>=0 && pE[r].iValue!=e2.iValue)
   394 				{
   395 				a.Close();
   396 				b.Close();
   397 				return -15;
   398 				}			
   399 			r=b.Find(e1.iKey,CompareSEntryByKeyKey);
   400 			if (r!=i)
   401 				{
   402 				a.Close();
   403 				b.Close();
   404 				return -16;
   405 				}
   406 			r=b.Find(e3.iKey,CompareSEntryByKeyKey);
   407 			if (r>=0 && pE[r].iKey!=e3.iKey)
   408 				{
   409 				a.Close();
   410 				b.Close();
   411 				return -17;
   412 				}
   413 			}
   414 		delete[] pE;
   415 		a.Close();
   416 		b.Close();
   417 		}
   418 	return KErrNone;
   419 	}
   420 	
   421 LOCAL_C TInt IntFindReverseTest(TInt aCount, TInt aNumTests, TInt64 aMask)
   422 	{
   423 	TInt n;
   424 	for (n=0; n<aNumTests; n++)
   425 		{
   426 		RArray<TInt64> a(aCount);
   427 		TInt64 *pA=new TInt64[aCount];
   428 		if (!pA)
   429 			{
   430 			a.Close();
   431 			return -65535;
   432 			}
   433 		TInt i;
   434 		for (i=0; i<aCount; i++)
   435 			{
   436 			pA[i]=Random64(aMask);
   437 			a.Append(pA[i]);
   438 			}
   439 		if (a.Count()!=aCount)
   440 			{
   441 			a.Close();
   442 			return -1;
   443 			}
   444 		for (i=0; i<aCount; i++)
   445 			{
   446 			TInt r=a.FindReverse(pA[i],Int64Identity);
   447 			if (pA[i]!=pA[r] || r<i)
   448 				{
   449 				a.Close();
   450 				return -2;
   451 				}
   452 			}
   453 		delete[] pA;
   454 		a.Close();
   455 		}
   456 	return KErrNone;
   457 	}
   458 
   459 LOCAL_C TInt EntryFindReverseTest(TInt aCount, TInt aNumTests)
   460 	{
   461 	TInt n;
   462 	for (n=0; n<aNumTests; n++)
   463 		{
   464 		RArray<SEntry> a(aCount,0);	// keyed on iKey
   465 		RArray<SEntry> b(aCount,4);	// keyed on iValue
   466 		SEntry *pE=new SEntry[aCount];
   467 		if (!pE)
   468 			{
   469 			a.Close();
   470 			b.Close();
   471 			return -65535;
   472 			}
   473 		TInt i;
   474 		for (i=0; i<aCount; i++)
   475 			{
   476 			pE[i].iValue=Random();
   477 			pE[i].iKey=Random();
   478 			a.Append(pE[i]);
   479 			b.Append(pE[i]);
   480 			}
   481 		if (a.Count()!=aCount)
   482 			{
   483 			a.Close();
   484 			b.Close();
   485 			return -1;
   486 			}
   487 		if (b.Count()!=aCount)
   488 			{
   489 			a.Close();
   490 			b.Close();
   491 			return -1;
   492 			}
   493 		for (i=0; i<aCount; i++)
   494 			{
   495 			SEntry e1=pE[i];
   496 			SEntry e2=pE[i];
   497 			e2.iValue=~e2.iValue;
   498 			SEntry e3=pE[i];
   499 			e3.iKey=~e3.iKey;
   500 			TInt r=a.FindReverse(e1);
   501 			if (r!=i)
   502 				{
   503 				a.Close();
   504 				b.Close();
   505 				return -2;
   506 				}
   507 			r=a.FindReverse(e2);
   508 			if (r!=i)
   509 				{
   510 				a.Close();
   511 				b.Close();
   512 				return -3;
   513 				}
   514 			r=a.FindReverse(e3);
   515 			if (r>=0 && pE[r].iKey!=e3.iKey)
   516 				{
   517 				a.Close();
   518 				b.Close();
   519 				return -4;
   520 				}
   521 			r=b.FindReverse(e1);
   522 			if (r!=i)
   523 				{
   524 				a.Close();
   525 				b.Close();
   526 				return -5;
   527 				}
   528 			r=b.FindReverse(e3);
   529 			if (r!=i)
   530 				{
   531 				a.Close();
   532 				b.Close();
   533 				return -6;
   534 				}
   535 			r=b.FindReverse(e2);
   536 			if (r>=0 && pE[r].iValue!=e3.iValue)
   537 				{
   538 				a.Close();
   539 				b.Close();
   540 				return -7;
   541 				}
   542 			r=a.FindReverse(e1,SEntryIdentity);
   543 			if (r!=i)
   544 				{
   545 				a.Close();
   546 				b.Close();
   547 				return -8;
   548 				}
   549 			r=a.FindReverse(e2,SEntryIdentity);
   550 			if (r>=0 && pE[r]!=e3)
   551 				{
   552 				a.Close();
   553 				b.Close();
   554 				return -9;
   555 				}
   556 			r=a.FindReverse(e3,SEntryIdentity);
   557 			if (r>=0 && pE[r]!=e3)
   558 				{
   559 				a.Close();
   560 				b.Close();
   561 				return -10;
   562 				}
   563 			r=b.FindReverse(e1,SEntryIdentity);
   564 			if (r!=i)
   565 				{
   566 				a.Close();
   567 				b.Close();
   568 				return -11;
   569 				}
   570 			r=b.FindReverse(e3,SEntryIdentity);
   571 			if (r>=0 && pE[r]!=e3)
   572 				{
   573 				a.Close();
   574 				b.Close();
   575 				return -12;
   576 				}
   577 			r=b.FindReverse(e2,SEntryIdentity);
   578 			if (r>=0 && pE[r]!=e3)
   579 				{
   580 				a.Close();
   581 				b.Close();
   582 				return -13;
   583 				}
   584 			r=a.FindReverse(e1.iValue,CompareSEntryByKeyValue);
   585 			if (r!=i)
   586 				{
   587 				a.Close();
   588 				b.Close();
   589 				return -14;
   590 				}
   591 			r=a.FindReverse(e2.iValue,CompareSEntryByKeyValue);
   592 			if (r>=0 && pE[r].iValue!=e2.iValue)
   593 				{
   594 				a.Close();
   595 				b.Close();
   596 				return -15;
   597 				}			
   598 			r=b.FindReverse(e1.iKey,CompareSEntryByKeyKey);
   599 			if (r!=i)
   600 				{
   601 				a.Close();
   602 				b.Close();
   603 				return -16;
   604 				}
   605 			r=b.FindReverse(e3.iKey,CompareSEntryByKeyKey);
   606 			if (r>=0 && pE[r].iKey!=e3.iKey)
   607 				{
   608 				a.Close();
   609 				b.Close();
   610 				return -17;
   611 				}
   612 			}
   613 		delete[] pE;
   614 		a.Close();
   615 		b.Close();
   616 		}
   617 	return KErrNone;
   618 	}
   619 
   620 LOCAL_C TInt IntFindInOrderTest(TInt aCount, TInt aNumTests, TInt64 aMask)
   621 // require aRange*aCount<2^32
   622 	{
   623 	TInt n;
   624 	for (n=0; n<aNumTests; n++)
   625 		{
   626 		RArray<TInt64> a(aCount);
   627 		TInt64 *pA=new TInt64[aCount];
   628 		if (!pA)
   629 			{
   630 			a.Close();
   631 			return -65535;
   632 			}
   633 		TInt i=0;
   634 		TInt64 y=-256;
   635 		for(i=0; i<aCount; i++)
   636 			{
   637 			TInt64 x=Random64(aMask);	// this is always >=0
   638 			pA[i]=y;
   639 			a.Append(y);
   640 			y+=x;
   641 			}
   642 		if (a.Count()!=aCount)
   643 			{
   644 			a.Close();
   645 			return -1;
   646 			}
   647 		for (i=0; i<aCount; i++)
   648 			{
   649 			TInt r=a.FindInOrder(pA[i],Int64Order);
   650 			if (r<0 || pA[r]!=pA[i])
   651 				{
   652 				a.Close();
   653 				return -2;
   654 				}
   655 			TInt64 x=Random64(aMask);
   656 			r=a.FindInOrder(x,Int64Order);
   657 			if (r<0)
   658 				{
   659 				TInt j;
   660 				for (j=0; j<aCount; j++)
   661 					{
   662 					if (pA[j]==x)
   663 						{
   664 						a.Close();
   665 						return -3;
   666 						}
   667 					}
   668 				}
   669 			else if (pA[r]!=x)
   670 				{
   671 				a.Close();
   672 				return -4;
   673 				}
   674 			}
   675 		delete[] pA;
   676 		a.Close();
   677 		}
   678 	return KErrNone;
   679 	}
   680 
   681 LOCAL_C TInt EntryFindInOrderTest(TInt aCount, TInt aNumTests)
   682 // require aRange*aCount<2^32
   683 	{
   684 	TInt n;
   685 	for (n=0; n<aNumTests; n++)
   686 		{
   687 		RArray<SEntry> a(aCount,0);	// keyed on iKey
   688 		RArray<SEntry> b(aCount,4);	// keyed on iValue
   689 		SEntry *pE=new SEntry[aCount];
   690 		SEntry *pF=new SEntry[aCount];
   691 		if (!pE || !pF)
   692 			{
   693 			a.Close();
   694 			b.Close();
   695 			return -65535;
   696 			}
   697 		TInt i=0;
   698 		for(i=0; i<aCount; i++)
   699 			{
   700 			pE[i].iKey=i*19;
   701 			pE[i].iValue=Random();
   702 			a.Append(pE[i]);
   703 			pF[i].iKey=Random();
   704 			pF[i].iValue=i*i;
   705 			b.Append(pF[i]);
   706 			}
   707 		if (a.Count()!=aCount)
   708 			{
   709 			a.Close();
   710 			b.Close();
   711 			return -1;
   712 			}
   713 		if (b.Count()!=aCount)
   714 			{
   715 			a.Close();
   716 			b.Close();
   717 			return -2;
   718 			}
   719 		for (i=0; i<aCount; i++)
   720 			{
   721 			TInt r=a.FindInSignedKeyOrder(pE[i]);
   722 			if (r!=i)
   723 				{
   724 				a.Close();
   725 				b.Close();
   726 				return -2;
   727 				}
   728 			r=b.FindInSignedKeyOrder(pF[i]);
   729 			if (r!=i)
   730 				{
   731 				a.Close();
   732 				b.Close();
   733 				return -3;
   734 				}
   735 			TInt x=Random()&1023;
   736 			SEntry e;
   737 			e.iKey=x;
   738 			r=a.FindInSignedKeyOrder(e);
   739 			if (r<0)
   740 				{
   741 				if (x%19==0)
   742 					{
   743 					a.Close();
   744 					b.Close();
   745 					return -4;
   746 					}
   747 				}
   748 			else if (x!=r*19)
   749 				{
   750 				a.Close();
   751 				b.Close();
   752 				return -5;
   753 				}
   754 			TInt z=8+(Random()&127);
   755 			TInt y=Random()&15;
   756 			x=z*z+y;
   757 			e.iKey=-2;
   758 			e.iValue=x;
   759 			r=b.FindInSignedKeyOrder(e);
   760 			if (r<0)
   761 				{
   762 				if (y==0 && z<aCount)
   763 					{
   764 					a.Close();
   765 					b.Close();
   766 					return -6;
   767 					}
   768 				}
   769 			else if (y!=0)
   770 				{
   771 				a.Close();
   772 				b.Close();
   773 				return -7;
   774 				}
   775 			}
   776 		delete[] pE;
   777 		delete[] pF;
   778 		a.Close();
   779 		b.Close();
   780 		}
   781 	return KErrNone;
   782 	}
   783 
   784 LOCAL_C TInt IntInsertInOrderTest(TInt aCount, TInt aNumTests, TInt64 aMask)
   785 	{
   786 	TInt n;
   787 	for (n=0; n<aNumTests; n++)
   788 		{
   789 		RArray<TInt64> a(aCount);
   790 		RArray<TInt64> b(aCount);
   791 		RArray<TInt64> c(aCount);
   792 		TInt i;
   793 		TInt cc=0;
   794 		for (i=0; i<aCount; i++)
   795 			{
   796 			TInt64 x=Random64(aMask);
   797 			a.Append(x);
   798 			b.InsertInOrderAllowRepeats(x,Int64Order);
   799 			TInt r=c.InsertInOrder(x,Int64Order);
   800 			if (r==KErrNone)
   801 				cc++;
   802 			}
   803 		if (a.Count()!=aCount)
   804 			{
   805 			a.Close();
   806 			b.Close();
   807 			c.Close();
   808 			return -1;
   809 			}
   810 		if (b.Count()!=aCount)
   811 			{
   812 			a.Close();
   813 			b.Close();
   814 			c.Close();
   815 			return -2;
   816 			}
   817 		for (i=0; i<aCount-1; i++)
   818 			{
   819 			if (b[i]>b[i+1])
   820 				{
   821 				a.Close();
   822 				b.Close();
   823 				c.Close();
   824 				return -3;
   825 				}
   826 			}
   827 		for (i=0; i<aCount; i++)
   828 			{
   829 			if (a.Find(b[i],Int64Identity)<0)
   830 				{
   831 				a.Close();
   832 				b.Close();
   833 				c.Close();
   834 				return -4;
   835 				}
   836 			if (b.Find(a[i],Int64Identity)<0)
   837 				{
   838 				a.Close();
   839 				b.Close();
   840 				c.Close();
   841 				return -5;
   842 				}
   843 			if (c.Find(a[i],Int64Identity)<0)
   844 				{
   845 				a.Close();
   846 				b.Close();
   847 				c.Close();
   848 				return -6;
   849 				}
   850 			}
   851 		if (c.Count()!=cc)
   852 			{
   853 			a.Close();
   854 			b.Close();
   855 			c.Close();
   856 			return -7;
   857 			}
   858 		for (i=0; i<c.Count()-1; i++)
   859 			{
   860 			if (c[i]>=c[i+1])
   861 				{
   862 				a.Close();
   863 				b.Close();
   864 				c.Close();
   865 				return -8;
   866 				}
   867 			if (a.Find(c[i],Int64Identity)<0)
   868 				{
   869 				a.Close();
   870 				b.Close();
   871 				c.Close();
   872 				return -9;
   873 				}
   874 			}
   875 		a.Close();
   876 		b.Close();
   877 		c.Close();
   878 		}
   879 	return KErrNone;
   880 	}
   881 
   882 LOCAL_C TInt EntryInsertInOrderTest()
   883 	{
   884 	RArray<SEntry> a1(1024,0);	// keyed on iKey
   885 	RArray<SEntry> a2(1024,0);	// keyed on iKey
   886 	RArray<SEntry> b1(1024,4);	// keyed on iValue
   887 	RArray<SEntry> b2(1024,4);	// keyed on iValue
   888 	RArray<SEntry> c1(1024,0);	// keyed on iKey
   889 	RArray<SEntry> c2(1024,0);	// keyed on iKey
   890 	RArray<SEntry> d1(1024,4);	// keyed on iValue
   891 	RArray<SEntry> d2(1024,4);	// keyed on iValue
   892 	TInt i;
   893 	for (i=0; i<1024; i++)
   894 		{
   895 		SEntry e;
   896 		e.iValue=i-512;
   897 		e.iKey=(i&31)-16;
   898 		a1.InsertInSignedKeyOrderAllowRepeats(e);
   899 		a2.InsertInSignedKeyOrder(e);
   900 		b1.InsertInSignedKeyOrderAllowRepeats(e);
   901 		b2.InsertInSignedKeyOrder(e);
   902 		c1.InsertInUnsignedKeyOrderAllowRepeats(e);
   903 		c2.InsertInUnsignedKeyOrder(e);
   904 		d1.InsertInUnsignedKeyOrderAllowRepeats(e);
   905 		d2.InsertInUnsignedKeyOrder(e);
   906 		}
   907 	if (a1.Count()!=1024)
   908 		{
   909 		a1.Close();
   910 		a2.Close();
   911 		b1.Close();
   912 		b2.Close();
   913 		c1.Close();
   914 		c2.Close();
   915 		d1.Close();
   916 		d2.Close();
   917 		return -1;
   918 		}
   919 	if (b1.Count()!=1024)
   920 		{
   921 		a1.Close();
   922 		a2.Close();
   923 		b1.Close();
   924 		b2.Close();
   925 		c1.Close();
   926 		c2.Close();
   927 		d1.Close();
   928 		d2.Close();
   929 		return -2;
   930 		}
   931 	if (c1.Count()!=1024)
   932 		{
   933 		a1.Close();
   934 		a2.Close();
   935 		b1.Close();
   936 		b2.Close();
   937 		c1.Close();
   938 		c2.Close();
   939 		d1.Close();
   940 		d2.Close();
   941 		return -3;
   942 		}
   943 	if (d1.Count()!=1024)
   944 		{
   945 		a1.Close();
   946 		a2.Close();
   947 		b1.Close();
   948 		b2.Close();
   949 		c1.Close();
   950 		c2.Close();
   951 		d1.Close();
   952 		d2.Close();
   953 		return -4;
   954 		}
   955 	for (i=0; i<1024; i++)
   956 		{
   957 		SEntry e=a1[i];
   958 		if (e.iKey!=(i>>5)-16)
   959 			{
   960 			a1.Close();
   961 			a2.Close();
   962 			b1.Close();
   963 			b2.Close();
   964 			c1.Close();
   965 			c2.Close();
   966 			d1.Close();
   967 			d2.Close();
   968 			return -5;
   969 			}
   970 		if ( e.iValue!=(((i&31)<<5 | (i>>5))-512) )
   971 			{
   972 			a1.Close();
   973 			a2.Close();
   974 			b1.Close();
   975 			b2.Close();
   976 			c1.Close();
   977 			c2.Close();
   978 			d1.Close();
   979 			d2.Close();
   980 			return -6;
   981 			}
   982 		e=b1[i];
   983 		if (e.iKey!=((i&31)-16))
   984 			{
   985 			a1.Close();
   986 			a2.Close();
   987 			b1.Close();
   988 			b2.Close();
   989 			c1.Close();
   990 			c2.Close();
   991 			d1.Close();
   992 			d2.Close();
   993 			return -7;
   994 			}
   995 		if ( e.iValue!=(i-512) )
   996 			{
   997 			a1.Close();
   998 			a2.Close();
   999 			b1.Close();
  1000 			b2.Close();
  1001 			c1.Close();
  1002 			c2.Close();
  1003 			d1.Close();
  1004 			d2.Close();
  1005 			return -8;
  1006 			}
  1007 		e=c1[i];
  1008 		TInt j=i>>5;
  1009 		j^=16;
  1010 		j=((i&31)<<5)|j;
  1011 		SEntry f;
  1012 		f.iValue=j-512;
  1013 		f.iKey=(j&31)-16;
  1014 		if (e.iKey!=f.iKey)
  1015 			{
  1016 			a1.Close();
  1017 			a2.Close();
  1018 			b1.Close();
  1019 			b2.Close();
  1020 			c1.Close();
  1021 			c2.Close();
  1022 			d1.Close();
  1023 			d2.Close();
  1024 			return -9;
  1025 			}
  1026 		if (e.iValue!=f.iValue)
  1027 			{
  1028 			a1.Close();
  1029 			a2.Close();
  1030 			b1.Close();
  1031 			b2.Close();
  1032 			c1.Close();
  1033 			c2.Close();
  1034 			d1.Close();
  1035 			d2.Close();
  1036 			return -10;
  1037 			}
  1038 		e=d1[i];
  1039 		j=i^512;
  1040 		f.iValue=j-512;
  1041 		f.iKey=(j&31)-16;
  1042 		if (e.iKey!=f.iKey)
  1043 			{
  1044 			a1.Close();
  1045 			a2.Close();
  1046 			b1.Close();
  1047 			b2.Close();
  1048 			c1.Close();
  1049 			c2.Close();
  1050 			d1.Close();
  1051 			d2.Close();
  1052 			return -11;
  1053 			}
  1054 		if (e.iValue!=f.iValue)
  1055 			{
  1056 			a1.Close();
  1057 			a2.Close();
  1058 			b1.Close();
  1059 			b2.Close();
  1060 			c1.Close();
  1061 			c2.Close();
  1062 			d1.Close();
  1063 			d2.Close();
  1064 			return -12;
  1065 			}
  1066 		}
  1067 	if (a2.Count()!=32)
  1068 		{
  1069 		a1.Close();
  1070 		a2.Close();
  1071 		b1.Close();
  1072 		b2.Close();
  1073 		c1.Close();
  1074 		c2.Close();
  1075 		d1.Close();
  1076 		d2.Close();
  1077 		return -13;
  1078 		}
  1079 	if (b2.Count()!=1024)
  1080 		{
  1081 		a1.Close();
  1082 		a2.Close();
  1083 		b1.Close();
  1084 		b2.Close();
  1085 		c1.Close();
  1086 		c2.Close();
  1087 		d1.Close();
  1088 		d2.Close();
  1089 		return -14;
  1090 		}
  1091 	if (c2.Count()!=32)
  1092 		{
  1093 		a1.Close();
  1094 		a2.Close();
  1095 		b1.Close();
  1096 		b2.Close();
  1097 		c1.Close();
  1098 		c2.Close();
  1099 		d1.Close();
  1100 		d2.Close();
  1101 		return -15;
  1102 		}
  1103 	if (d2.Count()!=1024)
  1104 		{
  1105 		a1.Close();
  1106 		a2.Close();
  1107 		b1.Close();
  1108 		b2.Close();
  1109 		c1.Close();
  1110 		c2.Close();
  1111 		d1.Close();
  1112 		d2.Close();
  1113 		return -16;
  1114 		}
  1115 	for (i=0; i<1024; i++)
  1116 		{
  1117 		SEntry e=b2[i];
  1118 		if (e.iKey!=((i&31)-16))
  1119 			{
  1120 			a1.Close();
  1121 			a2.Close();
  1122 			b1.Close();
  1123 			b2.Close();
  1124 			c1.Close();
  1125 			c2.Close();
  1126 			d1.Close();
  1127 			d2.Close();
  1128 			return -17;
  1129 			}
  1130 		if ( e.iValue!=(i-512) )
  1131 			{
  1132 			a1.Close();
  1133 			a2.Close();
  1134 			b1.Close();
  1135 			b2.Close();
  1136 			c1.Close();
  1137 			c2.Close();
  1138 			d1.Close();
  1139 			d2.Close();
  1140 			return -18;
  1141 			}
  1142 		e=d2[i];
  1143 		TInt j=i^512;
  1144 		SEntry f;
  1145 		f.iValue=j-512;
  1146 		f.iKey=(j&31)-16;
  1147 		if (e.iKey!=f.iKey)
  1148 			{
  1149 			a1.Close();
  1150 			a2.Close();
  1151 			b1.Close();
  1152 			b2.Close();
  1153 			c1.Close();
  1154 			c2.Close();
  1155 			d1.Close();
  1156 			d2.Close();
  1157 			return -19;
  1158 			}
  1159 		if (e.iValue!=f.iValue)
  1160 			{
  1161 			a1.Close();
  1162 			a2.Close();
  1163 			b1.Close();
  1164 			b2.Close();
  1165 			c1.Close();
  1166 			c2.Close();
  1167 			d1.Close();
  1168 			d2.Close();
  1169 			return -20;
  1170 			}
  1171 		}
  1172 	for (i=0; i<31; i++)
  1173 		{
  1174 		SEntry e=a2[i];
  1175 		TInt j=i;
  1176 		SEntry f;
  1177 		f.iValue=j-512;
  1178 		f.iKey=(j&31)-16;
  1179 		if (e.iKey!=f.iKey)
  1180 			{
  1181 			a1.Close();
  1182 			a2.Close();
  1183 			b1.Close();
  1184 			b2.Close();
  1185 			c1.Close();
  1186 			c2.Close();
  1187 			d1.Close();
  1188 			d2.Close();
  1189 			return -21;
  1190 			}
  1191 		if (e.iValue!=f.iValue)
  1192 			{
  1193 			a1.Close();
  1194 			a2.Close();
  1195 			b1.Close();
  1196 			b2.Close();
  1197 			c1.Close();
  1198 			c2.Close();
  1199 			d1.Close();
  1200 			d2.Close();
  1201 			return -22;
  1202 			}
  1203 		e=c2[i];
  1204 		j=i^16;
  1205 		f.iValue=j-512;
  1206 		f.iKey=(j&31)-16;
  1207 		if (e.iKey!=f.iKey)
  1208 			{
  1209 			a1.Close();
  1210 			a2.Close();
  1211 			b1.Close();
  1212 			b2.Close();
  1213 			c1.Close();
  1214 			c2.Close();
  1215 			d1.Close();
  1216 			d2.Close();
  1217 			return -23;
  1218 			}
  1219 		if (e.iValue!=f.iValue)
  1220 			{
  1221 			a1.Close();
  1222 			a2.Close();
  1223 			b1.Close();
  1224 			b2.Close();
  1225 			c1.Close();
  1226 			c2.Close();
  1227 			d1.Close();
  1228 			d2.Close();
  1229 			return -24;
  1230 			}
  1231 		}
  1232 	a1.Close();
  1233 	a2.Close();
  1234 	b1.Close();
  1235 	b2.Close();
  1236 	c1.Close();
  1237 	c2.Close();
  1238 	d1.Close();
  1239 	d2.Close();
  1240 	return KErrNone;
  1241 	}
  1242 
  1243 LOCAL_C TInt IntSortTest(TInt aCount, TInt aNumTests, TInt64 aMask)
  1244 	{
  1245 	TInt n;
  1246 	for (n=0; n<aNumTests; n++)
  1247 		{
  1248 		RArray<TInt64> a(aCount);
  1249 		RArray<TInt64> b(aCount);
  1250 		TInt i;
  1251 		for (i=0; i<aCount; i++)
  1252 			{
  1253 			TInt64 x=Random64(aMask);
  1254 			a.Append(x);
  1255 			b.InsertInOrderAllowRepeats(x,Int64Order);
  1256 			}
  1257 		a.Sort(Int64Order);
  1258 		if (a.Count()!=aCount)
  1259 			{
  1260 			a.Close();
  1261 			b.Close();
  1262 			return -1;
  1263 			}
  1264 		if (b.Count()!=aCount)
  1265 			{
  1266 			a.Close();
  1267 			b.Close();
  1268 			return -2;
  1269 			}
  1270 		for (i=0; i<aCount; i++)
  1271 			{
  1272 			if (a[i]!=b[i])
  1273 				{
  1274 				a.Close();
  1275 				b.Close();
  1276 				return -3;
  1277 				}
  1278 			}
  1279 		a.Close();
  1280 		b.Close();
  1281 		}
  1282 	return KErrNone;
  1283 	}
  1284 
  1285 LOCAL_C TInt EntrySortTest(TInt aCount, TInt aNumTests)
  1286 	{
  1287 	TInt n;
  1288 	for (n=0; n<aNumTests; n++)
  1289 		{
  1290 		RArray<SEntry> a1(aCount,0);	// keyed on iKey
  1291 		RArray<SEntry> a2(aCount,0);	// keyed on iKey
  1292 		RArray<SEntry> b1(aCount,4);	// keyed on iValue
  1293 		RArray<SEntry> b2(aCount,4);	// keyed on iValue
  1294 		RArray<SEntry> c1(aCount,0);	// keyed on iKey
  1295 		RArray<SEntry> c2(aCount,0);	// keyed on iKey
  1296 		RArray<SEntry> d1(aCount,4);	// keyed on iValue
  1297 		RArray<SEntry> d2(aCount,4);	// keyed on iValue
  1298 		TInt i;
  1299 		for (i=0; i<aCount; i++)
  1300 			{
  1301 			SEntry e;
  1302 			e.iKey=Random();
  1303 			e.iValue=Random();
  1304 			a1.Append(e);
  1305 			a2.InsertInSignedKeyOrderAllowRepeats(e);
  1306 			b1.Append(e);
  1307 			b2.InsertInSignedKeyOrderAllowRepeats(e);
  1308 			c1.Append(e);
  1309 			c2.InsertInUnsignedKeyOrderAllowRepeats(e);
  1310 			d1.Append(e);
  1311 			d2.InsertInUnsignedKeyOrderAllowRepeats(e);
  1312 			}
  1313 		a1.SortSigned();
  1314 		b1.SortSigned();
  1315 		c1.SortUnsigned();
  1316 		d1.SortUnsigned();
  1317 		if (a1.Count()!=aCount)
  1318 			{
  1319 			a1.Close();
  1320 			a2.Close();
  1321 			b1.Close();
  1322 			b2.Close();
  1323 			c1.Close();
  1324 			c2.Close();
  1325 			d1.Close();
  1326 			d2.Close();
  1327 			return -1;
  1328 			}
  1329 		if (a2.Count()!=aCount)
  1330 			{
  1331 			a1.Close();
  1332 			a2.Close();
  1333 			b1.Close();
  1334 			b2.Close();
  1335 			c1.Close();
  1336 			c2.Close();
  1337 			d1.Close();
  1338 			d2.Close();
  1339 			return -2;
  1340 			}
  1341 		if (b1.Count()!=aCount)
  1342 			{
  1343 			a1.Close();
  1344 			a2.Close();
  1345 			b1.Close();
  1346 			b2.Close();
  1347 			c1.Close();
  1348 			c2.Close();
  1349 			d1.Close();
  1350 			d2.Close();
  1351 			return -3;
  1352 			}
  1353 		if (b2.Count()!=aCount)
  1354 			{
  1355 			a1.Close();
  1356 			a2.Close();
  1357 			b1.Close();
  1358 			b2.Close();
  1359 			c1.Close();
  1360 			c2.Close();
  1361 			d1.Close();
  1362 			d2.Close();
  1363 			return -4;
  1364 			}
  1365 		if (c1.Count()!=aCount)
  1366 			{
  1367 			a1.Close();
  1368 			a2.Close();
  1369 			b1.Close();
  1370 			b2.Close();
  1371 			c1.Close();
  1372 			c2.Close();
  1373 			d1.Close();
  1374 			d2.Close();
  1375 			return -5;
  1376 			}
  1377 		if (c2.Count()!=aCount)
  1378 			{
  1379 			a1.Close();
  1380 			a2.Close();
  1381 			b1.Close();
  1382 			b2.Close();
  1383 			c1.Close();
  1384 			c2.Close();
  1385 			d1.Close();
  1386 			d2.Close();
  1387 			return -6;
  1388 			}
  1389 		if (d1.Count()!=aCount)
  1390 			{
  1391 			a1.Close();
  1392 			a2.Close();
  1393 			b1.Close();
  1394 			b2.Close();
  1395 			c1.Close();
  1396 			c2.Close();
  1397 			d1.Close();
  1398 			d2.Close();
  1399 			return -7;
  1400 			}
  1401 		if (d2.Count()!=aCount)
  1402 			{
  1403 			a1.Close();
  1404 			a2.Close();
  1405 			b1.Close();
  1406 			b2.Close();
  1407 			c1.Close();
  1408 			c2.Close();
  1409 			d1.Close();
  1410 			d2.Close();
  1411 			return -8;
  1412 			}
  1413 		for (i=0; i<aCount; i++)
  1414 			{
  1415 			if (a1[i]!=a2[i])
  1416 				{
  1417 				a1.Close();
  1418 				a2.Close();
  1419 				b1.Close();
  1420 				b2.Close();
  1421 				c1.Close();
  1422 				c2.Close();
  1423 				d1.Close();
  1424 				d2.Close();
  1425 				return -9;
  1426 				}
  1427 			if (b1[i]!=b2[i])
  1428 				{
  1429 				a1.Close();
  1430 				a2.Close();
  1431 				b1.Close();
  1432 				b2.Close();
  1433 				c1.Close();
  1434 				c2.Close();
  1435 				d1.Close();
  1436 				d2.Close();
  1437 				return -10;
  1438 				}
  1439 			if (c1[i]!=c2[i])
  1440 				{
  1441 				a1.Close();
  1442 				a2.Close();
  1443 				b1.Close();
  1444 				b2.Close();
  1445 				c1.Close();
  1446 				c2.Close();
  1447 				d1.Close();
  1448 				d2.Close();
  1449 				return -11;
  1450 				}
  1451 			if (d1[i]!=d2[i])
  1452 				{
  1453 				a1.Close();
  1454 				a2.Close();
  1455 				b1.Close();
  1456 				b2.Close();
  1457 				c1.Close();
  1458 				c2.Close();
  1459 				d1.Close();
  1460 				d2.Close();
  1461 				return -12;
  1462 				}
  1463 			}
  1464 		a1.Close();
  1465 		a2.Close();
  1466 		b1.Close();
  1467 		b2.Close();
  1468 		c1.Close();
  1469 		c2.Close();
  1470 		d1.Close();
  1471 		d2.Close();
  1472 		}
  1473 	return KErrNone;
  1474 	}
  1475 
  1476 LOCAL_C TInt SortAccessBoundsTest(TInt aCount)
  1477 	{
  1478 	TInt bytes = aCount * sizeof(TInt);
  1479 	RChunk chunk;
  1480 	TInt r = chunk.CreateDoubleEndedLocal(4096, bytes + 4096, bytes + 8192);
  1481 	if (r != KErrNone)
  1482 		return r;
  1483 	TInt size = chunk.Size() / sizeof(TInt); // Now rounded up to page boundary
  1484 	TInt* data = (TInt*)(chunk.Base() + chunk.Bottom());
  1485 
  1486 	TInt i, j;
  1487 	
  1488 	for (i = 1 ; i < aCount ; ++i)
  1489 		{
  1490 		for (j = 0 ; j < i ; ++j)
  1491 			data[j] = Random();
  1492 		RArray<TInt> a(data, i);
  1493 		a.Sort();
  1494 		
  1495 		for (j = 0 ; j < i ; ++j)
  1496 			data[j] = Random();
  1497 		RArray<TUint> b((TUint*)data, i);
  1498 		b.Sort();
  1499 
  1500 		if (i % 2 == 0)
  1501 			{
  1502 			RArray<SEntry> c(sizeof(SEntry), (SEntry*)data, i / 2);
  1503 		
  1504 			for (j = 0 ; j < i ; ++j)
  1505 				data[j] = Random();
  1506 			c.SortSigned();
  1507 		
  1508 			for (j = 0 ; j < i ; ++j)
  1509 				data[j] = Random();
  1510 			c.SortUnsigned();
  1511 			}
  1512 		}
  1513 		
  1514 	for (i = 1 ; i < aCount ; ++i)
  1515 		{
  1516 		for (j = 0 ; j < i ; ++j)
  1517 			data[size - j - 1] = Random();
  1518 		RArray<TInt> a(data + size - i, i);
  1519 		a.Sort();
  1520 		
  1521 		for (j = 0 ; j < i ; ++j)
  1522 			data[size - j - 1] = Random();
  1523 		RArray<TUint> b((TUint*)(data + size - i), i);
  1524 		b.Sort();
  1525 
  1526 		if (i % 2 == 0)
  1527 			{
  1528 			RArray<SEntry> c(sizeof(SEntry), (SEntry*)(data + size - i), i / 2);
  1529 		
  1530 			for (j = 0 ; j < i ; ++j)
  1531 				data[size - j - 1] = Random();
  1532 			c.SortSigned();
  1533 		
  1534 			for (j = 0 ; j < i ; ++j)
  1535 				data[size - j - 1] = Random();
  1536 			c.SortUnsigned();
  1537 			}
  1538 		}
  1539 	
  1540 	chunk.Close();	
  1541 	return KErrNone;
  1542 	}
  1543 
  1544 LOCAL_C TInt SEntrySpecificFindTests(TInt aCount, TInt aNumTests, TInt aRange)
  1545 	{
  1546 	TInt n;
  1547 	TInt nmiss = 0;
  1548 	TInt nrpt = 0;
  1549 	TInt ntot = 0;
  1550 	for (n=0; n<aNumTests; n++)
  1551 		{
  1552 		RArray<SEntry> a;
  1553 		RArray<SEntry> b;
  1554 		RArray<SEntry> c;
  1555 		RArray<SEntry> d;
  1556 		TInt i;
  1557 		for (i=0; i<aCount; i++)
  1558 			{
  1559 			TInt x=Random()&aRange;
  1560 			x-=(aRange>>1);
  1561 			SEntry e;
  1562 			e.iKey = x;
  1563 			e.iValue = i;
  1564 			a.Append(e);
  1565 			c.Append(e);
  1566 			b.InsertInSignedKeyOrderAllowRepeats(e);
  1567 			d.InsertInUnsignedKeyOrderAllowRepeats(e);
  1568 			}
  1569 		a.Sort(&OrderSEntry2);
  1570 		c.Sort(&OrderSEntryU2);
  1571 		test(a.Count()==aCount);
  1572 		test(b.Count()==aCount);
  1573 		test(c.Count()==aCount);
  1574 		test(d.Count()==aCount);
  1575 		for (i=0; i<aCount; i++)
  1576 			{
  1577 			test(a[i]==b[i]);
  1578 			test(c[i]==d[i]);
  1579 			}
  1580 		for (i=-(aRange>>1); i<=(aRange>>1); ++i)
  1581 			{
  1582 			SEntry es;
  1583 			es.iKey = i;
  1584 			TInt fk = a.SpecificFindInSignedKeyOrder(es, EArrayFindMode_First);
  1585 			TInt lk = a.SpecificFindInSignedKeyOrder(es, EArrayFindMode_Last);
  1586 			TInt ak = a.SpecificFindInSignedKeyOrder(es, EArrayFindMode_Any);
  1587 			TInt fki, lki, aki;
  1588 			TInt fk2 = a.SpecificFindInSignedKeyOrder(es, fki, EArrayFindMode_First);
  1589 			TInt lk2 = a.SpecificFindInSignedKeyOrder(es, lki, EArrayFindMode_Last);
  1590 			TInt ak2 = a.SpecificFindInSignedKeyOrder(es, aki, EArrayFindMode_Any);
  1591 
  1592 			TInt first = a.SpecificFindInOrder(es, &OrderSEntry, EArrayFindMode_First);
  1593 			TInt last = a.SpecificFindInOrder(es, &OrderSEntry, EArrayFindMode_Last);
  1594 			TInt any = a.SpecificFindInOrder(es, &OrderSEntry, EArrayFindMode_Any);
  1595 			TInt fi, li, ai;
  1596 			TInt first2 = a.SpecificFindInOrder(es, fi, &OrderSEntry, EArrayFindMode_First);
  1597 			TInt last2 = a.SpecificFindInOrder(es, li, &OrderSEntry, EArrayFindMode_Last);
  1598 			TInt any2 = a.SpecificFindInOrder(es, ai, &OrderSEntry, EArrayFindMode_Any);
  1599 			++ntot;
  1600 			test(first == fk);
  1601 			test(last == lk);
  1602 			test(any == ak);
  1603 			test(first2 == fk2);
  1604 			test(last2 == lk2);
  1605 			test(any2 == ak2);
  1606 			test(fki == fi);
  1607 			test(lki == li);
  1608 			test(aki == ai);
  1609 			if (first < 0)
  1610 				{
  1611 				test(first == KErrNotFound);
  1612 				test(first == last);
  1613 				test(first == any);
  1614 				test(first == first2);
  1615 				test(first == last2);
  1616 				test(first == any2);
  1617 				test(fi == li);
  1618 				test(fi == ai);
  1619 				test(li==aCount || a[li].iKey>i);
  1620 				test(li==0 || a[li-1].iKey<i);
  1621 				++nmiss;
  1622 				}
  1623 			else
  1624 				{
  1625 				test(first2 == KErrNone);
  1626 				test(last2 == KErrNone);
  1627 				test(any2 == KErrNone);
  1628 				test(first == fi);
  1629 				test(last == li);
  1630 				test(any == ai);
  1631 				test(a[fi].iKey == i);
  1632 				test(a[li-1].iKey == i);
  1633 				test(li==aCount || a[li].iKey>i);
  1634 				test(ai>=fi && ai<li);
  1635 				test(a[ai].iKey == i);
  1636 				if (li-fi > 1)
  1637 					{
  1638 					++nrpt;
  1639 					TInt j;
  1640 					for (j=fi+1; j<li; ++j)
  1641 						test(a[j].iValue > a[j-1].iValue);
  1642 					}
  1643 				}
  1644 			}
  1645 		for (i=-(aRange>>1); i<=(aRange>>1); ++i)
  1646 			{
  1647 			TUint u = (TUint)i;
  1648 			SEntry eu;
  1649 			eu.iKey = i;
  1650 			TInt fk = c.SpecificFindInUnsignedKeyOrder(eu, EArrayFindMode_First);
  1651 			TInt lk = c.SpecificFindInUnsignedKeyOrder(eu, EArrayFindMode_Last);
  1652 			TInt ak = c.SpecificFindInUnsignedKeyOrder(eu, EArrayFindMode_Any);
  1653 			TInt fki, lki, aki;
  1654 			TInt fk2 = c.SpecificFindInUnsignedKeyOrder(eu, fki, EArrayFindMode_First);
  1655 			TInt lk2 = c.SpecificFindInUnsignedKeyOrder(eu, lki, EArrayFindMode_Last);
  1656 			TInt ak2 = c.SpecificFindInUnsignedKeyOrder(eu, aki, EArrayFindMode_Any);
  1657 
  1658 			TInt first = c.SpecificFindInOrder(eu, &OrderSEntryU, EArrayFindMode_First);
  1659 			TInt last = c.SpecificFindInOrder(eu, &OrderSEntryU, EArrayFindMode_Last);
  1660 			TInt any = c.SpecificFindInOrder(eu, &OrderSEntryU, EArrayFindMode_Any);
  1661 			TInt fi, li, ai;
  1662 			TInt first2 = c.SpecificFindInOrder(eu, fi, &OrderSEntryU, EArrayFindMode_First);
  1663 			TInt last2 = c.SpecificFindInOrder(eu, li, &OrderSEntryU, EArrayFindMode_Last);
  1664 			TInt any2 = c.SpecificFindInOrder(eu, ai, &OrderSEntryU, EArrayFindMode_Any);
  1665 			++ntot;
  1666 			test(first == fk);
  1667 			test(last == lk);
  1668 			test(any == ak);
  1669 			test(first2 == fk2);
  1670 			test(last2 == lk2);
  1671 			test(any2 == ak2);
  1672 			test(fki == fi);
  1673 			test(lki == li);
  1674 			test(aki == ai);
  1675 			if (first < 0)
  1676 				{
  1677 				test(first == KErrNotFound);
  1678 				test(first == last);
  1679 				test(first == any);
  1680 				test(first == first2);
  1681 				test(first == last2);
  1682 				test(first == any2);
  1683 				test(fi == li);
  1684 				test(fi == ai);
  1685 				test(li==aCount || TUint(c[li].iKey)>u);
  1686 				test(li==0 || TUint(c[li-1].iKey)<u);
  1687 				++nmiss;
  1688 				}
  1689 			else
  1690 				{
  1691 				test(first2 == KErrNone);
  1692 				test(last2 == KErrNone);
  1693 				test(any2 == KErrNone);
  1694 				test(first == fi);
  1695 				test(last == li);
  1696 				test(any == ai);
  1697 				test(c[fi].iKey == i);
  1698 				test(c[li-1].iKey == i);
  1699 				test(li==aCount || TUint(c[li].iKey)>u);
  1700 				test(ai>=fi && ai<li);
  1701 				test(c[ai].iKey == i);
  1702 				if (li-fi > 1)
  1703 					{
  1704 					++nrpt;
  1705 					TInt j;
  1706 					for (j=fi+1; j<li; ++j)
  1707 						test(c[j].iValue > c[j-1].iValue);
  1708 					}
  1709 				}
  1710 			}
  1711 		a.Close();
  1712 		b.Close();
  1713 		c.Close();
  1714 		d.Close();
  1715 		}
  1716 	test.Printf(_L("ntot=%d nmiss=%d nrpt=%d\n"), ntot, nmiss, nrpt);
  1717 	return KErrNone;
  1718 	}
  1719 
  1720 LOCAL_C void TestGrowCompress(RArray<TInt64>* a, ...)
  1721 	{
  1722 	SArray& pa = *(SArray*)a;
  1723 	VA_LIST list;
  1724 	VA_START(list, a);
  1725 	TInt64 x;
  1726 	FOREVER
  1727 		{
  1728 		TInt r = KErrNone;
  1729 		TInt action = VA_ARG(list, TInt);
  1730 		if (action == -99)
  1731 			break;
  1732 		TInt result = VA_ARG(list, TInt);
  1733 		TInt orig = pa.iAllocated;
  1734 		if (action == -1)
  1735 			a->Compress();
  1736 		else if (action == -2)
  1737 			a->GranularCompress();
  1738 		else if (action == -3)
  1739 			a->Remove(pa.iCount - 1);
  1740 		else if (action > 0)
  1741 			{
  1742 			TInt i;
  1743 			for (i=0; i<action && r==KErrNone; ++i)
  1744 				r = a->Append(x);
  1745 			}
  1746 		if ( (r<0 && (result!=r || pa.iAllocated!=orig)) || (r==0 && pa.iAllocated!=result) )
  1747 			{
  1748 			test.Printf(_L("Action %d Orig %d Expected %d r=%d newalloc=%d\n"), action, orig, result, r, pa.iAllocated);
  1749 			test(0);
  1750 			}
  1751 		}
  1752 	a->Reset();
  1753 	}
  1754 
  1755 LOCAL_C void TestGrowCompress()
  1756 	{
  1757 	RArray<TInt64> a;
  1758 	TestGrowCompress(&a, 1, 8, 7, 8, 1, 16, 7, 16, 1, 24, -2, 24, -1, 17, 1, 25, -2, 25, -3, 25, -2, 24, -99);
  1759 	TestGrowCompress(&a, 1, 8, 7, 8, 1, 16, 7, 16, 1, 24, -2, 24, -1, 17, 1, 25, -2, 25, -3, 25, -3, 25, -2, 16, -99);
  1760 
  1761 	RArray<TInt64> b(100);
  1762 	TestGrowCompress(&b, 1, 100, 99, 100, 1, 200, 99, 200, 1, 300, -2, 300, -1, 201, 1, 301, -2, 301, -3, 301, -2, 300, -99);
  1763 	TestGrowCompress(&b, 1, 100, 99, 100, 1, 200, 99, 200, 1, 300, -2, 300, -1, 201, 1, 301, -2, 301, -3, 301, -3, 301, -2, 200, -99);
  1764 
  1765 	RArray<TInt64> c(8, 0, 512);
  1766 	TestGrowCompress(&c, 1, 8, 7, 8, 1, 16, 7, 16, 1, 32, 15, 32, 1, 64, -2, 40, 7, 40, 1, 80, -1, 41, -99);
  1767 
  1768 	RArray<TInt64> d(20, 0, 640);
  1769 	TestGrowCompress(&d, 1, 20, 19, 20, 1, 50, 29, 50, 1, 125, -2, 60, -1, 51, -99);
  1770 
  1771 	RArray<TInt64> e(8, 0, 320);
  1772 	TestGrowCompress(&e, 1, 8, 7, 8, 1, 16, 7, 16, 1, 24, 7, 24, 1, 32, 7, 32, 1, 40, 7, 40, 1, 50, 9, 50, 1, 63, -99);
  1773 
  1774 	RArray<TInt64> f(2, 0, 257);
  1775 	TestGrowCompress(&f, 1, 2, 255, 256, 256, 512, 128, 640, 1, 643, 2, 643, 1, 646, -99);
  1776 	}
  1777 
  1778 GLDEF_C void DoSimpleArrayTests()
  1779 	{
  1780 	test.Start(_L("Simple Arrays..."));
  1781 
  1782 	test.Next(_L("AppendAndAccess tests..."));
  1783 	test.Next(_L("Count 10 Mask 0x0000000300000003"));
  1784 	test(IntAppendAndAccessTest(10,NUM_TESTS,MAKE_TINT64(0x3,0x3))==KErrNone);
  1785 	test.Next(_L("Count 100 Range all"));
  1786 	test(IntAppendAndAccessTest(100,NUM_TESTS,MAKE_TINT64(0xffffffff,0xffffffff))==KErrNone);
  1787 
  1788 	test.Next(_L("Remove test"));
  1789 	test(IntRemoveTest()==KErrNone);
  1790 
  1791 	test.Next(_L("Find tests..."));
  1792 	test.Next(_L("Count 10 Mask 0x0000000300000003"));
  1793 	test(IntFindTest(10,NUM_TESTS,MAKE_TINT64(3,3))==KErrNone);
  1794 	test.Next(_L("Count 100 Range all"));
  1795 	test(IntFindTest(100,NUM_TESTS,MAKE_TINT64(0xffffffff,0xffffffff))==KErrNone);
  1796 	test.Next(_L("SEntry find tests"));
  1797 	test(EntryFindTest(128,NUM_TESTS)==KErrNone);
  1798 	test.Next(_L("Find with equality operator tests"));
  1799 	test(FindWithEqualityOpTest()==KErrNone);
  1800 
  1801 
  1802 	test.Next(_L("FindReverse tests..."));
  1803 	test.Next(_L("Count 10 Mask 0x0000000300000003"));
  1804 	test(IntFindReverseTest(10,NUM_TESTS,MAKE_TINT64(3,3))==KErrNone);
  1805 	test.Next(_L("Count 100 Range all"));
  1806 	test(IntFindReverseTest(100,NUM_TESTS,MAKE_TINT64(0xffffffff,0xffffffff))==KErrNone);
  1807 	test.Next(_L("SEntry find tests"));
  1808 	test(EntryFindReverseTest(128,NUM_TESTS)==KErrNone);
  1809 
  1810 
  1811 	test.Next(_L("FindInOrder tests..."));
  1812 	test.Next(_L("Count 20 Mask 0x00000003C0000000"));
  1813 	test(IntFindInOrderTest(20,NUM_TESTS,MAKE_TINT64(0x3,0xc0000000))==KErrNone);
  1814 	test.Next(_L("Count 100 Mask 0x0000000FF0000000"));
  1815 	test(IntFindInOrderTest(100,NUM_TESTS,MAKE_TINT64(0xf,0xf0000000))==KErrNone);
  1816 	test.Next(_L("SEntry FindInOrder test"));
  1817 	test(EntryFindInOrderTest(128,NUM_TESTS)==KErrNone);
  1818 
  1819 	test.Next(_L("InsertInOrder tests..."));
  1820 	test.Next(_L("Count 50 Mask 0x00000003C0000000"));
  1821 	test(IntInsertInOrderTest(50,NUM_TESTS,MAKE_TINT64(0x3,0xc0000000))==KErrNone);
  1822 	test.Next(_L("Count 100 all"));
  1823 	test(IntInsertInOrderTest(100,NUM_TESTS,MAKE_TINT64(0xffffffff,0xffffffff))==KErrNone);
  1824 	test.Next(_L("SEntry InsertInOrder test"));
  1825 	test(EntryInsertInOrderTest()==KErrNone);
  1826 	
  1827 	test.Next(_L("Sort tests..."));
  1828 	test.Next(_L("Count 30 Mask 0x00000003C0000000"));
  1829 	test(IntSortTest(30,NUM_TESTS,MAKE_TINT64(0x3,0xc0000000))==KErrNone);
  1830 	test.Next(_L("Count 100 all"));
  1831 	test(IntSortTest(100,NUM_TESTS,MAKE_TINT64(0xffffffff,0xffffffff))==KErrNone);
  1832 	test.Next(_L("SEntry sort test"));
  1833 	test(EntrySortTest(128,NUM_TESTS)==KErrNone);
  1834 
  1835 	test.Next(_L("SEntrySpecificFindTests..."));
  1836 	test(SEntrySpecificFindTests(100, 10, 15)==KErrNone);
  1837 	test(SEntrySpecificFindTests(100, 10, 127)==KErrNone);
  1838 
  1839 	test.Next(_L("Test Grow/Compress"));
  1840 	TestGrowCompress();
  1841 
  1842 	test.Next(_L("Test sort methods don't access memory beyond the end of the array"));
  1843 	test(SortAccessBoundsTest(128)==KErrNone);
  1844 	
  1845 	test.End();
  1846 	}
  1847 
  1848 
  1849 GLDEF_C void DoArrayLeavingInterfaceTest()
  1850 	{
  1851 	TInt trap, ret(0);
  1852 	TInt64 Int64s[3];
  1853 	for (TInt i=0;i<3;i++) Int64s[i] = i;
  1854 
  1855 	RArray<TInt64> array;
  1856 	CleanupClosePushL(array);
  1857 
  1858 	test.Start(_L("Checking Leaving Arrays Interface..."));
  1859 
  1860 	test.Next(_L("AppendL test..."));
  1861 	TRAP(trap, array.AppendL(Int64s[0]));
  1862 	test(trap==KErrNone);
  1863 
  1864 	test.Next(_L("InsertL test..."));
  1865 	TRAP(trap, array.InsertL(Int64s[1],1));
  1866 	test(trap==KErrNone);
  1867 
  1868 	test.Next(_L("Test FindL(const T& anEntry) const..."));
  1869 	TRAP(trap, ret = array.FindL(Int64s[0]));
  1870 	test(trap==0);
  1871 	test(ret==0);
  1872 	TRAP(trap, ret = array.FindL(Int64s[2]));
  1873 	test(trap==KErrNotFound);
  1874 	
  1875 	test.Next(_L("Test FindL(const T& anEntry, TIdentityRelation<T> anIdentity) const..."));
  1876 	TRAP(trap, ret = array.FindL(Int64s[0],Int64Identity));
  1877 	test(trap==0);
  1878 	test(ret==0);
  1879 	TRAP(trap, ret = array.FindL(Int64s[2],Int64Identity));
  1880 	test(trap==KErrNotFound);
  1881 
  1882 	test.Next(_L("Test FindInSignedKeyOrderL(const T& anEntry) const..."));
  1883 	TRAP(trap, ret = array.FindInSignedKeyOrderL(Int64s[0]));
  1884 	test(trap==0);
  1885 	test(ret==0);
  1886 	TRAP(trap, ret = array.FindInSignedKeyOrderL(Int64s[2]));
  1887 	test(trap==KErrNotFound);
  1888 
  1889 	test.Next(_L("Test FindInUnsignedKeyOrderL(const T& anEntry) const..."));
  1890 	TRAP(trap, ret = array.FindInUnsignedKeyOrderL(Int64s[0]));
  1891 	test(trap==0);
  1892 	test(ret==0);
  1893 	TRAP(trap, ret = array.FindInUnsignedKeyOrderL(Int64s[2]));
  1894 	test(trap==KErrNotFound);
  1895 
  1896 	test.Next(_L("Test FindInOrderL(const T& anEntry, TLinearOrder<T> anOrder) const..."));
  1897 	TRAP(trap, ret = array.FindInOrderL(Int64s[0], Int64Order));
  1898 	test(trap==0);
  1899 	test(ret==0);
  1900 	TRAP(trap, ret = array.FindInOrderL(Int64s[2], Int64Order));
  1901 	test(trap==KErrNotFound);
  1902 
  1903 	test.Next(_L("Test FindInSignedKeyOrderL(const T& anEntry, TInt& anIndex) const..."));
  1904 	TRAP(trap, array.FindInSignedKeyOrderL(Int64s[0], ret));
  1905 	test(trap==0);
  1906 	test(ret==0);
  1907 	TRAP(trap, array.FindInSignedKeyOrderL(Int64s[2], ret));
  1908 	test(trap==KErrNotFound);
  1909 
  1910 	test.Next(_L("Test FindInUnsignedKeyOrderL(const T& anEntry, TInt& anIndex) const..."));
  1911 	TRAP(trap, array.FindInUnsignedKeyOrderL(Int64s[0], ret));
  1912 	test(trap==0);
  1913 	test(ret==0);
  1914 	TRAP(trap, array.FindInUnsignedKeyOrderL(Int64s[2], ret));
  1915 	test(trap==KErrNotFound);
  1916 
  1917 	test.Next(_L("Test FindInOrderL(const T& anEntry, TInt& anIndex, TLinearOrder<T> anOrder) const..."));
  1918 	TRAP(trap, array.FindInOrderL(Int64s[0], ret, Int64Order));
  1919 	test(trap==0);
  1920 	test(ret==0);
  1921 	TRAP(trap, array.FindInOrderL(Int64s[2], ret, Int64Order));
  1922 	test(trap==KErrNotFound);
  1923 
  1924 	test.Next(_L("Test SpecificFindInSignedKeyOrderL(const T& anEntry, TInt aMode) const..."));
  1925 	TRAP(trap, ret = array.SpecificFindInSignedKeyOrderL(Int64s[0], EArrayFindMode_First));
  1926 	test(trap==0);
  1927 	test(ret==0);
  1928 	TRAP(trap, ret = array.SpecificFindInSignedKeyOrderL(Int64s[2], EArrayFindMode_First));
  1929 	test(trap==KErrNotFound);
  1930 
  1931 	test.Next(_L("Test SpecificFindInUnsignedKeyOrderL(const T& anEntry, TInt aMode) const..."));
  1932 	TRAP(trap, ret = array.SpecificFindInUnsignedKeyOrderL(Int64s[0], EArrayFindMode_First));
  1933 	test(trap==0);
  1934 	test(ret==0);
  1935 	TRAP(trap, ret = array.SpecificFindInUnsignedKeyOrderL(Int64s[2], EArrayFindMode_First));
  1936 	test(trap==KErrNotFound);
  1937 
  1938 	test.Next(_L("Test SpecificFindInOrderL(const T& anEntry, TLinearOrder<T> anOrder, TInt aMode) const..."));
  1939 	TRAP(trap, ret = array.SpecificFindInOrderL(Int64s[0], Int64Order, EArrayFindMode_First));
  1940 	test(trap==0);
  1941 	test(ret==0);
  1942 	TRAP(trap, ret = array.SpecificFindInOrderL(Int64s[2], Int64Order, EArrayFindMode_First));
  1943 	test(trap==KErrNotFound);
  1944 
  1945 	test.Next(_L("Test SpecificFindInSignedKeyOrderL(const T& anEntry, TInt& anIndex, TInt aMode) const..."));
  1946 	TRAP(trap, array.SpecificFindInSignedKeyOrderL(Int64s[0], ret, EArrayFindMode_First));
  1947 	test(trap==0);
  1948 	test(ret==0);
  1949 	TRAP(trap, array.SpecificFindInSignedKeyOrderL(Int64s[2], ret, EArrayFindMode_First));
  1950 	test(trap==KErrNotFound);
  1951 
  1952 	test.Next(_L("Test SpecificFindInUnsignedKeyOrderL(const T& anEntry, TInt& anIndex, TInt aMode) const..."));
  1953 	TRAP(trap, array.SpecificFindInUnsignedKeyOrderL(Int64s[0], ret, EArrayFindMode_First));
  1954 	test(trap==0);
  1955 	test(ret==0);
  1956 	TRAP(trap, array.SpecificFindInUnsignedKeyOrderL(Int64s[2], ret, EArrayFindMode_First));
  1957 	test(trap==KErrNotFound);
  1958 
  1959 	test.Next(_L("Test SpecificFindInOrderL(const T& anEntry, TInt& anIndex, TLinearOrder<T> anOrder, TInt aMode) const..."));
  1960 	TRAP(trap, array.SpecificFindInOrderL(Int64s[0], ret, Int64Order, EArrayFindMode_First));
  1961 	test(trap==0);
  1962 	test(ret==0);
  1963 	TRAP(trap, array.SpecificFindInOrderL(Int64s[2], ret, Int64Order, EArrayFindMode_First));
  1964 	test(trap==KErrNotFound);
  1965 
  1966 	test.Next(_L("Test InsertInSignedKeyOrderL(const T& anEntry)..."));
  1967 	TRAP(trap, array.InsertInSignedKeyOrderL(Int64s[0]));
  1968 	test(trap==KErrAlreadyExists);
  1969 	TRAP(trap, array.InsertInSignedKeyOrderL(Int64s[2]));
  1970 	test(trap==KErrNone);
  1971 	array.Remove(2);
  1972 
  1973 	test.Next(_L("Test InsertInUnsignedKeyOrderL(const T& anEntry)..."));
  1974 	TRAP(trap, array.InsertInUnsignedKeyOrderL(Int64s[0]));
  1975 	test(trap==KErrAlreadyExists);
  1976 	TRAP(trap, array.InsertInUnsignedKeyOrderL(Int64s[2]));
  1977 	test(trap==KErrNone);
  1978 	array.Remove(2);
  1979 
  1980 	test.Next(_L("Test InsertInOrderL(const T& anEntry, TLinearOrder<T> anOrder)..."));
  1981 	TRAP(trap, array.InsertInOrderL(Int64s[0], Int64Order));
  1982 	test(trap==KErrAlreadyExists);
  1983 	TRAP(trap, array.InsertInOrderL(Int64s[2], Int64Order));
  1984 	test(trap==KErrNone);
  1985 	array.Remove(2);
  1986 
  1987 	test.Next(_L("Test InsertInSignedKeyOrderAllowRepeatsL(const T& anEntry)..."));
  1988 	TRAP(trap, array.InsertInSignedKeyOrderAllowRepeatsL(Int64s[2]));
  1989 	test(trap==KErrNone);
  1990 	array.Remove(2);
  1991 
  1992 	test.Next(_L("Test InsertInUnsignedKeyOrderAllowRepeatsL(const T& anEntry)..."));
  1993 	TRAP(trap, array.InsertInUnsignedKeyOrderAllowRepeatsL(Int64s[2]));
  1994 	test(trap==KErrNone);
  1995 	array.Remove(2);
  1996 
  1997 	test.Next(_L("Test InsertInOrderAllowRepeatsL(const T& anEntry, TLinearOrder<T> anOrder)..."));
  1998 	TRAP(trap, array.InsertInOrderAllowRepeatsL(Int64s[2], Int64Order));
  1999 	test(trap==KErrNone);
  2000 	array.Remove(2);
  2001 
  2002 	CleanupStack::PopAndDestroy(&array);
  2003 	test.End();
  2004 	}
  2005 
  2006 GLDEF_C void DoTIntArrayLeavingInterfaceTest()
  2007 	{
  2008 	TInt trap, ret(0);
  2009 	TInt Ints[3];
  2010 	for (TInt i=0;i<3;i++) Ints[i] = i;
  2011 
  2012 	RArray<TInt> array;
  2013 	CleanupClosePushL(array);
  2014 
  2015 	test.Start(_L("Checking Leaving Array<TInt> Interface..."));
  2016 
  2017 	test.Next(_L("AppendL test..."));
  2018 	TRAP(trap, array.AppendL(Ints[0]));
  2019 	test(trap==KErrNone);
  2020 
  2021 	test.Next(_L("InsertL test..."));
  2022 	TRAP(trap, array.InsertL(Ints[1],1));
  2023 	test(trap==KErrNone);
  2024 
  2025 	test.Next(_L("Test FindL(TInt anEntry) const..."));
  2026 	TRAP(trap, ret = array.FindL(Ints[0]));
  2027 	test(trap==0);
  2028 	test(ret==0);
  2029 	TRAP(trap, ret = array.FindL(Ints[2]));
  2030 	test(trap==KErrNotFound);
  2031 	
  2032 
  2033 	test.Next(_L("Test FindInOrderL(TInt anEntry) const..."));
  2034 	TRAP(trap, ret = array.FindInOrderL(Ints[0]));
  2035 	test(trap==0);
  2036 	test(ret==0);
  2037 	TRAP(trap, ret = array.FindInOrderL(Ints[2]));
  2038 	test(trap==KErrNotFound);
  2039 
  2040 	test.Next(_L("Test FindInOrderL(TInt anEntry, TInt& anIndex) const..."));
  2041 	TRAP(trap, array.FindInOrderL(Ints[0], ret));
  2042 	test(trap==0);
  2043 	test(ret==0);
  2044 	TRAP(trap, array.FindInOrderL(Ints[2], ret));
  2045 	test(trap==KErrNotFound);
  2046 
  2047 	test.Next(_L("Test SpecificFindInOrderL(TInt anEntry, TInt aMode) const..."));
  2048 	TRAP(trap, ret = array.SpecificFindInOrderL(Ints[0], EArrayFindMode_First));
  2049 	test(trap==0);
  2050 	test(ret==0);
  2051 	TRAP(trap, ret = array.SpecificFindInOrderL(Ints[2], EArrayFindMode_First));
  2052 	test(trap==KErrNotFound);
  2053 
  2054 	test.Next(_L("Test SpecificFindInOrderL(TInt anEntry, TInt& anIndex, TInt aMode) const..."));
  2055 	TRAP(trap, array.SpecificFindInOrderL(Ints[0], ret, EArrayFindMode_First));
  2056 	test(trap==0);
  2057 	test(ret==0);
  2058 	TRAP(trap, array.SpecificFindInOrderL(Ints[2], ret, EArrayFindMode_First));
  2059 	test(trap==KErrNotFound);
  2060 
  2061 	test.Next(_L("Test InsertInOrderL(TInt anEntry)..."));
  2062 	TRAP(trap, array.InsertInOrderL(Ints[0]));
  2063 	test(trap==KErrAlreadyExists);
  2064 	TRAP(trap, array.InsertInOrderL(Ints[2]));
  2065 	test(trap==KErrNone);
  2066 	array.Remove(2);
  2067 
  2068 	test.Next(_L("Test InsertInOrderAllowRepeatsL(TInt anEntry)..."));
  2069 	TRAP(trap, array.InsertInOrderAllowRepeatsL(Ints[2]));
  2070 	test(trap==KErrNone);
  2071 	array.Remove(2);
  2072 
  2073 	CleanupStack::PopAndDestroy(&array);
  2074 	test.End();
  2075 	}
  2076 
  2077 GLDEF_C void DoTUintArrayLeavingInterfaceTest()
  2078 	{
  2079 	TInt trap, ret(0);
  2080 	TInt UInts[3];
  2081 	for (TInt i=0;i<3;i++) UInts[i] = i;
  2082 
  2083 	RArray<TInt> array;
  2084 	CleanupClosePushL(array);
  2085 
  2086 	test.Start(_L("Checking Leaving Array<TUint> Interface..."));
  2087 
  2088 	test.Next(_L("AppendL test..."));
  2089 	TRAP(trap, array.AppendL(UInts[0]));
  2090 	test(trap==KErrNone);
  2091 
  2092 	test.Next(_L("InsertL test..."));
  2093 	TRAP(trap, array.InsertL(UInts[1],1));
  2094 	test(trap==KErrNone);
  2095 
  2096 	test.Next(_L("Test FindL(TUint anEntry) const..."));
  2097 	TRAP(trap, ret = array.FindL(UInts[0]));
  2098 	test(trap==0);
  2099 	test(ret==0);
  2100 	TRAP(trap, ret = array.FindL(UInts[2]));
  2101 	test(trap==KErrNotFound);
  2102 	
  2103 
  2104 	test.Next(_L("Test FindInOrderL(TUint anEntry) const..."));
  2105 	TRAP(trap, ret = array.FindInOrderL(UInts[0]));
  2106 	test(trap==0);
  2107 	test(ret==0);
  2108 	TRAP(trap, ret = array.FindInOrderL(UInts[2]));
  2109 	test(trap==KErrNotFound);
  2110 
  2111 	test.Next(_L("Test FindInOrderL(TUint anEntry, TInt& anIndex) const..."));
  2112 	TRAP(trap, array.FindInOrderL(UInts[0], ret));
  2113 	test(trap==0);
  2114 	test(ret==0);
  2115 	TRAP(trap, array.FindInOrderL(UInts[2], ret));
  2116 	test(trap==KErrNotFound);
  2117 
  2118 	test.Next(_L("Test SpecificFindInOrderL(TUint anEntry, TInt aMode) const..."));
  2119 	TRAP(trap, ret = array.SpecificFindInOrderL(UInts[0], EArrayFindMode_First));
  2120 	test(trap==0);
  2121 	test(ret==0);
  2122 	TRAP(trap, ret = array.SpecificFindInOrderL(UInts[2], EArrayFindMode_First));
  2123 	test(trap==KErrNotFound);
  2124 
  2125 	test.Next(_L("Test SpecificFindInOrderL(TUint anEntry, TInt& anIndex, TInt aMode) const..."));
  2126 	TRAP(trap, array.SpecificFindInOrderL(UInts[0], ret, EArrayFindMode_First));
  2127 	test(trap==0);
  2128 	test(ret==0);
  2129 	TRAP(trap, array.SpecificFindInOrderL(UInts[2], ret, EArrayFindMode_First));
  2130 	test(trap==KErrNotFound);
  2131 
  2132 	test.Next(_L("Test InsertInOrderL(TUint anEntry)..."));
  2133 	TRAP(trap, array.InsertInOrderL(UInts[0]));
  2134 	test(trap==KErrAlreadyExists);
  2135 	TRAP(trap, array.InsertInOrderL(UInts[2]));
  2136 	test(trap==KErrNone);
  2137 	array.Remove(2);
  2138 
  2139 	test.Next(_L("Test InsertInOrderAllowRepeatsL(TUint anEntry)..."));
  2140 	TRAP(trap, array.InsertInOrderAllowRepeatsL(UInts[2]));
  2141 	test(trap==KErrNone);
  2142 	array.Remove(2);
  2143 
  2144 	CleanupStack::PopAndDestroy(&array);
  2145 	test.End();
  2146 	}