sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "tbitbltbase.h" sl@0: sl@0: sl@0: CTBitBltBase::CTBitBltBase() sl@0: { sl@0: sl@0: } sl@0: sl@0: CTBitBltBase::~CTBitBltBase() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Override of base class pure virtual sl@0: Our implementation only gets called if the base class doTestStepPreambleL() did sl@0: not leave. That being the case, the current test result value will be EPass. sl@0: @leave Gets system wide error code sl@0: @return TVerdict code sl@0: */ sl@0: TVerdict CTBitBltBase::doTestStepL() sl@0: { sl@0: // Test for each target pixel format sl@0: for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--) sl@0: { sl@0: iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex]; sl@0: TBuf targetPixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iTargetPixelFormat)); sl@0: sl@0: // Test for each source pixel format sl@0: for(TInt sourcePixelFormatIndex = iSourcePixelFormatArray.Count() - 1; sourcePixelFormatIndex >= 0; sourcePixelFormatIndex--) sl@0: { sl@0: TBool isEColor256 = EFalse; sl@0: iTestParams.iSourcePixelFormat = iSourcePixelFormatArray[sourcePixelFormatIndex]; sl@0: if(EUidPixelFormatP_8 == iTestParams.iSourcePixelFormat) sl@0: isEColor256 = ETrue; sl@0: TBuf sourcePixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iSourcePixelFormat)); sl@0: sl@0: INFO_PRINTF3(_L("Target Pixel Format: %S; Source Pixel Format: %S"), &targetPixelFormatName, &sourcePixelFormatName); sl@0: sl@0: // small target sl@0: SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KTarget1Size); sl@0: iLargeTarget = EFalse; sl@0: sl@0: // create source bitmaps for tests sl@0: CreateBitmapsL(iTestParams.iSourcePixelFormat); sl@0: RunTestsL(); sl@0: // only run OOM tests for one target pixel format to prevent duplication of tests sl@0: if ((targetPixelFormatIndex == 0) && isEColor256) sl@0: { sl@0: RunOomTestsL(); //from base class sl@0: } sl@0: // delete source bitmaps sl@0: DeleteBitmaps(); sl@0: sl@0: // large target sl@0: SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KTarget2Size); sl@0: iLargeTarget = ETrue; sl@0: sl@0: // create source bitmaps for tests sl@0: CreateBitmapsL(iTestParams.iSourcePixelFormat); sl@0: RunTestsL(); sl@0: if ((targetPixelFormatIndex == 0) && isEColor256) sl@0: { sl@0: RunOomTestsL(); //from base class sl@0: } sl@0: // delete source bitmaps sl@0: DeleteBitmaps(); sl@0: } sl@0: } sl@0: CloseTMSGraphicsStep(); sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: Override of base class virtual sl@0: @leave Gets system wide error code sl@0: @return - TVerdict code sl@0: */ sl@0: TVerdict CTBitBltBase::doTestStepPreambleL() sl@0: { sl@0: CTDirectGdiStepBase::doTestStepPreambleL(); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: Override of base class virtual sl@0: @leave Gets system wide error code sl@0: @return - TVerdict code sl@0: */ sl@0: TVerdict CTBitBltBase::doTestStepPostambleL() sl@0: { sl@0: DeleteBitmaps(); sl@0: CTDirectGdiStepBase::doTestStepPostambleL(); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: Write target output. sl@0: Call method from base class with test case name and source pixel format string. sl@0: @param aTestCaseName Name of test case. sl@0: */ sl@0: void CTBitBltBase::WriteTargetOutput(TPtrC aTestCaseName) sl@0: { sl@0: TBuf postfix; sl@0: postfix.Append(KSourceString); sl@0: postfix.Append(KSeparator); sl@0: postfix.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(iTestParams.iSourcePixelFormat)); sl@0: sl@0: TESTNOERROR(CTDirectGdiStepBase::WriteTargetOutput(iTestParams, aTestCaseName, &postfix)); sl@0: } sl@0: sl@0: /** sl@0: Create set of bitmaps needed for tests. sl@0: @param aPixelFormat Source pixel format of bitmap. sl@0: */ sl@0: void CTBitBltBase::CreateBitmapsL(TUidPixelFormat aPixelFormat) sl@0: { sl@0: iNotInitialisedBitmap = new (ELeave)CFbsBitmap(); sl@0: iZeroSizeBitmap = new (ELeave)CFbsBitmap(); sl@0: TESTNOERRORL(iZeroSizeBitmap->Create(TSize(0,0),TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat))); sl@0: iCompressedBitmap = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap2Size, TSize(8, 8)); sl@0: iCompressedBitmap->Compress(); sl@0: iCompressedBitmapSmall = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap1Size, TSize(2,2)); sl@0: iCompressedBitmapSmall->Compress(); sl@0: iCheckedBoardBitmap1 = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap1Size, KBitmap1Size); sl@0: iCheckedBoardBitmap2 = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap2Size, TSize(8, 8)); sl@0: iConcentricRectsBitmap1 = CreateConcentricRectsBitmapL(aPixelFormat, KBitmap1Size); sl@0: iConcentricRectsBitmap2 = CreateConcentricRectsBitmapL(aPixelFormat, KBitmap2Size); sl@0: iCheckedBoardWithAlphaBitmap = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap2Size, TSize(16, 16), ETrue); sl@0: } sl@0: sl@0: /** sl@0: Delete set of test bitmaps. sl@0: */ sl@0: void CTBitBltBase::DeleteBitmaps() sl@0: { sl@0: delete iNotInitialisedBitmap; sl@0: iNotInitialisedBitmap = NULL; sl@0: delete iZeroSizeBitmap; sl@0: iZeroSizeBitmap = NULL; sl@0: delete iCompressedBitmap; sl@0: iCompressedBitmap = NULL; sl@0: delete iCompressedBitmapSmall; sl@0: iCompressedBitmapSmall = NULL; sl@0: delete iCheckedBoardBitmap1; sl@0: iCheckedBoardBitmap1 = NULL; sl@0: delete iCheckedBoardBitmap2; sl@0: iCheckedBoardBitmap2 = NULL; sl@0: delete iConcentricRectsBitmap1; sl@0: iConcentricRectsBitmap1 = NULL; sl@0: delete iConcentricRectsBitmap2; sl@0: iConcentricRectsBitmap2 = NULL; sl@0: delete iCheckedBoardWithAlphaBitmap; sl@0: iCheckedBoardWithAlphaBitmap = NULL; sl@0: } sl@0: sl@0: /** sl@0: Common positioning test function for BitBlt() and DrawBitmap() tests. sl@0: The test iterates positions over whole target, outside target and on the target boundaries sl@0: and call tested function for those positions. sl@0: @param aTestName Name of test case. sl@0: @param aFunc Tested function. EBitBlt and EDrawBitmap are supported. sl@0: */ sl@0: void CTBitBltBase::TestPositioningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc) sl@0: { sl@0: CFbsBitmap* bitmap; sl@0: if(iTestParams.iDoCompressed) sl@0: { sl@0: bitmap = iCompressedBitmap; sl@0: } sl@0: else sl@0: { sl@0: bitmap = iConcentricRectsBitmap1; sl@0: } sl@0: sl@0: TInt width = iGdiTarget->SizeInPixels().iWidth; sl@0: TInt height = iGdiTarget->SizeInPixels().iHeight; sl@0: TInt bmpWidth = bitmap->SizeInPixels().iWidth; sl@0: TInt bmpHeight = bitmap->SizeInPixels().iHeight; sl@0: TSize bmpSize(bmpWidth, bmpHeight); sl@0: sl@0: // test two versions of function sl@0: for(TInt i = 0; i < 2; i++) sl@0: { sl@0: ResetGc(); sl@0: sl@0: TPositionIterator posIterator(-30, width+30, bmpWidth, -30, height+30, bmpHeight); sl@0: posIterator.Begin(); sl@0: sl@0: do sl@0: { sl@0: //It is done to shift the rectangle drawn. It gives a slope effect in the image. sl@0: TPoint pos(posIterator.iPosX+posIterator.iIndexY, posIterator.iPosY+posIterator.iIndexX); sl@0: if(aFunc == EBitBlt) sl@0: { sl@0: if(i == 0) sl@0: { sl@0: iGc->BitBlt(pos, *bitmap); sl@0: } sl@0: else sl@0: { sl@0: // additionally source rect size is iterated sl@0: iGc->BitBlt(pos, *bitmap, TRect(TPoint(0, 0), TSize(posIterator.iIndexX, posIterator.iIndexY))); sl@0: } sl@0: } sl@0: else // (aFunc == EDrawBitmap) sl@0: { sl@0: if(i == 0) sl@0: { sl@0: iGc->DrawBitmap(TRect(pos, bmpSize), *bitmap); sl@0: } sl@0: else sl@0: { sl@0: // additionally source rect size is iterated sl@0: iGc->DrawBitmap(TRect(pos, bmpSize),*bitmap, TRect(TPoint(0, 0), TSize(posIterator.iIndexX, posIterator.iIndexY))); sl@0: } sl@0: } sl@0: } sl@0: while(posIterator.Next()); sl@0: sl@0: TESTNOERRORL(iGc->GetError()); sl@0: sl@0: if(!iTestParams.iDoCompressed) sl@0: { sl@0: // add 1 or 2 to test case name to identity function version sl@0: TBuf<30> testName; sl@0: testName.Append(aTestName); sl@0: testName.AppendNum(i+1); sl@0: WriteTargetOutput(testName); sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Common invalid parameters test function for BitBlt() and DrawBitmap() tests. sl@0: The function tests against invalid source rectangle, zero size source bitmap sl@0: (both cases should return KErrArgument) and not initialised source bitmap (should sl@0: return KErrBadHandle). sl@0: @param aTestName Name of test case. sl@0: @param aFunc Tested function. EBitBlt and EDrawBitmap are supported. sl@0: */ sl@0: void CTBitBltBase::TestInvalidParametersBaseL(const TDesC& aTestName, TBitBltFuncType aFunc) sl@0: { sl@0: ResetGc(); sl@0: sl@0: CFbsBitmap* bitmap = iConcentricRectsBitmap2; sl@0: sl@0: TInt bmpWidth = bitmap->SizeInPixels().iWidth; sl@0: TInt bmpHeight = bitmap->SizeInPixels().iHeight; sl@0: sl@0: // invalid source rectangle sl@0: RArray rectArray; sl@0: CleanupClosePushL(rectArray); sl@0: TInt err = KErrNone; sl@0: err |= rectArray.Append(TRect(-30, -30, -10, -10)); sl@0: err |= rectArray.Append(TRect(bmpWidth+10, bmpHeight+10, bmpWidth+20, bmpHeight+20)); sl@0: err |= rectArray.Append(TRect(bmpWidth, bmpHeight, 0, 0)); sl@0: err |= rectArray.Append(TRect(-10, -10, -30, -30)); sl@0: err |= rectArray.Append(TRect(0, 0, 0, 0)); sl@0: TESTL(KErrNone == err); sl@0: sl@0: for(TInt i = 0; i < rectArray.Count(); i++) sl@0: { sl@0: if(aFunc == EBitBlt) sl@0: { sl@0: iGc->BitBlt(TPoint(i*20, 0), *bitmap, rectArray[i]); sl@0: } sl@0: else // (aFunc == EDrawBitmap) sl@0: { sl@0: iGc->DrawBitmap(TRect(TPoint(i*20, 0), TSize(50, 50)), *bitmap, rectArray[i]); sl@0: } sl@0: } sl@0: sl@0: TESTNOERRORL(iGc->GetError()); sl@0: sl@0: CleanupStack::PopAndDestroy(&rectArray); sl@0: sl@0: if(aFunc == EBitBlt) sl@0: { sl@0: // invalid source bitmap, zero size bitmap sl@0: iGc->BitBlt(TPoint(0, 20), *iZeroSizeBitmap); sl@0: CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: sl@0: iGc->BitBlt(TPoint(20, 20), *iZeroSizeBitmap, TRect(TPoint(0, 0), TSize(0, 0))); sl@0: CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: sl@0: // invalid source bitmap, not initialised bitmap sl@0: iGc->BitBlt(TPoint(0, 40), *iNotInitialisedBitmap); sl@0: CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: sl@0: iGc->BitBlt(TPoint(20, 40), *iNotInitialisedBitmap, TRect(TPoint(0, 0), TSize(0, 0))); sl@0: CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: } sl@0: else // (aFunc == EDrawBitmap) sl@0: { sl@0: // invalid source bitmap, zero size bitmap sl@0: iGc->DrawBitmap(TRect(TPoint(0, 20), TSize(50, 50)), *iZeroSizeBitmap); sl@0: CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: sl@0: iGc->DrawBitmap(TRect(TPoint(20, 20), TSize(50, 50)), *iZeroSizeBitmap, TRect(TPoint(0, 0), TSize(10, 10))); sl@0: CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: sl@0: // invalid source bitmap, not initialised bitmap sl@0: iGc->DrawBitmap(TRect(TPoint(0, 40), TSize(50, 50)), *iNotInitialisedBitmap); sl@0: CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: sl@0: iGc->DrawBitmap(TRect(TPoint(20, 40), TSize(50, 50)), *iNotInitialisedBitmap, sl@0: TRect(TPoint(0, 0), TSize(10, 10))); sl@0: CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: } sl@0: sl@0: // test if target is still clear sl@0: TBool res = TestTargetL(KRgbWhite); sl@0: TEST(res); sl@0: // output the bitmap if there was an error to assist with debugging sl@0: if (res == EFalse) sl@0: { sl@0: WriteTargetOutput(aTestName); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Common source bitmap cloning test function for BitBlt() and DrawBitmap() tests. sl@0: @param aTestName Name of test case. sl@0: @param aFunc Tested function. EBitBlt and EDrawBitmap are supported. sl@0: */ sl@0: void CTBitBltBase::TestSourceBitmapCloningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc) sl@0: { sl@0: ResetGc(); sl@0: sl@0: TSize bmpSize(KBitmap2Size); sl@0: sl@0: for(TInt i = 0; i < 5; i++) sl@0: { sl@0: CFbsBitmap* bitmap = CreateConcentricRectsBitmapL(iTestParams.iSourcePixelFormat, bmpSize); sl@0: if(iTestParams.iDoCompressed) sl@0: bitmap->Compress(); sl@0: sl@0: if(aFunc == EBitBlt) sl@0: { sl@0: iGc->BitBlt(TPoint(55-35+i*10+1, -60+80+i*7+i), *bitmap); sl@0: } sl@0: else // (aFunc == EDrawBitmap) sl@0: { sl@0: iGc->DrawBitmap(TRect(TPoint(55-35+i*10+1, -60+80+i*7+i), bmpSize), *bitmap); sl@0: } sl@0: sl@0: delete bitmap; sl@0: bitmap = NULL; sl@0: sl@0: bmpSize -= TSize(10, 15); sl@0: } sl@0: sl@0: TESTNOERRORL(iGc->GetError()); sl@0: if(!iTestParams.iDoCompressed) sl@0: WriteTargetOutput(aTestName); sl@0: }