kerneltest/e32test/buffer/t_array.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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\t_array.cpp
       
    15 // Overview:
       
    16 // Simple array tests.
       
    17 // API Information:
       
    18 // RArray, RPointerArray.
       
    19 // Details:
       
    20 // - Create fixed length array of 32 and 64 bit integer objects, an array 
       
    21 // of pointers to objects and verify that they are created successfully. 
       
    22 // - Simulate heap allocation failure test for the current thread's heap, 
       
    23 // append some 32 & 64 bit integers to the created arrays and verify the 
       
    24 // returned errors are as expected.
       
    25 // - Append some 32, 64 bit integers to fixed length arrays of 32 and 64 
       
    26 // bit integer objects respectively, check that KErrNoMemory is returned 
       
    27 // as expected.
       
    28 // - Verify heap allocation granularity.
       
    29 // - Simulate heap allocation failure, attempt to insert an object into 
       
    30 // the arrays, verify failure as expected and verify that the array 
       
    31 // contents were not modified.
       
    32 // - Remove elements from the arrays and verify that the number of 
       
    33 // elements held in the arrays are as expected.
       
    34 // - Append and remove an element to each array (uncompressed) and check
       
    35 // that the number of elements held in the arrays are as expected.
       
    36 // - Simulate heap allocation failure, compress the arrays and verify 
       
    37 // that KErrNoMemory is returned on appending elements to the arrays.
       
    38 // - Reset the arrays and check the number of elements held in the arrays are 0.
       
    39 // - Append some 64 bit integer objects to the array of pointers to objects and 
       
    40 // verify that the number of elements held in the array is as expected.
       
    41 // - Empty the array of pointers, and verify that the heap has not been corrupted by 
       
    42 // any of the tests.
       
    43 // - Using a variety of random sized arrays, test RArray::FindInOrder and 
       
    44 // RPointerArray::FindInOrder, verify that the results are as expected.
       
    45 // - Using a variety of random sized arrays, test RArray::FindInSignedKeyOrder 
       
    46 // and RArray::FindInUnsignedKeyOrder, verify that the results are as expected.
       
    47 // - Using a variety of random sized arrays of a struct, test RArray::FindInUnsignedKeyOrder
       
    48 // an dRArray::FindInUnsignedKeyOrder, verify that the results are as expected.
       
    49 // - Using a variety of random sized arrays, test RPointerArray::FindInAddressOrder, 
       
    50 // verify that the results are as expected.
       
    51 // - Verify that the heap has not been corrupted by any of the tests.
       
    52 // - Tests for RArray and standard array objects:
       
    53 // - Append random numbers to the arrays and verify that the arrays are as expected. 
       
    54 // - Append and remove integers to an RArray, check the values are added and removed 
       
    55 // as expected.
       
    56 // - Append some random numbers, check that the numbers are found in the array using 
       
    57 // sequential and binary search techniques.
       
    58 // - Append some random numbers, insert them into the arrays allowing duplicates 
       
    59 // entries and without duplicate entries and check the numbers are found as expected.
       
    60 // - Insert some random numbers into the arrays allowing duplicates, and check the 
       
    61 // numbers are added as  expected.
       
    62 // - Insert a sequence of integers into an array, use the SpecificFindInOrder method 
       
    63 // and verify that results are as expected.
       
    64 // - Tests for 4 byte RArrays:
       
    65 // - Append random numbers to the arrays and verify that the arrays are as expected. 
       
    66 // - Append and remove integers to an RArray, check the values are added and removed 
       
    67 // as expected.
       
    68 // - Append some random numbers, check that the numbers are found in the array using 
       
    69 // sequential and binary search techniques.
       
    70 // - Append some random numbers, insert them into the arrays allowing duplicates 
       
    71 // entries and without duplicate entries and check the numbers are found as expected.
       
    72 // - Insert some random numbers into the arrays allowing duplicates, and check the 
       
    73 // numbers are added as  expected.
       
    74 // - Insert a sequence of integers into an array, use the SpecificFindInOrder method 
       
    75 // and verify that results are as expected.
       
    76 // - Verify that the heap has not been corrupted by any of the tests.
       
    77 // - Repeat the above test for arrays of unsigned integers, pointers, 64 bit integer 
       
    78 // array objects and array of pointers objects.
       
    79 // - Test and trap a variety of error conditions that cause the array functions to leave. 
       
    80 // Test on arrays of integers, pointers, unsigned integers and TInts.
       
    81 // - Verify that the heap has not been corrupted by any of the tests.
       
    82 // - Perform simple array tests by appending, finding, find in order, insert in order, 
       
    83 // sorting, growing and compressing arrays. Verify results are as expected.
       
    84 // - Perform a variety of speed tests on array objects.
       
    85 // - Test whether the heap has been corrupted by all the tests.
       
    86 // Platforms/Drives/Compatibility:
       
    87 // All 
       
    88 // Assumptions/Requirement/Pre-requisites:
       
    89 // Failures and causes:
       
    90 // Base Port information:
       
    91 // 
       
    92 //
       
    93 
       
    94 #include <e32test.h>
       
    95 #include <e32math.h>
       
    96 
       
    97 GLREF_C void DoSpeedTests();
       
    98 GLREF_C void DoIntArrayTests();
       
    99 GLREF_C void DoUintArrayTests();
       
   100 GLREF_C void DoPointerArrayTests();
       
   101 GLREF_C void DoPointerArrayLeavingInterfaceTest();
       
   102 GLREF_C void DoPointerArrayAnyTests();
       
   103 GLREF_C void DoPointerArrayAnyLeavingInterfaceTest();
       
   104 GLREF_C void DoArrayLeavingInterfaceTest();
       
   105 GLDEF_C void DoTIntArrayLeavingInterfaceTest();
       
   106 GLDEF_C void DoTUintArrayLeavingInterfaceTest();
       
   107 GLREF_C void DoSimpleArrayTests();
       
   108 GLREF_C void DoRArrayTests();
       
   109 
       
   110 GLDEF_C RTest test(_L("T_ARRAY"));
       
   111 
       
   112 static TInt64 seed = MAKE_TINT64(0xb504f333,0xf9de6484);
       
   113 GLDEF_C TInt Random()
       
   114 	{
       
   115 	// Using this formula ensures repeated numbers wont come up in the tests.
       
   116 	seed = ((TUint) (69069*seed + 41));
       
   117 	return (TInt) seed;
       
   118 	}
       
   119 
       
   120 #ifdef _DEBUG
       
   121 RArray<TInt> *TheIntArray;
       
   122 RPointerArray<TInt64> *ThePtrArray;
       
   123 RArray<TInt64> *TheSimpleArray;
       
   124 
       
   125 void DoAllocTests()
       
   126 	{
       
   127 	test.Next(_L("Testing alloc failure"));
       
   128 	TheIntArray = new RArray<TInt>(16);
       
   129 	test(TheIntArray!=NULL);
       
   130 	ThePtrArray = new RPointerArray<TInt64>;
       
   131 	test(ThePtrArray!=NULL);
       
   132 	TheSimpleArray = new RArray<TInt64>;
       
   133 	test(TheSimpleArray!=NULL);
       
   134 	__UHEAP_MARK;
       
   135 	__UHEAP_SETFAIL(RHeap::EDeterministic,1);
       
   136 	TInt64 x = MAKE_TINT64(0xb504f333,0xf9de6484);
       
   137 	TInt64 y = MAKE_TINT64(0xc90fdaa2,0xc2352168);
       
   138 	TInt i;
       
   139 	TInt r=TheIntArray->Append(0);
       
   140 	test(r==KErrNoMemory);
       
   141 	r=ThePtrArray->Append(&x);
       
   142 	test(r==KErrNoMemory);
       
   143 	r=TheSimpleArray->Append(x);
       
   144 	test(r==KErrNoMemory);
       
   145 	__UHEAP_RESET;
       
   146 	r=TheIntArray->Append(0);
       
   147 	test(r==KErrNone);
       
   148 	r=ThePtrArray->Append(&x);
       
   149 	test(r==KErrNone);
       
   150 	r=TheSimpleArray->Append(x);
       
   151 	test(r==KErrNone);
       
   152 	TUint8* p1=new TUint8[1024];	// alloc a big cell to block simple expansion
       
   153 	__UHEAP_SETFAIL(RHeap::EDeterministic,1);
       
   154 	test.Next(_L("Testing granularity"));
       
   155 	TInt n=0;
       
   156 	while(r==KErrNone)
       
   157 		{
       
   158 		n++;
       
   159 		r=TheIntArray->Append(0);
       
   160 		}
       
   161 	test(r==KErrNoMemory);
       
   162 	test(n==16);
       
   163 	test(TheIntArray->Count()==16);
       
   164 	r=KErrNone;
       
   165 	n=0;
       
   166 	while(r==KErrNone)
       
   167 		{
       
   168 		n++;
       
   169 		r=ThePtrArray->Append(&x);
       
   170 		}
       
   171 	test(r==KErrNoMemory);
       
   172 	test(n==8);
       
   173 	test(ThePtrArray->Count()==8);		// default
       
   174 	r=KErrNone;
       
   175 	n=0;
       
   176 	while(r==KErrNone)
       
   177 		{
       
   178 		n++;
       
   179 		r=TheSimpleArray->Append(x);
       
   180 		}
       
   181 	test(r==KErrNoMemory);
       
   182 	test(n==8);
       
   183 	test(TheSimpleArray->Count()==8);	// default
       
   184 
       
   185 	r=TheIntArray->Insert(1,1);
       
   186 	test(r==KErrNoMemory);
       
   187 	test(TheIntArray->Count()==16);
       
   188 	for (i=0; i<TheIntArray->Count(); i++)
       
   189 		{
       
   190 		test((*TheIntArray)[i]==0);
       
   191 		}
       
   192 	r=ThePtrArray->Insert(&y,1);
       
   193 	test(r==KErrNoMemory);
       
   194 	test(ThePtrArray->Count()==8);
       
   195 	for (i=0; i<ThePtrArray->Count(); i++)
       
   196 		{
       
   197 		test((*ThePtrArray)[i]==&x);
       
   198 		}
       
   199 	r=TheSimpleArray->Insert(y,1);
       
   200 	test(r==KErrNoMemory);
       
   201 	test(TheSimpleArray->Count()==8);
       
   202 	for (i=0; i<TheSimpleArray->Count(); i++)
       
   203 		{
       
   204 		test((*TheSimpleArray)[i]==x);
       
   205 		}
       
   206 
       
   207 	for (i=1; i<16; i++)
       
   208 		{
       
   209 		TheIntArray->Remove(1);
       
   210 		}
       
   211 	for (i=1; i<8; i++)
       
   212 		{
       
   213 		ThePtrArray->Remove(1);
       
   214 		}
       
   215 	for (i=1; i<8; i++)
       
   216 		{
       
   217 		TheSimpleArray->Remove(1);
       
   218 		}
       
   219 	test(TheIntArray->Count()==1);
       
   220 	test(ThePtrArray->Count()==1);
       
   221 	test(TheSimpleArray->Count()==1);
       
   222 
       
   223 	__UHEAP_RESET;
       
   224 	TAny* p2=User::Alloc(48);
       
   225 	TAny* p3=User::Alloc(24);
       
   226 	TAny* p4=User::Alloc(24);
       
   227 	__UHEAP_SETFAIL(RHeap::EDeterministic,1);
       
   228 	r=TheIntArray->Append(0);
       
   229 	test(r==KErrNone);
       
   230 	r=ThePtrArray->Append(&x);
       
   231 	test(r==KErrNone);
       
   232 	r=TheSimpleArray->Append(x);
       
   233 	test(r==KErrNone);
       
   234 	test(TheIntArray->Count()==2);
       
   235 	test(ThePtrArray->Count()==2);
       
   236 	test(TheSimpleArray->Count()==2);
       
   237 	TheIntArray->Remove(1);
       
   238 	ThePtrArray->Remove(1);
       
   239 	TheSimpleArray->Remove(1);
       
   240 	test(TheIntArray->Count()==1);
       
   241 	test(ThePtrArray->Count()==1);
       
   242 	test(TheSimpleArray->Count()==1);
       
   243 	TheIntArray->Compress();
       
   244 	ThePtrArray->Compress();
       
   245 	TheSimpleArray->Compress();
       
   246 	User::Free(p2);
       
   247 	User::Free(p3);
       
   248 	User::Free(p4);
       
   249 	__UHEAP_RESET;
       
   250 	p2=User::Alloc(48);
       
   251 	p3=User::Alloc(24);
       
   252 	p4=User::Alloc(24);
       
   253 	__UHEAP_SETFAIL(RHeap::EDeterministic,1);
       
   254 	r=TheIntArray->Append(0);
       
   255 	test(r==KErrNoMemory);
       
   256 	r=ThePtrArray->Append(&x);
       
   257 	test(r==KErrNoMemory);
       
   258 	r=TheSimpleArray->Append(x);
       
   259 	test(r==KErrNoMemory);
       
   260 	TheIntArray->Reset();
       
   261 	ThePtrArray->Reset();
       
   262 	TheSimpleArray->Reset();
       
   263 	test(TheIntArray->Count()==0);
       
   264 	test(ThePtrArray->Count()==0);
       
   265 	test(TheSimpleArray->Count()==0);
       
   266 	delete p1;
       
   267 	User::Free(p2);
       
   268 	User::Free(p3);
       
   269 	User::Free(p4);
       
   270 	__UHEAP_RESET;
       
   271 	test.Next(_L("ResetAndDestroy"));
       
   272 	TInt64 *i1=new TInt64;
       
   273 	TInt64 *i2=new TInt64;
       
   274 	TInt64 *i3=new TInt64;
       
   275 	TInt64 *i4=new TInt64;
       
   276 	ThePtrArray->Append(i1);
       
   277 	ThePtrArray->Append(i2);
       
   278 	ThePtrArray->Append(i3);
       
   279 	ThePtrArray->Append(i4);
       
   280 	test(ThePtrArray->Count()==4);
       
   281 	ThePtrArray->ResetAndDestroy();
       
   282 	__UHEAP_MARKEND;
       
   283 	TheIntArray->Close();
       
   284 	delete TheIntArray;
       
   285 	ThePtrArray->Close();
       
   286 	delete ThePtrArray;
       
   287 	TheSimpleArray->Close();
       
   288 	delete TheSimpleArray;
       
   289 	}
       
   290 #endif
       
   291 
       
   292 class RHeapMonitor : public RAllocator
       
   293 	{
       
   294 public:
       
   295 	static RHeapMonitor& Install();
       
   296 	void Uninstall();
       
   297 	RHeapMonitor();
       
   298 public:
       
   299 	virtual TAny* Alloc(TInt);
       
   300 	virtual void Free(TAny*);
       
   301 	virtual TAny* ReAlloc(TAny*, TInt, TInt);
       
   302 	virtual TInt AllocLen(const TAny*) const;
       
   303 	virtual TInt Compress();
       
   304 	virtual void Reset();
       
   305 	virtual TInt AllocSize(TInt&) const;
       
   306 	virtual TInt Available(TInt&) const;
       
   307 	virtual TInt DebugFunction(TInt, TAny*, TAny*);
       
   308 	virtual TInt Extension_(TUint, TAny*&, TAny*);
       
   309 public:
       
   310 	RAllocator* iOrig;
       
   311 	TInt iAllocs;
       
   312 	TInt iFailedAllocs;
       
   313 	TInt iFrees;
       
   314 	TInt iReallocs;
       
   315 	TInt iFailedReallocs;
       
   316 	};
       
   317 
       
   318 RHeapMonitor::RHeapMonitor()
       
   319 	{
       
   320 	iOrig = &User::Allocator();
       
   321 	iAllocs = 0;
       
   322 	iFailedAllocs = 0;
       
   323 	iFrees = 0;
       
   324 	iReallocs = 0;
       
   325 	iFailedReallocs = 0;
       
   326 	}
       
   327 
       
   328 RHeapMonitor& RHeapMonitor::Install()
       
   329 	{
       
   330 	RHeapMonitor* m = new RHeapMonitor;
       
   331 	test(m!=0);
       
   332 	RAllocator* orig = User::SwitchAllocator(m);
       
   333 	test(orig == m->iOrig);
       
   334 	return *m;
       
   335 	}
       
   336 
       
   337 void RHeapMonitor::Uninstall()
       
   338 	{
       
   339 	RAllocator* m = User::SwitchAllocator(iOrig);
       
   340 	test(m == this);
       
   341 	delete this;
       
   342 	}
       
   343 
       
   344 TAny* RHeapMonitor::Alloc(TInt a)
       
   345 	{
       
   346 	++iAllocs;
       
   347 	TAny* p = iOrig->Alloc(a);
       
   348 	if (!p) ++iFailedAllocs;
       
   349 	return p;
       
   350 	}
       
   351 
       
   352 void RHeapMonitor::Free(TAny* a)
       
   353 	{
       
   354 	if (a) ++iFrees;
       
   355 	iOrig->Free(a);
       
   356 	}
       
   357 
       
   358 TAny* RHeapMonitor::ReAlloc(TAny* aCell, TInt aSize, TInt aMode)
       
   359 	{
       
   360 	if (aCell && aSize>0)
       
   361 		++iReallocs;
       
   362 	else if (aCell)
       
   363 		++iFrees;
       
   364 	else
       
   365 		++iAllocs;
       
   366 	TAny* p = iOrig->ReAlloc(aCell, aSize, aMode);
       
   367 	if (!p && aSize>0)
       
   368 		{
       
   369 		if (aCell)
       
   370 			++iFailedReallocs;
       
   371 		else
       
   372 			++iFailedAllocs;
       
   373 		}
       
   374 	return p;
       
   375 	}
       
   376 
       
   377 TInt RHeapMonitor::AllocLen(const TAny* a) const
       
   378 	{
       
   379 	return iOrig->AllocLen(a);
       
   380 	}
       
   381 
       
   382 TInt RHeapMonitor::Compress()
       
   383 	{
       
   384 	return iOrig->Compress();
       
   385 	}
       
   386 
       
   387 void RHeapMonitor::Reset()
       
   388 	{
       
   389 	iOrig->Reset();
       
   390 	}
       
   391 
       
   392 TInt RHeapMonitor::AllocSize(TInt& a) const
       
   393 	{
       
   394 	return iOrig->AllocSize(a);
       
   395 	}
       
   396 
       
   397 TInt RHeapMonitor::Available(TInt& a) const
       
   398 	{
       
   399 	return iOrig->Available(a);
       
   400 	}
       
   401 
       
   402 TInt RHeapMonitor::DebugFunction(TInt aFunc, TAny* a1, TAny* a2)
       
   403 	{
       
   404 	return iOrig->DebugFunction(aFunc, a1, a2);
       
   405 	}
       
   406 
       
   407 TInt RHeapMonitor::Extension_(TUint, TAny*&, TAny*)
       
   408 	{
       
   409 	return KErrExtensionNotSupported;
       
   410 	}
       
   411 
       
   412 template<class T>
       
   413 void TestReserveT()
       
   414 	{
       
   415 	RHeapMonitor& m = RHeapMonitor::Install();
       
   416 	TInt r;
       
   417 	RArray<T> a(1);
       
   418 	test(a.Count()==0);
       
   419 	test(m.iAllocs==0);
       
   420 	test(a.Append(1)==KErrNone);
       
   421 	test(m.iAllocs==1);
       
   422 	test(m.iReallocs==0);
       
   423 	test(a.Append(2)==KErrNone);
       
   424 	test(m.iReallocs==1);	// should have realloc'd
       
   425 	a.Close();
       
   426 	test(m.iFrees==1);
       
   427 	test(m.iAllocs==1);
       
   428 	test(m.iReallocs==1);
       
   429 	test(a.Count()==0);
       
   430 	test(a.Reserve(2)==KErrNone);
       
   431 	test(m.iAllocs==2);
       
   432 	TRAP(r,a.ReserveL(2));
       
   433 	test(r==KErrNone);
       
   434 	test(m.iFrees==1);
       
   435 	test(m.iAllocs==2);
       
   436 	test(m.iReallocs==1);
       
   437 	test(a.Append(1)==KErrNone);
       
   438 	test(m.iFrees==1);
       
   439 	test(m.iAllocs==2);
       
   440 	test(m.iReallocs==1);
       
   441 	test(a.Append(2)==KErrNone);
       
   442 	test(m.iFrees==1);
       
   443 	test(m.iAllocs==2);
       
   444 	test(m.iReallocs==1);	// shouldn't have realloc'd
       
   445 	test(a.Append(3)==KErrNone);
       
   446 	test(m.iFrees==1);
       
   447 	test(m.iAllocs==2);
       
   448 	test(m.iReallocs==2);	// should have realloc'd
       
   449 	a.Close();
       
   450 	test(m.iFrees==2);
       
   451 	test(m.iAllocs==2);
       
   452 	test(m.iReallocs==2);
       
   453 	test(a.Count()==0);
       
   454 	test(a.Reserve(2)==KErrNone);
       
   455 	test(m.iFrees==2);
       
   456 	test(m.iAllocs==3);
       
   457 	test(m.iReallocs==2);
       
   458 	test(a.Append(1)==KErrNone);
       
   459 	test(m.iFrees==2);
       
   460 	test(m.iAllocs==3);
       
   461 	test(m.iReallocs==2);
       
   462 	test(a.Append(2)==KErrNone);
       
   463 	test(m.iFrees==2);
       
   464 	test(m.iAllocs==3);
       
   465 	test(m.iReallocs==2);
       
   466 	test(a.Reserve(0x20000000)==KErrNoMemory);
       
   467 	test(m.iFrees==2);
       
   468 	test(m.iAllocs==3);
       
   469 	test(m.iReallocs==2);
       
   470 	test(m.iFrees==2);
       
   471 	test(m.iAllocs==3);
       
   472 	test(m.iReallocs==2);
       
   473 	test(a.Reserve(8)==KErrNone);
       
   474 	test(m.iFrees==2);
       
   475 	test(m.iAllocs==3);
       
   476 	test(m.iReallocs==3);
       
   477 	test(a.Append(3)==KErrNone);
       
   478 	test(a.Append(4)==KErrNone);
       
   479 	test(a.Append(5)==KErrNone);
       
   480 	test(a.Append(6)==KErrNone);
       
   481 	test(a.Append(7)==KErrNone);
       
   482 	test(a.Append(8)==KErrNone);
       
   483 	test(a.Count()==8);
       
   484 	test(m.iFrees==2);
       
   485 	test(m.iAllocs==3);
       
   486 	test(m.iReallocs==3);
       
   487 	TInt i;
       
   488 	for (i=0; i<=8; ++i)
       
   489 		{
       
   490 		test(a.Reserve(i)==KErrNone);
       
   491 		test(m.iFrees==2);
       
   492 		test(m.iAllocs==3);
       
   493 		test(m.iReallocs==3);
       
   494 		}
       
   495 	test(a.Append(9)==KErrNone);
       
   496 	test(m.iFrees==2);
       
   497 	test(m.iAllocs==3);
       
   498 	test(m.iReallocs==4);
       
   499 	a.Close();
       
   500 	test(m.iFrees==3);
       
   501 	test(m.iAllocs==3);
       
   502 	test(m.iReallocs==4);
       
   503 #ifdef _DEBUG
       
   504 	__UHEAP_FAILNEXT(1);
       
   505 	test(a.Count()==0);
       
   506 	test(a.Reserve(0)==KErrNone);
       
   507 	test(m.iFrees==3);
       
   508 	test(m.iAllocs==3);
       
   509 	test(m.iReallocs==4);
       
   510 	test(m.iFailedAllocs==0);
       
   511 	test(a.Reserve(1)==KErrNoMemory);
       
   512 	test(m.iFrees==3);
       
   513 	test(m.iAllocs==4);
       
   514 	test(m.iReallocs==4);
       
   515 	test(m.iFailedAllocs==1);
       
   516 	test(a.Reserve(1)==KErrNone);
       
   517 	test(m.iFrees==3);
       
   518 	test(m.iAllocs==5);
       
   519 	test(m.iReallocs==4);
       
   520 	test(m.iFailedAllocs==1);
       
   521 	a.Close();
       
   522 	test(m.iFrees==4);
       
   523 	test(m.iAllocs==5);
       
   524 	test(m.iReallocs==4);
       
   525 	test(m.iFailedAllocs==1);
       
   526 #endif
       
   527 	m.Uninstall();
       
   528 	TUint count = 0x80000000u / sizeof(T);
       
   529 
       
   530 	// don't do this in the heap monitored section because
       
   531 	// throwing a C++ exception allocates and frees memory
       
   532 	TRAP(r,a.ReserveL(count));
       
   533 	test(r==KErrNoMemory);
       
   534 	}
       
   535 
       
   536 void TestReserve()
       
   537 	{
       
   538 	test.Start(_L("Test Reserve()"));
       
   539 	__UHEAP_MARK;
       
   540 
       
   541 	TestReserveT<TInt>();
       
   542 	TestReserveT<TInt64>();
       
   543 
       
   544 	__UHEAP_MARKEND;
       
   545 	test.End();
       
   546 	}
       
   547 
       
   548 GLDEF_C TInt E32Main()
       
   549 	{
       
   550 
       
   551 	CTrapCleanup* trapHandler=CTrapCleanup::New();
       
   552 	test(trapHandler!=NULL);
       
   553 
       
   554 	test.Title();
       
   555 	test.Start(_L("Simple array tests"));
       
   556 #ifdef _DEBUG
       
   557 	DoAllocTests();
       
   558 #endif
       
   559 	TestReserve();
       
   560 	__UHEAP_MARK;
       
   561 	DoRArrayTests();
       
   562 	__UHEAP_MARKEND;
       
   563 	__UHEAP_MARK;
       
   564 	DoIntArrayTests();
       
   565 	__UHEAP_MARKEND;
       
   566 	__UHEAP_MARK;
       
   567 	DoUintArrayTests();
       
   568 	__UHEAP_MARKEND;
       
   569 	__UHEAP_MARK;
       
   570 	DoPointerArrayTests();
       
   571 	__UHEAP_MARKEND;
       
   572 	__UHEAP_MARK;
       
   573 	TRAPD(ret,DoArrayLeavingInterfaceTest());
       
   574 	test(ret==KErrNone);
       
   575 	__UHEAP_MARKEND;
       
   576 	__UHEAP_MARK;
       
   577 	TRAP(ret,DoPointerArrayLeavingInterfaceTest());
       
   578 	test(ret==KErrNone);
       
   579 	__UHEAP_MARKEND;
       
   580 	__UHEAP_MARK;
       
   581 	TRAP(ret,DoTIntArrayLeavingInterfaceTest());
       
   582 	test(ret==KErrNone);
       
   583 	__UHEAP_MARKEND;
       
   584 	__UHEAP_MARK;
       
   585 	TRAP(ret,DoTUintArrayLeavingInterfaceTest());
       
   586 	test(ret==KErrNone);
       
   587 	__UHEAP_MARKEND;
       
   588 	__UHEAP_MARK;
       
   589 	DoSimpleArrayTests();
       
   590 	__UHEAP_MARKEND;
       
   591 	__UHEAP_MARK;
       
   592 	DoPointerArrayAnyTests();
       
   593 	__UHEAP_MARKEND;
       
   594 	__UHEAP_MARK;
       
   595 	TRAP(ret,DoPointerArrayAnyLeavingInterfaceTest());
       
   596 	test(ret==KErrNone);
       
   597 	__UHEAP_MARKEND;
       
   598 	__UHEAP_MARK;
       
   599 	DoSpeedTests();
       
   600 	__UHEAP_MARKEND;
       
   601 	test.End();
       
   602 
       
   603 	delete trapHandler;
       
   604 	return KErrNone;
       
   605 	}