os/graphics/graphicsdeviceinterface/directgdi/test/tdirectgdicontext.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 "tdirectgdicontext.h"
    17 #include <s32mem.h>
    18 
    19 #include <graphics/directgdicontext.h>
    20 
    21 
    22 _LIT16(KAbcd,"Abcd efgh ijkl mnop");
    23 
    24 CTDirectGdiContext::CTDirectGdiContext()
    25 	{
    26 	SetTestStepName(KTDirectGdiContextStep);
    27 	}
    28 
    29 CTDirectGdiContext::~CTDirectGdiContext()
    30 	{
    31 	if(iFont)
    32 		{
    33 		ReleaseFont(iFont);		
    34 		}	
    35 	}
    36 
    37 /**
    38 @SYMTestCaseID
    39 	GRAPHICS-DIRECTGDI-CONTEXT-0001
    40 
    41 @SYMTestPriority
    42 	Critical
    43 
    44 @SYMPREQ
    45 	PREQ39
    46 
    47 @SYMREQ
    48 	REQ9195
    49 	REQ9201 
    50 	REQ9202 
    51 	REQ9222 
    52 	REQ9223 
    53 	REQ9236 
    54 	REQ9237
    55 
    56 @SYMTestCaseDesc
    57 	Use case - Single context and single target.
    58 
    59 @SYMTestActions		
    60 	Single context is created and activated on a single target.
    61 	Then some draw operations are done.
    62 
    63 @SYMTestExpectedResults
    64 	It should be able to draw using the correct context and target.
    65 	
    66 @SYMTestStatus 		
    67 	Implemented
    68 */
    69 void CTDirectGdiContext::OneContextOneTarget()
    70 	{		
    71 	_LIT(KTestName, "Context-OneContextOneTarget"); 
    72 	if(!iRunningOomTests)
    73 		{
    74 		INFO_PRINTF1(KTestName);
    75 		}
    76 	ResetGc();		
    77 	
    78 	iGc->SetPenColor(TRgb(255, 0, 0));
    79 	TEST(iGc->PenColor() == TRgb(255, 0, 0));
    80 	iGc->DrawEllipse(TRect(0, 0, 60, 60));
    81 	TESTNOERROR(iGc->GetError());
    82 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(KTestName)));
    83 	}
    84 
    85 /**
    86 @SYMTestCaseID		
    87 	GRAPHICS-DIRECTGDI-CONTEXT-0002
    88 
    89 @SYMTestPriority
    90 	Critical
    91 
    92 @SYMPREQ
    93 	PREQ39
    94 
    95 @SYMREQ
    96 	REQ9195
    97 	REQ9201 
    98 	REQ9202 
    99 	REQ9222 
   100 	REQ9223 
   101 	REQ9236 
   102 	REQ9237
   103 
   104 @SYMTestCaseDesc
   105 	Use case - Draw to two separate targets using a single context. 	
   106 
   107 @SYMTestActions		
   108 	Test that a single context can be activated on two different targets.
   109 	- A single context is created and activated on a target then a green circle is drawn. 
   110 	- The same context then activated on a second target and a red circle is drawn.  
   111 
   112 @SYMTestExpectedResults
   113 	It should be able to draw using the correct context and target and context should 
   114 	be able to switch between the targets. The first target should have a green circle 
   115 	only drawn on it, the second target should have a red circle only drawn on it.
   116 
   117 @SYMTestStatus 		
   118 	Implemented
   119 */
   120 void CTDirectGdiContext::OneContextTwoTargets()
   121 	{	
   122 	TBuf<KTestCaseLength> testCaseNameA;
   123 	TBuf<KTestCaseLength> testCaseNameB;
   124 	_LIT(KTestCase, "Context-OneContextTwoTargets");
   125 	testCaseNameA.Append(KTestCase);
   126 	testCaseNameB.Append(KTestCase);
   127 	if(iCaseNum == EOneContextTwoTargets_SamePixelType)
   128 		{
   129 		testCaseNameA.Append(KSamePixelType);
   130 		testCaseNameB.Append(KSamePixelType);
   131 		}
   132 	else
   133 		{
   134 		testCaseNameA.Append(KDifferentPixelType);
   135 		testCaseNameB.Append(KDifferentPixelType);
   136 		}
   137 	testCaseNameA.Append(KTarget1);
   138 	testCaseNameB.Append(KTarget2);
   139 	if(!iRunningOomTests)
   140 		{
   141 		INFO_PRINTF1(KTestCase);
   142 		}
   143 	ResetGc();
   144 	iGc->SetPenColor(TRgb(0, 255, 0));
   145 	TEST(iGc->PenColor() == TRgb(0, 255, 0));
   146 	iGc->DrawEllipse(TRect(0, 0, 60, 60));
   147 	TESTNOERROR(iGc->GetError());
   148 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameA)));
   149 	
   150 	iGdiTarget2->Activate(iGc);
   151 	
   152 	ResetGc();
   153 	iGc->SetPenColor(TRgb(255, 0, 0));
   154 	TEST(iGc->PenColor() == TRgb(255, 0, 0));
   155 	iGc->DrawEllipse(TRect(0, 0, 60, 60));
   156 	TESTNOERROR(iGc->GetError());
   157 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameB),iGdiTarget2));
   158 	}
   159 
   160 /**
   161 @SYMTestCaseID		
   162 	GRAPHICS-DIRECTGDI-CONTEXT-0003
   163 
   164 @SYMTestPriority
   165 	Critical
   166 
   167 @SYMPREQ
   168 	PREQ39
   169 
   170 @SYMREQ
   171 	REQ9195
   172 	REQ9201 
   173 	REQ9202 
   174 	REQ9222 
   175 	REQ9223 
   176 	REQ9236 
   177 	REQ9237
   178 
   179 @SYMTestCaseDesc
   180 	Use case - draw to a single target using two different contexts.
   181 
   182 @SYMTestActions	
   183 	Test context's creation and activation when drawing using two different contexts to a single target.
   184 	- Activate the first context on the target and draw a red circle.
   185 	- Write out the contents of the target.
   186 	- Activate the second context on the target, clear it and draw a smaller black circle.
   187 	- Write out the contents of the target.
   188 
   189 @SYMTestExpectedResults
   190 	It should be able to draw using the correct context and target. The first image written out
   191 	should contain a red circle, the second image written out should contain a smaller black circle.
   192 	
   193 @SYMTestStatus 		
   194 	Implemented
   195 */
   196 void CTDirectGdiContext::TwoContextsOneTarget()
   197 	{	
   198 	TBuf<KTestCaseLength> testCaseNameA;
   199 	TBuf<KTestCaseLength> testCaseNameB;
   200 	_LIT(KTestCase, "Context-TwoContextsOneTarget");
   201 	testCaseNameA.Append(KTestCase);
   202 	testCaseNameB.Append(KTestCase);
   203 	testCaseNameA.Append(KContext1);
   204 	testCaseNameB.Append(KContext2);
   205 	
   206 	if(!iRunningOomTests)
   207 		{
   208 		INFO_PRINTF1(KTestCase);
   209 		}
   210 	iGdiTarget->Activate(iGc);
   211 	ResetGc();
   212 	iGc->SetPenColor(TRgb(255, 0, 0));
   213 	TEST(iGc->PenColor() == TRgb(255, 0, 0));
   214 	iGc->DrawEllipse(TRect(0, 0, 60, 60));
   215 	TESTNOERROR(iGc->GetError());
   216 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameA)));	
   217 		
   218 	iGdiTarget->Activate(iGc2);
   219 	iGc2->Reset();
   220 	iGc2->Clear();
   221 	iGc2->SetPenColor(TRgb(0, 0, 0));
   222 	TEST(iGc2->PenColor() == TRgb(0, 0, 0));
   223 	iGc2->DrawEllipse(TRect(0, 0, 30, 30));
   224 	TESTNOERROR(iGc2->GetError());	
   225 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameB)));
   226 	}
   227 
   228 /**
   229 @SYMTestCaseID		
   230 	GRAPHICS-DIRECTGDI-CONTEXT-0004
   231 
   232 @SYMTestPriority
   233 	Critical
   234 
   235 @SYMPREQ
   236 	PREQ39
   237 
   238 @SYMREQ
   239 	REQ9195
   240 	REQ9201 
   241 	REQ9202 
   242 	REQ9222 
   243 	REQ9223 
   244 	REQ9236 
   245 	REQ9237
   246 
   247 @SYMTestCaseDesc
   248 	Use case - Two contexts and two targets, but there is no sharing
   249 
   250 @SYMTestActions		
   251 	Two contexts are created and activated on two different targets. There is no sharing between the contexts and targets, they
   252 	are completely isolated.
   253 	Then some draw operations are done. 
   254 
   255 @SYMTestExpectedResults
   256 	It should be able to draw using the correct context and target.
   257 	
   258 @SYMTestStatus 		
   259 	Implemented
   260 */
   261 void CTDirectGdiContext::TwoContextsTwoTargets_WithoutSharingL()
   262 	{	
   263 	TBuf<KTestCaseLength> testCaseNameA;
   264 	TBuf<KTestCaseLength> testCaseNameB;
   265 	_LIT(KTestCase, "Context-TwoContextsTwoTargets_NotSharing");
   266 	testCaseNameA.Append(KTestCase);
   267 	testCaseNameB.Append(KTestCase);
   268 	if(iCaseNum == ETwoContextsTwoTargets_WithoutSharing_SamePixelType)
   269 		{
   270 		testCaseNameA.Append(KSamePixelType);
   271 		testCaseNameB.Append(KSamePixelType);
   272 		}
   273 	else
   274 		{
   275 		testCaseNameA.Append(KDifferentPixelType);
   276 		testCaseNameB.Append(KDifferentPixelType);
   277 		}
   278 	testCaseNameA.Append(KTarget1);
   279 	testCaseNameB.Append(KTarget2);
   280 	
   281 	if(!iRunningOomTests)
   282 		{
   283 		INFO_PRINTF1(KTestCase);
   284 		}
   285 	iGdiTarget->Activate(iGc);
   286 	ResetGc();
   287 	iGc->SetPenColor(TRgb(255, 0, 0));
   288 	TEST(iGc->PenColor() == TRgb(255, 0, 0));
   289 	iGc->DrawEllipse(TRect(0, 0, 60, 60));
   290 	TESTNOERROR(iGc->GetError());
   291 
   292 	iGdiTarget2->Activate(iGc2);
   293 	iGc2->Reset();
   294 	iGc2->Clear();
   295 	iGc2->SetPenColor(TRgb(0, 255, 0));
   296 	TEST(iGc2->PenColor() == TRgb(0, 255, 0));
   297 	iGc2->DrawEllipse(TRect(0, 0, 30, 30));
   298 	TESTNOERROR(iGc2->GetError());	
   299 	
   300 	// Draw to both again twice to make sure that context switching works.
   301 	iGc->DrawEllipse(TRect(0,0,60,60));
   302 	TESTNOERROR(iGc->GetError());
   303 	iGc2->DrawEllipse(TRect(0, 0, 30, 30));
   304 	TESTNOERROR(iGc2->GetError());
   305 	
   306 	iGc->DrawEllipse(TRect(0,0,60,60));
   307 	TESTNOERROR(iGc->GetError());
   308 	iGc2->DrawEllipse(TRect(0, 0, 30, 30));
   309 	TESTNOERROR(iGc2->GetError());
   310 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameA)));
   311 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameB),iGdiTarget2));
   312 	}
   313 
   314 /**
   315 @SYMTestCaseID		
   316 	GRAPHICS-DIRECTGDI-CONTEXT-0005
   317 
   318 @SYMTestPriority
   319 	Critical
   320 
   321 @SYMPREQ
   322 	PREQ39
   323 
   324 @SYMREQ
   325 	REQ9195
   326 	REQ9201 
   327 	REQ9202 
   328 	REQ9222 
   329 	REQ9223 
   330 	REQ9236 
   331 	REQ9237
   332 
   333 @SYMTestCaseDesc
   334 	Use case - Draw using two contexts and two targets, swapping the targets over half way through the test.
   335 
   336 @SYMTestActions
   337 	Test that a context can draw to a target that has been previously drawn to using a different context.		
   338 	Two contexts are created and activated on two different targets. Then some draw operations are done, 
   339 	a red circle is drawn on the first target and a black circle is drawn on the second target.
   340 	Then these contexts are activated on the opposite targets. There is sharing between the contexts 
   341 	and targets (contexts are activated on each other's targets).
   342 	Then again some draw operations are done, the targets are cleared and a red circle is drawn on each target.
   343  
   344 
   345 @SYMTestExpectedResults
   346 	It should be able to draw using the correct context and target and context should be able to switch between 
   347 	the targets. 
   348 	The target 1 drawn to with context 1 should show a red circle, 
   349 	target 2 drawn to with context2 should show a black circle, 
   350 	target 1 drawn to with context 2 should show a red circle,
   351 	target 2 drawn to with context 1 should show a red circle. 
   352 	
   353 @SYMTestStatus 		
   354 	Implemented
   355 */
   356 void CTDirectGdiContext::TwoContextsTwoTargets_WithSharingL()
   357 	{	
   358 	TBuf<KTestCaseLength> testCaseNameA;
   359 	TBuf<KTestCaseLength> testCaseNameB;
   360 	TBuf<KTestCaseLength> testCaseNameAB;
   361 	TBuf<KTestCaseLength> testCaseNameBA;
   362 
   363 	_LIT(KTestCase, "Context-TwoContextsTwoTargets_Sharing");
   364 	testCaseNameA.Append(KTestCase);
   365 	testCaseNameB.Append(KTestCase);
   366 	testCaseNameAB.Append(KTestCase);
   367 	testCaseNameBA.Append(KTestCase);
   368 
   369 	if(iCaseNum == ETwoContextsTwoTargets_WithSharing_SamePixelType)
   370 		{
   371 		testCaseNameA.Append(KSamePixelType);
   372 		testCaseNameB.Append(KSamePixelType);
   373 		testCaseNameAB.Append(KSamePixelType);
   374 		testCaseNameBA.Append(KSamePixelType);
   375 		}
   376 	else
   377 		{
   378 		testCaseNameA.Append(KDifferentPixelType);
   379 		testCaseNameB.Append(KDifferentPixelType);
   380 		testCaseNameAB.Append(KDifferentPixelType);
   381 		testCaseNameBA.Append(KDifferentPixelType);
   382 		}
   383 	testCaseNameA.Append(KContext1);
   384 	testCaseNameA.Append(KTarget1);
   385 	testCaseNameB.Append(KContext2);
   386 	testCaseNameB.Append(KTarget2);
   387 	testCaseNameAB.Append(KContext1);
   388 	testCaseNameAB.Append(KTarget2);
   389 	testCaseNameBA.Append(KContext2);
   390 	testCaseNameBA.Append(KTarget1);
   391 	
   392 	if(!iRunningOomTests)
   393 		{
   394 		INFO_PRINTF1(KTestCase);
   395 		}
   396 	iGdiTarget->Activate(iGc);
   397 	ResetGc();
   398 	iGc->SetPenColor(TRgb(255, 0, 0));
   399 	TEST(iGc->PenColor() == TRgb(255, 0, 0));
   400 	iGc->DrawEllipse(TRect(0, 0, 60, 60));
   401 	TESTNOERROR(iGc->GetError());
   402 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameA)));	
   403 	
   404 	iGdiTarget2->Activate(iGc2);
   405 	iGc2->Reset();
   406 	iGc2->Clear();
   407 	iGc2->SetPenColor(TRgb(0, 0, 0));
   408 	TEST(iGc2->PenColor() == TRgb(0, 0, 0));
   409 	iGc2->DrawEllipse(TRect(0, 0, 30, 30));
   410 	TESTNOERROR(iGc2->GetError());	
   411 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameB),iGdiTarget2));
   412 	
   413 	iGdiTarget->Activate(iGc2);
   414 	iGdiTarget2->Activate(iGc);
   415 
   416 	ResetGc();
   417 	iGc->SetPenColor(TRgb(255, 0, 0));
   418 	TEST(iGc->PenColor() == TRgb(255, 0, 0));
   419 	iGc->DrawEllipse(TRect(0, 0, 60, 60));
   420 	TESTNOERROR(iGc->GetError());
   421 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameAB),iGdiTarget2));
   422 	
   423 	iGc2->Reset();
   424 	iGc2->Clear();
   425 	iGc2->SetPenColor(TRgb(255, 0, 0));
   426 	TEST(iGc->PenColor() == TRgb(255, 0, 0));
   427 	iGc2->DrawEllipse(TRect(0, 0, 60, 60));
   428 	TESTNOERROR(iGc2->GetError());
   429 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameBA)));	
   430 	}
   431 
   432 /**
   433 @SYMTestCaseID		
   434 	GRAPHICS-DIRECTGDI-CONTEXT-0006
   435 
   436 @SYMTestPriority
   437 	Critical
   438 
   439 @SYMPREQ
   440 	PREQ39
   441 
   442 @SYMREQ
   443 	REQ9195
   444 	REQ9201 
   445 	REQ9202 
   446 	REQ9222 
   447 	REQ9223 
   448 	REQ9236 
   449 	REQ9237
   450 
   451 @SYMTestCaseDesc
   452 	Use case - Single context and single target, but calling activate twice.
   453 
   454 @SYMTestActions		
   455 	Single context is created and activated twice on the same target, just to prove that there is no affect of calling
   456 	Activate() twice on the same target by the same context, in succession.
   457 
   458 @SYMTestExpectedResults
   459 	It should be able to draw using the correct context and target.
   460 	
   461 @SYMTestStatus 		
   462 	Implemented
   463 */
   464 void CTDirectGdiContext::OneContextOneTarget_TwiceActivateL()
   465 	{	
   466 	_LIT(KTestName, "Context-OneContextOneTargetTwiceActivate");
   467 	if(!iRunningOomTests)
   468 		{
   469 		INFO_PRINTF1(KTestName);
   470 		}
   471 	_LIT(KTestNameA, "Context-OneContextOneTarget_TwiceActivateA"); 
   472 	_LIT(KTestNameB, "Context-OneContextOneTarget_TwiceActivateB"); 
   473 	ResetGc();
   474 	iGc->SetPenColor(TRgb(255, 0, 0));
   475 	TEST(iGc->PenColor() == TRgb(255, 0, 0));
   476 	iGc->DrawEllipse(TRect(0, 0, 60, 60));
   477 	TESTNOERROR(iGc->GetError());
   478 	TEST(KErrNone == WriteTargetOutput(iTestParams, TPtrC(KTestNameA)));	
   479 	
   480 	iGdiTarget->Activate(iGc);
   481 	
   482 	ResetGc();
   483 	iGc->SetPenColor(TRgb(0, 0, 255));
   484 	TEST(iGc->PenColor() == TRgb(0, 0, 255));
   485 	iGc->DrawEllipse(TRect(0, 0, 60, 60));
   486 	TESTNOERROR(iGc->GetError());
   487 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(KTestNameB)));
   488 	}
   489 
   490 LOCAL_C void ContextReset(TAny* aPtr)
   491 	{
   492 	CTContextBase* gc = reinterpret_cast <CTContextBase*> (aPtr);
   493 	gc->Reset();
   494 	}
   495 
   496 /**
   497 @SYMTestCaseID
   498 	GRAPHICS-DIRECTGDI-CONTEXT-0007
   499 
   500 @SYMTestPriority
   501 	Critical
   502 
   503 @SYMPREQ
   504 	PREQ39
   505 
   506 @SYMREQ
   507 	REQ9195 
   508 	REQ9201 
   509 	REQ9202 
   510 	REQ9222 
   511 	REQ9223 
   512 	REQ9236 
   513 	REQ9237
   514 
   515 @SYMTestStatus
   516 	Complete
   517 
   518 @SYMTestCaseDesc
   519 	Externalize and internalize a context.
   520 
   521 @SYMTestActions
   522 	Test the use case where we:
   523 	Create a new GC for the purpose of the test.
   524 	Set Pen and Brush colour non-default colours.
   525 	Set the Pen and Brush styles to non-default styles.
   526 	Set the clipping regions.
   527 	Set a font (DirectGdi only, BitGdi causes the font to be cached and UHEAP failures occur).
   528 	Set the origin and the internal drawing position to non-defaults.
   529 	Externalise.
   530 	Reset the context, and set the state to other values.
   531 	Internalise.
   532 	Draw a line from the current internal drawing position.
   533 	Draw a rectangle using current pen and brush styles/colours/size.
   534 	Destroy the temporary GC and reinstate the original.
   535 
   536 @SYMTestStatus 
   537 	Implemented
   538  */
   539 void CTDirectGdiContext::ExternalizeInternalizeTestL()
   540 	{
   541 	__UHEAP_MARK;
   542 	_LIT(KTestName, "Context-ExternalizeInternalize"); 	
   543 	if(!iRunningOomTests)
   544 		{
   545 		INFO_PRINTF1(KTestName);
   546 		}
   547 	const TInt width = iGdiTarget->SizeInPixels().iWidth;
   548 	const TInt height = iGdiTarget->SizeInPixels().iHeight;
   549 
   550 	// For this test, create a temporary GC which we can delete later.
   551 	// This is to avoid UHEAP mismatches if we used the original iGc.
   552 	// Set this to be iGc for this test.	
   553 	CTContextBase *oldGc = iGc;
   554 	iGc = NULL;
   555 	CleanupStack::PushL(oldGc);
   556 	TESTNOERRORL(iGdiTarget->CreateContext(iGc));
   557 	ResetGc();
   558 
   559 	// Create some clipping regions. These should not be externalised/internalised.
   560 	RRegion clippingRegion(2);
   561 	clippingRegion.AddRect(TRect(width*3/10,0,width*7/10,height));
   562 	clippingRegion.AddRect(TRect(0,height*3/10,width,height*7/10));
   563 	CleanupClosePushL(clippingRegion);
   564 	iGc->SetClippingRegion(clippingRegion);
   565 	CleanupStack::PushL(TCleanupItem(ContextReset, iGc));
   566 
   567 	// Create a bitmap to use as a brush pattern
   568 	CFbsBitmap* pattern = CreateCheckedBoardBitmapL(iTestParams.iTargetPixelFormat, TSize(100,100));
   569 	CleanupStack::PushL(pattern);
   570 
   571 	// Set non-default state.
   572 	iGc->SetOrigin(TPoint(10,10));
   573 	iGc->SetPenSize(TSize(3,3));
   574 	iGc->SetPenColor(TRgb(255,0,255));
   575 	iGc->SetPenStyle(DirectGdi::EDashedPen);
   576 	iGc->SetBrushColor(TRgb(0,255,0));
   577 	iGc->SetBrushPattern(*pattern);
   578 	iGc->SetBrushStyle(DirectGdi::EPatternedBrush);
   579 	iGc->SetBrushOrigin(TPoint(3, 3));
   580 	iGc->MoveTo(TPoint(10, height/2));
   581 	iGc->SetDrawMode(DirectGdi::EDrawModePEN);
   582 
   583 	if (iUseDirectGdi)
   584 		{
   585 		// Internalizing/externalizing a font in BitGdi will cause the font to be cached and 
   586 		// memory UHEAP mismatch occurs, so only do it for DirectGdi. We wont draw any text in the image.
   587 		TESTL(iFont != NULL);
   588 		iGc->SetFont(iFont);
   589 		}
   590 
   591 	// create buffer for save/restore
   592 	CBufFlat* buf = NULL;
   593 	TRAPD(err, buf=CBufFlat::NewL(512));
   594 	if(KErrNone != err)
   595 		{
   596 		iGc->ResetClippingRegion();
   597 		User::LeaveIfError(err);
   598 		}
   599 	CleanupStack::PushL(buf);
   600 
   601 	// save and then restore
   602 	RBufWriteStream ws(*buf,0);
   603 	iGc->ExternalizeL(ws);
   604 	ws.Close();
   605 
   606 	// Make some modifications to iGc.
   607 	// The clipping regions should be persistant even after the Internalize().
   608 	iGc->Reset();
   609 	iGc->ResetClippingRegion();
   610 	iGc->ResetFont();
   611 	iGc->SetPenColor(TRgb(0,0,0));
   612 	RRegion tempClippingRegion(1);
   613 	tempClippingRegion.AddRect(TRect(width/10, height/10, width*9/10, height*9/10));
   614 	iGc->SetClippingRegion(tempClippingRegion);	
   615 	CleanupClosePushL(tempClippingRegion);
   616 
   617 	// Internalise the state.
   618 	RBufReadStream rs(*buf,0);
   619 	iGc->InternalizeL(rs);
   620 	rs.Close();
   621 
   622 	// Draw using the newly internalised context.
   623 	// We don't draw any text as we don't internalize/externalize text for BitGdi.
   624 	iGc->Clear();
   625 	iGc->DrawRect(TRect(width/4, height/4, width*3/4, height*3/4));
   626 	iGc->DrawLineTo(TPoint(width, height/2));
   627 	TESTNOERROR(iGc->GetError());
   628 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(KTestName)));
   629 
   630 	CleanupStack::PopAndDestroy(5);
   631 	CleanupStack::Pop(1, oldGc);
   632 
   633 	// Destroy the temporary Gc and reinstate the original one.
   634 	iGdiTarget->Activate(oldGc);
   635 	delete iGc;
   636 	iGc = oldGc;
   637 	__UHEAP_MARKEND;
   638 	}
   639 
   640 /**
   641 @SYMTestCaseID		
   642 	GRAPHICS-DIRECTGDI-CONTEXT-0008
   643 
   644 @SYMTestPriority
   645 	Critical
   646 
   647 @SYMPREQ
   648 	PREQ39
   649 
   650 @SYMREQ
   651 	REQ9195
   652 	REQ9201 
   653 	REQ9202 
   654 	REQ9222 
   655 	REQ9223 
   656 	REQ9236 
   657 	REQ9237
   658 
   659 @SYMTestCaseDesc
   660 	Use case - two contexts and one target. 
   661   
   662 @SYMTestActions		
   663 	Two contexts are created and activated on the same target.
   664 	Then some draw operations are done. 
   665 	CopySettings() is called to copy settings from first context to the second one.
   666 	Then again some draw operations are done to verify that settings have been copied properly.
   667 
   668 @SYMTestExpectedResults
   669 	It should be able to draw using the correct settings of context and target.
   670 	
   671 @SYMTestStatus 		
   672 	Implemented
   673 */
   674 void CTDirectGdiContext::TestCopySettings()
   675 	{	
   676 	TBuf<KTestCaseLength> testCaseNameA;
   677 	TBuf<KTestCaseLength> testCaseNameB;
   678 	_LIT(KTestCase, "Context-CopySettings");
   679 	if(!iRunningOomTests)
   680 		{
   681 		INFO_PRINTF1(KTestCase);
   682 		}
   683 	testCaseNameA.Append(KTestCase);
   684 	testCaseNameB.Append(KTestCase);
   685 	testCaseNameA.Append(KContext1);
   686 	testCaseNameB.Append(KContext2);	
   687 
   688 	// Draw to the first graphics context
   689 	iGdiTarget->Activate(iGc);
   690 	ResetGc();		
   691 	iGc->SetPenColor(KRgbRed);
   692 	iGc->SetPenSize(TSize(3,3));
   693 	iGc->SetBrushColor(KRgbYellow);
   694 	iGc->SetBrushStyle(DirectGdi::ESolidBrush);
   695 	iGc->SetTextShadowColor(KRgbGreen);
   696 	TEST(iGc->PenColor() == KRgbRed);
   697 	
   698 	// Do some drawing
   699 	iGc->DrawEllipse(TRect(5, 5, 50, 50));	
   700 	iGc->SetFont(iFont);	
   701 	iGc->SetStrikethroughStyle(DirectGdi::EStrikethroughOn);
   702 	iGc->SetCharJustification(10, 10);
   703 	iGc->SetWordJustification(20, 20);
   704 	iGc->DrawText(KAbcd, NULL, TPoint(10, 100));
   705 	TESTNOERROR(iGc->GetError());
   706 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameA)));	
   707 		
   708 	// Activate the second context and reset the context settings
   709 	iGdiTarget->Activate(iGc2);
   710 	iGc2->Reset();
   711 	iGc2->Clear();
   712 	TEST(iGc2->PenColor() == TRgb(0, 0, 0));
   713 	// Copy the settings from the first context to the second one
   714 	iGc2->CopySettings(*iGc);
   715 	TEST(iGc2->PenColor() == TRgb(255, 0, 0));
   716 	
   717 	// Do some drawing, the ellipse is drawn deliberately smaller this time,
   718 	// the text should look the same as before 
   719 	iGc2->DrawEllipse(TRect(0, 0, 30, 30));
   720 	iGc->DrawText(KAbcd, NULL, TPoint(10, 100));
   721 	TESTNOERROR(iGc2->GetError());	
   722 	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameB)));
   723 	
   724 	// Test that the settings from iGc have been copied to iGc2
   725 	TEST(iGc->PenColor() == iGc2->PenColor());
   726 	TEST(iGc->BrushColor() == iGc2->BrushColor());
   727 	TEST(iGc->TextShadowColor() == iGc2->TextShadowColor());
   728 	
   729 	iGc->ResetFont();
   730 	iGc2->ResetFont();
   731 	
   732 	// Force a cleanup of the pen array when testing the SW version of DirectGdi, 
   733 	// if this is not done the OOM tests fail when running this test.
   734 	iGc->SetPenSize(TSize(1,1));
   735 	iGc2->SetPenSize(TSize(1,1));
   736 	}
   737 
   738 /** 
   739 Override of base class pure virtual
   740 Our implementation only gets called if the base class doTestStepPreambleL() did
   741 not leave. That being the case, the current test result value will be EPass.
   742 @leave Gets system wide error code
   743 @return TVerdict code
   744 */	
   745 TVerdict CTDirectGdiContext::doTestStepL()
   746 	{			
   747 	// Test for each pixel format
   748 	for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
   749 		{	
   750 		iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
   751 		for(iCaseNum = EOneContextOneTarget; iCaseNum < ELast; ++iCaseNum)
   752 			{			
   753 			SetTargetL(iTestParams.iTargetPixelFormat, static_cast<TContextTestCase>(iCaseNum));							
   754 			
   755 			// Create fonts outside of the OOM tests to avoid cached fonts being included
   756 			iFont = GetFont();
   757 			User::LeaveIfNull(iFont);					
   758 	
   759 			RunTestsL();
   760 			// only run OOM tests for one target pixel format to prevent duplication of tests
   761 			if (targetPixelFormatIndex == 0)
   762 				{
   763 				RunOomTestsL();  //from base class
   764 				}		
   765 			if(iFont)
   766 				{
   767 				ReleaseFont(iFont);
   768 				iFont = NULL;
   769 				}			
   770 			}
   771 		}
   772 	CloseTMSGraphicsStep();
   773 	return TestStepResult();
   774 	}
   775 
   776 /**
   777 Override of base class virtual
   778 @leave Gets system wide error code
   779 @return - TVerdict code
   780 */
   781 TVerdict CTDirectGdiContext::doTestStepPreambleL()
   782 	{			
   783 	CTDirectGdiStepBase::doTestStepPreambleL();	
   784 	return TestStepResult();
   785 	}
   786 
   787 /**
   788 Override of base class pure virtual
   789 Lists the tests to be run
   790 */
   791 void CTDirectGdiContext::RunTestsL()
   792 	{
   793 	SetTestStepID(KUnknownSYMTestCaseIDName);
   794 	switch(iCaseNum)
   795 		{
   796 		case EOneContextOneTarget:
   797 			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0001"));
   798 			OneContextOneTarget();
   799 			if (!iRunningOomTests)
   800 				{
   801 				RecordTestResultL();
   802 				SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0007"));
   803 				ExternalizeInternalizeTestL();
   804 				}
   805 			break;
   806 		case EOneContextTwoTargets_SamePixelType:
   807 		case EOneContextTwoTargets_DifferentPixelType:
   808 			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0002"));
   809 			OneContextTwoTargets();
   810 			break;
   811 		case ETwoContextsOneTarget:
   812 			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0003"));
   813 			TwoContextsOneTarget();			
   814 			RecordTestResultL();
   815 			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0008"));
   816 			TestCopySettings();			
   817 			break;
   818 		case ETwoContextsTwoTargets_WithoutSharing_SamePixelType:
   819 		case ETwoContextsTwoTargets_WithoutSharing_DifferentPixelType:
   820 			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0004"));
   821 			TwoContextsTwoTargets_WithoutSharingL();
   822 			break;
   823 		case ETwoContextsTwoTargets_WithSharing_SamePixelType:
   824 		case ETwoContextsTwoTargets_WithSharing_DifferentPixelType:
   825 			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0005"));
   826 			TwoContextsTwoTargets_WithSharingL();
   827 			break;
   828 		case EOneContextOneTarget_TwiceActivate:
   829 			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0006"));
   830 			OneContextOneTarget_TwiceActivateL();
   831 			break;				
   832 		}
   833 	RecordTestResultL();
   834 	
   835 	}