os/graphics/fbs/fontandbitmapserver/tfbs/TALLOC.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1996-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 "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
//
sl@0
    15
sl@0
    16
#include <s32file.h>
sl@0
    17
#include <graphics/bitmapuid.h>
sl@0
    18
#include "../sfbs/UTILS.H"
sl@0
    19
#include "TFBS.H"
sl@0
    20
#include "TALLOC.H"
sl@0
    21
#include "../sfbs/fbsbitmapasyncstreamer.h"
sl@0
    22
#include "fbsmessage.h"
sl@0
    23
#include "fbsdefs.h"
sl@0
    24
sl@0
    25
const TSize KLargeSize(4096 + 100, 1);
sl@0
    26
const TSize KLargeSizeAlt(4096 + 200, 2);
sl@0
    27
const TSize KSmallSize(10, 10);
sl@0
    28
const TSize KSmallSizeAlt(20, 20);
sl@0
    29
sl@0
    30
CTAlloc::CTAlloc(CTestStep* aStep):
sl@0
    31
	CTGraphicsBase(aStep), 
sl@0
    32
	iFbs(NULL),
sl@0
    33
	iStore(NULL),
sl@0
    34
	iBitmap(NULL),
sl@0
    35
	iBitmap2(NULL)
sl@0
    36
	{
sl@0
    37
	INFO_PRINTF1(_L("Font/Bitmap Server Alloc Failure Recovery Testing"));
sl@0
    38
	}
sl@0
    39
sl@0
    40
CTAlloc::~CTAlloc()
sl@0
    41
	{
sl@0
    42
	if (iShutdownFbs)
sl@0
    43
		{
sl@0
    44
		iFbs->SendCommand(EFbsMessShutdown);
sl@0
    45
		}
sl@0
    46
	iFbs->Disconnect();
sl@0
    47
	
sl@0
    48
	delete iStore;
sl@0
    49
	}
sl@0
    50
sl@0
    51
void CTAlloc::ConstructL()
sl@0
    52
	{
sl@0
    53
	iStore = CFbsTypefaceStore::NewL(NULL);
sl@0
    54
sl@0
    55
	if(RFbsSession::Connect()==KErrNone)
sl@0
    56
		{
sl@0
    57
		RFbsSession::Disconnect();
sl@0
    58
		iShutdownFbs = EFalse;
sl@0
    59
		}
sl@0
    60
	else
sl@0
    61
		{
sl@0
    62
		FbsStartup();
sl@0
    63
		iShutdownFbs = ETrue;
sl@0
    64
		}
sl@0
    65
	}
sl@0
    66
sl@0
    67
