os/kernelhwsrv/kerneltest/e32test/buffer/t_array.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/buffer/t_array.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,605 @@
     1.4 +// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\buffer\t_array.cpp
    1.18 +// Overview:
    1.19 +// Simple array tests.
    1.20 +// API Information:
    1.21 +// RArray, RPointerArray.
    1.22 +// Details:
    1.23 +// - Create fixed length array of 32 and 64 bit integer objects, an array 
    1.24 +// of pointers to objects and verify that they are created successfully. 
    1.25 +// - Simulate heap allocation failure test for the current thread's heap, 
    1.26 +// append some 32 & 64 bit integers to the created arrays and verify the 
    1.27 +// returned errors are as expected.
    1.28 +// - Append some 32, 64 bit integers to fixed length arrays of 32 and 64 
    1.29 +// bit integer objects respectively, check that KErrNoMemory is returned 
    1.30 +// as expected.
    1.31 +// - Verify heap allocation granularity.
    1.32 +// - Simulate heap allocation failure, attempt to insert an object into 
    1.33 +// the arrays, verify failure as expected and verify that the array 
    1.34 +// contents were not modified.
    1.35 +// - Remove elements from the arrays and verify that the number of 
    1.36 +// elements held in the arrays are as expected.
    1.37 +// - Append and remove an element to each array (uncompressed) and check
    1.38 +// that the number of elements held in the arrays are as expected.
    1.39 +// - Simulate heap allocation failure, compress the arrays and verify 
    1.40 +// that KErrNoMemory is returned on appending elements to the arrays.
    1.41 +// - Reset the arrays and check the number of elements held in the arrays are 0.
    1.42 +// - Append some 64 bit integer objects to the array of pointers to objects and 
    1.43 +// verify that the number of elements held in the array is as expected.
    1.44 +// - Empty the array of pointers, and verify that the heap has not been corrupted by 
    1.45 +// any of the tests.
    1.46 +// - Using a variety of random sized arrays, test RArray::FindInOrder and 
    1.47 +// RPointerArray::FindInOrder, verify that the results are as expected.
    1.48 +// - Using a variety of random sized arrays, test RArray::FindInSignedKeyOrder 
    1.49 +// and RArray::FindInUnsignedKeyOrder, verify that the results are as expected.
    1.50 +// - Using a variety of random sized arrays of a struct, test RArray::FindInUnsignedKeyOrder
    1.51 +// an dRArray::FindInUnsignedKeyOrder, verify that the results are as expected.
    1.52 +// - Using a variety of random sized arrays, test RPointerArray::FindInAddressOrder, 
    1.53 +// verify that the results are as expected.
    1.54 +// - Verify that the heap has not been corrupted by any of the tests.
    1.55 +// - Tests for RArray and standard array objects:
    1.56 +// - Append random numbers to the arrays and verify that the arrays are as expected. 
    1.57 +// - Append and remove integers to an RArray, check the values are added and removed 
    1.58 +// as expected.
    1.59 +// - Append some random numbers, check that the numbers are found in the array using 
    1.60 +// sequential and binary search techniques.
    1.61 +// - Append some random numbers, insert them into the arrays allowing duplicates 
    1.62 +// entries and without duplicate entries and check the numbers are found as expected.
    1.63 +// - Insert some random numbers into the arrays allowing duplicates, and check the 
    1.64 +// numbers are added as  expected.
    1.65 +// - Insert a sequence of integers into an array, use the SpecificFindInOrder method 
    1.66 +// and verify that results are as expected.
    1.67 +// - Tests for 4 byte RArrays:
    1.68 +// - Append random numbers to the arrays and verify that the arrays are as expected. 
    1.69 +// - Append and remove integers to an RArray, check the values are added and removed 
    1.70 +// as expected.
    1.71 +// - Append some random numbers, check that the numbers are found in the array using 
    1.72 +// sequential and binary search techniques.
    1.73 +// - Append some random numbers, insert them into the arrays allowing duplicates 
    1.74 +// entries and without duplicate entries and check the numbers are found as expected.
    1.75 +// - Insert some random numbers into the arrays allowing duplicates, and check the 
    1.76 +// numbers are added as  expected.
    1.77 +// - Insert a sequence of integers into an array, use the SpecificFindInOrder method 
    1.78 +// and verify that results are as expected.
    1.79 +// - Verify that the heap has not been corrupted by any of the tests.
    1.80 +// - Repeat the above test for arrays of unsigned integers, pointers, 64 bit integer 
    1.81 +// array objects and array of pointers objects.
    1.82 +// - Test and trap a variety of error conditions that cause the array functions to leave. 
    1.83 +// Test on arrays of integers, pointers, unsigned integers and TInts.
    1.84 +// - Verify that the heap has not been corrupted by any of the tests.
    1.85 +// - Perform simple array tests by appending, finding, find in order, insert in order, 
    1.86 +// sorting, growing and compressing arrays. Verify results are as expected.
    1.87 +// - Perform a variety of speed tests on array objects.
    1.88 +// - Test whether the heap has been corrupted by all the tests.
    1.89 +// Platforms/Drives/Compatibility:
    1.90 +// All 
    1.91 +// Assumptions/Requirement/Pre-requisites:
    1.92 +// Failures and causes:
    1.93 +// Base Port information:
    1.94 +// 
    1.95 +//
    1.96 +
    1.97 +#include <e32test.h>
    1.98 +#include <e32math.h>
    1.99 +
   1.100 +GLREF_C void DoSpeedTests();
   1.101 +GLREF_C void DoIntArrayTests();
   1.102 +GLREF_C void DoUintArrayTests();
   1.103 +GLREF_C void DoPointerArrayTests();
   1.104 +GLREF_C void DoPointerArrayLeavingInterfaceTest();
   1.105 +GLREF_C void DoPointerArrayAnyTests();
   1.106 +GLREF_C void DoPointerArrayAnyLeavingInterfaceTest();
   1.107 +GLREF_C void DoArrayLeavingInterfaceTest();
   1.108 +GLDEF_C void DoTIntArrayLeavingInterfaceTest();
   1.109 +GLDEF_C void DoTUintArrayLeavingInterfaceTest();
   1.110 +GLREF_C void DoSimpleArrayTests();
   1.111 +GLREF_C void DoRArrayTests();
   1.112 +
   1.113 +GLDEF_C RTest test(_L("T_ARRAY"));
   1.114 +
   1.115 +static TInt64 seed = MAKE_TINT64(0xb504f333,0xf9de6484);
   1.116 +GLDEF_C TInt Random()
   1.117 +	{
   1.118 +	// Using this formula ensures repeated numbers wont come up in the tests.
   1.119 +	seed = ((TUint) (69069*seed + 41));
   1.120 +	return (TInt) seed;
   1.121 +	}
   1.122 +
   1.123 +#ifdef _DEBUG
   1.124 +RArray<TInt> *TheIntArray;
   1.125 +RPointerArray<TInt64> *ThePtrArray;
   1.126 +RArray<TInt64> *TheSimpleArray;
   1.127 +
   1.128 +void DoAllocTests()
   1.129 +	{
   1.130 +	test.Next(_L("Testing alloc failure"));
   1.131 +	TheIntArray = new RArray<TInt>(16);
   1.132 +	test(TheIntArray!=NULL);
   1.133 +	ThePtrArray = new RPointerArray<TInt64>;
   1.134 +	test(ThePtrArray!=NULL);
   1.135 +	TheSimpleArray = new RArray<TInt64>;
   1.136 +	test(TheSimpleArray!=NULL);
   1.137 +	__UHEAP_MARK;
   1.138 +	__UHEAP_SETFAIL(RHeap::EDeterministic,1);
   1.139 +	TInt64 x = MAKE_TINT64(0xb504f333,0xf9de6484);
   1.140 +	TInt64 y = MAKE_TINT64(0xc90fdaa2,0xc2352168);
   1.141 +	TInt i;
   1.142 +	TInt r=TheIntArray->Append(0);
   1.143 +	test(r==KErrNoMemory);
   1.144 +	r=ThePtrArray->Append(&x);
   1.145 +	test(r==KErrNoMemory);
   1.146 +	r=TheSimpleArray->Append(x);
   1.147 +	test(r==KErrNoMemory);
   1.148 +	__UHEAP_RESET;
   1.149 +	r=TheIntArray->Append(0);
   1.150 +	test(r==KErrNone);
   1.151 +	r=ThePtrArray->Append(&x);
   1.152 +	test(r==KErrNone);
   1.153 +	r=TheSimpleArray->Append(x);
   1.154 +	test(r==KErrNone);
   1.155 +	TUint8* p1=new TUint8[1024];	// alloc a big cell to block simple expansion
   1.156 +	__UHEAP_SETFAIL(RHeap::EDeterministic,1);
   1.157 +	test.Next(_L("Testing granularity"));
   1.158 +	TInt n=0;
   1.159 +	while(r==KErrNone)
   1.160 +		{
   1.161 +		n++;
   1.162 +		r=TheIntArray->Append(0);
   1.163 +		}
   1.164 +	test(r==KErrNoMemory);
   1.165 +	test(n==16);
   1.166 +	test(TheIntArray->Count()==16);
   1.167 +	r=KErrNone;
   1.168 +	n=0;
   1.169 +	while(r==KErrNone)
   1.170 +		{
   1.171 +		n++;
   1.172 +		r=ThePtrArray->Append(&x);
   1.173 +		}
   1.174 +	test(r==KErrNoMemory);
   1.175 +	test(n==8);
   1.176 +	test(ThePtrArray->Count()==8);		// default
   1.177 +	r=KErrNone;
   1.178 +	n=0;
   1.179 +	while(r==KErrNone)
   1.180 +		{
   1.181 +		n++;
   1.182 +		r=TheSimpleArray->Append(x);
   1.183 +		}
   1.184 +	test(r==KErrNoMemory);
   1.185 +	test(n==8);
   1.186 +	test(TheSimpleArray->Count()==8);	// default
   1.187 +
   1.188 +	r=TheIntArray->Insert(1,1);
   1.189 +	test(r==KErrNoMemory);
   1.190 +	test(TheIntArray->Count()==16);
   1.191 +	for (i=0; i<TheIntArray->Count(); i++)
   1.192 +		{
   1.193 +		test((*TheIntArray)[i]==0);
   1.194 +		}
   1.195 +	r=ThePtrArray->Insert(&y,1);
   1.196 +	test(r==KErrNoMemory);
   1.197 +	test(ThePtrArray->Count()==8);
   1.198 +	for (i=0; i<ThePtrArray->Count(); i++)
   1.199 +		{
   1.200 +		test((*ThePtrArray)[i]==&x);
   1.201 +		}
   1.202 +	r=TheSimpleArray->Insert(y,1);
   1.203 +	test(r==KErrNoMemory);
   1.204 +	test(TheSimpleArray->Count()==8);
   1.205 +	for (i=0; i<TheSimpleArray->Count(); i++)
   1.206 +		{
   1.207 +		test((*TheSimpleArray)[i]==x);
   1.208 +		}
   1.209 +
   1.210 +	for (i=1; i<16; i++)
   1.211 +		{
   1.212 +		TheIntArray->Remove(1);
   1.213 +		}
   1.214 +	for (i=1; i<8; i++)
   1.215 +		{
   1.216 +		ThePtrArray->Remove(1);
   1.217 +		}
   1.218 +	for (i=1; i<8; i++)
   1.219 +		{
   1.220 +		TheSimpleArray->Remove(1);
   1.221 +		}
   1.222 +	test(TheIntArray->Count()==1);
   1.223 +	test(ThePtrArray->Count()==1);
   1.224 +	test(TheSimpleArray->Count()==1);
   1.225 +
   1.226 +	__UHEAP_RESET;
   1.227 +	TAny* p2=User::Alloc(48);
   1.228 +	TAny* p3=User::Alloc(24);
   1.229 +	TAny* p4=User::Alloc(24);
   1.230 +	__UHEAP_SETFAIL(RHeap::EDeterministic,1);
   1.231 +	r=TheIntArray->Append(0);
   1.232 +	test(r==KErrNone);
   1.233 +	r=ThePtrArray->Append(&x);
   1.234 +	test(r==KErrNone);
   1.235 +	r=TheSimpleArray->Append(x);
   1.236 +	test(r==KErrNone);
   1.237 +	test(TheIntArray->Count()==2);
   1.238 +	test(ThePtrArray->Count()==2);
   1.239 +	test(TheSimpleArray->Count()==2);
   1.240 +	TheIntArray->Remove(1);
   1.241 +	ThePtrArray->Remove(1);
   1.242 +	TheSimpleArray->Remove(1);
   1.243 +	test(TheIntArray->Count()==1);
   1.244 +	test(ThePtrArray->Count()==1);
   1.245 +	test(TheSimpleArray->Count()==1);
   1.246 +	TheIntArray->Compress();
   1.247 +	ThePtrArray->Compress();
   1.248 +	TheSimpleArray->Compress();
   1.249 +	User::Free(p2);
   1.250 +	User::Free(p3);
   1.251 +	User::Free(p4);
   1.252 +	__UHEAP_RESET;
   1.253 +	p2=User::Alloc(48);
   1.254 +	p3=User::Alloc(24);
   1.255 +	p4=User::Alloc(24);
   1.256 +	__UHEAP_SETFAIL(RHeap::EDeterministic,1);
   1.257 +	r=TheIntArray->Append(0);
   1.258 +	test(r==KErrNoMemory);
   1.259 +	r=ThePtrArray->Append(&x);
   1.260 +	test(r==KErrNoMemory);
   1.261 +	r=TheSimpleArray->Append(x);
   1.262 +	test(r==KErrNoMemory);
   1.263 +	TheIntArray->Reset();
   1.264 +	ThePtrArray->Reset();
   1.265 +	TheSimpleArray->Reset();
   1.266 +	test(TheIntArray->Count()==0);
   1.267 +	test(ThePtrArray->Count()==0);
   1.268 +	test(TheSimpleArray->Count()==0);
   1.269 +	delete p1;
   1.270 +	User::Free(p2);
   1.271 +	User::Free(p3);
   1.272 +	User::Free(p4);
   1.273 +	__UHEAP_RESET;
   1.274 +	test.Next(_L("ResetAndDestroy"));
   1.275 +	TInt64 *i1=new TInt64;
   1.276 +	TInt64 *i2=new TInt64;
   1.277 +	TInt64 *i3=new TInt64;
   1.278 +	TInt64 *i4=new TInt64;
   1.279 +	ThePtrArray->Append(i1);
   1.280 +	ThePtrArray->Append(i2);
   1.281 +	ThePtrArray->Append(i3);
   1.282 +	ThePtrArray->Append(i4);
   1.283 +	test(ThePtrArray->Count()==4);
   1.284 +	ThePtrArray->ResetAndDestroy();
   1.285 +	__UHEAP_MARKEND;
   1.286 +	TheIntArray->Close();
   1.287 +	delete TheIntArray;
   1.288 +	ThePtrArray->Close();
   1.289 +	delete ThePtrArray;
   1.290 +	TheSimpleArray->Close();
   1.291 +	delete TheSimpleArray;
   1.292 +	}
   1.293 +#endif
   1.294 +
   1.295 +class RHeapMonitor : public RAllocator
   1.296 +	{
   1.297 +public:
   1.298 +	static RHeapMonitor& Install();
   1.299 +	void Uninstall();
   1.300 +	RHeapMonitor();
   1.301 +public:
   1.302 +	virtual TAny* Alloc(TInt);
   1.303 +	virtual void Free(TAny*);
   1.304 +	virtual TAny* ReAlloc(TAny*, TInt, TInt);
   1.305 +	virtual TInt AllocLen(const TAny*) const;
   1.306 +	virtual TInt Compress();
   1.307 +	virtual void Reset();
   1.308 +	virtual TInt AllocSize(TInt&) const;
   1.309 +	virtual TInt Available(TInt&) const;
   1.310 +	virtual TInt DebugFunction(TInt, TAny*, TAny*);
   1.311 +	virtual TInt Extension_(TUint, TAny*&, TAny*);
   1.312 +public:
   1.313 +	RAllocator* iOrig;
   1.314 +	TInt iAllocs;
   1.315 +	TInt iFailedAllocs;
   1.316 +	TInt iFrees;
   1.317 +	TInt iReallocs;
   1.318 +	TInt iFailedReallocs;
   1.319 +	};
   1.320 +
   1.321 +RHeapMonitor::RHeapMonitor()
   1.322 +	{
   1.323 +	iOrig = &User::Allocator();
   1.324 +	iAllocs = 0;
   1.325 +	iFailedAllocs = 0;
   1.326 +	iFrees = 0;
   1.327 +	iReallocs = 0;
   1.328 +	iFailedReallocs = 0;
   1.329 +	}
   1.330 +
   1.331 +RHeapMonitor& RHeapMonitor::Install()
   1.332 +	{
   1.333 +	RHeapMonitor* m = new RHeapMonitor;
   1.334 +	test(m!=0);
   1.335 +	RAllocator* orig = User::SwitchAllocator(m);
   1.336 +	test(orig == m->iOrig);
   1.337 +	return *m;
   1.338 +	}
   1.339 +
   1.340 +void RHeapMonitor::Uninstall()
   1.341 +	{
   1.342 +	RAllocator* m = User::SwitchAllocator(iOrig);
   1.343 +	test(m == this);
   1.344 +	delete this;
   1.345 +	}
   1.346 +
   1.347 +TAny* RHeapMonitor::Alloc(TInt a)
   1.348 +	{
   1.349 +	++iAllocs;
   1.350 +	TAny* p = iOrig->Alloc(a);
   1.351 +	if (!p) ++iFailedAllocs;
   1.352 +	return p;
   1.353 +	}
   1.354 +
   1.355 +void RHeapMonitor::Free(TAny* a)
   1.356 +	{
   1.357 +	if (a) ++iFrees;
   1.358 +	iOrig->Free(a);
   1.359 +	}
   1.360 +
   1.361 +TAny* RHeapMonitor::ReAlloc(TAny* aCell, TInt aSize, TInt aMode)
   1.362 +	{
   1.363 +	if (aCell && aSize>0)
   1.364 +		++iReallocs;
   1.365 +	else if (aCell)
   1.366 +		++iFrees;
   1.367 +	else
   1.368 +		++iAllocs;
   1.369 +	TAny* p = iOrig->ReAlloc(aCell, aSize, aMode);
   1.370 +	if (!p && aSize>0)
   1.371 +		{
   1.372 +		if (aCell)
   1.373 +			++iFailedReallocs;
   1.374 +		else
   1.375 +			++iFailedAllocs;
   1.376 +		}
   1.377 +	return p;
   1.378 +	}
   1.379 +
   1.380 +TInt RHeapMonitor::AllocLen(const TAny* a) const
   1.381 +	{
   1.382 +	return iOrig->AllocLen(a);
   1.383 +	}
   1.384 +
   1.385 +TInt RHeapMonitor::Compress()
   1.386 +	{
   1.387 +	return iOrig->Compress();
   1.388 +	}
   1.389 +
   1.390 +void RHeapMonitor::Reset()
   1.391 +	{
   1.392 +	iOrig->Reset();
   1.393 +	}
   1.394 +
   1.395 +TInt RHeapMonitor::AllocSize(TInt& a) const
   1.396 +	{
   1.397 +	return iOrig->AllocSize(a);
   1.398 +	}
   1.399 +
   1.400 +TInt RHeapMonitor::Available(TInt& a) const
   1.401 +	{
   1.402 +	return iOrig->Available(a);
   1.403 +	}
   1.404 +
   1.405 +TInt RHeapMonitor::DebugFunction(TInt aFunc, TAny* a1, TAny* a2)
   1.406 +	{
   1.407 +	return iOrig->DebugFunction(aFunc, a1, a2);
   1.408 +	}
   1.409 +
   1.410 +TInt RHeapMonitor::Extension_(TUint, TAny*&, TAny*)
   1.411 +	{
   1.412 +	return KErrExtensionNotSupported;
   1.413 +	}
   1.414 +
   1.415 +template<class T>
   1.416 +void TestReserveT()
   1.417 +	{
   1.418 +	RHeapMonitor& m = RHeapMonitor::Install();
   1.419 +	TInt r;
   1.420 +	RArray<T> a(1);
   1.421 +	test(a.Count()==0);
   1.422 +	test(m.iAllocs==0);
   1.423 +	test(a.Append(1)==KErrNone);
   1.424 +	test(m.iAllocs==1);
   1.425 +	test(m.iReallocs==0);
   1.426 +	test(a.Append(2)==KErrNone);
   1.427 +	test(m.iReallocs==1);	// should have realloc'd
   1.428 +	a.Close();
   1.429 +	test(m.iFrees==1);
   1.430 +	test(m.iAllocs==1);
   1.431 +	test(m.iReallocs==1);
   1.432 +	test(a.Count()==0);
   1.433 +	test(a.Reserve(2)==KErrNone);
   1.434 +	test(m.iAllocs==2);
   1.435 +	TRAP(r,a.ReserveL(2));
   1.436 +	test(r==KErrNone);
   1.437 +	test(m.iFrees==1);
   1.438 +	test(m.iAllocs==2);
   1.439 +	test(m.iReallocs==1);
   1.440 +	test(a.Append(1)==KErrNone);
   1.441 +	test(m.iFrees==1);
   1.442 +	test(m.iAllocs==2);
   1.443 +	test(m.iReallocs==1);
   1.444 +	test(a.Append(2)==KErrNone);
   1.445 +	test(m.iFrees==1);
   1.446 +	test(m.iAllocs==2);
   1.447 +	test(m.iReallocs==1);	// shouldn't have realloc'd
   1.448 +	test(a.Append(3)==KErrNone);
   1.449 +	test(m.iFrees==1);
   1.450 +	test(m.iAllocs==2);
   1.451 +	test(m.iReallocs==2);	// should have realloc'd
   1.452 +	a.Close();
   1.453 +	test(m.iFrees==2);
   1.454 +	test(m.iAllocs==2);
   1.455 +	test(m.iReallocs==2);
   1.456 +	test(a.Count()==0);
   1.457 +	test(a.Reserve(2)==KErrNone);
   1.458 +	test(m.iFrees==2);
   1.459 +	test(m.iAllocs==3);
   1.460 +	test(m.iReallocs==2);
   1.461 +	test(a.Append(1)==KErrNone);
   1.462 +	test(m.iFrees==2);
   1.463 +	test(m.iAllocs==3);
   1.464 +	test(m.iReallocs==2);
   1.465 +	test(a.Append(2)==KErrNone);
   1.466 +	test(m.iFrees==2);
   1.467 +	test(m.iAllocs==3);
   1.468 +	test(m.iReallocs==2);
   1.469 +	test(a.Reserve(0x20000000)==KErrNoMemory);
   1.470 +	test(m.iFrees==2);
   1.471 +	test(m.iAllocs==3);
   1.472 +	test(m.iReallocs==2);
   1.473 +	test(m.iFrees==2);
   1.474 +	test(m.iAllocs==3);
   1.475 +	test(m.iReallocs==2);
   1.476 +	test(a.Reserve(8)==KErrNone);
   1.477 +	test(m.iFrees==2);
   1.478 +	test(m.iAllocs==3);
   1.479 +	test(m.iReallocs==3);
   1.480 +	test(a.Append(3)==KErrNone);
   1.481 +	test(a.Append(4)==KErrNone);
   1.482 +	test(a.Append(5)==KErrNone);
   1.483 +	test(a.Append(6)==KErrNone);
   1.484 +	test(a.Append(7)==KErrNone);
   1.485 +	test(a.Append(8)==KErrNone);
   1.486 +	test(a.Count()==8);
   1.487 +	test(m.iFrees==2);
   1.488 +	test(m.iAllocs==3);
   1.489 +	test(m.iReallocs==3);
   1.490 +	TInt i;
   1.491 +	for (i=0; i<=8; ++i)
   1.492 +		{
   1.493 +		test(a.Reserve(i)==KErrNone);
   1.494 +		test(m.iFrees==2);
   1.495 +		test(m.iAllocs==3);
   1.496 +		test(m.iReallocs==3);
   1.497 +		}
   1.498 +	test(a.Append(9)==KErrNone);
   1.499 +	test(m.iFrees==2);
   1.500 +	test(m.iAllocs==3);
   1.501 +	test(m.iReallocs==4);
   1.502 +	a.Close();
   1.503 +	test(m.iFrees==3);
   1.504 +	test(m.iAllocs==3);
   1.505 +	test(m.iReallocs==4);
   1.506 +#ifdef _DEBUG
   1.507 +	__UHEAP_FAILNEXT(1);
   1.508 +	test(a.Count()==0);
   1.509 +	test(a.Reserve(0)==KErrNone);
   1.510 +	test(m.iFrees==3);
   1.511 +	test(m.iAllocs==3);
   1.512 +	test(m.iReallocs==4);
   1.513 +	test(m.iFailedAllocs==0);
   1.514 +	test(a.Reserve(1)==KErrNoMemory);
   1.515 +	test(m.iFrees==3);
   1.516 +	test(m.iAllocs==4);
   1.517 +	test(m.iReallocs==4);
   1.518 +	test(m.iFailedAllocs==1);
   1.519 +	test(a.Reserve(1)==KErrNone);
   1.520 +	test(m.iFrees==3);
   1.521 +	test(m.iAllocs==5);
   1.522 +	test(m.iReallocs==4);
   1.523 +	test(m.iFailedAllocs==1);
   1.524 +	a.Close();
   1.525 +	test(m.iFrees==4);
   1.526 +	test(m.iAllocs==5);
   1.527 +	test(m.iReallocs==4);
   1.528 +	test(m.iFailedAllocs==1);
   1.529 +#endif
   1.530 +	m.Uninstall();
   1.531 +	TUint count = 0x80000000u / sizeof(T);
   1.532 +
   1.533 +	// don't do this in the heap monitored section because
   1.534 +	// throwing a C++ exception allocates and frees memory
   1.535 +	TRAP(r,a.ReserveL(count));
   1.536 +	test(r==KErrNoMemory);
   1.537 +	}
   1.538 +
   1.539 +void TestReserve()
   1.540 +	{
   1.541 +	test.Start(_L("Test Reserve()"));
   1.542 +	__UHEAP_MARK;
   1.543 +
   1.544 +	TestReserveT<TInt>();
   1.545 +	TestReserveT<TInt64>();
   1.546 +
   1.547 +	__UHEAP_MARKEND;
   1.548 +	test.End();
   1.549 +	}
   1.550 +
   1.551 +GLDEF_C TInt E32Main()
   1.552 +	{
   1.553 +
   1.554 +	CTrapCleanup* trapHandler=CTrapCleanup::New();
   1.555 +	test(trapHandler!=NULL);
   1.556 +
   1.557 +	test.Title();
   1.558 +	test.Start(_L("Simple array tests"));
   1.559 +#ifdef _DEBUG
   1.560 +	DoAllocTests();
   1.561 +#endif
   1.562 +	TestReserve();
   1.563 +	__UHEAP_MARK;
   1.564 +	DoRArrayTests();
   1.565 +	__UHEAP_MARKEND;
   1.566 +	__UHEAP_MARK;
   1.567 +	DoIntArrayTests();
   1.568 +	__UHEAP_MARKEND;
   1.569 +	__UHEAP_MARK;
   1.570 +	DoUintArrayTests();
   1.571 +	__UHEAP_MARKEND;
   1.572 +	__UHEAP_MARK;
   1.573 +	DoPointerArrayTests();
   1.574 +	__UHEAP_MARKEND;
   1.575 +	__UHEAP_MARK;
   1.576 +	TRAPD(ret,DoArrayLeavingInterfaceTest());
   1.577 +	test(ret==KErrNone);
   1.578 +	__UHEAP_MARKEND;
   1.579 +	__UHEAP_MARK;
   1.580 +	TRAP(ret,DoPointerArrayLeavingInterfaceTest());
   1.581 +	test(ret==KErrNone);
   1.582 +	__UHEAP_MARKEND;
   1.583 +	__UHEAP_MARK;
   1.584 +	TRAP(ret,DoTIntArrayLeavingInterfaceTest());
   1.585 +	test(ret==KErrNone);
   1.586 +	__UHEAP_MARKEND;
   1.587 +	__UHEAP_MARK;
   1.588 +	TRAP(ret,DoTUintArrayLeavingInterfaceTest());
   1.589 +	test(ret==KErrNone);
   1.590 +	__UHEAP_MARKEND;
   1.591 +	__UHEAP_MARK;
   1.592 +	DoSimpleArrayTests();
   1.593 +	__UHEAP_MARKEND;
   1.594 +	__UHEAP_MARK;
   1.595 +	DoPointerArrayAnyTests();
   1.596 +	__UHEAP_MARKEND;
   1.597 +	__UHEAP_MARK;
   1.598 +	TRAP(ret,DoPointerArrayAnyLeavingInterfaceTest());
   1.599 +	test(ret==KErrNone);
   1.600 +	__UHEAP_MARKEND;
   1.601 +	__UHEAP_MARK;
   1.602 +	DoSpeedTests();
   1.603 +	__UHEAP_MARKEND;
   1.604 +	test.End();
   1.605 +
   1.606 +	delete trapHandler;
   1.607 +	return KErrNone;
   1.608 +	}