os/graphics/graphicsdeviceinterface/directgdi/test/tbrushandpen.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdi/test/tbrushandpen.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,811 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "tbrushandpen.h"
    1.20 +#include <e32math.h>
    1.21 +
    1.22 +/**
    1.23 +default brush and pen drawing target size
    1.24 +*/
    1.25 +const TSize KDrawBrushPenDefaultSize(640, 450);
    1.26 +
    1.27 +CTBrushAndPen::CTBrushAndPen()
    1.28 +	{
    1.29 +	SetTestStepName(KTDirectGdiBrushAndPenStep);
    1.30 +	}
    1.31 +
    1.32 +CTBrushAndPen::~CTBrushAndPen()
    1.33 +	{
    1.34 +	}
    1.35 +
    1.36 +
    1.37 +/**
    1.38 +@SYMTestCaseID  
    1.39 +	GRAPHICS-DIRECTGDI-PENBRUSH-0001
    1.40 +
    1.41 +@SYMPREQ 
    1.42 +	PREQ39
    1.43 +
    1.44 +@SYMREQ
    1.45 +	REQ9195
    1.46 +	REQ9201 
    1.47 +	REQ9202 
    1.48 +	REQ9222 
    1.49 +	REQ9223 
    1.50 +	REQ9236 
    1.51 +	REQ9237
    1.52 +
    1.53 +@SYMTestCaseDesc  
    1.54 +	Test drawing with brush.
    1.55 +
    1.56 +@SYMTestPriority 
    1.57 +	High
    1.58 +
    1.59 +@SYMTestStatus
    1.60 +	Implemented
    1.61 +
    1.62 +@SYMTestActions 
    1.63 +	Basic test for pen and brush methods.
    1.64 +	Test the following brush settings:
    1.65 +		- colour
    1.66 +		- style
    1.67 +		Call drawing functions with the following parameters:
    1.68 +			colours from the COLOR_TABLE.
    1.69 +			aBrushStyle
    1.70 +				ENullBrush
    1.71 +				ESolidBrush
    1.72 +				EPatternedBrush 
    1.73 +				EVerticalHatchBrush 
    1.74 +				EForwardDiagonalHatchBrush 
    1.75 +				EHorizontalHatchBrush 
    1.76 +				ERearwardDiagonalHatchBrush 
    1.77 +				ESquareCrossHatchBrush 
    1.78 +				EDiamondCrossHatchBrush 
    1.79 +	Issue shape drawing operations: DrawRect, DrawRoundRect, DrawEllipse, DrawPie, DrawPolygon.
    1.80 +	Draw overlapping shapes to test correctness of brush transparency. 
    1.81 +	Repeat the drawing in write alpha mode (DrawModeWriteAlpha bitmap).	
    1.82 +
    1.83 +@SYMTestExpectedResults
    1.84 +	Brush colours and styles should be correctly drawn for each shape and each draw mode.
    1.85 +	Valid bitmap should be created. This bitmap shall be compared to a reference bitmap.
    1.86 +
    1.87 +@param	aDrawMode	the draw mode to run this test in, only DirectGdi::EDrawModePEN and DirectGdi::EDrawModeWriteAlpha
    1.88 +		are supported
    1.89 +*/
    1.90 +void CTBrushAndPen::TestBrushColorAndStyleL(const DirectGdi::TDrawMode aDrawMode)
    1.91 +	{	
    1.92 +	_LIT(KTestName, "PenBrush-BrushColourStyle_%S"); //test case name		
    1.93 +	_LIT(KDrawModePEN, "DrawModePen"); 
    1.94 +	_LIT(KDrawModeWriteAlpha, "DrawModeWriteAlpha"); 
    1.95 +	TBuf<50> testCaseName;	
    1.96 +	
    1.97 +	switch (aDrawMode)
    1.98 +		{
    1.99 +		case DirectGdi::EDrawModePEN:
   1.100 +			testCaseName.Format(KTestName, &KDrawModePEN);
   1.101 +			break;		
   1.102 +		case DirectGdi::EDrawModeWriteAlpha:
   1.103 +			testCaseName.Format(KTestName, &KDrawModeWriteAlpha);
   1.104 +			break;		
   1.105 +		default:
   1.106 +			// This method should only be called aDrawMode set to DirectGdi::EDrawModePEN or DirectGdi::EDrawModeWriteAlpha
   1.107 +			TESTL(EFalse);
   1.108 +			break;
   1.109 +		}
   1.110 +		
   1.111 +	if(!iRunningOomTests)
   1.112 +		{
   1.113 +		INFO_PRINTF1(testCaseName);	
   1.114 +		}
   1.115 +	
   1.116 +	ResetGc();
   1.117 +	
   1.118 +	// Set the draw mode
   1.119 +	iGc->SetDrawMode(aDrawMode);
   1.120 +	TESTNOERROR(iGc->GetError());
   1.121 +	
   1.122 +	iGc->SetPenStyle(DirectGdi::ESolidPen);
   1.123 +
   1.124 +	// print two row of shapes
   1.125 +	// the second one has overlapping shapes to test alpha blending
   1.126 +	for(TInt j =0; j<2; j++) 
   1.127 +		{
   1.128 +		// draw 8 columns of different shapes with various pen colours
   1.129 +		// brush colours, and brush styles 
   1.130 +		for(TInt i = 0; i<8; i++) 
   1.131 +			{			
   1.132 +			iGc->SetBrushStyle(KBrushStyleTable[i==1?1:i+1]);
   1.133 +		
   1.134 +			TInt startx = 10+i*70 - j*i*10;
   1.135 +			TInt endx = 70+i*70;
   1.136 +			TInt starty = j*263;
   1.137 +			
   1.138 +			//this is setter helper function, see below method definition
   1.139 +			SetHashColors(i,j,1);
   1.140 +			iGc->DrawRect(TRect(startx,starty+10,endx,starty+30));
   1.141 +		
   1.142 +			SetHashColors(i,j,2);
   1.143 +			iGc->DrawRoundRect(TRect(startx,starty+40,endx,starty+60), TSize(10,10));
   1.144 +			
   1.145 +			SetHashColors(i,j,3);
   1.146 +			iGc->DrawPie(TRect(startx,starty+65,endx,starty+125), TPoint(startx,starty+65) , TPoint(endx,starty+65));
   1.147 +			
   1.148 +			// below shapes are not necessary to test alpha blending,
   1.149 +			// so there are drawn only three above shapes with increasing overlap
   1.150 +			if(j == 0) 
   1.151 +				{
   1.152 +				SetHashColors(i,j,4);
   1.153 +				iGc->DrawEllipse(TRect(startx,starty+130 ,endx,starty+190 ));
   1.154 +	
   1.155 +				SetHashColors(i,j,5);
   1.156 +				CArrayFixFlat<TPoint>* pointList = new (ELeave) CArrayFixFlat<TPoint>(6);
   1.157 +				CleanupStack::PushL(pointList);
   1.158 +				pointList->AppendL(TPoint(startx,starty+192));
   1.159 +				pointList->AppendL(TPoint(startx + 50,starty+242));
   1.160 +				pointList->AppendL(TPoint(startx + 10,starty+242));
   1.161 +				pointList->AppendL(TPoint(endx,starty+192));
   1.162 +				pointList->AppendL(TPoint(endx,starty+262));
   1.163 +				pointList->AppendL(TPoint(startx,starty+262));
   1.164 +			
   1.165 +				DirectGdi::TFillRule fillrule = i%2==0 ? DirectGdi::EAlternate : DirectGdi::EWinding;
   1.166 +			
   1.167 +				iGc->DrawPolygon(*pointList ,fillrule);
   1.168 +				CleanupStack::PopAndDestroy(pointList);
   1.169 +				}
   1.170 +			}
   1.171 +		}
   1.172 +	
   1.173 +	// For coverage - test the BrushColor() method works correctly
   1.174 +	iGc->SetBrushColor(KRgbRed);
   1.175 +	TESTL(iGc->BrushColor() == KRgbRed);	
   1.176 +
   1.177 +	TEST(KErrNone == WriteTargetOutput(iTestParams, TPtrC(testCaseName)));
   1.178 +	}
   1.179 +	
   1.180 +/**
   1.181 +Helper method that sets the current pen and brush colours from a color table. The color table used contains a 
   1.182 +palette of 16 standard colors ranging from white to black.
   1.183 +@param aGeneralIndex Used when indexing into the color table for the pen and brush colors, and for setting their alpha values.
   1.184 +@param aAlphaStep Used when setting an alpha value for the pen and the brush, the alpha value is set to (255-aAlphaStep*aGeneralIndex*32).
   1.185 +@param aPenBrushIndex Used when indexing into the color table for the pen and brush colors. The pen color is set to 
   1.186 +KColor16Table[(3*aGeneralIndex+aPenBrushIndex)%16] and the brush color is set to KColor16Table[(5*aGeneralIndex+aPenBrushIndex)%16]. 
   1.187 + */
   1.188 +void CTBrushAndPen::SetHashColors(TInt aGeneralIndex, TInt aAlphaStep, TInt aPenBrushIndex)
   1.189 +	{
   1.190 +	TRgb penColor;
   1.191 +	TRgb brushColor;
   1.192 +	penColor = KColor16Table[(3*aGeneralIndex+aPenBrushIndex)%16];
   1.193 +	penColor.SetAlpha(255-aAlphaStep*aGeneralIndex*32);
   1.194 +	iGc->SetPenColor(penColor);
   1.195 +	brushColor = KColor16Table[(5*aGeneralIndex+aPenBrushIndex)%16];
   1.196 +	brushColor.SetAlpha(255-aAlphaStep*aGeneralIndex*32);
   1.197 +	iGc->SetBrushColor(brushColor);
   1.198 +	}
   1.199 +
   1.200 +/**
   1.201 +@SYMTestCaseID
   1.202 +	GRAPHICS-DIRECTGDI-PENBRUSH-0002
   1.203 +
   1.204 +@SYMPREQ 
   1.205 +	PREQ39
   1.206 +
   1.207 +@SYMREQ
   1.208 +	REQ9195
   1.209 +	REQ9201 
   1.210 +	REQ9202 
   1.211 +	REQ9222 
   1.212 +	REQ9223 
   1.213 +	REQ9236 
   1.214 +	REQ9237
   1.215 +
   1.216 +@SYMTestCaseDesc
   1.217 +	Test for brush pattern functionality: set a brush pattern for a CDirectGdiContext object,
   1.218 +	then check it has a brush pattern. Test that the SetBrushOrigin() method works as expected.
   1.219 +
   1.220 +@SYMTestPriority 
   1.221 +	High
   1.222 +
   1.223 +@SYMTestStatus
   1.224 +	Implemented
   1.225 +
   1.226 +@SYMTestActions
   1.227 +	Test various brush pattern usage scenarios:
   1.228 +	Set it's brush pattern, then check it has a brush pattern.
   1.229 +	Check setting a brush pattern both from a CFbsBitmap and from a handle.
   1.230 +	Test resetting of brush pattern.
   1.231 +	Call functions that use brush during shapes drawing.
   1.232 +	Create a brush pattern image and set it as the brush pattern. Draw a rectangle, move 
   1.233 +	the brush origin to various positions and draw more shapes.
   1.234 +
   1.235 +@SYMTestExpectedResults
   1.236 +	The rectangle is filled correctly for each different brush origins.
   1.237 +	Valid bitmap should be created. This bitmap shall be compared to a reference bitmap.
   1.238 +*/ 
   1.239 +void CTBrushAndPen::TestBrushPatternOriginL()
   1.240 +	{	
   1.241 +	_LIT(KTestName, "PenBrush-BrushPatternOrigin"); //test case name
   1.242 +	if(!iRunningOomTests)
   1.243 +		{
   1.244 +		INFO_PRINTF1(KTestName);
   1.245 +		}
   1.246 +	
   1.247 +	ResetGc();		
   1.248 +	
   1.249 +	// create patterns programatically so we can test EPatternedBrush		
   1.250 +	TUidPixelFormat pixelFormat = iTestParams.iTargetPixelFormat;
   1.251 +	TSize patternSize(56,56);
   1.252 +	CFbsBitmap* pattern = CreateCheckedBoardBitmapL(pixelFormat, patternSize);
   1.253 +	CleanupStack::PushL(pattern);	
   1.254 +	
   1.255 +	CFbsBitmap* pattern2 = CreateCheckedBoardBitmapL(pixelFormat, patternSize);
   1.256 +	CleanupStack::PushL(pattern2);	
   1.257 +
   1.258 +	//draw nine columns of different shapes with various settings 
   1.259 +	// of brush style and brush origin
   1.260 +	for(TInt i = 0; i<9; i++)
   1.261 +		{
   1.262 +		switch(i)
   1.263 +			{
   1.264 +			case 0:
   1.265 +				{
   1.266 +				// (for coverage)
   1.267 +				iGc->ResetBrushPattern();
   1.268 +				
   1.269 +				// Set a brush pattern using CFbsBitmap
   1.270 +				iGc->SetBrushPattern(*pattern);
   1.271 +				TESTNOERRORL(iGc->GetError());
   1.272 +				TEST(iGc->HasBrushPattern());
   1.273 +				
   1.274 +				iGc->SetBrushStyle(DirectGdi::EPatternedBrush);
   1.275 +				break;
   1.276 +				}
   1.277 +			case 1:
   1.278 +				{
   1.279 +				// Check that ResetBrushPattern works
   1.280 +				iGc->ResetBrushPattern();
   1.281 +				TEST(iGc->HasBrushPattern() == EFalse);
   1.282 +				
   1.283 +				// Set a brush pattern using a handle
   1.284 +				iGc->SetBrushPattern(pattern2->Handle());
   1.285 +				TEST(iGc->HasBrushPattern());
   1.286 +			
   1.287 +				iGc->SetBrushStyle(DirectGdi::EPatternedBrush);
   1.288 +				break;
   1.289 +				}
   1.290 +			//change brush origin, and use last settings of brush style	
   1.291 +			case 2:
   1.292 +				{
   1.293 +				// Set a NULL brush pattern, then set the pattern using the handle  
   1.294 +				// for pattern2 (for coverage)
   1.295 +				if(iUseDirectGdi)
   1.296 +					{
   1.297 +					iGc->SetBrushPattern(KNullHandle);				
   1.298 +					TESTL(iGc->GetError() == KErrBadHandle);
   1.299 +					}
   1.300 +				iGc->SetBrushPattern(pattern2->Handle());				
   1.301 +				iGc->SetBrushOrigin(TPoint(10,10));
   1.302 +				break;
   1.303 +				}
   1.304 +			//change brush style and set brush origin
   1.305 +			// in case 4 change only brush origin
   1.306 +			case 3:
   1.307 +				{
   1.308 +				iGc->SetBrushStyle(DirectGdi::EForwardDiagonalHatchBrush);
   1.309 +				iGc->SetPenColor(KRgbGreen);
   1.310 +				iGc->SetBrushColor(KRgbRed);
   1.311 +				iGc->SetBrushOrigin(TPoint(i,i));
   1.312 +				break;
   1.313 +				}
   1.314 +			//change brush style and set brush origin
   1.315 +			// in case 6 change only brush origin
   1.316 +			case 5:
   1.317 +				{
   1.318 +				iGc->SetBrushStyle(DirectGdi::ESquareCrossHatchBrush);
   1.319 +				iGc->SetPenColor(KRgbGreen);
   1.320 +				iGc->SetBrushColor(KRgbRed);
   1.321 +				iGc->SetBrushOrigin(TPoint(i,i));
   1.322 +				break;
   1.323 +				}
   1.324 +			//change brush style and set brush origin
   1.325 +			// in case 8 change only brush origin
   1.326 +			case 7:
   1.327 +				{
   1.328 +				iGc->SetBrushStyle(DirectGdi::EDiamondCrossHatchBrush);
   1.329 +				iGc->SetPenColor(KRgbGreen);
   1.330 +				iGc->SetBrushColor(KRgbRed);
   1.331 +				iGc->SetBrushOrigin(TPoint(i,i));
   1.332 +				break;
   1.333 +				}
   1.334 +			case 4:
   1.335 +			case 6:
   1.336 +			case 8:
   1.337 +				{
   1.338 +				iGc->SetBrushOrigin(TPoint(i,i));
   1.339 +				break;
   1.340 +				}
   1.341 +			}
   1.342 +			
   1.343 +		//draw a set of shapes using current brush
   1.344 +		TInt startx = 10+i*70;
   1.345 +		TInt endx = 70+i*70;
   1.346 +		TInt starty = 0;
   1.347 +		
   1.348 +		iGc->DrawRect(TRect(startx,starty+10,endx,starty+30));
   1.349 +		iGc->DrawRoundRect(TRect(startx,starty+40,endx,starty+60), TSize(10,10));
   1.350 +		iGc->DrawPie(TRect(startx,starty+70,endx,starty+130), TPoint(startx,starty+70) , TPoint(endx,starty+70));
   1.351 +		iGc->DrawEllipse(TRect(startx,starty+130 ,endx,starty+190 ));
   1.352 +		
   1.353 +		CArrayFixFlat<TPoint>* pointList = new (ELeave) CArrayFixFlat<TPoint>(6);
   1.354 +		CleanupStack::PushL(pointList);
   1.355 +		pointList->AppendL(TPoint(startx,starty+200));
   1.356 +		pointList->AppendL(TPoint(startx + 50,starty+250));
   1.357 +		pointList->AppendL(TPoint(startx + 10,starty+250));
   1.358 +		pointList->AppendL(TPoint(endx,starty+200));
   1.359 +		pointList->AppendL(TPoint(endx,starty+270));
   1.360 +		pointList->AppendL(TPoint(startx,starty+270));
   1.361 +	
   1.362 +		iGc->DrawPolygon(*pointList ,DirectGdi::EAlternate);
   1.363 +		CleanupStack::PopAndDestroy(pointList);
   1.364 +		}
   1.365 +	
   1.366 +	// Check that ResetBrushPattern() works
   1.367 +	iGc->ResetBrushPattern();
   1.368 +	TEST(iGc->HasBrushPattern() == EFalse);				
   1.369 +	
   1.370 +	pattern2->Reset();
   1.371 +	TESTNOERROR(iGc->GetError());
   1.372 +
   1.373 +	TEST(KErrNone == WriteTargetOutput(iTestParams, KTestName()));
   1.374 +
   1.375 +	CleanupStack::PopAndDestroy(2, pattern);		
   1.376 +	}
   1.377 +
   1.378 +
   1.379 +/**
   1.380 +@SYMTestCaseID
   1.381 +	GRAPHICS-DIRECTGDI-PENBRUSH-0003
   1.382 +
   1.383 +@SYMPREQ 
   1.384 +	PREQ39
   1.385 +
   1.386 +@SYMREQ
   1.387 +	REQ9195
   1.388 +	REQ9201 
   1.389 +	REQ9202 
   1.390 +	REQ9222 
   1.391 +	REQ9223 
   1.392 +	REQ9236 
   1.393 +	REQ9237
   1.394 +
   1.395 +@SYMTestCaseDesc
   1.396 +	Test pen drawing functionality.
   1.397 +
   1.398 +@SYMTestPriority 
   1.399 +	High
   1.400 +
   1.401 +@SYMTestStatus
   1.402 +	Implemented.
   1.403 +
   1.404 +@SYMTestActions
   1.405 +	Test setting pen colour and size.
   1.406 +	Change pen settings:
   1.407 +		colours from the COLOR_TABLE.
   1.408 +		Iterate over various pen sizes.
   1.409 +	Perform drawing operations that use the pen.
   1.410 +	Use also overlapping shapes to test alpha blending.
   1.411 +
   1.412 +@SYMTestExpectedResults
   1.413 +	Valid bitmap should be created. Shapes will be drawn with correct pen colour and size.
   1.414 +	This bitmap shall be compared to a reference bitmap.
   1.415 +*/ 
   1.416 +void CTBrushAndPen::TestPenColorSizeL(const DirectGdi::TDrawMode aDrawMode)
   1.417 +	{
   1.418 +	_LIT(KTestName, "PenBrush-PenColorSize_%S"); //test case name
   1.419 +	_LIT(KDrawModePEN, "DrawModePen");
   1.420 +	_LIT(KDrawModeWriteAlpha, "DrawModeWriteAlpha");
   1.421 +	TBuf<50> testCaseName;
   1.422 +
   1.423 +	switch (aDrawMode)
   1.424 +		{
   1.425 +		case DirectGdi::EDrawModePEN:
   1.426 +			testCaseName.Format(KTestName, &KDrawModePEN);
   1.427 +			break;
   1.428 +		
   1.429 +		case DirectGdi::EDrawModeWriteAlpha:
   1.430 +			testCaseName.Format(KTestName, &KDrawModeWriteAlpha);
   1.431 +			break;
   1.432 +		
   1.433 +		default:
   1.434 +			// This method should only be called aDrawMode set to DirectGdi::EDrawModePEN or DirectGdi::EDrawModeWriteAlpha
   1.435 +			TESTL(EFalse);
   1.436 +			break;
   1.437 +		}
   1.438 +	
   1.439 +	if(!iRunningOomTests)
   1.440 +		{
   1.441 +		INFO_PRINTF1(testCaseName);	
   1.442 +		}
   1.443 +	
   1.444 +	ResetGc();
   1.445 +
   1.446 +	//draw nine columns of different shapes
   1.447 +	// the last four overlaps to test alpha blending
   1.448 +	for(TInt i = 0 ; i < 9; i++)
   1.449 +		{
   1.450 +		if(i==0)
   1.451 +			{
   1.452 +			iGc->SetBrushStyle(DirectGdi::ESolidBrush);
   1.453 +			iGc->SetBrushColor(KRgbDarkRed);
   1.454 +			}
   1.455 +		else
   1.456 +			{
   1.457 +			iGc->SetBrushStyle(DirectGdi::ENullBrush);
   1.458 +			}
   1.459 +		
   1.460 +		
   1.461 +		TInt stfact = (i<5 ? 0 : i);
   1.462 +		TInt startx = 10+i*70 - stfact*10;
   1.463 +		TInt endx = 70+i*70;
   1.464 +		
   1.465 +		TRgb penColor;
   1.466 +				
   1.467 +		iGc->SetPenSize(TSize(i,i));
   1.468 +		// The sw version allocates memory when you set a pen size and this memory is not freed
   1.469 +		// until after the __UHEAP_MARKEND macro when running OOM tests, this causes a memory 
   1.470 +		// leak when this test leaves. The following TCleanupItem has been added to reset the pen
   1.471 +		// size to 1,1 on account of a leave as settting the pen size to 1,1 deletes the allocated
   1.472 +		// pen memory.
   1.473 +		CleanupStack::PushL(TCleanupItem(ResetPenSize, iGc));
   1.474 +
   1.475 +		penColor = KColor16Table[(5*i+1)%15+1];
   1.476 +		penColor.SetAlpha(255-stfact*30);
   1.477 +		iGc->SetPenColor(penColor);	
   1.478 +		iGc->DrawRect(TRect(startx,10,endx,30));
   1.479 +
   1.480 +		penColor = KColor16Table[(5*i+2)%15+1];
   1.481 +		penColor.SetAlpha(255-stfact*30);
   1.482 +		iGc->SetPenColor(penColor);
   1.483 +		iGc->DrawRoundRect(TRect(startx,40,endx,60), TSize(10,10));
   1.484 +			
   1.485 +		penColor = KColor16Table[(5*i+3)%15+1];
   1.486 +		penColor.SetAlpha(255-stfact*30);
   1.487 +		iGc->SetPenColor(penColor);
   1.488 +		iGc->DrawPie(TRect(startx,70,endx,130), TPoint(startx,70), TPoint(endx,70));
   1.489 +			
   1.490 +		penColor = KColor16Table[(5*i+4)%15+1];
   1.491 +		penColor.SetAlpha(255-stfact*30);
   1.492 +		iGc->SetPenColor(penColor);
   1.493 +		iGc->DrawEllipse(TRect(startx,135 ,endx,195 ));
   1.494 +			
   1.495 +		penColor = KColor16Table[(5*i+5)%15+1];
   1.496 +		penColor.SetAlpha(255-stfact*30);
   1.497 +		CArrayFixFlat<TPoint>* pointList = new (ELeave) CArrayFixFlat<TPoint>(6);
   1.498 +		CleanupStack::PushL(pointList);
   1.499 +		pointList->AppendL(TPoint(startx,200));
   1.500 +		pointList->AppendL(TPoint(startx+50,250));
   1.501 +		pointList->AppendL(TPoint(startx+10,250));
   1.502 +		pointList->AppendL(TPoint(endx,200));
   1.503 +		pointList->AppendL(TPoint(endx,270));
   1.504 +		pointList->AppendL(TPoint(startx,270));
   1.505 +		iGc->SetPenColor(penColor);
   1.506 +		iGc->DrawPolygon(*pointList ,DirectGdi::EAlternate);
   1.507 +		CleanupStack::PopAndDestroy(pointList);
   1.508 +			
   1.509 +		penColor = KColor16Table[(5*i+6)%15+1];
   1.510 +		penColor.SetAlpha(255-stfact*30);
   1.511 +		CArrayFixFlat<TPoint>* pointListPolyLine = new (ELeave) CArrayFixFlat<TPoint>(4);
   1.512 +		CleanupStack::PushL(pointListPolyLine);
   1.513 +	    pointListPolyLine->AppendL(TPoint(startx,280));
   1.514 +	    pointListPolyLine->AppendL(TPoint(endx,320));
   1.515 +	    pointListPolyLine->AppendL(TPoint(startx,320));
   1.516 +	    pointListPolyLine->AppendL(TPoint(endx,280));
   1.517 +		iGc->SetPenColor(penColor);
   1.518 +	    iGc->DrawPolyLine(*pointListPolyLine);
   1.519 +	    CleanupStack::PopAndDestroy(pointListPolyLine);
   1.520 +
   1.521 +	    penColor = KColor16Table[(5*i+7)%15+1];
   1.522 +		penColor.SetAlpha(255-stfact*30);
   1.523 +		iGc->SetPenColor(penColor);
   1.524 +		iGc->DrawArc(TRect(startx,330 ,endx, 360),TPoint(endx,330),TPoint(startx,330));
   1.525 +
   1.526 +	    penColor = KColor16Table[(5*i+8)%15+1];
   1.527 +		penColor.SetAlpha(255-stfact*30);
   1.528 +		iGc->SetPenColor(penColor);
   1.529 +	    iGc->DrawLine(TPoint(startx,355),TPoint(endx,375));
   1.530 +	    
   1.531 +	    penColor = KColor16Table[(5*i+8)%15+1];
   1.532 +		penColor.SetAlpha(255-stfact*30);
   1.533 +		pointListPolyLine = new (ELeave) CArrayFixFlat<TPoint>(4);
   1.534 +		CleanupStack::PushL(pointListPolyLine);
   1.535 +	    pointListPolyLine->AppendL(TPoint(startx,400));
   1.536 +	    pointListPolyLine->AppendL(TPoint(endx,440));
   1.537 +	    pointListPolyLine->AppendL(TPoint(startx,440));
   1.538 +	    pointListPolyLine->AppendL(TPoint(endx,400));
   1.539 +		iGc->SetPenColor(penColor);		
   1.540 +	    iGc->DrawPolyLineNoEndPoint(*pointListPolyLine);
   1.541 +	    CleanupStack::PopAndDestroy(pointListPolyLine);
   1.542 +	    
   1.543 +	    CleanupStack::PopAndDestroy(1);
   1.544 +		}
   1.545 +
   1.546 +	TEST(KErrNone == WriteTargetOutput(iTestParams, TPtrC(testCaseName)));
   1.547 +	}
   1.548 +
   1.549 +/**
   1.550 +@SYMTestCaseID
   1.551 +	GRAPHICS-DIRECTGDI-PENBRUSH-0004
   1.552 +
   1.553 +@SYMPREQ 
   1.554 +	PREQ39
   1.555 +
   1.556 +@SYMREQ
   1.557 +	REQ9195
   1.558 +	REQ9201 
   1.559 +	REQ9202 
   1.560 +	REQ9222 
   1.561 +	REQ9223 
   1.562 +	REQ9236 
   1.563 +	REQ9237
   1.564 +
   1.565 +@SYMTestCaseDesc
   1.566 +	Test drawing with various brush styles.
   1.567 +
   1.568 +@SYMTestPriority 
   1.569 +	High
   1.570 +
   1.571 +@SYMTestStatus
   1.572 +	Implemented
   1.573 +
   1.574 +@SYMTestActions
   1.575 +	Test setting pen style.
   1.576 +	Set pen style:
   1.577 +	Call functions that use pen during shapes drawing and are affected by the pen
   1.578 +	style (DrawLine(), DrawPolyLine(), DrawRect(), DrawPolygon();.
   1.579 +
   1.580 +@SYMTestExpectedResults
   1.581 +	Valid bitmap should be created. Shapes will be drawn with correct pen style. This
   1.582 +	bitmap shall be compared to a reference bitmap.
   1.583 +*/
   1.584 +void CTBrushAndPen::TestPenStyleL()
   1.585 +	{
   1.586 +	_LIT(KTestName, "PenBrush-PenStyle"); //test case name		
   1.587 +	if(!iRunningOomTests)
   1.588 +		{
   1.589 +		INFO_PRINTF1(KTestName);
   1.590 +		}
   1.591 +	
   1.592 +	ResetGc();	
   1.593 +
   1.594 +	//draw nine columns of different shapes with 
   1.595 +	// various pen style settigns
   1.596 +	for(TInt i = 0 ; i < 9; i++)
   1.597 +		{
   1.598 +		TInt colindx = ( i < 6 ? i : i+1 );
   1.599 +		iGc->SetPenStyle(KPenStyleTable[colindx%6]);
   1.600 +		
   1.601 +		iGc->SetPenColor(KColor16Table[(i+6)%16]);	
   1.602 +		iGc->DrawRect(TRect(10+i*70,10,70+i*70,30));
   1.603 +		
   1.604 +		iGc->DrawLine(TPoint(10+i*70,40),TPoint(70+i*70,190));
   1.605 +		iGc->DrawLine(TPoint(70+i*70,40),TPoint(10+i*70,190));
   1.606 +			
   1.607 +		CArrayFixFlat<TPoint>* pointList = new (ELeave) CArrayFixFlat<TPoint>(6);
   1.608 +		CleanupStack::PushL(pointList);
   1.609 +		pointList->AppendL(TPoint(10+i*70,200));
   1.610 +		pointList->AppendL(TPoint(60+i*70,250));
   1.611 +		pointList->AppendL(TPoint(20+i*70,250));
   1.612 +		pointList->AppendL(TPoint(70+i*70,200));
   1.613 +		pointList->AppendL(TPoint(70+i*70,270));
   1.614 +		pointList->AppendL(TPoint(10+i*70,270));
   1.615 +		
   1.616 +		iGc->DrawPolygon(*pointList ,DirectGdi::EAlternate);
   1.617 +		CleanupStack::PopAndDestroy(pointList);
   1.618 +			
   1.619 +		CArrayFixFlat<TPoint>* pointListPolyLine = new (ELeave) CArrayFixFlat<TPoint>(4);
   1.620 +		CleanupStack::PushL(pointListPolyLine);
   1.621 +	    pointListPolyLine->AppendL(TPoint(10+i*70,280));
   1.622 +	    pointListPolyLine->AppendL(TPoint(70+i*70,320));
   1.623 +	    pointListPolyLine->AppendL(TPoint(10+i*70,320));
   1.624 +	    pointListPolyLine->AppendL(TPoint(70+i*70,280));
   1.625 +
   1.626 +	    iGc->DrawPolyLine(*pointListPolyLine);
   1.627 +		    
   1.628 +	    CleanupStack::PopAndDestroy(pointListPolyLine);
   1.629 +	    		    
   1.630 +	    iGc->DrawLine(TPoint(10+i*70,370),TPoint(70+i*70,370));
   1.631 +		}
   1.632 +
   1.633 +	TEST(KErrNone == WriteTargetOutput(iTestParams, KTestName()));
   1.634 +	}
   1.635 +
   1.636 +/**
   1.637 +@SYMTestCaseID  
   1.638 +	GRAPHICS-DIRECTGDI-PENBRUSH-0005
   1.639 +
   1.640 +@SYMPREQ 
   1.641 +	PREQ39
   1.642 +
   1.643 +@SYMREQ
   1.644 +	REQ9195
   1.645 +	REQ9201 
   1.646 +	REQ9202 
   1.647 +	REQ9222 
   1.648 +	REQ9223 
   1.649 +	REQ9236 
   1.650 +	REQ9237
   1.651 +
   1.652 +@SYMTestPriority
   1.653 +	High
   1.654 +
   1.655 +@SYMTestStatus
   1.656 +	Implemented
   1.657 +
   1.658 +@SYMTestCaseDesc
   1.659 +	Test shape drawing functions invalid pen and brush parameters handling.
   1.660 +
   1.661 +@SYMTestActions		
   1.662 +	Draw a rectangle with pen style not from DirectGdi::TPenStyle enum.
   1.663 +	Draw a ellipse with brush style not from DirectGdi::TBrushStyle enum.
   1.664 +	Use negative pen size.
   1.665 +
   1.666 +@SYMTestExpectedResults
   1.667 +	Shapes should be drawn with default brush and pen settings when invalid paramaters are used.
   1.668 +*/
   1.669 +void CTBrushAndPen::TestBrushAndPenInvalidParametersL()
   1.670 +	{	
   1.671 +	//there is no way in BitGDI to check if KErrArgument error occured,
   1.672 +	//so this is test only in DirectGDI
   1.673 +	if(!iUseDirectGdi)
   1.674 +		return;
   1.675 +		
   1.676 +	_LIT(KTestName, "PenBrush-InvalidParameters"); //test case name				
   1.677 +	if(!iRunningOomTests)
   1.678 +		{
   1.679 +		INFO_PRINTF1(KTestName);
   1.680 +		}
   1.681 +	
   1.682 +	ResetGc();				
   1.683 +	
   1.684 +	TInt i;
   1.685 +	for(i = 0; i<6; i++)
   1.686 +		{
   1.687 +		switch (i)
   1.688 +			{
   1.689 +			case 0:
   1.690 +				{
   1.691 +				iGc->SetPenStyle(static_cast<DirectGdi::TPenStyle>(-1));
   1.692 +				CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
   1.693 +				break;
   1.694 +				}
   1.695 +			case 1:
   1.696 +				{
   1.697 +				iGc->SetPenStyle(static_cast<DirectGdi::TPenStyle>(10));
   1.698 +				CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
   1.699 +				iGc->SetPenSize(TSize(3,3));
   1.700 +				break;
   1.701 +				}
   1.702 +			case 2:
   1.703 +				{
   1.704 +				iGc->SetPenStyle(DirectGdi::ESolidPen);
   1.705 +				iGc->SetPenSize(TSize(-1,-1));
   1.706 +				CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
   1.707 +				break;
   1.708 +				}
   1.709 +			case 3:
   1.710 +				{
   1.711 +				iGc->SetPenStyle(static_cast<DirectGdi::TPenStyle>(-1));
   1.712 +				CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
   1.713 +				iGc->SetPenSize(TSize(-3,-3));
   1.714 +				CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
   1.715 +				break;
   1.716 +				}
   1.717 +			case 4:
   1.718 +				{
   1.719 +				iGc->SetPenStyle(DirectGdi::ESolidPen);
   1.720 +				iGc->SetPenSize(TSize(1,1));
   1.721 +				iGc->SetBrushStyle(static_cast<DirectGdi::TBrushStyle>(-1));
   1.722 +				CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
   1.723 +				break;
   1.724 +				}
   1.725 +			case 5:
   1.726 +				{
   1.727 +				iGc->SetPenStyle(DirectGdi::ESolidPen);
   1.728 +				iGc->SetPenSize(TSize(1,1));
   1.729 +				iGc->SetBrushStyle(static_cast<DirectGdi::TBrushStyle>(20));
   1.730 +				CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
   1.731 +				break;
   1.732 +				}
   1.733 +			}
   1.734 +
   1.735 +		TInt startx = 5+i*70;
   1.736 +		TInt endx = 65+i*70;
   1.737 +		iGc->DrawRect(TRect(startx,10,endx,30));
   1.738 +		TESTNOERROR(iGc->GetError());
   1.739 +		iGc->DrawRoundRect(TRect(startx,40,endx,60), TSize(10,10));
   1.740 +		TESTNOERROR(iGc->GetError());
   1.741 +		iGc->DrawPie(TRect(startx,70,endx,130), TPoint(30,0), TPoint(150,0));
   1.742 +		TESTNOERROR(iGc->GetError());
   1.743 +		iGc->DrawEllipse(TRect(startx,130,endx,190));
   1.744 +		TESTNOERROR(iGc->GetError());
   1.745 +		iGc->DrawArc(TRect(startx,190,endx,250),TPoint(endx,250),TPoint(startx,190));
   1.746 +		TESTNOERROR(iGc->GetError());
   1.747 +		iGc->DrawLine(TPoint(startx,270), TPoint(endx,270));
   1.748 +		TESTNOERROR(iGc->GetError());
   1.749 +		}
   1.750 +	
   1.751 +	TEST(KErrNone == WriteTargetOutput(iTestParams, KTestName()));
   1.752 +	}
   1.753 +
   1.754 +/**
   1.755 +Override of base class virtual
   1.756 +@leave Gets system wide error code
   1.757 +@return - TVerdict code
   1.758 +*/
   1.759 +TVerdict CTBrushAndPen::doTestStepPreambleL()
   1.760 +	{			
   1.761 +	CTDirectGdiStepBase::doTestStepPreambleL();	
   1.762 +	return TestStepResult();
   1.763 +	}
   1.764 +	
   1.765 +/** 
   1.766 +Override of base class pure virtual
   1.767 +Our implementation only gets called if the base class doTestStepPreambleL() did
   1.768 +not leave. That being the case, the current test result value will be EPass.
   1.769 +@leave Gets system wide error code
   1.770 +@return TVerdict code
   1.771 +*/	
   1.772 +TVerdict CTBrushAndPen::doTestStepL()
   1.773 +	{		
   1.774 +	// Test for each pixel format
   1.775 +	for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
   1.776 +		{
   1.777 +		iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
   1.778 +		SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KDrawBrushPenDefaultSize);
   1.779 +		
   1.780 +		RunTestsL();
   1.781 +		RunOomTestsL();
   1.782 +		}
   1.783 +	CloseTMSGraphicsStep();
   1.784 +	return TestStepResult();
   1.785 +	}
   1.786 +
   1.787 +/**
   1.788 +Override of base class pure virtual
   1.789 +Lists the tests to be run
   1.790 +*/
   1.791 +void CTBrushAndPen::RunTestsL()
   1.792 +	{	
   1.793 +	SetTestStepID(_L("GRAPHICS-DIRECTGDI-PENBRUSH-0001"));
   1.794 +	TestBrushColorAndStyleL(DirectGdi::EDrawModePEN);
   1.795 +	RecordTestResultL();
   1.796 +	SetTestStepID(_L("GRAPHICS-DIRECTGDI-PENBRUSH-0005"));
   1.797 +	TestBrushAndPenInvalidParametersL();
   1.798 +	RecordTestResultL();
   1.799 +	SetTestStepID(_L("GRAPHICS-DIRECTGDI-PENBRUSH-0002"));
   1.800 +	TestBrushPatternOriginL();
   1.801 +	RecordTestResultL();
   1.802 +	SetTestStepID(_L("GRAPHICS-DIRECTGDI-PENBRUSH-0004"));
   1.803 +	TestPenStyleL();
   1.804 +	RecordTestResultL();
   1.805 +	if(!iRunningOomTests || iUseDirectGdi) // disable pen color and size tests for BitGdi Oom
   1.806 +		{
   1.807 +		SetTestStepID(_L("GRAPHICS-DIRECTGDI-PENBRUSH-0003"));
   1.808 +		TestPenColorSizeL(DirectGdi::EDrawModePEN);
   1.809 +		RecordTestResultL();
   1.810 +		SetTestStepID(_L("GRAPHICS-DIRECTGDI-PENBRUSH-0003"));
   1.811 +		TestPenColorSizeL(DirectGdi::EDrawModeWriteAlpha);
   1.812 +		RecordTestResultL();
   1.813 +		}
   1.814 +	}