graphicsdeviceinterface/directgdi/test/tbitbltbase.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 "tbitbltbase.h"
       
    17 
       
    18 
       
    19 CTBitBltBase::CTBitBltBase()
       
    20 	{
       
    21 	
       
    22 	}
       
    23 
       
    24 CTBitBltBase::~CTBitBltBase()
       
    25 	{
       
    26 	}
       
    27 
       
    28 /** 
       
    29 Override of base class pure virtual
       
    30 Our implementation only gets called if the base class doTestStepPreambleL() did
       
    31 not leave. That being the case, the current test result value will be EPass.
       
    32 @leave Gets system wide error code
       
    33 @return TVerdict code
       
    34 */	
       
    35 TVerdict CTBitBltBase::doTestStepL()
       
    36 	{
       
    37 	// Test for each target pixel format
       
    38 	for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
       
    39 		{
       
    40 		iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
       
    41 		TBuf<KPixelFormatNameLength> targetPixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iTargetPixelFormat));
       
    42 
       
    43 		// Test for each source pixel format
       
    44 		for(TInt sourcePixelFormatIndex = iSourcePixelFormatArray.Count() - 1; sourcePixelFormatIndex >= 0; sourcePixelFormatIndex--)
       
    45 			{
       
    46 			TBool isEColor256 = EFalse;
       
    47 			iTestParams.iSourcePixelFormat = iSourcePixelFormatArray[sourcePixelFormatIndex];
       
    48 			if(EUidPixelFormatP_8 == iTestParams.iSourcePixelFormat)
       
    49 				isEColor256 = ETrue;
       
    50 			TBuf<KPixelFormatNameLength> sourcePixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iSourcePixelFormat));
       
    51 
       
    52 			INFO_PRINTF3(_L("Target Pixel Format: %S;  Source Pixel Format: %S"), &targetPixelFormatName, &sourcePixelFormatName);
       
    53 
       
    54 			// small target
       
    55 			SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KTarget1Size);
       
    56 			iLargeTarget = EFalse;
       
    57 			
       
    58 			// create source bitmaps for tests
       
    59 			CreateBitmapsL(iTestParams.iSourcePixelFormat);
       
    60 			RunTestsL();
       
    61 			// only run OOM tests for one target pixel format to prevent duplication of tests
       
    62 			if ((targetPixelFormatIndex == 0) && isEColor256)
       
    63 				{
       
    64 				RunOomTestsL();  //from base class
       
    65 				}
       
    66 			// delete source bitmaps
       
    67 			DeleteBitmaps();
       
    68 						
       
    69 			// large target
       
    70 			SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KTarget2Size);
       
    71 			iLargeTarget = ETrue;
       
    72 			
       
    73 			// create source bitmaps for tests
       
    74 			CreateBitmapsL(iTestParams.iSourcePixelFormat);
       
    75 			RunTestsL();
       
    76 			if ((targetPixelFormatIndex == 0) && isEColor256)
       
    77 				{
       
    78 				RunOomTestsL();  //from base class
       
    79 				}
       
    80 			// delete source bitmaps
       
    81 			DeleteBitmaps();
       
    82 			}
       
    83 		}
       
    84 	CloseTMSGraphicsStep();
       
    85 
       
    86 	return TestStepResult();
       
    87 	}
       
    88 
       
    89 /**
       
    90 Override of base class virtual
       
    91 @leave Gets system wide error code
       
    92 @return - TVerdict code
       
    93 */
       
    94 TVerdict CTBitBltBase::doTestStepPreambleL()
       
    95 	{
       
    96 	CTDirectGdiStepBase::doTestStepPreambleL();
       
    97 	return TestStepResult();
       
    98 	}
       
    99 
       
   100 /**
       
   101 Override of base class virtual
       
   102 @leave Gets system wide error code
       
   103 @return - TVerdict code
       
   104 */
       
   105 TVerdict CTBitBltBase::doTestStepPostambleL()
       
   106 	{
       
   107 	DeleteBitmaps();
       
   108 	CTDirectGdiStepBase::doTestStepPostambleL();
       
   109 	return TestStepResult();
       
   110 	}
       
   111 
       
   112 /**
       
   113 Write target output.
       
   114 Call method from base class with test case name and source pixel format string.
       
   115 @param aTestCaseName Name of test case.
       
   116 */
       
   117 void CTBitBltBase::WriteTargetOutput(TPtrC aTestCaseName)
       
   118 	{	
       
   119 	TBuf<KFileNameLength> postfix;
       
   120 	postfix.Append(KSourceString);
       
   121 	postfix.Append(KSeparator);
       
   122 	postfix.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(iTestParams.iSourcePixelFormat));
       
   123 	
       
   124 	TESTNOERROR(CTDirectGdiStepBase::WriteTargetOutput(iTestParams, aTestCaseName, &postfix));
       
   125 	}
       
   126 
       
   127 /**
       
   128 Create set of bitmaps needed for tests.
       
   129 @param aPixelFormat Source pixel format of bitmap.
       
   130 */
       
   131 void CTBitBltBase::CreateBitmapsL(TUidPixelFormat aPixelFormat)
       
   132 	{
       
   133 	iNotInitialisedBitmap = new (ELeave)CFbsBitmap();
       
   134 	iZeroSizeBitmap	 = new (ELeave)CFbsBitmap();
       
   135 	TESTNOERRORL(iZeroSizeBitmap->Create(TSize(0,0),TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
       
   136 	iCompressedBitmap = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap2Size, TSize(8, 8));
       
   137 	iCompressedBitmap->Compress();
       
   138 	iCompressedBitmapSmall = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap1Size, TSize(2,2));
       
   139 	iCompressedBitmapSmall->Compress();
       
   140 	iCheckedBoardBitmap1 = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap1Size, KBitmap1Size);
       
   141 	iCheckedBoardBitmap2 = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap2Size, TSize(8, 8));
       
   142 	iConcentricRectsBitmap1 = CreateConcentricRectsBitmapL(aPixelFormat, KBitmap1Size);
       
   143 	iConcentricRectsBitmap2 = CreateConcentricRectsBitmapL(aPixelFormat, KBitmap2Size);
       
   144 	iCheckedBoardWithAlphaBitmap = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap2Size, TSize(16, 16), ETrue);
       
   145 	}
       
   146 
       
   147 /**
       
   148 Delete set of test bitmaps.
       
   149 */
       
   150 void CTBitBltBase::DeleteBitmaps()
       
   151 	{	
       
   152 	delete iNotInitialisedBitmap;
       
   153 	iNotInitialisedBitmap = NULL;
       
   154 	delete iZeroSizeBitmap;
       
   155 	iZeroSizeBitmap = NULL;
       
   156 	delete iCompressedBitmap;
       
   157 	iCompressedBitmap = NULL;
       
   158 	delete iCompressedBitmapSmall;
       
   159 	iCompressedBitmapSmall = NULL;
       
   160 	delete iCheckedBoardBitmap1;
       
   161 	iCheckedBoardBitmap1 = NULL;
       
   162 	delete iCheckedBoardBitmap2;
       
   163 	iCheckedBoardBitmap2 = NULL;
       
   164 	delete iConcentricRectsBitmap1;
       
   165 	iConcentricRectsBitmap1 = NULL;
       
   166 	delete iConcentricRectsBitmap2;
       
   167 	iConcentricRectsBitmap2 = NULL;
       
   168 	delete iCheckedBoardWithAlphaBitmap;
       
   169 	iCheckedBoardWithAlphaBitmap = NULL;
       
   170 	}
       
   171 
       
   172 /**
       
   173 Common positioning test function for BitBlt() and DrawBitmap() tests.
       
   174 The test iterates positions over whole target, outside target and on the target boundaries
       
   175 and call tested function for those positions.
       
   176 @param aTestName Name of test case.
       
   177 @param aFunc Tested function. EBitBlt and EDrawBitmap are supported.
       
   178 */
       
   179 void CTBitBltBase::TestPositioningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
       
   180 	{	
       
   181 	CFbsBitmap* bitmap;
       
   182 	if(iTestParams.iDoCompressed)
       
   183 		{
       
   184 		bitmap = iCompressedBitmap;
       
   185 		}
       
   186 	else
       
   187 		{
       
   188 		bitmap = iConcentricRectsBitmap1;
       
   189 		}
       
   190 	
       
   191 	TInt width = iGdiTarget->SizeInPixels().iWidth;
       
   192 	TInt height = iGdiTarget->SizeInPixels().iHeight;
       
   193 	TInt bmpWidth = bitmap->SizeInPixels().iWidth;
       
   194 	TInt bmpHeight = bitmap->SizeInPixels().iHeight;
       
   195 	TSize bmpSize(bmpWidth, bmpHeight);
       
   196 
       
   197 	// test two versions of function
       
   198 	for(TInt i = 0; i < 2; i++)
       
   199 		{
       
   200 		ResetGc();
       
   201 
       
   202 		TPositionIterator posIterator(-30, width+30, bmpWidth, -30, height+30, bmpHeight);
       
   203 		posIterator.Begin();
       
   204 
       
   205 		do
       
   206 			{
       
   207 			//It is done to shift the rectangle drawn. It gives a slope effect in the image.
       
   208 			TPoint pos(posIterator.iPosX+posIterator.iIndexY, posIterator.iPosY+posIterator.iIndexX);
       
   209 			if(aFunc == EBitBlt)
       
   210 				{
       
   211 				if(i == 0)
       
   212 					{
       
   213 					iGc->BitBlt(pos, *bitmap);
       
   214 					}
       
   215 				else
       
   216 					{
       
   217 					// additionally source rect size is iterated
       
   218 					iGc->BitBlt(pos, *bitmap, TRect(TPoint(0, 0), TSize(posIterator.iIndexX, posIterator.iIndexY)));
       
   219 					}
       
   220 				}
       
   221 			else // (aFunc == EDrawBitmap)
       
   222 				{
       
   223 				if(i == 0)
       
   224 					{
       
   225 					iGc->DrawBitmap(TRect(pos, bmpSize), *bitmap);
       
   226 					}
       
   227 				else
       
   228 					{
       
   229 					// additionally source rect size is iterated
       
   230 					iGc->DrawBitmap(TRect(pos, bmpSize),*bitmap, TRect(TPoint(0, 0), TSize(posIterator.iIndexX, posIterator.iIndexY)));
       
   231 					}
       
   232 				}
       
   233 			}
       
   234 		while(posIterator.Next());
       
   235 
       
   236 		TESTNOERRORL(iGc->GetError());
       
   237 
       
   238 		if(!iTestParams.iDoCompressed)
       
   239 			{
       
   240 			// add 1 or 2 to test case name to identity function version
       
   241 			TBuf<30> testName;
       
   242 			testName.Append(aTestName);
       
   243 			testName.AppendNum(i+1);
       
   244 			WriteTargetOutput(testName);
       
   245 			}
       
   246 		}
       
   247 	}
       
   248 
       
   249 /**
       
   250 Common invalid parameters test function for BitBlt() and DrawBitmap() tests.
       
   251 The function tests against invalid source rectangle, zero size source bitmap
       
   252 (both cases should return KErrArgument) and not initialised source bitmap (should
       
   253 return KErrBadHandle).
       
   254 @param aTestName Name of test case.
       
   255 @param aFunc Tested function. EBitBlt and EDrawBitmap are supported.
       
   256 */
       
   257 void CTBitBltBase::TestInvalidParametersBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
       
   258 	{		
       
   259 	ResetGc();
       
   260 
       
   261 	CFbsBitmap* bitmap = iConcentricRectsBitmap2;
       
   262 
       
   263 	TInt bmpWidth = bitmap->SizeInPixels().iWidth;
       
   264 	TInt bmpHeight = bitmap->SizeInPixels().iHeight;
       
   265 
       
   266 	// invalid source rectangle
       
   267 	RArray<TRect> rectArray;
       
   268 	CleanupClosePushL(rectArray);
       
   269 	TInt err = KErrNone;
       
   270 	err |= rectArray.Append(TRect(-30, -30, -10, -10));
       
   271 	err |= rectArray.Append(TRect(bmpWidth+10, bmpHeight+10, bmpWidth+20, bmpHeight+20));
       
   272 	err |= rectArray.Append(TRect(bmpWidth, bmpHeight, 0, 0));
       
   273 	err |= rectArray.Append(TRect(-10, -10, -30, -30));
       
   274 	err |= rectArray.Append(TRect(0, 0, 0, 0));
       
   275 	TESTL(KErrNone == err);
       
   276 	
       
   277 	for(TInt i = 0; i < rectArray.Count(); i++)
       
   278 		{
       
   279 		if(aFunc == EBitBlt)
       
   280 			{
       
   281 			iGc->BitBlt(TPoint(i*20, 0), *bitmap, rectArray[i]);
       
   282 			}
       
   283 		else // (aFunc == EDrawBitmap)
       
   284 			{
       
   285 			iGc->DrawBitmap(TRect(TPoint(i*20, 0), TSize(50, 50)), *bitmap, rectArray[i]);
       
   286 			}
       
   287 		}
       
   288 
       
   289 	TESTNOERRORL(iGc->GetError());
       
   290 
       
   291 	CleanupStack::PopAndDestroy(&rectArray);
       
   292 
       
   293 	if(aFunc == EBitBlt)
       
   294 		{
       
   295 		// invalid source bitmap, zero size bitmap
       
   296 		iGc->BitBlt(TPoint(0, 20), *iZeroSizeBitmap);
       
   297 		CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
       
   298 		
       
   299 		iGc->BitBlt(TPoint(20, 20), *iZeroSizeBitmap, TRect(TPoint(0, 0), TSize(0, 0)));
       
   300 		CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
       
   301 
       
   302 		// invalid source bitmap, not initialised bitmap
       
   303 		iGc->BitBlt(TPoint(0, 40), *iNotInitialisedBitmap);
       
   304 		CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
       
   305 		
       
   306 		iGc->BitBlt(TPoint(20, 40), *iNotInitialisedBitmap, TRect(TPoint(0, 0), TSize(0, 0)));
       
   307 		CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
       
   308 		}
       
   309 	else // (aFunc == EDrawBitmap)
       
   310 		{
       
   311 		// invalid source bitmap, zero size bitmap
       
   312 		iGc->DrawBitmap(TRect(TPoint(0, 20), TSize(50, 50)), *iZeroSizeBitmap);
       
   313 		CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
       
   314 		
       
   315 		iGc->DrawBitmap(TRect(TPoint(20, 20), TSize(50, 50)), *iZeroSizeBitmap,	TRect(TPoint(0, 0), TSize(10, 10)));
       
   316 		CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
       
   317 
       
   318 		// invalid source bitmap, not initialised bitmap
       
   319 		iGc->DrawBitmap(TRect(TPoint(0, 40), TSize(50, 50)), *iNotInitialisedBitmap);
       
   320 		CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
       
   321 		
       
   322 		iGc->DrawBitmap(TRect(TPoint(20, 40), TSize(50, 50)), *iNotInitialisedBitmap,
       
   323 				TRect(TPoint(0, 0), TSize(10, 10)));
       
   324 		CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
       
   325 		}
       
   326 
       
   327 	// test if target is still clear
       
   328 	TBool res = TestTargetL(KRgbWhite); 
       
   329 	TEST(res);
       
   330 	// output the bitmap if there was an error to assist with debugging
       
   331 	if (res == EFalse)
       
   332 		{			
       
   333 		WriteTargetOutput(aTestName);
       
   334 		}
       
   335 	}
       
   336 
       
   337 /**
       
   338 Common source bitmap cloning test function for BitBlt() and DrawBitmap() tests.
       
   339 @param aTestName Name of test case.
       
   340 @param aFunc Tested function. EBitBlt and EDrawBitmap are supported.
       
   341 */
       
   342 void CTBitBltBase::TestSourceBitmapCloningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
       
   343 	{
       
   344 	ResetGc();
       
   345 
       
   346 	TSize bmpSize(KBitmap2Size);
       
   347 
       
   348 	for(TInt i = 0; i < 5; i++)
       
   349 		{
       
   350 		CFbsBitmap* bitmap = CreateConcentricRectsBitmapL(iTestParams.iSourcePixelFormat, bmpSize);
       
   351 		if(iTestParams.iDoCompressed)
       
   352 			bitmap->Compress();
       
   353 			
       
   354 		if(aFunc == EBitBlt)
       
   355 			{
       
   356 			iGc->BitBlt(TPoint(55-35+i*10+1, -60+80+i*7+i), *bitmap);
       
   357 			}
       
   358 		else // (aFunc == EDrawBitmap)
       
   359 			{
       
   360 			iGc->DrawBitmap(TRect(TPoint(55-35+i*10+1, -60+80+i*7+i), bmpSize), *bitmap);
       
   361 			}
       
   362 
       
   363 		delete bitmap;
       
   364 		bitmap = NULL;
       
   365 
       
   366 		bmpSize -= TSize(10, 15);
       
   367 		}
       
   368 	
       
   369 	TESTNOERRORL(iGc->GetError());
       
   370 	if(!iTestParams.iDoCompressed)
       
   371 		WriteTargetOutput(aTestName);
       
   372 	}