os/graphics/fbs/fontandbitmapserver/tfbs/trfile.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/fbs/fontandbitmapserver/tfbs/trfile.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,584 @@
     1.4 +// Copyright (c) 2005-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 "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 +//
    1.18 +
    1.19 +#include <f32file.h>
    1.20 +#include <fbs.h>
    1.21 +#include <bitdev.h>
    1.22 +#include <bitstd.h>
    1.23 +#include <graphics/gdi/gdiconsts.h>
    1.24 +#include "../sfbs/UTILS.H"
    1.25 +#include "trfile.h"
    1.26 +#include "fbsmessage.h"
    1.27 +#include "fbsdefs.h"
    1.28 +
    1.29 +// Define FBSTEST_SCREENSHOT to save the screen to a .mbm file
    1.30 +//#define FBSTEST_SCREENSHOT
    1.31 +
    1.32 +const TInt KNumBitmap = 3;
    1.33 +const TDisplayMode KDisplayMode = EColor64K;
    1.34 +const TSize KLargeSize(128,128);
    1.35 +const TSize KMidSize(64,64);
    1.36 +const TSize KSmallSize(32,32);
    1.37 +
    1.38 +
    1.39 +_LIT(KRamFile1,"c:\\rf1.mbm");
    1.40 +_LIT(KRamFile2,"c:\\rf2.mbm");
    1.41 +_LIT(KRamFile3,"c:\\rf3.mbm");
    1.42 +_LIT(KRamFile4,"c:\\rf123.mbm");
    1.43 +_LIT(KRomFile1,"z:\\system\\data\\rf1.mbm");
    1.44 +_LIT(KRomFile2,"z:\\system\\data\\rf2.mbm");
    1.45 +_LIT(KRomFile3,"z:\\system\\data\\rf3.mbm");
    1.46 +_LIT(KRomFile4,"z:\\system\\data\\rf123.mbm");
    1.47 +
    1.48 +
    1.49 +CTFile::CTFile(CTestStep* aStep):
    1.50 +	CTGraphicsBase(aStep),
    1.51 +	iFbs(NULL),
    1.52 +	iSource(KNumBitmap)
    1.53 +	{
    1.54 +	}
    1.55 +
    1.56 +CTFile::~CTFile()
    1.57 +	{
    1.58 +	CleanUp();
    1.59 +	if (iShutdownFbs)
    1.60 +		iFbs->SendCommand(EFbsMessShutdown);
    1.61 +	iFbs->Disconnect();
    1.62 +	}
    1.63 +	
    1.64 +
    1.65 +void CTFile::ConstructL()
    1.66 +	{
    1.67 +	if(RFbsSession::Connect()==KErrNone)
    1.68 +		{
    1.69 +		RFbsSession::Disconnect();
    1.70 +		iShutdownFbs = EFalse;
    1.71 +		}
    1.72 +	else
    1.73 +		{
    1.74 +		FbsStartup();
    1.75 +		iShutdownFbs = ETrue;
    1.76 +		}
    1.77 +
    1.78 +	TInt ret = RFbsSession::Connect();
    1.79 +	TEST(ret==KErrNone);
    1.80 +	iFbs = RFbsSession::GetSession();
    1.81 +	TEST(iFbs != NULL);
    1.82 +
    1.83 +	ret = iFs.Connect();
    1.84 +	TEST(ret==KErrNone);
    1.85 +	// required to allow file handle to be adopted by another process
    1.86 +	iFs.ShareProtected();
    1.87 +	
    1.88 +	TUint32* romAddress = NULL;
    1.89 +	if(!CFbsBitmap::IsFileInRom(KRomFile1, romAddress)) //any ROM bitmap
    1.90 +		{
    1.91 +		INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."),
    1.92 +				&KRomFile1);
    1.93 +		INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported."));
    1.94 +		iSkipRomBitmapTests = ETrue;
    1.95 +		}
    1.96 +	}
    1.97 +
    1.98 +void CTFile::CleanUp()
    1.99 +	{
   1.100 +	const TBufC<32> names[KNumBitmap] =
   1.101 +		{
   1.102 +		(const TDesC&)KRamFile1,
   1.103 +		(const TDesC&)KRamFile2,
   1.104 +		(const TDesC&)KRamFile3
   1.105 +		};
   1.106 +	TInt i;
   1.107 +	for (i=0; i<KNumBitmap; ++i)
   1.108 +		{
   1.109 +		delete iSource[i];
   1.110 +		iFs.Delete(names[i]);
   1.111 +		}
   1.112 +	iSource.Close();
   1.113 +	iFs.Delete(KRamFile4);
   1.114 +	iFs.Close();	
   1.115 +	}
   1.116 +	
   1.117 +void CTFile::RunTestCaseL(TInt aCurTestCase)
   1.118 +	{
   1.119 +	((CTFileStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   1.120 +	switch(aCurTestCase)
   1.121 +		{
   1.122 +	case 1:
   1.123 +		((CTFileStep*)iStep)->SetTestStepID(_L("	GRAPHICS-FBSERV-0588"));
   1.124 +		CreateL();
   1.125 +		break;
   1.126 +	case 2:
   1.127 +		((CTFileStep*)iStep)->SetTestStepID(_L("	GRAPHICS-FBSERV-0589"));
   1.128 +		SaveL();
   1.129 +		break;
   1.130 +	case 3:
   1.131 +		((CTFileStep*)iStep)->SetTestStepID(_L("	GRAPHICS-FBSERV-0590"));
   1.132 +		StoreL();
   1.133 +		break;
   1.134 +	case 4:
   1.135 +		((CTFileStep*)iStep)->SetTestStepID(_L("	GRAPHICS-FBSERV-0591"));
   1.136 +		LoadL();
   1.137 +		break;
   1.138 +	case 5:
   1.139 +		((CTFileStep*)iStep)->SetTestStepID(_L("	GRAPHICS-FBSERV-0592"));
   1.140 +		LoadAndCompressL();
   1.141 +		break;
   1.142 +	case 6:
   1.143 +		((CTFileStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   1.144 +		((CTFileStep*)iStep)->CloseTMSGraphicsStep();
   1.145 +		TestComplete();
   1.146 +		break;
   1.147 +		}
   1.148 +	((CTFileStep*)iStep)->RecordTestResultL();
   1.149 +	}
   1.150 +
   1.151 +
   1.152 +/**
   1.153 +	Draw union jack
   1.154 +*/
   1.155 +void CTFile::Draw(CFbsBitGc* aGc, const TSize& aSize)
   1.156 +	{
   1.157 +	const TSize thick(aSize.iWidth/4,aSize.iWidth/4);
   1.158 +	const TSize thin(thick.iWidth/2,thick.iWidth/2);
   1.159 +	
   1.160 +	// background
   1.161 +	aGc->SetBrushColor(KRgbBlue);
   1.162 +	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.163 +	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
   1.164 +	aGc->DrawRect(aSize);
   1.165 +
   1.166 +	// corner to corner section
   1.167 +	aGc->SetPenColor(KRgbWhite);
   1.168 +	aGc->SetPenSize(thick);
   1.169 +	aGc->DrawLine(TPoint(0,0),TPoint(aSize.iWidth,aSize.iHeight));
   1.170 +	aGc->DrawLine(TPoint(aSize.iWidth,0),TPoint(0,aSize.iHeight));	
   1.171 +	aGc->SetPenColor(KRgbRed);
   1.172 +	aGc->SetPenSize(thin);
   1.173 +	aGc->DrawLine(TPoint(0,0),TPoint(aSize.iWidth,aSize.iHeight));
   1.174 +	aGc->DrawLine(TPoint(aSize.iWidth,0),TPoint(0,aSize.iHeight));	
   1.175 +	
   1.176 +	// cross section
   1.177 +	aGc->SetPenColor(KRgbWhite);
   1.178 +	aGc->SetPenSize(thick);
   1.179 +	aGc->DrawLine(TPoint(aSize.iWidth/2,0),TPoint(aSize.iWidth/2,aSize.iHeight));	
   1.180 +	aGc->DrawLine(TPoint(0,aSize.iHeight/2),TPoint(aSize.iWidth,aSize.iHeight/2));	
   1.181 +	aGc->SetPenColor(KRgbRed);
   1.182 +	aGc->SetPenSize(thin);
   1.183 +	aGc->DrawLine(TPoint(aSize.iWidth/2,0),TPoint(aSize.iWidth/2,aSize.iHeight));	
   1.184 +	aGc->DrawLine(TPoint(0,aSize.iHeight/2),TPoint(aSize.iWidth,aSize.iHeight/2));	
   1.185 +	}
   1.186 +
   1.187 +/**
   1.188 +
   1.189 +*/	
   1.190 +/**
   1.191 +	@SYMTestCaseID
   1.192 +	GRAPHICS-FBSERV-0588
   1.193 +
   1.194 +	@SYMTestCaseDesc
   1.195 +	Create various size bitmap for testing (original bitmaps) 
   1.196 +	ie small (<4KB), mid (=4KB) and large (>4KB).
   1.197 +	
   1.198 +	@SYMTestActions	
   1.199 +	
   1.200 +	@SYMTestExpectedResults
   1.201 +	Test should pass
   1.202 +*/
   1.203 +void CTFile::CreateL()
   1.204 +	{
   1.205 +	const TSize sizes[KNumBitmap] = 
   1.206 +		{
   1.207 +		KSmallSize,
   1.208 +		KMidSize,
   1.209 +		KLargeSize
   1.210 +		};
   1.211 +	TInt i;
   1.212 +	for (i=0; i<KNumBitmap; ++i)
   1.213 +		{
   1.214 +		CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
   1.215 +		CleanupStack::PushL(bmp);
   1.216 +		User::LeaveIfError(bmp->Create(sizes[i],KDisplayMode));
   1.217 +		
   1.218 +		CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(bmp);
   1.219 +		CleanupStack::PushL(dev);
   1.220 +		
   1.221 +		CFbsBitGc* gc;
   1.222 +		User::LeaveIfError(dev->CreateContext(gc));
   1.223 +		
   1.224 +		Draw(gc,sizes[i]);
   1.225 +		
   1.226 +		delete gc;
   1.227 +		CleanupStack::PopAndDestroy(dev);
   1.228 +		
   1.229 +		iSource.AppendL(bmp);
   1.230 +		
   1.231 +		CleanupStack::Pop(bmp);
   1.232 +		}
   1.233 +	}
   1.234 +
   1.235 +/**
   1.236 +	@SYMTestCaseID
   1.237 +	GRAPHICS-FBSERV-0589
   1.238 +
   1.239 +	@SYMTestCaseDesc
   1.240 +	Save single bitmap to file using an opened file handle
   1.241 +	
   1.242 +	@SYMTestActions
   1.243 +	Save original bitmap to file using file handle (saved bitmap)
   1.244 +	Load saved bitmap using file name and compare against original
   1.245 +	Leave saved bitmap files for next test (Load,LoadAndCompress)
   1.246 +	
   1.247 +	@SYMTestExpectedResults
   1.248 +	Saved bitmap match original bitmap
   1.249 +*/
   1.250 +void CTFile::SaveL()
   1.251 +	{
   1.252 +	const TBufC<32> names[KNumBitmap] =
   1.253 +		{
   1.254 +		(const TDesC&)KRamFile1,
   1.255 +		(const TDesC&)KRamFile2,
   1.256 +		(const TDesC&)KRamFile3
   1.257 +		};
   1.258 +		
   1.259 +	INFO_PRINTF1(_L("Saving bitmap"));		
   1.260 +	TInt i;
   1.261 +	for (i=0; i<KNumBitmap; ++i)
   1.262 +		{
   1.263 +		RFile f;
   1.264 +		TInt mode = EFileWrite;
   1.265 +		TInt ret = f.Open(iFs,names[i],mode);
   1.266 +		if (ret==KErrNotFound)
   1.267 +			ret = f.Create(iFs,names[i],mode);
   1.268 +		TEST(ret==KErrNone);
   1.269 +		
   1.270 +		TEST(iSource[i]->Save(f)==KErrNone);
   1.271 +		f.Close();
   1.272 +		
   1.273 +		CFbsBitmap bmp;
   1.274 +		TEST(bmp.Load(names[i])==KErrNone);
   1.275 +		
   1.276 +		CFbsBitmap* orig = iSource[i];
   1.277 +		TSize size = orig->SizeInPixels();
   1.278 +		TInt bytes = orig->ScanLineLength(size.iWidth,KDisplayMode)*size.iHeight;
   1.279 +		orig->LockHeap();
   1.280 +		bmp.LockHeap();
   1.281 +		TEST(Mem::Compare((TUint8*)orig->DataAddress(),bytes,(TUint8*)bmp.DataAddress(),bytes)==0);
   1.282 +		orig->UnlockHeap();
   1.283 +		bmp.UnlockHeap();
   1.284 +		}
   1.285 +	}
   1.286 +
   1.287 +/**
   1.288 +	@SYMTestCaseID
   1.289 +	GRAPHICS-FBSERV-0590
   1.290 +
   1.291 +	@SYMTestCaseDesc
   1.292 +	Save multi bitmaps to file using an opened file handle.
   1.293 +	
   1.294 +	@SYMTestActions
   1.295 +	Save original bitmaps to file (saved bitmaps).
   1.296 +	Load saved bitmaps and compare it against originals.
   1.297 +	
   1.298 +	@SYMTestExpectedResults
   1.299 +	Saved bitmaps match original bitmaps
   1.300 +*/
   1.301 +void CTFile::StoreL()
   1.302 +	{
   1.303 +	const TBufC<32> names[KNumBitmap] =
   1.304 +		{
   1.305 +		(const TDesC&)KRamFile1,
   1.306 +		(const TDesC&)KRamFile2,
   1.307 +		(const TDesC&)KRamFile3
   1.308 +		};
   1.309 +	INFO_PRINTF1(_L("Storing bitmaps"));
   1.310 +	RFile f;
   1.311 +	TInt mode = EFileWrite;
   1.312 +	TInt ret = f.Open(iFs,KRamFile4,mode);
   1.313 +	if (ret==KErrNotFound)
   1.314 +		ret = f.Create(iFs,KRamFile4,mode);
   1.315 +	TEST(ret==KErrNone);
   1.316 +	
   1.317 +	const TDesC* bmps[] = {&names[0],&names[1],&names[2]};
   1.318 +	TInt32 ids[] = {0,0,0};
   1.319 +	TRAP(ret,CFbsBitmap::StoreL(f,KNumBitmap,bmps,ids));
   1.320 +	TEST(ret==KErrNone);
   1.321 +	f.Close();
   1.322 +	
   1.323 +	TInt id;
   1.324 +	for (id=0; id<KNumBitmap; ++id)
   1.325 +		{
   1.326 +		CFbsBitmap bmp;
   1.327 +		TEST(bmp.Load(KRamFile4,id)==KErrNone);
   1.328 +		
   1.329 +		CFbsBitmap* orig = iSource[id];
   1.330 +		TSize size = orig->SizeInPixels();
   1.331 +		TInt bytes = orig->ScanLineLength(size.iWidth,KDisplayMode)*size.iHeight;
   1.332 +		orig->LockHeap();
   1.333 +		bmp.LockHeap();
   1.334 +		TEST(Mem::Compare((TUint8*)orig->DataAddress(),bytes,(TUint8*)bmp.DataAddress(),bytes)==0);
   1.335 +		orig->UnlockHeap();
   1.336 +		bmp.UnlockHeap();
   1.337 +		}
   1.338 +	}
   1.339 +
   1.340 +/**
   1.341 +	@SYMTestCaseID
   1.342 +	GRAPHICS-FBSERV-0591
   1.343 +
   1.344 +	@SYMTestCaseDesc
   1.345 +	Load bitmap from file using an opened file handle.
   1.346 +	
   1.347 +	@SYMTestActions
   1.348 +	Load bitmap using file handle.
   1.349 +	Compare loaded bitmaps against original.
   1.350 +	
   1.351 +	@SYMTestExpectedResults
   1.352 +	Loaded bitmap match original
   1.353 +*/
   1.354 +void CTFile::LoadL()
   1.355 +	{
   1.356 +	// Load single bitmap file
   1.357 +	const TBufC<32> names[2*KNumBitmap] =
   1.358 +		{
   1.359 +		(const TDesC&)KRamFile1, //keep ram files at the top to make it easier to skip rom bitmaps
   1.360 +		(const TDesC&)KRamFile2,
   1.361 +		(const TDesC&)KRamFile3,
   1.362 +		(const TDesC&)KRomFile1,
   1.363 +		(const TDesC&)KRomFile2,
   1.364 +		(const TDesC&)KRomFile3
   1.365 +		};
   1.366 +	INFO_PRINTF1(_L("Loading bitmaps"));
   1.367 +	TInt i;
   1.368 +	TInt maxIndex = (iSkipRomBitmapTests ? KNumBitmap - 1 : 2 * KNumBitmap - 1);
   1.369 +	for (i=0; i <= maxIndex; ++i)
   1.370 +		{
   1.371 +		RFile f;
   1.372 +		TInt mode = EFileShareReadersOnly;
   1.373 +		TInt ret = f.Open(iFs,names[i],mode);
   1.374 +		TEST(ret==KErrNone);
   1.375 +		CFbsBitmap bmp;
   1.376 +		TEST(bmp.Load(f)==KErrNone);
   1.377 +		f.Close();
   1.378 +		
   1.379 +		CFbsBitmap* orig = iSource[i%KNumBitmap];
   1.380 +		TSize size = orig->SizeInPixels();
   1.381 +		TInt bytes = orig->ScanLineLength(size.iWidth,KDisplayMode)*size.iHeight;
   1.382 +		orig->LockHeap();
   1.383 +		bmp.LockHeap();
   1.384 +		TEST(Mem::Compare((TUint8*)orig->DataAddress(),bytes,(TUint8*)bmp.DataAddress(),bytes)==0);
   1.385 +		orig->UnlockHeap();
   1.386 +		bmp.UnlockHeap();
   1.387 +		}
   1.388 +		
   1.389 +	// Load multi bitmap file
   1.390 +	const TBufC<32> mbm[] =
   1.391 +		{
   1.392 +		(const TDesC&)KRamFile4, //keep ram files at the top to make it easier to skip rom bitmaps
   1.393 +		(const TDesC&)KRomFile4
   1.394 +		};
   1.395 +	maxIndex = (iSkipRomBitmapTests ? 0 : 1);
   1.396 +	for (i=0; i <= maxIndex; ++i)
   1.397 +		{
   1.398 +		RFile f;
   1.399 +		TInt mode = EFileShareReadersOnly;
   1.400 +		TInt ret = f.Open(iFs,mbm[i],mode);
   1.401 +		TEST(ret==KErrNone);
   1.402 +		TInt id;
   1.403 +		for (id=0; id<KNumBitmap; ++id)
   1.404 +			{
   1.405 +			CFbsBitmap bmp;
   1.406 +			TEST(bmp.Load(f,id)==KErrNone);
   1.407 +			
   1.408 +			CFbsBitmap* orig = iSource[id];
   1.409 +			TSize size = orig->SizeInPixels();
   1.410 +			TInt bytes = orig->ScanLineLength(size.iWidth,KDisplayMode)*size.iHeight;
   1.411 +			orig->LockHeap();
   1.412 +			bmp.LockHeap();
   1.413 +			TEST(Mem::Compare((TUint8*)orig->DataAddress(),bytes,(TUint8*)bmp.DataAddress(),bytes)==0);
   1.414 +			orig->UnlockHeap();
   1.415 +			bmp.UnlockHeap();
   1.416 +			}
   1.417 +		f.Close();
   1.418 +		}
   1.419 +	}
   1.420 +
   1.421 +/**
   1.422 +	@SYMTestCaseID
   1.423 +	GRAPHICS-FBSERV-0592
   1.424 +
   1.425 +	@SYMTestCaseDesc
   1.426 +	Load and compress bitmap from file using an opened file handle.
   1.427 +	
   1.428 +	@SYMTestActions
   1.429 +	Compress original bitmap.
   1.430 +	Load and compress bitmap using file handle.
   1.431 +	Blit loaded+compressed bitmaps and compressed original to screen.
   1.432 +	Compare screen area.
   1.433 +	
   1.434 +	@SYMTestExpectedResults
   1.435 +	LoadAndCompress ROM file return KErrAccessDenied.
   1.436 +	Drawn bitmap on screen match.
   1.437 +*/
   1.438 +void CTFile::LoadAndCompressL()
   1.439 +	{
   1.440 +	INFO_PRINTF1(_L("Loading and compressing bitmaps"));
   1.441 +
   1.442 +	RFile f;
   1.443 +	TInt ret = KErrNone;
   1.444 +	if(!iSkipRomBitmapTests)
   1.445 +		{
   1.446 +		// load and compress ROM file
   1.447 +		ret = f.Open(iFs,KRomFile1,EFileShareReadersOnly);
   1.448 +		TEST(ret==KErrNone);
   1.449 +		CFbsBitmap bmp;
   1.450 +		TEST(bmp.LoadAndCompress(f)==KErrAccessDenied);
   1.451 +		f.Close();
   1.452 +		}
   1.453 +
   1.454 +	// load single bitmap file
   1.455 +	const TBufC<32> names[KNumBitmap] =
   1.456 +		{
   1.457 +		(const TDesC&)KRamFile1,
   1.458 +		(const TDesC&)KRamFile2,
   1.459 +		(const TDesC&)KRamFile3
   1.460 +		};
   1.461 +	TInt i;
   1.462 +	for (i=0; i<KNumBitmap; ++i)
   1.463 +		{
   1.464 +		ret = f.Open(iFs,names[i],EFileShareReadersOnly);
   1.465 +		TEST(ret==KErrNone);
   1.466 +		CFbsBitmap bmp;
   1.467 +		TEST(bmp.LoadAndCompress(f)==KErrNone);
   1.468 +		f.Close();
   1.469 +		TEST(bmp.IsCompressedInRAM());
   1.470 +		
   1.471 +		CFbsBitmap* orig = iSource[i];
   1.472 +		TEST(orig->Compress()==KErrNone);
   1.473 +		TEST(orig->IsCompressedInRAM());
   1.474 +
   1.475 +		TRAP(ret,BlitAndCompareL(orig,&bmp,orig->SizeInPixels()));
   1.476 +		TEST(ret==KErrNone);
   1.477 +		}
   1.478 +	// Load multi bitmap KRamFile4
   1.479 +	ret = f.Open(iFs,KRamFile4,EFileShareReadersOnly);
   1.480 +	TEST(ret==KErrNone);
   1.481 +	TInt id;
   1.482 +	for (id=0; id<KNumBitmap; ++id)
   1.483 +		{
   1.484 +		CFbsBitmap bmp;
   1.485 +		TEST(bmp.LoadAndCompress(f,id)==KErrNone);
   1.486 +		TEST(bmp.IsCompressedInRAM());
   1.487 +		
   1.488 +		CFbsBitmap* orig = iSource[id];
   1.489 +		TEST(orig->Compress()==KErrNone);
   1.490 +		TEST(orig->IsCompressedInRAM());
   1.491 +
   1.492 +		TRAP(ret,BlitAndCompareL(orig,&bmp,orig->SizeInPixels()));
   1.493 +		TEST(ret==KErrNone);
   1.494 +		}
   1.495 +	f.Close();
   1.496 +	}
   1.497 +
   1.498 +/**
   1.499 +	Blit two bitmap to screen device and compare if both match
   1.500 +*/
   1.501 +void CTFile::BlitAndCompareL(CFbsBitmap* aBmpOrig,CFbsBitmap* aBmpTest,const TSize& aBmpSize)
   1.502 +	{
   1.503 +	CFbsScreenDevice* scd=NULL;
   1.504 +	TRAPD(err,scd=CFbsScreenDevice::NewL(KDefaultScreenNo,KDisplayMode));
   1.505 +	if (err!=KErrNone)
   1.506 +		{
   1.507 +		_LIT(KLog,"Failed to create screen device for mode %S  err=%d");
   1.508 +		INFO_PRINTF3(KLog,&ColorModeName(KDisplayMode),err);
   1.509 +		}
   1.510 +	if (err==KErrNotSupported)
   1.511 +		{
   1.512 +		TRAPD(err,scd=CFbsScreenDevice::NewL(KDefaultScreenNo,EColor256));
   1.513 +		if (err!=KErrNone)
   1.514 +			{
   1.515 +			_LIT(KLog,"Failed to create Color256 screen device  err=%d");
   1.516 +			INFO_PRINTF2(KLog,err);
   1.517 +			}
   1.518 +		}
   1.519 +	if (err==KErrNotSupported)
   1.520 +		{
   1.521 +		TRAPD(err,scd=CFbsScreenDevice::NewL(KDefaultScreenNo,EColor16MA));
   1.522 +		if (err!=KErrNone)
   1.523 +			{
   1.524 +			_LIT(KLog,"Failed to create Color16MA screen device  err=%d");
   1.525 +			INFO_PRINTF2(KLog,err);
   1.526 +			}
   1.527 +		}
   1.528 +	if (err==KErrNotSupported)
   1.529 +		{
   1.530 +		TRAPD(err,scd=CFbsScreenDevice::NewL(KDefaultScreenNo,EColor16MAP));
   1.531 +		if (err!=KErrNone)
   1.532 +			{
   1.533 +			_LIT(KLog,"Failed to create Color16MA screen device  err=%d");
   1.534 +			INFO_PRINTF2(KLog,err);
   1.535 +			}
   1.536 +		}
   1.537 +	_LIT(KLog,"Create screen device with mode %S");
   1.538 +	INFO_PRINTF2(KLog,&ColorModeName(scd->DisplayMode()));
   1.539 +	CleanupStack::PushL(scd);
   1.540 +	scd->ChangeScreenDevice(NULL);
   1.541 +	CFbsBitGc* sgc;
   1.542 +	User::LeaveIfError(scd->CreateContext((CGraphicsContext*&)sgc)); 
   1.543 +	CleanupStack::PushL(sgc);
   1.544 +
   1.545 +	TSize scrSize = scd->SizeInPixels();
   1.546 +	TPoint left(0,0);
   1.547 +	TPoint right(scrSize.iWidth/2,0);
   1.548 +	TRect bmpRect(TPoint(0,0),aBmpSize);
   1.549 +
   1.550 +	// if bitmap width is greater than half screen width,
   1.551 +	// try positioning right bitmap below original.
   1.552 +	if (scrSize.iWidth < aBmpSize.iWidth*2)
   1.553 +		{
   1.554 +		if (scrSize.iHeight < aBmpSize.iHeight/2)
   1.555 +			{
   1.556 +			//That still doesn't work out, so restrict size of rect
   1.557 +			// being blitted to half screen size.
   1.558 +			INFO_PRINTF1(_L("Warning: the whole of the test images may not be compared"));
   1.559 +			bmpRect = TRect(TPoint(0,0),TSize(scrSize.iWidth/2,aBmpSize.iHeight));
   1.560 +			}
   1.561 +		else
   1.562 +			{
   1.563 +			right = TPoint(0, scrSize.iHeight/2);
   1.564 +			}
   1.565 +		}
   1.566 +	
   1.567 +	sgc->BitBlt(left, aBmpOrig, bmpRect);
   1.568 +	sgc->BitBlt(right, aBmpTest, bmpRect);
   1.569 +	scd->Update();
   1.570 +	
   1.571 +#ifdef FBSTEST_SCREENSHOT
   1.572 +	SaveScreenShotL(scd);
   1.573 +#endif //FBSTEST_SCREENSHOT
   1.574 +	
   1.575 +	TBool match=scd->RectCompare(TRect(left,bmpRect.Size()),*scd,TRect(right,bmpRect.Size()));
   1.576 +	if (!match)
   1.577 +		{
   1.578 +		_LIT(KLog,"Two areas of the screen don't match");
   1.579 +		INFO_PRINTF1(KLog);
   1.580 +		}
   1.581 +	TEST(match);
   1.582 +
   1.583 +	CleanupStack::PopAndDestroy(2,scd);
   1.584 +	}
   1.585 +
   1.586 +//--------------
   1.587 +__CONSTRUCT_STEP__(File)