os/graphics/fbs/fontandbitmapserver/tfbs/trfile.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) 2005-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 <f32file.h>
sl@0
    17
#include <fbs.h>
sl@0
    18
#include <bitdev.h>
sl@0
    19
#include <bitstd.h>
sl@0
    20
#include <graphics/gdi/gdiconsts.h>
sl@0
    21
#include "../sfbs/UTILS.H"
sl@0
    22
#include "trfile.h"
sl@0
    23
#include "fbsmessage.h"
sl@0
    24
#include "fbsdefs.h"
sl@0
    25
sl@0
    26
// Define FBSTEST_SCREENSHOT to save the screen to a .mbm file
sl@0
    27
//#define FBSTEST_SCREENSHOT
sl@0
    28
sl@0
    29
const TInt KNumBitmap = 3;
sl@0
    30
const TDisplayMode KDisplayMode = EColor64K;
sl@0
    31
const TSize KLargeSize(128,128);
sl@0
    32
const TSize KMidSize(64,64);
sl@0
    33
const TSize KSmallSize(32,32);
sl@0
    34
sl@0
    35
sl@0
    36
_LIT(KRamFile1,"c:\\rf1.mbm");
sl@0
    37
_LIT(KRamFile2,"c:\\rf2.mbm");
sl@0
    38
_LIT(KRamFile3,"c:\\rf3.mbm");
sl@0
    39
_LIT(KRamFile4,"c:\\rf123.mbm");
sl@0
    40
_LIT(KRomFile1,"z:\\system\\data\\rf1.mbm");
sl@0
    41
_LIT(KRomFile2,"z:\\system\\data\\rf2.mbm");
sl@0
    42
_LIT(KRomFile3,"z:\\system\\data\\rf3.mbm");
sl@0
    43
_LIT(KRomFile4,"z:\\system\\data\\rf123.mbm");
sl@0
    44
sl@0
    45
sl@0
    46
CTFile::CTFile(CTestStep* aStep):
sl@0
    47
	CTGraphicsBase(aStep),
sl@0
    48
	iFbs(NULL),
sl@0
    49
	iSource(KNumBitmap)
sl@0
    50
	{
sl@0
    51
	}
sl@0
    52
sl@0
    53
CTFile::~CTFile()
sl@0
    54
	{
sl@0
    55
	CleanUp();
sl@0
    56
	if (iShutdownFbs)
sl@0
    57
		iFbs->SendCommand(EFbsMessShutdown);
sl@0
    58
	iFbs->Disconnect();
sl@0
    59
	}
sl@0
    60
	
sl@0
    61
sl@0
    62
void CTFile::ConstructL()
sl@0
    63
	{
sl@0
    64
	if(RFbsSession::Connect()==KErrNone)
sl@0
    65
		{
sl@0
    66
		RFbsSession::Disconnect();
sl@0
    67
		iShutdownFbs = EFalse;
sl@0
    68
		}
sl@0
    69
	else
sl@0
    70
		{
sl@0
    71
		FbsStartup();
sl@0
    72
		iShutdownFbs = ETrue;
sl@0
    73
		}
sl@0
    74
sl@0
    75
	TInt ret = RFbsSession::Connect();
sl@0
    76
	TEST(ret==KErrNone);
sl@0
    77
	iFbs = RFbsSession::GetSession();
sl@0
    78
	TEST(iFbs != NULL);
sl@0
    79
sl@0
    80
	ret = iFs.Connect();
sl@0
    81
	TEST(ret==KErrNone);
sl@0
    82
	// required to allow file handle to be adopted by another process
sl@0
    83
	iFs.ShareProtected();
sl@0
    84
	
sl@0
    85
	TUint32* romAddress = NULL;
sl@0
    86
	if(!CFbsBitmap::IsFileInRom(KRomFile1, romAddress)) //any ROM bitmap
sl@0
    87
		{
sl@0
    88
		INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."),
sl@0
    89
				&KRomFile1);
sl@0
    90
		INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported."));
sl@0
    91
		iSkipRomBitmapTests = ETrue;
sl@0
    92
		}
