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