First public contribution.
     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".
 
     8 // Initial Contributors:
 
     9 // Nokia Corporation - initial contribution.
 
    14 // e32test\buffer\smpl_arr.cpp
 
    21 #include <e32std_private.h>
 
    26 GLREF_C TInt Random();
 
    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);}
 
    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);
 
    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;
 
    61 LOCAL_C TInt64 Random64(TInt64& aMask)
 
    63 	TInt64 x = MAKE_TINT64(Random()&I64HIGH(aMask), Random()&I64LOW(aMask));
 
    67 LOCAL_C TInt IntAppendAndAccessTest(TInt aCount, TInt aNumTests, TInt64 aMask)
 
    70 	for (n=0; n<aNumTests; n++)
 
    72 		RArray<TInt64> a(aCount);
 
    73 		TInt64 *pA=new TInt64[aCount];
 
    80 		for (i=0; i<aCount; i++)
 
    82 			TInt64 x=Random64(aMask);
 
    86 		if (a.Count()!=aCount)
 
    91 		for (i=0; i<aCount; i++)
 
    98 			pA[i]=Random64(aMask);
 
   101 		if (a.Count()!=aCount)
 
   106 		for (i=0; i<aCount; i++)
 
   120 LOCAL_C TInt IntRemoveTest()
 
   128 		TInt64 x = MAKE_TINT64(i*i,i);
 
   135 		for (j=0; j<(2*i-2); j++)
 
   148 		TInt64 x = MAKE_TINT64(i*i*i*i,i*i);
 
   159 LOCAL_C TInt IntFindTest(TInt aCount, TInt aNumTests, TInt64 aMask)
 
   162 	for (n=0; n<aNumTests; n++)
 
   164 		RArray<TInt64> a(aCount);
 
   165 		TInt64 *pA=new TInt64[aCount];
 
   172 		for (i=0; i<aCount; i++)
 
   174 			pA[i]=Random64(aMask);
 
   177 		if (a.Count()!=aCount)
 
   182 		for (i=0; i<aCount; i++)
 
   184 			TInt r=a.Find(pA[i],Int64Identity);
 
   185 			if (r<0 || pA[i]!=pA[r] || r>i)
 
   197 template <class XTestInput>
 
   198 LOCAL_C TInt FindWithEqualityOp(XTestInput &aObject1, XTestInput &aObject2)
 
   200 	//Construct a suitable RArray
 
   201 	RArray<XTestInput> testRArray;
 
   203 	//Append the test objects to the RArray
 
   204 	testRArray.AppendL(aObject1);
 
   205 	testRArray.AppendL(aObject2);
 
   206 	testRArray.AppendL(aObject1);
 
   207 	testRArray.AppendL(aObject2);
 
   209 	//Demonstrate that "regular" Find() method returns incorrect result
 
   210 	TInt pos = KErrNotFound;
 
   211 	pos = testRArray.Find(aObject1);
 
   214 	pos = testRArray.Find(aObject2);
 
   218 	//Test the Find() method using TIdentityRelation default CTOR
 
   219 	pos = testRArray.Find(aObject1, TIdentityRelation<XTestInput>());
 
   222 	pos = testRArray.Find(aObject2, TIdentityRelation<XTestInput>());
 
   226 	//Test the FindReverse() method using TIdentityRelation default CTOR
 
   227 	pos = testRArray.FindReverse(aObject1, TIdentityRelation<XTestInput>());
 
   230 	pos = testRArray.FindReverse(aObject2, TIdentityRelation<XTestInput>());
 
   234 	//Objects have been found correctly if this point reached
 
   240 LOCAL_C TInt FindWithEqualityOpTest()
 
   242 	//Test "complex" objects which would work incorrectly with the regular Find() method
 
   247 	test(FindWithEqualityOp(p1, p2) == KErrNone);
 
   251 	test(FindWithEqualityOp(rect1, rect2) == KErrNone);
 
   253     TBuf<5> buf1(_L("test1"));
 
   254 	TBuf<5> buf2(_L("test2"));
 
   255 	test(FindWithEqualityOp(buf1, buf2) == KErrNone);
 
   260 LOCAL_C TInt EntryFindTest(TInt aCount, TInt aNumTests)
 
   263 	for (n=0; n<aNumTests; n++)
 
   265 		RArray<SEntry> a(aCount,0);	// keyed on iKey
 
   266 		RArray<SEntry> b(aCount,4);	// keyed on iValue
 
   267 		SEntry *pE=new SEntry[aCount];
 
   275 		for (i=0; i<aCount; i++)
 
   277 			pE[i].iValue=Random();
 
   282 		if (a.Count()!=aCount)
 
   288 		if (b.Count()!=aCount)
 
   294 		for (i=0; i<aCount; i++)
 
   298 			e2.iValue=~e2.iValue;
 
   316 			if (r>=0 && pE[r].iKey!=e3.iKey)
 
   337 			if (r>=0 && pE[r].iValue!=e3.iValue)
 
   343 			r=a.Find(e1,SEntryIdentity);
 
   350 			r=a.Find(e2,SEntryIdentity);
 
   351 			if (r>=0 && pE[r]!=e3)
 
   357 			r=a.Find(e3,SEntryIdentity);
 
   358 			if (r>=0 && pE[r]!=e3)
 
   364 			r=b.Find(e1,SEntryIdentity);
 
   371 			r=b.Find(e3,SEntryIdentity);
 
   372 			if (r>=0 && pE[r]!=e3)
 
   378 			r=b.Find(e2,SEntryIdentity);
 
   379 			if (r>=0 && pE[r]!=e3)
 
   385 			r=a.Find(e1.iValue,CompareSEntryByKeyValue);
 
   392 			r=a.Find(e2.iValue,CompareSEntryByKeyValue);
 
   393 			if (r>=0 && pE[r].iValue!=e2.iValue)
 
   399 			r=b.Find(e1.iKey,CompareSEntryByKeyKey);
 
   406 			r=b.Find(e3.iKey,CompareSEntryByKeyKey);
 
   407 			if (r>=0 && pE[r].iKey!=e3.iKey)
 
   421 LOCAL_C TInt IntFindReverseTest(TInt aCount, TInt aNumTests, TInt64 aMask)
 
   424 	for (n=0; n<aNumTests; n++)
 
   426 		RArray<TInt64> a(aCount);
 
   427 		TInt64 *pA=new TInt64[aCount];
 
   434 		for (i=0; i<aCount; i++)
 
   436 			pA[i]=Random64(aMask);
 
   439 		if (a.Count()!=aCount)
 
   444 		for (i=0; i<aCount; i++)
 
   446 			TInt r=a.FindReverse(pA[i],Int64Identity);
 
   447 			if (pA[i]!=pA[r] || r<i)
 
   459 LOCAL_C TInt EntryFindReverseTest(TInt aCount, TInt aNumTests)
 
   462 	for (n=0; n<aNumTests; n++)
 
   464 		RArray<SEntry> a(aCount,0);	// keyed on iKey
 
   465 		RArray<SEntry> b(aCount,4);	// keyed on iValue
 
   466 		SEntry *pE=new SEntry[aCount];
 
   474 		for (i=0; i<aCount; i++)
 
   476 			pE[i].iValue=Random();
 
   481 		if (a.Count()!=aCount)
 
   487 		if (b.Count()!=aCount)
 
   493 		for (i=0; i<aCount; i++)
 
   497 			e2.iValue=~e2.iValue;
 
   500 			TInt r=a.FindReverse(e1);
 
   515 			if (r>=0 && pE[r].iKey!=e3.iKey)
 
   536 			if (r>=0 && pE[r].iValue!=e3.iValue)
 
   542 			r=a.FindReverse(e1,SEntryIdentity);
 
   549 			r=a.FindReverse(e2,SEntryIdentity);
 
   550 			if (r>=0 && pE[r]!=e3)
 
   556 			r=a.FindReverse(e3,SEntryIdentity);
 
   557 			if (r>=0 && pE[r]!=e3)
 
   563 			r=b.FindReverse(e1,SEntryIdentity);
 
   570 			r=b.FindReverse(e3,SEntryIdentity);
 
   571 			if (r>=0 && pE[r]!=e3)
 
   577 			r=b.FindReverse(e2,SEntryIdentity);
 
   578 			if (r>=0 && pE[r]!=e3)
 
   584 			r=a.FindReverse(e1.iValue,CompareSEntryByKeyValue);
 
   591 			r=a.FindReverse(e2.iValue,CompareSEntryByKeyValue);
 
   592 			if (r>=0 && pE[r].iValue!=e2.iValue)
 
   598 			r=b.FindReverse(e1.iKey,CompareSEntryByKeyKey);
 
   605 			r=b.FindReverse(e3.iKey,CompareSEntryByKeyKey);
 
   606 			if (r>=0 && pE[r].iKey!=e3.iKey)
 
   620 LOCAL_C TInt IntFindInOrderTest(TInt aCount, TInt aNumTests, TInt64 aMask)
 
   621 // require aRange*aCount<2^32
 
   624 	for (n=0; n<aNumTests; n++)
 
   626 		RArray<TInt64> a(aCount);
 
   627 		TInt64 *pA=new TInt64[aCount];
 
   635 		for(i=0; i<aCount; i++)
 
   637 			TInt64 x=Random64(aMask);	// this is always >=0
 
   642 		if (a.Count()!=aCount)
 
   647 		for (i=0; i<aCount; i++)
 
   649 			TInt r=a.FindInOrder(pA[i],Int64Order);
 
   650 			if (r<0 || pA[r]!=pA[i])
 
   655 			TInt64 x=Random64(aMask);
 
   656 			r=a.FindInOrder(x,Int64Order);
 
   660 				for (j=0; j<aCount; j++)
 
   681 LOCAL_C TInt EntryFindInOrderTest(TInt aCount, TInt aNumTests)
 
   682 // require aRange*aCount<2^32
 
   685 	for (n=0; n<aNumTests; n++)
 
   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];
 
   698 		for(i=0; i<aCount; i++)
 
   701 			pE[i].iValue=Random();
 
   707 		if (a.Count()!=aCount)
 
   713 		if (b.Count()!=aCount)
 
   719 		for (i=0; i<aCount; i++)
 
   721 			TInt r=a.FindInSignedKeyOrder(pE[i]);
 
   728 			r=b.FindInSignedKeyOrder(pF[i]);
 
   735 			TInt x=Random()&1023;
 
   738 			r=a.FindInSignedKeyOrder(e);
 
   754 			TInt z=8+(Random()&127);
 
   759 			r=b.FindInSignedKeyOrder(e);
 
   762 				if (y==0 && z<aCount)
 
   784 LOCAL_C TInt IntInsertInOrderTest(TInt aCount, TInt aNumTests, TInt64 aMask)
 
   787 	for (n=0; n<aNumTests; n++)
 
   789 		RArray<TInt64> a(aCount);
 
   790 		RArray<TInt64> b(aCount);
 
   791 		RArray<TInt64> c(aCount);
 
   794 		for (i=0; i<aCount; i++)
 
   796 			TInt64 x=Random64(aMask);
 
   798 			b.InsertInOrderAllowRepeats(x,Int64Order);
 
   799 			TInt r=c.InsertInOrder(x,Int64Order);
 
   803 		if (a.Count()!=aCount)
 
   810 		if (b.Count()!=aCount)
 
   817 		for (i=0; i<aCount-1; i++)
 
   827 		for (i=0; i<aCount; i++)
 
   829 			if (a.Find(b[i],Int64Identity)<0)
 
   836 			if (b.Find(a[i],Int64Identity)<0)
 
   843 			if (c.Find(a[i],Int64Identity)<0)
 
   858 		for (i=0; i<c.Count()-1; i++)
 
   867 			if (a.Find(c[i],Int64Identity)<0)
 
   882 LOCAL_C TInt EntryInsertInOrderTest()
 
   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
 
   893 	for (i=0; i<1024; i++)
 
   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);
 
   907 	if (a1.Count()!=1024)
 
   919 	if (b1.Count()!=1024)
 
   931 	if (c1.Count()!=1024)
 
   943 	if (d1.Count()!=1024)
 
   955 	for (i=0; i<1024; i++)
 
   958 		if (e.iKey!=(i>>5)-16)
 
   970 		if ( e.iValue!=(((i&31)<<5 | (i>>5))-512) )
 
   983 		if (e.iKey!=((i&31)-16))
 
   995 		if ( e.iValue!=(i-512) )
 
  1026 		if (e.iValue!=f.iValue)
 
  1054 		if (e.iValue!=f.iValue)
 
  1079 	if (b2.Count()!=1024)
 
  1103 	if (d2.Count()!=1024)
 
  1115 	for (i=0; i<1024; i++)
 
  1118 		if (e.iKey!=((i&31)-16))
 
  1130 		if ( e.iValue!=(i-512) )
 
  1159 		if (e.iValue!=f.iValue)
 
  1172 	for (i=0; i<31; i++)
 
  1191 		if (e.iValue!=f.iValue)
 
  1219 		if (e.iValue!=f.iValue)
 
  1243 LOCAL_C TInt IntSortTest(TInt aCount, TInt aNumTests, TInt64 aMask)
 
  1246 	for (n=0; n<aNumTests; n++)
 
  1248 		RArray<TInt64> a(aCount);
 
  1249 		RArray<TInt64> b(aCount);
 
  1251 		for (i=0; i<aCount; i++)
 
  1253 			TInt64 x=Random64(aMask);
 
  1255 			b.InsertInOrderAllowRepeats(x,Int64Order);
 
  1258 		if (a.Count()!=aCount)
 
  1264 		if (b.Count()!=aCount)
 
  1270 		for (i=0; i<aCount; i++)
 
  1285 LOCAL_C TInt EntrySortTest(TInt aCount, TInt aNumTests)
 
  1288 	for (n=0; n<aNumTests; n++)
 
  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
 
  1299 		for (i=0; i<aCount; i++)
 
  1305 			a2.InsertInSignedKeyOrderAllowRepeats(e);
 
  1307 			b2.InsertInSignedKeyOrderAllowRepeats(e);
 
  1309 			c2.InsertInUnsignedKeyOrderAllowRepeats(e);
 
  1311 			d2.InsertInUnsignedKeyOrderAllowRepeats(e);
 
  1317 		if (a1.Count()!=aCount)
 
  1329 		if (a2.Count()!=aCount)
 
  1341 		if (b1.Count()!=aCount)
 
  1353 		if (b2.Count()!=aCount)
 
  1365 		if (c1.Count()!=aCount)
 
  1377 		if (c2.Count()!=aCount)
 
  1389 		if (d1.Count()!=aCount)
 
  1401 		if (d2.Count()!=aCount)
 
  1413 		for (i=0; i<aCount; i++)
 
  1476 LOCAL_C TInt SortAccessBoundsTest(TInt aCount)
 
  1478 	TInt bytes = aCount * sizeof(TInt);
 
  1480 	TInt r = chunk.CreateDoubleEndedLocal(4096, bytes + 4096, bytes + 8192);
 
  1483 	TInt size = chunk.Size() / sizeof(TInt); // Now rounded up to page boundary
 
  1484 	TInt* data = (TInt*)(chunk.Base() + chunk.Bottom());
 
  1488 	for (i = 1 ; i < aCount ; ++i)
 
  1490 		for (j = 0 ; j < i ; ++j)
 
  1492 		RArray<TInt> a(data, i);
 
  1495 		for (j = 0 ; j < i ; ++j)
 
  1497 		RArray<TUint> b((TUint*)data, i);
 
  1502 			RArray<SEntry> c(sizeof(SEntry), (SEntry*)data, i / 2);
 
  1504 			for (j = 0 ; j < i ; ++j)
 
  1508 			for (j = 0 ; j < i ; ++j)
 
  1514 	for (i = 1 ; i < aCount ; ++i)
 
  1516 		for (j = 0 ; j < i ; ++j)
 
  1517 			data[size - j - 1] = Random();
 
  1518 		RArray<TInt> a(data + size - i, i);
 
  1521 		for (j = 0 ; j < i ; ++j)
 
  1522 			data[size - j - 1] = Random();
 
  1523 		RArray<TUint> b((TUint*)(data + size - i), i);
 
  1528 			RArray<SEntry> c(sizeof(SEntry), (SEntry*)(data + size - i), i / 2);
 
  1530 			for (j = 0 ; j < i ; ++j)
 
  1531 				data[size - j - 1] = Random();
 
  1534 			for (j = 0 ; j < i ; ++j)
 
  1535 				data[size - j - 1] = Random();
 
  1544 LOCAL_C TInt SEntrySpecificFindTests(TInt aCount, TInt aNumTests, TInt aRange)
 
  1550 	for (n=0; n<aNumTests; n++)
 
  1557 		for (i=0; i<aCount; i++)
 
  1559 			TInt x=Random()&aRange;
 
  1566 			b.InsertInSignedKeyOrderAllowRepeats(e);
 
  1567 			d.InsertInUnsignedKeyOrderAllowRepeats(e);
 
  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++)
 
  1580 		for (i=-(aRange>>1); i<=(aRange>>1); ++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);
 
  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);
 
  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);
 
  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);
 
  1603 			test(first2 == fk2);
 
  1611 				test(first == KErrNotFound);
 
  1612 				test(first == last);
 
  1614 				test(first == first2);
 
  1615 				test(first == last2);
 
  1616 				test(first == any2);
 
  1619 				test(li==aCount || a[li].iKey>i);
 
  1620 				test(li==0 || a[li-1].iKey<i);
 
  1625 				test(first2 == KErrNone);
 
  1626 				test(last2 == KErrNone);
 
  1627 				test(any2 == KErrNone);
 
  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);
 
  1640 					for (j=fi+1; j<li; ++j)
 
  1641 						test(a[j].iValue > a[j-1].iValue);
 
  1645 		for (i=-(aRange>>1); i<=(aRange>>1); ++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);
 
  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);
 
  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);
 
  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);
 
  1669 			test(first2 == fk2);
 
  1677 				test(first == KErrNotFound);
 
  1678 				test(first == last);
 
  1680 				test(first == first2);
 
  1681 				test(first == last2);
 
  1682 				test(first == any2);
 
  1685 				test(li==aCount || TUint(c[li].iKey)>u);
 
  1686 				test(li==0 || TUint(c[li-1].iKey)<u);
 
  1691 				test(first2 == KErrNone);
 
  1692 				test(last2 == KErrNone);
 
  1693 				test(any2 == KErrNone);
 
  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);
 
  1706 					for (j=fi+1; j<li; ++j)
 
  1707 						test(c[j].iValue > c[j-1].iValue);
 
  1716 	test.Printf(_L("ntot=%d nmiss=%d nrpt=%d\n"), ntot, nmiss, nrpt);
 
  1720 LOCAL_C void TestGrowCompress(RArray<TInt64>* a, ...)
 
  1722 	SArray& pa = *(SArray*)a;
 
  1729 		TInt action = VA_ARG(list, TInt);
 
  1732 		TInt result = VA_ARG(list, TInt);
 
  1733 		TInt orig = pa.iAllocated;
 
  1736 		else if (action == -2)
 
  1737 			a->GranularCompress();
 
  1738 		else if (action == -3)
 
  1739 			a->Remove(pa.iCount - 1);
 
  1740 		else if (action > 0)
 
  1743 			for (i=0; i<action && r==KErrNone; ++i)
 
  1746 		if ( (r<0 && (result!=r || pa.iAllocated!=orig)) || (r==0 && pa.iAllocated!=result) )
 
  1748 			test.Printf(_L("Action %d Orig %d Expected %d r=%d newalloc=%d\n"), action, orig, result, r, pa.iAllocated);
 
  1755 LOCAL_C void TestGrowCompress()
 
  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);
 
  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);
 
  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);
 
  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);
 
  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);
 
  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);
 
  1778 GLDEF_C void DoSimpleArrayTests()
 
  1780 	test.Start(_L("Simple Arrays..."));
 
  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);
 
  1788 	test.Next(_L("Remove test"));
 
  1789 	test(IntRemoveTest()==KErrNone);
 
  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);
 
  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);
 
  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);
 
  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);
 
  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);
 
  1835 	test.Next(_L("SEntrySpecificFindTests..."));
 
  1836 	test(SEntrySpecificFindTests(100, 10, 15)==KErrNone);
 
  1837 	test(SEntrySpecificFindTests(100, 10, 127)==KErrNone);
 
  1839 	test.Next(_L("Test Grow/Compress"));
 
  1842 	test.Next(_L("Test sort methods don't access memory beyond the end of the array"));
 
  1843 	test(SortAccessBoundsTest(128)==KErrNone);
 
  1849 GLDEF_C void DoArrayLeavingInterfaceTest()
 
  1853 	for (TInt i=0;i<3;i++) Int64s[i] = i;
 
  1855 	RArray<TInt64> array;
 
  1856 	CleanupClosePushL(array);
 
  1858 	test.Start(_L("Checking Leaving Arrays Interface..."));
 
  1860 	test.Next(_L("AppendL test..."));
 
  1861 	TRAP(trap, array.AppendL(Int64s[0]));
 
  1862 	test(trap==KErrNone);
 
  1864 	test.Next(_L("InsertL test..."));
 
  1865 	TRAP(trap, array.InsertL(Int64s[1],1));
 
  1866 	test(trap==KErrNone);
 
  1868 	test.Next(_L("Test FindL(const T& anEntry) const..."));
 
  1869 	TRAP(trap, ret = array.FindL(Int64s[0]));
 
  1872 	TRAP(trap, ret = array.FindL(Int64s[2]));
 
  1873 	test(trap==KErrNotFound);
 
  1875 	test.Next(_L("Test FindL(const T& anEntry, TIdentityRelation<T> anIdentity) const..."));
 
  1876 	TRAP(trap, ret = array.FindL(Int64s[0],Int64Identity));
 
  1879 	TRAP(trap, ret = array.FindL(Int64s[2],Int64Identity));
 
  1880 	test(trap==KErrNotFound);
 
  1882 	test.Next(_L("Test FindInSignedKeyOrderL(const T& anEntry) const..."));
 
  1883 	TRAP(trap, ret = array.FindInSignedKeyOrderL(Int64s[0]));
 
  1886 	TRAP(trap, ret = array.FindInSignedKeyOrderL(Int64s[2]));
 
  1887 	test(trap==KErrNotFound);
 
  1889 	test.Next(_L("Test FindInUnsignedKeyOrderL(const T& anEntry) const..."));
 
  1890 	TRAP(trap, ret = array.FindInUnsignedKeyOrderL(Int64s[0]));
 
  1893 	TRAP(trap, ret = array.FindInUnsignedKeyOrderL(Int64s[2]));
 
  1894 	test(trap==KErrNotFound);
 
  1896 	test.Next(_L("Test FindInOrderL(const T& anEntry, TLinearOrder<T> anOrder) const..."));
 
  1897 	TRAP(trap, ret = array.FindInOrderL(Int64s[0], Int64Order));
 
  1900 	TRAP(trap, ret = array.FindInOrderL(Int64s[2], Int64Order));
 
  1901 	test(trap==KErrNotFound);
 
  1903 	test.Next(_L("Test FindInSignedKeyOrderL(const T& anEntry, TInt& anIndex) const..."));
 
  1904 	TRAP(trap, array.FindInSignedKeyOrderL(Int64s[0], ret));
 
  1907 	TRAP(trap, array.FindInSignedKeyOrderL(Int64s[2], ret));
 
  1908 	test(trap==KErrNotFound);
 
  1910 	test.Next(_L("Test FindInUnsignedKeyOrderL(const T& anEntry, TInt& anIndex) const..."));
 
  1911 	TRAP(trap, array.FindInUnsignedKeyOrderL(Int64s[0], ret));
 
  1914 	TRAP(trap, array.FindInUnsignedKeyOrderL(Int64s[2], ret));
 
  1915 	test(trap==KErrNotFound);
 
  1917 	test.Next(_L("Test FindInOrderL(const T& anEntry, TInt& anIndex, TLinearOrder<T> anOrder) const..."));
 
  1918 	TRAP(trap, array.FindInOrderL(Int64s[0], ret, Int64Order));
 
  1921 	TRAP(trap, array.FindInOrderL(Int64s[2], ret, Int64Order));
 
  1922 	test(trap==KErrNotFound);
 
  1924 	test.Next(_L("Test SpecificFindInSignedKeyOrderL(const T& anEntry, TInt aMode) const..."));
 
  1925 	TRAP(trap, ret = array.SpecificFindInSignedKeyOrderL(Int64s[0], EArrayFindMode_First));
 
  1928 	TRAP(trap, ret = array.SpecificFindInSignedKeyOrderL(Int64s[2], EArrayFindMode_First));
 
  1929 	test(trap==KErrNotFound);
 
  1931 	test.Next(_L("Test SpecificFindInUnsignedKeyOrderL(const T& anEntry, TInt aMode) const..."));
 
  1932 	TRAP(trap, ret = array.SpecificFindInUnsignedKeyOrderL(Int64s[0], EArrayFindMode_First));
 
  1935 	TRAP(trap, ret = array.SpecificFindInUnsignedKeyOrderL(Int64s[2], EArrayFindMode_First));
 
  1936 	test(trap==KErrNotFound);
 
  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));
 
  1942 	TRAP(trap, ret = array.SpecificFindInOrderL(Int64s[2], Int64Order, EArrayFindMode_First));
 
  1943 	test(trap==KErrNotFound);
 
  1945 	test.Next(_L("Test SpecificFindInSignedKeyOrderL(const T& anEntry, TInt& anIndex, TInt aMode) const..."));
 
  1946 	TRAP(trap, array.SpecificFindInSignedKeyOrderL(Int64s[0], ret, EArrayFindMode_First));
 
  1949 	TRAP(trap, array.SpecificFindInSignedKeyOrderL(Int64s[2], ret, EArrayFindMode_First));
 
  1950 	test(trap==KErrNotFound);
 
  1952 	test.Next(_L("Test SpecificFindInUnsignedKeyOrderL(const T& anEntry, TInt& anIndex, TInt aMode) const..."));
 
  1953 	TRAP(trap, array.SpecificFindInUnsignedKeyOrderL(Int64s[0], ret, EArrayFindMode_First));
 
  1956 	TRAP(trap, array.SpecificFindInUnsignedKeyOrderL(Int64s[2], ret, EArrayFindMode_First));
 
  1957 	test(trap==KErrNotFound);
 
  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));
 
  1963 	TRAP(trap, array.SpecificFindInOrderL(Int64s[2], ret, Int64Order, EArrayFindMode_First));
 
  1964 	test(trap==KErrNotFound);
 
  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);
 
  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);
 
  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);
 
  1987 	test.Next(_L("Test InsertInSignedKeyOrderAllowRepeatsL(const T& anEntry)..."));
 
  1988 	TRAP(trap, array.InsertInSignedKeyOrderAllowRepeatsL(Int64s[2]));
 
  1989 	test(trap==KErrNone);
 
  1992 	test.Next(_L("Test InsertInUnsignedKeyOrderAllowRepeatsL(const T& anEntry)..."));
 
  1993 	TRAP(trap, array.InsertInUnsignedKeyOrderAllowRepeatsL(Int64s[2]));
 
  1994 	test(trap==KErrNone);
 
  1997 	test.Next(_L("Test InsertInOrderAllowRepeatsL(const T& anEntry, TLinearOrder<T> anOrder)..."));
 
  1998 	TRAP(trap, array.InsertInOrderAllowRepeatsL(Int64s[2], Int64Order));
 
  1999 	test(trap==KErrNone);
 
  2002 	CleanupStack::PopAndDestroy(&array);
 
  2006 GLDEF_C void DoTIntArrayLeavingInterfaceTest()
 
  2010 	for (TInt i=0;i<3;i++) Ints[i] = i;
 
  2013 	CleanupClosePushL(array);
 
  2015 	test.Start(_L("Checking Leaving Array<TInt> Interface..."));
 
  2017 	test.Next(_L("AppendL test..."));
 
  2018 	TRAP(trap, array.AppendL(Ints[0]));
 
  2019 	test(trap==KErrNone);
 
  2021 	test.Next(_L("InsertL test..."));
 
  2022 	TRAP(trap, array.InsertL(Ints[1],1));
 
  2023 	test(trap==KErrNone);
 
  2025 	test.Next(_L("Test FindL(TInt anEntry) const..."));
 
  2026 	TRAP(trap, ret = array.FindL(Ints[0]));
 
  2029 	TRAP(trap, ret = array.FindL(Ints[2]));
 
  2030 	test(trap==KErrNotFound);
 
  2033 	test.Next(_L("Test FindInOrderL(TInt anEntry) const..."));
 
  2034 	TRAP(trap, ret = array.FindInOrderL(Ints[0]));
 
  2037 	TRAP(trap, ret = array.FindInOrderL(Ints[2]));
 
  2038 	test(trap==KErrNotFound);
 
  2040 	test.Next(_L("Test FindInOrderL(TInt anEntry, TInt& anIndex) const..."));
 
  2041 	TRAP(trap, array.FindInOrderL(Ints[0], ret));
 
  2044 	TRAP(trap, array.FindInOrderL(Ints[2], ret));
 
  2045 	test(trap==KErrNotFound);
 
  2047 	test.Next(_L("Test SpecificFindInOrderL(TInt anEntry, TInt aMode) const..."));
 
  2048 	TRAP(trap, ret = array.SpecificFindInOrderL(Ints[0], EArrayFindMode_First));
 
  2051 	TRAP(trap, ret = array.SpecificFindInOrderL(Ints[2], EArrayFindMode_First));
 
  2052 	test(trap==KErrNotFound);
 
  2054 	test.Next(_L("Test SpecificFindInOrderL(TInt anEntry, TInt& anIndex, TInt aMode) const..."));
 
  2055 	TRAP(trap, array.SpecificFindInOrderL(Ints[0], ret, EArrayFindMode_First));
 
  2058 	TRAP(trap, array.SpecificFindInOrderL(Ints[2], ret, EArrayFindMode_First));
 
  2059 	test(trap==KErrNotFound);
 
  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);
 
  2068 	test.Next(_L("Test InsertInOrderAllowRepeatsL(TInt anEntry)..."));
 
  2069 	TRAP(trap, array.InsertInOrderAllowRepeatsL(Ints[2]));
 
  2070 	test(trap==KErrNone);
 
  2073 	CleanupStack::PopAndDestroy(&array);
 
  2077 GLDEF_C void DoTUintArrayLeavingInterfaceTest()
 
  2081 	for (TInt i=0;i<3;i++) UInts[i] = i;
 
  2084 	CleanupClosePushL(array);
 
  2086 	test.Start(_L("Checking Leaving Array<TUint> Interface..."));
 
  2088 	test.Next(_L("AppendL test..."));
 
  2089 	TRAP(trap, array.AppendL(UInts[0]));
 
  2090 	test(trap==KErrNone);
 
  2092 	test.Next(_L("InsertL test..."));
 
  2093 	TRAP(trap, array.InsertL(UInts[1],1));
 
  2094 	test(trap==KErrNone);
 
  2096 	test.Next(_L("Test FindL(TUint anEntry) const..."));
 
  2097 	TRAP(trap, ret = array.FindL(UInts[0]));
 
  2100 	TRAP(trap, ret = array.FindL(UInts[2]));
 
  2101 	test(trap==KErrNotFound);
 
  2104 	test.Next(_L("Test FindInOrderL(TUint anEntry) const..."));
 
  2105 	TRAP(trap, ret = array.FindInOrderL(UInts[0]));
 
  2108 	TRAP(trap, ret = array.FindInOrderL(UInts[2]));
 
  2109 	test(trap==KErrNotFound);
 
  2111 	test.Next(_L("Test FindInOrderL(TUint anEntry, TInt& anIndex) const..."));
 
  2112 	TRAP(trap, array.FindInOrderL(UInts[0], ret));
 
  2115 	TRAP(trap, array.FindInOrderL(UInts[2], ret));
 
  2116 	test(trap==KErrNotFound);
 
  2118 	test.Next(_L("Test SpecificFindInOrderL(TUint anEntry, TInt aMode) const..."));
 
  2119 	TRAP(trap, ret = array.SpecificFindInOrderL(UInts[0], EArrayFindMode_First));
 
  2122 	TRAP(trap, ret = array.SpecificFindInOrderL(UInts[2], EArrayFindMode_First));
 
  2123 	test(trap==KErrNotFound);
 
  2125 	test.Next(_L("Test SpecificFindInOrderL(TUint anEntry, TInt& anIndex, TInt aMode) const..."));
 
  2126 	TRAP(trap, array.SpecificFindInOrderL(UInts[0], ret, EArrayFindMode_First));
 
  2129 	TRAP(trap, array.SpecificFindInOrderL(UInts[2], ret, EArrayFindMode_First));
 
  2130 	test(trap==KErrNotFound);
 
  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);
 
  2139 	test.Next(_L("Test InsertInOrderAllowRepeatsL(TUint anEntry)..."));
 
  2140 	TRAP(trap, array.InsertInOrderAllowRepeatsL(UInts[2]));
 
  2141 	test(trap==KErrNone);
 
  2144 	CleanupStack::PopAndDestroy(&array);