1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdi/test/tbitbltbase.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,372 @@
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 "tbitbltbase.h"
1.20 +
1.21 +
1.22 +CTBitBltBase::CTBitBltBase()
1.23 + {
1.24 +
1.25 + }
1.26 +
1.27 +CTBitBltBase::~CTBitBltBase()
1.28 + {
1.29 + }
1.30 +
1.31 +/**
1.32 +Override of base class pure virtual
1.33 +Our implementation only gets called if the base class doTestStepPreambleL() did
1.34 +not leave. That being the case, the current test result value will be EPass.
1.35 +@leave Gets system wide error code
1.36 +@return TVerdict code
1.37 +*/
1.38 +TVerdict CTBitBltBase::doTestStepL()
1.39 + {
1.40 + // Test for each target pixel format
1.41 + for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
1.42 + {
1.43 + iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
1.44 + TBuf<KPixelFormatNameLength> targetPixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iTargetPixelFormat));
1.45 +
1.46 + // Test for each source pixel format
1.47 + for(TInt sourcePixelFormatIndex = iSourcePixelFormatArray.Count() - 1; sourcePixelFormatIndex >= 0; sourcePixelFormatIndex--)
1.48 + {
1.49 + TBool isEColor256 = EFalse;
1.50 + iTestParams.iSourcePixelFormat = iSourcePixelFormatArray[sourcePixelFormatIndex];
1.51 + if(EUidPixelFormatP_8 == iTestParams.iSourcePixelFormat)
1.52 + isEColor256 = ETrue;
1.53 + TBuf<KPixelFormatNameLength> sourcePixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iSourcePixelFormat));
1.54 +
1.55 + INFO_PRINTF3(_L("Target Pixel Format: %S; Source Pixel Format: %S"), &targetPixelFormatName, &sourcePixelFormatName);
1.56 +
1.57 + // small target
1.58 + SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KTarget1Size);
1.59 + iLargeTarget = EFalse;
1.60 +
1.61 + // create source bitmaps for tests
1.62 + CreateBitmapsL(iTestParams.iSourcePixelFormat);
1.63 + RunTestsL();
1.64 + // only run OOM tests for one target pixel format to prevent duplication of tests
1.65 + if ((targetPixelFormatIndex == 0) && isEColor256)
1.66 + {
1.67 + RunOomTestsL(); //from base class
1.68 + }
1.69 + // delete source bitmaps
1.70 + DeleteBitmaps();
1.71 +
1.72 + // large target
1.73 + SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KTarget2Size);
1.74 + iLargeTarget = ETrue;
1.75 +
1.76 + // create source bitmaps for tests
1.77 + CreateBitmapsL(iTestParams.iSourcePixelFormat);
1.78 + RunTestsL();
1.79 + if ((targetPixelFormatIndex == 0) && isEColor256)
1.80 + {
1.81 + RunOomTestsL(); //from base class
1.82 + }
1.83 + // delete source bitmaps
1.84 + DeleteBitmaps();
1.85 + }
1.86 + }
1.87 + CloseTMSGraphicsStep();
1.88 +
1.89 + return TestStepResult();
1.90 + }
1.91 +
1.92 +/**
1.93 +Override of base class virtual
1.94 +@leave Gets system wide error code
1.95 +@return - TVerdict code
1.96 +*/
1.97 +TVerdict CTBitBltBase::doTestStepPreambleL()
1.98 + {
1.99 + CTDirectGdiStepBase::doTestStepPreambleL();
1.100 + return TestStepResult();
1.101 + }
1.102 +
1.103 +/**
1.104 +Override of base class virtual
1.105 +@leave Gets system wide error code
1.106 +@return - TVerdict code
1.107 +*/
1.108 +TVerdict CTBitBltBase::doTestStepPostambleL()
1.109 + {
1.110 + DeleteBitmaps();
1.111 + CTDirectGdiStepBase::doTestStepPostambleL();
1.112 + return TestStepResult();
1.113 + }
1.114 +
1.115 +/**
1.116 +Write target output.
1.117 +Call method from base class with test case name and source pixel format string.
1.118 +@param aTestCaseName Name of test case.
1.119 +*/
1.120 +void CTBitBltBase::WriteTargetOutput(TPtrC aTestCaseName)
1.121 + {
1.122 + TBuf<KFileNameLength> postfix;
1.123 + postfix.Append(KSourceString);
1.124 + postfix.Append(KSeparator);
1.125 + postfix.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(iTestParams.iSourcePixelFormat));
1.126 +
1.127 + TESTNOERROR(CTDirectGdiStepBase::WriteTargetOutput(iTestParams, aTestCaseName, &postfix));
1.128 + }
1.129 +
1.130 +/**
1.131 +Create set of bitmaps needed for tests.
1.132 +@param aPixelFormat Source pixel format of bitmap.
1.133 +*/
1.134 +void CTBitBltBase::CreateBitmapsL(TUidPixelFormat aPixelFormat)
1.135 + {
1.136 + iNotInitialisedBitmap = new (ELeave)CFbsBitmap();
1.137 + iZeroSizeBitmap = new (ELeave)CFbsBitmap();
1.138 + TESTNOERRORL(iZeroSizeBitmap->Create(TSize(0,0),TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
1.139 + iCompressedBitmap = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap2Size, TSize(8, 8));
1.140 + iCompressedBitmap->Compress();
1.141 + iCompressedBitmapSmall = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap1Size, TSize(2,2));
1.142 + iCompressedBitmapSmall->Compress();
1.143 + iCheckedBoardBitmap1 = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap1Size, KBitmap1Size);
1.144 + iCheckedBoardBitmap2 = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap2Size, TSize(8, 8));
1.145 + iConcentricRectsBitmap1 = CreateConcentricRectsBitmapL(aPixelFormat, KBitmap1Size);
1.146 + iConcentricRectsBitmap2 = CreateConcentricRectsBitmapL(aPixelFormat, KBitmap2Size);
1.147 + iCheckedBoardWithAlphaBitmap = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap2Size, TSize(16, 16), ETrue);
1.148 + }
1.149 +
1.150 +/**
1.151 +Delete set of test bitmaps.
1.152 +*/
1.153 +void CTBitBltBase::DeleteBitmaps()
1.154 + {
1.155 + delete iNotInitialisedBitmap;
1.156 + iNotInitialisedBitmap = NULL;
1.157 + delete iZeroSizeBitmap;
1.158 + iZeroSizeBitmap = NULL;
1.159 + delete iCompressedBitmap;
1.160 + iCompressedBitmap = NULL;
1.161 + delete iCompressedBitmapSmall;
1.162 + iCompressedBitmapSmall = NULL;
1.163 + delete iCheckedBoardBitmap1;
1.164 + iCheckedBoardBitmap1 = NULL;
1.165 + delete iCheckedBoardBitmap2;
1.166 + iCheckedBoardBitmap2 = NULL;
1.167 + delete iConcentricRectsBitmap1;
1.168 + iConcentricRectsBitmap1 = NULL;
1.169 + delete iConcentricRectsBitmap2;
1.170 + iConcentricRectsBitmap2 = NULL;
1.171 + delete iCheckedBoardWithAlphaBitmap;
1.172 + iCheckedBoardWithAlphaBitmap = NULL;
1.173 + }
1.174 +
1.175 +/**
1.176 +Common positioning test function for BitBlt() and DrawBitmap() tests.
1.177 +The test iterates positions over whole target, outside target and on the target boundaries
1.178 +and call tested function for those positions.
1.179 +@param aTestName Name of test case.
1.180 +@param aFunc Tested function. EBitBlt and EDrawBitmap are supported.
1.181 +*/
1.182 +void CTBitBltBase::TestPositioningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
1.183 + {
1.184 + CFbsBitmap* bitmap;
1.185 + if(iTestParams.iDoCompressed)
1.186 + {
1.187 + bitmap = iCompressedBitmap;
1.188 + }
1.189 + else
1.190 + {
1.191 + bitmap = iConcentricRectsBitmap1;
1.192 + }
1.193 +
1.194 + TInt width = iGdiTarget->SizeInPixels().iWidth;
1.195 + TInt height = iGdiTarget->SizeInPixels().iHeight;
1.196 + TInt bmpWidth = bitmap->SizeInPixels().iWidth;
1.197 + TInt bmpHeight = bitmap->SizeInPixels().iHeight;
1.198 + TSize bmpSize(bmpWidth, bmpHeight);
1.199 +
1.200 + // test two versions of function
1.201 + for(TInt i = 0; i < 2; i++)
1.202 + {
1.203 + ResetGc();
1.204 +
1.205 + TPositionIterator posIterator(-30, width+30, bmpWidth, -30, height+30, bmpHeight);
1.206 + posIterator.Begin();
1.207 +
1.208 + do
1.209 + {
1.210 + //It is done to shift the rectangle drawn. It gives a slope effect in the image.
1.211 + TPoint pos(posIterator.iPosX+posIterator.iIndexY, posIterator.iPosY+posIterator.iIndexX);
1.212 + if(aFunc == EBitBlt)
1.213 + {
1.214 + if(i == 0)
1.215 + {
1.216 + iGc->BitBlt(pos, *bitmap);
1.217 + }
1.218 + else
1.219 + {
1.220 + // additionally source rect size is iterated
1.221 + iGc->BitBlt(pos, *bitmap, TRect(TPoint(0, 0), TSize(posIterator.iIndexX, posIterator.iIndexY)));
1.222 + }
1.223 + }
1.224 + else // (aFunc == EDrawBitmap)
1.225 + {
1.226 + if(i == 0)
1.227 + {
1.228 + iGc->DrawBitmap(TRect(pos, bmpSize), *bitmap);
1.229 + }
1.230 + else
1.231 + {
1.232 + // additionally source rect size is iterated
1.233 + iGc->DrawBitmap(TRect(pos, bmpSize),*bitmap, TRect(TPoint(0, 0), TSize(posIterator.iIndexX, posIterator.iIndexY)));
1.234 + }
1.235 + }
1.236 + }
1.237 + while(posIterator.Next());
1.238 +
1.239 + TESTNOERRORL(iGc->GetError());
1.240 +
1.241 + if(!iTestParams.iDoCompressed)
1.242 + {
1.243 + // add 1 or 2 to test case name to identity function version
1.244 + TBuf<30> testName;
1.245 + testName.Append(aTestName);
1.246 + testName.AppendNum(i+1);
1.247 + WriteTargetOutput(testName);
1.248 + }
1.249 + }
1.250 + }
1.251 +
1.252 +/**
1.253 +Common invalid parameters test function for BitBlt() and DrawBitmap() tests.
1.254 +The function tests against invalid source rectangle, zero size source bitmap
1.255 +(both cases should return KErrArgument) and not initialised source bitmap (should
1.256 +return KErrBadHandle).
1.257 +@param aTestName Name of test case.
1.258 +@param aFunc Tested function. EBitBlt and EDrawBitmap are supported.
1.259 +*/
1.260 +void CTBitBltBase::TestInvalidParametersBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
1.261 + {
1.262 + ResetGc();
1.263 +
1.264 + CFbsBitmap* bitmap = iConcentricRectsBitmap2;
1.265 +
1.266 + TInt bmpWidth = bitmap->SizeInPixels().iWidth;
1.267 + TInt bmpHeight = bitmap->SizeInPixels().iHeight;
1.268 +
1.269 + // invalid source rectangle
1.270 + RArray<TRect> rectArray;
1.271 + CleanupClosePushL(rectArray);
1.272 + TInt err = KErrNone;
1.273 + err |= rectArray.Append(TRect(-30, -30, -10, -10));
1.274 + err |= rectArray.Append(TRect(bmpWidth+10, bmpHeight+10, bmpWidth+20, bmpHeight+20));
1.275 + err |= rectArray.Append(TRect(bmpWidth, bmpHeight, 0, 0));
1.276 + err |= rectArray.Append(TRect(-10, -10, -30, -30));
1.277 + err |= rectArray.Append(TRect(0, 0, 0, 0));
1.278 + TESTL(KErrNone == err);
1.279 +
1.280 + for(TInt i = 0; i < rectArray.Count(); i++)
1.281 + {
1.282 + if(aFunc == EBitBlt)
1.283 + {
1.284 + iGc->BitBlt(TPoint(i*20, 0), *bitmap, rectArray[i]);
1.285 + }
1.286 + else // (aFunc == EDrawBitmap)
1.287 + {
1.288 + iGc->DrawBitmap(TRect(TPoint(i*20, 0), TSize(50, 50)), *bitmap, rectArray[i]);
1.289 + }
1.290 + }
1.291 +
1.292 + TESTNOERRORL(iGc->GetError());
1.293 +
1.294 + CleanupStack::PopAndDestroy(&rectArray);
1.295 +
1.296 + if(aFunc == EBitBlt)
1.297 + {
1.298 + // invalid source bitmap, zero size bitmap
1.299 + iGc->BitBlt(TPoint(0, 20), *iZeroSizeBitmap);
1.300 + CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
1.301 +
1.302 + iGc->BitBlt(TPoint(20, 20), *iZeroSizeBitmap, TRect(TPoint(0, 0), TSize(0, 0)));
1.303 + CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
1.304 +
1.305 + // invalid source bitmap, not initialised bitmap
1.306 + iGc->BitBlt(TPoint(0, 40), *iNotInitialisedBitmap);
1.307 + CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
1.308 +
1.309 + iGc->BitBlt(TPoint(20, 40), *iNotInitialisedBitmap, TRect(TPoint(0, 0), TSize(0, 0)));
1.310 + CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
1.311 + }
1.312 + else // (aFunc == EDrawBitmap)
1.313 + {
1.314 + // invalid source bitmap, zero size bitmap
1.315 + iGc->DrawBitmap(TRect(TPoint(0, 20), TSize(50, 50)), *iZeroSizeBitmap);
1.316 + CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
1.317 +
1.318 + iGc->DrawBitmap(TRect(TPoint(20, 20), TSize(50, 50)), *iZeroSizeBitmap, TRect(TPoint(0, 0), TSize(10, 10)));
1.319 + CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
1.320 +
1.321 + // invalid source bitmap, not initialised bitmap
1.322 + iGc->DrawBitmap(TRect(TPoint(0, 40), TSize(50, 50)), *iNotInitialisedBitmap);
1.323 + CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
1.324 +
1.325 + iGc->DrawBitmap(TRect(TPoint(20, 40), TSize(50, 50)), *iNotInitialisedBitmap,
1.326 + TRect(TPoint(0, 0), TSize(10, 10)));
1.327 + CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
1.328 + }
1.329 +
1.330 + // test if target is still clear
1.331 + TBool res = TestTargetL(KRgbWhite);
1.332 + TEST(res);
1.333 + // output the bitmap if there was an error to assist with debugging
1.334 + if (res == EFalse)
1.335 + {
1.336 + WriteTargetOutput(aTestName);
1.337 + }
1.338 + }
1.339 +
1.340 +/**
1.341 +Common source bitmap cloning test function for BitBlt() and DrawBitmap() tests.
1.342 +@param aTestName Name of test case.
1.343 +@param aFunc Tested function. EBitBlt and EDrawBitmap are supported.
1.344 +*/
1.345 +void CTBitBltBase::TestSourceBitmapCloningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
1.346 + {
1.347 + ResetGc();
1.348 +
1.349 + TSize bmpSize(KBitmap2Size);
1.350 +
1.351 + for(TInt i = 0; i < 5; i++)
1.352 + {
1.353 + CFbsBitmap* bitmap = CreateConcentricRectsBitmapL(iTestParams.iSourcePixelFormat, bmpSize);
1.354 + if(iTestParams.iDoCompressed)
1.355 + bitmap->Compress();
1.356 +
1.357 + if(aFunc == EBitBlt)
1.358 + {
1.359 + iGc->BitBlt(TPoint(55-35+i*10+1, -60+80+i*7+i), *bitmap);
1.360 + }
1.361 + else // (aFunc == EDrawBitmap)
1.362 + {
1.363 + iGc->DrawBitmap(TRect(TPoint(55-35+i*10+1, -60+80+i*7+i), bmpSize), *bitmap);
1.364 + }
1.365 +
1.366 + delete bitmap;
1.367 + bitmap = NULL;
1.368 +
1.369 + bmpSize -= TSize(10, 15);
1.370 + }
1.371 +
1.372 + TESTNOERRORL(iGc->GetError());
1.373 + if(!iTestParams.iDoCompressed)
1.374 + WriteTargetOutput(aTestName);
1.375 + }