sl@0
    93
	}
sl@0
    94
sl@0
    95
void CTFile::CleanUp()
sl@0
    96
	{
sl@0
    97
	const TBufC<32> names[KNumBitmap] =
sl@0
    98
		{
sl@0
    99
		(const TDesC&)KRamFile1,
sl@0
   100
		(const TDesC&)KRamFile2,
sl@0
   101
		(const TDesC&)KRamFile3
sl@0
   102
		};
sl@0
   103
	TInt i;
sl@0
   104
	for (i=0; i<KNumBitmap; ++i)
sl@0
   105
		{
sl@0
   106
		delete iSource[i];
sl@0
   107
		iFs.Delete(names[i]);
sl@0
   108
		}
sl@0
   109
	iSource.Close();
sl@0
   110
	iFs.Delete(KRamFile4);
sl@0
   111
	iFs.Close();	
sl@0
   112
	}
sl@0
   113
	
sl@0
   114
void CTFile::RunTestCaseL(TInt aCurTestCase)
sl@0
   115
	{
sl@0
   116
	((CTFileStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
   117
	switch(aCurTestCase)
sl@0
   118
		{
sl@0
   119
	case 1:
sl@0
   120
		((CTFileStep*)iStep)->SetTestStepID(_L("	GRAPHICS-FBSERV-0588"));
sl@0
   121
		CreateL();
sl@0
   122
		break;
sl@0
   123
	case 2:
sl@0
   124
		((CTFileStep*)iStep)->SetTestStepID(_L("	GRAPHICS-FBSERV-0589"));
sl@0
   125
		SaveL();
sl@0
   126
		break;
sl@0
   127
	case 3:
sl@0
   128
		((CTFileStep*)iStep)->SetTestStepID(_L("	GRAPHICS-FBSERV-0590"));
sl@0
   129
		StoreL();
sl@0
   130
		break;
sl@0
   131
	case 4:
sl@0
   132
		((CTFileStep*)iStep)->SetTestStepID(_L("	GRAPHICS-FBSERV-0591"));
sl@0
   133
		LoadL();
sl@0
   134
		break;
sl@0
   135
	case 5:
sl@0
   136
		((CTFileStep*)iStep)->SetTestStepID(_L("	GRAPHICS-FBSERV-0592"));
sl@0
   137
		LoadAndCompressL();
sl@0
   138
		break;
sl@0
   139
	case 6:
sl@0
   140
		((CTFileStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   141
		((CTFileStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   142
		TestComplete();
sl@0
   143
		break;
sl@0
   144
		}
sl@0
   145
	((CTFileStep*)iStep)->RecordTestResultL();
sl@0
   146
	}
sl@0
   147
sl@0
   148
sl@0
   149
/**
sl@0
   150
	Draw union jack
sl@0
   151
*/
sl@0
   152
void CTFile::Draw(CFbsBitGc* aGc, const TSize& aSize)
sl@0
   153
	{
sl@0
   154
	const TSize thick(aSize.iWidth/4,aSize.iWidth/4);
sl@0
   155
	const TSize thin(thick.iWidth/2,thick.iWidth/2);
sl@0
   156
	
sl@0
   157
	// background
sl@0
   158
	aGc->SetBrushColor(KRgbBlue);
sl@0
   159
	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   160
	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
sl@0
   161
	aGc->DrawRect(aSize);
sl@0
   162
sl@0
   163
	// corner to corner section
sl@0
   164
	aGc->SetPenColor(KRgbWhite);
sl@0
   165
	aGc->SetPenSize(thick);
sl@0
   166
	aGc->DrawLine(TPoint(0,0),TPoint(aSize.iWidth,aSize.iHeight));
sl@0
   167
	aGc->DrawLine(TPoint(aSize.iWidth,0),TPoint(0,aSize.iHeight));	
sl@0
   168
	aGc->SetPenColor(KRgbRed);
sl@0
   169
	aGc->SetPenSize(thin);
sl@0
   170
	aGc->DrawLine(TPoint(0,0),TPoint(aSize.iWidth,aSize.iHeight));
sl@0
   171
	aGc->DrawLine(TPoint(aSize.iWidth,0),TPoint(0,aSize.iHeight));	
sl@0
   172
	
sl@0
   173
	// cross section
sl@0
   174
	aGc->SetPenColor(KRgbWhite);
sl@0
   175
	aGc->SetPenSize(thick);
sl@0
   176
	aGc->DrawLine(TPoint(aSize.iWidth/2,0),TPoint(aSize.iWidth/2,aSize.iHeight));	
sl@0
   177
	aGc->DrawLine(TPoint(0,aSize.iHeight/2),TPoint(aSize.iWidth,aSize.iHeight/2));	
sl@0
   178
	aGc->SetPenColor(KRgbRed);
sl@0
   179
	aGc->SetPenSize(thin);
sl@0
   180
	aGc->DrawLine(TPoint(aSize.iWidth/2,0),TPoint(aSize.iWidth/2,aSize.iHeight));	
sl@0
   181
	aGc->DrawLine(TPoint(0,aSize.iHeight/2),TPoint(aSize.iWidth,aSize.iHeight/2));	
sl@0
   182
	}
sl@0
   183
sl@0
   184
/**
sl@0
   185
sl@0
   186
*/	
sl@0
   187
/**
sl@0
   188
	@SYMTestCaseID
sl@0
   189
	GRAPHICS-FBSERV-0588
sl@0
   190
sl@0
   191
	@SYMTestCaseDesc
sl@0
   192
	Create various size bitmap for testing (original bitmaps) 
sl@0
   193
	ie small (<4KB), mid (=4KB) and large (>4KB).
sl@0
   194
	
sl@0
   195
	@SYMTestActions	
sl@0
   196
	
sl@0
   197
	@SYMTestExpectedResults
sl@0
   198
	Test should pass
sl@0
   199
*/
sl@0
   200
void CTFile::CreateL()
sl@0
   201
	{
sl@0
   202
	const TSize sizes[KNumBitmap] = 
sl@0
   203
		{
sl@0
   204
		KSmallSize,
sl@0
   205
		KMidSize,
sl@0
   206
		KLargeSize
sl@0
   207
		};
sl@0
   208
	TInt i;
sl@0
   209
	for (i=0; i<KNumBitmap; ++i)
sl@0
   210
		{
sl@0
   211
		CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
sl@0
   212
		CleanupStack::PushL(bmp);
sl@0
   213
		User::LeaveIfError(bmp->Create(sizes[i],KDisplayMode));
sl@0
   214
		
sl@0
   215
		CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(bmp);
sl@0
   216
		CleanupStack::PushL(dev);
sl@0
   217
		
sl@0
   218
		CFbsBitGc* gc;
sl@0
   219
		User::LeaveIfError(dev->CreateContext(gc));
sl@0
   220
		
sl@0
   221
		Draw(gc,sizes[i]);
sl@0
   222
		
sl@0
   223
		delete gc;
sl@0
   224
		CleanupStack::PopAndDestroy(dev);
sl@0
   225
		
sl@0
   226
		iSource.AppendL(bmp);
sl@0
   227
		
sl@0
   228
		CleanupStack::Pop(bmp);
sl@0
   229
		}
sl@0
   230
	}
sl@0
   231
sl@0
   232
/**
sl@0
   233
	@SYMTestCaseID
sl@0
   234
	GRAPHICS-FBSERV-0589
sl@0
   235
sl@0
   236
	@SYMTestCaseDesc
sl@0
   237
	Save single bitmap to file using an opened file handle
sl@0
   238
	
sl@0
   239
	@SYMTestActions
sl@0
   240
	Save original bitmap to file using file handle (saved bitmap)
sl@0
   241
	Load saved bitmap using file name and compare against original
sl@0
   242
	Leave saved bitmap files for next test (Load,LoadAndCompress)
sl@0
   243
	
sl@0
   244
	@SYMTestExpectedResults
sl@0
   245
	Saved bitmap match original bitmap
sl@0
   246
*/
sl@0
   247
void CTFile::SaveL()
sl@0
   248
	{
sl@0
   249
	const TBufC<32> names[KNumBitmap] =
sl@0
   250
		{
sl@0
   251
		(const TDesC&)KRamFile1,
sl@0
   252
		(const TDesC&)KRamFile2,
sl@0
   253
		(const TDesC&)KRamFile3
sl@0
   254
		};
sl@0
   255
		
sl@0
   256
	INFO_PRINTF1(_L("Saving bitmap"));		
sl@0
   257
	TInt i;
sl@0
   258
	for (i=0; i<KNumBitmap; ++i)
sl@0
   259
		{
sl@0
   260
		RFile f;
sl@0
   261
		TInt mode = EFileWrite;
sl@0
   262
		TInt ret = f.Open(iFs,names[i],mode);
sl@0
   263
		if (ret==KErrNotFound)
sl@0
   264
			ret = f.Create(iFs,names[i],mode);
sl@0
   265
		TEST(ret==KErrNone);
sl@0
   266
		
sl@0
   267
		TEST(iSource[i]->Save(f)==KErrNone);
sl@0
   268
		f.Close();
sl@0
   269
		
sl@0
   270
		CFbsBitmap bmp;
sl@0
   271
		TEST(bmp.Load(names[i])==KErrNone);
sl@0
   272
		
sl@0
   273
		CFbsBitmap* orig = iSource[i];
sl@0
   274
		TSize size = orig->SizeInPixels();
sl@0
   275
		TInt bytes = orig->ScanLineLength(size.iWidth,KDisplayMode)*size.iHeight;
sl@0
   276
		orig->LockHeap();
sl@0
   277
		bmp.LockHeap();
sl@0
   278
		TEST(Mem::Compare((TUint8*)orig->DataAddress(),bytes,(TUint8*)bmp.DataAddress(),bytes)==0);
sl@0
   279
		orig->UnlockHeap();
sl@0
   280
		bmp.UnlockHeap();
sl@0
   281
		}
sl@0
   282
	}
sl@0
   283
sl@0
   284
/**
sl@0
   285
	@SYMTestCaseID
sl@0
   286
	GRAPHICS-FBSERV-0590
sl@0
   287
sl@0
   288
	@SYMTestCaseDesc
sl@0
   289
	Save multi bitmaps to file using an opened file handle.
sl@0
   290
	
sl@0
   291
	@SYMTestActions
sl@0
   292
	Save original bitmaps to file (saved bitmaps).
sl@0
   293
	Load saved bitmaps and compare it against originals.
sl@0
   294
	
sl@0
   295
	@SYMTestExpectedResults
sl@0
   296
	Saved bitmaps match original bitmaps
sl@0
   297
*/
sl@0
   298
void CTFile::StoreL()
sl@0
   299
	{
sl@0
   300
	const TBufC<32> names[KNumBitmap] =
sl@0
   301
		{
sl@0
   302
		(const TDesC&)KRamFile1,
sl@0
   303
		(const TDesC&)KRamFile2,
sl@0
   304
		(const TDesC&)KRamFile3
sl@0
   305
		};
sl@0
   306
	INFO_PRINTF1(_L("Storing bitmaps"));
sl@0
   307
	RFile f;
sl@0
   308
	TInt mode = EFileWrite;
sl@0
   309
	TInt ret = f.Open(iFs,KRamFile4,mode);
sl@0
   310
	if (ret==KErrNotFound)
sl@0
   311
		ret = f.Create(iFs,KRamFile4,mode);
sl@0
   312
	TEST(ret==KErrNone);
sl@0
   313
	
sl@0
   314
	const TDesC* bmps[] = {&names[0],&names[1],&names[2]};
sl@0
   315
	TInt32 ids[] = {0,0,0};
sl@0
   316
	TRAP(ret,CFbsBitmap::StoreL(f,KNumBitmap,bmps,ids));
sl@0
   317
	TEST(ret==KErrNone);
sl@0
   318
	f.Close();
sl@0
   319
	
sl@0
   320
	TInt id;
sl@0
   321
	for (id=0; id<KNumBitmap; ++id)
sl@0
   322
		{
sl@0
   323
		CFbsBitmap bmp;
sl@0
   324
		TEST(bmp.Load(KRamFile4,id)==KErrNone);
sl@0
   325
		
sl@0
   326
		CFbsBitmap* orig = iSource[id];
sl@0
   327
		TSize size = orig->SizeInPixels();
sl@0
   328
		TInt bytes = orig->ScanLineLength(size.iWidth,KDisplayMode)*size.iHeight;
sl@0
   329
		orig->LockHeap();
sl@0
   330
		bmp.LockHeap();
sl@0
   331
		TEST(Mem::Compare((TUint8*)orig->DataAddress(),bytes,(TUint8*)bmp.DataAddress(),bytes)==0);
sl@0
   332
		orig->UnlockHeap();
sl@0
   333
		bmp.UnlockHeap();
sl@0
   334
		}
sl@0
   335
	}
sl@0
   336
sl@0
   337
/**
sl@0
   338
	@SYMTestCaseID
sl@0
   339
	GRAPHICS-FBSERV-0591
sl@0
   340
sl@0
   341
	@SYMTestCaseDesc
sl@0
   342
	Load bitmap from file using an opened file handle.
sl@0
   343
	
sl@0
   344
	@SYMTestActions
sl@0
   345
	Load bitmap using file handle.
sl@0
   346
	Compare loaded bitmaps against original.
sl@0
   347
	
sl@0
   348
	@SYMTestExpectedResults
sl@0
   349
	Loaded bitmap match original
sl@0
   350
*/
sl@0
   351
void CTFile::LoadL()
sl@0
   352
	{
sl@0
   353
	// Load single bitmap file
sl@0
   354
	const TBufC<32> names[2*KNumBitmap] =
sl@0
   355
		{
sl@0
   356
		(const TDesC&)KRamFile1, //keep ram files at the top to make it easier to skip rom bitmaps
sl@0
   357
		(const TDesC&)KRamFile2,
sl@0
   358
		(const TDesC&)KRamFile3,
sl@0
   359
		(const TDesC&)KRomFile1,
sl@0
   360
		(const TDesC&)KRomFile2,
sl@0
   361
		(const TDesC&)KRomFile3
sl@0
   362
		};
sl@0
   363
	INFO_PRINTF1(_L("Loading bitmaps"));
sl@0
   364
	TInt i;
sl@0
   365
	TInt maxIndex = (iSkipRomBitmapTests ? KNumBitmap - 1 : 2 * KNumBitmap - 1);
sl@0
   366
	for (i=0; i <= maxIndex; ++i)
sl@0
   367
		{
sl@0
   368
		RFile f;
sl@0
   369
		TInt mode = EFileShareReadersOnly;
sl@0
   370
		TInt ret = f.Open(iFs,names[i],mode);
sl@0
   371
		TEST(ret==KErrNone);
sl@0
   372
		CFbsBitmap bmp;
sl@0
   373
		TEST(bmp.Load(f)==KErrNone);
sl@0
   374
		f.Close();
sl@0
   375
		
sl@0
   376
		CFbsBitmap* orig = iSource[i%KNumBitmap];
sl@0
   377
		TSize size = orig->SizeInPixels();
sl@0
   378
		TInt bytes = orig->ScanLineLength(size.iWidth,KDisplayMode)*size.iHeight;
sl@0
   379
		orig->LockHeap();
sl@0
   380
		bmp.LockHeap();
sl@0
   381
		TEST(Mem::Compare((TUint8*)orig->DataAddress(),bytes,(TUint8*)bmp.DataAddress(),bytes)==0);
sl@0
   382
		orig->UnlockHeap();
sl@0
   383
		bmp.UnlockHeap();
sl@0
   384
		}
sl@0
   385
		
sl@0
   386
	// Load multi bitmap file
sl@0
   387
	const TBufC<32> mbm[] =
sl@0
   388
		{
sl@0
   389
		(const TDesC&)KRamFile4, //keep ram files at the top to make it easier to skip rom bitmaps
sl@0
   390
		(const TDesC&)KRomFile4
sl@0
   391
		};
sl@0
   392
	maxIndex = (iSkipRomBitmapTests ? 0 : 1);
sl@0
   393
	for (i=0; i <= maxIndex; ++i)
sl@0
   394
		{
sl@0
   395
		RFile f;
sl@0
   396
		TInt mode = EFileShareReadersOnly;
sl@0
   397
		TInt ret = f.Open(iFs,mbm[i],mode);
sl@0
   398
		TEST(ret==KErrNone);
sl@0
   399
		TInt id;
sl@0
   400
		for (id=0; id<KNumBitmap; ++id)
sl@0
   401
			{
sl@0
   402
			CFbsBitmap bmp;
sl@0
   403
			TEST(bmp.Load(f,id)==KErrNone);
sl@0
   404
			
sl@0
   405
			CFbsBitmap* orig = iSource[id];
sl@0
   406
			TSize size = orig->SizeInPixels();
sl@0
   407
			TInt bytes = orig->ScanLineLength(size.iWidth,KDisplayMode)*size.iHeight;
sl@0
   408
			orig->LockHeap();
sl@0
   409
			bmp.LockHeap();
sl@0
   410
			TEST(Mem::Compare((TUint8*)orig->DataAddress(),bytes,(TUint8*)bmp.DataAddress(),bytes)==0);
sl@0
   411
			orig->UnlockHeap();
sl@0
   412
			bmp.UnlockHeap();
sl@0
   413
			}
sl@0
   414
		f.Close();
sl@0
   415
		}
sl@0
   416
	}
sl@0
   417
sl@0
   418
/**
sl@0
   419
	@SYMTestCaseID
sl@0
   420
	GRAPHICS-FBSERV-0592
sl@0
   421
sl@0
   422
	@SYMTestCaseDesc
sl@0
   423
	Load and compress bitmap from file using an opened file handle.
sl@0
   424
	
sl@0
   425
	@SYMTestActions
sl@0
   426
	Compress original bitmap.
sl@0
   427
	Load and compress bitmap using file handle.
sl@0
   428
	Blit loaded+compressed bitmaps and compressed original to screen.
sl@0
   429
	Compare screen area.
sl@0
   430
	
sl@0
   431
	@SYMTestExpectedResults
sl@0
   432
	LoadAndCompress ROM file return KErrAccessDenied.
sl@0
   433
	Drawn bitmap on screen match.
sl@0
   434
*/
sl@0
   435
void CTFile::LoadAndCompressL()
sl@0
   436
	{
sl@0
   437
	INFO_PRINTF1(_L("Loading and compressing bitmaps"));
sl@0
   438
sl@0
   439
	RFile f;
sl@0
   440
	TInt ret = KErrNone;
sl@0
   441
	if(!iSkipRomBitmapTests)
sl@0
   442
		{
sl@0
   443
		// load and compress ROM file
sl@0
   444
		ret = f.Open(iFs,KRomFile1,EFileShareReadersOnly);
sl@0
   445
		TEST(ret==KErrNone);
sl@0
   446
		CFbsBitmap bmp;
sl@0
   447
		TEST(bmp.LoadAndCompress(f)==KErrAccessDenied);
sl@0
   448
		f.Close();
sl@0
   449
		}
sl@0
   450
sl@0
   451
	// load single bitmap file
sl@0
   452
	const TBufC<32> names[KNumBitmap] =
sl@0
   453
		{
sl@0
   454
		(const TDesC&)KRamFile1,
sl@0
   455
		(const TDesC&)KRamFile2,
sl@0
   456
		(const TDesC&)KRamFile3
sl@0
   457
		};
sl@0
   458
	TInt i;
sl@0
   459
	for (i=0; i<KNumBitmap; ++i)
sl@0
   460
		{
sl@0
   461
		ret = f.Open(iFs,names[i],EFileShareReadersOnly);
sl@0
   462
		TEST(ret==KErrNone);
sl@0
   463
		CFbsBitmap bmp;
sl@0
   464
		TEST(bmp.LoadAndCompress(f)==KErrNone);
sl@0
   465
		f.Close();
sl@0
   466
		TEST(bmp.IsCompressedInRAM());
sl@0
   467
		
sl@0
   468
		CFbsBitmap* orig = iSource[i];
sl@0
   469
		TEST(orig->Compress()==KErrNone);
sl@0
   470
		TEST(orig->IsCompressedInRAM());
sl@0
   471
sl@0
   472
		TRAP(ret,BlitAndCompareL(orig,&bmp,orig->SizeInPixels()));
sl@0
   473
		TEST(ret==KErrNone);
sl@0
   474
		}
sl@0
   475
	// Load multi bitmap KRamFile4
sl@0
   476
	ret = f.Open(iFs,KRamFile4,EFileShareReadersOnly);
sl@0
   477
	TEST(ret==KErrNone);
sl@0
   478
	TInt id;
sl@0
   479
	for (id=0; id<KNumBitmap; ++id)
sl@0
   480
		{
sl@0
   481
		CFbsBitmap bmp;
sl@0
   482
		TEST(bmp.LoadAndCompress(f,id)==KErrNone);
sl@0
   483
		TEST(bmp.IsCompressedInRAM());
sl@0
   484
		
sl@0
   485
		CFbsBitmap* orig = iSource[id];
sl@0
   486
		TEST(orig->Compress()==KErrNone);
sl@0
   487
		TEST(orig->IsCompressedInRAM());
sl@0
   488
sl@0
   489
		TRAP(ret,BlitAndCompareL(orig,&bmp,orig->SizeInPixels()));
sl@0
   490
		TEST(ret==KErrNone);
sl@0
   491
		}
sl@0
   492
	f.Close();
sl@0
   493
	}
sl@0
   494
sl@0
   495
/**
sl@0
   496
	Blit two bitmap to screen device and compare if both match
sl@0
   497
*/
sl@0
   498
void CTFile::BlitAndCompareL(CFbsBitmap* aBmpOrig,CFbsBitmap* aBmpTest,const TSize& aBmpSize)
sl@0
   499
	{
sl@0
   500
	CFbsScreenDevice* scd=NULL;
sl@0
   501
	TRAPD(err,scd=CFbsScreenDevice::NewL(KDefaultScreenNo,KDisplayMode));
sl@0
   502
	if (err!=KErrNone)
sl@0
   503
		{
sl@0
   504
		_LIT(KLog,"Failed to create screen device for mode %S  err=%d");
sl@0
   505
		INFO_PRINTF3(KLog,&ColorModeName(KDisplayMode),err);
sl@0
   506
		}
sl@0
   507
	if (err==KErrNotSupported)
sl@0
   508
		{
sl@0
   509
		TRAPD(err,scd=CFbsScreenDevice::NewL(KDefaultScreenNo,EColor256));
sl@0
   510
		if (err!=KErrNone)
sl@0
   511
			{
sl@0
   512
			_LIT(KLog,"Failed to create Color256 screen device  err=%d");
sl@0
   513
			INFO_PRINTF2(KLog,err);
sl@0
   514
			}
sl@0
   515
		}
sl@0
   516
	if (err==KErrNotSupported)
sl@0
   517
		{
sl@0
   518
		TRAPD(err,scd=CFbsScreenDevice::NewL(KDefaultScreenNo,EColor16MA));
sl@0
   519
		if (err!=KErrNone)
sl@0
   520
			{
sl@0
   521
			_LIT(KLog,"Failed to create Color16MA screen device  err=%d");
sl@0
   522
			INFO_PRINTF2(KLog,err);
sl@0
   523
			}
sl@0
   524
		}
sl@0
   525
	if (err==KErrNotSupported)
sl@0
   526
		{
sl@0
   527
		TRAPD(err,scd=CFbsScreenDevice::NewL(KDefaultScreenNo,EColor16MAP));
sl@0
   528
		if (err!=KErrNone)
sl@0
   529
			{
sl@0
   530
			_LIT(KLog,"Failed to create Color16MA screen device  err=%d");
sl@0
   531
			INFO_PRINTF2(KLog,err);
sl@0
   532
			}
sl@0
   533
		}
sl@0
   534
	_LIT(KLog,"Create screen device with mode %S");
sl@0
   535
	INFO_PRINTF2(KLog,&ColorModeName(scd->DisplayMode()));
sl@0
   536
	CleanupStack::PushL(scd);
sl@0
   537
	scd->ChangeScreenDevice(NULL);
sl@0
   538
	CFbsBitGc* sgc;
sl@0
   539
	User::LeaveIfError(scd->CreateContext((CGraphicsContext*&)sgc)); 
sl@0
   540
	CleanupStack::PushL(sgc);
sl@0
   541
sl@0
   542
	TSize scrSize = scd->SizeInPixels();
sl@0
   543
	TPoint left(0,0);
sl@0
   544
	TPoint right(scrSize.iWidth/2,0);
sl@0
   545
	TRect bmpRect(TPoint(0,0),aBmpSize);
sl@0
   546
sl@0
   547
	// if bitmap width is greater than half screen width,
sl@0
   548
	// try positioning right bitmap below original.
sl@0
   549
	if (scrSize.iWidth < aBmpSize.iWidth*2)
sl@0
   550
		{
sl@0
   551
		if (scrSize.iHeight < aBmpSize.iHeight/2)
sl@0
   552
			{
sl@0
   553
			//That still doesn't work out, so restrict size of rect
sl@0
   554
			// being blitted to half screen size.
sl@0
   555
			INFO_PRINTF1(_L("Warning: the whole of the test images may not be compared"));
sl@0
   556
			bmpRect = TRect(TPoint(0,0),TSize(scrSize.iWidth/2,aBmpSize.iHeight));
sl@0
   557
			}
sl@0
   558
		else
sl@0
   559
			{
sl@0
   560
			right = TPoint(0, scrSize.iHeight/2);
sl@0
   561
			}
sl@0
   562
		}
sl@0
   563
	
sl@0
   564
	sgc->BitBlt(left, aBmpOrig, bmpRect);
sl@0
   565
	sgc->BitBlt(right, aBmpTest, bmpRect);
sl@0
   566
	scd->Update();
sl@0
   567
	
sl@0
   568
#ifdef FBSTEST_SCREENSHOT
sl@0
   569
	SaveScreenShotL(scd);
sl@0
   570
#endif //FBSTEST_SCREENSHOT
sl@0
   571
	
sl@0
   572
	TBool match=scd->RectCompare(TRect(left,bmpRect.Size()),*scd,TRect(right,bmpRect.Size()));
sl@0
   573
	if (!match)
sl@0
   574
		{
sl@0
   575
		_LIT(KLog,"Two areas of the screen don't match");
sl@0
   576
		INFO_PRINTF1(KLog);
sl@0
   577
		}
sl@0
   578
	TEST(match);
sl@0
   579
sl@0
   580
	CleanupStack::PopAndDestroy(2,scd);
sl@0
   581
	}
sl@0
   582
sl@0
   583
//--------------
sl@0
   584
__CONSTRUCT_STEP__(File)