graphicsdeviceinterface/directgdi/test/tdirectgdi_test_step_base.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "tdirectgdi_test_step_base.h"
       
    17 #include <graphics/directgdiextensioninterfaces.h>
       
    18 
       
    19 //These reference and test bitmaps are used for image comparison
       
    20 //These are saved at
       
    21 _LIT(KRefPath, "\\img\\ref\\%S.mbm");
       
    22 _LIT(KTestPath, "\\img\\test\\%S.mbm");
       
    23 
       
    24 //The default image cache size to use for the tests.
       
    25 const TInt KDriverImageCacheSizeTests = 0x400000;
       
    26 
       
    27 /**
       
    28 Position iterator constructor.
       
    29 @param aStartX Start x position.
       
    30 @param aEndX End x position.
       
    31 @param aStepX Step for x position.
       
    32 @param aStartY Start y position.
       
    33 @param aEndY End y position.
       
    34 @param aStepY Step for y position.
       
    35 */
       
    36 TPositionIterator::TPositionIterator(TInt aStartX, TInt aEndX, TInt aStepX,
       
    37 	TInt aStartY, TInt aEndY, TInt aStepY) :
       
    38 	iStartX(aStartX), iEndX(aEndX), iStepX(aStepX),
       
    39 	iStartY(aStartY), iEndY(aEndY), iStepY(aStepY),
       
    40 	iPosX(aStartX), iPosY(aStartY), iIndexX(0), iIndexY(0)
       
    41 	{
       
    42 	}
       
    43 
       
    44 /**
       
    45 Begin iteration.
       
    46 All needed variables are initialized to start iteration.
       
    47 */
       
    48 void TPositionIterator::Begin()
       
    49 	{
       
    50 	iPosX = iStartX;
       
    51 	iPosY = iStartY;
       
    52 	iIndexX = 0;
       
    53 	iIndexY = 0;
       
    54 	}
       
    55 
       
    56 /**
       
    57 Next iteration.
       
    58 Generates next position and position indices.
       
    59 @return EFalse is returned if end of iterations else ETrue.
       
    60 */
       
    61 TBool TPositionIterator::Next()
       
    62 	{
       
    63 	if(iPosX < iEndX)
       
    64 		{
       
    65 		iPosX += iStepX;
       
    66 		iIndexX++;
       
    67 		return ETrue;
       
    68 		}
       
    69 	else
       
    70 		{
       
    71 		if(iPosY < iEndY)
       
    72 			{
       
    73 			iPosX = iStartX;
       
    74 			iIndexX = 0;
       
    75 			iPosY += iStepY;
       
    76 			iIndexY++;
       
    77 			return ETrue;
       
    78 			}
       
    79 		else
       
    80 			{
       
    81 			return EFalse;
       
    82 			}
       
    83 		}
       
    84 	}
       
    85 
       
    86 CBitmapDevice* CTImageTarget::BitmapDevice() const
       
    87 	{
       
    88 	return iBitmapDevice;
       
    89 	}
       
    90 
       
    91 /**
       
    92 Create a new bitgdi target
       
    93 @param aPixelFormat The pixel format for the target
       
    94 @param aSize The size of the target to create
       
    95 @return On return, contains a pointer to a bitgdi target object
       
    96 */
       
    97 CTBitGdiTarget*  CTBitGdiTarget::NewL(TUidPixelFormat aPixelFormat, const TSize& aSize)
       
    98 	{
       
    99 	CTBitGdiTarget* self = new(ELeave) CTBitGdiTarget();
       
   100 	CleanupStack::PushL(self);
       
   101 	self->ConstructL(aPixelFormat, aSize);
       
   102 	CleanupStack::Pop(); // self
       
   103 	return self;
       
   104 	}
       
   105 
       
   106 /**
       
   107 Second phase constructor of CTBitGdiTarget. Creates a bitmap for use as a target.
       
   108 @param aPixelFormat The pixel format for the target to be created
       
   109 @param aSize The size of the target to be created
       
   110 */
       
   111 void CTBitGdiTarget::ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize)
       
   112 	{	
       
   113 	// create a bitmap
       
   114 	iBitmap = new(ELeave) CFbsBitmap;
       
   115 	iBitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat));
       
   116 	// create an off screen bitmap device
       
   117 	iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
       
   118 	}
       
   119 
       
   120 /**
       
   121 Create a bitgdi context
       
   122 @param aGc A pointer to the created graphics context
       
   123 @param aActivate ETrue to create and activate the context aGc, EFalse to just create it.
       
   124 @return On return, contains a pointer to the created bitgdi context
       
   125 */
       
   126 TInt CTBitGdiTarget::CreateContext(CTContextBase*& aGc, TBool aActivate)
       
   127 	{
       
   128 	TInt result = KErrGeneral;
       
   129 	TRAP(result, aGc = CTBitGdiContext::NewL((CFbsBitmapDevice*)iBitmapDevice, aActivate));
       
   130    	return result;
       
   131    	}
       
   132 
       
   133 /**
       
   134 Sets the object to draw to a particular device 
       
   135 @param aGc A pointer to the created graphics context
       
   136 */
       
   137 TInt CTBitGdiTarget::Activate(CTContextBase*& aGc)
       
   138 	{
       
   139 	CTBitGdiContext* gc = (CTBitGdiContext*)aGc;
       
   140 	// Activate the context on a rendering target.
       
   141 	return gc->Activate(iBitmapDevice);
       
   142 	}
       
   143 /**
       
   144 Get the size of the device area in pixels
       
   145 @return On return, The width and height of the target, in pixels 
       
   146 */
       
   147 TSize CTBitGdiTarget::SizeInPixels() const 
       
   148 	{
       
   149 	return iBitmapDevice->SizeInPixels();
       
   150 	}
       
   151 
       
   152 
       
   153 /**
       
   154 Get a target FBsBitmap
       
   155 @return The target FBsBitmap
       
   156 */
       
   157 CFbsBitmap* CTBitGdiTarget::GetTargetFbsBitmapL()
       
   158 	{
       
   159 	return iBitmap;
       
   160 	}
       
   161 
       
   162 /**
       
   163 Nothing to be implemented for BitGdi Finish()
       
   164 */
       
   165 void CTBitGdiTarget::Finish ()
       
   166 	{
       
   167 	}
       
   168 
       
   169 
       
   170 void CTBitGdiTarget::Close() 
       
   171 	{	
       
   172 	}
       
   173 
       
   174 
       
   175 /**
       
   176 Destructor of CTBitGdiTarget
       
   177 */
       
   178 CTBitGdiTarget::~CTBitGdiTarget()
       
   179 	{
       
   180 	delete iBitmapDevice;
       
   181 	delete iBitmap;
       
   182 	}
       
   183 
       
   184 /**
       
   185 Default constructor.
       
   186 */
       
   187 CTDirectGdiTarget::CTDirectGdiTarget()
       
   188 	{
       
   189 	}
       
   190 
       
   191 /**
       
   192 Create a new directgdi target
       
   193 @param aPixelFormat The pixel format for the target
       
   194 @param aSize The size of the target to create
       
   195 @return On return, contains a pointer to a directgdi target object
       
   196 */
       
   197 CTDirectGdiTarget*  CTDirectGdiTarget::NewL(TUidPixelFormat aPixelFormat, const TSize& aSize)
       
   198 	{
       
   199 	CTDirectGdiTarget* self = new(ELeave) CTDirectGdiTarget();
       
   200 	CleanupStack::PushL(self);
       
   201 	self->ConstructL(aPixelFormat, aSize);
       
   202 	CleanupStack::Pop(); // self
       
   203 	return self;
       
   204 	}
       
   205 /**
       
   206 Second phase constructor of CTDirectGdiTarget
       
   207 @param aPixelFormat The pixel format for the target
       
   208 @param aSize The size of the target to create
       
   209 */
       
   210 void CTDirectGdiTarget::ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize)
       
   211 	{	
       
   212 	// open the driver
       
   213 	User::LeaveIfError(CDirectGdiDriver::Open());
       
   214 	iDGdiDriver = CDirectGdiDriver::Static();
       
   215 	if (iDGdiDriver == NULL)
       
   216 		User::Leave(KErrNoMemory);
       
   217 	
       
   218 	// set a large cache size (if available to do so) so the tests execute more quickly.
       
   219 	MDirectGdiDriverCacheSize* driverCacheInterface = NULL;
       
   220 	if (KErrNone == iDGdiDriver->GetInterface(TUid::Uid(KDirectGdiDriverCacheSizeUid), (TAny*&)driverCacheInterface))
       
   221 		{
       
   222 		User::LeaveIfError(driverCacheInterface->SetMaxImageCacheSize(KDriverImageCacheSizeTests));
       
   223 		}
       
   224 	
       
   225 	iDGdiImageTarget = new (ELeave) RDirectGdiImageTarget(*iDGdiDriver);
       
   226 	// create a bitmap which is used to save the image data from an RSgImage to a file.
       
   227 	iBitmap = new(ELeave) CFbsBitmap;
       
   228 	User::LeaveIfError(iBitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
       
   229 	iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
       
   230 	// Set up image attributes
       
   231 	iImageInfo.iSizeInPixels = aSize;
       
   232 	iImageInfo.iPixelFormat = aPixelFormat;
       
   233 	iImageInfo.iUsage = ESgUsageDirectGdiTarget;
       
   234 	User::LeaveIfError(iRSgImage.Create(iImageInfo, NULL,0));
       
   235 	User::LeaveIfError(iDGdiImageTarget->Create(iRSgImage));
       
   236 	}
       
   237 
       
   238 
       
   239 /**
       
   240 Create a Direct GDI graphics context.
       
   241 
       
   242 @param aGc	A reference to a pointer to the created graphics context. If return is anything 
       
   243 			other than KErrNone then aGc is set to NULL.
       
   244 @param aActivate ETrue to create and activate the context aGc, EFalse to just create it.
       
   245 
       
   246 @return KErrNone, if successful; otherwise, another of the system-wide error codes.
       
   247 */
       
   248 TInt CTDirectGdiTarget::CreateContext(CTContextBase*& aGc, TBool aActivate)
       
   249 	{	
       
   250 	TInt result = KErrGeneral;
       
   251 	
       
   252 	aGc = NULL;
       
   253 	
       
   254     TRAP(result, aGc = CTestDirectGdiContext::NewL());
       
   255     CTestDirectGdiContext* gc = (CTestDirectGdiContext*)aGc;
       
   256 
       
   257     // If the GC is not NULL, make sure the return code indicates
       
   258     // success.
       
   259     if (aActivate && aGc)
       
   260     	{
       
   261 		if(result != KErrNone)
       
   262 			{
       
   263 			return result;
       
   264 			}		
       
   265 		else
       
   266 			{
       
   267 			// Activate the context on a rendering target.
       
   268 			result = gc->Activate(*iDGdiImageTarget);
       
   269 			}
       
   270     	}	
       
   271 	return result;
       
   272 	}
       
   273 
       
   274 /**
       
   275 Sets the object to draw to a particular device 
       
   276 @param aGc A pointer to the created graphics context
       
   277 */
       
   278 TInt CTDirectGdiTarget::Activate(CTContextBase*& aGc)
       
   279 	{
       
   280     CTestDirectGdiContext* gc = (CTestDirectGdiContext*)aGc;
       
   281 	// Activate the context on a rendering target.
       
   282     return gc->Activate(*iDGdiImageTarget);
       
   283 	}
       
   284 
       
   285 /**
       
   286 Get the size of the device area in pixels
       
   287 @return On return, The width and height of the target, in pixels 
       
   288 */
       
   289 TSize CTDirectGdiTarget::SizeInPixels() const 
       
   290 	{
       
   291 	return iImageInfo.iSizeInPixels;
       
   292 	}
       
   293 
       
   294 /**
       
   295 Get a target FBsBitmap.
       
   296 @return The target FBsBitmap
       
   297 */
       
   298 CFbsBitmap* CTDirectGdiTarget::GetTargetFbsBitmapL()
       
   299 	{
       
   300 	// Create a copy of the RSgImage that is CPU-accessible for mapping.
       
   301 	RSgImage cpuAccessibleImage;
       
   302 	TSgImageInfo imageInfo;
       
   303 	imageInfo.iSizeInPixels = iImageInfo.iSizeInPixels;
       
   304 	imageInfo.iPixelFormat = iImageInfo.iPixelFormat;
       
   305 	imageInfo.iCpuAccess = ESgCpuAccessReadOnly;
       
   306 	User::LeaveIfError(cpuAccessibleImage.Create(imageInfo, iRSgImage));
       
   307 	CleanupClosePushL(cpuAccessibleImage);
       
   308 	
       
   309 	iBitmap->BeginDataAccess();
       
   310 	const TInt bitmapDataStride = iBitmap->DataStride();
       
   311 	const TInt numScanlines = imageInfo.iSizeInPixels.iHeight;
       
   312 	const TAny* sgImageDataAddress;
       
   313 	TInt sgImageDataStride = 0;
       
   314 	
       
   315 	User::LeaveIfError(cpuAccessibleImage.MapReadOnly(sgImageDataAddress, sgImageDataStride));
       
   316 
       
   317     TUint32* bitmapDataAddress = iBitmap->DataAddress();
       
   318     for (TInt scanline = 0; scanline < numScanlines; ++scanline)
       
   319     	{
       
   320     	Mem::Copy((TUint8*)bitmapDataAddress + (scanline*bitmapDataStride), (TUint8*)sgImageDataAddress + (scanline*sgImageDataStride), bitmapDataStride);
       
   321     	}
       
   322     iBitmap->EndDataAccess();
       
   323     cpuAccessibleImage.Unmap();
       
   324 
       
   325 	CleanupStack::PopAndDestroy(1);
       
   326     	
       
   327     return iBitmap;
       
   328 	}
       
   329 
       
   330 /**
       
   331 Force completion of all batched rendering operations. Will not return
       
   332 until rendering is complete.
       
   333 
       
   334 @pre	Fully initialised image target.
       
   335 */
       
   336 void CTDirectGdiTarget::Finish ()
       
   337 	{	
       
   338 	if (iDGdiDriver)
       
   339 		iDGdiDriver->Finish();
       
   340 	}
       
   341 
       
   342 
       
   343 void CTDirectGdiTarget::Close() 
       
   344 	{
       
   345 	if (iDGdiImageTarget)
       
   346 		iDGdiImageTarget->Close();
       
   347 	}
       
   348 
       
   349 /**
       
   350 Destructor of CTDirectGdiTarget
       
   351 */
       
   352 CTDirectGdiTarget::~CTDirectGdiTarget()
       
   353 	{
       
   354 	delete iBitmapDevice;
       
   355 	delete iBitmap;
       
   356 	if (iDGdiImageTarget)
       
   357 		{
       
   358 		iDGdiImageTarget->Close();	
       
   359 		delete iDGdiImageTarget;
       
   360 		}
       
   361 	if (iDGdiDriver)
       
   362 		iDGdiDriver->Close();
       
   363 	iRSgImage.Close();
       
   364 	}
       
   365 
       
   366 /**
       
   367 Implementation of CTestStep base class virtual
       
   368 It is used for doing all common initialisation to derived classes.
       
   369 Make it being able to leave 
       
   370 The leave will be picked up by the framework.
       
   371 @leave Gets system wide error code
       
   372 @return - TVerdict code
       
   373 */
       
   374 TVerdict CTDirectGdiStepBase::doTestStepPreambleL()
       
   375 	{
       
   376 	SetTestStepResult(EPass);
       
   377 	
       
   378 	// Create and install Active Scheduler in case tests require active objects
       
   379 	iScheduler = new(ELeave) CActiveScheduler;
       
   380 	CActiveScheduler::Install(iScheduler);
       
   381 	
       
   382 	TPtrC targetPixelFormatInput;
       
   383 	TPtrC sourcePixelFormatInput;
       
   384 	TPtrC sourceResourcePixelFormatInput;
       
   385 	
       
   386 	// get input for tests from .ini file
       
   387 	_LIT(KDirectgdiTestInput, "DirectgdiTestInput");
       
   388 	_LIT(KTargetPixelFormatEnums, "TargetPixelFormatEnums ");
       
   389 	_LIT(KSourcePixelFormatEnums, "SourcePixelFormatEnums ");
       
   390 	_LIT(KSourceResourcePixelFormatEnums, "SourceResourcePixelFormatEnums ");
       
   391 	_LIT(KDoRefImg, "DoRefImg");
       
   392 	_LIT(KDoDirectGdi, "DoDirectGdi");
       
   393 	_LIT(KRunOomTests, "RunOomTests");
       
   394 	TEST(GetStringFromConfig(KDirectgdiTestInput, KTargetPixelFormatEnums, targetPixelFormatInput));
       
   395 	TEST(GetStringFromConfig(KDirectgdiTestInput, KSourcePixelFormatEnums, sourcePixelFormatInput));
       
   396 	TEST(GetStringFromConfig(KDirectgdiTestInput, KSourceResourcePixelFormatEnums, sourceResourcePixelFormatInput));
       
   397 	TEST(GetIntFromConfig(KDirectgdiTestInput, KDoRefImg, iMakeRefImg));
       
   398 	TEST(GetIntFromConfig(KDirectgdiTestInput, KDoDirectGdi, iUseDirectGdi));
       
   399 	TEST(GetIntFromConfig(KDirectgdiTestInput, KRunOomTests, iDoOomTests));
       
   400 	#ifndef _DEBUG
       
   401 	if(iDoOomTests)
       
   402 		{
       
   403 		iDoOomTests = EFalse;
       
   404 		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."));
       
   405 		}
       
   406 	#endif
       
   407 
       
   408 	ConvertPixelFormats(targetPixelFormatInput, iTargetPixelFormatArray);
       
   409 	ConvertPixelFormats(sourcePixelFormatInput, iSourcePixelFormatArray);
       
   410 	ConvertPixelFormats(sourceResourcePixelFormatInput, iSourceResourcePixelFormatArray);
       
   411 	iRunningOomTests = EFalse;
       
   412 
       
   413 	Logger().ShareAuto();
       
   414 
       
   415 	__UHEAP_MARK;		
       
   416 	User::LeaveIfError(SgDriver::Open());
       
   417 	User::LeaveIfError(RFbsSession::Connect());	
       
   418 		
       
   419 	return TestStepResult();
       
   420 	}
       
   421 
       
   422 /**
       
   423 Convert the pixel format strings to pixel format enums
       
   424 @param aPixelFormatInput The pixel format string for testing
       
   425 @param aPixelFormatArray The array of converted pixel formats is returned here
       
   426 */
       
   427 void CTDirectGdiStepBase::ConvertPixelFormats(TPtrC aPixelFormatInput, RArray<TUidPixelFormat>& aPixelFormatArray)
       
   428 	{
       
   429 	TPtrC tempBuf = aPixelFormatInput;
       
   430 	TInt position = tempBuf.Find(_L(","));
       
   431 			
       
   432 	while(KErrNotFound != position)
       
   433 		{
       
   434 		aPixelFormatArray.Append(TDisplayModeMapping::ConvertPixelFormatStringToPixelFormat(tempBuf.Left(position)));
       
   435 		tempBuf.Set(tempBuf.Mid(position + 2));
       
   436 		position = tempBuf.Find(_L(","));
       
   437 		}	
       
   438 
       
   439 	if (position == KErrNotFound)
       
   440 		{
       
   441 		aPixelFormatArray.Append(TDisplayModeMapping::ConvertPixelFormatStringToPixelFormat(tempBuf));
       
   442 		}
       
   443 	}
       
   444 
       
   445 /**
       
   446 Implementation of CTestStep base class virtual
       
   447 It is used for doing all after test treatment common to derived classes in here.
       
   448 Make it being able to leave
       
   449 The leave will be picked up by the framework.
       
   450 @leave Gets system wide error code
       
   451 @return - TVerdict
       
   452 */
       
   453  TVerdict CTDirectGdiStepBase::doTestStepPostambleL()
       
   454 	{
       
   455 	if(iFontStore)
       
   456 		{
       
   457 		if(iFontId)
       
   458 			{
       
   459 			iFontStore->RemoveFile(iFontId);
       
   460 			iFontId = 0;
       
   461 			}
       
   462 		delete iFontStore;
       
   463 		iFontStore = NULL;
       
   464 		}
       
   465 	delete iGc;
       
   466 	iGc = NULL;
       
   467 	delete iGc2;
       
   468 	iGc2 = NULL;
       
   469 	delete iGdiTarget;
       
   470 	iGdiTarget = NULL;
       
   471 	delete iGdiTarget2;
       
   472 	iGdiTarget2 = NULL;	
       
   473 	SgDriver::Close();
       
   474 	RFbsSession::Disconnect();
       
   475 	__UHEAP_MARKEND;
       
   476 	delete iScheduler;
       
   477 	iScheduler = NULL;
       
   478 	return TestStepResult();
       
   479 	}
       
   480 
       
   481 CTDirectGdiStepBase::~CTDirectGdiStepBase()
       
   482 	{
       
   483 	if(iFontStore)
       
   484 		{
       
   485 		if(iFontId)
       
   486 			{
       
   487 			iFontStore->RemoveFile(iFontId);			
       
   488 			}
       
   489 		delete iFontStore;
       
   490 		}
       
   491 	delete iScheduler;
       
   492 	delete iGc;
       
   493 	delete iGc2;
       
   494 	delete iGdiTarget;
       
   495 	delete iGdiTarget2;
       
   496 	iTargetPixelFormatArray.Close();
       
   497 	iSourcePixelFormatArray.Close();
       
   498 	iSourceResourcePixelFormatArray.Close();
       
   499 	}
       
   500 
       
   501 CTDirectGdiStepBase::CTDirectGdiStepBase()
       
   502 	{
       
   503 	}
       
   504 
       
   505 /**
       
   506 Create a name in the format of <TestImage / RefImage>_< TestCase Name >_<DisplayModeName>_<Orientation>_<PostFix(optional)>
       
   507 @param aParams A structure object of parameters to be passed through
       
   508 @param aTestName The test name to be generated 
       
   509 @param aTestCaseName The test case name passed in, to be used in the resultant filename
       
   510 @param aNamePostfix If this is not NULL, it is appended to filename with an underscore in front of it
       
   511 */
       
   512 void CTDirectGdiStepBase::CreateFileName(TTestParams& aParams, TDes& aTestName, TPtrC& aTestCaseName, TDesC* aNamePostfix)
       
   513 	{	
       
   514 	if (iUseDirectGdi)
       
   515 		{
       
   516 		aTestName.Append(KDirectGc);
       
   517 		}
       
   518 	else
       
   519 		{
       
   520 		aTestName.Append(KBitGc);		
       
   521 		}
       
   522 	
       
   523 	if (aParams.iDoCompressed)
       
   524 		{
       
   525 		aTestName.Append(KSeparator);	
       
   526 		aTestName.Append(KCom);
       
   527 		}
       
   528 
       
   529 	aTestName.Append(KSeparator);	
       
   530 	aTestName.Append(aTestCaseName);
       
   531 	aTestName.Append(KSeparator);
       
   532 	aTestName.Append(KTargetString);
       
   533 	aTestName.Append(KSeparator);
       
   534 	aTestName.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(aParams.iTargetPixelFormat));
       
   535 	
       
   536 	if (aNamePostfix)
       
   537 		{
       
   538 		aTestName.Append(KSeparator);
       
   539 		aTestName.Append(*aNamePostfix);
       
   540 		}
       
   541 	}
       
   542 
       
   543 /**
       
   544 @see DisplayTargetImageL(TUidPixelFormat, CTImageTarget*)
       
   545  */
       
   546 void CTDirectGdiStepBase::DisplayTargetImageL(TUidPixelFormat aPixelFormat)
       
   547 	{
       
   548 	DisplayTargetImageL(aPixelFormat, iGdiTarget);
       
   549 	}
       
   550 
       
   551 /**
       
   552 Bitblt an image to screen
       
   553 @param aPixelFormat The pixel format for tests
       
   554 @param aGdiTarget The target image to blit
       
   555 */
       
   556 void CTDirectGdiStepBase::DisplayTargetImageL(TUidPixelFormat aPixelFormat, CTImageTarget* aGdiTarget)
       
   557 	{
       
   558 	// Ensure the image has been completly rendered.
       
   559 	aGdiTarget->Finish();
       
   560 	CFbsScreenDevice* screenDevice = CFbsScreenDevice::NewL(_L("scdv"), TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat));
       
   561 	TEST(screenDevice!=NULL);
       
   562 	CleanupStack::PushL(screenDevice);
       
   563 	
       
   564 	CFbsBitGc* bitGc;
       
   565 	screenDevice->CreateContext(bitGc);
       
   566 	TEST(bitGc!=NULL);
       
   567 	CleanupStack::PushL(bitGc);
       
   568 
       
   569  	TPoint startPoint = TPoint(0, 0);
       
   570 	bitGc->Clear();
       
   571 	bitGc->BitBlt(startPoint, aGdiTarget->GetTargetFbsBitmapL()); 		
       
   572 	screenDevice->Update();
       
   573 
       
   574 	CleanupStack::PopAndDestroy(2, screenDevice);	
       
   575 	}
       
   576 
       
   577 /**
       
   578 Initialises a target (or targets) and a graphics context (or contexts), depending on the value passed in aCase.
       
   579 Deletes the previously used target(s) and context(s).
       
   580 @param aPixelFormat The pixel format to be applied
       
   581 @param aCase The type of test that this target is for, for example when testing with one context and two targets
       
   582 this could be EOneContextTwoTargets_SamePixelType, the default value is EOneContextOneTarget.
       
   583 @param aSize The size of the target(s) to be created
       
   584 */
       
   585 void CTDirectGdiStepBase::SetTargetL(TUidPixelFormat aPixelFormat, const TContextTestCase aCase, const TSize& aSize)
       
   586 	{
       
   587 	if(!iRunningOomTests)
       
   588 		{
       
   589 		TBuf<KPixelFormatNameLength> pixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(aPixelFormat));
       
   590 		INFO_PRINTF4(_L("SetTarget (using off screen bitmap): %S %dx%d"), &pixelFormatName, aSize.iWidth, aSize.iHeight);
       
   591 		}
       
   592 	
       
   593 	delete iGc;
       
   594 	iGc = NULL;	
       
   595 	delete iGc2;
       
   596 	iGc2 = NULL;	
       
   597 	delete iGdiTarget;
       
   598 	iGdiTarget = NULL;
       
   599 	delete iGdiTarget2;
       
   600 	iGdiTarget2 = NULL;
       
   601 	TUidPixelFormat aPixelFormat2 = aPixelFormat;
       
   602 	switch(aPixelFormat)
       
   603 		{
       
   604 		case EUidPixelFormatRGB_565:
       
   605 			aPixelFormat2 = EUidPixelFormatARGB_8888_PRE;
       
   606 			break;			
       
   607 		case EUidPixelFormatARGB_8888_PRE:	
       
   608 			aPixelFormat2 = EUidPixelFormatXRGB_8888;	
       
   609 			break;			
       
   610 		case EUidPixelFormatXRGB_8888:		
       
   611 			aPixelFormat2 = EUidPixelFormatRGB_565;	
       
   612 			break;
       
   613 		}	
       
   614 		
       
   615 	switch(aCase)
       
   616 		{
       
   617 		case EOneContextOneTarget:				
       
   618 			{
       
   619 			if(iUseDirectGdi)
       
   620 				{
       
   621 				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
       
   622 				}
       
   623 			else
       
   624 				{
       
   625 				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
       
   626 				}
       
   627 			User::LeaveIfError(iGdiTarget->CreateContext(iGc));	
       
   628 			}
       
   629 			break;
       
   630 		case EOneContextTwoTargets_SamePixelType:
       
   631 			{			
       
   632 			if(iUseDirectGdi)
       
   633 				{
       
   634 				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
       
   635 				iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
       
   636 				}
       
   637 			else
       
   638 				{
       
   639 				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
       
   640 				iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat, aSize);		
       
   641 				}
       
   642 			User::LeaveIfError(iGdiTarget->CreateContext(iGc));				
       
   643 			}
       
   644 			break;
       
   645 		case EOneContextTwoTargets_DifferentPixelType:
       
   646 			{	
       
   647 			if(iUseDirectGdi)
       
   648 				{
       
   649 				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
       
   650 				iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat2, aSize);		
       
   651 				}
       
   652 			else
       
   653 				{
       
   654 				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
       
   655 				iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat2, aSize);		
       
   656 				}
       
   657 			User::LeaveIfError(iGdiTarget->CreateContext(iGc));				
       
   658 			}
       
   659 			break;
       
   660 		case ETwoContextsOneTarget:
       
   661 			{
       
   662 			if(iUseDirectGdi)
       
   663 				{
       
   664 				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
       
   665 				}
       
   666 			else
       
   667 				{
       
   668 				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
       
   669 				}
       
   670 			User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse));	
       
   671 			User::LeaveIfError(iGdiTarget->CreateContext(iGc2, EFalse));		
       
   672 			}		
       
   673 			break;
       
   674 		case ETwoContextsTwoTargets_WithoutSharing_SamePixelType:
       
   675 		case ETwoContextsTwoTargets_WithSharing_SamePixelType:
       
   676 			{
       
   677 			if(iUseDirectGdi)
       
   678 				{
       
   679 				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
       
   680 				iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
       
   681 				}
       
   682 			else
       
   683 				{
       
   684 				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
       
   685 				iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat, aSize);
       
   686 				}
       
   687 			User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse));	
       
   688 			User::LeaveIfError(iGdiTarget2->CreateContext(iGc2, EFalse));	
       
   689 			}
       
   690 			break;
       
   691 		case ETwoContextsTwoTargets_WithoutSharing_DifferentPixelType:
       
   692 		case ETwoContextsTwoTargets_WithSharing_DifferentPixelType:
       
   693 			{
       
   694 			if(iUseDirectGdi)
       
   695 				{
       
   696 				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
       
   697 				iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat2, aSize);		
       
   698 				}
       
   699 			else
       
   700 				{
       
   701 				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
       
   702 				iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat2, aSize);
       
   703 				}
       
   704 			User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse));	
       
   705 			User::LeaveIfError(iGdiTarget2->CreateContext(iGc2, EFalse));	
       
   706 			}
       
   707 			break;									
       
   708 		case EOneContextOneTarget_TwiceActivate:
       
   709 			{
       
   710 			if(iUseDirectGdi)
       
   711 				{
       
   712 				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
       
   713 				}
       
   714 			else
       
   715 				{
       
   716 				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
       
   717 				}
       
   718 			User::LeaveIfError(iGdiTarget->CreateContext(iGc));	
       
   719 			}
       
   720 			break;		
       
   721 		}	
       
   722 
       
   723 	// setup font store
       
   724 	if(iFontStore)
       
   725 		{
       
   726 		if(iFontId)
       
   727 			{
       
   728 			iFontStore->RemoveFile(iFontId);
       
   729 			iFontId = 0;
       
   730 			}
       
   731 		delete iFontStore;
       
   732 		iFontStore = NULL;
       
   733 		}
       
   734 	
       
   735 	iFontStore = CFbsTypefaceStore::NewL(iGdiTarget->BitmapDevice());
       
   736 
       
   737 	_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr");
       
   738 	TESTL(KErrNone == iFontStore->AddFile(KEonFontFileName, iFontId));
       
   739 	
       
   740 	// Reset VGImage cache - OpenVG DirectGDI only
       
   741 	iVgImageCache = NULL;
       
   742 	if (iUseDirectGdi)
       
   743 		{
       
   744 		TInt err = iGc->GetInterface(TUid::Uid(KDirectGdiVgImageCacheUid), (TAny*&) iVgImageCache);
       
   745 		if (KErrNotSupported == err)
       
   746 			{
       
   747 			// Must be using software DirectGDI as this does not have a VGImage cache
       
   748 			iUseSwDirectGdi = ETrue;
       
   749 			}
       
   750 		}
       
   751 	}
       
   752 
       
   753 /**
       
   754 Get a font by looking for it in the font store. Only gets "DejaVu Sans Mono" at the moment.
       
   755 @return Returns a pointer to the "DejaVu Sans Mono" font if it is found in the font store, returns NULL if it not found.
       
   756 */
       
   757 CFont* CTDirectGdiStepBase::GetFont()
       
   758 	{
       
   759 	_LIT(KFontFamily, "DejaVu Sans Mono");
       
   760 
       
   761 	CFont* font = NULL;
       
   762 	TFontSpec spec(KFontFamily, 13);
       
   763 	iFontStore->GetNearestFontInPixels(font, spec);
       
   764 	return font;
       
   765 	}
       
   766 
       
   767 /**
       
   768 Releases the passed font in the font store.
       
   769 @param aFont A pointer to the font to be released.
       
   770  */
       
   771 void CTDirectGdiStepBase::ReleaseFont(CFont* aFont)
       
   772 	{
       
   773 	if(aFont && iFontStore)
       
   774 		{
       
   775 		iFontStore->ReleaseFont(aFont);
       
   776 		}
       
   777 	}
       
   778 
       
   779 /**
       
   780 Create a file and save the target image to the file with a filename created from aTestCaseName and aNamePostfix
       
   781 @param aParams A structure object of parameters to be passed through
       
   782 @param aTestCaseName The name of the test case
       
   783 @param aImageTarget The image target to be written out to the file
       
   784 @param aNamePostfix A postfix to be appended to the test case name
       
   785 @see CreateFileName()
       
   786 @return KErrNone if successful, one of the system wide error codes otherwise
       
   787 */
       
   788 TInt CTDirectGdiStepBase::WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, CTImageTarget* aImageTarget, TDesC* aNamePostfix)
       
   789 	{
       
   790 	// Finish is called for the OOM tests as well as the normal tests as it is responsible for
       
   791 	// clearing up the pending image array. Images get left in the array and cause the OOM tests
       
   792 	// for DrawResource to fail if Finish is not called.
       
   793 	aImageTarget->Finish();
       
   794 	
       
   795 	if(!iRunningOomTests) // don't want to save test images when running our of memory twsts
       
   796 		{
       
   797 		TBuf<KFileNameLength> testFileName;
       
   798 		CreateFileName(aParams, testFileName, aTestCaseName, aNamePostfix);
       
   799 		TFileName mbmFile;
       
   800 		TBuf<KFileNameLength> testPathName;
       
   801 		#ifdef __WINS__
       
   802 			testPathName.Append(_L("c:"));
       
   803 		#else
       
   804 			testPathName.Append(_L("e:"));
       
   805 		#endif
       
   806 	
       
   807 		if (iMakeRefImg)
       
   808 			{
       
   809 			testPathName.Append(KRefPath);
       
   810 			mbmFile.Format(testPathName, &testFileName);
       
   811 			}
       
   812 		else
       
   813 			{
       
   814 			testPathName.Append(KTestPath);
       
   815 			mbmFile.Format(testPathName, &testFileName);
       
   816 			}
       
   817 		INFO_PRINTF1(testFileName);
       
   818 		
       
   819 		CFbsBitmap* targetBitmap = NULL;
       
   820 		TRAPD(err, targetBitmap = aImageTarget->GetTargetFbsBitmapL());
       
   821 		return (err != KErrNone) ? err : targetBitmap->Save(mbmFile);		
       
   822 		}
       
   823 	return KErrNone;
       
   824 	}
       
   825 
       
   826 /**
       
   827 Create a file and save the current target image to the file with a filename created from aTestCaseName and aNamePostfix
       
   828 @param aParams A structure object of parameters to be passed through
       
   829 @param aTestCaseName The name of the test case
       
   830 @param aNamePostfix A postfix to be appended to the test case name
       
   831 @see CreateFileName()
       
   832 @return KErrNone if successful, one of the system wide error codes otherwise
       
   833 */
       
   834 TInt CTDirectGdiStepBase::WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, TDesC* aNamePostfix)
       
   835 	{
       
   836 	return WriteTargetOutput(aParams, aTestCaseName, iGdiTarget, aNamePostfix);
       
   837 	}
       
   838 
       
   839 /**
       
   840 Reset the graphics context
       
   841 */
       
   842 void CTDirectGdiStepBase::ResetGc()
       
   843 	{
       
   844 	iGc->Reset();
       
   845 	iGc->Clear();
       
   846 	}
       
   847 
       
   848 /**
       
   849 Compares the target image pixel by pixel against the given colour. If a pixel with a  
       
   850 different colour than aColour is found then the test will fail, otherwise the test will pass.
       
   851 @param aColour A colour rgba value to find.
       
   852 @return ETrue if test passed or EFalse if test failed.
       
   853 */
       
   854 TBool CTDirectGdiStepBase::TestTargetL(const TRgb& aColour)
       
   855 	{
       
   856 	iGdiTarget->Finish();
       
   857 		
       
   858 	CFbsBitmap* bitmap = iGdiTarget->GetTargetFbsBitmapL();
       
   859 	TInt width = bitmap->SizeInPixels().iWidth;
       
   860 	TInt height = bitmap->SizeInPixels().iHeight;
       
   861 
       
   862 	HBufC8* lineBuf = HBufC8::NewLC(width*4);
       
   863 	TPtr8 linePtr(lineBuf->Des());
       
   864 
       
   865 	TBool pass = ETrue;
       
   866 
       
   867 	for(TInt line=0; line<height; line++)
       
   868 		{
       
   869 		bitmap->GetScanLine(linePtr, TPoint(0, line), width, EColor16MA);
       
   870 
       
   871 		const TUint8* pPtr = linePtr.Ptr();
       
   872 		for(TInt x=0; x<width; x++)
       
   873 			{
       
   874 			// EColor16MA pixel representation is 32-bit BGRA
       
   875 			TRgb pColour(pPtr[2], pPtr[1], pPtr[0], pPtr[3]);
       
   876 			pPtr += 4;
       
   877 			
       
   878 			if (iTestParams.iTargetPixelFormat == EUidPixelFormatXRGB_8888)
       
   879 				{
       
   880 				if ((pColour.Value() & 0xFFFFFF) != (aColour.Value() & 0xFFFFFF))
       
   881 					{
       
   882 					pass = EFalse;
       
   883 					break; // break inner loop
       
   884 					}
       
   885 				}
       
   886 			else if(pColour != aColour)
       
   887 				{
       
   888 				pass = EFalse;
       
   889 				break; // break inner loop
       
   890 				}
       
   891 			}
       
   892 
       
   893 		if(!pass)
       
   894 			break; // break outer loop if test failed in inner loop
       
   895 		}
       
   896 
       
   897 	CleanupStack::PopAndDestroy(lineBuf);
       
   898 
       
   899 	return pass;
       
   900 	}
       
   901 
       
   902 /**
       
   903 Checks the graphics context for the passed error codes and logs an error if the codes do not match. 
       
   904 If the tests are running using DirectGdi then aDirectGdiErrorCode is checked against the current error in the
       
   905 graphics context, if the tests are running using BitGdi then aBitGdiErrorCode is checked against the current 
       
   906 error in the graphics context.
       
   907 @param aDirectGdiErrorCode The DirectGdi error code to check when the tests are running using DirectGdi
       
   908 @param aBitGdiErrorCode The BitGdi error code to check when the tests are running using BitGdi
       
   909 @param aFile The filename to use when reporting the error
       
   910 @param aLine The line number to use when reporting the error
       
   911 */
       
   912 void CTDirectGdiStepBase::CheckErrorsL(TInt aDirectGdiErrorCode, TInt aBitGdiErrorCode, const TText8* aFile, TInt aLine)
       
   913 	{
       
   914 	if(iUseDirectGdi)
       
   915 		{
       
   916 		TESTWITHFILENAMEANDLINENUMBERL(iGc->GetError() == aDirectGdiErrorCode, aFile, aLine);
       
   917 		}
       
   918 	else
       
   919 		{
       
   920 		TESTWITHFILENAMEANDLINENUMBERL(iGc->GetError() == aBitGdiErrorCode, aFile, aLine);
       
   921 		}
       
   922 	}
       
   923 
       
   924 /**
       
   925 Derived classes should override this method and add their calls to individual test cases in
       
   926 the overridden version.
       
   927 */
       
   928 void CTDirectGdiStepBase::RunTestsL()
       
   929 	{
       
   930 	}
       
   931 
       
   932 /**
       
   933 Runs the tests in RunTestsL checking for Out of Memory conditions and testing for memory leaks.
       
   934 */
       
   935 void CTDirectGdiStepBase::RunOomTestsL()
       
   936 	{
       
   937 	if (!iDoOomTests)
       
   938 		{
       
   939 		// don't run the out of memory tests
       
   940 		return;
       
   941 		}
       
   942 	TInt tryCount = 0;
       
   943 	INFO_PRINTF1(_L("*****Running Out Of Memory Tests*****"));
       
   944 	
       
   945 	// save the current state of test step results
       
   946 	TVerdict currentTestStepResult = TestStepResult();
       
   947 
       
   948 	FOREVER
       
   949 		{		
       
   950 		iRunningOomTests = ETrue;
       
   951 		TInt err = KErrNone;
       
   952 		
       
   953 		// count cells so we can know how many we leaked
       
   954 		TInt cellsStart = User::CountAllocCells();
       
   955 		
       
   956 		__UHEAP_FAILNEXT(++tryCount);
       
   957 		__UHEAP_MARK;
       
   958 		
       
   959 		TRAP(err, RunTestsL());
       
   960 
       
   961 		TBool finishedCorrectly = EFalse;
       
   962 		if ((err == KErrNone))
       
   963 			{
       
   964 			// claims to have finished correctly, and we're not failing every alloc
       
   965 			finishedCorrectly = CheckForHeapFailNext();
       
   966 			}		
       
   967 		__UHEAP_RESET;
       
   968 		TInt cellsEnd = User::CountAllocCells();
       
   969 		if (cellsStart < cellsEnd)
       
   970 			{
       
   971 			// leaked.
       
   972 			TInt leakedCells = cellsEnd - cellsStart;
       
   973 			ERR_PRINTF3(_L("On loop number %d we leaked %d cells. About to cause panic."),tryCount,leakedCells);				
       
   974 			}
       
   975 		__UHEAP_MARKEND;
       
   976 		
       
   977 		// check to see if we finished all OOM testing successfully
       
   978 		if ((err == KErrNone) && finishedCorrectly)
       
   979 			{
       
   980 			INFO_PRINTF2(_L(" - Test completed successfully after %d iterations."),tryCount);
       
   981 			break;
       
   982 			}
       
   983 		}
       
   984 	// restore test step result and ignore any test failures the out of memory tests produce
       
   985 	SetTestStepResult(currentTestStepResult);
       
   986 	iRunningOomTests = EFalse;
       
   987 	}
       
   988 
       
   989 /**
       
   990 Tests that the passed condition aCondition is equal to ETrue and reports an error if it is not.
       
   991 This method does not report errors when the tests are running in OOM mode.
       
   992 @see testBooleanTrue()
       
   993 @param aCondition The boolean value to be checked for being equal to ETrue
       
   994 @param aFile The filename to use when reporting the error
       
   995 @param aLine The line number to use when reporting the error
       
   996 */
       
   997 void CTDirectGdiStepBase::testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine) 
       
   998 	{
       
   999 	if(!iRunningOomTests)
       
  1000 		{
       
  1001 		CTestStep::testBooleanTrue(aCondition, aFile, aLine, ETrue);
       
  1002 		}
       
  1003 	}
       
  1004 
       
  1005 /**
       
  1006 A leaving version of testBooleanTrue().
       
  1007 @see testBooleanTrue()
       
  1008 */
       
  1009 void CTDirectGdiStepBase::testBooleanTrueL(TBool aCondition, const TText8* aFile, TInt aLine) 
       
  1010 	{
       
  1011 	if(!iRunningOomTests)
       
  1012 		{
       
  1013 		CTestStep::testBooleanTrueL(aCondition, aFile, aLine, ETrue);
       
  1014 		}
       
  1015 	else
       
  1016 		{
       
  1017 		if(!aCondition)
       
  1018 			{
       
  1019 			User::Leave(TEST_ERROR_CODE);
       
  1020 			}
       
  1021 		}
       
  1022 	}
       
  1023 
       
  1024 /**
       
  1025 A version of testBooleanTrue() that additionally writes an error code to the output if aCondition is not equal to ETrue.
       
  1026 @see testBooleanTrue()
       
  1027 @param aCondition The boolean value to be checked for being equal to ETrue
       
  1028 @param aErrorCode An error code to be reported if aCondition is EFalse
       
  1029 @param aFile The filename to use when reporting the error
       
  1030 @param aLine The line number to use when reporting the error
       
  1031 */
       
  1032 void CTDirectGdiStepBase::testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine)
       
  1033 	{
       
  1034 	if(!iRunningOomTests)
       
  1035 		{
       
  1036 		if(!aCondition)			
       
  1037 			{
       
  1038 			SetTestStepResult(EFail);
       
  1039 			_LIT(KMessage,"Test Failed with error [%d]");
       
  1040 			Logger().LogExtra(aFile, aLine, ESevrErr, KMessage, aErrorCode);
       
  1041 			}
       
  1042 		}
       
  1043 	}
       
  1044 
       
  1045 /**
       
  1046 A leaving version of testBooleanTrueWithErrorCode()
       
  1047 @see testBooleanTrueWithErrorCode()
       
  1048 @param aCondition The boolean value to be checked for being equal to ETrue
       
  1049 @param aErrorCode An error code to be reported if aCondition is EFalse
       
  1050 @param aFile The filename to use when reporting the error
       
  1051 @param aLine The line number to use when reporting the error
       
  1052 */
       
  1053 void CTDirectGdiStepBase::testBooleanTrueWithErrorCodeL(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine)
       
  1054 	{
       
  1055 	if(!iRunningOomTests)
       
  1056 		{
       
  1057 		testBooleanTrueWithErrorCode(aCondition, aErrorCode, aFile, aLine);
       
  1058 		}
       
  1059 	else
       
  1060 		{
       
  1061 		if(!aCondition)
       
  1062 			{
       
  1063 			User::Leave(aErrorCode);
       
  1064 			}
       
  1065 		}
       
  1066 	}
       
  1067 
       
  1068 /**
       
  1069 Creates a CFbsBitmap that has a pattern of differently coloured concentric rectangles on it for use in test cases.
       
  1070 @param aPixelFormat The pixel format for create the target bitmap
       
  1071 @param aSize The size of the bitmap to be created
       
  1072 */
       
  1073 CFbsBitmap* CTDirectGdiStepBase::CreateConcentricRectsBitmapL(TUidPixelFormat aPixelFormat, const TSize& aSize)
       
  1074 	{
       
  1075 	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
  1076 	CleanupStack::PushL(bitmap);
       
  1077 
       
  1078 	TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
       
  1079 
       
  1080 	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
       
  1081 	TESTL(bitmapDevice!=NULL);
       
  1082 	CleanupStack::PushL(bitmapDevice);
       
  1083 	
       
  1084 	CFbsBitGc* bitGc = NULL;
       
  1085 	User::LeaveIfError(bitmapDevice->CreateContext(bitGc));
       
  1086 	TESTL(bitGc!=NULL);
       
  1087 	CleanupStack::PushL(bitGc);
       
  1088 
       
  1089 	for (TInt i = aSize.iWidth/2; i>0; --i)
       
  1090 		{
       
  1091 		bitGc->SetPenColor(KColor16Table[i%16]);	
       
  1092 		bitGc->DrawRect(TRect(i,i,aSize.iWidth - i, aSize.iHeight - i));
       
  1093 		}
       
  1094 
       
  1095 	CleanupStack::PopAndDestroy(2, bitmapDevice);
       
  1096 	CleanupStack::Pop(bitmap);
       
  1097 	
       
  1098 	return bitmap;
       
  1099 	}
       
  1100 
       
  1101 /**
       
  1102 Creates a bitmap that contains a checked board pattern of coloured rectangles for use in test cases.
       
  1103 @param aPixelFormat The pixel format for create the target bitmap
       
  1104 @param aSize The size of the bitmap
       
  1105 @param aChecksPerAxis Number of checks on X and Y.
       
  1106 @param aGenAlpha If ETrue then generate pattern in alpha channel.
       
  1107 */
       
  1108 CFbsBitmap* CTDirectGdiStepBase::CreateCheckedBoardBitmapL(TUidPixelFormat aPixelFormat,
       
  1109 		const TSize& aSize, const TSize& aChecksPerAxis, TBool aGenAlpha)
       
  1110 	{
       
  1111 	
       
  1112 	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
  1113 	CleanupStack::PushL(bitmap);
       
  1114 	TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
       
  1115 	
       
  1116 	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
       
  1117 	CleanupStack::PushL(bitmapDevice);
       
  1118 	TESTL(bitmapDevice!=NULL);
       
  1119 	
       
  1120 	CFbsBitGc* bitGc = NULL;
       
  1121 	User::LeaveIfError(bitmapDevice->CreateContext(bitGc));
       
  1122 	CleanupStack::PushL(bitGc);
       
  1123 	TESTL(bitGc!=NULL);
       
  1124 	
       
  1125 	bitGc->Clear();
       
  1126 	bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  1127 	bitGc->SetPenStyle(CGraphicsContext::ENullPen);
       
  1128 	if(aGenAlpha)
       
  1129 		{
       
  1130 		bitGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
  1131 		}
       
  1132 	TPoint point(0,0);
       
  1133 	const TSize checkerSize(aSize.iWidth/aChecksPerAxis.iWidth,aSize.iHeight/aChecksPerAxis.iHeight);
       
  1134 	TInt brushColour = 0x00;
       
  1135 	for(point.iY = 0; point.iY < aSize.iHeight; point.iY += checkerSize.iHeight)
       
  1136 		{
       
  1137 		for(point.iX = 0; point.iX < aSize.iWidth; point.iX += checkerSize.iWidth)
       
  1138 			{
       
  1139 			TRgb colour = KColor16Table[brushColour++ & 0x0F];
       
  1140 			if(aGenAlpha)
       
  1141 				{
       
  1142 				// Note that this is converted internally to pre-multiplied alpha
       
  1143 				// for pre-multiplied alpha targets.
       
  1144 				colour.SetAlpha((brushColour*5) & 255);
       
  1145 				
       
  1146 				//Use the following line to simplify test for manual verification.
       
  1147 				//colour.SetAlpha(0x80);
       
  1148 				}
       
  1149 			bitGc->SetBrushColor(colour);
       
  1150 			TRect rect(point, checkerSize);
       
  1151 			bitGc->DrawRect(rect);
       
  1152 			}
       
  1153 		}
       
  1154 	CleanupStack::PopAndDestroy(2, bitmapDevice);
       
  1155 	CleanupStack::Pop(bitmap);
       
  1156 	
       
  1157 	return bitmap;
       
  1158 	}
       
  1159 
       
  1160 /**
       
  1161 Create a black and white checked bitmap
       
  1162 @param aPixelFormat The pixel format to use when creating the target bitmap
       
  1163 @param aSize The size of the bitmap to create
       
  1164 @param aChecksPerAxis Number of checks to draw in the X and Y directions
       
  1165 @param aIsHardwareBitmap If ETrue, creates a hardware CFbsBitmap.
       
  1166 */
       
  1167 CFbsBitmap* CTDirectGdiStepBase::CreateBlackWhiteBitmapL(TUidPixelFormat aPixelFormat,
       
  1168 		const TSize& aSize, const TSize& aChecksPerAxis)
       
  1169 	{
       
  1170 	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
  1171 	CleanupStack::PushL(bitmap);
       
  1172 	
       
  1173 	TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
       
  1174 	
       
  1175 	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
       
  1176 	CleanupStack::PushL(bitmapDevice);
       
  1177 	TESTL(bitmapDevice!=NULL);
       
  1178 
       
  1179 	CFbsBitGc* bitGc = NULL;
       
  1180 	bitmapDevice->CreateContext(bitGc);
       
  1181 	CleanupStack::PushL(bitGc);
       
  1182 	TESTL(bitGc!=NULL);
       
  1183 
       
  1184 	bitGc->Clear();
       
  1185 	bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  1186 	bitGc->SetPenStyle(CGraphicsContext::ENullPen);
       
  1187 	TPoint point(0,0);	
       
  1188 	const TSize checkerSize(aSize.iWidth/aChecksPerAxis.iWidth,aSize.iHeight/aChecksPerAxis.iHeight);
       
  1189 	for(point.iY = 0; point.iY < aSize.iHeight; point.iY += checkerSize.iHeight)
       
  1190 		{
       
  1191 		TBool isBlack = ETrue;
       
  1192 		for(point.iX = 0; point.iX < aSize.iWidth; point.iX += checkerSize.iWidth)
       
  1193 			{
       
  1194 			if(isBlack)
       
  1195 				bitGc->SetBrushColor(KRgbBlack);
       
  1196 			else 
       
  1197 				bitGc->SetBrushColor(KRgbWhite);
       
  1198 			TRect rect(point, checkerSize);
       
  1199 			bitGc->DrawRect(rect);
       
  1200 			isBlack = EFalse;
       
  1201 			}
       
  1202 		}	
       
  1203 	CleanupStack::PopAndDestroy(2, bitmapDevice);
       
  1204 	CleanupStack::Pop(bitmap);	
       
  1205 	return bitmap;
       
  1206 	}
       
  1207 
       
  1208 /**
       
  1209 Create a bitmap designed for masking tests.
       
  1210 @param aPixelFormat The pixel format to use when creating the bitmap
       
  1211 @param aSize The size of the bitmap to create
       
  1212 */
       
  1213 CFbsBitmap* CTDirectGdiStepBase::CreateMaskingPixmapL (
       
  1214 		TUidPixelFormat aPixelFormat, 
       
  1215 		const TSize& aSize)
       
  1216 	{
       
  1217 	
       
  1218 	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
  1219 	CleanupStack::PushL(bitmap);
       
  1220 	TESTL(KErrNone == bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
       
  1221 	
       
  1222 	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
       
  1223 	CleanupStack::PushL(bitmapDevice);
       
  1224 	TESTL(bitmapDevice!=NULL);
       
  1225 	
       
  1226 	CFbsBitGc* bitGc = NULL;
       
  1227 	bitmapDevice->CreateContext(bitGc);
       
  1228 	CleanupStack::PushL(bitGc);
       
  1229 	TESTL(bitGc!=NULL);
       
  1230 	
       
  1231 	bitGc->Clear();
       
  1232 	bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  1233 	bitGc->SetPenStyle(CGraphicsContext::ENullPen);
       
  1234 
       
  1235 	bitGc->SetBrushColor(TRgb(0x808080));
       
  1236 	TRect rect(aSize);
       
  1237 	bitGc->DrawRect(rect);
       
  1238 
       
  1239 	bitGc->SetBrushColor(TRgb(0x202020));
       
  1240 	TRect rect2(0, 0, aSize.iWidth, aSize.iHeight>>2);
       
  1241 	bitGc->DrawRect(rect2);
       
  1242 	
       
  1243 	TRect rect3(0, 0, aSize.iWidth>>3, aSize.iHeight);
       
  1244 	bitGc->DrawRect(rect3);
       
  1245 
       
  1246 	CleanupStack::PopAndDestroy(2, bitmapDevice);
       
  1247 	CleanupStack::Pop(bitmap);
       
  1248 	return bitmap;
       
  1249 	}
       
  1250 
       
  1251 /** 
       
  1252 Stack cleanup helper function to use when the cache needs to be reset
       
  1253 from the cleanup stack.
       
  1254 This method calls MVgImageCache::ResetCache() on the passed MVgImageCache object
       
  1255 @param aPtr A pointer to an image cache object, MVgImageCache*, to be reset
       
  1256 */
       
  1257 void CTDirectGdiStepBase::ResetCache(TAny* aPtr)
       
  1258 	{
       
  1259 	MVgImageCache* cache = reinterpret_cast <MVgImageCache*> (aPtr);
       
  1260 	cache->ResetCache();
       
  1261 	}
       
  1262 
       
  1263 /** 
       
  1264 Stack cleanup helper function to use when the pen size needs to be reset to (1,1)
       
  1265 from the cleanup stack. This is needed when SetPenSize() is called when testing the
       
  1266 DirectGdi SW version as setting a pen size other then (1,1) causes memory to be
       
  1267 created that is not freed until SetPenSize(1,1) is called (or the related graphics
       
  1268 engine is destroyed).
       
  1269 This method calls CTContextBase::SetPenSize(1,1) on the passed CTContextBase object
       
  1270 @param aPtr A pointer to a test context object, CTContextBase*.
       
  1271 */
       
  1272 void CTDirectGdiStepBase::ResetPenSize(TAny* aPtr)
       
  1273 	{
       
  1274 	if (CTContextBase* context = reinterpret_cast <CTContextBase*> (aPtr))
       
  1275 		context->SetPenSize(TSize(1,1));
       
  1276 	}