os/graphics/graphicsdeviceinterface/directgdi/test/tdirectgdi_test_step_base.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdi/test/tdirectgdi_test_step_base.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1276 @@
     1.4 +// Copyright (c) 2007-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 "tdirectgdi_test_step_base.h"
    1.20 +#include <graphics/directgdiextensioninterfaces.h>
    1.21 +
    1.22 +//These reference and test bitmaps are used for image comparison
    1.23 +//These are saved at
    1.24 +_LIT(KRefPath, "\\img\\ref\\%S.mbm");
    1.25 +_LIT(KTestPath, "\\img\\test\\%S.mbm");
    1.26 +
    1.27 +//The default image cache size to use for the tests.
    1.28 +const TInt KDriverImageCacheSizeTests = 0x400000;
    1.29 +
    1.30 +/**
    1.31 +Position iterator constructor.
    1.32 +@param aStartX Start x position.
    1.33 +@param aEndX End x position.
    1.34 +@param aStepX Step for x position.
    1.35 +@param aStartY Start y position.
    1.36 +@param aEndY End y position.
    1.37 +@param aStepY Step for y position.
    1.38 +*/
    1.39 +TPositionIterator::TPositionIterator(TInt aStartX, TInt aEndX, TInt aStepX,
    1.40 +	TInt aStartY, TInt aEndY, TInt aStepY) :
    1.41 +	iStartX(aStartX), iEndX(aEndX), iStepX(aStepX),
    1.42 +	iStartY(aStartY), iEndY(aEndY), iStepY(aStepY),
    1.43 +	iPosX(aStartX), iPosY(aStartY), iIndexX(0), iIndexY(0)
    1.44 +	{
    1.45 +	}
    1.46 +
    1.47 +/**
    1.48 +Begin iteration.
    1.49 +All needed variables are initialized to start iteration.
    1.50 +*/
    1.51 +void TPositionIterator::Begin()
    1.52 +	{
    1.53 +	iPosX = iStartX;
    1.54 +	iPosY = iStartY;
    1.55 +	iIndexX = 0;
    1.56 +	iIndexY = 0;
    1.57 +	}
    1.58 +
    1.59 +/**
    1.60 +Next iteration.
    1.61 +Generates next position and position indices.
    1.62 +@return EFalse is returned if end of iterations else ETrue.
    1.63 +*/
    1.64 +TBool TPositionIterator::Next()
    1.65 +	{
    1.66 +	if(iPosX < iEndX)
    1.67 +		{
    1.68 +		iPosX += iStepX;
    1.69 +		iIndexX++;
    1.70 +		return ETrue;
    1.71 +		}
    1.72 +	else
    1.73 +		{
    1.74 +		if(iPosY < iEndY)
    1.75 +			{
    1.76 +			iPosX = iStartX;
    1.77 +			iIndexX = 0;
    1.78 +			iPosY += iStepY;
    1.79 +			iIndexY++;
    1.80 +			return ETrue;
    1.81 +			}
    1.82 +		else
    1.83 +			{
    1.84 +			return EFalse;
    1.85 +			}
    1.86 +		}
    1.87 +	}
    1.88 +
    1.89 +CBitmapDevice* CTImageTarget::BitmapDevice() const
    1.90 +	{
    1.91 +	return iBitmapDevice;
    1.92 +	}
    1.93 +
    1.94 +/**
    1.95 +Create a new bitgdi target
    1.96 +@param aPixelFormat The pixel format for the target
    1.97 +@param aSize The size of the target to create
    1.98 +@return On return, contains a pointer to a bitgdi target object
    1.99 +*/
   1.100 +CTBitGdiTarget*  CTBitGdiTarget::NewL(TUidPixelFormat aPixelFormat, const TSize& aSize)
   1.101 +	{
   1.102 +	CTBitGdiTarget* self = new(ELeave) CTBitGdiTarget();
   1.103 +	CleanupStack::PushL(self);
   1.104 +	self->ConstructL(aPixelFormat, aSize);
   1.105 +	CleanupStack::Pop(); // self
   1.106 +	return self;
   1.107 +	}
   1.108 +
   1.109 +/**
   1.110 +Second phase constructor of CTBitGdiTarget. Creates a bitmap for use as a target.
   1.111 +@param aPixelFormat The pixel format for the target to be created
   1.112 +@param aSize The size of the target to be created
   1.113 +*/
   1.114 +void CTBitGdiTarget::ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize)
   1.115 +	{	
   1.116 +	// create a bitmap
   1.117 +	iBitmap = new(ELeave) CFbsBitmap;
   1.118 +	iBitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat));
   1.119 +	// create an off screen bitmap device
   1.120 +	iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
   1.121 +	}
   1.122 +
   1.123 +/**
   1.124 +Create a bitgdi context
   1.125 +@param aGc A pointer to the created graphics context
   1.126 +@param aActivate ETrue to create and activate the context aGc, EFalse to just create it.
   1.127 +@return On return, contains a pointer to the created bitgdi context
   1.128 +*/
   1.129 +TInt CTBitGdiTarget::CreateContext(CTContextBase*& aGc, TBool aActivate)
   1.130 +	{
   1.131 +	TInt result = KErrGeneral;
   1.132 +	TRAP(result, aGc = CTBitGdiContext::NewL((CFbsBitmapDevice*)iBitmapDevice, aActivate));
   1.133 +   	return result;
   1.134 +   	}
   1.135 +
   1.136 +/**
   1.137 +Sets the object to draw to a particular device 
   1.138 +@param aGc A pointer to the created graphics context
   1.139 +*/
   1.140 +TInt CTBitGdiTarget::Activate(CTContextBase*& aGc)
   1.141 +	{
   1.142 +	CTBitGdiContext* gc = (CTBitGdiContext*)aGc;
   1.143 +	// Activate the context on a rendering target.
   1.144 +	return gc->Activate(iBitmapDevice);
   1.145 +	}
   1.146 +/**
   1.147 +Get the size of the device area in pixels
   1.148 +@return On return, The width and height of the target, in pixels 
   1.149 +*/
   1.150 +TSize CTBitGdiTarget::SizeInPixels() const 
   1.151 +	{
   1.152 +	return iBitmapDevice->SizeInPixels();
   1.153 +	}
   1.154 +
   1.155 +
   1.156 +/**
   1.157 +Get a target FBsBitmap
   1.158 +@return The target FBsBitmap
   1.159 +*/
   1.160 +CFbsBitmap* CTBitGdiTarget::GetTargetFbsBitmapL()
   1.161 +	{
   1.162 +	return iBitmap;
   1.163 +	}
   1.164 +
   1.165 +/**
   1.166 +Nothing to be implemented for BitGdi Finish()
   1.167 +*/
   1.168 +void CTBitGdiTarget::Finish ()
   1.169 +	{
   1.170 +	}
   1.171 +
   1.172 +
   1.173 +void CTBitGdiTarget::Close() 
   1.174 +	{	
   1.175 +	}
   1.176 +
   1.177 +
   1.178 +/**
   1.179 +Destructor of CTBitGdiTarget
   1.180 +*/
   1.181 +CTBitGdiTarget::~CTBitGdiTarget()
   1.182 +	{
   1.183 +	delete iBitmapDevice;
   1.184 +	delete iBitmap;
   1.185 +	}
   1.186 +
   1.187 +/**
   1.188 +Default constructor.
   1.189 +*/
   1.190 +CTDirectGdiTarget::CTDirectGdiTarget()
   1.191 +	{
   1.192 +	}
   1.193 +
   1.194 +/**
   1.195 +Create a new directgdi target
   1.196 +@param aPixelFormat The pixel format for the target
   1.197 +@param aSize The size of the target to create
   1.198 +@return On return, contains a pointer to a directgdi target object
   1.199 +*/
   1.200 +CTDirectGdiTarget*  CTDirectGdiTarget::NewL(TUidPixelFormat aPixelFormat, const TSize& aSize)
   1.201 +	{
   1.202 +	CTDirectGdiTarget* self = new(ELeave) CTDirectGdiTarget();
   1.203 +	CleanupStack::PushL(self);
   1.204 +	self->ConstructL(aPixelFormat, aSize);
   1.205 +	CleanupStack::Pop(); // self
   1.206 +	return self;
   1.207 +	}
   1.208 +/**
   1.209 +Second phase constructor of CTDirectGdiTarget
   1.210 +@param aPixelFormat The pixel format for the target
   1.211 +@param aSize The size of the target to create
   1.212 +*/
   1.213 +void CTDirectGdiTarget::ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize)
   1.214 +	{	
   1.215 +	// open the driver
   1.216 +	User::LeaveIfError(CDirectGdiDriver::Open());
   1.217 +	iDGdiDriver = CDirectGdiDriver::Static();
   1.218 +	if (iDGdiDriver == NULL)
   1.219 +		User::Leave(KErrNoMemory);
   1.220 +	
   1.221 +	// set a large cache size (if available to do so) so the tests execute more quickly.
   1.222 +	MDirectGdiDriverCacheSize* driverCacheInterface = NULL;
   1.223 +	if (KErrNone == iDGdiDriver->GetInterface(TUid::Uid(KDirectGdiDriverCacheSizeUid), (TAny*&)driverCacheInterface))
   1.224 +		{
   1.225 +		User::LeaveIfError(driverCacheInterface->SetMaxImageCacheSize(KDriverImageCacheSizeTests));
   1.226 +		}
   1.227 +	
   1.228 +	iDGdiImageTarget = new (ELeave) RDirectGdiImageTarget(*iDGdiDriver);
   1.229 +	// create a bitmap which is used to save the image data from an RSgImage to a file.
   1.230 +	iBitmap = new(ELeave) CFbsBitmap;
   1.231 +	User::LeaveIfError(iBitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
   1.232 +	iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
   1.233 +	// Set up image attributes
   1.234 +	iImageInfo.iSizeInPixels = aSize;
   1.235 +	iImageInfo.iPixelFormat = aPixelFormat;
   1.236 +	iImageInfo.iUsage = ESgUsageDirectGdiTarget;
   1.237 +	User::LeaveIfError(iRSgImage.Create(iImageInfo, NULL,0));
   1.238 +	User::LeaveIfError(iDGdiImageTarget->Create(iRSgImage));
   1.239 +	}
   1.240 +
   1.241 +
   1.242 +/**
   1.243 +Create a Direct GDI graphics context.
   1.244 +
   1.245 +@param aGc	A reference to a pointer to the created graphics context. If return is anything 
   1.246 +			other than KErrNone then aGc is set to NULL.
   1.247 +@param aActivate ETrue to create and activate the context aGc, EFalse to just create it.
   1.248 +
   1.249 +@return KErrNone, if successful; otherwise, another of the system-wide error codes.
   1.250 +*/
   1.251 +TInt CTDirectGdiTarget::CreateContext(CTContextBase*& aGc, TBool aActivate)
   1.252 +	{	
   1.253 +	TInt result = KErrGeneral;
   1.254 +	
   1.255 +	aGc = NULL;
   1.256 +	
   1.257 +    TRAP(result, aGc = CTestDirectGdiContext::NewL());
   1.258 +    CTestDirectGdiContext* gc = (CTestDirectGdiContext*)aGc;
   1.259 +
   1.260 +    // If the GC is not NULL, make sure the return code indicates
   1.261 +    // success.
   1.262 +    if (aActivate && aGc)
   1.263 +    	{
   1.264 +		if(result != KErrNone)
   1.265 +			{
   1.266 +			return result;
   1.267 +			}		
   1.268 +		else
   1.269 +			{
   1.270 +			// Activate the context on a rendering target.
   1.271 +			result = gc->Activate(*iDGdiImageTarget);
   1.272 +			}
   1.273 +    	}	
   1.274 +	return result;
   1.275 +	}
   1.276 +
   1.277 +/**
   1.278 +Sets the object to draw to a particular device 
   1.279 +@param aGc A pointer to the created graphics context
   1.280 +*/
   1.281 +TInt CTDirectGdiTarget::Activate(CTContextBase*& aGc)
   1.282 +	{
   1.283 +    CTestDirectGdiContext* gc = (CTestDirectGdiContext*)aGc;
   1.284 +	// Activate the context on a rendering target.
   1.285 +    return gc->Activate(*iDGdiImageTarget);
   1.286 +	}
   1.287 +
   1.288 +/**
   1.289 +Get the size of the device area in pixels
   1.290 +@return On return, The width and height of the target, in pixels 
   1.291 +*/
   1.292 +TSize CTDirectGdiTarget::SizeInPixels() const 
   1.293 +	{
   1.294 +	return iImageInfo.iSizeInPixels;
   1.295 +	}
   1.296 +
   1.297 +/**
   1.298 +Get a target FBsBitmap.
   1.299 +@return The target FBsBitmap
   1.300 +*/
   1.301 +CFbsBitmap* CTDirectGdiTarget::GetTargetFbsBitmapL()
   1.302 +	{
   1.303 +	// Create a copy of the RSgImage that is CPU-accessible for mapping.
   1.304 +	RSgImage cpuAccessibleImage;
   1.305 +	TSgImageInfo imageInfo;
   1.306 +	imageInfo.iSizeInPixels = iImageInfo.iSizeInPixels;
   1.307 +	imageInfo.iPixelFormat = iImageInfo.iPixelFormat;
   1.308 +	imageInfo.iCpuAccess = ESgCpuAccessReadOnly;
   1.309 +	User::LeaveIfError(cpuAccessibleImage.Create(imageInfo, iRSgImage));
   1.310 +	CleanupClosePushL(cpuAccessibleImage);
   1.311 +	
   1.312 +	iBitmap->BeginDataAccess();
   1.313 +	const TInt bitmapDataStride = iBitmap->DataStride();
   1.314 +	const TInt numScanlines = imageInfo.iSizeInPixels.iHeight;
   1.315 +	const TAny* sgImageDataAddress;
   1.316 +	TInt sgImageDataStride = 0;
   1.317 +	
   1.318 +	User::LeaveIfError(cpuAccessibleImage.MapReadOnly(sgImageDataAddress, sgImageDataStride));
   1.319 +
   1.320 +    TUint32* bitmapDataAddress = iBitmap->DataAddress();
   1.321 +    for (TInt scanline = 0; scanline < numScanlines; ++scanline)
   1.322 +    	{
   1.323 +    	Mem::Copy((TUint8*)bitmapDataAddress + (scanline*bitmapDataStride), (TUint8*)sgImageDataAddress + (scanline*sgImageDataStride), bitmapDataStride);
   1.324 +    	}
   1.325 +    iBitmap->EndDataAccess();
   1.326 +    cpuAccessibleImage.Unmap();
   1.327 +
   1.328 +	CleanupStack::PopAndDestroy(1);
   1.329 +    	
   1.330 +    return iBitmap;
   1.331 +	}
   1.332 +
   1.333 +/**
   1.334 +Force completion of all batched rendering operations. Will not return
   1.335 +until rendering is complete.
   1.336 +
   1.337 +@pre	Fully initialised image target.
   1.338 +*/
   1.339 +void CTDirectGdiTarget::Finish ()
   1.340 +	{	
   1.341 +	if (iDGdiDriver)
   1.342 +		iDGdiDriver->Finish();
   1.343 +	}
   1.344 +
   1.345 +
   1.346 +void CTDirectGdiTarget::Close() 
   1.347 +	{
   1.348 +	if (iDGdiImageTarget)
   1.349 +		iDGdiImageTarget->Close();
   1.350 +	}
   1.351 +
   1.352 +/**
   1.353 +Destructor of CTDirectGdiTarget
   1.354 +*/
   1.355 +CTDirectGdiTarget::~CTDirectGdiTarget()
   1.356 +	{
   1.357 +	delete iBitmapDevice;
   1.358 +	delete iBitmap;
   1.359 +	if (iDGdiImageTarget)
   1.360 +		{
   1.361 +		iDGdiImageTarget->Close();	
   1.362 +		delete iDGdiImageTarget;
   1.363 +		}
   1.364 +	if (iDGdiDriver)
   1.365 +		iDGdiDriver->Close();
   1.366 +	iRSgImage.Close();
   1.367 +	}
   1.368 +
   1.369 +/**
   1.370 +Implementation of CTestStep base class virtual
   1.371 +It is used for doing all common initialisation to derived classes.
   1.372 +Make it being able to leave 
   1.373 +The leave will be picked up by the framework.
   1.374 +@leave Gets system wide error code
   1.375 +@return - TVerdict code
   1.376 +*/
   1.377 +TVerdict CTDirectGdiStepBase::doTestStepPreambleL()
   1.378 +	{
   1.379 +	SetTestStepResult(EPass);
   1.380 +	
   1.381 +	// Create and install Active Scheduler in case tests require active objects
   1.382 +	iScheduler = new(ELeave) CActiveScheduler;
   1.383 +	CActiveScheduler::Install(iScheduler);
   1.384 +	
   1.385 +	TPtrC targetPixelFormatInput;
   1.386 +	TPtrC sourcePixelFormatInput;
   1.387 +	TPtrC sourceResourcePixelFormatInput;
   1.388 +	
   1.389 +	// get input for tests from .ini file
   1.390 +	_LIT(KDirectgdiTestInput, "DirectgdiTestInput");
   1.391 +	_LIT(KTargetPixelFormatEnums, "TargetPixelFormatEnums ");
   1.392 +	_LIT(KSourcePixelFormatEnums, "SourcePixelFormatEnums ");
   1.393 +	_LIT(KSourceResourcePixelFormatEnums, "SourceResourcePixelFormatEnums ");
   1.394 +	_LIT(KDoRefImg, "DoRefImg");
   1.395 +	_LIT(KDoDirectGdi, "DoDirectGdi");
   1.396 +	_LIT(KRunOomTests, "RunOomTests");
   1.397 +	TEST(GetStringFromConfig(KDirectgdiTestInput, KTargetPixelFormatEnums, targetPixelFormatInput));
   1.398 +	TEST(GetStringFromConfig(KDirectgdiTestInput, KSourcePixelFormatEnums, sourcePixelFormatInput));
   1.399 +	TEST(GetStringFromConfig(KDirectgdiTestInput, KSourceResourcePixelFormatEnums, sourceResourcePixelFormatInput));
   1.400 +	TEST(GetIntFromConfig(KDirectgdiTestInput, KDoRefImg, iMakeRefImg));
   1.401 +	TEST(GetIntFromConfig(KDirectgdiTestInput, KDoDirectGdi, iUseDirectGdi));
   1.402 +	TEST(GetIntFromConfig(KDirectgdiTestInput, KRunOomTests, iDoOomTests));
   1.403 +	#ifndef _DEBUG
   1.404 +	if(iDoOomTests)
   1.405 +		{
   1.406 +		iDoOomTests = EFalse;
   1.407 +		INFO_PRINTF1(_L("WARNING: Can't run out of memory tests under a release build. OOM tests set to run in ini file so turning OOM tests off."));
   1.408 +		}
   1.409 +	#endif
   1.410 +
   1.411 +	ConvertPixelFormats(targetPixelFormatInput, iTargetPixelFormatArray);
   1.412 +	ConvertPixelFormats(sourcePixelFormatInput, iSourcePixelFormatArray);
   1.413 +	ConvertPixelFormats(sourceResourcePixelFormatInput, iSourceResourcePixelFormatArray);
   1.414 +	iRunningOomTests = EFalse;
   1.415 +
   1.416 +	Logger().ShareAuto();
   1.417 +
   1.418 +	__UHEAP_MARK;		
   1.419 +	User::LeaveIfError(SgDriver::Open());
   1.420 +	User::LeaveIfError(RFbsSession::Connect());	
   1.421 +		
   1.422 +	return TestStepResult();
   1.423 +	}
   1.424 +
   1.425 +/**
   1.426 +Convert the pixel format strings to pixel format enums
   1.427 +@param aPixelFormatInput The pixel format string for testing
   1.428 +@param aPixelFormatArray The array of converted pixel formats is returned here
   1.429 +*/
   1.430 +void CTDirectGdiStepBase::ConvertPixelFormats(TPtrC aPixelFormatInput, RArray<TUidPixelFormat>& aPixelFormatArray)
   1.431 +	{
   1.432 +	TPtrC tempBuf = aPixelFormatInput;
   1.433 +	TInt position = tempBuf.Find(_L(","));
   1.434 +			
   1.435 +	while(KErrNotFound != position)
   1.436 +		{
   1.437 +		aPixelFormatArray.Append(TDisplayModeMapping::ConvertPixelFormatStringToPixelFormat(tempBuf.Left(position)));
   1.438 +		tempBuf.Set(tempBuf.Mid(position + 2));
   1.439 +		position = tempBuf.Find(_L(","));
   1.440 +		}	
   1.441 +
   1.442 +	if (position == KErrNotFound)
   1.443 +		{
   1.444 +		aPixelFormatArray.Append(TDisplayModeMapping::ConvertPixelFormatStringToPixelFormat(tempBuf));
   1.445 +		}
   1.446 +	}
   1.447 +
   1.448 +/**
   1.449 +Implementation of CTestStep base class virtual
   1.450 +It is used for doing all after test treatment common to derived classes in here.
   1.451 +Make it being able to leave
   1.452 +The leave will be picked up by the framework.
   1.453 +@leave Gets system wide error code
   1.454 +@return - TVerdict
   1.455 +*/
   1.456 + TVerdict CTDirectGdiStepBase::doTestStepPostambleL()
   1.457 +	{
   1.458 +	if(iFontStore)
   1.459 +		{
   1.460 +		if(iFontId)
   1.461 +			{
   1.462 +			iFontStore->RemoveFile(iFontId);
   1.463 +			iFontId = 0;
   1.464 +			}
   1.465 +		delete iFontStore;
   1.466 +		iFontStore = NULL;
   1.467 +		}
   1.468 +	delete iGc;
   1.469 +	iGc = NULL;
   1.470 +	delete iGc2;
   1.471 +	iGc2 = NULL;
   1.472 +	delete iGdiTarget;
   1.473 +	iGdiTarget = NULL;
   1.474 +	delete iGdiTarget2;
   1.475 +	iGdiTarget2 = NULL;	
   1.476 +	SgDriver::Close();
   1.477 +	RFbsSession::Disconnect();
   1.478 +	__UHEAP_MARKEND;
   1.479 +	delete iScheduler;
   1.480 +	iScheduler = NULL;
   1.481 +	return TestStepResult();
   1.482 +	}
   1.483 +
   1.484 +CTDirectGdiStepBase::~CTDirectGdiStepBase()
   1.485 +	{
   1.486 +	if(iFontStore)
   1.487 +		{
   1.488 +		if(iFontId)
   1.489 +			{
   1.490 +			iFontStore->RemoveFile(iFontId);			
   1.491 +			}
   1.492 +		delete iFontStore;
   1.493 +		}
   1.494 +	delete iScheduler;
   1.495 +	delete iGc;
   1.496 +	delete iGc2;
   1.497 +	delete iGdiTarget;
   1.498 +	delete iGdiTarget2;
   1.499 +	iTargetPixelFormatArray.Close();
   1.500 +	iSourcePixelFormatArray.Close();
   1.501 +	iSourceResourcePixelFormatArray.Close();
   1.502 +	}
   1.503 +
   1.504 +CTDirectGdiStepBase::CTDirectGdiStepBase()
   1.505 +	{
   1.506 +	}
   1.507 +
   1.508 +/**
   1.509 +Create a name in the format of <TestImage / RefImage>_< TestCase Name >_<DisplayModeName>_<Orientation>_<PostFix(optional)>
   1.510 +@param aParams A structure object of parameters to be passed through
   1.511 +@param aTestName The test name to be generated 
   1.512 +@param aTestCaseName The test case name passed in, to be used in the resultant filename
   1.513 +@param aNamePostfix If this is not NULL, it is appended to filename with an underscore in front of it
   1.514 +*/
   1.515 +void CTDirectGdiStepBase::CreateFileName(TTestParams& aParams, TDes& aTestName, TPtrC& aTestCaseName, TDesC* aNamePostfix)
   1.516 +	{	
   1.517 +	if (iUseDirectGdi)
   1.518 +		{
   1.519 +		aTestName.Append(KDirectGc);
   1.520 +		}
   1.521 +	else
   1.522 +		{
   1.523 +		aTestName.Append(KBitGc);		
   1.524 +		}
   1.525 +	
   1.526 +	if (aParams.iDoCompressed)
   1.527 +		{
   1.528 +		aTestName.Append(KSeparator);	
   1.529 +		aTestName.Append(KCom);
   1.530 +		}
   1.531 +
   1.532 +	aTestName.Append(KSeparator);	
   1.533 +	aTestName.Append(aTestCaseName);
   1.534 +	aTestName.Append(KSeparator);
   1.535 +	aTestName.Append(KTargetString);
   1.536 +	aTestName.Append(KSeparator);
   1.537 +	aTestName.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(aParams.iTargetPixelFormat));
   1.538 +	
   1.539 +	if (aNamePostfix)
   1.540 +		{
   1.541 +		aTestName.Append(KSeparator);
   1.542 +		aTestName.Append(*aNamePostfix);
   1.543 +		}
   1.544 +	}
   1.545 +
   1.546 +/**
   1.547 +@see DisplayTargetImageL(TUidPixelFormat, CTImageTarget*)
   1.548 + */
   1.549 +void CTDirectGdiStepBase::DisplayTargetImageL(TUidPixelFormat aPixelFormat)
   1.550 +	{
   1.551 +	DisplayTargetImageL(aPixelFormat, iGdiTarget);
   1.552 +	}
   1.553 +
   1.554 +/**
   1.555 +Bitblt an image to screen
   1.556 +@param aPixelFormat The pixel format for tests
   1.557 +@param aGdiTarget The target image to blit
   1.558 +*/
   1.559 +void CTDirectGdiStepBase::DisplayTargetImageL(TUidPixelFormat aPixelFormat, CTImageTarget* aGdiTarget)
   1.560 +	{
   1.561 +	// Ensure the image has been completly rendered.
   1.562 +	aGdiTarget->Finish();
   1.563 +	CFbsScreenDevice* screenDevice = CFbsScreenDevice::NewL(_L("scdv"), TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat));
   1.564 +	TEST(screenDevice!=NULL);
   1.565 +	CleanupStack::PushL(screenDevice);
   1.566 +	
   1.567 +	CFbsBitGc* bitGc;
   1.568 +	screenDevice->CreateContext(bitGc);
   1.569 +	TEST(bitGc!=NULL);
   1.570 +	CleanupStack::PushL(bitGc);
   1.571 +
   1.572 + 	TPoint startPoint = TPoint(0, 0);
   1.573 +	bitGc->Clear();
   1.574 +	bitGc->BitBlt(startPoint, aGdiTarget->GetTargetFbsBitmapL()); 		
   1.575 +	screenDevice->Update();
   1.576 +
   1.577 +	CleanupStack::PopAndDestroy(2, screenDevice);	
   1.578 +	}
   1.579 +
   1.580 +/**
   1.581 +Initialises a target (or targets) and a graphics context (or contexts), depending on the value passed in aCase.
   1.582 +Deletes the previously used target(s) and context(s).
   1.583 +@param aPixelFormat The pixel format to be applied
   1.584 +@param aCase The type of test that this target is for, for example when testing with one context and two targets
   1.585 +this could be EOneContextTwoTargets_SamePixelType, the default value is EOneContextOneTarget.
   1.586 +@param aSize The size of the target(s) to be created
   1.587 +*/
   1.588 +void CTDirectGdiStepBase::SetTargetL(TUidPixelFormat aPixelFormat, const TContextTestCase aCase, const TSize& aSize)
   1.589 +	{
   1.590 +	if(!iRunningOomTests)
   1.591 +		{
   1.592 +		TBuf<KPixelFormatNameLength> pixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(aPixelFormat));
   1.593 +		INFO_PRINTF4(_L("SetTarget (using off screen bitmap): %S %dx%d"), &pixelFormatName, aSize.iWidth, aSize.iHeight);
   1.594 +		}
   1.595 +	
   1.596 +	delete iGc;
   1.597 +	iGc = NULL;	
   1.598 +	delete iGc2;
   1.599 +	iGc2 = NULL;	
   1.600 +	delete iGdiTarget;
   1.601 +	iGdiTarget = NULL;
   1.602 +	delete iGdiTarget2;
   1.603 +	iGdiTarget2 = NULL;
   1.604 +	TUidPixelFormat aPixelFormat2 = aPixelFormat;
   1.605 +	switch(aPixelFormat)
   1.606 +		{
   1.607 +		case EUidPixelFormatRGB_565:
   1.608 +			aPixelFormat2 = EUidPixelFormatARGB_8888_PRE;
   1.609 +			break;			
   1.610 +		case EUidPixelFormatARGB_8888_PRE:	
   1.611 +			aPixelFormat2 = EUidPixelFormatXRGB_8888;	
   1.612 +			break;			
   1.613 +		case EUidPixelFormatXRGB_8888:		
   1.614 +			aPixelFormat2 = EUidPixelFormatRGB_565;	
   1.615 +			break;
   1.616 +		}	
   1.617 +		
   1.618 +	switch(aCase)
   1.619 +		{
   1.620 +		case EOneContextOneTarget:				
   1.621 +			{
   1.622 +			if(iUseDirectGdi)
   1.623 +				{
   1.624 +				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
   1.625 +				}
   1.626 +			else
   1.627 +				{
   1.628 +				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
   1.629 +				}
   1.630 +			User::LeaveIfError(iGdiTarget->CreateContext(iGc));	
   1.631 +			}
   1.632 +			break;
   1.633 +		case EOneContextTwoTargets_SamePixelType:
   1.634 +			{			
   1.635 +			if(iUseDirectGdi)
   1.636 +				{
   1.637 +				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
   1.638 +				iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
   1.639 +				}
   1.640 +			else
   1.641 +				{
   1.642 +				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
   1.643 +				iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat, aSize);		
   1.644 +				}
   1.645 +			User::LeaveIfError(iGdiTarget->CreateContext(iGc));				
   1.646 +			}
   1.647 +			break;
   1.648 +		case EOneContextTwoTargets_DifferentPixelType:
   1.649 +			{	
   1.650 +			if(iUseDirectGdi)
   1.651 +				{
   1.652 +				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
   1.653 +				iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat2, aSize);		
   1.654 +				}
   1.655 +			else
   1.656 +				{
   1.657 +				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
   1.658 +				iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat2, aSize);		
   1.659 +				}
   1.660 +			User::LeaveIfError(iGdiTarget->CreateContext(iGc));				
   1.661 +			}
   1.662 +			break;
   1.663 +		case ETwoContextsOneTarget:
   1.664 +			{
   1.665 +			if(iUseDirectGdi)
   1.666 +				{
   1.667 +				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
   1.668 +				}
   1.669 +			else
   1.670 +				{
   1.671 +				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
   1.672 +				}
   1.673 +			User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse));	
   1.674 +			User::LeaveIfError(iGdiTarget->CreateContext(iGc2, EFalse));		
   1.675 +			}		
   1.676 +			break;
   1.677 +		case ETwoContextsTwoTargets_WithoutSharing_SamePixelType:
   1.678 +		case ETwoContextsTwoTargets_WithSharing_SamePixelType:
   1.679 +			{
   1.680 +			if(iUseDirectGdi)
   1.681 +				{
   1.682 +				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
   1.683 +				iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
   1.684 +				}
   1.685 +			else
   1.686 +				{
   1.687 +				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
   1.688 +				iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat, aSize);
   1.689 +				}
   1.690 +			User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse));	
   1.691 +			User::LeaveIfError(iGdiTarget2->CreateContext(iGc2, EFalse));	
   1.692 +			}
   1.693 +			break;
   1.694 +		case ETwoContextsTwoTargets_WithoutSharing_DifferentPixelType:
   1.695 +		case ETwoContextsTwoTargets_WithSharing_DifferentPixelType:
   1.696 +			{
   1.697 +			if(iUseDirectGdi)
   1.698 +				{
   1.699 +				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
   1.700 +				iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat2, aSize);		
   1.701 +				}
   1.702 +			else
   1.703 +				{
   1.704 +				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
   1.705 +				iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat2, aSize);
   1.706 +				}
   1.707 +			User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse));	
   1.708 +			User::LeaveIfError(iGdiTarget2->CreateContext(iGc2, EFalse));	
   1.709 +			}
   1.710 +			break;									
   1.711 +		case EOneContextOneTarget_TwiceActivate:
   1.712 +			{
   1.713 +			if(iUseDirectGdi)
   1.714 +				{
   1.715 +				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
   1.716 +				}
   1.717 +			else
   1.718 +				{
   1.719 +				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
   1.720 +				}
   1.721 +			User::LeaveIfError(iGdiTarget->CreateContext(iGc));	
   1.722 +			}
   1.723 +			break;		
   1.724 +		}	
   1.725 +
   1.726 +	// setup font store
   1.727 +	if(iFontStore)
   1.728 +		{
   1.729 +		if(iFontId)
   1.730 +			{
   1.731 +			iFontStore->RemoveFile(iFontId);
   1.732 +			iFontId = 0;
   1.733 +			}
   1.734 +		delete iFontStore;
   1.735 +		iFontStore = NULL;
   1.736 +		}
   1.737 +	
   1.738 +	iFontStore = CFbsTypefaceStore::NewL(iGdiTarget->BitmapDevice());
   1.739 +
   1.740 +	_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr");
   1.741 +	TESTL(KErrNone == iFontStore->AddFile(KEonFontFileName, iFontId));
   1.742 +	
   1.743 +	// Reset VGImage cache - OpenVG DirectGDI only
   1.744 +	iVgImageCache = NULL;
   1.745 +	if (iUseDirectGdi)
   1.746 +		{
   1.747 +		TInt err = iGc->GetInterface(TUid::Uid(KDirectGdiVgImageCacheUid), (TAny*&) iVgImageCache);
   1.748 +		if (KErrNotSupported == err)
   1.749 +			{
   1.750 +			// Must be using software DirectGDI as this does not have a VGImage cache
   1.751 +			iUseSwDirectGdi = ETrue;
   1.752 +			}
   1.753 +		}
   1.754 +	}
   1.755 +
   1.756 +/**
   1.757 +Get a font by looking for it in the font store. Only gets "DejaVu Sans Mono" at the moment.
   1.758 +@return Returns a pointer to the "DejaVu Sans Mono" font if it is found in the font store, returns NULL if it not found.
   1.759 +*/
   1.760 +CFont* CTDirectGdiStepBase::GetFont()
   1.761 +	{
   1.762 +	_LIT(KFontFamily, "DejaVu Sans Mono");
   1.763 +
   1.764 +	CFont* font = NULL;
   1.765 +	TFontSpec spec(KFontFamily, 13);
   1.766 +	iFontStore->GetNearestFontInPixels(font, spec);
   1.767 +	return font;
   1.768 +	}
   1.769 +
   1.770 +/**
   1.771 +Releases the passed font in the font store.
   1.772 +@param aFont A pointer to the font to be released.
   1.773 + */
   1.774 +void CTDirectGdiStepBase::ReleaseFont(CFont* aFont)
   1.775 +	{
   1.776 +	if(aFont && iFontStore)
   1.777 +		{
   1.778 +		iFontStore->ReleaseFont(aFont);
   1.779 +		}
   1.780 +	}
   1.781 +
   1.782 +/**
   1.783 +Create a file and save the target image to the file with a filename created from aTestCaseName and aNamePostfix
   1.784 +@param aParams A structure object of parameters to be passed through
   1.785 +@param aTestCaseName The name of the test case
   1.786 +@param aImageTarget The image target to be written out to the file
   1.787 +@param aNamePostfix A postfix to be appended to the test case name
   1.788 +@see CreateFileName()
   1.789 +@return KErrNone if successful, one of the system wide error codes otherwise
   1.790 +*/
   1.791 +TInt CTDirectGdiStepBase::WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, CTImageTarget* aImageTarget, TDesC* aNamePostfix)
   1.792 +	{
   1.793 +	// Finish is called for the OOM tests as well as the normal tests as it is responsible for
   1.794 +	// clearing up the pending image array. Images get left in the array and cause the OOM tests
   1.795 +	// for DrawResource to fail if Finish is not called.
   1.796 +	aImageTarget->Finish();
   1.797 +	
   1.798 +	if(!iRunningOomTests) // don't want to save test images when running our of memory twsts
   1.799 +		{
   1.800 +		TBuf<KFileNameLength> testFileName;
   1.801 +		CreateFileName(aParams, testFileName, aTestCaseName, aNamePostfix);
   1.802 +		TFileName mbmFile;
   1.803 +		TBuf<KFileNameLength> testPathName;
   1.804 +		#ifdef __WINS__
   1.805 +			testPathName.Append(_L("c:"));
   1.806 +		#else
   1.807 +			testPathName.Append(_L("e:"));
   1.808 +		#endif
   1.809 +	
   1.810 +		if (iMakeRefImg)
   1.811 +			{
   1.812 +			testPathName.Append(KRefPath);
   1.813 +			mbmFile.Format(testPathName, &testFileName);
   1.814 +			}
   1.815 +		else
   1.816 +			{
   1.817 +			testPathName.Append(KTestPath);
   1.818 +			mbmFile.Format(testPathName, &testFileName);
   1.819 +			}
   1.820 +		INFO_PRINTF1(testFileName);
   1.821 +		
   1.822 +		CFbsBitmap* targetBitmap = NULL;
   1.823 +		TRAPD(err, targetBitmap = aImageTarget->GetTargetFbsBitmapL());
   1.824 +		return (err != KErrNone) ? err : targetBitmap->Save(mbmFile);		
   1.825 +		}
   1.826 +	return KErrNone;
   1.827 +	}
   1.828 +
   1.829 +/**
   1.830 +Create a file and save the current target image to the file with a filename created from aTestCaseName and aNamePostfix
   1.831 +@param aParams A structure object of parameters to be passed through
   1.832 +@param aTestCaseName The name of the test case
   1.833 +@param aNamePostfix A postfix to be appended to the test case name
   1.834 +@see CreateFileName()
   1.835 +@return KErrNone if successful, one of the system wide error codes otherwise
   1.836 +*/
   1.837 +TInt CTDirectGdiStepBase::WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, TDesC* aNamePostfix)
   1.838 +	{
   1.839 +	return WriteTargetOutput(aParams, aTestCaseName, iGdiTarget, aNamePostfix);
   1.840 +	}
   1.841 +
   1.842 +/**
   1.843 +Reset the graphics context
   1.844 +*/
   1.845 +void CTDirectGdiStepBase::ResetGc()
   1.846 +	{
   1.847 +	iGc->Reset();
   1.848 +	iGc->Clear();
   1.849 +	}
   1.850 +
   1.851 +/**
   1.852 +Compares the target image pixel by pixel against the given colour. If a pixel with a  
   1.853 +different colour than aColour is found then the test will fail, otherwise the test will pass.
   1.854 +@param aColour A colour rgba value to find.
   1.855 +@return ETrue if test passed or EFalse if test failed.
   1.856 +*/
   1.857 +TBool CTDirectGdiStepBase::TestTargetL(const TRgb& aColour)
   1.858 +	{
   1.859 +	iGdiTarget->Finish();
   1.860 +		
   1.861 +	CFbsBitmap* bitmap = iGdiTarget->GetTargetFbsBitmapL();
   1.862 +	TInt width = bitmap->SizeInPixels().iWidth;
   1.863 +	TInt height = bitmap->SizeInPixels().iHeight;
   1.864 +
   1.865 +	HBufC8* lineBuf = HBufC8::NewLC(width*4);
   1.866 +	TPtr8 linePtr(lineBuf->Des());
   1.867 +
   1.868 +	TBool pass = ETrue;
   1.869 +
   1.870 +	for(TInt line=0; line<height; line++)
   1.871 +		{
   1.872 +		bitmap->GetScanLine(linePtr, TPoint(0, line), width, EColor16MA);
   1.873 +
   1.874 +		const TUint8* pPtr = linePtr.Ptr();
   1.875 +		for(TInt x=0; x<width; x++)
   1.876 +			{
   1.877 +			// EColor16MA pixel representation is 32-bit BGRA
   1.878 +			TRgb pColour(pPtr[2], pPtr[1], pPtr[0], pPtr[3]);
   1.879 +			pPtr += 4;
   1.880 +			
   1.881 +			if (iTestParams.iTargetPixelFormat == EUidPixelFormatXRGB_8888)
   1.882 +				{
   1.883 +				if ((pColour.Value() & 0xFFFFFF) != (aColour.Value() & 0xFFFFFF))
   1.884 +					{
   1.885 +					pass = EFalse;
   1.886 +					break; // break inner loop
   1.887 +					}
   1.888 +				}
   1.889 +			else if(pColour != aColour)
   1.890 +				{
   1.891 +				pass = EFalse;
   1.892 +				break; // break inner loop
   1.893 +				}
   1.894 +			}
   1.895 +
   1.896 +		if(!pass)
   1.897 +			break; // break outer loop if test failed in inner loop
   1.898 +		}
   1.899 +
   1.900 +	CleanupStack::PopAndDestroy(lineBuf);
   1.901 +
   1.902 +	return pass;
   1.903 +	}
   1.904 +
   1.905 +/**
   1.906 +Checks the graphics context for the passed error codes and logs an error if the codes do not match. 
   1.907 +If the tests are running using DirectGdi then aDirectGdiErrorCode is checked against the current error in the
   1.908 +graphics context, if the tests are running using BitGdi then aBitGdiErrorCode is checked against the current 
   1.909 +error in the graphics context.
   1.910 +@param aDirectGdiErrorCode The DirectGdi error code to check when the tests are running using DirectGdi
   1.911 +@param aBitGdiErrorCode The BitGdi error code to check when the tests are running using BitGdi
   1.912 +@param aFile The filename to use when reporting the error
   1.913 +@param aLine The line number to use when reporting the error
   1.914 +*/
   1.915 +void CTDirectGdiStepBase::CheckErrorsL(TInt aDirectGdiErrorCode, TInt aBitGdiErrorCode, const TText8* aFile, TInt aLine)
   1.916 +	{
   1.917 +	if(iUseDirectGdi)
   1.918 +		{
   1.919 +		TESTWITHFILENAMEANDLINENUMBERL(iGc->GetError() == aDirectGdiErrorCode, aFile, aLine);
   1.920 +		}
   1.921 +	else
   1.922 +		{
   1.923 +		TESTWITHFILENAMEANDLINENUMBERL(iGc->GetError() == aBitGdiErrorCode, aFile, aLine);
   1.924 +		}
   1.925 +	}
   1.926 +
   1.927 +/**
   1.928 +Derived classes should override this method and add their calls to individual test cases in
   1.929 +the overridden version.
   1.930 +*/
   1.931 +void CTDirectGdiStepBase::RunTestsL()
   1.932 +	{
   1.933 +	}
   1.934 +
   1.935 +/**
   1.936 +Runs the tests in RunTestsL checking for Out of Memory conditions and testing for memory leaks.
   1.937 +*/
   1.938 +void CTDirectGdiStepBase::RunOomTestsL()
   1.939 +	{
   1.940 +	if (!iDoOomTests)
   1.941 +		{
   1.942 +		// don't run the out of memory tests
   1.943 +		return;
   1.944 +		}
   1.945 +	TInt tryCount = 0;
   1.946 +	INFO_PRINTF1(_L("*****Running Out Of Memory Tests*****"));
   1.947 +	
   1.948 +	// save the current state of test step results
   1.949 +	TVerdict currentTestStepResult = TestStepResult();
   1.950 +
   1.951 +	FOREVER
   1.952 +		{		
   1.953 +		iRunningOomTests = ETrue;
   1.954 +		TInt err = KErrNone;
   1.955 +		
   1.956 +		// count cells so we can know how many we leaked
   1.957 +		TInt cellsStart = User::CountAllocCells();
   1.958 +		
   1.959 +		__UHEAP_FAILNEXT(++tryCount);
   1.960 +		__UHEAP_MARK;
   1.961 +		
   1.962 +		TRAP(err, RunTestsL());
   1.963 +
   1.964 +		TBool finishedCorrectly = EFalse;
   1.965 +		if ((err == KErrNone))
   1.966 +			{
   1.967 +			// claims to have finished correctly, and we're not failing every alloc
   1.968 +			finishedCorrectly = CheckForHeapFailNext();
   1.969 +			}		
   1.970 +		__UHEAP_RESET;
   1.971 +		TInt cellsEnd = User::CountAllocCells();
   1.972 +		if (cellsStart < cellsEnd)
   1.973 +			{
   1.974 +			// leaked.
   1.975 +			TInt leakedCells = cellsEnd - cellsStart;
   1.976 +			ERR_PRINTF3(_L("On loop number %d we leaked %d cells. About to cause panic."),tryCount,leakedCells);				
   1.977 +			}
   1.978 +		__UHEAP_MARKEND;
   1.979 +		
   1.980 +		// check to see if we finished all OOM testing successfully
   1.981 +		if ((err == KErrNone) && finishedCorrectly)
   1.982 +			{
   1.983 +			INFO_PRINTF2(_L(" - Test completed successfully after %d iterations."),tryCount);
   1.984 +			break;
   1.985 +			}
   1.986 +		}
   1.987 +	// restore test step result and ignore any test failures the out of memory tests produce
   1.988 +	SetTestStepResult(currentTestStepResult);
   1.989 +	iRunningOomTests = EFalse;
   1.990 +	}
   1.991 +
   1.992 +/**
   1.993 +Tests that the passed condition aCondition is equal to ETrue and reports an error if it is not.
   1.994 +This method does not report errors when the tests are running in OOM mode.
   1.995 +@see testBooleanTrue()
   1.996 +@param aCondition The boolean value to be checked for being equal to ETrue
   1.997 +@param aFile The filename to use when reporting the error
   1.998 +@param aLine The line number to use when reporting the error
   1.999 +*/
  1.1000 +void CTDirectGdiStepBase::testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine) 
  1.1001 +	{
  1.1002 +	if(!iRunningOomTests)
  1.1003 +		{
  1.1004 +		CTestStep::testBooleanTrue(aCondition, aFile, aLine, ETrue);
  1.1005 +		}
  1.1006 +	}
  1.1007 +
  1.1008 +/**
  1.1009 +A leaving version of testBooleanTrue().
  1.1010 +@see testBooleanTrue()
  1.1011 +*/
  1.1012 +void CTDirectGdiStepBase::testBooleanTrueL(TBool aCondition, const TText8* aFile, TInt aLine) 
  1.1013 +	{
  1.1014 +	if(!iRunningOomTests)
  1.1015 +		{
  1.1016 +		CTestStep::testBooleanTrueL(aCondition, aFile, aLine, ETrue);
  1.1017 +		}
  1.1018 +	else
  1.1019 +		{
  1.1020 +		if(!aCondition)
  1.1021 +			{
  1.1022 +			User::Leave(TEST_ERROR_CODE);
  1.1023 +			}
  1.1024 +		}
  1.1025 +	}
  1.1026 +
  1.1027 +/**
  1.1028 +A version of testBooleanTrue() that additionally writes an error code to the output if aCondition is not equal to ETrue.
  1.1029 +@see testBooleanTrue()
  1.1030 +@param aCondition The boolean value to be checked for being equal to ETrue
  1.1031 +@param aErrorCode An error code to be reported if aCondition is EFalse
  1.1032 +@param aFile The filename to use when reporting the error
  1.1033 +@param aLine The line number to use when reporting the error
  1.1034 +*/
  1.1035 +void CTDirectGdiStepBase::testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine)
  1.1036 +	{
  1.1037 +	if(!iRunningOomTests)
  1.1038 +		{
  1.1039 +		if(!aCondition)			
  1.1040 +			{
  1.1041 +			SetTestStepResult(EFail);
  1.1042 +			_LIT(KMessage,"Test Failed with error [%d]");
  1.1043 +			Logger().LogExtra(aFile, aLine, ESevrErr, KMessage, aErrorCode);
  1.1044 +			}
  1.1045 +		}
  1.1046 +	}
  1.1047 +
  1.1048 +/**
  1.1049 +A leaving version of testBooleanTrueWithErrorCode()
  1.1050 +@see testBooleanTrueWithErrorCode()
  1.1051 +@param aCondition The boolean value to be checked for being equal to ETrue
  1.1052 +@param aErrorCode An error code to be reported if aCondition is EFalse
  1.1053 +@param aFile The filename to use when reporting the error
  1.1054 +@param aLine The line number to use when reporting the error
  1.1055 +*/
  1.1056 +void CTDirectGdiStepBase::testBooleanTrueWithErrorCodeL(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine)
  1.1057 +	{
  1.1058 +	if(!iRunningOomTests)
  1.1059 +		{
  1.1060 +		testBooleanTrueWithErrorCode(aCondition, aErrorCode, aFile, aLine);
  1.1061 +		}
  1.1062 +	else
  1.1063 +		{
  1.1064 +		if(!aCondition)
  1.1065 +			{
  1.1066 +			User::Leave(aErrorCode);
  1.1067 +			}
  1.1068 +		}
  1.1069 +	}
  1.1070 +
  1.1071 +/**
  1.1072 +Creates a CFbsBitmap that has a pattern of differently coloured concentric rectangles on it for use in test cases.
  1.1073 +@param aPixelFormat The pixel format for create the target bitmap
  1.1074 +@param aSize The size of the bitmap to be created
  1.1075 +*/
  1.1076 +CFbsBitmap* CTDirectGdiStepBase::CreateConcentricRectsBitmapL(TUidPixelFormat aPixelFormat, const TSize& aSize)
  1.1077 +	{
  1.1078 +	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
  1.1079 +	CleanupStack::PushL(bitmap);
  1.1080 +
  1.1081 +	TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
  1.1082 +
  1.1083 +	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
  1.1084 +	TESTL(bitmapDevice!=NULL);
  1.1085 +	CleanupStack::PushL(bitmapDevice);
  1.1086 +	
  1.1087 +	CFbsBitGc* bitGc = NULL;
  1.1088 +	User::LeaveIfError(bitmapDevice->CreateContext(bitGc));
  1.1089 +	TESTL(bitGc!=NULL);
  1.1090 +	CleanupStack::PushL(bitGc);
  1.1091 +
  1.1092 +	for (TInt i = aSize.iWidth/2; i>0; --i)
  1.1093 +		{
  1.1094 +		bitGc->SetPenColor(KColor16Table[i%16]);	
  1.1095 +		bitGc->DrawRect(TRect(i,i,aSize.iWidth - i, aSize.iHeight - i));
  1.1096 +		}
  1.1097 +
  1.1098 +	CleanupStack::PopAndDestroy(2, bitmapDevice);
  1.1099 +	CleanupStack::Pop(bitmap);
  1.1100 +	
  1.1101 +	return bitmap;
  1.1102 +	}
  1.1103 +
  1.1104 +/**
  1.1105 +Creates a bitmap that contains a checked board pattern of coloured rectangles for use in test cases.
  1.1106 +@param aPixelFormat The pixel format for create the target bitmap
  1.1107 +@param aSize The size of the bitmap
  1.1108 +@param aChecksPerAxis Number of checks on X and Y.
  1.1109 +@param aGenAlpha If ETrue then generate pattern in alpha channel.
  1.1110 +*/
  1.1111 +CFbsBitmap* CTDirectGdiStepBase::CreateCheckedBoardBitmapL(TUidPixelFormat aPixelFormat,
  1.1112 +		const TSize& aSize, const TSize& aChecksPerAxis, TBool aGenAlpha)
  1.1113 +	{
  1.1114 +	
  1.1115 +	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
  1.1116 +	CleanupStack::PushL(bitmap);
  1.1117 +	TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
  1.1118 +	
  1.1119 +	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
  1.1120 +	CleanupStack::PushL(bitmapDevice);
  1.1121 +	TESTL(bitmapDevice!=NULL);
  1.1122 +	
  1.1123 +	CFbsBitGc* bitGc = NULL;
  1.1124 +	User::LeaveIfError(bitmapDevice->CreateContext(bitGc));
  1.1125 +	CleanupStack::PushL(bitGc);
  1.1126 +	TESTL(bitGc!=NULL);
  1.1127 +	
  1.1128 +	bitGc->Clear();
  1.1129 +	bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1.1130 +	bitGc->SetPenStyle(CGraphicsContext::ENullPen);
  1.1131 +	if(aGenAlpha)
  1.1132 +		{
  1.1133 +		bitGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
  1.1134 +		}
  1.1135 +	TPoint point(0,0);
  1.1136 +	const TSize checkerSize(aSize.iWidth/aChecksPerAxis.iWidth,aSize.iHeight/aChecksPerAxis.iHeight);
  1.1137 +	TInt brushColour = 0x00;
  1.1138 +	for(point.iY = 0; point.iY < aSize.iHeight; point.iY += checkerSize.iHeight)
  1.1139 +		{
  1.1140 +		for(point.iX = 0; point.iX < aSize.iWidth; point.iX += checkerSize.iWidth)
  1.1141 +			{
  1.1142 +			TRgb colour = KColor16Table[brushColour++ & 0x0F];
  1.1143 +			if(aGenAlpha)
  1.1144 +				{
  1.1145 +				// Note that this is converted internally to pre-multiplied alpha
  1.1146 +				// for pre-multiplied alpha targets.
  1.1147 +				colour.SetAlpha((brushColour*5) & 255);
  1.1148 +				
  1.1149 +				//Use the following line to simplify test for manual verification.
  1.1150 +				//colour.SetAlpha(0x80);
  1.1151 +				}
  1.1152 +			bitGc->SetBrushColor(colour);
  1.1153 +			TRect rect(point, checkerSize);
  1.1154 +			bitGc->DrawRect(rect);
  1.1155 +			}
  1.1156 +		}
  1.1157 +	CleanupStack::PopAndDestroy(2, bitmapDevice);
  1.1158 +	CleanupStack::Pop(bitmap);
  1.1159 +	
  1.1160 +	return bitmap;
  1.1161 +	}
  1.1162 +
  1.1163 +/**
  1.1164 +Create a black and white checked bitmap
  1.1165 +@param aPixelFormat The pixel format to use when creating the target bitmap
  1.1166 +@param aSize The size of the bitmap to create
  1.1167 +@param aChecksPerAxis Number of checks to draw in the X and Y directions
  1.1168 +@param aIsHardwareBitmap If ETrue, creates a hardware CFbsBitmap.
  1.1169 +*/
  1.1170 +CFbsBitmap* CTDirectGdiStepBase::CreateBlackWhiteBitmapL(TUidPixelFormat aPixelFormat,
  1.1171 +		const TSize& aSize, const TSize& aChecksPerAxis)
  1.1172 +	{
  1.1173 +	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
  1.1174 +	CleanupStack::PushL(bitmap);
  1.1175 +	
  1.1176 +	TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
  1.1177 +	
  1.1178 +	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
  1.1179 +	CleanupStack::PushL(bitmapDevice);
  1.1180 +	TESTL(bitmapDevice!=NULL);
  1.1181 +
  1.1182 +	CFbsBitGc* bitGc = NULL;
  1.1183 +	bitmapDevice->CreateContext(bitGc);
  1.1184 +	CleanupStack::PushL(bitGc);
  1.1185 +	TESTL(bitGc!=NULL);
  1.1186 +
  1.1187 +	bitGc->Clear();
  1.1188 +	bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1.1189 +	bitGc->SetPenStyle(CGraphicsContext::ENullPen);
  1.1190 +	TPoint point(0,0);	
  1.1191 +	const TSize checkerSize(aSize.iWidth/aChecksPerAxis.iWidth,aSize.iHeight/aChecksPerAxis.iHeight);
  1.1192 +	for(point.iY = 0; point.iY < aSize.iHeight; point.iY += checkerSize.iHeight)
  1.1193 +		{
  1.1194 +		TBool isBlack = ETrue;
  1.1195 +		for(point.iX = 0; point.iX < aSize.iWidth; point.iX += checkerSize.iWidth)
  1.1196 +			{
  1.1197 +			if(isBlack)
  1.1198 +				bitGc->SetBrushColor(KRgbBlack);
  1.1199 +			else 
  1.1200 +				bitGc->SetBrushColor(KRgbWhite);
  1.1201 +			TRect rect(point, checkerSize);
  1.1202 +			bitGc->DrawRect(rect);
  1.1203 +			isBlack = EFalse;
  1.1204 +			}
  1.1205 +		}	
  1.1206 +	CleanupStack::PopAndDestroy(2, bitmapDevice);
  1.1207 +	CleanupStack::Pop(bitmap);	
  1.1208 +	return bitmap;
  1.1209 +	}
  1.1210 +
  1.1211 +/**
  1.1212 +Create a bitmap designed for masking tests.
  1.1213 +@param aPixelFormat The pixel format to use when creating the bitmap
  1.1214 +@param aSize The size of the bitmap to create
  1.1215 +*/
  1.1216 +CFbsBitmap* CTDirectGdiStepBase::CreateMaskingPixmapL (
  1.1217 +		TUidPixelFormat aPixelFormat, 
  1.1218 +		const TSize& aSize)
  1.1219 +	{
  1.1220 +	
  1.1221 +	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
  1.1222 +	CleanupStack::PushL(bitmap);
  1.1223 +	TESTL(KErrNone == bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
  1.1224 +	
  1.1225 +	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
  1.1226 +	CleanupStack::PushL(bitmapDevice);
  1.1227 +	TESTL(bitmapDevice!=NULL);
  1.1228 +	
  1.1229 +	CFbsBitGc* bitGc = NULL;
  1.1230 +	bitmapDevice->CreateContext(bitGc);
  1.1231 +	CleanupStack::PushL(bitGc);
  1.1232 +	TESTL(bitGc!=NULL);
  1.1233 +	
  1.1234 +	bitGc->Clear();
  1.1235 +	bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1.1236 +	bitGc->SetPenStyle(CGraphicsContext::ENullPen);
  1.1237 +
  1.1238 +	bitGc->SetBrushColor(TRgb(0x808080));
  1.1239 +	TRect rect(aSize);
  1.1240 +	bitGc->DrawRect(rect);
  1.1241 +
  1.1242 +	bitGc->SetBrushColor(TRgb(0x202020));
  1.1243 +	TRect rect2(0, 0, aSize.iWidth, aSize.iHeight>>2);
  1.1244 +	bitGc->DrawRect(rect2);
  1.1245 +	
  1.1246 +	TRect rect3(0, 0, aSize.iWidth>>3, aSize.iHeight);
  1.1247 +	bitGc->DrawRect(rect3);
  1.1248 +
  1.1249 +	CleanupStack::PopAndDestroy(2, bitmapDevice);
  1.1250 +	CleanupStack::Pop(bitmap);
  1.1251 +	return bitmap;
  1.1252 +	}
  1.1253 +
  1.1254 +/** 
  1.1255 +Stack cleanup helper function to use when the cache needs to be reset
  1.1256 +from the cleanup stack.
  1.1257 +This method calls MVgImageCache::ResetCache() on the passed MVgImageCache object
  1.1258 +@param aPtr A pointer to an image cache object, MVgImageCache*, to be reset
  1.1259 +*/
  1.1260 +void CTDirectGdiStepBase::ResetCache(TAny* aPtr)
  1.1261 +	{
  1.1262 +	MVgImageCache* cache = reinterpret_cast <MVgImageCache*> (aPtr);
  1.1263 +	cache->ResetCache();
  1.1264 +	}
  1.1265 +
  1.1266 +/** 
  1.1267 +Stack cleanup helper function to use when the pen size needs to be reset to (1,1)
  1.1268 +from the cleanup stack. This is needed when SetPenSize() is called when testing the
  1.1269 +DirectGdi SW version as setting a pen size other then (1,1) causes memory to be
  1.1270 +created that is not freed until SetPenSize(1,1) is called (or the related graphics
  1.1271 +engine is destroyed).
  1.1272 +This method calls CTContextBase::SetPenSize(1,1) on the passed CTContextBase object
  1.1273 +@param aPtr A pointer to a test context object, CTContextBase*.
  1.1274 +*/
  1.1275 +void CTDirectGdiStepBase::ResetPenSize(TAny* aPtr)
  1.1276 +	{
  1.1277 +	if (CTContextBase* context = reinterpret_cast <CTContextBase*> (aPtr))
  1.1278 +		context->SetPenSize(TSize(1,1));
  1.1279 +	}