Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "tbitbltbase.h"
19 CTBitBltBase::CTBitBltBase()
24 CTBitBltBase::~CTBitBltBase()
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
35 TVerdict CTBitBltBase::doTestStepL()
37 // Test for each target pixel format
38 for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
40 iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
41 TBuf<KPixelFormatNameLength> targetPixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iTargetPixelFormat));
43 // Test for each source pixel format
44 for(TInt sourcePixelFormatIndex = iSourcePixelFormatArray.Count() - 1; sourcePixelFormatIndex >= 0; sourcePixelFormatIndex--)
46 TBool isEColor256 = EFalse;
47 iTestParams.iSourcePixelFormat = iSourcePixelFormatArray[sourcePixelFormatIndex];
48 if(EUidPixelFormatP_8 == iTestParams.iSourcePixelFormat)
50 TBuf<KPixelFormatNameLength> sourcePixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iSourcePixelFormat));
52 INFO_PRINTF3(_L("Target Pixel Format: %S; Source Pixel Format: %S"), &targetPixelFormatName, &sourcePixelFormatName);
55 SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KTarget1Size);
56 iLargeTarget = EFalse;
58 // create source bitmaps for tests
59 CreateBitmapsL(iTestParams.iSourcePixelFormat);
61 // only run OOM tests for one target pixel format to prevent duplication of tests
62 if ((targetPixelFormatIndex == 0) && isEColor256)
64 RunOomTestsL(); //from base class
66 // delete source bitmaps
70 SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KTarget2Size);
73 // create source bitmaps for tests
74 CreateBitmapsL(iTestParams.iSourcePixelFormat);
76 if ((targetPixelFormatIndex == 0) && isEColor256)
78 RunOomTestsL(); //from base class
80 // delete source bitmaps
84 CloseTMSGraphicsStep();
86 return TestStepResult();
90 Override of base class virtual
91 @leave Gets system wide error code
92 @return - TVerdict code
94 TVerdict CTBitBltBase::doTestStepPreambleL()
96 CTDirectGdiStepBase::doTestStepPreambleL();
97 return TestStepResult();
101 Override of base class virtual
102 @leave Gets system wide error code
103 @return - TVerdict code
105 TVerdict CTBitBltBase::doTestStepPostambleL()
108 CTDirectGdiStepBase::doTestStepPostambleL();
109 return TestStepResult();
114 Call method from base class with test case name and source pixel format string.
115 @param aTestCaseName Name of test case.
117 void CTBitBltBase::WriteTargetOutput(TPtrC aTestCaseName)
119 TBuf<KFileNameLength> postfix;
120 postfix.Append(KSourceString);
121 postfix.Append(KSeparator);
122 postfix.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(iTestParams.iSourcePixelFormat));
124 TESTNOERROR(CTDirectGdiStepBase::WriteTargetOutput(iTestParams, aTestCaseName, &postfix));
128 Create set of bitmaps needed for tests.
129 @param aPixelFormat Source pixel format of bitmap.
131 void CTBitBltBase::CreateBitmapsL(TUidPixelFormat aPixelFormat)
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);
148 Delete set of test bitmaps.
150 void CTBitBltBase::DeleteBitmaps()
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;
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.
179 void CTBitBltBase::TestPositioningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
182 if(iTestParams.iDoCompressed)
184 bitmap = iCompressedBitmap;
188 bitmap = iConcentricRectsBitmap1;
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);
197 // test two versions of function
198 for(TInt i = 0; i < 2; i++)
202 TPositionIterator posIterator(-30, width+30, bmpWidth, -30, height+30, bmpHeight);
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);
213 iGc->BitBlt(pos, *bitmap);
217 // additionally source rect size is iterated
218 iGc->BitBlt(pos, *bitmap, TRect(TPoint(0, 0), TSize(posIterator.iIndexX, posIterator.iIndexY)));
221 else // (aFunc == EDrawBitmap)
225 iGc->DrawBitmap(TRect(pos, bmpSize), *bitmap);
229 // additionally source rect size is iterated
230 iGc->DrawBitmap(TRect(pos, bmpSize),*bitmap, TRect(TPoint(0, 0), TSize(posIterator.iIndexX, posIterator.iIndexY)));
234 while(posIterator.Next());
236 TESTNOERRORL(iGc->GetError());
238 if(!iTestParams.iDoCompressed)
240 // add 1 or 2 to test case name to identity function version
242 testName.Append(aTestName);
243 testName.AppendNum(i+1);
244 WriteTargetOutput(testName);
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.
257 void CTBitBltBase::TestInvalidParametersBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
261 CFbsBitmap* bitmap = iConcentricRectsBitmap2;
263 TInt bmpWidth = bitmap->SizeInPixels().iWidth;
264 TInt bmpHeight = bitmap->SizeInPixels().iHeight;
266 // invalid source rectangle
267 RArray<TRect> rectArray;
268 CleanupClosePushL(rectArray);
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);
277 for(TInt i = 0; i < rectArray.Count(); i++)
281 iGc->BitBlt(TPoint(i*20, 0), *bitmap, rectArray[i]);
283 else // (aFunc == EDrawBitmap)
285 iGc->DrawBitmap(TRect(TPoint(i*20, 0), TSize(50, 50)), *bitmap, rectArray[i]);
289 TESTNOERRORL(iGc->GetError());
291 CleanupStack::PopAndDestroy(&rectArray);
295 // invalid source bitmap, zero size bitmap
296 iGc->BitBlt(TPoint(0, 20), *iZeroSizeBitmap);
297 CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
299 iGc->BitBlt(TPoint(20, 20), *iZeroSizeBitmap, TRect(TPoint(0, 0), TSize(0, 0)));
300 CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
302 // invalid source bitmap, not initialised bitmap
303 iGc->BitBlt(TPoint(0, 40), *iNotInitialisedBitmap);
304 CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
306 iGc->BitBlt(TPoint(20, 40), *iNotInitialisedBitmap, TRect(TPoint(0, 0), TSize(0, 0)));
307 CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
309 else // (aFunc == EDrawBitmap)
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__);
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__);
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__);
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__);
327 // test if target is still clear
328 TBool res = TestTargetL(KRgbWhite);
330 // output the bitmap if there was an error to assist with debugging
333 WriteTargetOutput(aTestName);
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.
342 void CTBitBltBase::TestSourceBitmapCloningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
346 TSize bmpSize(KBitmap2Size);
348 for(TInt i = 0; i < 5; i++)
350 CFbsBitmap* bitmap = CreateConcentricRectsBitmapL(iTestParams.iSourcePixelFormat, bmpSize);
351 if(iTestParams.iDoCompressed)
356 iGc->BitBlt(TPoint(55-35+i*10+1, -60+80+i*7+i), *bitmap);
358 else // (aFunc == EDrawBitmap)
360 iGc->DrawBitmap(TRect(TPoint(55-35+i*10+1, -60+80+i*7+i), bmpSize), *bitmap);
366 bmpSize -= TSize(10, 15);
369 TESTNOERRORL(iGc->GetError());
370 if(!iTestParams.iDoCompressed)
371 WriteTargetOutput(aTestName);