First public contribution.
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 "tdirectgdi_test_step_base.h"
17 #include <graphics/directgdiextensioninterfaces.h>
19 //These reference and test bitmaps are used for image comparison
21 _LIT(KRefPath, "\\img\\ref\\%S.mbm");
22 _LIT(KTestPath, "\\img\\test\\%S.mbm");
24 //The default image cache size to use for the tests.
25 const TInt KDriverImageCacheSizeTests = 0x400000;
28 Position iterator constructor.
29 @param aStartX Start x position.
30 @param aEndX End x position.
31 @param aStepX Step for x position.
32 @param aStartY Start y position.
33 @param aEndY End y position.
34 @param aStepY Step for y position.
36 TPositionIterator::TPositionIterator(TInt aStartX, TInt aEndX, TInt aStepX,
37 TInt aStartY, TInt aEndY, TInt aStepY) :
38 iStartX(aStartX), iEndX(aEndX), iStepX(aStepX),
39 iStartY(aStartY), iEndY(aEndY), iStepY(aStepY),
40 iPosX(aStartX), iPosY(aStartY), iIndexX(0), iIndexY(0)
46 All needed variables are initialized to start iteration.
48 void TPositionIterator::Begin()
58 Generates next position and position indices.
59 @return EFalse is returned if end of iterations else ETrue.
61 TBool TPositionIterator::Next()
86 CBitmapDevice* CTImageTarget::BitmapDevice() const
92 Create a new bitgdi target
93 @param aPixelFormat The pixel format for the target
94 @param aSize The size of the target to create
95 @return On return, contains a pointer to a bitgdi target object
97 CTBitGdiTarget* CTBitGdiTarget::NewL(TUidPixelFormat aPixelFormat, const TSize& aSize)
99 CTBitGdiTarget* self = new(ELeave) CTBitGdiTarget();
100 CleanupStack::PushL(self);
101 self->ConstructL(aPixelFormat, aSize);
102 CleanupStack::Pop(); // self
107 Second phase constructor of CTBitGdiTarget. Creates a bitmap for use as a target.
108 @param aPixelFormat The pixel format for the target to be created
109 @param aSize The size of the target to be created
111 void CTBitGdiTarget::ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize)
114 iBitmap = new(ELeave) CFbsBitmap;
115 iBitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat));
116 // create an off screen bitmap device
117 iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
121 Create a bitgdi context
122 @param aGc A pointer to the created graphics context
123 @param aActivate ETrue to create and activate the context aGc, EFalse to just create it.
124 @return On return, contains a pointer to the created bitgdi context
126 TInt CTBitGdiTarget::CreateContext(CTContextBase*& aGc, TBool aActivate)
128 TInt result = KErrGeneral;
129 TRAP(result, aGc = CTBitGdiContext::NewL((CFbsBitmapDevice*)iBitmapDevice, aActivate));
134 Sets the object to draw to a particular device
135 @param aGc A pointer to the created graphics context
137 TInt CTBitGdiTarget::Activate(CTContextBase*& aGc)
139 CTBitGdiContext* gc = (CTBitGdiContext*)aGc;
140 // Activate the context on a rendering target.
141 return gc->Activate(iBitmapDevice);
144 Get the size of the device area in pixels
145 @return On return, The width and height of the target, in pixels
147 TSize CTBitGdiTarget::SizeInPixels() const
149 return iBitmapDevice->SizeInPixels();
154 Get a target FBsBitmap
155 @return The target FBsBitmap
157 CFbsBitmap* CTBitGdiTarget::GetTargetFbsBitmapL()
163 Nothing to be implemented for BitGdi Finish()
165 void CTBitGdiTarget::Finish ()
170 void CTBitGdiTarget::Close()
176 Destructor of CTBitGdiTarget
178 CTBitGdiTarget::~CTBitGdiTarget()
180 delete iBitmapDevice;
187 CTDirectGdiTarget::CTDirectGdiTarget()
192 Create a new directgdi target
193 @param aPixelFormat The pixel format for the target
194 @param aSize The size of the target to create
195 @return On return, contains a pointer to a directgdi target object
197 CTDirectGdiTarget* CTDirectGdiTarget::NewL(TUidPixelFormat aPixelFormat, const TSize& aSize)
199 CTDirectGdiTarget* self = new(ELeave) CTDirectGdiTarget();
200 CleanupStack::PushL(self);
201 self->ConstructL(aPixelFormat, aSize);
202 CleanupStack::Pop(); // self
206 Second phase constructor of CTDirectGdiTarget
207 @param aPixelFormat The pixel format for the target
208 @param aSize The size of the target to create
210 void CTDirectGdiTarget::ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize)
213 User::LeaveIfError(CDirectGdiDriver::Open());
214 iDGdiDriver = CDirectGdiDriver::Static();
215 if (iDGdiDriver == NULL)
216 User::Leave(KErrNoMemory);
218 // set a large cache size (if available to do so) so the tests execute more quickly.
219 MDirectGdiDriverCacheSize* driverCacheInterface = NULL;
220 if (KErrNone == iDGdiDriver->GetInterface(TUid::Uid(KDirectGdiDriverCacheSizeUid), (TAny*&)driverCacheInterface))
222 User::LeaveIfError(driverCacheInterface->SetMaxImageCacheSize(KDriverImageCacheSizeTests));
225 iDGdiImageTarget = new (ELeave) RDirectGdiImageTarget(*iDGdiDriver);
226 // create a bitmap which is used to save the image data from an RSgImage to a file.
227 iBitmap = new(ELeave) CFbsBitmap;
228 User::LeaveIfError(iBitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
229 iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
230 // Set up image attributes
231 iImageInfo.iSizeInPixels = aSize;
232 iImageInfo.iPixelFormat = aPixelFormat;
233 iImageInfo.iUsage = ESgUsageDirectGdiTarget;
234 User::LeaveIfError(iRSgImage.Create(iImageInfo, NULL,0));
235 User::LeaveIfError(iDGdiImageTarget->Create(iRSgImage));
240 Create a Direct GDI graphics context.
242 @param aGc A reference to a pointer to the created graphics context. If return is anything
243 other than KErrNone then aGc is set to NULL.
244 @param aActivate ETrue to create and activate the context aGc, EFalse to just create it.
246 @return KErrNone, if successful; otherwise, another of the system-wide error codes.
248 TInt CTDirectGdiTarget::CreateContext(CTContextBase*& aGc, TBool aActivate)
250 TInt result = KErrGeneral;
254 TRAP(result, aGc = CTestDirectGdiContext::NewL());
255 CTestDirectGdiContext* gc = (CTestDirectGdiContext*)aGc;
257 // If the GC is not NULL, make sure the return code indicates
259 if (aActivate && aGc)
261 if(result != KErrNone)
267 // Activate the context on a rendering target.
268 result = gc->Activate(*iDGdiImageTarget);
275 Sets the object to draw to a particular device
276 @param aGc A pointer to the created graphics context
278 TInt CTDirectGdiTarget::Activate(CTContextBase*& aGc)
280 CTestDirectGdiContext* gc = (CTestDirectGdiContext*)aGc;
281 // Activate the context on a rendering target.
282 return gc->Activate(*iDGdiImageTarget);
286 Get the size of the device area in pixels
287 @return On return, The width and height of the target, in pixels
289 TSize CTDirectGdiTarget::SizeInPixels() const
291 return iImageInfo.iSizeInPixels;
295 Get a target FBsBitmap.
296 @return The target FBsBitmap
298 CFbsBitmap* CTDirectGdiTarget::GetTargetFbsBitmapL()
300 // Create a copy of the RSgImage that is CPU-accessible for mapping.
301 RSgImage cpuAccessibleImage;
302 TSgImageInfo imageInfo;
303 imageInfo.iSizeInPixels = iImageInfo.iSizeInPixels;
304 imageInfo.iPixelFormat = iImageInfo.iPixelFormat;
305 imageInfo.iCpuAccess = ESgCpuAccessReadOnly;
306 User::LeaveIfError(cpuAccessibleImage.Create(imageInfo, iRSgImage));
307 CleanupClosePushL(cpuAccessibleImage);
309 iBitmap->BeginDataAccess();
310 const TInt bitmapDataStride = iBitmap->DataStride();
311 const TInt numScanlines = imageInfo.iSizeInPixels.iHeight;
312 const TAny* sgImageDataAddress;
313 TInt sgImageDataStride = 0;
315 User::LeaveIfError(cpuAccessibleImage.MapReadOnly(sgImageDataAddress, sgImageDataStride));
317 TUint32* bitmapDataAddress = iBitmap->DataAddress();
318 for (TInt scanline = 0; scanline < numScanlines; ++scanline)
320 Mem::Copy((TUint8*)bitmapDataAddress + (scanline*bitmapDataStride), (TUint8*)sgImageDataAddress + (scanline*sgImageDataStride), bitmapDataStride);
322 iBitmap->EndDataAccess();
323 cpuAccessibleImage.Unmap();
325 CleanupStack::PopAndDestroy(1);
331 Force completion of all batched rendering operations. Will not return
332 until rendering is complete.
334 @pre Fully initialised image target.
336 void CTDirectGdiTarget::Finish ()
339 iDGdiDriver->Finish();
343 void CTDirectGdiTarget::Close()
345 if (iDGdiImageTarget)
346 iDGdiImageTarget->Close();
350 Destructor of CTDirectGdiTarget
352 CTDirectGdiTarget::~CTDirectGdiTarget()
354 delete iBitmapDevice;
356 if (iDGdiImageTarget)
358 iDGdiImageTarget->Close();
359 delete iDGdiImageTarget;
362 iDGdiDriver->Close();
367 Implementation of CTestStep base class virtual
368 It is used for doing all common initialisation to derived classes.
369 Make it being able to leave
370 The leave will be picked up by the framework.
371 @leave Gets system wide error code
372 @return - TVerdict code
374 TVerdict CTDirectGdiStepBase::doTestStepPreambleL()
376 SetTestStepResult(EPass);
378 // Create and install Active Scheduler in case tests require active objects
379 iScheduler = new(ELeave) CActiveScheduler;
380 CActiveScheduler::Install(iScheduler);
382 TPtrC targetPixelFormatInput;
383 TPtrC sourcePixelFormatInput;
384 TPtrC sourceResourcePixelFormatInput;
386 // get input for tests from .ini file
387 _LIT(KDirectgdiTestInput, "DirectgdiTestInput");
388 _LIT(KTargetPixelFormatEnums, "TargetPixelFormatEnums ");
389 _LIT(KSourcePixelFormatEnums, "SourcePixelFormatEnums ");
390 _LIT(KSourceResourcePixelFormatEnums, "SourceResourcePixelFormatEnums ");
391 _LIT(KDoRefImg, "DoRefImg");
392 _LIT(KDoDirectGdi, "DoDirectGdi");
393 _LIT(KRunOomTests, "RunOomTests");
394 TEST(GetStringFromConfig(KDirectgdiTestInput, KTargetPixelFormatEnums, targetPixelFormatInput));
395 TEST(GetStringFromConfig(KDirectgdiTestInput, KSourcePixelFormatEnums, sourcePixelFormatInput));
396 TEST(GetStringFromConfig(KDirectgdiTestInput, KSourceResourcePixelFormatEnums, sourceResourcePixelFormatInput));
397 TEST(GetIntFromConfig(KDirectgdiTestInput, KDoRefImg, iMakeRefImg));
398 TEST(GetIntFromConfig(KDirectgdiTestInput, KDoDirectGdi, iUseDirectGdi));
399 TEST(GetIntFromConfig(KDirectgdiTestInput, KRunOomTests, iDoOomTests));
403 iDoOomTests = EFalse;
404 INFO_PRINTF1(_L("WARNING: Can't run out of memory tests under a release build. OOM tests set to run in ini file so turning OOM tests off."));
408 ConvertPixelFormats(targetPixelFormatInput, iTargetPixelFormatArray);
409 ConvertPixelFormats(sourcePixelFormatInput, iSourcePixelFormatArray);
410 ConvertPixelFormats(sourceResourcePixelFormatInput, iSourceResourcePixelFormatArray);
411 iRunningOomTests = EFalse;
413 Logger().ShareAuto();
416 User::LeaveIfError(SgDriver::Open());
417 User::LeaveIfError(RFbsSession::Connect());
419 return TestStepResult();
423 Convert the pixel format strings to pixel format enums
424 @param aPixelFormatInput The pixel format string for testing
425 @param aPixelFormatArray The array of converted pixel formats is returned here
427 void CTDirectGdiStepBase::ConvertPixelFormats(TPtrC aPixelFormatInput, RArray<TUidPixelFormat>& aPixelFormatArray)
429 TPtrC tempBuf = aPixelFormatInput;
430 TInt position = tempBuf.Find(_L(","));
432 while(KErrNotFound != position)
434 aPixelFormatArray.Append(TDisplayModeMapping::ConvertPixelFormatStringToPixelFormat(tempBuf.Left(position)));
435 tempBuf.Set(tempBuf.Mid(position + 2));
436 position = tempBuf.Find(_L(","));
439 if (position == KErrNotFound)
441 aPixelFormatArray.Append(TDisplayModeMapping::ConvertPixelFormatStringToPixelFormat(tempBuf));
446 Implementation of CTestStep base class virtual
447 It is used for doing all after test treatment common to derived classes in here.
448 Make it being able to leave
449 The leave will be picked up by the framework.
450 @leave Gets system wide error code
453 TVerdict CTDirectGdiStepBase::doTestStepPostambleL()
459 iFontStore->RemoveFile(iFontId);
474 RFbsSession::Disconnect();
478 return TestStepResult();
481 CTDirectGdiStepBase::~CTDirectGdiStepBase()
487 iFontStore->RemoveFile(iFontId);
496 iTargetPixelFormatArray.Close();
497 iSourcePixelFormatArray.Close();
498 iSourceResourcePixelFormatArray.Close();
501 CTDirectGdiStepBase::CTDirectGdiStepBase()
506 Create a name in the format of <TestImage / RefImage>_< TestCase Name >_<DisplayModeName>_<Orientation>_<PostFix(optional)>
507 @param aParams A structure object of parameters to be passed through
508 @param aTestName The test name to be generated
509 @param aTestCaseName The test case name passed in, to be used in the resultant filename
510 @param aNamePostfix If this is not NULL, it is appended to filename with an underscore in front of it
512 void CTDirectGdiStepBase::CreateFileName(TTestParams& aParams, TDes& aTestName, TPtrC& aTestCaseName, TDesC* aNamePostfix)
516 aTestName.Append(KDirectGc);
520 aTestName.Append(KBitGc);
523 if (aParams.iDoCompressed)
525 aTestName.Append(KSeparator);
526 aTestName.Append(KCom);
529 aTestName.Append(KSeparator);
530 aTestName.Append(aTestCaseName);
531 aTestName.Append(KSeparator);
532 aTestName.Append(KTargetString);
533 aTestName.Append(KSeparator);
534 aTestName.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(aParams.iTargetPixelFormat));
538 aTestName.Append(KSeparator);
539 aTestName.Append(*aNamePostfix);
544 @see DisplayTargetImageL(TUidPixelFormat, CTImageTarget*)
546 void CTDirectGdiStepBase::DisplayTargetImageL(TUidPixelFormat aPixelFormat)
548 DisplayTargetImageL(aPixelFormat, iGdiTarget);
552 Bitblt an image to screen
553 @param aPixelFormat The pixel format for tests
554 @param aGdiTarget The target image to blit
556 void CTDirectGdiStepBase::DisplayTargetImageL(TUidPixelFormat aPixelFormat, CTImageTarget* aGdiTarget)
558 // Ensure the image has been completly rendered.
559 aGdiTarget->Finish();
560 CFbsScreenDevice* screenDevice = CFbsScreenDevice::NewL(_L("scdv"), TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat));
561 TEST(screenDevice!=NULL);
562 CleanupStack::PushL(screenDevice);
565 screenDevice->CreateContext(bitGc);
567 CleanupStack::PushL(bitGc);
569 TPoint startPoint = TPoint(0, 0);
571 bitGc->BitBlt(startPoint, aGdiTarget->GetTargetFbsBitmapL());
572 screenDevice->Update();
574 CleanupStack::PopAndDestroy(2, screenDevice);
578 Initialises a target (or targets) and a graphics context (or contexts), depending on the value passed in aCase.
579 Deletes the previously used target(s) and context(s).
580 @param aPixelFormat The pixel format to be applied
581 @param aCase The type of test that this target is for, for example when testing with one context and two targets
582 this could be EOneContextTwoTargets_SamePixelType, the default value is EOneContextOneTarget.
583 @param aSize The size of the target(s) to be created
585 void CTDirectGdiStepBase::SetTargetL(TUidPixelFormat aPixelFormat, const TContextTestCase aCase, const TSize& aSize)
587 if(!iRunningOomTests)
589 TBuf<KPixelFormatNameLength> pixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(aPixelFormat));
590 INFO_PRINTF4(_L("SetTarget (using off screen bitmap): %S %dx%d"), &pixelFormatName, aSize.iWidth, aSize.iHeight);
601 TUidPixelFormat aPixelFormat2 = aPixelFormat;
604 case EUidPixelFormatRGB_565:
605 aPixelFormat2 = EUidPixelFormatARGB_8888_PRE;
607 case EUidPixelFormatARGB_8888_PRE:
608 aPixelFormat2 = EUidPixelFormatXRGB_8888;
610 case EUidPixelFormatXRGB_8888:
611 aPixelFormat2 = EUidPixelFormatRGB_565;
617 case EOneContextOneTarget:
621 iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);
625 iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
627 User::LeaveIfError(iGdiTarget->CreateContext(iGc));
630 case EOneContextTwoTargets_SamePixelType:
634 iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);
635 iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat, aSize);
639 iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
640 iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat, aSize);
642 User::LeaveIfError(iGdiTarget->CreateContext(iGc));
645 case EOneContextTwoTargets_DifferentPixelType:
649 iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);
650 iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat2, aSize);
654 iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
655 iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat2, aSize);
657 User::LeaveIfError(iGdiTarget->CreateContext(iGc));
660 case ETwoContextsOneTarget:
664 iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);
668 iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
670 User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse));
671 User::LeaveIfError(iGdiTarget->CreateContext(iGc2, EFalse));
674 case ETwoContextsTwoTargets_WithoutSharing_SamePixelType:
675 case ETwoContextsTwoTargets_WithSharing_SamePixelType:
679 iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);
680 iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat, aSize);
684 iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
685 iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat, aSize);
687 User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse));
688 User::LeaveIfError(iGdiTarget2->CreateContext(iGc2, EFalse));
691 case ETwoContextsTwoTargets_WithoutSharing_DifferentPixelType:
692 case ETwoContextsTwoTargets_WithSharing_DifferentPixelType:
696 iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);
697 iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat2, aSize);
701 iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
702 iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat2, aSize);
704 User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse));
705 User::LeaveIfError(iGdiTarget2->CreateContext(iGc2, EFalse));
708 case EOneContextOneTarget_TwiceActivate:
712 iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);
716 iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
718 User::LeaveIfError(iGdiTarget->CreateContext(iGc));
728 iFontStore->RemoveFile(iFontId);
735 iFontStore = CFbsTypefaceStore::NewL(iGdiTarget->BitmapDevice());
737 _LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr");
738 TESTL(KErrNone == iFontStore->AddFile(KEonFontFileName, iFontId));
740 // Reset VGImage cache - OpenVG DirectGDI only
741 iVgImageCache = NULL;
744 TInt err = iGc->GetInterface(TUid::Uid(KDirectGdiVgImageCacheUid), (TAny*&) iVgImageCache);
745 if (KErrNotSupported == err)
747 // Must be using software DirectGDI as this does not have a VGImage cache
748 iUseSwDirectGdi = ETrue;
754 Get a font by looking for it in the font store. Only gets "DejaVu Sans Mono" at the moment.
755 @return Returns a pointer to the "DejaVu Sans Mono" font if it is found in the font store, returns NULL if it not found.
757 CFont* CTDirectGdiStepBase::GetFont()
759 _LIT(KFontFamily, "DejaVu Sans Mono");
762 TFontSpec spec(KFontFamily, 13);
763 iFontStore->GetNearestFontInPixels(font, spec);
768 Releases the passed font in the font store.
769 @param aFont A pointer to the font to be released.
771 void CTDirectGdiStepBase::ReleaseFont(CFont* aFont)
773 if(aFont && iFontStore)
775 iFontStore->ReleaseFont(aFont);
780 Create a file and save the target image to the file with a filename created from aTestCaseName and aNamePostfix
781 @param aParams A structure object of parameters to be passed through
782 @param aTestCaseName The name of the test case
783 @param aImageTarget The image target to be written out to the file
784 @param aNamePostfix A postfix to be appended to the test case name
785 @see CreateFileName()
786 @return KErrNone if successful, one of the system wide error codes otherwise
788 TInt CTDirectGdiStepBase::WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, CTImageTarget* aImageTarget, TDesC* aNamePostfix)
790 // Finish is called for the OOM tests as well as the normal tests as it is responsible for
791 // clearing up the pending image array. Images get left in the array and cause the OOM tests
792 // for DrawResource to fail if Finish is not called.
793 aImageTarget->Finish();
795 if(!iRunningOomTests) // don't want to save test images when running our of memory twsts
797 TBuf<KFileNameLength> testFileName;
798 CreateFileName(aParams, testFileName, aTestCaseName, aNamePostfix);
800 TBuf<KFileNameLength> testPathName;
802 testPathName.Append(_L("c:"));
804 testPathName.Append(_L("e:"));
809 testPathName.Append(KRefPath);
810 mbmFile.Format(testPathName, &testFileName);
814 testPathName.Append(KTestPath);
815 mbmFile.Format(testPathName, &testFileName);
817 INFO_PRINTF1(testFileName);
819 CFbsBitmap* targetBitmap = NULL;
820 TRAPD(err, targetBitmap = aImageTarget->GetTargetFbsBitmapL());
821 return (err != KErrNone) ? err : targetBitmap->Save(mbmFile);
827 Create a file and save the current target image to the file with a filename created from aTestCaseName and aNamePostfix
828 @param aParams A structure object of parameters to be passed through
829 @param aTestCaseName The name of the test case
830 @param aNamePostfix A postfix to be appended to the test case name
831 @see CreateFileName()
832 @return KErrNone if successful, one of the system wide error codes otherwise
834 TInt CTDirectGdiStepBase::WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, TDesC* aNamePostfix)
836 return WriteTargetOutput(aParams, aTestCaseName, iGdiTarget, aNamePostfix);
840 Reset the graphics context
842 void CTDirectGdiStepBase::ResetGc()
849 Compares the target image pixel by pixel against the given colour. If a pixel with a
850 different colour than aColour is found then the test will fail, otherwise the test will pass.
851 @param aColour A colour rgba value to find.
852 @return ETrue if test passed or EFalse if test failed.
854 TBool CTDirectGdiStepBase::TestTargetL(const TRgb& aColour)
856 iGdiTarget->Finish();
858 CFbsBitmap* bitmap = iGdiTarget->GetTargetFbsBitmapL();
859 TInt width = bitmap->SizeInPixels().iWidth;
860 TInt height = bitmap->SizeInPixels().iHeight;
862 HBufC8* lineBuf = HBufC8::NewLC(width*4);
863 TPtr8 linePtr(lineBuf->Des());
867 for(TInt line=0; line<height; line++)
869 bitmap->GetScanLine(linePtr, TPoint(0, line), width, EColor16MA);
871 const TUint8* pPtr = linePtr.Ptr();
872 for(TInt x=0; x<width; x++)
874 // EColor16MA pixel representation is 32-bit BGRA
875 TRgb pColour(pPtr[2], pPtr[1], pPtr[0], pPtr[3]);
878 if (iTestParams.iTargetPixelFormat == EUidPixelFormatXRGB_8888)
880 if ((pColour.Value() & 0xFFFFFF) != (aColour.Value() & 0xFFFFFF))
883 break; // break inner loop
886 else if(pColour != aColour)
889 break; // break inner loop
894 break; // break outer loop if test failed in inner loop
897 CleanupStack::PopAndDestroy(lineBuf);
903 Checks the graphics context for the passed error codes and logs an error if the codes do not match.
904 If the tests are running using DirectGdi then aDirectGdiErrorCode is checked against the current error in the
905 graphics context, if the tests are running using BitGdi then aBitGdiErrorCode is checked against the current
906 error in the graphics context.
907 @param aDirectGdiErrorCode The DirectGdi error code to check when the tests are running using DirectGdi
908 @param aBitGdiErrorCode The BitGdi error code to check when the tests are running using BitGdi
909 @param aFile The filename to use when reporting the error
910 @param aLine The line number to use when reporting the error
912 void CTDirectGdiStepBase::CheckErrorsL(TInt aDirectGdiErrorCode, TInt aBitGdiErrorCode, const TText8* aFile, TInt aLine)
916 TESTWITHFILENAMEANDLINENUMBERL(iGc->GetError() == aDirectGdiErrorCode, aFile, aLine);
920 TESTWITHFILENAMEANDLINENUMBERL(iGc->GetError() == aBitGdiErrorCode, aFile, aLine);
925 Derived classes should override this method and add their calls to individual test cases in
926 the overridden version.
928 void CTDirectGdiStepBase::RunTestsL()
933 Runs the tests in RunTestsL checking for Out of Memory conditions and testing for memory leaks.
935 void CTDirectGdiStepBase::RunOomTestsL()
939 // don't run the out of memory tests
943 INFO_PRINTF1(_L("*****Running Out Of Memory Tests*****"));
945 // save the current state of test step results
946 TVerdict currentTestStepResult = TestStepResult();
950 iRunningOomTests = ETrue;
953 // count cells so we can know how many we leaked
954 TInt cellsStart = User::CountAllocCells();
956 __UHEAP_FAILNEXT(++tryCount);
959 TRAP(err, RunTestsL());
961 TBool finishedCorrectly = EFalse;
962 if ((err == KErrNone))
964 // claims to have finished correctly, and we're not failing every alloc
965 finishedCorrectly = CheckForHeapFailNext();
968 TInt cellsEnd = User::CountAllocCells();
969 if (cellsStart < cellsEnd)
972 TInt leakedCells = cellsEnd - cellsStart;
973 ERR_PRINTF3(_L("On loop number %d we leaked %d cells. About to cause panic."),tryCount,leakedCells);
977 // check to see if we finished all OOM testing successfully
978 if ((err == KErrNone) && finishedCorrectly)
980 INFO_PRINTF2(_L(" - Test completed successfully after %d iterations."),tryCount);
984 // restore test step result and ignore any test failures the out of memory tests produce
985 SetTestStepResult(currentTestStepResult);
986 iRunningOomTests = EFalse;
990 Tests that the passed condition aCondition is equal to ETrue and reports an error if it is not.
991 This method does not report errors when the tests are running in OOM mode.
992 @see testBooleanTrue()
993 @param aCondition The boolean value to be checked for being equal to ETrue
994 @param aFile The filename to use when reporting the error
995 @param aLine The line number to use when reporting the error
997 void CTDirectGdiStepBase::testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine)
999 if(!iRunningOomTests)
1001 CTestStep::testBooleanTrue(aCondition, aFile, aLine, ETrue);
1006 A leaving version of testBooleanTrue().
1007 @see testBooleanTrue()
1009 void CTDirectGdiStepBase::testBooleanTrueL(TBool aCondition, const TText8* aFile, TInt aLine)
1011 if(!iRunningOomTests)
1013 CTestStep::testBooleanTrueL(aCondition, aFile, aLine, ETrue);
1019 User::Leave(TEST_ERROR_CODE);
1025 A version of testBooleanTrue() that additionally writes an error code to the output if aCondition is not equal to ETrue.
1026 @see testBooleanTrue()
1027 @param aCondition The boolean value to be checked for being equal to ETrue
1028 @param aErrorCode An error code to be reported if aCondition is EFalse
1029 @param aFile The filename to use when reporting the error
1030 @param aLine The line number to use when reporting the error
1032 void CTDirectGdiStepBase::testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine)
1034 if(!iRunningOomTests)
1038 SetTestStepResult(EFail);
1039 _LIT(KMessage,"Test Failed with error [%d]");
1040 Logger().LogExtra(aFile, aLine, ESevrErr, KMessage, aErrorCode);
1046 A leaving version of testBooleanTrueWithErrorCode()
1047 @see testBooleanTrueWithErrorCode()
1048 @param aCondition The boolean value to be checked for being equal to ETrue
1049 @param aErrorCode An error code to be reported if aCondition is EFalse
1050 @param aFile The filename to use when reporting the error
1051 @param aLine The line number to use when reporting the error
1053 void CTDirectGdiStepBase::testBooleanTrueWithErrorCodeL(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine)
1055 if(!iRunningOomTests)
1057 testBooleanTrueWithErrorCode(aCondition, aErrorCode, aFile, aLine);
1063 User::Leave(aErrorCode);
1069 Creates a CFbsBitmap that has a pattern of differently coloured concentric rectangles on it for use in test cases.
1070 @param aPixelFormat The pixel format for create the target bitmap
1071 @param aSize The size of the bitmap to be created
1073 CFbsBitmap* CTDirectGdiStepBase::CreateConcentricRectsBitmapL(TUidPixelFormat aPixelFormat, const TSize& aSize)
1075 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
1076 CleanupStack::PushL(bitmap);
1078 TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
1080 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
1081 TESTL(bitmapDevice!=NULL);
1082 CleanupStack::PushL(bitmapDevice);
1084 CFbsBitGc* bitGc = NULL;
1085 User::LeaveIfError(bitmapDevice->CreateContext(bitGc));
1087 CleanupStack::PushL(bitGc);
1089 for (TInt i = aSize.iWidth/2; i>0; --i)
1091 bitGc->SetPenColor(KColor16Table[i%16]);
1092 bitGc->DrawRect(TRect(i,i,aSize.iWidth - i, aSize.iHeight - i));
1095 CleanupStack::PopAndDestroy(2, bitmapDevice);
1096 CleanupStack::Pop(bitmap);
1102 Creates a bitmap that contains a checked board pattern of coloured rectangles for use in test cases.
1103 @param aPixelFormat The pixel format for create the target bitmap
1104 @param aSize The size of the bitmap
1105 @param aChecksPerAxis Number of checks on X and Y.
1106 @param aGenAlpha If ETrue then generate pattern in alpha channel.
1108 CFbsBitmap* CTDirectGdiStepBase::CreateCheckedBoardBitmapL(TUidPixelFormat aPixelFormat,
1109 const TSize& aSize, const TSize& aChecksPerAxis, TBool aGenAlpha)
1112 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
1113 CleanupStack::PushL(bitmap);
1114 TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
1116 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
1117 CleanupStack::PushL(bitmapDevice);
1118 TESTL(bitmapDevice!=NULL);
1120 CFbsBitGc* bitGc = NULL;
1121 User::LeaveIfError(bitmapDevice->CreateContext(bitGc));
1122 CleanupStack::PushL(bitGc);
1126 bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
1127 bitGc->SetPenStyle(CGraphicsContext::ENullPen);
1130 bitGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
1133 const TSize checkerSize(aSize.iWidth/aChecksPerAxis.iWidth,aSize.iHeight/aChecksPerAxis.iHeight);
1134 TInt brushColour = 0x00;
1135 for(point.iY = 0; point.iY < aSize.iHeight; point.iY += checkerSize.iHeight)
1137 for(point.iX = 0; point.iX < aSize.iWidth; point.iX += checkerSize.iWidth)
1139 TRgb colour = KColor16Table[brushColour++ & 0x0F];
1142 // Note that this is converted internally to pre-multiplied alpha
1143 // for pre-multiplied alpha targets.
1144 colour.SetAlpha((brushColour*5) & 255);
1146 //Use the following line to simplify test for manual verification.
1147 //colour.SetAlpha(0x80);
1149 bitGc->SetBrushColor(colour);
1150 TRect rect(point, checkerSize);
1151 bitGc->DrawRect(rect);
1154 CleanupStack::PopAndDestroy(2, bitmapDevice);
1155 CleanupStack::Pop(bitmap);
1161 Create a black and white checked bitmap
1162 @param aPixelFormat The pixel format to use when creating the target bitmap
1163 @param aSize The size of the bitmap to create
1164 @param aChecksPerAxis Number of checks to draw in the X and Y directions
1165 @param aIsHardwareBitmap If ETrue, creates a hardware CFbsBitmap.
1167 CFbsBitmap* CTDirectGdiStepBase::CreateBlackWhiteBitmapL(TUidPixelFormat aPixelFormat,
1168 const TSize& aSize, const TSize& aChecksPerAxis)
1170 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
1171 CleanupStack::PushL(bitmap);
1173 TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
1175 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
1176 CleanupStack::PushL(bitmapDevice);
1177 TESTL(bitmapDevice!=NULL);
1179 CFbsBitGc* bitGc = NULL;
1180 bitmapDevice->CreateContext(bitGc);
1181 CleanupStack::PushL(bitGc);
1185 bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
1186 bitGc->SetPenStyle(CGraphicsContext::ENullPen);
1188 const TSize checkerSize(aSize.iWidth/aChecksPerAxis.iWidth,aSize.iHeight/aChecksPerAxis.iHeight);
1189 for(point.iY = 0; point.iY < aSize.iHeight; point.iY += checkerSize.iHeight)
1191 TBool isBlack = ETrue;
1192 for(point.iX = 0; point.iX < aSize.iWidth; point.iX += checkerSize.iWidth)
1195 bitGc->SetBrushColor(KRgbBlack);
1197 bitGc->SetBrushColor(KRgbWhite);
1198 TRect rect(point, checkerSize);
1199 bitGc->DrawRect(rect);
1203 CleanupStack::PopAndDestroy(2, bitmapDevice);
1204 CleanupStack::Pop(bitmap);
1209 Create a bitmap designed for masking tests.
1210 @param aPixelFormat The pixel format to use when creating the bitmap
1211 @param aSize The size of the bitmap to create
1213 CFbsBitmap* CTDirectGdiStepBase::CreateMaskingPixmapL (
1214 TUidPixelFormat aPixelFormat,
1218 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
1219 CleanupStack::PushL(bitmap);
1220 TESTL(KErrNone == bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
1222 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
1223 CleanupStack::PushL(bitmapDevice);
1224 TESTL(bitmapDevice!=NULL);
1226 CFbsBitGc* bitGc = NULL;
1227 bitmapDevice->CreateContext(bitGc);
1228 CleanupStack::PushL(bitGc);
1232 bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
1233 bitGc->SetPenStyle(CGraphicsContext::ENullPen);
1235 bitGc->SetBrushColor(TRgb(0x808080));
1237 bitGc->DrawRect(rect);
1239 bitGc->SetBrushColor(TRgb(0x202020));
1240 TRect rect2(0, 0, aSize.iWidth, aSize.iHeight>>2);
1241 bitGc->DrawRect(rect2);
1243 TRect rect3(0, 0, aSize.iWidth>>3, aSize.iHeight);
1244 bitGc->DrawRect(rect3);
1246 CleanupStack::PopAndDestroy(2, bitmapDevice);
1247 CleanupStack::Pop(bitmap);
1252 Stack cleanup helper function to use when the cache needs to be reset
1253 from the cleanup stack.
1254 This method calls MVgImageCache::ResetCache() on the passed MVgImageCache object
1255 @param aPtr A pointer to an image cache object, MVgImageCache*, to be reset
1257 void CTDirectGdiStepBase::ResetCache(TAny* aPtr)
1259 MVgImageCache* cache = reinterpret_cast <MVgImageCache*> (aPtr);
1260 cache->ResetCache();
1264 Stack cleanup helper function to use when the pen size needs to be reset to (1,1)
1265 from the cleanup stack. This is needed when SetPenSize() is called when testing the
1266 DirectGdi SW version as setting a pen size other then (1,1) causes memory to be
1267 created that is not freed until SetPenSize(1,1) is called (or the related graphics
1268 engine is destroyed).
1269 This method calls CTContextBase::SetPenSize(1,1) on the passed CTContextBase object
1270 @param aPtr A pointer to a test context object, CTContextBase*.
1272 void CTDirectGdiStepBase::ResetPenSize(TAny* aPtr)
1274 if (CTContextBase* context = reinterpret_cast <CTContextBase*> (aPtr))
1275 context->SetPenSize(TSize(1,1));