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 "tdirectgdicontexttarget.h" sl@0: #include sl@0: sl@0: CTDirectGdiContextTarget::CTDirectGdiContextTarget() sl@0: { sl@0: SetTestStepName(KTDirectGdiContextTargetStep); sl@0: } sl@0: sl@0: CTDirectGdiContextTarget::~CTDirectGdiContextTarget() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-DIRECTGDI-CONTEXTTARGET-0001 sl@0: sl@0: @SYMTestPriority sl@0: Critical sl@0: sl@0: @SYMPREQ sl@0: PREQ39 sl@0: sl@0: @SYMREQ sl@0: REQ9195 sl@0: REQ9201 sl@0: REQ9202 sl@0: REQ9222 sl@0: REQ9223 sl@0: REQ9236 sl@0: REQ9237 sl@0: sl@0: @SYMTestCaseDesc sl@0: Use case - Single context and multiple targets. sl@0: sl@0: @SYMTestActions sl@0: Construct CDirectGdiDriver. sl@0: Construct CDirectGdiContext. sl@0: sl@0: Construct RSgImage1. sl@0: Construct MDirectGdiImageTarget1. sl@0: Create MDirectGdiImageTarget1, using RSgImage1. sl@0: sl@0: Activate CDirectGdiContext using MDirectGdiImageTarget1. sl@0: Do some drawing operations using a different pen/brush setting sl@0: sl@0: Construct RSgImage2. sl@0: Construct MDirectGdiImageTarget2. sl@0: Create MDirectGdiImageTarget2, using RSgImage2. sl@0: sl@0: Activate CDirectGdiContext using MDirectGdiImageTarget2. sl@0: Do some drawing operations using a different pen/brush setting sl@0: sl@0: Destroy RSgImage. sl@0: Destroy MDirectGdiImageTarget. sl@0: sl@0: Destroy CDirectGdiContext. sl@0: Close CDirectGdiDriver. sl@0: sl@0: @SYMTestExpectedResults sl@0: It should be able to switch the targets between the same context. sl@0: sl@0: @SYMTestStatus sl@0: Implemented sl@0: */ sl@0: void CTDirectGdiContextTarget::TestSwitchingTargetsL() sl@0: { sl@0: TInt result = KErrNone; sl@0: _LIT(KTestName, "ContextTarget-SwitchingTargets"); sl@0: if(!iRunningOomTests) sl@0: { sl@0: INFO_PRINTF1(KTestName); sl@0: } sl@0: sl@0: if (iTargetPixelFormatArray.Count() <= 1) sl@0: { sl@0: // The MBX driver only supports one pixelformat. This test has no purpose sl@0: // when both targets are the same, so in this case we don't run it. sl@0: INFO_PRINTF1(_L("Not enough formats supported. Skipping test...")); sl@0: return; sl@0: } sl@0: sl@0: TInt err = CDirectGdiDriver::Open(); sl@0: TESTNOERRORL(err); sl@0: sl@0: CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static(); sl@0: TESTL(dgdiDriver != NULL); sl@0: CleanupClosePushL(*dgdiDriver); sl@0: sl@0: CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver); sl@0: CleanupStack::PushL(gc); sl@0: sl@0: RSgImage rsgImage1; sl@0: RSgImage rsgImage2; sl@0: sl@0: // Set the bitmap up... sl@0: TSgImageInfo imageInfo; sl@0: imageInfo.iSizeInPixels = TSize (320, 240); sl@0: imageInfo.iPixelFormat = iTargetPixelFormatArray[0]; sl@0: imageInfo.iUsage = ESgUsageDirectGdiTarget; sl@0: result = rsgImage1.Create(imageInfo, NULL,0); sl@0: TESTNOERRORL(result); sl@0: CleanupClosePushL(rsgImage1); sl@0: sl@0: imageInfo.iSizeInPixels = TSize (300, 300); sl@0: imageInfo.iPixelFormat = iTargetPixelFormatArray[1]; sl@0: result = rsgImage2.Create(imageInfo, NULL,0); sl@0: TESTNOERRORL(result); sl@0: CleanupClosePushL(rsgImage2); sl@0: sl@0: RDirectGdiImageTarget dgdiImageTarget1(*dgdiDriver); sl@0: result = dgdiImageTarget1.Create(rsgImage1); sl@0: TESTNOERRORL(result); sl@0: CleanupClosePushL(dgdiImageTarget1); sl@0: sl@0: result = gc->Activate (dgdiImageTarget1); sl@0: TESTNOERRORL(result); sl@0: gc->SetPenColor(TRgb(100,100,100)); sl@0: TEST(gc->PenColor() == TRgb(100,100,100)); sl@0: gc->DrawEllipse(TRect(0,0,30,30)); sl@0: TESTNOERROR(dgdiDriver->GetError()); sl@0: sl@0: RDirectGdiImageTarget dgdiImageTarget2(*dgdiDriver); sl@0: result = dgdiImageTarget2.Create(rsgImage1); sl@0: TESTNOERRORL(result); sl@0: CleanupClosePushL(dgdiImageTarget2); sl@0: sl@0: result = gc->Activate (dgdiImageTarget2); sl@0: TESTNOERRORL(result); sl@0: gc->SetPenColor(TRgb(0,0,0)); sl@0: TEST(gc->PenColor() == TRgb(0,0,0)); sl@0: gc->DrawEllipse(TRect(0,0,30,30)); sl@0: TESTNOERROR(dgdiDriver->GetError()); sl@0: sl@0: CleanupStack::PopAndDestroy(6, dgdiDriver); //dgdiImageTarget1&2, rsgImage1&2, gc, dgdiDriver sl@0: sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-DIRECTGDI-CONTEXTTARGET-0002 sl@0: sl@0: @SYMTestPriority sl@0: Critical sl@0: sl@0: @SYMPREQ sl@0: PREQ39 sl@0: sl@0: @SYMREQ sl@0: REQ9195 sl@0: REQ9201 sl@0: REQ9202 sl@0: REQ9222 sl@0: REQ9223 sl@0: REQ9236 sl@0: REQ9237 sl@0: sl@0: @SYMTestCaseDesc sl@0: Test the integrity of RSgImage metadata after being written to. sl@0: sl@0: @SYMTestActions sl@0: Construct CDirectGdiDriver. sl@0: Construct CDirectGdiContext. sl@0: Construct RSgImage. sl@0: Construct MDirectGdiImageTarget. sl@0: Create MDirectGdiImageTarget1, using RSgImage. sl@0: Check the current RSgImage info matches that at creation time. sl@0: Activate CDirectGdiContext using MDirectGdiImageTarget. sl@0: Do some drawing operations on the target. sl@0: Check the current RSgImage info matches that at creation time. sl@0: Destroy RSgImage. sl@0: Destroy MDirectGdiImageTarget. sl@0: Destroy CDirectGdiContext. sl@0: Close CDirectGdiDriver. sl@0: sl@0: @SYMTestExpectedResults sl@0: The RSgImage info should be the same at all times. sl@0: sl@0: @SYMTestStatus sl@0: Implemented sl@0: */ sl@0: void CTDirectGdiContextTarget::TestRSgImageMetadataIntegrityL() sl@0: { sl@0: _LIT(KTestName, "ContextTarget-RSgImageMetadataIntegrity"); sl@0: if(!iRunningOomTests) sl@0: { sl@0: INFO_PRINTF1(KTestName); sl@0: } sl@0: sl@0: TInt err = CDirectGdiDriver::Open(); sl@0: TESTNOERRORL(err); sl@0: CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static(); sl@0: TESTL(dgdiDriver != NULL); sl@0: CleanupClosePushL(*dgdiDriver); sl@0: CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver); sl@0: CleanupStack::PushL(gc); sl@0: sl@0: // Create RSgImage, initialise some info. sl@0: RSgImage rsgImage; sl@0: TSgImageInfo imageInfo; sl@0: imageInfo.iSizeInPixels = TSize (320, 240); sl@0: imageInfo.iPixelFormat = iTestParams.iTargetPixelFormat; sl@0: imageInfo.iUsage = ESgUsageDirectGdiTarget; sl@0: TInt result = rsgImage.Create(imageInfo, NULL,0); sl@0: TESTNOERRORL(result); sl@0: CleanupClosePushL(rsgImage); sl@0: sl@0: // Test that after creation, the info is still the same. sl@0: TSgImageInfo retrievedInfo; sl@0: TESTNOERRORL(rsgImage.GetInfo(retrievedInfo)); sl@0: TBool match = CompareInfos(retrievedInfo, imageInfo); sl@0: TEST(match); sl@0: sl@0: // Perform writing to the target. sl@0: RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver); sl@0: TESTNOERRORL(dgdiImageTarget.Create(rsgImage)); sl@0: CleanupClosePushL(dgdiImageTarget); sl@0: TESTNOERRORL(gc->Activate (dgdiImageTarget) ); sl@0: gc->SetBrushColor(TRgb(255,0,0,255)); sl@0: gc->Clear(); sl@0: dgdiDriver->Finish(); sl@0: sl@0: // Test that after being written to, the info is still the same. If this fails, sl@0: // an indication that image data is being written over the metadata. sl@0: TESTNOERRORL(rsgImage.GetInfo(retrievedInfo)); sl@0: match = CompareInfos(retrievedInfo, imageInfo); sl@0: TEST(match); sl@0: sl@0: CleanupStack::PopAndDestroy(4); //dgdiImageTarget, rsgImage, gc, dgdiDriver sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-DIRECTGDI-CONTEXTTARGET-0003 sl@0: sl@0: @SYMTestPriority sl@0: Critical sl@0: sl@0: @SYMPREQ sl@0: PREQ39 sl@0: sl@0: @SYMREQ sl@0: REQ9195 sl@0: REQ9201 sl@0: REQ9202 sl@0: REQ9222 sl@0: REQ9223 sl@0: REQ9236 sl@0: REQ9237 sl@0: sl@0: @SYMTestCaseDesc sl@0: Test that the RdirectGdiImageTarget::Create() and RDirectGdiDrawableSource::Create() methods sl@0: validate their arguments. sl@0: - Test that creation of a target from an RSgImage that was created as a source fails. sl@0: - Test that creation of a source from an RSgImage that was created as a target fails. sl@0: sl@0: @SYMTestActions sl@0: Construct CDirectGdiDriver. sl@0: Construct CDirectGdiContext. sl@0: Create a RSgImage 1 as a source. sl@0: Create a RSgImage 2 as a target. sl@0: Attempt to create RDirectGdiImageTarget from RSgImage 1 (a source). sl@0: KErrNotSupported should be returned. sl@0: Attempt to create RDirectGdiDrawableSource from RSgImage 2 (a target). sl@0: KErrNotSupported should be returned. sl@0: sl@0: @SYMTestExpectedResults sl@0: Functions return the correct error code. sl@0: sl@0: @SYMTestStatus sl@0: Implemented sl@0: */ sl@0: void CTDirectGdiContextTarget::TestCreateCloseSourceTargetInvalidParametersL() sl@0: { sl@0: _LIT(KTestName, "ContextTarget-CreateCloseSourceTargetInvalidParameters"); sl@0: if(!iRunningOomTests) sl@0: { sl@0: INFO_PRINTF1(KTestName); sl@0: } sl@0: sl@0: TInt err = CDirectGdiDriver::Open(); sl@0: TESTNOERRORL(err); sl@0: CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static(); sl@0: TESTL(dgdiDriver != NULL); sl@0: CleanupClosePushL(*dgdiDriver); sl@0: sl@0: CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver); sl@0: CleanupStack::PushL(gc); sl@0: sl@0: //Create an image with usage set to ESgUsageDirectGdiSource sl@0: TSgImageInfo info1; sl@0: info1.iSizeInPixels = TSize(8, 8); sl@0: info1.iUsage = ESgUsageDirectGdiSource; sl@0: info1.iPixelFormat = EUidPixelFormatARGB_8888; sl@0: info1.iCpuAccess = ESgCpuAccessReadWrite; sl@0: info1.iShareable = ETrue; sl@0: RSgImage image1; sl@0: TESTNOERRORL(image1.Create(info1, NULL, 0)); sl@0: CleanupClosePushL(image1); sl@0: sl@0: //Create an image with usage set to ESgUsageDirectGdiTarget sl@0: TSgImageInfo info2; sl@0: info2.iSizeInPixels = TSize(8, 8); sl@0: info2.iUsage = ESgUsageDirectGdiTarget; sl@0: info2.iPixelFormat = EUidPixelFormatRGB_565; sl@0: info2.iCpuAccess = ESgCpuAccessNone; sl@0: info2.iShareable = ETrue; sl@0: RSgImage image2; sl@0: TESTNOERRORL(image2.Create(info2, NULL, 0)); sl@0: CleanupClosePushL(image2); sl@0: sl@0: //create a RDirectGdiImageTarget from an image with sl@0: //usage set to ESgUsageDirectGdiSource sl@0: RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver); sl@0: TESTL(KErrNotSupported == dgdiImageTarget.Create(image1)); sl@0: sl@0: //create a RDirectGdiDrawableSource from an image with sl@0: //usage set to ESgUsageDirectGdiTarget sl@0: RDirectGdiDrawableSource dgdiImageSource(*dgdiDriver); sl@0: TESTL(KErrNotSupported == dgdiImageSource.Create(image2)); sl@0: sl@0: //create a RDirectGdiImageTarget from an image with sl@0: //usage set to ESgUsageDirectGdiTarget sl@0: //should succeed sl@0: TESTNOERRORL(dgdiImageTarget.Create(image2)); sl@0: CleanupClosePushL(dgdiImageTarget); sl@0: sl@0: // Need to activate a target before we can create a source due to OpenVG limitation. sl@0: // An OpenVG context must exist before a source can be created, but is not available sl@0: // until a target is activated. sl@0: gc->Activate(dgdiImageTarget); sl@0: sl@0: //create a RDirectGdiDrawableSource from an image with sl@0: //usage set to ESgUsageDirectGdiSource sl@0: //should succeed sl@0: TESTNOERRORL(dgdiImageSource.Create(image1)); sl@0: CleanupClosePushL(dgdiImageSource); sl@0: sl@0: CleanupStack::PopAndDestroy(6, dgdiDriver); 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 CTDirectGdiContextTarget::doTestStepL() sl@0: { sl@0: if(iUseDirectGdi) sl@0: { sl@0: // Test for each pixel format sl@0: for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--) sl@0: { sl@0: iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex]; sl@0: RunTestsL(); sl@0: RunOomTestsL(); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("BitGDI has no RSgImage to test!")); sl@0: } sl@0: CloseTMSGraphicsStep(); 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 CTDirectGdiContextTarget::doTestStepPreambleL() sl@0: { sl@0: CTDirectGdiStepBase::doTestStepPreambleL(); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: Override of base class pure virtual sl@0: Lists the tests to be run sl@0: */ sl@0: void CTDirectGdiContextTarget::RunTestsL() sl@0: { sl@0: SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXTTARGET-0001")); sl@0: TestSwitchingTargetsL(); sl@0: RecordTestResultL(); sl@0: SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXTTARGET-0002")); sl@0: TestRSgImageMetadataIntegrityL(); sl@0: RecordTestResultL(); sl@0: SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXTTARGET-0003")); sl@0: TestCreateCloseSourceTargetInvalidParametersL(); sl@0: RecordTestResultL(); sl@0: } sl@0: sl@0: /** sl@0: Helper function to test the equivalence of two TSgImageInfo structures. sl@0: sl@0: @see CTSgTestStepBase::CompareInfos sl@0: @param info1 A TSgImageInfo structure to compare. sl@0: @param info2 A TSgImageInfo structure to compare. sl@0: sl@0: @return ETrue if the two are identical, EFalse otherwise. sl@0: */ sl@0: TBool CTDirectGdiContextTarget::CompareInfos(const TSgImageInfo& info1, const TSgImageInfo& info2) sl@0: { sl@0: return info1.iCpuAccess == info2.iCpuAccess sl@0: && info1.iPixelFormat == info2.iPixelFormat sl@0: && info1.iScreenId == info2.iScreenId sl@0: && info1.iShareable == info2.iShareable sl@0: && info1.iSizeInPixels == info2.iSizeInPixels sl@0: && info1.iUsage | info2.iUsage sl@0: && info1.iUserAttributeCount == info2.iUserAttributeCount; sl@0: }