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: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: #include "tsgdrawablegeneric.h" sl@0: #include sl@0: sl@0: CTSgDrawableGeneric::CTSgDrawableGeneric() sl@0: { sl@0: INFO_PRINTF1(_L("Graphics resource component test - RSgDrawable Generic Tests.\r\n")); sl@0: } sl@0: sl@0: CTSgDrawableGeneric::~CTSgDrawableGeneric() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Overrides 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 CTSgDrawableGeneric::doTestStepL() sl@0: { sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0013")); sl@0: INFO_PRINTF1(_L("Opening an image in RSgDrawable.\r\n")); sl@0: TestOpenImageAsDrawableL(); sl@0: RecordTestResultL(); sl@0: sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0014")); sl@0: INFO_PRINTF1(_L("Retrieving drawable id of an RSgDrawable object.\r\n")); sl@0: TestGetDrawableDrawableIdL(); sl@0: RecordTestResultL(); sl@0: sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0032")); sl@0: INFO_PRINTF1(_L("RSgDrawable::Open() with invalid parameters.\r\n")); sl@0: TestOpenDrawableInvalidL(); sl@0: RecordTestResultL(); sl@0: sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0033")); sl@0: INFO_PRINTF1(_L("Releasing reference to the image in RSgDrawable without first opening it.\r\n")); sl@0: TestCloseDrawableWithoutOpenL(); sl@0: RecordTestResultL(); sl@0: sl@0: #ifdef _DEBUG sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0081 sl@0: */ sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0081")); sl@0: INFO_PRINTF1(_L("RSgDrawable generic out of memory tests.\r\n")); sl@0: TestOOM(); sl@0: RecordTestResultL(); sl@0: sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0080")); sl@0: INFO_PRINTF1(_L("RSgDrawable generic panic test - Open() when the driver is not initialised.\r\n")); sl@0: TestPanicDrawableOpenNoDriverL(); sl@0: RecordTestResultL(); sl@0: #else sl@0: INFO_PRINTF1(_L("Warning: Skipping the panic tests in release build. \r\n")); sl@0: #endif sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0013 sl@0: @SYMTestCaseDesc Opens an RSgImage as an RSgDrawable. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ9225 sl@0: @SYMREQ REQ9224 sl@0: @SYMREQ REQ9233 sl@0: @SYMREQ REQ9234 sl@0: @SYMFssID RSgImage::Id()\n sl@0: RSgDrawable::Open(const TSgDrawableId&) sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To ensure an RSgDrawable object can reference an image. sl@0: @SYMTestActions Initialise the graphics resource component. Create an image. Declare an sl@0: RSgDrawable object. Call Open() on the object with the resource ID of the sl@0: image. sl@0: @SYMTestExpectedResults The function should return KErrNone. The RSgDrawable now references an sl@0: image. sl@0: @SYMTestStatus Implemented sl@0: */ sl@0: void CTSgDrawableGeneric::TestOpenImageAsDrawableL() sl@0: { sl@0: TestOpenDriverL(); sl@0: RSgImage image; sl@0: CreateImageL(image); sl@0: CleanupClosePushL(image); sl@0: const TSgDrawableId id = image.Id(); sl@0: TSgImageInfo imageinfo; sl@0: image.GetInfo(imageinfo); sl@0: sl@0: //opening an image as a drawable in the current thread sl@0: RSgImage drawable; sl@0: TEST(drawable.IsNull()); sl@0: CheckErrorL(KErrNone, drawable.Open(id), (TText8*)__FILE__, __LINE__); sl@0: TEST(!drawable.IsNull()); sl@0: drawable.Close(); sl@0: sl@0: //opening an image as a drawable in another thread in the same process sl@0: TSgresTestInfo threadInfo = {id, imageinfo, 0, ESgresSecondThreadOpenDrawable}; sl@0: TInt testResult = CreateSecondThreadAndDoTestL(threadInfo); sl@0: User::LeaveIfError(testResult); sl@0: TEST(testResult & EFirstTestPassed); sl@0: TEST(testResult & ESecondTestPassed); sl@0: TEST(testResult & EThirdTestPassed); sl@0: sl@0: //opening an image as drawbale in a different process sl@0: TSgresTestInfo processInfo = {id, imageinfo, 0, ESgresSecondProcessOpenDrawable}; sl@0: testResult = CreateSecondProcessAndDoTestL(KSecondProcess, processInfo); sl@0: User::LeaveIfError(testResult); sl@0: TEST(testResult & EFirstTestPassed); sl@0: TEST(testResult & ESecondTestPassed); sl@0: TEST(testResult & EThirdTestPassed); sl@0: sl@0: CleanupStack::PopAndDestroy(); sl@0: TestCloseDriver(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0014 sl@0: @SYMTestCaseDesc Retrieves drawable id of an RSgDrawable. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ9225 sl@0: @SYMREQ REQ9224 sl@0: @SYMREQ REQ9233 sl@0: @SYMREQ REQ9234 sl@0: @SYMFssID RSgImage::Id()\n sl@0: RSgDrawable::Open(const TSgDrawableId&)\n sl@0: RSgDrawable::Id() sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To ensure the globally unique drawable id of the RSgDrawable object can be retrieved. sl@0: @SYMTestActions Initialise the graphics resource component. Create an image. Call Id() on the image. sl@0: Construct an RSgDrawable object and open an image in it. Call Id() on the sl@0: RSgDrawable object. Compare the two ids. sl@0: @SYMTestExpectedResults The two drawable ids should be identical. sl@0: @SYMTestStatus Implemented sl@0: */ sl@0: void CTSgDrawableGeneric::TestGetDrawableDrawableIdL() sl@0: { sl@0: TestOpenDriverL(); sl@0: RSgImage image; sl@0: CreateImageL(image); sl@0: CleanupClosePushL(image); sl@0: TSgDrawableId id1 = image.Id(); sl@0: TEST(id1 != KSgNullDrawableId); sl@0: sl@0: RSgDrawable drawable; sl@0: TEST(KErrNone == drawable.Open(id1)); sl@0: TSgDrawableId id2 = drawable.Id(); sl@0: TEST(id2 != KSgNullDrawableId); sl@0: TEST(id1 == id2); sl@0: sl@0: drawable.Close(); sl@0: CleanupStack::PopAndDestroy(); sl@0: TestCloseDriver(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0032 sl@0: @SYMTestCaseDesc Calls RSgDrawable::Open() with invalid parameters. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ9225 sl@0: @SYMREQ REQ9224 sl@0: @SYMREQ REQ9233 sl@0: @SYMREQ REQ9234 sl@0: @SYMFssID RSgImage::Id()\n sl@0: RSgDrawable::Open(const TSgDrawableId&) sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To check the correct error codes are returned if Open() uses invalid parameters. sl@0: @SYMTestActions Initialise the graphics resource component. Create an image. Declare an RSgDrawable sl@0: object. Call Open() with:\n sl@0: \t 1. null drawable id\n sl@0: \t 2. a non-existing \n sl@0: \t 3. drawable id of a non-sharable image\n sl@0: \t 4. on a RSgDrawable handle that is not null\n sl@0: Do the same tests in a second thread in the same process and in a second process. sl@0: @SYMTestExpectedResults The function should return:\n sl@0: \t 1. KErrArgument\n sl@0: \t 2. KErrNotFound\n sl@0: \t 3. KErrNone in the same process and KErrPermissionDenied or KErrNotFound in the second process\n sl@0: \t 4. KErrInUse sl@0: @SYMTestStatus Implemented sl@0: */ sl@0: void CTSgDrawableGeneric::TestOpenDrawableInvalidL() sl@0: { sl@0: TestOpenDriverL(); sl@0: //same thread sl@0: // null drawable id sl@0: RSgDrawable drawable; sl@0: CheckErrorL(KErrArgument, drawable.Open(KSgNullDrawableId), (TText8*)__FILE__, __LINE__); sl@0: drawable.Close(); sl@0: sl@0: // non-existing drawable id sl@0: TSgDrawableId fakeid = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}; sl@0: CheckErrorL(KErrNotFound, drawable.Open(fakeid), (TText8*)__FILE__, __LINE__); sl@0: drawable.Close(); sl@0: sl@0: //create a non-sharable image sl@0: TSgImageInfo info; sl@0: info.iSizeInPixels = TSize(8, 8); sl@0: info.iUsage = ESgUsageDirectGdiTarget; sl@0: info.iPixelFormat = EUidPixelFormatRGB_565; sl@0: info.iCpuAccess = ESgCpuAccessNone; sl@0: info.iShareable = EFalse; sl@0: sl@0: RSgImage image; sl@0: CheckErrorL(KErrNone, image.Create(info, KImageData, 16), (TText8*)__FILE__, __LINE__); sl@0: CleanupClosePushL(image); sl@0: const TSgDrawableId id = image.Id(); sl@0: sl@0: // open a non-sharable image - should succeed sl@0: TEST(KErrNone == drawable.Open(id)); sl@0: sl@0: // open on a non-null RSgDrawable handle sl@0: TEST(KErrInUse == drawable.Open(id)); sl@0: drawable.Close(); sl@0: sl@0: //different thread in the same process sl@0: TSgresTestInfo threadInfo = {id, info, 0, ESgresSecondThreadOpenDrawableInvalid}; sl@0: TInt testResult = CreateSecondThreadAndDoTestL(threadInfo); sl@0: User::LeaveIfError(testResult); sl@0: TEST(testResult & EFirstTestPassed); sl@0: TEST(testResult & ESecondTestPassed); sl@0: TEST(testResult & EThirdTestPassed); sl@0: TEST(testResult & EFourthTestPassed); sl@0: sl@0: //different process sl@0: TSgresTestInfo processInfo = {id, info, 0, ESgresSecondProcessOpenDrawableInvalid}; sl@0: testResult = CreateSecondProcessAndDoTestL(KSecondProcess, processInfo); sl@0: User::LeaveIfError(testResult); sl@0: TEST(testResult & EFirstTestPassed); sl@0: TEST(testResult & ESecondTestPassed); sl@0: TEST(testResult & EThirdTestPassed); sl@0: TEST(testResult & EFourthTestPassed); sl@0: TEST(testResult & EFifthTestPassed); sl@0: sl@0: drawable.Close(); sl@0: CleanupStack::PopAndDestroy(); sl@0: TestCloseDriver(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0033 sl@0: @SYMTestCaseDesc Closes RSgDrawable without first opening it. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ9225 sl@0: @SYMREQ REQ9224 sl@0: @SYMREQ REQ9233 sl@0: @SYMREQ REQ9234 sl@0: @SYMFssID RSgDrawable::Close() sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To check the function does nothing if Open() was not called. sl@0: @SYMTestActions Initialise the graphics resource component. Declare an RSgDrawable object. Call Close(). sl@0: @SYMTestExpectedResults The function should not panic or return any error. sl@0: @SYMTestStatus Implemented sl@0: */ sl@0: void CTSgDrawableGeneric::TestCloseDrawableWithoutOpenL() sl@0: { sl@0: TestOpenDriverL(); sl@0: RSgDrawable drawable; sl@0: drawable.Close(); sl@0: drawable.Close(); sl@0: drawable.Close(); sl@0: TestCloseDriver(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0080 sl@0: @SYMTestCaseDesc Calls RSgDrawable::Open() when the driver was not initialised. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ8809 sl@0: @SYMREQ REQ9175 sl@0: @SYMFssID RSgImage::Open()\n sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To ensure calling RSgDrawable::Open() with an uninitialised driver will cause a panic. sl@0: @SYMTestActions Do not Initialise the graphics resource component and call RSgDrawable::Open() in a second thread. sl@0: @SYMTestExpectedResults The function should panic in the second thread with panic code SGRES 5 (ESgPanicNoDriver). sl@0: @SYMTestStatus Implemented sl@0: */ sl@0: void CTSgDrawableGeneric::TestPanicDrawableOpenNoDriverL() sl@0: { sl@0: TSgImageInfo info; sl@0: TSgresTestInfo threadInfo = {KSgNullDrawableId, info, 0, ESgresSecondThreadPanicDrawableOpenNoDriver, ETrue}; sl@0: TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory); sl@0: _LIT(KTestName, "TestPanicDrawableOpenNoDriverL"); sl@0: CreateSecondThreadAndCheckPanicL(threadInfo, 5, exitCategoryName, KTestName); sl@0: } sl@0: sl@0: void CTSgDrawableGeneric::DoMemoryTestsL() sl@0: { sl@0: __UHEAP_MARK; SgDriver::AllocMarkStart(); sl@0: TestOpenImageAsDrawableL(); sl@0: __UHEAP_MARKEND; SgDriver::AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; SgDriver::AllocMarkStart(); sl@0: TestGetDrawableDrawableIdL(); sl@0: __UHEAP_MARKEND; SgDriver::AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; SgDriver::AllocMarkStart(); sl@0: TestOpenDrawableInvalidL(); sl@0: __UHEAP_MARKEND; SgDriver::AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; SgDriver::AllocMarkStart(); sl@0: TestCloseDrawableWithoutOpenL(); sl@0: __UHEAP_MARKEND; SgDriver::AllocMarkEnd(0); sl@0: }