os/graphics/graphicsdeviceinterface/directgdi/test/tclipping.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdi/test/tclipping.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,337 @@
     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 "tclipping.h"
    1.20 +
    1.21 +CTClipping::CTClipping()
    1.22 +	{
    1.23 +	SetTestStepName(KTDirectGdiClippingStep);
    1.24 +	}
    1.25 +
    1.26 +CTClipping::~CTClipping()
    1.27 +	{
    1.28 +	}
    1.29 +			
    1.30 +/**
    1.31 +@SYMTestCaseID  
    1.32 +	GRAPHICS-DIRECTGDI-CLIPPING-0001
    1.33 +	
    1.34 +@SYMPREQ 
    1.35 +	PREQ39
    1.36 +
    1.37 +@SYMREQ
    1.38 +	REQ9195
    1.39 +	REQ9201 
    1.40 +	REQ9202 
    1.41 +	REQ9222 
    1.42 +	REQ9223 
    1.43 +	REQ9236 
    1.44 +	REQ9237
    1.45 +	
    1.46 +@SYMTestCaseDesc  
    1.47 +	Tests setting clipping regions.
    1.48 +	
    1.49 +@SYMTestPriority  
    1.50 +	High
    1.51 +	
    1.52 +@SYMTestStatus 
    1.53 +	Implemented
    1.54 +	
    1.55 +@SYMTestActions 
    1.56 +	Set the clipping region consisting of a number of rectangles. Blit a bitmap. 
    1.57 +	Reset the clipping region.
    1.58 +	
    1.59 +@SYMTestExpectedResults 
    1.60 +	Bitmap should be drawn only within the clipped regions successfully.
    1.61 +*/
    1.62 +void CTClipping::TestClippingBasicL()
    1.63 +	{	
    1.64 +	_LIT(KTestName, "Clipping-Basic"); 
    1.65 +	if(!iRunningOomTests)
    1.66 +		{
    1.67 +		INFO_PRINTF1(KTestName);
    1.68 +		}
    1.69 +	
    1.70 +	CFbsBitmap* bitmap = CreateCheckedBoardBitmapL(iTestParams.iTargetPixelFormat, TSize(150,150));
    1.71 +	TESTL(bitmap != NULL);
    1.72 +	RRegion clippingRegion(8);
    1.73 +	clippingRegion.AddRect(TRect(10,10,40,40)); // normal square clipping rect
    1.74 +	clippingRegion.AddRect(TRect(60,70,67,132));	// normal rectangular clipping rect
    1.75 +	clippingRegion.AddRect(TRect(50,75,110,85));	// clipping rect crosses another clipping rect
    1.76 +	clippingRegion.AddRect(TRect(125,125,125,125));	// clipping rect with zero size
    1.77 +	clippingRegion.AddRect(TRect(50,30,45,25));	// clipping rect with negative size
    1.78 +	
    1.79 +	ResetGc();
    1.80 +	iGc->SetClippingRegion(clippingRegion);
    1.81 +	TESTNOERROR(iGc->GetError());
    1.82 +	iGc->BitBlt(TPoint(0, 0), *bitmap);
    1.83 +	TESTNOERROR(iGc->GetError());
    1.84 +	iGc->ResetClippingRegion();
    1.85 +	TESTNOERROR(iGc->GetError());
    1.86 +	clippingRegion.Close();
    1.87 +	delete bitmap;
    1.88 +	if (iUseDirectGdi && !iUseSwDirectGdi)
    1.89 +		{
    1.90 +		iVgImageCache->ResetCache();
    1.91 +		}
    1.92 +
    1.93 +	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(KTestName)));
    1.94 +	}
    1.95 +
    1.96 +
    1.97 +
    1.98 +/**
    1.99 +@SYMTestCaseID 
   1.100 +	GRAPHICS-DIRECTGDI-CLIPPING-0002
   1.101 +	
   1.102 +@SYMPREQ 
   1.103 +	PREQ39
   1.104 +
   1.105 +@SYMREQ
   1.106 +	REQ9195
   1.107 +	REQ9201 
   1.108 +	REQ9202 
   1.109 +	REQ9222 
   1.110 +	REQ9223 
   1.111 +	REQ9236 
   1.112 +	REQ9237
   1.113 +	
   1.114 +@SYMTestCaseDesc  
   1.115 +	Tests the argument checking within SetClippingRegion(TRegion&).
   1.116 +	
   1.117 +@SYMTestPriority  
   1.118 +	High
   1.119 +	
   1.120 +@SYMTestStatus 
   1.121 +	Implemented  
   1.122 +	
   1.123 +@SYMTestActions 
   1.124 +	1. Test a region that is outside the bounds of the target.  
   1.125 +	2. Test a region which is partially outside the bounds of the target.
   1.126 +	3. Test using a region which has its error flag set.
   1.127 +	
   1.128 +@SYMTestExpectedResults 
   1.129 +	Test should return KErrArgument.
   1.130 +*/
   1.131 +void CTClipping::TestClippingErrors()
   1.132 +	{	
   1.133 +	_LIT(KTestName, "Clipping-Errors"); 
   1.134 +	if(!iRunningOomTests)
   1.135 +		{
   1.136 +		INFO_PRINTF1(KTestName);
   1.137 +		}
   1.138 +	
   1.139 +	RRegion outOfBoundsRegion(TRect(200,200,220,220));	// clipping rect wholly outside target area
   1.140 +	RRegion partOutOfBoundsRegion(TRect(80,-10,100,25));	// clipping rect partially outside target area
   1.141 +	TRegionFix<1> regionWithError(TRect(50,75,110,85));
   1.142 +	//add more rects than region can hold to set error flag
   1.143 +	regionWithError.AddRect(TRect(0,0,5,5));
   1.144 +
   1.145 +	ResetGc();
   1.146 +	
   1.147 +	// Test whether setting clipping region returns  error when passed invalid clipping regions
   1.148 +	// 1: Pass region wholly outside of target.
   1.149 +	iGc->SetClippingRegion(outOfBoundsRegion);
   1.150 +	TEST(KErrArgument == iGc->GetError());
   1.151 +	iGc->ResetClippingRegion();
   1.152 +	TESTNOERROR(iGc->GetError());
   1.153 +	// 2: Pass region partially outside of target.
   1.154 +	iGc->SetClippingRegion(partOutOfBoundsRegion);
   1.155 +	TEST(KErrArgument == iGc->GetError());
   1.156 +	iGc->ResetClippingRegion();
   1.157 +	TESTNOERROR(iGc->GetError());
   1.158 +	// 3: Pass region with error flag set.
   1.159 +	iGc->SetClippingRegion(regionWithError);
   1.160 +	TEST(KErrArgument == iGc->GetError());
   1.161 +	iGc->ResetClippingRegion();
   1.162 +	TESTNOERROR(iGc->GetError());
   1.163 +	outOfBoundsRegion.Close();
   1.164 +	partOutOfBoundsRegion.Close();
   1.165 +	}
   1.166 +
   1.167 +/**
   1.168 +@SYMTestCaseID  
   1.169 +	GRAPHICS-DIRECTGDI-CLIPPING-0003
   1.170 +	
   1.171 +@SYMPREQ 
   1.172 +	PREQ39
   1.173 +
   1.174 +@SYMREQ
   1.175 +	REQ9195
   1.176 +	REQ9201 
   1.177 +	REQ9202 
   1.178 +	REQ9222 
   1.179 +	REQ9223 
   1.180 +	REQ9236 
   1.181 +	REQ9237
   1.182 +	
   1.183 +@SYMTestCaseDesc  
   1.184 +	Tests using clipping regions while using various APIs to draw images, using a non-zero origin.
   1.185 +	
   1.186 +@SYMTestPriority  
   1.187 +	High
   1.188 +	
   1.189 +@SYMTestStatus 
   1.190 +	Implemented
   1.191 +	
   1.192 +@SYMTestActions 
   1.193 +	Create a bitmap.
   1.194 +	Set a clipping region rectangle (50,50) from the top-left of the target.
   1.195 +	Set the origin to 50,50.
   1.196 +	Draw an image using BitBlt() at (0,0).
   1.197 +	Reset the clipping.
   1.198 +	Set a clipping region rectangle (150,50) from the top-left of the target.
   1.199 +	Set the origin to 150,50.
   1.200 +	Draw an image using DrawBitmap() at (0,0).
   1.201 +	Reset the clipping.
   1.202 +	Set a clipping region rectangle (50,150) from the top-left of the target.
   1.203 +	Set the origin to 50,150.
   1.204 +	Draw an image using BitBltMasked() at (0,0).
   1.205 +	Reset the clipping.
   1.206 +	Set a clipping region rectangle (150,150) from the top-left of the target.
   1.207 +	Set the origin to 150,150.
   1.208 +	Draw an image using DrawBitmapMasked() at (0,0).
   1.209 +	
   1.210 +@SYMTestExpectedResults 
   1.211 +	The first bitmap should be drawn, 50,50 from the top-left of the target. 
   1.212 +	The second bitmap should be drawn, 100,50 from the top-left of the target.
   1.213 +	The third bitmap should be drawn, 50,100 from the top-left of the target.
   1.214 +	The fourth bitmap should be drawn, 100,100 from the top-left of the target.
   1.215 +	None of them should be clipped because although it is always being drawn at (0,0), the
   1.216 +	drawing and the clipping should take into account the Origin offset.
   1.217 +*/
   1.218 +void CTClipping::TestClippingWithOriginL()
   1.219 +	{	
   1.220 +	_LIT(KTestName, "Clipping-WithOrigin"); 
   1.221 +	if(!iRunningOomTests)
   1.222 +		{
   1.223 +		INFO_PRINTF1(KTestName);
   1.224 +		}
   1.225 +	
   1.226 +	ResetGc();
   1.227 +	
   1.228 +	const TSize bitmapSrcSize = TSize(40,40);
   1.229 +	
   1.230 +	CFbsBitmap* bitmap = CreateCheckedBoardBitmapL(iTestParams.iTargetPixelFormat, bitmapSrcSize);
   1.231 +	CleanupStack::PushL(bitmap);
   1.232 +	CFbsBitmap* mask = CreateBlackWhiteBitmapL(iTestParams.iTargetPixelFormat, bitmapSrcSize, TSize(2,2));
   1.233 +	CleanupStack::PushL(mask);
   1.234 +	
   1.235 +	// Test with BitBlt().
   1.236 +	iGc->SetOrigin(TPoint(50,50));
   1.237 +	RRegion clippingRegion(1);
   1.238 +	clippingRegion.AddRect(TRect(TPoint(50,50), TSize(50,50)));
   1.239 +	iGc->SetClippingRegion(clippingRegion);
   1.240 +	iGc->BitBlt(TPoint(0,0), *bitmap);
   1.241 +	iGc->ResetClippingRegion();
   1.242 +	clippingRegion.Close();
   1.243 +	TESTNOERROR(iGc->GetError());
   1.244 +	
   1.245 +	// Test with DrawBitmap() with scaling.
   1.246 +	iGc->SetOrigin(TPoint(150, 50));
   1.247 +	clippingRegion.AddRect(TRect(TPoint(150,50), TSize(50,50)));
   1.248 +	iGc->SetClippingRegion(clippingRegion);
   1.249 +	iGc->DrawBitmap(TRect(TPoint(0,0), TSize(50,50)), *bitmap, TRect(TPoint(0,0), bitmapSrcSize));
   1.250 +	iGc->ResetClippingRegion();
   1.251 +	clippingRegion.Close();
   1.252 +	TESTNOERROR(iGc->GetError());
   1.253 +	
   1.254 +	// Test with BitBltMasked().
   1.255 +	iGc->SetOrigin(TPoint(50, 150));
   1.256 +	clippingRegion.AddRect(TRect(TPoint(50,150), TSize(50,50)));
   1.257 +	iGc->SetClippingRegion(clippingRegion);
   1.258 +	iGc->BitBltMasked(TPoint(0,0), *bitmap, TRect(TPoint(0,0), bitmapSrcSize), *mask, EFalse);
   1.259 +	iGc->ResetClippingRegion();
   1.260 +	clippingRegion.Close();	
   1.261 +	TESTNOERROR(iGc->GetError());
   1.262 +	
   1.263 +	// Test with DrawBitmapMasked().
   1.264 +	iGc->SetOrigin(TPoint(150, 150));
   1.265 +	clippingRegion.AddRect(TRect(TPoint(150,150), TSize(50,50)));
   1.266 +	iGc->SetClippingRegion(clippingRegion);
   1.267 +	iGc->DrawBitmapMasked(TRect(TPoint(0,0), TSize(50,50)), *bitmap, TRect(TPoint(0,0), bitmapSrcSize), *mask, EFalse);
   1.268 +	iGc->ResetClippingRegion();
   1.269 +	clippingRegion.Close();	
   1.270 +	TESTNOERROR(iGc->GetError());
   1.271 +	
   1.272 +	CleanupStack::PopAndDestroy(2, bitmap);
   1.273 +	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(KTestName)));
   1.274 +	}
   1.275 +
   1.276 +/**
   1.277 +Override of base class virtual
   1.278 +@leave Gets system wide error code
   1.279 +@return - TVerdict code
   1.280 +*/
   1.281 +TVerdict CTClipping::doTestStepPreambleL()
   1.282 +	{			
   1.283 +	CTDirectGdiStepBase::doTestStepPreambleL();	
   1.284 +	return TestStepResult();
   1.285 +	}
   1.286 +	
   1.287 +/** 
   1.288 +Override of base class pure virtual
   1.289 +Our implementation only gets called if the base class doTestStepPreambleL() did
   1.290 +not leave. That being the case, the current test result value will be EPass.
   1.291 +@leave Gets system wide error code
   1.292 +@return TVerdict code
   1.293 +*/	
   1.294 +TVerdict CTClipping::doTestStepL()
   1.295 +	{
   1.296 +	// Test for each pixel format
   1.297 +	for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
   1.298 +		{
   1.299 +		iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
   1.300 +		SetTargetL(iTestParams.iTargetPixelFormat);	
   1.301 +		RunTestsL();
   1.302 +		// only run OOM tests for one target pixel format to prevent duplication of tests
   1.303 +		if (targetPixelFormatIndex == 0)
   1.304 +			{
   1.305 +			RunOomTestsL();  //from base class
   1.306 +			}
   1.307 +		}
   1.308 +	CloseTMSGraphicsStep();
   1.309 +	return TestStepResult();
   1.310 +	}
   1.311 +
   1.312 +/**
   1.313 +Override of base class pure virtual
   1.314 +Lists the tests to be run
   1.315 +*/
   1.316 +void CTClipping::RunTestsL()
   1.317 +	{
   1.318 +	if(iUseDirectGdi && !iUseSwDirectGdi)
   1.319 +		{
   1.320 +		// At least one clipping test uses BitBlt() or DrawBitmap().
   1.321 +		// In the event that a test leaves after a BitBlt() or DrawBitmap() has occurred
   1.322 +		// the vgimage cache will need to be reset.
   1.323 +		// This needs to be the first item on the cleanupstack, 
   1.324 +		// as some tests perform pushes and pops of bitmaps.
   1.325 +		CleanupStack::PushL(TCleanupItem(ResetCache, iVgImageCache));
   1.326 +		}
   1.327 +	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CLIPPING-0001"));
   1.328 +	TestClippingBasicL();
   1.329 +	RecordTestResultL();
   1.330 +	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CLIPPING-0002"));
   1.331 +	TestClippingErrors();
   1.332 +	RecordTestResultL();
   1.333 +	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CLIPPING-0003"));
   1.334 +	TestClippingWithOriginL();
   1.335 +	RecordTestResultL();
   1.336 +	if(iUseDirectGdi && !iUseSwDirectGdi)
   1.337 +		{
   1.338 +		CleanupStack::PopAndDestroy(iVgImageCache);
   1.339 +		}
   1.340 +	}