void CTAlloc::RunTestCaseL(TInt aCurTestCase)
sl@0
    68
	{
sl@0
    69
	((CTAllocStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
    70
	switch(aCurTestCase)
sl@0
    71
		{
sl@0
    72
	case 1:
sl@0
    73
		((CTAllocStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0511"));
sl@0
    74
		Session();
sl@0
    75
		break;
sl@0
    76
	case 2:
sl@0
    77
		{
sl@0
    78
/**
sl@0
    79
	@SYMTestCaseID GRAPHICS-FBSERV-0611
sl@0
    80
*/
sl@0
    81
		((CTAllocStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0611"));
sl@0
    82
		TInt ret = RFbsSession::Connect();
sl@0
    83
		TEST2(ret, KErrNone);
sl@0
    84
		iFbs = RFbsSession::GetSession();
sl@0
    85
		TEST(iFbs != NULL);
sl@0
    86
		}
sl@0
    87
		break;
sl@0
    88
	case 4:
sl@0
    89
		((CTAllocStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0512"));
sl@0
    90
		BitmapsL();
sl@0
    91
		break;
sl@0
    92
	case 5:
sl@0
    93
		((CTAllocStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0514"));
sl@0
    94
		BitmapHandlerL();
sl@0
    95
		break;
sl@0
    96
	case 6:
sl@0
    97
		((CTAllocStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0513"));
sl@0
    98
		TypefaceStoreL();
sl@0
    99
		break;
sl@0
   100
	case 7:
sl@0
   101
		((CTAllocStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0515"));
sl@0
   102
		FontStoreL();
sl@0
   103
		break;
sl@0
   104
	case 8:
sl@0
   105
		((CTAllocStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   106
		((CTAllocStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   107
		TestComplete();
sl@0
   108
		break;
sl@0
   109
	default:
sl@0
   110
		((CTAllocStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   111
		break;
sl@0
   112
		}
sl@0
   113
	((CTAllocStep*)iStep)->RecordTestResultL();
sl@0
   114
	}
sl@0
   115
sl@0
   116
/**
sl@0
   117
	@SYMTestCaseID
sl@0
   118
	GRAPHICS-FBSERV-0511
sl@0
   119
sl@0
   120
	@SYMTestCaseDesc
sl@0
   121
	Allocated sessions with the FbsServer and simulates memory allocation errors
sl@0
   122
sl@0
   123
	@SYMTestActions
sl@0
   124
	Checks the heap
sl@0
   125
sl@0
   126
	@SYMTestExpectedResults
sl@0
   127
	Test should pass
sl@0
   128
*/
sl@0
   129
void CTAlloc::Session()
sl@0
   130
	{
sl@0
   131
	INFO_PRINTF1(_L("RFbsSession::Connect()\r\n"));
sl@0
   132
sl@0
   133
	for (TInt count = 1; ; count++)
sl@0
   134
		{
sl@0
   135
		__UHEAP_FAILNEXT(count);
sl@0
   136
		__UHEAP_MARK;
sl@0
   137
sl@0
   138
		TInt ret = RFbsSession::Connect();
sl@0
   139
sl@0
   140
		if (ret == KErrNoMemory)
sl@0
   141
			{
sl@0
   142
			__UHEAP_MARKEND;
sl@0
   143
			}
sl@0
   144
		else if (ret == KErrNone)
sl@0
   145
			{
sl@0
   146
			RFbsSession::Disconnect();
sl@0
   147
			__UHEAP_MARKEND;
sl@0
   148
			break;
sl@0
   149
			}
sl@0
   150
		else 
sl@0
   151
			{
sl@0
   152
			__UHEAP_MARKEND;
sl@0
   153
			TEST2(ret, KErrNone);
sl@0
   154
			}
sl@0
   155
		}
sl@0
   156
sl@0
   157
	__UHEAP_RESET;
sl@0
   158
	}
sl@0
   159
sl@0
   160
/**
sl@0
   161
	@SYMTestCaseID
sl@0
   162
	GRAPHICS-FBSERV-0512
sl@0
   163
sl@0
   164
	@SYMTestCaseDesc
sl@0
   165
	Creates bitmaps in different ways and checks if memory allocation succeeded 
sl@0
   166
sl@0
   167
	@SYMTestActions
sl@0
   168
	Creates normal size bitmaps, large bitmaps, loads bitmaps, loads shared bitmaps,
sl@0
   169
	duplicated bitmaps, resizes bitmaps, compresses bitmaps, externalized bitmaps to write store, 
sl@0
   170
	internalizes bitmaps back again from write store. All ways of creating bitmaps are tested
sl@0
   171
	against Out Of Memory error conditions	
sl@0
   172
sl@0
   173
	@SYMTestExpectedResults
sl@0
   174
	Test should pass
sl@0
   175
*/
sl@0
   176
void CTAlloc::BitmapsL()
sl@0
   177
	{
sl@0
   178
	TInt heapMarkCheckFlag;	
sl@0
   179
	if( !iStep->GetIntFromConfig(KDefaultSectionName, KFbsHeapMarkCheckFlag, heapMarkCheckFlag) )
sl@0
   180
		{
sl@0
   181
		INFO_PRINTF1(_L("Error reading ini file"));
sl@0
   182
		User::Leave(KErrNotFound);
sl@0
   183
		}
sl@0
   184
	
sl@0
   185
	CFbsBitmap iBitmap;
sl@0
   186
	CFbsBitmap iBitmap2;
sl@0
   187
sl@0
   188
	iTestBitmapName = KTestBitmapOnZ;
sl@0
   189
	TInt ret = iBitmap.Load(iTestBitmapName,ETfbs,NULL);
sl@0
   190
	TEST2(ret, KErrNone);
sl@0
   191
sl@0
   192
	ret = iBitmap.Create(KLargeSize,EColor256); // Expand server caches
sl@0
   193
	TEST2(ret, KErrNone);
sl@0
   194
	iBitmap.Reset();
sl@0
   195
sl@0
   196
	TInt count;
sl@0
   197
sl@0
   198
// Create bitmap
sl@0
   199
	INFO_PRINTF1(_L("CFbsBitmap::Create()\r\n"));
sl@0
   200
	for (count = 1; ; count++)
sl@0
   201
		{
sl@0
   202
		iFbs->SendCommand(EFbsMessDefaultAllocFail,count);
sl@0
   203
		if(heapMarkCheckFlag)
sl@0
   204
			{
sl@0
   205
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   206
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   207
			}
sl@0
   208
		ret = iBitmap.Create(KSmallSize,EColor256);
sl@0
   209
sl@0
   210
		if (ret == KErrNoMemory)
sl@0
   211
			{
sl@0
   212
			if(heapMarkCheckFlag)
sl@0
   213
				{
sl@0
   214
				iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   215
				iFbs->SendCommand(EFbsMessUserMark);
sl@0
   216
				}
sl@0
   217
			}
sl@0
   218
		else if (ret == KErrNone)
sl@0
   219
			{
sl@0
   220
			iBitmap.Reset();
sl@0
   221
			if(heapMarkCheckFlag)
sl@0
   222
				{
sl@0
   223
				iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   224
				iFbs->SendCommand(EFbsMessUserMark);
sl@0
   225
				}
sl@0
   226
			break;
sl@0
   227
			}
sl@0
   228
		else 
sl@0
   229
			TEST2(ret, KErrNone);
sl@0
   230
		}
sl@0
   231
sl@0
   232
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   233
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   234
	TEST(iFbs->ResourceCount()==0);
sl@0
   235
sl@0
   236
	for (count = 1; ; count++)
sl@0
   237
		{
sl@0
   238
		iFbs->SendCommand(EFbsMessUserAllocFail,count);
sl@0
   239
		if(heapMarkCheckFlag)
sl@0
   240
			{
sl@0
   241
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   242
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   243
			}
sl@0
   244
sl@0
   245
		ret=iBitmap.Create(KSmallSize,EGray2);
sl@0
   246
sl@0
   247
		if (ret == KErrNoMemory)
sl@0
   248
			{
sl@0
   249
			if(heapMarkCheckFlag)
sl@0
   250
				{
sl@0
   251
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   252
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   253
				}
sl@0
   254
			}
sl@0
   255
		else if (ret == KErrNone)
sl@0
   256
			{
sl@0
   257
			iBitmap.Reset();
sl@0
   258
			if(heapMarkCheckFlag)
sl@0
   259
				{
sl@0
   260
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   261
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   262
				}
sl@0
   263
			break;
sl@0
   264
			}
sl@0
   265
		else 
sl@0
   266
			TEST2(ret, KErrNone);
sl@0
   267
		}
sl@0
   268
sl@0
   269
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   270
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   271
	TEST(iFbs->ResourceCount()==0);
sl@0
   272
sl@0
   273
// Create (large)
sl@0
   274
	for (count = 1; ; count++)
sl@0
   275
		{
sl@0
   276
		iFbs->SendCommand(EFbsMessDefaultAllocFail,count);
sl@0
   277
		if(heapMarkCheckFlag)
sl@0
   278
			{
sl@0
   279
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   280
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   281
			}
sl@0
   282
sl@0
   283
		ret = iBitmap.Create(KLargeSize,EColor256);
sl@0
   284
sl@0
   285
		if (ret == KErrNoMemory)
sl@0
   286
			{
sl@0
   287
			if(heapMarkCheckFlag)
sl@0
   288
				{
sl@0
   289
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   290
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   291
				}
sl@0
   292
			}
sl@0
   293
		else if (ret == KErrNone)
sl@0
   294
			{
sl@0
   295
			iBitmap.Reset();
sl@0
   296
			if(heapMarkCheckFlag)
sl@0
   297
				{
sl@0
   298
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   299
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   300
				}
sl@0
   301
			break;
sl@0
   302
			}
sl@0
   303
		else 
sl@0
   304
			TEST2(ret, KErrNone);
sl@0
   305
		}
sl@0
   306
sl@0
   307
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   308
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   309
	TEST(iFbs->ResourceCount()==0);
sl@0
   310
sl@0
   311
	for (count = 1; ; count++)
sl@0
   312
		{
sl@0
   313
		iFbs->SendCommand(EFbsMessUserAllocFail,count);
sl@0
   314
		if(heapMarkCheckFlag)
sl@0
   315
			{
sl@0
   316
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   317
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   318
			}
sl@0
   319
sl@0
   320
		ret = iBitmap.Create(KLargeSize,EColor256);
sl@0
   321
sl@0
   322
		if (ret == KErrNoMemory)
sl@0
   323
			{
sl@0
   324
			if(heapMarkCheckFlag)
sl@0
   325
				{
sl@0
   326
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   327
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   328
				}
sl@0
   329
			}
sl@0
   330
		else if (ret == KErrNone)
sl@0
   331
			{
sl@0
   332
			iBitmap.Reset();
sl@0
   333
			if(heapMarkCheckFlag)
sl@0
   334
				{
sl@0
   335
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   336
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   337
				}
sl@0
   338
			break;
sl@0
   339
			}
sl@0
   340
		else 
sl@0
   341
			TEST2(ret, KErrNone);
sl@0
   342
		}
sl@0
   343
sl@0
   344
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   345
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   346
	TEST(iFbs->ResourceCount()==0);
sl@0
   347
sl@0
   348
// Load
sl@0
   349
	INFO_PRINTF1(_L("CFbsBitmap::Load()\r\n"));
sl@0
   350
	ret = iBitmap.Load(iTestBitmapName,ETfbs,NULL);
sl@0
   351
	TEST2(ret, KErrNone);
sl@0
   352
	iBitmap.Reset();
sl@0
   353
	for (count = 1; ; count++)
sl@0
   354
		{
sl@0
   355
		iFbs->SendCommand(EFbsMessDefaultAllocFail,count);
sl@0
   356
		if(heapMarkCheckFlag)
sl@0
   357
			{
sl@0
   358
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   359
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   360
			}
sl@0
   361
sl@0
   362
		ret = iBitmap.Load(iTestBitmapName,ETfbs,NULL);
sl@0
   363
sl@0
   364
		if (ret == KErrNoMemory)
sl@0
   365
			{
sl@0
   366
			if(heapMarkCheckFlag)
sl@0
   367
				{
sl@0
   368
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   369
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   370
				}
sl@0
   371
			}
sl@0
   372
		else if (ret == KErrNone)
sl@0
   373
			{
sl@0
   374
			iBitmap.Reset();
sl@0
   375
			if(heapMarkCheckFlag)
sl@0
   376
				{
sl@0
   377
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   378
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   379
				}
sl@0
   380
			break;
sl@0
   381
			}
sl@0
   382
		else 
sl@0
   383
			TEST2(ret, KErrNone);
sl@0
   384
		}
sl@0
   385
sl@0
   386
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   387
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   388
	TEST(iFbs->ResourceCount()==0);
sl@0
   389
sl@0
   390
	for (count = 1; ; count++)
sl@0
   391
		{
sl@0
   392
		iFbs->SendCommand(EFbsMessUserAllocFail,count);
sl@0
   393
		if(heapMarkCheckFlag)
sl@0
   394
			{
sl@0
   395
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   396
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   397
			}
sl@0
   398
sl@0
   399
		ret = iBitmap.Load(iTestBitmapName,ETfbs,NULL);
sl@0
   400
sl@0
   401
		if (ret == KErrNoMemory)
sl@0
   402
			{
sl@0
   403
			if(heapMarkCheckFlag)
sl@0
   404
				{
sl@0
   405
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   406
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   407
				}
sl@0
   408
			}
sl@0
   409
		else if (ret == KErrNone)
sl@0
   410
			{
sl@0
   411
			iBitmap.Reset();
sl@0
   412
			if(heapMarkCheckFlag)
sl@0
   413
				{
sl@0
   414
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   415
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   416
				}
sl@0
   417
			break;
sl@0
   418
			}
sl@0
   419
		else 
sl@0
   420
			TEST2(ret, KErrNone);
sl@0
   421
	}
sl@0
   422
sl@0
   423
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   424
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   425
	TEST(iFbs->ResourceCount()==0);
sl@0
   426
sl@0
   427
// Load (shared)
sl@0
   428
	INFO_PRINTF1(_L("CFbsBitmap::Load() - shared \r\n"));
sl@0
   429
	
sl@0
   430
	// Do an initial load to ensure the StreamId cache does not get updated whilst OOM testing
sl@0
   431
	ret = iBitmap.Load(iTestBitmapName,ETfbs,ETrue);
sl@0
   432
	TEST2(ret, KErrNone);
sl@0
   433
	iBitmap.Reset();
sl@0
   434
	
sl@0
   435
	for (count = 1; ; count++)
sl@0
   436
		{
sl@0
   437
		iFbs->SendCommand(EFbsMessDefaultAllocFail,count);
sl@0
   438
		if(heapMarkCheckFlag)
sl@0
   439
			{
sl@0
   440
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   441
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   442
			}
sl@0
   443
sl@0
   444
		ret = iBitmap.Load(iTestBitmapName,ETfbs,ETrue);
sl@0
   445
		
sl@0
   446
		if (ret == KErrNoMemory)
sl@0
   447
			{
sl@0
   448
			if(heapMarkCheckFlag)
sl@0
   449
				{
sl@0
   450
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   451
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   452
				}
sl@0
   453
			continue;
sl@0
   454
			}
sl@0
   455
		else if (ret != KErrNone)
sl@0
   456
			TEST2(ret, KErrNone);
sl@0
   457
			
sl@0
   458
		ret = iBitmap2.Load(iTestBitmapName,ETfbs,ETrue);	
sl@0
   459
			
sl@0
   460
		if (ret == KErrNoMemory)
sl@0
   461
			{
sl@0
   462
			iBitmap.Reset();
sl@0
   463
			if(heapMarkCheckFlag)
sl@0
   464
				{
sl@0
   465
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   466
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   467
				}
sl@0
   468
			continue;
sl@0
   469
			}
sl@0
   470
		else if (ret == KErrNone)
sl@0
   471
			{
sl@0
   472
			iBitmap.Reset();	
sl@0
   473
			iBitmap2.Reset();
sl@0
   474
			if(heapMarkCheckFlag)
sl@0
   475
				{
sl@0
   476
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   477
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   478
				}
sl@0
   479
			break;
sl@0
   480
			}
sl@0
   481
		else 
sl@0
   482
			TEST2(ret, KErrNone);		
sl@0
   483
		}
sl@0
   484
sl@0
   485
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   486
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   487
	TEST(iFbs->ResourceCount()==0);
sl@0
   488
sl@0
   489
	for (count = 1; ; count++)
sl@0
   490
		{
sl@0
   491
		iFbs->SendCommand(EFbsMessUserAllocFail,count);
sl@0
   492
		if(heapMarkCheckFlag)
sl@0
   493
			{
sl@0
   494
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   495
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   496
			}
sl@0
   497
sl@0
   498
		ret = iBitmap.Load(iTestBitmapName,ETfbs,ETrue);
sl@0
   499
		
sl@0
   500
		if (ret == KErrNoMemory)
sl@0
   501
			{
sl@0
   502
			if(heapMarkCheckFlag)
sl@0
   503
				{
sl@0
   504
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   505
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   506
				}
sl@0
   507
			continue;
sl@0
   508
			}
sl@0
   509
		else if (ret != KErrNone)
sl@0
   510
			TEST2(ret, KErrNone);
sl@0
   511
			
sl@0
   512
		ret = iBitmap2.Load(iTestBitmapName,ETfbs,ETrue);
sl@0
   513
sl@0
   514
		if (ret == KErrNoMemory)
sl@0
   515
			{
sl@0
   516
			iBitmap.Reset();
sl@0
   517
			if(heapMarkCheckFlag)
sl@0
   518
				{
sl@0
   519
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   520
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   521
				}
sl@0
   522
			continue;
sl@0
   523
			}
sl@0
   524
		else if (ret == KErrNone)
sl@0
   525
			{
sl@0
   526
			iBitmap.Reset();
sl@0
   527
			iBitmap2.Reset();
sl@0
   528
			if(heapMarkCheckFlag)
sl@0
   529
				{
sl@0
   530
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   531
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   532
				}
sl@0
   533
			break;
sl@0
   534
			}
sl@0
   535
		else 
sl@0
   536
			TEST2(ret, KErrNone);
sl@0
   537
	}
sl@0
   538
sl@0
   539
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   540
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   541
	TEST(iFbs->ResourceCount()==0);
sl@0
   542
	
sl@0
   543
	
sl@0
   544
// Duplicate
sl@0
   545
	CFbsBitmap bmpalt;
sl@0
   546
	ret = bmpalt.Create(KSmallSize,EColor256);
sl@0
   547
	TEST2(ret, KErrNone);
sl@0
   548
sl@0
   549
	INFO_PRINTF1(_L("CFbsBitmap::Duplicate()\r\n"));
sl@0
   550
	for (count = 1; ; count++)
sl@0
   551
		{
sl@0
   552
		iFbs->SendCommand(EFbsMessDefaultAllocFail,count);
sl@0
   553
		if(heapMarkCheckFlag)
sl@0
   554
			{
sl@0
   555
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   556
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   557
			}
sl@0
   558
sl@0
   559
		ret = iBitmap.Duplicate(bmpalt.Handle());
sl@0
   560
sl@0
   561
		if (ret == KErrNoMemory)
sl@0
   562
			{
sl@0
   563
			if(heapMarkCheckFlag)
sl@0
   564
				{
sl@0
   565
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   566
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   567
				}
sl@0
   568
			}
sl@0
   569
		else if (ret == KErrNone)
sl@0
   570
			{
sl@0
   571
			iBitmap.Reset();
sl@0
   572
			if(heapMarkCheckFlag)
sl@0
   573
				{
sl@0
   574
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   575
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   576
				}
sl@0
   577
			break;
sl@0
   578
			}
sl@0
   579
		else 
sl@0
   580
			TEST2(ret, KErrNone);
sl@0
   581
		}
sl@0
   582
sl@0
   583
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   584
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   585
	TEST(iFbs->ResourceCount()==1);
sl@0
   586
	ret = bmpalt.Create(KSmallSize,EColor256);
sl@0
   587
	TEST2(ret, KErrNone);
sl@0
   588
sl@0
   589
	for (count = 1; ; count++)
sl@0
   590
		{
sl@0
   591
		iFbs->SendCommand(EFbsMessUserAllocFail,count);
sl@0
   592
		if(heapMarkCheckFlag)
sl@0
   593
			{
sl@0
   594
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   595
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   596
			}
sl@0
   597
sl@0
   598
		ret = iBitmap.Duplicate(bmpalt.Handle());
sl@0
   599
sl@0
   600
		if (ret == KErrNoMemory)
sl@0
   601
			{
sl@0
   602
			if(heapMarkCheckFlag)
sl@0
   603
				{
sl@0
   604
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   605
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   606
				}
sl@0
   607
			}
sl@0
   608
		else if (ret == KErrNone)
sl@0
   609
			{
sl@0
   610
			iBitmap.Reset();
sl@0
   611
			if(heapMarkCheckFlag)
sl@0
   612
				{
sl@0
   613
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   614
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   615
				}
sl@0
   616
			break;
sl@0
   617
			}
sl@0
   618
		else 
sl@0
   619
			TEST2(ret, KErrNone);
sl@0
   620
		}
sl@0
   621
sl@0
   622
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   623
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   624
	bmpalt.Reset();
sl@0
   625
	TEST(iFbs->ResourceCount()==0);
sl@0
   626
sl@0
   627
// Resize
sl@0
   628
	// force fbserv to do a resize. This makes the pile to insert an index in it's array
sl@0
   629
	// If the array is empty when the tests below are run then the insert will look like a mem leak
sl@0
   630
	ret=iBitmap.Create(KLargeSize,EColor256);
sl@0
   631
	iBitmap.Resize(KLargeSizeAlt);
sl@0
   632
	iBitmap.Reset();
sl@0
   633
	
sl@0
   634
	ret=iBitmap.Create(KSmallSize,EColor256);
sl@0
   635
	TEST2(ret, KErrNone);
sl@0
   636
sl@0
   637
	INFO_PRINTF1(_L("CFbsBitmap::Resize()\r\n"));
sl@0
   638
	for (count = 1; ; count++)
sl@0
   639
		{
sl@0
   640
		iFbs->SendCommand(EFbsMessDefaultAllocFail,count);
sl@0
   641
		if(heapMarkCheckFlag)
sl@0
   642
			{
sl@0
   643
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   644
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   645
			}
sl@0
   646
sl@0
   647
		ret = iBitmap.Resize(KSmallSizeAlt);
sl@0
   648
sl@0
   649
		if (ret == KErrNoMemory)
sl@0
   650
			{
sl@0
   651
			if(heapMarkCheckFlag)
sl@0
   652
				{
sl@0
   653
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   654
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   655
				}
sl@0
   656
			}
sl@0
   657
		else if (ret == KErrNone)
sl@0
   658
			{
sl@0
   659
			iBitmap.Reset();
sl@0
   660
			if(heapMarkCheckFlag)
sl@0
   661
				{
sl@0
   662
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   663
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   664
				}
sl@0
   665
			break;
sl@0
   666
			}
sl@0
   667
		else 
sl@0
   668
			TEST2(ret, KErrNone);
sl@0
   669
		}
sl@0
   670
sl@0
   671
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   672
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   673
	TEST(iFbs->ResourceCount()==0);
sl@0
   674
	
sl@0
   675
	
sl@0
   676
	// force fbserv to do a resize. This makes the pile to insert an index in it's array
sl@0
   677
	// If the array is empty when the tests below are run then the insert will look like a mem leak
sl@0
   678
	ret=iBitmap.Create(KLargeSize,EColor256);
sl@0
   679
	iBitmap.Resize(KLargeSizeAlt);
sl@0
   680
	iBitmap.Reset();
sl@0
   681
	
sl@0
   682
	ret=iBitmap.Create(KLargeSize,EColor256);
sl@0
   683
	TEST2(ret, KErrNone);
sl@0
   684
sl@0
   685
	for (count = 1; ; count++)
sl@0
   686
		{
sl@0
   687
		iFbs->SendCommand(EFbsMessUserAllocFail,count);
sl@0
   688
		if(heapMarkCheckFlag)
sl@0
   689
			{
sl@0
   690
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   691
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   692
			}
sl@0
   693
sl@0
   694
		ret = iBitmap.Resize(KLargeSizeAlt);
sl@0
   695
sl@0
   696
		if (ret == KErrNoMemory)
sl@0
   697
			{
sl@0
   698
			if(heapMarkCheckFlag)
sl@0
   699
				{
sl@0
   700
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   701
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   702
				}
sl@0
   703
			}
sl@0
   704
		else if (ret == KErrNone)
sl@0
   705
			{
sl@0
   706
			iBitmap.Reset();
sl@0
   707
			if(heapMarkCheckFlag)
sl@0
   708
				{
sl@0
   709
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   710
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   711
				}
sl@0
   712
			break;
sl@0
   713
			}
sl@0
   714
		else 
sl@0
   715
			TEST2(ret, KErrNone);
sl@0
   716
		}
sl@0
   717
sl@0
   718
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   719
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   720
	TEST(iFbs->ResourceCount()==0);
sl@0
   721
sl@0
   722
// Compress
sl@0
   723
	ret=iBitmap.Create(KSmallSize,EColor256);
sl@0
   724
	TEST2(ret, KErrNone);
sl@0
   725
sl@0
   726
	INFO_PRINTF1(_L("CFbsBitmap::Compress()\r\n"));
sl@0
   727
	for (count = 1; ; count++)
sl@0
   728
		{
sl@0
   729
		iFbs->SendCommand(EFbsMessDefaultAllocFail,count);
sl@0
   730
		if(heapMarkCheckFlag)
sl@0
   731
			{
sl@0
   732
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   733
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   734
			}
sl@0
   735
sl@0
   736
		ret = iBitmap.Compress();
sl@0
   737
sl@0
   738
		if (ret == KErrNoMemory)
sl@0
   739
			{
sl@0
   740
			if(heapMarkCheckFlag)
sl@0
   741
				{
sl@0
   742
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   743
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   744
				}
sl@0
   745
			}
sl@0
   746
		else if (ret == KErrNone)
sl@0
   747
			{
sl@0
   748
			iBitmap.Reset();
sl@0
   749
			if(heapMarkCheckFlag)
sl@0
   750
				{
sl@0
   751
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   752
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   753
				}
sl@0
   754
			break;
sl@0
   755
			}
sl@0
   756
		else 
sl@0
   757
			TEST2(ret, KErrNone);
sl@0
   758
		}
sl@0
   759
sl@0
   760
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   761
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   762
	TEST(iFbs->ResourceCount()==0);
sl@0
   763
sl@0
   764
	ret=iBitmap.Create(KLargeSize,EColor256);
sl@0
   765
	TEST2(ret, KErrNone);
sl@0
   766
sl@0
   767
	INFO_PRINTF1(_L("CFbsBitmap::Compress()\r\n"));
sl@0
   768
	for (count = 1; ; count++)
sl@0
   769
		{
sl@0
   770
		iFbs->SendCommand(EFbsMessDefaultAllocFail,count);
sl@0
   771
		if(heapMarkCheckFlag)
sl@0
   772
			{
sl@0
   773
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   774
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   775
			}
sl@0
   776
sl@0
   777
		ret = iBitmap.Compress();
sl@0
   778
sl@0
   779
		if (ret == KErrNoMemory)
sl@0
   780
			{
sl@0
   781
			if(heapMarkCheckFlag)
sl@0
   782
				{
sl@0
   783
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   784
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   785
				}
sl@0
   786
			}
sl@0
   787
		else if (ret == KErrNone)
sl@0
   788
			{
sl@0
   789
			iBitmap.Reset();
sl@0
   790
			if(heapMarkCheckFlag)
sl@0
   791
				{
sl@0
   792
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   793
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   794
				}
sl@0
   795
			break;
sl@0
   796
			}
sl@0
   797
		else 
sl@0
   798
			TEST2(ret, KErrNone);
sl@0
   799
		}
sl@0
   800
sl@0
   801
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   802
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   803
	TEST(iFbs->ResourceCount()==0);
sl@0
   804
sl@0
   805
// WriteStore creation
sl@0
   806
	RFs fs;
sl@0
   807
	ret=fs.Connect();
sl@0
   808
	TEST2(ret, KErrNone);
sl@0
   809
	CDirectFileStore* writestore=NULL;
sl@0
   810
sl@0
   811
	//Construct filename using the thread id to enable concurrent test runs.
sl@0
   812
	_LIT(KSbmFileName,"c:\\tall_");
sl@0
   813
	TBuf<36> buf(KSbmFileName);
sl@0
   814
	TThreadId threadId = RThread().Id();
sl@0
   815
	TUint64 id = threadId.Id();
sl@0
   816
	TBuf<20> threadIdBuf;
sl@0
   817
	threadIdBuf.Num(id);
sl@0
   818
	buf.Append(threadIdBuf);
sl@0
   819
	buf.Append(_L(".sbm"));
sl@0
   820
	
sl@0
   821
	TRAP(ret,writestore=CDirectFileStore::ReplaceL(fs,buf,EFileStream|EFileWrite));
sl@0
   822
	TEST2(ret, KErrNone);
sl@0
   823
	TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
sl@0
   824
	TRAP(ret,writestore->SetTypeL(uidtype));
sl@0
   825
	TEST2(ret, KErrNone);
sl@0
   826
sl@0
   827
	RStoreWriteStream writestrm;
sl@0
   828
	TStreamId headerid(0);
sl@0
   829
	TRAP(ret,headerid=writestrm.CreateL(*writestore));
sl@0
   830
	TEST2(ret, KErrNone);
sl@0
   831
	TRAP(ret,writestore->SetRootL(headerid));
sl@0
   832
	TEST2(ret, KErrNone);
sl@0
   833
sl@0
   834
// Externalize
sl@0
   835
	ret=iBitmap.Create(KSmallSize,EColor256);
sl@0
   836
	TEST2(ret, KErrNone);
sl@0
   837
sl@0
   838
	INFO_PRINTF1(_L("CFbsBitmap::ExternalizeL()\r\n"));
sl@0
   839
	for (count = 1; ; count++)
sl@0
   840
		{
sl@0
   841
		__UHEAP_SETFAIL(RHeap::EDeterministic,count);
sl@0
   842
		__UHEAP_MARK;
sl@0
   843
sl@0
   844
		TRAP(ret,iBitmap.ExternalizeL(writestrm));
sl@0
   845
sl@0
   846
		if (ret == KErrNoMemory)
sl@0
   847
			{
sl@0
   848
			__UHEAP_MARKEND;
sl@0
   849
			}
sl@0
   850
		else if (ret == KErrNone)
sl@0
   851
			{
sl@0
   852
			iBitmap.Reset();
sl@0
   853
			__UHEAP_MARKEND;
sl@0
   854
			break;
sl@0
   855
			}
sl@0
   856
		else 
sl@0
   857
			{
sl@0
   858
			__UHEAP_MARKEND;
sl@0
   859
			TEST2(ret, KErrNone);
sl@0
   860
			}
sl@0
   861
		}
sl@0
   862
sl@0
   863
	__UHEAP_RESET;
sl@0
   864
	TEST(iFbs->ResourceCount()==0);
sl@0
   865
sl@0
   866
// ExternalizeRectangle
sl@0
   867
	ret=iBitmap.Create(KSmallSize,EColor256);
sl@0
   868
	TEST2(ret, KErrNone);
sl@0
   869
sl@0
   870
	INFO_PRINTF1(_L("CFbsBitmap::ExternalizeRectangleL()\r\n"));
sl@0
   871
	for (count = 1; ; count++)
sl@0
   872
		{
sl@0
   873
		__UHEAP_SETFAIL(RHeap::EDeterministic,count);
sl@0
   874
		__UHEAP_MARK;
sl@0
   875
sl@0
   876
		TRAP(ret,iBitmap.ExternalizeRectangleL(writestrm,TRect(3,3,7,7)));
sl@0
   877
sl@0
   878
		if (ret == KErrNoMemory)
sl@0
   879
			{
sl@0
   880
			__UHEAP_MARKEND;
sl@0
   881
			}
sl@0
   882
		else if (ret == KErrNone)
sl@0
   883
			{
sl@0
   884
			__UHEAP_MARKEND;
sl@0
   885
			break;
sl@0
   886
			}
sl@0
   887
		else 
sl@0
   888
			{
sl@0
   889
			__UHEAP_MARKEND;
sl@0
   890
			TEST2(ret, KErrNone);
sl@0
   891
			}
sl@0
   892
		}
sl@0
   893
sl@0
   894
	__UHEAP_RESET;
sl@0
   895
	writestrm.Close();
sl@0
   896
	delete writestore;
sl@0
   897
	iBitmap.Reset();
sl@0
   898
	TEST(iFbs->ResourceCount()==0);
sl@0
   899
sl@0
   900
// Internalize
sl@0
   901
	INFO_PRINTF1(_L("CFbsBitmap::InternalizeL()\r\n"));
sl@0
   902
	for (count = 1; ; count++)
sl@0
   903
		{
sl@0
   904
		// ReadStore creation
sl@0
   905
		CDirectFileStore* readstore=NULL;
sl@0
   906
		TRAP(ret,readstore=CDirectFileStore::OpenL(fs,buf,EFileStream|EFileRead|EFileShareAny));
sl@0
   907
		TEST2(ret, KErrNone);
sl@0
   908
		RStoreReadStream readstrm;
sl@0
   909
		headerid=readstore->Root();
sl@0
   910
		TRAP(ret,readstrm.OpenL(*readstore,headerid));
sl@0
   911
		TEST2(ret, KErrNone);
sl@0
   912
sl@0
   913
		iFbs->SendCommand(EFbsMessDefaultAllocFail,count);
sl@0
   914
		if(heapMarkCheckFlag)
sl@0
   915
			{
sl@0
   916
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   917
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   918
			}
sl@0
   919
sl@0
   920
		TRAP(ret,iBitmap.InternalizeL(readstrm));
sl@0
   921
sl@0
   922
		readstrm.Close();
sl@0
   923
		delete readstore;
sl@0
   924
sl@0
   925
		if (ret == KErrNoMemory)
sl@0
   926
			{
sl@0
   927
			if(heapMarkCheckFlag)
sl@0
   928
				{
sl@0
   929
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   930
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   931
				}
sl@0
   932
			}
sl@0
   933
		else if (ret == KErrNone)
sl@0
   934
			{
sl@0
   935
			iBitmap.Reset();
sl@0
   936
			if(heapMarkCheckFlag)
sl@0
   937
				{
sl@0
   938
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   939
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   940
				}
sl@0
   941
			break;
sl@0
   942
			}
sl@0
   943
		else 
sl@0
   944
			TEST2(ret, KErrNone);
sl@0
   945
		}
sl@0
   946
sl@0
   947
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   948
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   949
	TEST(iFbs->ResourceCount()==0);
sl@0
   950
sl@0
   951
	for (count = 1; ; count++)
sl@0
   952
		{
sl@0
   953
		// ReadStore re-creation
sl@0
   954
		CDirectFileStore* readstore=NULL;
sl@0
   955
//		TRAP(ret,readstore=CDirectFileStore::OpenL(fs,_L("c:\\tall.sbm"),EFileStream|EFileRead|EFileShareAny));
sl@0
   956
		TRAP(ret,readstore=CDirectFileStore::OpenL(fs,buf,EFileStream|EFileRead|EFileShareAny));
sl@0
   957
		TEST2(ret, KErrNone);
sl@0
   958
		headerid=readstore->Root();
sl@0
   959
		RStoreReadStream readstrm;
sl@0
   960
		TRAP(ret,readstrm.OpenL(*readstore,headerid));
sl@0
   961
		TEST2(ret, KErrNone);
sl@0
   962
sl@0
   963
		iFbs->SendCommand(EFbsMessUserAllocFail,count);
sl@0
   964
		if(heapMarkCheckFlag)
sl@0
   965
			{
sl@0
   966
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
   967
			iFbs->SendCommand(EFbsMessUserMark);
sl@0
   968
			}
sl@0
   969
sl@0
   970
		TRAP(ret,iBitmap.InternalizeL(readstrm));
sl@0
   971
sl@0
   972
		readstrm.Close();
sl@0
   973
		delete readstore;
sl@0
   974
sl@0
   975
		if (ret == KErrNoMemory)
sl@0
   976
			{
sl@0
   977
			if(heapMarkCheckFlag)
sl@0
   978
				{
sl@0
   979
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   980
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   981
				}
sl@0
   982
			}
sl@0
   983
		else if (ret == KErrNone)
sl@0
   984
			{
sl@0
   985
			iBitmap.Reset();
sl@0
   986
			if(heapMarkCheckFlag)
sl@0
   987
				{
sl@0
   988
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   989
				iFbs->SendCommand(EFbsMessUserMarkEnd);
sl@0
   990
				}
sl@0
   991
			break;
sl@0
   992
			}
sl@0
   993
		else 
sl@0
   994
			TEST2(ret, KErrNone);
sl@0
   995
		}
sl@0
   996
sl@0
   997
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
   998
	iFbs->SendCommand(EFbsMessUserAllocFail,0);
sl@0
   999
	TEST(iFbs->ResourceCount()==0);
sl@0
  1000
sl@0
  1001
	fs.Delete(buf);
sl@0
  1002
	fs.Close();
sl@0
  1003
	}
sl@0
  1004
sl@0
  1005
/**
sl@0
  1006
	@SYMTestCaseID
sl@0
  1007
	GRAPHICS-FBSERV-0513
sl@0
  1008
sl@0
  1009
	@SYMTestCaseDesc
sl@0
  1010
	Checks allocations of CFbsTypeFaceStore Objects OOM conditions
sl@0
  1011
sl@0
  1012
	@SYMTestActions
sl@0
  1013
	Uses different fonts and allocates CFbsTypeFaceStore objects
sl@0
  1014
	and checks them under Out Of Memory conditions
sl@0
  1015
	
sl@0
  1016
	@SYMTestExpectedResults
sl@0
  1017
	Test should pass
sl@0
  1018
*/
sl@0
  1019
void CTAlloc::TypefaceStoreL()
sl@0
  1020
	{
sl@0
  1021
	TInt count;
sl@0
  1022
	TInt ret;
sl@0
  1023
	CFbsTypefaceStore* tfs = NULL;
sl@0
  1024
	INFO_PRINTF1(_L("CFbsTypefaceStore::NewL()\r\n"));
sl@0
  1025
sl@0
  1026
	TInt heapMarkCheckFlag;
sl@0
  1027
	if( !iStep->GetIntFromConfig(KDefaultSectionName, KFbsHeapMarkCheckFlag, heapMarkCheckFlag) )
sl@0
  1028
		{
sl@0
  1029
		INFO_PRINTF1(_L("Error reading ini file"));
sl@0
  1030
		User::Leave(KErrNotFound);
sl@0
  1031
		}
sl@0
  1032
	
sl@0
  1033
// CFbsTypefaceStore::NewL()
sl@0
  1034
	for (count = 1; ; count++)
sl@0
  1035
		{
sl@0
  1036
		__UHEAP_SETFAIL(RHeap::EDeterministic,count);
sl@0
  1037
		__UHEAP_MARK;
sl@0
  1038
sl@0
  1039
		TRAP(ret,tfs=CFbsTypefaceStore::NewL(NULL));
sl@0
  1040
sl@0
  1041
		if (ret == KErrNoMemory)
sl@0
  1042
			{
sl@0
  1043
			__UHEAP_MARKEND;
sl@0
  1044
			}
sl@0
  1045
		else if (ret == KErrNone)
sl@0
  1046
			{
sl@0
  1047
			delete tfs;
sl@0
  1048
			__UHEAP_MARKEND;
sl@0
  1049
			break;
sl@0
  1050
			}
sl@0
  1051
		else 
sl@0
  1052
			{
sl@0
  1053
			__UHEAP_MARKEND;
sl@0
  1054
			TEST2(ret, KErrNone);
sl@0
  1055
			}
sl@0
  1056
		}
sl@0
  1057
sl@0
  1058
	__UHEAP_RESET;
sl@0
  1059
sl@0
  1060
// CFbsTypefaceStore::SetFontNameAliasL()
sl@0
  1061
	_LIT(KFontNameAlias,"Fubar");
sl@0
  1062
	TRAP(ret,tfs = CFbsTypefaceStore::NewL(NULL));
sl@0
  1063
	TEST2(ret, KErrNone);
sl@0
  1064
	TRAP(ret, tfs->SetFontNameAliasL(_L("ExpandArray"),_L("DejaVu Serif Condensed")));
sl@0
  1065
	TEST2(ret, KErrNone);
sl@0
  1066
	TRAP(ret, tfs->SetFontNameAliasL(_L("ExpandArray"),KNullDesC));
sl@0
  1067
	TEST2(ret, KErrNone);
sl@0
  1068
sl@0
  1069
	for (count = 1; ; count++)
sl@0
  1070
		{
sl@0
  1071
		iFbs->SendCommand(EFbsMessDefaultAllocFail,count);
sl@0
  1072
		if(heapMarkCheckFlag)
sl@0
  1073
			{
sl@0
  1074
			iFbs->SendCommand(EFbsMessDefaultMark);
sl@0
  1075
			}
sl@0
  1076
sl@0
  1077
		TRAP(ret, tfs->SetFontNameAliasL(KFontNameAlias,_L("DejaVu Serif Condensed")));
sl@0
  1078
sl@0
  1079
		if (ret == KErrNoMemory)
sl@0
  1080
			{
sl@0
  1081
			if(heapMarkCheckFlag)
sl@0
  1082
				{
sl@0
  1083
				iFbs->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
  1084
				}
sl@0
  1085
			}
sl@0
  1086
		else if (ret == KErrNone)
sl@0
  1087
			{
sl@0
  1088
			if(heapMarkCheckFlag)
sl@0
  1089
				{
sl@0
  1090
				iFbs->SendCommand(EFbsMessDefaultMarkEnd,2);
sl@0
  1091
				}
sl@0
  1092
			break;
sl@0
  1093
			}
sl@0
  1094
		else 
sl@0
  1095
			TEST2(ret, KErrNone);
sl@0
  1096
		}
sl@0
  1097
sl@0
  1098
	iFbs->SendCommand(EFbsMessDefaultAllocFail,0);
sl@0
  1099
sl@0
  1100
// GetNearestFontToDesignHeightInTwips()
sl@0
  1101
	TFontSpec spec(_L("SwissA"),12);
sl@0
  1102
	CFont* font = NULL;
sl@0
  1103
	ret = tfs->GetNearestFontToDesignHeightInTwips(font,spec);
sl@0
  1104
	TEST2(ret, KErrNone);
sl@0
  1105
	tfs->ReleaseFont(font);
sl@0
  1106
	spec.iTypeface.iName = _L("DejaVu Serif Condensed");
sl@0
  1107
sl@0
  1108
	for (count = 1; ; count++)
sl@0
  1109
		{
sl@0
  1110
		__UHEAP_SETFAIL(RHeap::EDeterministic,count);
sl@0
  1111
		__UHEAP_MARK;
sl@0
  1112
		
sl@0
  1113
		ret = tfs->GetNearestFontToDesignHeightInTwips(font,spec);
sl@0
  1114
sl@0
  1115
		if (ret == KErrNoMemory)
sl@0
  1116
			{
sl@0
  1117
			ASSERT(!font);
sl@0
  1118
			__UHEAP_MARKEND;
sl@0
  1119
			}
sl@0
  1120
		else if (ret == KErrNone)
sl@0
  1121
			{
sl@0
  1122
			ASSERT(font);
sl@0
  1123
			tfs->ReleaseFont(font);
sl@0
  1124
			__UHEAP_MARKEND;
sl@0
  1125
			break;
sl@0
  1126
			}
sl@0
  1127
		else 
sl@0
  1128
			{
sl@0
  1129
			__UHEAP_MARKEND;
sl@0
  1130
			TEST2(ret, KErrNone);
sl@0
  1131
			}
sl@0
  1132
		}
sl@0
  1133
sl@0
  1134
	__UHEAP_RESET;
sl@0
  1135
sl@0
  1136
// GetNearestFontToDesignHeightInTwips() with alias
sl@0
  1137
	spec.iTypeface.iName = KFontNameAlias;
sl@0
  1138
	TRAP(ret, tfs->SetFontNameAliasL(KFontNameAlias,_L("DejaVu Serif Condensed")));
sl@0
  1139
	TEST2(ret, KErrNone);
sl@0
  1140
sl@0
  1141
	for (count = 1; ; count++)
sl@0
  1142
		{
sl@0
  1143
		__UHEAP_SETFAIL(RHeap::EDeterministic,count);
sl@0
  1144
		__UHEAP_MARK;
sl@0
  1145
sl@0
  1146
		ret = tfs->GetNearestFontToDesignHeightInTwips(font,spec);
sl@0
  1147
sl@0
  1148
		if (ret == KErrNoMemory)
sl@0
  1149
			{
sl@0
  1150
			ASSERT(!font);
sl@0
  1151
			__UHEAP_MARKEND;
sl@0
  1152
			}
sl@0
  1153
		else if (ret == KErrNone)
sl@0
  1154
			{
sl@0
  1155
			ASSERT(font);
sl@0
  1156
			tfs->ReleaseFont(font);
sl@0
  1157
			__UHEAP_MARKEND;
sl@0
  1158
			break;
sl@0
  1159
			}
sl@0
  1160
		else
sl@0
  1161
			{
sl@0
  1162
			__UHEAP_MARKEND;
sl@0
  1163
			TEST2(ret, KErrNone);
sl@0
  1164
			}
sl@0
  1165
		}
sl@0
  1166
sl@0
  1167
	__UHEAP_RESET;
sl@0
  1168
	TRAP(ret, tfs->SetFontNameAliasL(KFontNameAlias,KNullDesC));
sl@0
  1169
	TEST2(ret, KErrNone);
sl@0
  1170
	delete tfs;
sl@0
  1171
	}
sl@0
  1172
sl@0
  1173
/**
sl@0
  1174
	@SYMTestCaseID
sl@0
  1175
	GRAPHICS-FBSERV-0514
sl@0
  1176
sl@0
  1177
	@SYMTestCaseDesc
sl@0
  1178
	Asynchronous loading and saving of bitmaps
sl@0
  1179
sl@0
  1180
	@SYMTestActions
sl@0
  1181
	Creates a loader for bitmaps and simulates Out Of Memory conditions
sl@0
  1182
	and then creates and saver and simulates Out Of Memory conditions
sl@0
  1183
	
sl@0
  1184
	@SYMTestExpectedResults
sl@0
  1185
	Test should pass
sl@0
  1186
*/
sl@0
  1187
void CTAlloc::BitmapHandlerL()
sl@0
  1188
	{
sl@0
  1189
	TInt ret=KErrNone;
sl@0
  1190
	CFbsBitmapAsyncStreamer* bmphandler=NULL;
sl@0
  1191
sl@0
  1192
// Create loader
sl@0
  1193
	TInt count;
sl@0
  1194
	INFO_PRINTF1(_L("CFbsBitmapAsyncStreamer::NewL()\r\n"));
sl@0
  1195
	for (count = 1; ; count++)
sl@0
  1196
		{
sl@0
  1197
		__UHEAP_SETFAIL(RHeap::EDeterministic,count);
sl@0
  1198
		__UHEAP_MARK;
sl@0
  1199
sl@0
  1200
		TRAP(ret,bmphandler = CFbsBitmapAsyncStreamer::NewL(CFbsBitmapAsyncStreamer::ELoad));
sl@0
  1201
sl@0
  1202
		if (ret == KErrNoMemory)
sl@0
  1203
			{
sl@0
  1204
			__UHEAP_MARKEND;
sl@0
  1205
			}
sl@0
  1206
		else if (ret == KErrNone)
sl@0
  1207
			{
sl@0
  1208
			delete bmphandler;
sl@0
  1209
			__UHEAP_MARKEND;
sl@0
  1210
			break;
sl@0
  1211
			}
sl@0
  1212
		else 
sl@0
  1213
			{
sl@0
  1214
			__UHEAP_MARKEND;
sl@0
  1215
			TEST2(ret, KErrNone);
sl@0
  1216
			}
sl@0
  1217
		}
sl@0
  1218
sl@0
  1219
	__UHEAP_RESET;
sl@0
  1220
	TEST(iFbs->ResourceCount()==0);
sl@0
  1221
sl@0
  1222
// Create saver
sl@0
  1223
	for (count = 1; ; count++)
sl@0
  1224
		{
sl@0
  1225
		__UHEAP_SETFAIL(RHeap::EDeterministic,count);
sl@0
  1226
		__UHEAP_MARK;
sl@0
  1227
sl@0
  1228
		TRAP(ret,bmphandler=CFbsBitmapAsyncStreamer::NewL(CFbsBitmapAsyncStreamer::ESave));
sl@0
  1229
sl@0
  1230
		if (ret == KErrNoMemory)
sl@0
  1231
			{
sl@0
  1232
			__UHEAP_MARKEND;
sl@0
  1233
			}
sl@0
  1234
		else if (ret == KErrNone)
sl@0
  1235
			{
sl@0
  1236
			delete bmphandler;
sl@0
  1237
			__UHEAP_MARKEND;
sl@0
  1238
			break;
sl@0
  1239
			}
sl@0
  1240
		else 
sl@0
  1241
			{
sl@0
  1242
			__UHEAP_MARKEND;
sl@0
  1243
			TEST2(ret, KErrNone);
sl@0
  1244
			}
sl@0
  1245
		}
sl@0
  1246
sl@0
  1247
	__UHEAP_RESET;
sl@0
  1248
	TEST(iFbs->ResourceCount()==0);
sl@0
  1249
	}
sl@0
  1250
sl@0
  1251
/**
sl@0
  1252
	@SYMTestCaseID
sl@0
  1253
	GRAPHICS-FBSERV-0515
sl@0
  1254
sl@0
  1255
	@SYMTestCaseDesc
sl@0
  1256
	Tests memory allocation of CFontStore object
sl@0
  1257
sl@0
  1258
	@SYMTestActions
sl@0
  1259
	CFontStore objects is created on the heap
sl@0
  1260
	
sl@0
  1261
	@SYMTestExpectedResults
sl@0
  1262
	Test should pass
sl@0
  1263
*/
sl@0
  1264
void CTAlloc::FontStoreL()
sl@0
  1265
	{
sl@0
  1266
	INFO_PRINTF1(_L("CFontStore::NewL()\r\n"));
sl@0
  1267
sl@0
  1268
	for (TInt count = 1; ; count++)
sl@0
  1269
		{
sl@0
  1270
		__UHEAP_SETFAIL(RHeap::EDeterministic,count);
sl@0
  1271
		__UHEAP_MARK;
sl@0
  1272
sl@0
  1273
		CFontStore* fs = NULL;
sl@0
  1274
		TRAPD(ret,fs = CFontStore::NewL(&User::Heap()));
sl@0
  1275
sl@0
  1276
		if (ret == KErrNoMemory)
sl@0
  1277
			{
sl@0
  1278
			__UHEAP_MARKEND;
sl@0
  1279
			}
sl@0
  1280
		else if (ret == KErrNone)
sl@0
  1281
			{
sl@0
  1282
			delete fs;
sl@0
  1283
			__UHEAP_MARKEND;
sl@0
  1284
			__UHEAP_SETFAIL(RHeap::ENone,count);
sl@0
  1285
			break;
sl@0
  1286
			}
sl@0
  1287
		else
sl@0
  1288
			{
sl@0
  1289
			__UHEAP_MARKEND;
sl@0
  1290
			TEST2(ret, KErrNone);
sl@0
  1291
			}
sl@0
  1292
		}
sl@0
  1293
sl@0
  1294
	}
sl@0
  1295
sl@0
  1296
//--------------
sl@0
  1297
__CONSTRUCT_STEP__(Alloc)
sl@0
  1298