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 "tbitbltmaskedbase.h"
19 CTBitBltMaskedBase::CTBitBltMaskedBase()
24 CTBitBltMaskedBase::~CTBitBltMaskedBase()
31 Call method from base class with test case name and combined source pixel format and mask type string.
32 @param aTestCaseName Name of test case.
33 @return KErrNone if successful, otherwise one of the system-wide error codes.
35 TInt CTBitBltMaskedBase::WriteTargetOutput(TPtrC aTestCaseName)
37 TBuf<KFileNameLength> postfix;
38 postfix.Append(KSourceString);
39 postfix.Append(KSeparator);
40 postfix.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(
41 iTestParams.iSourcePixelFormat));
43 postfix.Append(KSeparator);
46 postfix.Append(_L16("Invert"));
48 postfix.Append(_L16("M"));
50 if(iMaskPixelFormat == EUidPixelFormatL_8)
52 postfix.Append(_L16("L8"));
54 else if(iMaskPixelFormat == EUidPixelFormatL_1)
56 postfix.Append(_L16("L1"));
59 return CTDirectGdiStepBase::WriteTargetOutput(iTestParams, aTestCaseName, &postfix);
63 Create set of bitmaps needed for tests.
64 @param aPixelFormat Source pixel format of bitmap.
66 void CTBitBltMaskedBase::CreateBitmapsL(TUidPixelFormat aPixelFormat)
68 CTBitBltBase::CreateBitmapsL(aPixelFormat);
69 iNotInitialisedMask = new (ELeave)CFbsBitmap();
70 iZeroSizeMask = new (ELeave)CFbsBitmap();
71 TESTL(KErrNone == iZeroSizeMask->Create(TSize(0,0), TDisplayModeMapping::MapPixelFormatToDisplayMode(EUidPixelFormatL_1)));
72 iMask1L1 = CreateCheckedBoardBitmapL(EUidPixelFormatL_1, KBitmap1Size, TSize(4, 4));
73 iMask2L1 = CreateCheckedBoardBitmapL(EUidPixelFormatL_1, KBitmap2Size, TSize(8, 8));
74 iMask1L8 = CreateMaskingPixmapL(EUidPixelFormatL_8, KBitmap1Size);
75 iMask2L8 = CreateMaskingPixmapL(EUidPixelFormatL_8, KBitmap2Size);
76 iCompressedMaskL8 = CreateMaskingPixmapL(EUidPixelFormatL_8, KBitmap2Size);
77 iCompressedMaskL8->Compress();
78 iBlackWhiteBitmap = CreateBlackWhiteBitmapL(aPixelFormat, KBitmap2Size, TSize(8, 8));
82 Delete set of test bitmaps.
84 void CTBitBltMaskedBase::DeleteBitmaps()
86 delete iNotInitialisedMask;
87 iNotInitialisedMask = NULL;
98 delete iCompressedMaskL8;
99 iCompressedMaskL8 = NULL;
100 delete iBlackWhiteBitmap;
101 iBlackWhiteBitmap = NULL;
102 CTBitBltBase::DeleteBitmaps();
106 Begin iteration through mask types.
107 All needed variables are initialized to start iteration.
109 void CTBitBltMaskedBase::BeginMaskIteration()
112 iMaskPixelFormat = EUidPixelFormatL_1;
113 iInvertMask = EFalse;
114 iCurrentMask1 = iMask1L1;
115 iCurrentMask2 = iMask2L1;
119 Next iteration of mask types.
120 Generates next mask type.
121 @return EFalse is returned if end of iterations else ETrue.
123 TBool CTBitBltMaskedBase::NextMaskIteration()
130 iMaskPixelFormat = EUidPixelFormatL_1;
131 iInvertMask = EFalse;
132 iCurrentMask1 = iMask1L1;
133 iCurrentMask2 = iMask2L1;
139 iMaskPixelFormat = EUidPixelFormatL_1;
141 iCurrentMask1 = iMask1L1;
142 iCurrentMask2 = iMask2L1;
148 iMaskPixelFormat = EUidPixelFormatL_8;
149 iInvertMask = EFalse;
150 iCurrentMask1 = iMask1L8;
151 iCurrentMask2 = iMask2L8;
155 case EMaskIterationEnd:
165 Common positioning test function for BitBltMasked() and DrawBitmapMasked() tests.
166 The test iterates positions over whole target, outside target and on the target boundaries
167 and call tested function for those positions.
168 @param aTestName Name of test case.
169 @param aFunc Tested function. EBitBltMasked and EDrawBitmapMasked are supported.
171 void CTBitBltMaskedBase::TestPositioningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
173 if (iRunningOomTests)
175 // OOM tests take too long if this test is run. Doesn't test anything new for OOM over other tests.
179 if(iTestParams.iDoCompressed)
181 bitmap = iCompressedBitmap;
185 bitmap = iConcentricRectsBitmap1;
188 TInt width = iGdiTarget->SizeInPixels().iWidth;
189 TInt height = iGdiTarget->SizeInPixels().iHeight;
190 TInt bmpWidth = bitmap->SizeInPixels().iWidth;
191 TInt bmpHeight = bitmap->SizeInPixels().iHeight;
192 TSize bmpSize(bmpWidth, bmpHeight);
196 TPositionIterator posIterator(-30, width+30, bmpWidth, -30, height+30, bmpHeight);
201 TPoint pos(posIterator.iPosX+posIterator.iIndexY, posIterator.iPosY+posIterator.iIndexX);
203 if(aFunc == EBitBltMasked)
205 if(iMaskPixelFormat == EUidPixelFormatL_1)
207 iGc->BitBltMasked(pos, *bitmap,
208 TRect(TPoint(0, 0), bmpSize), *iCurrentMask1, iInvertMask);
212 // additionaly mask position is iterated
213 iGc->BitBltMasked(pos, *bitmap,
214 TRect(TPoint(0, 0), bmpSize), *iCurrentMask1, TPoint(posIterator.iIndexX, posIterator.iIndexY));
217 else // (aFunc == EDrawBitmapMasked)
219 iGc->DrawBitmapMasked(TRect(pos, bmpSize), *bitmap,
220 TRect(TPoint(0, 0), bmpSize), *iCurrentMask1, iInvertMask);
223 while(posIterator.Next());
226 // It looks like AlphaBlendBitmaps() (which is mapped on DrawBitmapMasked() with alpha for BitGDI)
227 // do not support clipping and returns KErrArgument for destination rect (partialy) outside the target.
228 if(aFunc == EBitBltMasked)
230 if(iUseDirectGdi || (iMaskPixelFormat == EUidPixelFormatL_1) || (iGc->GetError() != KErrArgument))
232 TESTNOERROR(iGc->GetError());
237 TESTNOERROR(iGc->GetError());
239 if(!iTestParams.iDoCompressed)
240 TESTNOERRORL(WriteTargetOutput(aTestName));
244 Common invalid parameters test function for BitBltMasked() and DrawBitmapMasked() tests.
245 The function tests against invalid source rectangle, zero size source bitmap (both should
246 return KErrArgument) and not initialised source bitmap (should return KErrBadHandle).
247 @param aTestName Name of test case.
248 @param aFunc Tested function. EBitBltMasked and EDrawBitmapMasked are supported.
250 void CTBitBltMaskedBase::TestInvalidParametersBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
254 CFbsBitmap* bitmap = iConcentricRectsBitmap2;
256 TInt bmpWidth = bitmap->SizeInPixels().iWidth;
257 TInt bmpHeight = bitmap->SizeInPixels().iHeight;
258 TSize bmpSize(bmpWidth, bmpHeight);
260 // invalid source rectangle
261 RArray<TRect> rectArray;
262 CleanupClosePushL(rectArray);
264 err |= rectArray.Append(TRect(-30, -30, -10, -10));
265 err |= rectArray.Append(TRect(bmpWidth+10, bmpHeight+10, bmpWidth+20, bmpHeight+20));
266 err |= rectArray.Append(TRect(bmpWidth, bmpHeight, 0, 0));
267 err |= rectArray.Append(TRect(-10, -10, -30, -30));
268 err |= rectArray.Append(TRect(0, 0, 0, 0));
269 TESTL(KErrNone == err);
271 for(TInt i = 0; i < rectArray.Count(); i++)
273 if(aFunc == EBitBltMasked)
275 iGc->BitBltMasked(TPoint(i*20, 0), *bitmap, rectArray[i], *iMask1L1, EFalse);
277 else // (aFunc == EDrawBitmapMasked)
279 iGc->DrawBitmapMasked(TRect(TPoint(i*20, 0), bmpSize), *bitmap, rectArray[i], *iMask1L1, EFalse);
283 TESTNOERRORL(iGc->GetError());
285 CleanupStack::PopAndDestroy(&rectArray);
287 TRect zeroRect(TPoint(0, 0), TSize(0, 0));
289 if(aFunc == EBitBltMasked)
291 // invalid source bitmap, zero size bitmap
292 iGc->BitBltMasked(TPoint(0, 20), *iZeroSizeBitmap, zeroRect, *iMask1L1, EFalse);
293 CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
295 iGc->BitBltMasked(TPoint(20, 20), *iZeroSizeBitmap, zeroRect, *iMask1L8, TPoint(0, 0));
296 TESTL(iGc->GetError() == KErrArgument);
298 iGc->BitBltMasked(TPoint(20, 20), *iZeroSizeBitmap, zeroRect, *iMask1L8, TPoint(0, 0));
299 TESTL(iGc->GetError() == KErrArgument);
301 // invalid source bitmap, not initialised bitmap
302 iGc->BitBltMasked(TPoint(0, 40), *iNotInitialisedBitmap, zeroRect, *iMask1L1, EFalse);
303 CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
305 iGc->BitBltMasked(TPoint(20, 40), *iNotInitialisedBitmap, zeroRect, *iMask1L8, TPoint(0, 0));
306 TESTL(iGc->GetError() == iUseDirectGdi ? KErrBadHandle : KErrArgument);
308 TRect bmpRect(TPoint(0, 0), bmpSize);
310 // BitGDI performs drawing when mask is zero sized or not initialised
311 // so we test only in DirectGDI
314 // invalid mask, zero size mask
315 iGc->BitBltMasked(TPoint(0, 60), *bitmap, bmpRect, *iZeroSizeMask, EFalse);
316 TESTL(iGc->GetError() == KErrArgument);
318 iGc->BitBltMasked(TPoint(20, 60), *bitmap, bmpRect, *iZeroSizeMask, TPoint(0, 0));
319 TESTL(iGc->GetError() == KErrArgument);
321 // invalid mask, not initialised mask
322 iGc->BitBltMasked(TPoint(0, 80), *bitmap, bmpRect, *iNotInitialisedMask, EFalse);
323 TESTL(iGc->GetError() == KErrBadHandle);
325 iGc->BitBltMasked(TPoint(20, 80), *bitmap, bmpRect, *iNotInitialisedMask, TPoint(0, 0));
326 TESTL(iGc->GetError() == KErrBadHandle);
329 else // (aFunc == EDrawBitmapMasked)
331 // invalid source bitmap, zero size bitmap
332 iGc->DrawBitmapMasked(TRect(TPoint(0, 20), TSize(0, 0)), *iZeroSizeBitmap, zeroRect, *iMask1L1, EFalse);
333 CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
335 // invalid source bitmap, not initialised bitmap
336 iGc->DrawBitmapMasked(TRect(TPoint(0, 40), TSize(0, 0)), *iNotInitialisedBitmap, zeroRect, *iMask1L1, EFalse);
337 CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
339 // invalid mask, zero size mask
340 TRect bmpRect(TPoint(0, 0), bmpSize);
341 iGc->DrawBitmapMasked(TRect(TPoint(0, 60), bmpSize), *bitmap, bmpRect, *iZeroSizeMask, EFalse);
342 CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
344 // invalid mask, not initialised mask
345 iGc->DrawBitmapMasked(TRect(TPoint(0, 80), bmpSize), *bitmap, bmpRect, *iNotInitialisedMask, EFalse);
346 CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
349 // Test if target is clear. By definition, images rendered using any invalid parameter,
350 // should result in no change in the target.
351 //This test is not valid for BitGDI as it generates an output if mask size is zero.
354 TBool res = TestTargetL(KRgbWhite);
356 // output the bitmap if there was an error to assist with debugging
359 TESTNOERRORL(WriteTargetOutput(aTestName));
366 Common source bitmap cloning test function for BitBltMasked() and DrawBitmapMasked() tests.
367 @param aTestName Name of test case.
368 @param aFunc Tested function. EBitBltMasked and EDrawBitmapMasked are supported.
370 void CTBitBltMaskedBase::TestSourceBitmapCloningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
374 TInt width = iGdiTarget->SizeInPixels().iWidth;
375 TInt height = iGdiTarget->SizeInPixels().iHeight;
377 TSize bmpSize(KBitmap2Size);
379 for(TInt i = 0; i < 5; i++)
381 CFbsBitmap* bitmap = CreateConcentricRectsBitmapL(iTestParams.iSourcePixelFormat, bmpSize);
382 if(iTestParams.iDoCompressed)
385 if(aFunc == EBitBltMasked)
387 iGc->BitBltMasked(TPoint(55-35+i*10+1, -60+80+i*7+1), *bitmap,
388 TRect(TPoint(0, 0), bmpSize), *iCurrentMask2, iInvertMask);
390 else // (aFunc == EDrawBitmapMasked)
392 iGc->DrawBitmapMasked(TRect(TPoint(55-35+i*10+1, -60+80+i*7+1), bmpSize), *bitmap,
393 TRect(TPoint(0, 0), bmpSize), *iCurrentMask2, iInvertMask);
399 bmpSize -= TSize(10, 15);
402 TESTNOERRORL(iGc->GetError());
403 if(!iTestParams.iDoCompressed)
404 TESTNOERRORL(WriteTargetOutput(aTestName));
408 Common mask cloning test function for BitBltMasked() and DrawBitmapMasked() tests.
409 @param aTestName Name of test case.
410 @param aFunc Tested function. EBitBltMasked and EDrawBitmapMasked are supported.
412 void CTBitBltMaskedBase::TestMaskCloningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
416 TSize maskSize(KBitmap2Size);
418 for(TInt i = 0; i < 5; i++)
420 CFbsBitmap* mask = CreateCheckedBoardBitmapL(EUidPixelFormatL_1, maskSize, TSize(8, 8));
421 if(iTestParams.iDoCompressed)
424 if(aFunc == EBitBltMasked)
426 iGc->BitBltMasked(TPoint(55-35+i*10+1, -60+80+i*7+1), *iConcentricRectsBitmap2,
427 TRect(TPoint(0, 0), KBitmap2Size), *mask, iInvertMask);
429 else // (aFunc == EDrawBitmapMasked)
431 iGc->DrawBitmapMasked(TRect(TPoint(55-35+i*10+1, -60+80+i*7+1), iConcentricRectsBitmap2->SizeInPixels()),
432 *iConcentricRectsBitmap2, TRect(TPoint(0, 0), KBitmap2Size), *mask, iInvertMask);
438 maskSize -= TSize(10, 15);
441 TESTNOERRORL(iGc->GetError());
443 if(!iTestParams.iDoCompressed)
444 TESTNOERRORL(WriteTargetOutput(aTestName));