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 "tsgdriver.h" sl@0: sl@0: CTSgDriver::CTSgDriver() sl@0: { sl@0: INFO_PRINTF1(_L("Graphics resource component test - SgDriver Tests.\r\n")); sl@0: } sl@0: sl@0: CTSgDriver::~CTSgDriver() 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 CTSgDriver::doTestStepL() sl@0: { sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0001")); sl@0: INFO_PRINTF1(_L("Graphics resource component initialization and shutdown.\r\n")); sl@0: TestInitializationAndShutdown(); sl@0: RecordTestResultL(); sl@0: sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0002")); sl@0: INFO_PRINTF1(_L("Graphics resource component shutdown multiple time.\r\n")); sl@0: TestInitializeShutdownManyTimes(); sl@0: RecordTestResultL(); sl@0: sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0022")); sl@0: INFO_PRINTF1(_L("Shutting down an uninitialised driver.\r\n")); sl@0: TestShutdownUninitialized(); sl@0: RecordTestResultL(); sl@0: sl@0: #ifdef _DEBUG sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0078")); sl@0: INFO_PRINTF1(_L("SgDriver panic test - private heap memory leak.\r\n")); sl@0: TestDriverMemoryLeakL(); sl@0: RecordTestResultL(); sl@0: #ifndef __WINS__ sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0023")); sl@0: INFO_PRINTF1(_L("Shutting down without closing all resources.\r\n")); sl@0: TestShutdownMemoryLeakL(); sl@0: RecordTestResultL(); sl@0: #endif sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0079")); sl@0: INFO_PRINTF1(_L("SgDriver panic test - ResourceCount() without initialising the driver.\r\n")); sl@0: TestPanicResourceCountNoDriverL(); sl@0: RecordTestResultL(); sl@0: sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0090")); sl@0: INFO_PRINTF1(_L("SgDriver panic test - AllocMarkStart() without initialising the driver.\r\n")); sl@0: TestPanicAllocMarkStartNoDriverL(); sl@0: RecordTestResultL(); sl@0: sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0091")); sl@0: INFO_PRINTF1(_L("SgDriver panic test - AllocMarkEnd() without initialising the driver.\r\n")); sl@0: TestPanicAllocMarkEndNoDriverL(); sl@0: RecordTestResultL(); sl@0: sl@0: SetTestStepID(_L("GRAPHICS-RESOURCE-0092")); sl@0: INFO_PRINTF1(_L("SgDriver panic test - SetAllocFail() without initialising the driver.\r\n")); sl@0: TestPanicSetAllocFailNoDriverL(); sl@0: RecordTestResultL(); sl@0: #else sl@0: INFO_PRINTF1(_L("Warning: Skipping the panic tests. \r\n")); sl@0: #endif sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0001 sl@0: @SYMTestCaseDesc Initialises and shuts down the graphics resource driver. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ8809 sl@0: @SYMREQ REQ9175 sl@0: @SYMREQ REQ9224 sl@0: @SYMREQ REQ9233 sl@0: @SYMREQ REQ9234 sl@0: @SYMFssID SgDriver::Open()\n sl@0: RSgImage::Create(const TSgImageInfo&, const TAny*, TInt)\n sl@0: SgDriver::Close()\n sl@0: SgDriver::ResourceCount()\n sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To ensure the graphics resource driver can be initialised successfully sl@0: @SYMTestActions Call SgDriver::Open() to start the graphics resource driver, then try sl@0: to call RSgImage::Create(). Call SgDriver::Open() the second time sl@0: and then call RSgImage::Create() again. Close the driver and call sl@0: RSgImage::Create(). Close the driver. sl@0: @SYMTestExpectedResults RSgImage::Create() should return:\n sl@0: \t 1. KErrNone \n sl@0: \t 2. KErrNone \n sl@0: \t 3. KErrNone \n sl@0: SgDriver::Open() should return KErrNone both times. sl@0: @SYMTestStatus Implemented sl@0: */ sl@0: void CTSgDriver::TestInitializationAndShutdown() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: TSgImageInfo info; sl@0: info.iSizeInPixels = TSize(8, 8); sl@0: info.iUsage = ESgUsageDirectGdiSource; sl@0: info.iPixelFormat = EUidPixelFormatRGB_565; sl@0: info.iCpuAccess = ESgCpuAccessReadWrite; sl@0: info.iShareable = ETrue; sl@0: sl@0: RSgImage image; sl@0: TEST(KErrNone == SgDriver::Open()); sl@0: TEST(KErrNone == image.Create(info, KImageData, 16)); sl@0: TEST(0 < SgDriver::ResourceCount()); sl@0: image.Close(); sl@0: sl@0: TEST(KErrNone == SgDriver::Open()); sl@0: TEST(KErrNone == image.Create(info, KImageData, 16)); sl@0: image.Close(); sl@0: sl@0: SgDriver::Close(); sl@0: TEST(KErrNone == image.Create(info, KImageData, 16)); sl@0: image.Close(); sl@0: sl@0: TEST(0 == SgDriver::ResourceCount()); sl@0: SgDriver::Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0002 sl@0: @SYMTestCaseDesc Shuts down graphics resource driver multiple times. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ8809 sl@0: @SYMREQ REQ9175 sl@0: @SYMREQ REQ9224 sl@0: @SYMREQ REQ9233 sl@0: @SYMREQ REQ9234 sl@0: @SYMFssID SgDriver::Open()\n sl@0: SgDriver::Close()\n sl@0: SgDriver::ResourceCount()\n sl@0: RSgImage::Create(const TSgImageInfo&, const TAny*, TInt) sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To ensure the graphics resource driver could be shut down multiple times. sl@0: @SYMTestActions Initialise the graphics resource driver. Create an image then close it. sl@0: Shutdown the driver twice. Open and driver and create an image. Close the sl@0: image and shutdown the driver. sl@0: @SYMTestExpectedResults The graphics resource driver is successfully shut down. The calls to sl@0: RSgImage::Create() should return:\n sl@0: \t 1. KErrNone\n sl@0: \t 2. KErrNone\n sl@0: @SYMTestStatus Implemented sl@0: */ sl@0: void CTSgDriver::TestInitializeShutdownManyTimes() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: TEST(KErrNone == SgDriver::Open()); sl@0: sl@0: TSgImageInfo info; sl@0: info.iSizeInPixels = TSize(8, 8); sl@0: info.iUsage = ESgUsageDirectGdiSource; sl@0: info.iPixelFormat = EUidPixelFormatRGB_565; sl@0: info.iCpuAccess = ESgCpuAccessReadWrite; sl@0: info.iShareable = ETrue; sl@0: sl@0: RSgImage image; sl@0: sl@0: TEST(KErrNone == image.Create(info, KImageData, 16)); sl@0: image.Close(); sl@0: sl@0: SgDriver::Close(); sl@0: SgDriver::Close(); sl@0: sl@0: TEST(KErrNone == SgDriver::Open()); sl@0: TEST(KErrNone == image.Create(info, KImageData, 16)); sl@0: image.Close(); sl@0: sl@0: TEST(0 == SgDriver::ResourceCount()); sl@0: SgDriver::Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0022 sl@0: @SYMTestCaseDesc Shuts down an uninitialised driver. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ8809 sl@0: @SYMREQ REQ9175 sl@0: @SYMFssID SgDriver::Close() sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To ensure invalid Close() calls on the driver will cause no errors. sl@0: @SYMTestActions Call SgDriver::Close() several times without calling SgDriver::Open(). sl@0: @SYMTestExpectedResults No errors should be returned. sl@0: @SYMTestStatus Implemented sl@0: */ sl@0: void CTSgDriver::TestShutdownUninitialized() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: SgDriver::Close(); sl@0: SgDriver::Close(); sl@0: SgDriver::Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0023 sl@0: @SYMTestCaseDesc Shuts down the driver without closing all resources. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ8809 sl@0: @SYMREQ REQ9175 sl@0: @SYMREQ REQ9224 sl@0: @SYMREQ REQ9233 sl@0: @SYMREQ REQ9234 sl@0: @SYMFssID SgDriver::Open()\n sl@0: RSgImage::Create(const TSgImageInfo&, const TAny*, TInt)\n sl@0: SgDriver::Close() sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To ensure calling Close() without closing all resources will cause a panic. sl@0: @SYMTestActions Initialise the graphics resource component and create an image in a second thread. sl@0: Try to shutdown the component. sl@0: @SYMTestExpectedResults The function should panic in the second thread with panic code SGRES 1(ESgPanicUnclosedResources). sl@0: @SYMTestStatus Implemented sl@0: */ sl@0: void CTSgDriver::TestShutdownMemoryLeakL() sl@0: { sl@0: TestOpenDriverL(); sl@0: //run the test in another process sl@0: TSgImageInfo info; sl@0: TSgresTestInfo processInfo = {KSgNullDrawableId, info, 0, ESgresSecondProcessPanicDriverUnclosedResources, ETrue}; sl@0: TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory); sl@0: _LIT(KTestName, "TestShutdownMemoryLeakL"); sl@0: CreateSecondProcessAndCheckPanicL(processInfo, 1, exitCategoryName, KTestName); sl@0: TestCloseDriver(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0078 sl@0: @SYMTestCaseDesc Calls SgDriver::AllocMarkEnd() without shutting down all the resources. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ8809 sl@0: @SYMREQ REQ9175 sl@0: @SYMREQ REQ9224 sl@0: @SYMREQ REQ9233 sl@0: @SYMREQ REQ9234 sl@0: @SYMFssID SgDriver::AllocMarkStart()\n sl@0: SgDriver::AllocMarkEnd() sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To ensure calling SgDriver::AllocMarkEnd() without closing all resources will cause a panic. sl@0: @SYMTestActions Initialise the graphics resource component in a second process and call SgDriver::AllocMarkStart(). sl@0: Create an image and call SgDriver::AllocMarkEnd(). sl@0: @SYMTestExpectedResults The function should panic in the second process with panic code SGRES-ADAPTER 0. sl@0: @SYMTestStatus Implemented sl@0: */ sl@0: void CTSgDriver::TestDriverMemoryLeakL() sl@0: { sl@0: TestOpenDriverL(); sl@0: //run the test in another process sl@0: TSgImageInfo info; sl@0: TSgresTestInfo processInfo = {KSgNullDrawableId, info, 0, ESgresSecondProcessPanicMemoryLeak, ETrue}; sl@0: TExitCategoryName exitCategoryName(_L("SGALLOC")); sl@0: _LIT(KTestName, "TestDriverMemoryLeakL"); sl@0: CreateSecondProcessAndCheckPanicL(processInfo, 0, exitCategoryName, KTestName); sl@0: TestCloseDriver(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0079 sl@0: @SYMTestCaseDesc Calls SgDriver::ResourceCount() without initialising the driver. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ8809 sl@0: @SYMREQ REQ9175 sl@0: @SYMFssID SgDriver::ResourceCount())\n sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To ensure calling SgDriver::ResourceCount() without initialising sl@0: the driver first will cause a panic in the debug mode. sl@0: @SYMTestActions Do not Initialise the graphics resource component and call sl@0: SgDriver::ResourceCount() 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 CTSgDriver::TestPanicResourceCountNoDriverL() sl@0: { sl@0: TSgImageInfo info; sl@0: TSgresTestInfo threadInfo = {KSgNullDrawableId, info, 0, ESgresSecondThreadPanicResourceCountNoDriver, ETrue}; sl@0: TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory); sl@0: _LIT(KTestName, "TestPanicResourceCountNoDriverL"); sl@0: CreateSecondThreadAndCheckPanicL(threadInfo, 5, exitCategoryName, KTestName); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0090 sl@0: @SYMTestCaseDesc Calls SgDriver::AllocMarkStart() without initialising the driver. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ8809 sl@0: @SYMREQ REQ9175 sl@0: @SYMFssID SgDriver::AllocMarkStart())\n sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To ensure calling SgDriver::AllocMarkStart() without initialising sl@0: the driver first will cause a panic in the debug mode. sl@0: @SYMTestActions Do not Initialise the graphics resource component and call sl@0: SgDriver::AllocMarkStart() 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 CTSgDriver::TestPanicAllocMarkStartNoDriverL() sl@0: { sl@0: TSgImageInfo info; sl@0: TSgresTestInfo threadInfo = {KSgNullDrawableId, info, 0, ESgresSecondThreadPanicAllocMarkStartNoDriver, ETrue}; sl@0: TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory); sl@0: _LIT(KTestName, "TestPanicAllocMarkStartNoDriverL"); sl@0: CreateSecondThreadAndCheckPanicL(threadInfo, 5, exitCategoryName, KTestName); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0091 sl@0: @SYMTestCaseDesc Calls SgDriver::AllocMarkEnd() without initialising the driver. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ8809 sl@0: @SYMREQ REQ9175 sl@0: @SYMFssID SgDriver::AllocMarkEnd())\n sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To ensure calling SgDriver::AllocMarkEnd() without initialising sl@0: the driver first will cause a panic in the debug mode. sl@0: @SYMTestActions Do not Initialise the graphics resource component and call sl@0: SgDriver::AllocMarkEnd() 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 CTSgDriver::TestPanicAllocMarkEndNoDriverL() sl@0: { sl@0: TSgImageInfo info; sl@0: TSgresTestInfo threadInfo = {KSgNullDrawableId, info, 0, ESgresSecondThreadPanicAllocMarkEndNoDriver, ETrue}; sl@0: TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory); sl@0: _LIT(KTestName, "TestPanicAllocMarkEndNoDriverL"); sl@0: CreateSecondThreadAndCheckPanicL(threadInfo, 5, exitCategoryName, KTestName); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-RESOURCE-0092 sl@0: @SYMTestCaseDesc Calls SgDriver::SetAllocFail() without initialising the driver. sl@0: @SYMPREQ PREQ39 sl@0: @SYMREQ REQ8809 sl@0: @SYMREQ REQ9175 sl@0: @SYMFssID SgDriver::SetAllocFail())\n sl@0: @SYMTestPriority Critical sl@0: @SYMTestType Unit Test sl@0: @SYMTestPurpose To ensure calling SgDriver::SetAllocFail() without initialising sl@0: the driver first will cause a panic in the debug mode. sl@0: @SYMTestActions Do not Initialise the graphics resource component and call sl@0: SgDriver::SetAllocFail() 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 CTSgDriver::TestPanicSetAllocFailNoDriverL() sl@0: { sl@0: TSgImageInfo info; sl@0: TSgresTestInfo threadInfo = {KSgNullDrawableId, info, 0, ESgresSecondThreadPanicSetAllocFailNoDriver, ETrue}; sl@0: TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory); sl@0: _LIT(KTestName, "TestPanicSetAllocFailNoDriverL"); sl@0: CreateSecondThreadAndCheckPanicL(threadInfo, 5, exitCategoryName, KTestName); sl@0: }