graphicsdeviceinterface/directgdi/test/tclear.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 "tclear.h"
       
    17 
       
    18 #include <e32math.h>
       
    19 
       
    20 CTClear::CTClear()
       
    21 	{
       
    22 	SetTestStepName(KTDirectGdiClearStep);
       
    23 	}
       
    24 
       
    25 CTClear::~CTClear()
       
    26 	{
       
    27 	}
       
    28 
       
    29 /**
       
    30 @SYMTestCaseID
       
    31 	GRAPHICS-DIRECTGDI-CLEAR-0001
       
    32 
       
    33 @SYMPREQ 
       
    34 	PREQ39
       
    35 
       
    36 @SYMREQ
       
    37 	REQ9195
       
    38 	REQ9201 
       
    39 	REQ9202 
       
    40 	REQ9222 
       
    41 	REQ9223 
       
    42 	REQ9236 
       
    43 	REQ9237
       
    44 
       
    45 @SYMTestCaseDesc
       
    46 	Test that Clear clears the whole target successfully
       
    47 
       
    48 @SYMTestPriority  
       
    49 	Critical
       
    50 
       
    51 @SYMTestStatus
       
    52 	Implemented
       
    53 
       
    54 @SYMTestActions
       
    55 	Set the brush colour to black and pen colour to green.
       
    56 	Draw a rectangle in the centre of the target.
       
    57 	Set the brush colour to red (and therefore clear colour to red).
       
    58 	Clear the screen.
       
    59 
       
    60 @SYMTestExpectedResults
       
    61 	The target should be filled with red.
       
    62 */ 
       
    63 void CTClear::TestClear()
       
    64 	{
       
    65 	_LIT(KTestName, "Clear-EntireTarget"); 		
       
    66 	if(!iRunningOomTests)
       
    67 		{
       
    68 		INFO_PRINTF1(KTestName);
       
    69 		}
       
    70 	
       
    71 	ResetGc();
       
    72 	
       
    73 	iGc->SetPenSize(TSize(3,3));
       
    74 	iGc->SetBrushColor(TRgb(0,0,0));
       
    75 	iGc->SetPenColor(TRgb(0,255,0));
       
    76 	iGc->DrawRect(TRect(70,70,140,140));
       
    77 	iGc->SetBrushColor(TRgb(255,0,0));
       
    78 	iGc->Clear();
       
    79 	
       
    80 	iGc->SetOrigin(TPoint(0, 1));
       
    81 	iGc->Clear();
       
    82 	
       
    83 	iGc->SetOrigin(TPoint(1, 1));
       
    84 	iGc->Clear();
       
    85 	
       
    86 	TEST(KErrNone == WriteTargetOutput(iTestParams, KTestName()));
       
    87 	TESTNOERROR(iGc->GetError());
       
    88 	}
       
    89 
       
    90 
       
    91 /**
       
    92 @SYMTestCaseID
       
    93 	GRAPHICS-DIRECTGDI-CLEAR-0002
       
    94 
       
    95 @SYMPREQ 
       
    96 	PREQ39
       
    97 
       
    98 @SYMREQ
       
    99 	REQ9195
       
   100 	REQ9201 
       
   101 	REQ9202 
       
   102 	REQ9222 
       
   103 	REQ9223 
       
   104 	REQ9236 
       
   105 	REQ9237
       
   106 
       
   107 @SYMTestCaseDesc
       
   108 	Test that Clear clears a specified rectangle successfully.
       
   109 
       
   110 @SYMTestPriority  
       
   111 	Critical
       
   112 
       
   113 @SYMTestStatus
       
   114 	Implemented
       
   115 
       
   116 @SYMTestActions
       
   117 	Sets brush to red, and clears a rectangle at the top left of the target.
       
   118 	Sets brush to green, and clears a thin rectangle across the entire target, using negative and large rectangle parameters.
       
   119 	Sets brush to black, calls Clear using an empty rect.
       
   120 	Calls Clear using a TRect with all corners at the same point.
       
   121 	Calls Clear using a TRect with no width.
       
   122 	Calls Clear using a TRect with no height.
       
   123 	Calls Clear using a TRect with the bottom-right point defined first.
       
   124 
       
   125 @SYMTestExpectedResults
       
   126 	The first rectangle to be drawn correctly to the target for the regular clear.
       
   127 	A green rectangle across the target when testing large/negative rectangle values.
       
   128 	All other rectangle clears should clear nothing, no error should be set.
       
   129 */ 
       
   130 void CTClear::TestClearRect()
       
   131 	{
       
   132 	_LIT(KTestName, "Clear-Rect"); 		
       
   133 	if(!iRunningOomTests)
       
   134 		{
       
   135 		INFO_PRINTF1(KTestName);
       
   136 		}
       
   137 	
       
   138 	ResetGc();	
       
   139 	
       
   140 	// Regular rectangle clear.
       
   141 	iGc->SetBrushColor(KRgbRed);
       
   142 	iGc->Clear(TRect(20,20, 130,130));
       
   143 
       
   144 	// Test negative points and large points.	
       
   145 	iGc->SetBrushColor(KRgbGreen);
       
   146 	iGc->Clear(TRect(-10,60, 1000,90));
       
   147 	TESTNOERROR(iGc->GetError());
       
   148 	
       
   149 	// Test clearing an empty rectangle
       
   150 	iGc->SetBrushColor(KRgbBlack);
       
   151 	iGc->Clear(TRect(0,0,0,0));
       
   152 	TEST(!iUseDirectGdi || iGc->GetError() == KErrNone);
       
   153 	
       
   154 	// Test clearing a rectangle with all corners matching.
       
   155 	iGc->Clear(TRect(1,1,1,1));
       
   156 	TEST(!iUseDirectGdi || iGc->GetError() == KErrNone);
       
   157 	
       
   158 	// Test clearing a horizontal line.
       
   159 	iGc->Clear(TRect(0,70,150,70));
       
   160 	TEST(!iUseDirectGdi || iGc->GetError() == KErrNone);
       
   161 	
       
   162 	// Test clearing a vertical line.
       
   163 	iGc->Clear(TRect(70,0,70,150));	
       
   164 	TEST(!iUseDirectGdi || iGc->GetError() == KErrNone);
       
   165 	
       
   166 	// Test TRect defined bottom-right first.
       
   167 	iGc->SetBrushColor(KRgbCyan);
       
   168 	iGc->Clear(TRect(50,50,20,20));
       
   169 	TEST(!iUseDirectGdi || iGc->GetError() == KErrNone);
       
   170 	
       
   171 	TEST(KErrNone == WriteTargetOutput(iTestParams, KTestName()));
       
   172 	}
       
   173 
       
   174 
       
   175 /**
       
   176 @SYMTestCaseID
       
   177 	GRAPHICS-DIRECTGDI-CLEAR-0003
       
   178 
       
   179 @SYMPREQ 
       
   180 	PREQ39
       
   181 
       
   182 @SYMREQ
       
   183 	REQ9195
       
   184 	REQ9201 
       
   185 	REQ9202 
       
   186 	REQ9222 
       
   187 	REQ9223 
       
   188 	REQ9236 
       
   189 	REQ9237
       
   190 
       
   191 @SYMTestCaseDesc
       
   192 	Test that when clipping is enabled, Clear clears the defined clipping regions only
       
   193 
       
   194 @SYMTestPriority  
       
   195 	Critical
       
   196 
       
   197 @SYMTestStatus
       
   198 	Implemented
       
   199 
       
   200 @SYMTestActions
       
   201 	Set brush to blue, and clear target.
       
   202 	Set the brush to orange, and set a clipping region.
       
   203 	Call Clear to clear the whole target.
       
   204 
       
   205 @SYMTestExpectedResults
       
   206 	The target should be orange, with a large 'I' shape in the centre in blue.
       
   207  */ 
       
   208 void CTClear::TestClearWithClipping()
       
   209 	{
       
   210 	_LIT(KTestName, "Clear-Clipping"); 	
       
   211 	if(!iRunningOomTests)
       
   212 		{
       
   213 		INFO_PRINTF1(KTestName);
       
   214 		}
       
   215 	
       
   216 	ResetGc();
       
   217 	
       
   218 	// Clear screen in blue
       
   219 	iGc->SetBrushColor(TRgb(0,0,255));
       
   220 	iGc->Clear();
       
   221 	
       
   222 	// Define a clipping region.
       
   223 	RRegion clippingRegion(3);
       
   224 	clippingRegion.AddRect(TRect(10,10, 140, 30));
       
   225 	clippingRegion.AddRect(TRect(60, 10, 90, 140));
       
   226 	clippingRegion.AddRect(TRect(10,120, 140, 140));
       
   227 	
       
   228 	// Clear screen in orange, with clipping region set.
       
   229 	iGc->SetBrushColor(TRgb(255,128,0));
       
   230 	iGc->SetClippingRegion(clippingRegion);
       
   231 	iGc->Clear();
       
   232 	iGc->ResetClippingRegion();
       
   233 	clippingRegion.Close();
       
   234 	
       
   235 	TEST(KErrNone == WriteTargetOutput(iTestParams, KTestName()));
       
   236 	TESTNOERROR(iGc->GetError());
       
   237 	}
       
   238 
       
   239 /**
       
   240 @SYMTestCaseID
       
   241 	GRAPHICS-DIRECTGDI-CLEAR-0004
       
   242 
       
   243 @SYMPREQ 
       
   244 	PREQ39
       
   245 
       
   246 @SYMREQ
       
   247 	REQ9195
       
   248 	REQ9201 
       
   249 	REQ9202 
       
   250 	REQ9222 
       
   251 	REQ9223 
       
   252 	REQ9236 
       
   253 	REQ9237
       
   254 
       
   255 @SYMTestCaseDesc
       
   256 	Test the effects of the different drawmodes on Clear.
       
   257 
       
   258 @SYMTestPriority  
       
   259 	Critical
       
   260 
       
   261 @SYMTestStatus
       
   262 	Implemented
       
   263 
       
   264 @SYMTestActions
       
   265 	Clear the entire target in red.
       
   266 	Set drawmode to EDrawModePEN and clear a rectangular area of the screen in white, with opacity 0.5
       
   267 	Set drawmode to EDrawModeWriteAlpha and clear a different rectangular area of the screen in white.
       
   268 
       
   269 @SYMTestExpectedResults
       
   270 	A pink rectangle on the left (pink because it is white blended with the red underneath) 
       
   271 	and, if the display-mode has an alpha channel there will be a grey rectangle of equal size to the 
       
   272 	right (as it is not blending but using write-alpha), or if the display-mode does not have alpha it will
       
   273 	appear as white. with a darker red surrounding the rectangles. The rectangles are surrounded by a 
       
   274 	red border.
       
   275 */ 
       
   276 void CTClear::TestClearDrawModes()
       
   277 	{
       
   278 	_LIT(KTestName, "Clear-DrawModes"); 		
       
   279 	if(!iRunningOomTests)
       
   280 		{
       
   281 		INFO_PRINTF1(KTestName);
       
   282 		}
       
   283 	
       
   284 	ResetGc();
       
   285 	
       
   286 	// Clear screen in red
       
   287 	iGc->SetBrushColor(TRgb(255,0,0));
       
   288 	iGc->Clear();
       
   289 	// Left rectangle in white, using alpha-blend 50% opacity. 
       
   290 	iGc->SetDrawMode(DirectGdi::EDrawModePEN);
       
   291 	iGc->SetBrushColor(TRgb(255,255,255,128));
       
   292 	iGc->Clear(TRect(10,10,80,140));
       
   293 	// Right rectangle in white, using write-alpha 50% opacity. 
       
   294 	iGc->SetDrawMode(DirectGdi::EDrawModeWriteAlpha);
       
   295 	iGc->SetBrushColor(TRgb(255,255,255,128));
       
   296 	iGc->Clear(TRect(80,10,140,140));
       
   297 	TESTNOERROR(iGc->GetError());
       
   298 	
       
   299 	TEST(KErrNone == WriteTargetOutput(iTestParams, KTestName()));
       
   300 	}
       
   301 
       
   302 
       
   303 /**
       
   304 Override of base class virtual
       
   305 @leave Gets system wide error code
       
   306 @return - TVerdict code
       
   307 */
       
   308 TVerdict CTClear::doTestStepPreambleL()
       
   309 	{			
       
   310 	CTDirectGdiStepBase::doTestStepPreambleL();	
       
   311 	return TestStepResult();
       
   312 	}
       
   313 	
       
   314 /** 
       
   315 Override of base class pure virtual
       
   316 Our implementation only gets called if the base class doTestStepPreambleL() did
       
   317 not leave. That being the case, the current test result value will be EPass.
       
   318 @leave Gets system wide error code
       
   319 @return TVerdict code
       
   320 */	
       
   321 TVerdict CTClear::doTestStepL()
       
   322 	{		
       
   323 	// Test for each pixel format
       
   324 	for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
       
   325 		{
       
   326 		iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
       
   327 		SetTargetL(iTestParams.iTargetPixelFormat);
       
   328 		RunTestsL();
       
   329 		RunOomTestsL();
       
   330 		}
       
   331 	CloseTMSGraphicsStep();
       
   332 
       
   333 	return TestStepResult();
       
   334 	}
       
   335 
       
   336 /**
       
   337 Override of base class pure virtual
       
   338 Lists the tests to be run
       
   339 */
       
   340 void CTClear::RunTestsL()
       
   341 	{	
       
   342 	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CLEAR-0001"));
       
   343 	TestClear();
       
   344 	RecordTestResultL();
       
   345 	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CLEAR-0002"));
       
   346 	TestClearRect();
       
   347 	RecordTestResultL();
       
   348 	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CLEAR-0003"));
       
   349 	TestClearWithClipping();
       
   350 	RecordTestResultL();
       
   351 	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CLEAR-0004"));
       
   352 	TestClearDrawModes();
       
   353 	RecordTestResultL();
       
   354 	}