graphicsdeviceinterface/directgdi/test/tdirectgdicontexttarget.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 "tdirectgdicontexttarget.h"
       
    17 #include <graphics/directgdicontext.h>
       
    18 
       
    19 CTDirectGdiContextTarget::CTDirectGdiContextTarget()
       
    20 	{
       
    21 	SetTestStepName(KTDirectGdiContextTargetStep);
       
    22 	}
       
    23 
       
    24 CTDirectGdiContextTarget::~CTDirectGdiContextTarget()
       
    25 	{
       
    26 	}
       
    27 
       
    28 /**
       
    29 @SYMTestCaseID		
       
    30 	GRAPHICS-DIRECTGDI-CONTEXTTARGET-0001
       
    31 
       
    32 @SYMTestPriority
       
    33 	Critical
       
    34 
       
    35 @SYMPREQ
       
    36 	PREQ39
       
    37 
       
    38 @SYMREQ
       
    39 	REQ9195
       
    40 	REQ9201 
       
    41 	REQ9202 
       
    42 	REQ9222 
       
    43 	REQ9223 
       
    44 	REQ9236 
       
    45 	REQ9237
       
    46 
       
    47 @SYMTestCaseDesc
       
    48 	Use case - Single context and multiple targets.
       
    49 
       
    50 @SYMTestActions		
       
    51 	Construct CDirectGdiDriver.
       
    52 	Construct CDirectGdiContext.
       
    53 
       
    54 	Construct RSgImage1.
       
    55 	Construct MDirectGdiImageTarget1. 
       
    56  	Create MDirectGdiImageTarget1, using RSgImage1.
       
    57 
       
    58 	Activate CDirectGdiContext using MDirectGdiImageTarget1.
       
    59 	Do some drawing operations using a different pen/brush setting
       
    60   
       
    61 	Construct RSgImage2.
       
    62 	Construct MDirectGdiImageTarget2. 
       
    63 	Create MDirectGdiImageTarget2, using RSgImage2.
       
    64 
       
    65 	Activate CDirectGdiContext using MDirectGdiImageTarget2.
       
    66 	Do some drawing operations using a different pen/brush setting
       
    67   
       
    68 	Destroy RSgImage.
       
    69 	Destroy MDirectGdiImageTarget.
       
    70 
       
    71 	Destroy CDirectGdiContext.
       
    72 	Close CDirectGdiDriver.	
       
    73 
       
    74 @SYMTestExpectedResults
       
    75 	It should be able to switch the targets between the same context.
       
    76 	
       
    77 @SYMTestStatus 		
       
    78 	Implemented
       
    79 */
       
    80 void CTDirectGdiContextTarget::TestSwitchingTargetsL()
       
    81 	{
       
    82 	TInt result = KErrNone;
       
    83 	_LIT(KTestName, "ContextTarget-SwitchingTargets"); 
       
    84 	if(!iRunningOomTests)
       
    85 		{
       
    86 		INFO_PRINTF1(KTestName);
       
    87 		}
       
    88 	
       
    89 	if (iTargetPixelFormatArray.Count() <= 1)
       
    90 		{
       
    91 		// The MBX driver only supports one pixelformat. This test has no purpose
       
    92 		// when both targets are the same, so in this case we don't run it.
       
    93 		INFO_PRINTF1(_L("Not enough formats supported. Skipping test..."));
       
    94 		return;
       
    95 		}
       
    96 	
       
    97 	TInt err = CDirectGdiDriver::Open();
       
    98 	TESTNOERRORL(err);
       
    99 			
       
   100 	CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
       
   101 	TESTL(dgdiDriver != NULL);	
       
   102 	CleanupClosePushL(*dgdiDriver);	
       
   103 	
       
   104 	CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);	
       
   105 	CleanupStack::PushL(gc);
       
   106 	
       
   107 	RSgImage rsgImage1;	
       
   108 	RSgImage rsgImage2;	
       
   109 	
       
   110 	// Set the bitmap up...
       
   111 	TSgImageInfo imageInfo;
       
   112 	imageInfo.iSizeInPixels = TSize (320, 240);
       
   113 	imageInfo.iPixelFormat = iTargetPixelFormatArray[0];
       
   114 	imageInfo.iUsage = ESgUsageDirectGdiTarget;
       
   115 	result = rsgImage1.Create(imageInfo, NULL,0);
       
   116 	TESTNOERRORL(result);
       
   117 	CleanupClosePushL(rsgImage1);
       
   118 	
       
   119 	imageInfo.iSizeInPixels = TSize (300, 300);
       
   120 	imageInfo.iPixelFormat =  iTargetPixelFormatArray[1];
       
   121 	result = rsgImage2.Create(imageInfo, NULL,0);
       
   122 	TESTNOERRORL(result);
       
   123 	CleanupClosePushL(rsgImage2);	
       
   124 
       
   125 	RDirectGdiImageTarget dgdiImageTarget1(*dgdiDriver);	
       
   126 	result = dgdiImageTarget1.Create(rsgImage1);
       
   127 	TESTNOERRORL(result);
       
   128 	CleanupClosePushL(dgdiImageTarget1);
       
   129 
       
   130 	result = gc->Activate (dgdiImageTarget1);
       
   131 	TESTNOERRORL(result);
       
   132 	gc->SetPenColor(TRgb(100,100,100));
       
   133 	TEST(gc->PenColor() == TRgb(100,100,100));
       
   134 	gc->DrawEllipse(TRect(0,0,30,30));
       
   135 	TESTNOERROR(dgdiDriver->GetError());
       
   136 
       
   137 	RDirectGdiImageTarget dgdiImageTarget2(*dgdiDriver);	
       
   138 	result = dgdiImageTarget2.Create(rsgImage1);
       
   139 	TESTNOERRORL(result);
       
   140 	CleanupClosePushL(dgdiImageTarget2);
       
   141 
       
   142 	result = gc->Activate (dgdiImageTarget2);
       
   143 	TESTNOERRORL(result);
       
   144 	gc->SetPenColor(TRgb(0,0,0));
       
   145 	TEST(gc->PenColor() == TRgb(0,0,0));	
       
   146 	gc->DrawEllipse(TRect(0,0,30,30));
       
   147 	TESTNOERROR(dgdiDriver->GetError());		
       
   148 
       
   149 	CleanupStack::PopAndDestroy(6, dgdiDriver); //dgdiImageTarget1&2, rsgImage1&2, gc, dgdiDriver
       
   150 	
       
   151 	}
       
   152 
       
   153 /**
       
   154 @SYMTestCaseID		
       
   155 	GRAPHICS-DIRECTGDI-CONTEXTTARGET-0002
       
   156 
       
   157 @SYMTestPriority
       
   158 	Critical
       
   159 
       
   160 @SYMPREQ
       
   161 	PREQ39
       
   162 
       
   163 @SYMREQ
       
   164 	REQ9195
       
   165 	REQ9201 
       
   166 	REQ9202 
       
   167 	REQ9222 
       
   168 	REQ9223 
       
   169 	REQ9236 
       
   170 	REQ9237
       
   171 
       
   172 @SYMTestCaseDesc
       
   173 	Test the integrity of RSgImage metadata after being written to.
       
   174 
       
   175 @SYMTestActions		
       
   176 	Construct CDirectGdiDriver.
       
   177 	Construct CDirectGdiContext.
       
   178 	Construct RSgImage.
       
   179 	Construct MDirectGdiImageTarget. 
       
   180 	Create MDirectGdiImageTarget1, using RSgImage.
       
   181 	Check the current RSgImage info matches that at creation time.
       
   182 	Activate CDirectGdiContext using MDirectGdiImageTarget.
       
   183 	Do some drawing operations on the target.
       
   184 	Check the current RSgImage info matches that at creation time.  
       
   185 	Destroy RSgImage.
       
   186 	Destroy MDirectGdiImageTarget.
       
   187 	Destroy CDirectGdiContext.
       
   188 	Close CDirectGdiDriver.
       
   189 
       
   190 @SYMTestExpectedResults
       
   191 	The RSgImage info should be the same at all times.
       
   192   
       
   193 @SYMTestStatus 		
       
   194 	Implemented
       
   195 */
       
   196 void CTDirectGdiContextTarget::TestRSgImageMetadataIntegrityL()
       
   197 	{
       
   198 	_LIT(KTestName, "ContextTarget-RSgImageMetadataIntegrity"); 
       
   199 	if(!iRunningOomTests)
       
   200 		{
       
   201 		INFO_PRINTF1(KTestName);
       
   202 		}
       
   203 	
       
   204 	TInt err = CDirectGdiDriver::Open();
       
   205 	TESTNOERRORL(err);			
       
   206 	CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
       
   207 	TESTL(dgdiDriver != NULL);	
       
   208 	CleanupClosePushL(*dgdiDriver);	
       
   209 	CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);
       
   210 	CleanupStack::PushL(gc);
       
   211 	
       
   212 	// Create RSgImage, initialise some info.
       
   213 	RSgImage rsgImage;	
       
   214 	TSgImageInfo imageInfo;
       
   215 	imageInfo.iSizeInPixels = TSize (320, 240);
       
   216 	imageInfo.iPixelFormat = iTestParams.iTargetPixelFormat;
       
   217 	imageInfo.iUsage = ESgUsageDirectGdiTarget;
       
   218 	TInt result = rsgImage.Create(imageInfo, NULL,0);
       
   219 	TESTNOERRORL(result);
       
   220 	CleanupClosePushL(rsgImage);
       
   221 	
       
   222 	// Test that after creation, the info is still the same.
       
   223 	TSgImageInfo retrievedInfo;
       
   224 	TESTNOERRORL(rsgImage.GetInfo(retrievedInfo));
       
   225 	TBool match = CompareInfos(retrievedInfo, imageInfo);
       
   226 	TEST(match);
       
   227 	
       
   228 	// Perform writing to the target.
       
   229 	RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver);	
       
   230 	TESTNOERRORL(dgdiImageTarget.Create(rsgImage));
       
   231 	CleanupClosePushL(dgdiImageTarget);
       
   232 	TESTNOERRORL(gc->Activate (dgdiImageTarget) );
       
   233 	gc->SetBrushColor(TRgb(255,0,0,255));
       
   234 	gc->Clear();
       
   235 	dgdiDriver->Finish();
       
   236 	
       
   237 	// Test that after being written to, the info is still the same. If this fails, 
       
   238 	// an indication that image data is being written over the metadata.
       
   239 	TESTNOERRORL(rsgImage.GetInfo(retrievedInfo));
       
   240 	match = CompareInfos(retrievedInfo, imageInfo);
       
   241 	TEST(match);
       
   242 	
       
   243 	CleanupStack::PopAndDestroy(4); //dgdiImageTarget, rsgImage, gc, dgdiDriver	
       
   244 	}
       
   245 
       
   246 /**
       
   247 @SYMTestCaseID		
       
   248 	GRAPHICS-DIRECTGDI-CONTEXTTARGET-0003
       
   249 
       
   250 @SYMTestPriority
       
   251 	Critical
       
   252 
       
   253 @SYMPREQ
       
   254 	PREQ39
       
   255 
       
   256 @SYMREQ
       
   257 	REQ9195
       
   258 	REQ9201 
       
   259 	REQ9202 
       
   260 	REQ9222 
       
   261 	REQ9223 
       
   262 	REQ9236 
       
   263 	REQ9237
       
   264 
       
   265 @SYMTestCaseDesc
       
   266 	Test that the RdirectGdiImageTarget::Create() and RDirectGdiDrawableSource::Create() methods 
       
   267 	validate their arguments.
       
   268 	- Test that creation of a target from an RSgImage that was created as a source fails.
       
   269 	- Test that creation of a source from an RSgImage that was created as a target fails.
       
   270 
       
   271 @SYMTestActions		
       
   272 	Construct CDirectGdiDriver.
       
   273 	Construct CDirectGdiContext.
       
   274 	Create a RSgImage 1 as a source.
       
   275 	Create a RSgImage 2 as a target.
       
   276 	Attempt to create RDirectGdiImageTarget from RSgImage 1 (a source).
       
   277 	KErrNotSupported should be returned.
       
   278 	Attempt to create RDirectGdiDrawableSource from RSgImage 2 (a target).
       
   279 	KErrNotSupported should be returned.
       
   280 
       
   281 @SYMTestExpectedResults
       
   282 	Functions return the correct error code.
       
   283   
       
   284 @SYMTestStatus 		
       
   285 	Implemented
       
   286 */
       
   287 void CTDirectGdiContextTarget::TestCreateCloseSourceTargetInvalidParametersL()
       
   288 	{
       
   289 	_LIT(KTestName, "ContextTarget-CreateCloseSourceTargetInvalidParameters"); 
       
   290 	if(!iRunningOomTests)
       
   291 		{
       
   292 		INFO_PRINTF1(KTestName);
       
   293 		}
       
   294 	
       
   295 	TInt err = CDirectGdiDriver::Open();
       
   296 	TESTNOERRORL(err);			
       
   297 	CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
       
   298 	TESTL(dgdiDriver != NULL);	
       
   299 	CleanupClosePushL(*dgdiDriver);	
       
   300 	
       
   301 	CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);	
       
   302 	CleanupStack::PushL(gc);
       
   303 	
       
   304 	//Create an image with usage set to ESgUsageDirectGdiSource	
       
   305 	TSgImageInfo info1;
       
   306 	info1.iSizeInPixels = TSize(8, 8);
       
   307 	info1.iUsage = ESgUsageDirectGdiSource;
       
   308 	info1.iPixelFormat = EUidPixelFormatARGB_8888;
       
   309 	info1.iCpuAccess = ESgCpuAccessReadWrite;
       
   310 	info1.iShareable = ETrue;	
       
   311 	RSgImage image1;
       
   312 	TESTNOERRORL(image1.Create(info1, NULL, 0));
       
   313 	CleanupClosePushL(image1);	
       
   314 	
       
   315 	//Create an image with usage set to ESgUsageDirectGdiTarget
       
   316 	TSgImageInfo info2;
       
   317 	info2.iSizeInPixels = TSize(8, 8);
       
   318 	info2.iUsage = ESgUsageDirectGdiTarget;
       
   319 	info2.iPixelFormat = EUidPixelFormatRGB_565;
       
   320 	info2.iCpuAccess = ESgCpuAccessNone;
       
   321 	info2.iShareable = ETrue;
       
   322 	RSgImage image2;
       
   323 	TESTNOERRORL(image2.Create(info2, NULL, 0));
       
   324 	CleanupClosePushL(image2);
       
   325 	
       
   326 	//create a RDirectGdiImageTarget from an image with 
       
   327 	//usage set to ESgUsageDirectGdiSource
       
   328 	RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver);	
       
   329 	TESTL(KErrNotSupported == dgdiImageTarget.Create(image1));	
       
   330 	
       
   331 	//create a RDirectGdiDrawableSource from an image with
       
   332 	//usage set to ESgUsageDirectGdiTarget	
       
   333 	RDirectGdiDrawableSource dgdiImageSource(*dgdiDriver);
       
   334 	TESTL(KErrNotSupported == dgdiImageSource.Create(image2));
       
   335 	
       
   336 	//create a RDirectGdiImageTarget from an image with 
       
   337 	//usage set to ESgUsageDirectGdiTarget	
       
   338 	//should succeed
       
   339 	TESTNOERRORL(dgdiImageTarget.Create(image2));
       
   340 	CleanupClosePushL(dgdiImageTarget);
       
   341 	
       
   342 	// Need to activate a target before we can create a source due to OpenVG limitation.
       
   343 	// An OpenVG context must exist before a source can be created, but is not available
       
   344 	// until a target is activated.
       
   345 	gc->Activate(dgdiImageTarget);	
       
   346 
       
   347 	//create a RDirectGdiDrawableSource from an image with
       
   348 	//usage set to ESgUsageDirectGdiSource	
       
   349 	//should succeed
       
   350 	TESTNOERRORL(dgdiImageSource.Create(image1));
       
   351 	CleanupClosePushL(dgdiImageSource);
       
   352 	
       
   353 	CleanupStack::PopAndDestroy(6, dgdiDriver);
       
   354 	}
       
   355 
       
   356 /** 
       
   357 Override of base class pure virtual
       
   358 Our implementation only gets called if the base class doTestStepPreambleL() did
       
   359 not leave. That being the case, the current test result value will be EPass.
       
   360 @leave Gets system wide error code
       
   361 @return TVerdict code
       
   362 */	
       
   363 TVerdict CTDirectGdiContextTarget::doTestStepL()
       
   364 	{
       
   365 	if(iUseDirectGdi)
       
   366 		{
       
   367 		// Test for each pixel format
       
   368 		for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
       
   369 			{	
       
   370 			iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
       
   371 			RunTestsL();
       
   372 			RunOomTestsL();			
       
   373 			}
       
   374 		}
       
   375 	else
       
   376 		{
       
   377 		INFO_PRINTF1(_L("BitGDI has no RSgImage to test!"));
       
   378 		}
       
   379 	CloseTMSGraphicsStep();
       
   380 	return TestStepResult();
       
   381 	}
       
   382 
       
   383 /**
       
   384 Override of base class virtual
       
   385 @leave Gets system wide error code
       
   386 @return - TVerdict code
       
   387 */
       
   388 TVerdict CTDirectGdiContextTarget::doTestStepPreambleL()
       
   389 	{			
       
   390 	CTDirectGdiStepBase::doTestStepPreambleL();	
       
   391 	return TestStepResult();
       
   392 	}
       
   393 
       
   394 /**
       
   395 Override of base class pure virtual
       
   396 Lists the tests to be run
       
   397 */
       
   398 void CTDirectGdiContextTarget::RunTestsL()
       
   399 	{
       
   400 	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXTTARGET-0001"));
       
   401 	TestSwitchingTargetsL();	
       
   402 	RecordTestResultL();
       
   403 	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXTTARGET-0002"));
       
   404 	TestRSgImageMetadataIntegrityL();
       
   405 	RecordTestResultL();
       
   406 	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXTTARGET-0003"));
       
   407 	TestCreateCloseSourceTargetInvalidParametersL();
       
   408 	RecordTestResultL();
       
   409 	}
       
   410 
       
   411 /**
       
   412 Helper function to test the equivalence of two TSgImageInfo structures.
       
   413 
       
   414 @see     CTSgTestStepBase::CompareInfos
       
   415 @param   info1 A TSgImageInfo structure to compare.
       
   416 @param   info2 A TSgImageInfo structure to compare.
       
   417 
       
   418 @return  ETrue if the two are identical, EFalse otherwise.
       
   419 */
       
   420 TBool CTDirectGdiContextTarget::CompareInfos(const TSgImageInfo& info1, const TSgImageInfo& info2)
       
   421 	{
       
   422 	return info1.iCpuAccess == info2.iCpuAccess 
       
   423 			&& info1.iPixelFormat == info2.iPixelFormat
       
   424 			&& info1.iScreenId == info2.iScreenId
       
   425 			&& info1.iShareable == info2.iShareable
       
   426 			&& info1.iSizeInPixels == info2.iSizeInPixels
       
   427 			&& info1.iUsage | info2.iUsage
       
   428 			&& info1.iUserAttributeCount == info2.iUserAttributeCount;
       
   429 	}