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 - Graphics Resource API Conformance Test Suite sl@0: */ sl@0: sl@0: #include "tgraphicsresourceteststepbase.h" sl@0: #include sl@0: sl@0: CTSgTestStepBase::CTSgTestStepBase(TBool aConformanceTests) : sl@0: iEnableConformanceTests(aConformanceTests) sl@0: { sl@0: } sl@0: sl@0: CTSgTestStepBase::~CTSgTestStepBase() sl@0: { sl@0: iSecondThread.Close(); sl@0: iPixelFormatArray.Close(); sl@0: User::Free(iDiagonalImageData); sl@0: iSgDriver.Close(); sl@0: } sl@0: sl@0: /** sl@0: Overrides of base class virtual sl@0: @leave Gets system wide error code sl@0: @return - TVerdict code sl@0: */ sl@0: TVerdict CTSgTestStepBase::doTestStepPreambleL() sl@0: { sl@0: // Set the logger to shared so that secondary threads can write to the log sl@0: User::LeaveIfError(Logger().ShareAuto()); sl@0: SetTestStepResult(EPass); sl@0: iDiagonalImageData = static_cast(User::AllocL(KDiagonalImageSize * KDiagonalImageDataStride)); sl@0: // Populate iDiagonalImageData with green diagonal from top-left to bottom-right on white background sl@0: Mem::Fill(iDiagonalImageData, KDiagonalImageSize * KDiagonalImageDataStride, 0xFF); sl@0: for (TInt i = 0; i < KDiagonalImageSize; ++i) sl@0: { sl@0: iDiagonalImageData[i * (KDiagonalImageSize + 1)] = 0xFF00FF00; 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 CTSgTestStepBase::doTestStepPostambleL() sl@0: { sl@0: User::Free(iDiagonalImageData); sl@0: iDiagonalImageData = NULL; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: Creates an image with some predefined parameters. sl@0: @param aImage output image handle sl@0: @leave Gets system wide error code sl@0: */ sl@0: void CTSgTestStepBase::CreateImageL(RSgImage& aImage) sl@0: { sl@0: TSgImageInfo info; sl@0: info.iSizeInPixels = TSize(8, 8); sl@0: info.iUsage = ESgUsageBitOpenVgImage; sl@0: info.iPixelFormat = EUidPixelFormatRGB_565; sl@0: sl@0: CheckErrorL(KErrNone, aImage.Create(info, KCrossImageData, KCrossImageDataStride), (TText8*)__FILE__, __LINE__); sl@0: } sl@0: sl@0: /** sl@0: Creates a second process and do some tests in it. sl@0: @param aProcessName The name of the new process sl@0: @param aTestInfo The information for the tests sl@0: @return A bitwise mask of test passes (never an error code) sl@0: @leave Gets system wide error code sl@0: */ sl@0: TInt CTSgTestStepBase::CreateSecondProcessAndDoTestL(const TDesC &aProcessName, TSgProcessTestInfo& aTestInfo) sl@0: { sl@0: // Create a second process sl@0: RProcess process; sl@0: TInt err = process.Create(aProcessName, KNullDesC); sl@0: User::LeaveIfError(err); sl@0: CleanupClosePushL(process); sl@0: sl@0: // Specify the id passed to the second process sl@0: TPckg ptr(aTestInfo); sl@0: TESTL(KErrNone == process.SetParameter(KSecondProcessParametersSlot, ptr)); sl@0: sl@0: // Kick off the second process and wait for it to complete sl@0: // The actual testing is done in the second process sl@0: TRequestStatus status = KRequestPending; sl@0: process.Logon(status); sl@0: process.Resume(); sl@0: User::WaitForRequest(status); sl@0: sl@0: // exitreason could either be a negative error code or a bitwise sl@0: // mask of test passes. sl@0: TInt exitreason = process.ExitReason(); sl@0: sl@0: CleanupStack::PopAndDestroy(); sl@0: sl@0: if (exitreason < KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("The second process returned error code %d"), exitreason); sl@0: TEST(EFalse); sl@0: exitreason = 0; sl@0: } sl@0: //return test result sl@0: return exitreason; sl@0: } sl@0: sl@0: /** sl@0: Creates a second process, runs the requested test and ensures that sl@0: the specified panic occurs. sl@0: sl@0: @param aTestInfo The specification for this test sl@0: @param aPanicCode The expected panic code sl@0: @param aExitCategory The expected panic category sl@0: @param aProcessName The name of the new process sl@0: sl@0: @leave One of the system wide error codes sl@0: */ sl@0: void CTSgTestStepBase::CreateSecondProcessAndCheckPanicL(TSgProcessTestInfo& aTestInfo, TInt aPanicCode, TExitCategoryName aExitCategory, const TDesC &aProcessName) sl@0: { sl@0: // Create a second process sl@0: RProcess process; sl@0: User::LeaveIfError(process.Create(aProcessName, KNullDesC)); sl@0: CleanupClosePushL(process); sl@0: sl@0: // Specify the id passed to the second process sl@0: TPckg ptr(aTestInfo); sl@0: TESTL(KErrNone == process.SetParameter(KSecondProcessParametersSlot, ptr)); sl@0: sl@0: // Kick off the second process and wait for it to complete sl@0: // The actual testing is done in the second process sl@0: TRequestStatus status = KRequestPending; sl@0: process.Logon(status); sl@0: process.Resume(); sl@0: User::WaitForRequest(status); sl@0: sl@0: if(EExitPanic != process.ExitType()) sl@0: { sl@0: ERR_PRINTF3(_L("Expected exit type: %d, Actual exit type: %d"), EExitPanic, process.ExitType()); sl@0: TEST(EFalse); sl@0: } sl@0: sl@0: if(aPanicCode != process.ExitReason()) sl@0: { sl@0: ERR_PRINTF3(_L("Expected panic code: %d, Actual panic code: %d"), aPanicCode, process.ExitReason()); sl@0: TEST(EFalse); sl@0: } sl@0: sl@0: TExitCategoryName secondProcessExitCategory = process.ExitCategory(); sl@0: if(aExitCategory != secondProcessExitCategory) sl@0: { sl@0: ERR_PRINTF3(_L("Expected panic category: %S, Actual panic category: %S"), &aExitCategory, &secondProcessExitCategory); sl@0: TEST(EFalse); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: /** sl@0: Creates a second thread and do some tests in it. sl@0: @param aTestInfo The information for the tests sl@0: @leave Gets system wide error code sl@0: */ sl@0: TInt CTSgTestStepBase::CreateSecondThreadAndDoTestL(TSgThreadTestInfo aTestInfo) sl@0: { sl@0: //create a semaphore sl@0: RSemaphore sem; sl@0: User::LeaveIfError(sem.CreateGlobal(KSecondThreadSemaphore, 0, EOwnerThread)); sl@0: CleanupClosePushL(sem); sl@0: sl@0: aTestInfo.iTestStep = this; sl@0: sl@0: User::LeaveIfError(iSecondThread.Create(KSecondThread, SgTestSecondThread::ThreadStart, KDefaultStackSize, KSecondThreadMinHeapSize, KSecondThreadMaxHeapSize, &aTestInfo)); sl@0: // Launch second thread sl@0: TRequestStatus statusSecondThread; sl@0: iSecondThread.Logon(statusSecondThread); sl@0: iSecondThread.SetPriority(EPriorityLess); sl@0: iSecondThread.Resume(); sl@0: sl@0: User::WaitForRequest(statusSecondThread); sl@0: sl@0: TExitCategoryName exitCategory = iSecondThread.ExitCategory(); sl@0: if (exitCategory.Compare(_L("Kill")) != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Second thread terminated with reason category '%S'"), &exitCategory); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: TInt result = iSecondThread.ExitReason(); sl@0: sl@0: //Close the handle sl@0: CleanupStack::PopAndDestroy(1, &sem); sl@0: iSecondThread.Close(); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Creates a second thread and do some panic tests in it. sl@0: @param aTestInfo The information for the tests sl@0: @param aPanicCode The expected panic code sl@0: @param aExitCategory The expected panic category sl@0: @param aThreadName The name of the new thread sl@0: @leave Gets system wide error code sl@0: */ sl@0: void CTSgTestStepBase::CreateSecondThreadAndCheckPanicL(TSgThreadTestInfo aTestInfo, TInt aPanicCode, TExitCategoryName aExitCategory, const TDesC &aThreadName) sl@0: { sl@0: aTestInfo.iTestStep = this; sl@0: User::LeaveIfError(iSecondThread.Create(aThreadName, SgTestSecondThread::ThreadStart, KDefaultStackSize, KSecondThreadMinHeapSize, KSecondThreadMaxHeapSize, &aTestInfo)); sl@0: sl@0: // Launch second thread sl@0: TRequestStatus statusSecondThread; sl@0: iSecondThread.Logon(statusSecondThread); sl@0: iSecondThread.SetPriority(EPriorityLess); sl@0: iSecondThread.Resume(); sl@0: sl@0: User::WaitForRequest(statusSecondThread); sl@0: sl@0: if(EExitPanic != iSecondThread.ExitType()) sl@0: { sl@0: ERR_PRINTF3(_L("Expected exit type: %d, Actual exit type: %d"), EExitPanic, iSecondThread.ExitType()); sl@0: TEST(EFalse); sl@0: } sl@0: sl@0: if(aPanicCode != iSecondThread.ExitReason()) sl@0: { sl@0: ERR_PRINTF3(_L("Expected panic code: %d, Actual panic code: %d"), aPanicCode, iSecondThread.ExitReason()); sl@0: TEST(EFalse); sl@0: } sl@0: sl@0: TExitCategoryName secondThreadExitCategory = iSecondThread.ExitCategory(); sl@0: if(aExitCategory != secondThreadExitCategory) sl@0: { sl@0: ERR_PRINTF3(_L("Expected panic category: %S, Actual panic category: %S"), &aExitCategory, &secondThreadExitCategory); sl@0: TEST(EFalse); sl@0: } sl@0: sl@0: //Close the handle sl@0: iSecondThread.Close(); sl@0: } sl@0: sl@0: /** sl@0: Gets the supporting pixel formats according to the specified usage bit. sl@0: @leave Gets system wide error code sl@0: */ sl@0: void CTSgTestStepBase::CallGetPixelFormatsL(TUint32 aUsage) sl@0: { sl@0: iPixelFormatArray.Reset(); sl@0: CheckErrorL(KErrNone, RSgImage::GetPixelFormats(aUsage, iPixelFormatArray), (TText8*)__FILE__, __LINE__); sl@0: } sl@0: sl@0: /** sl@0: Checks the pixel formats returned against the compatibility guarantee table. sl@0: @leave Gets system wide error code sl@0: */ sl@0: void CTSgTestStepBase::TestGetPixelFormatCompatibilityGuaranteesL() sl@0: { sl@0: _LIT(KLibOpenGLES2, "libGLESv2.dll"); sl@0: sl@0: RLibrary lib; sl@0: TBool supportGLES2 = (lib.Load(KLibOpenGLES2) == KErrNone); sl@0: lib.Close(); sl@0: sl@0: // OpenVG - Mandatory support sl@0: CallGetPixelFormatsL(ESgUsageBitOpenVgImage); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888_PRE)); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888)); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatXRGB_8888)); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatRGB_565)); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatA_8)); sl@0: CallGetPixelFormatsL(ESgUsageBitOpenVgSurface); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888_PRE)); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatXRGB_8888)); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatRGB_565)); sl@0: sl@0: // OpenGL ES - Not mandatory, but should cause no errors. sl@0: CallGetPixelFormatsL(ESgUsageBitOpenGlesTexture2D); sl@0: CallGetPixelFormatsL(ESgUsageBitOpenGlesSurface); sl@0: sl@0: // OpenGL ES 2 - Mandatory if present. sl@0: CallGetPixelFormatsL(ESgUsageBitOpenGles2Texture2D); sl@0: if (supportGLES2) sl@0: { sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888_PRE)); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888)); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatXRGB_8888)); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatRGB_565)); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatA_8)); sl@0: } sl@0: CallGetPixelFormatsL(ESgUsageBitOpenGles2Surface); sl@0: if (supportGLES2) sl@0: { sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888_PRE)); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatXRGB_8888)); sl@0: TEST(CheckPixelFormatPresent(ESgPixelFormatRGB_565)); sl@0: } sl@0: sl@0: iPixelFormatArray.Reset(); sl@0: } sl@0: sl@0: /** sl@0: Helper function to check if a certain pixel format is present sl@0: in the pixel formats array retrieved by CallGetPixelFormatsL(). sl@0: sl@0: @param aPixelFormat The pixelformat to check sl@0: @return ETrue if the pixel format is present, otherwise EFalse sl@0: @see CTsgTestStepBase::CallGetPixelFormats() sl@0: */ sl@0: TBool CTSgTestStepBase::CheckPixelFormatPresent(TSgPixelFormat aPixelFormat) sl@0: { sl@0: for(TInt i=0; i(aInfo); sl@0: sl@0: RSemaphore sem; sl@0: TInt openSem = sem.OpenGlobal(KSecondThreadSemaphore, EOwnerThread); sl@0: sl@0: TInt result = KErrNone; sl@0: TRAPD(leaveCode, result = SgTestSecondThread::ThreadMainL(testInfo)); sl@0: if (KErrNone == openSem) sl@0: { sl@0: sem.Signal(); sl@0: } sl@0: sem.Close(); sl@0: sl@0: if (leaveCode != KErrNone) sl@0: { sl@0: testInfo->iTestStep->ERR_PRINTF2(_L("Second thread caused Leave (%d)"), leaveCode); sl@0: testInfo->iTestStep->SetTestStepResult(EFail); sl@0: result = leaveCode; sl@0: } sl@0: sl@0: delete cleanupStack; sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Run the test contained within the TSgresTestInfo object. A new thread is sl@0: created for each test and only one of the cases in the switch statements sl@0: below will be used. sl@0: sl@0: The first switch statement contains tests that must have no driver open, sl@0: the second set require an open driver to initiate the test but may sl@0: close it part way through. sl@0: sl@0: @param aInfo The parameters for the test sl@0: @return One of the system wide error codes or an enumeration of passed tests. sl@0: */ sl@0: TInt SgTestSecondThread::ThreadMainL(TSgThreadTestInfo* aInfo) sl@0: { sl@0: TInt result = 0; sl@0: sl@0: TSgresTestCase testcase = ((TSgThreadTestInfo*)aInfo)->iTestCase; sl@0: sl@0: RSgDriver driver; sl@0: CleanupClosePushL(driver); sl@0: TInt ret = driver.Open(); sl@0: if(KErrNoMemory == ret) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: //test cases without the need of an initialised driver sl@0: switch (testcase) sl@0: { sl@0: case ESgresSecondThreadPanicDrawableOpenNoDriver: sl@0: { sl@0: driver.Close(); sl@0: RSgDrawable drawable; sl@0: drawable.Open(KFakeSgDrawableId); // should panic with SGRES 1 sl@0: } sl@0: break; sl@0: case ESgresSecondThreadPanicImageOpenNoDriver: sl@0: { sl@0: driver.Close(); sl@0: RSgImage image; sl@0: image.Open(KFakeSgDrawableId); // should panic with SGRES 1 sl@0: image.Close(); sl@0: } sl@0: case ESgresSecondThreadPanicImageCreateNoDriver1: sl@0: { sl@0: driver.Close(); sl@0: RSgImage image; sl@0: image.Create(KSgImageInfo1, NULL, 0); // should panic with SGRES 1 sl@0: image.Close(); sl@0: } sl@0: break; sl@0: case ESgresSecondThreadPanicImageCreateNoDriver2: sl@0: { sl@0: driver.Close(); sl@0: RSgImage image; sl@0: RSgImage tempImage; sl@0: image.Create(KSgImageInfo1, tempImage); // should panic with SGRES 1 sl@0: image.Close(); sl@0: } sl@0: break; sl@0: case ESgresSecondThreadOpenImage: sl@0: result = OpenImage(((TSgThreadTestInfo*)aInfo), driver); sl@0: break; sl@0: case ESgresSecondThreadOpenDrawable: sl@0: result = OpenDrawable(((TSgThreadTestInfo*)aInfo)); sl@0: break; sl@0: case ESgresSecondThreadOpenImageInvalid: sl@0: result = OpenImageInvalid(((TSgThreadTestInfo*)aInfo)); sl@0: break; sl@0: case ESgresSecondThreadOpenDrawableInvalid: sl@0: result = OpenDrawableInvalid(((TSgThreadTestInfo*)aInfo)); sl@0: break; sl@0: case ESgresSecondThreadPanicImageGetInterfaceInvalidHandle: sl@0: result = PanicImageGetInterfaceInvalidHandle(driver); sl@0: break; sl@0: case ESgresSecondThreadPanicImageGetInterfaceNoDriver: sl@0: result = PanicImageGetInterfaceNoDriver(driver); sl@0: break; sl@0: case ESgresSecondThreadPanicImageCloseInvalidHandle: sl@0: result = PanicImageCloseInvalidHandle(driver); sl@0: break; sl@0: case ESgresSecondThreadPanicImageCloseNoDriver: sl@0: result = PanicImageCloseNoDriver(driver); sl@0: break; sl@0: case ESgresSecondThreadPanicImageIdInvalidHandle: sl@0: result = PanicImageIdInvalidHandle(driver); sl@0: break; sl@0: case ESgresSecondThreadPanicImageIdNoDriver: sl@0: result = PanicImageIdNoDriver(driver); sl@0: break; sl@0: case ESgresSecondThreadPanicImageDrawableTypeInvalidHandle: sl@0: result = PanicImageDrawableTypeInvalidHandle(driver); sl@0: break; sl@0: case ESgresSecondThreadPanicImageDrawableTypeNoDriver: sl@0: result = PanicImageDrawableTypeNoDriver(driver); sl@0: break; sl@0: case ESgresSecondThreadPanicImageCreateInvalidHandle: sl@0: result = PanicImageCreateInvalidHandle(driver); sl@0: break; sl@0: case ESgresSecondThreadPanicImageGetInfoInvalidHandle: sl@0: result = PanicImageGetInfoInvalidHandle(driver); sl@0: break; sl@0: case ESgresSecondThreadPanicImageGetInfoNoDriver: sl@0: result = PanicImageGetInfoNoDriver(driver); sl@0: break; sl@0: case ESgresSecondThreadPanicImageGetAttributeInvalidHandle: sl@0: result = PanicImageGetAttributeInvalidHandle(driver); sl@0: break; sl@0: case ESgresSecondThreadPanicImageGetAttributeNoDriver: sl@0: result = PanicImageGetAttributeNoDriver(driver); sl@0: break; sl@0: case ESgresMultipleThreadStressTest: sl@0: result = MultipleThreadStressTest(((TSgThreadTestInfo*)aInfo)); sl@0: break; sl@0: case ESgresSecondThreadPanicAttributeArrayInvalidIndex: sl@0: PanicAttributeArrayInvalidIndexL(); sl@0: break; sl@0: case ESgresSecondThreadPanicAttributeArrayInvalidIndex2: sl@0: PanicAttributeArrayInvalidIndex2L(); sl@0: break; sl@0: case ESgresSecondThreadOpenPassedDriver: sl@0: result = ((TSgThreadTestInfo*)aInfo)->iSgDriver->Open(); sl@0: break; sl@0: case ESgresSecondThreadClosePassedDriver: sl@0: ((TSgThreadTestInfo*)aInfo)->iSgDriver->Close(); sl@0: break; sl@0: case ESgresSecondThreadCreatePassedImage: sl@0: result = CreatePassedImageL(((TSgThreadTestInfo*)aInfo)->iSgImage); sl@0: break; sl@0: case ESgresSecondThreadOpenPassedImage: sl@0: ((TSgThreadTestInfo*)aInfo)->iSgImage->Open(((TSgThreadTestInfo*)aInfo)->iDrawableId); sl@0: break; sl@0: case ESgresSecondThreadClosePassedImage: sl@0: ((TSgThreadTestInfo*)aInfo)->iSgImage->Close(); sl@0: break; sl@0: }; sl@0: sl@0: CleanupStack::PopAndDestroy(&driver); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Checks the function for the passed error codes and logs an error if the codes do not match. sl@0: If run under OOM testing, this function will leave if KErrNoMemory or KErrNoGraphicsMemory was sl@0: the actual error; this is essential for OOM testing. sl@0: sl@0: @leave One of the System Wide Error Codes sl@0: sl@0: @param aExpectedErrorCode The expected error code to check against sl@0: @param aActualErrorCode The actual error code sl@0: @param aFile The filename to use when reporting the error sl@0: @param aLine The line number to use when reporting the error sl@0: */ sl@0: void CTSgTestStepBase::CheckErrorL(TInt aExpectedErrorCode, TInt aActualErrorCode, const TText8* aFile, TInt aLine) sl@0: { sl@0: if (iEnableConformanceTests) sl@0: { sl@0: TESTWITHFILENAMEANDLINENUMBERL(aExpectedErrorCode == aActualErrorCode, aFile, aLine); sl@0: } sl@0: else sl@0: { sl@0: //OOM Tests Enabled - Also test for KErrNoMemory/KErrNoGraphicsMemory sl@0: TESTWITHFILENAMEANDLINENUMBERL((aExpectedErrorCode == aActualErrorCode) || (KErrNoMemory == aActualErrorCode) || (KErrNoGraphicsMemory == aActualErrorCode), aFile, aLine); sl@0: if (aActualErrorCode == KErrNoMemory || aActualErrorCode == KErrNoGraphicsMemory) sl@0: { sl@0: User::Leave(aActualErrorCode); sl@0: } sl@0: } sl@0: } sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadOpenImage sl@0: sl@0: @return One of the system wide error codes or an enumeration of passed tests. sl@0: sl@0: @param TSgresTestInfo* The test parameters sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::OpenImage(TSgThreadTestInfo* aInfo, RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt result = 0; sl@0: TInt err = image.Open(aInfo->iDrawableId); sl@0: if(KErrNoMemory == err) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: if(KErrNone == err) sl@0: { sl@0: result |= EFirstTestPassed; sl@0: } sl@0: TSgImageInfo info; sl@0: if(KErrNone == image.GetInfo(info)) sl@0: { sl@0: result |= ESecondTestPassed; sl@0: } sl@0: if(CTSgTestStepBase::CompareInfos(aInfo->iImageInfo, info)) sl@0: { sl@0: result |= EThirdTestPassed; sl@0: } sl@0: TSgDrawableId id = image.Id(); sl@0: if(id != KSgNullDrawableId) sl@0: { sl@0: result |= EFourthTestPassed; sl@0: } sl@0: if(id == aInfo->iDrawableId) sl@0: { sl@0: result |= EFifthTestPassed; sl@0: } sl@0: TInt attribVal = KMaxTInt; sl@0: TUid uid = { 0x12345678 }; sl@0: if (KErrNotSupported == image.GetAttribute(uid, attribVal)) sl@0: { sl@0: result |= ESixthTestPassed; sl@0: } sl@0: if (KErrArgument == image.GetAttribute(KNullUid, attribVal)) sl@0: { sl@0: result |= ESeventhTestPassed; sl@0: } sl@0: image.Close(); sl@0: aSgDriver.Close(); sl@0: if (KErrBadHandle == image.GetAttribute(uid, attribVal)) sl@0: { sl@0: result |= EEighthTestPassed; sl@0: } sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadOpenDrawable sl@0: sl@0: @return One of the system wide error codes or an enumeration of passed tests. sl@0: sl@0: @param TSgresTestInfo* The test parameters sl@0: */ sl@0: TInt SgTestSecondThread::OpenDrawable(TSgThreadTestInfo* aInfo) sl@0: { sl@0: TInt result = 0; sl@0: RSgDrawable drawable; sl@0: TInt err = drawable.Open(aInfo->iDrawableId); sl@0: if(KErrNoMemory == err) sl@0: { sl@0: result = KErrNoMemory; sl@0: return result; sl@0: } sl@0: if(KErrNone == err) sl@0: { sl@0: result |= EFirstTestPassed; sl@0: } sl@0: TSgDrawableId id = drawable.Id(); sl@0: if(id != KSgNullDrawableId) sl@0: { sl@0: result |= ESecondTestPassed; sl@0: } sl@0: if(id == aInfo->iDrawableId) sl@0: { sl@0: result |= EThirdTestPassed; sl@0: } sl@0: drawable.Close(); sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadOpenImageInvalid sl@0: sl@0: @return One of the system wide error codes or an enumeration of passed tests. sl@0: sl@0: @param TSgresTestInfo* The test parameters sl@0: */ sl@0: TInt SgTestSecondThread::OpenImageInvalid(TSgThreadTestInfo* aInfo) sl@0: { sl@0: TInt result = 0; sl@0: RSgImage image; sl@0: TSgImageInfo info; sl@0: info.iSizeInPixels = TSize(8, 8); sl@0: info.iPixelFormat = EUidPixelFormatRGB_565; sl@0: info.iUsage = ESgUsageBitOpenVgImage; sl@0: sl@0: TInt err = image.Create(info, KCrossImageData, KCrossImageDataStride); sl@0: if(KErrNoMemory == err) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: if(KErrNone == err) sl@0: { sl@0: result |= EFirstTestPassed; sl@0: } sl@0: sl@0: // non-empty handle sl@0: TSgDrawableId id = aInfo->iDrawableId; sl@0: err = image.Open(id); sl@0: if(KErrNoMemory == err) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: if(KErrInUse == err) sl@0: { sl@0: result |= ESecondTestPassed; sl@0: } sl@0: image.Close(); sl@0: sl@0: // null drawable id sl@0: err = image.Open(KSgNullDrawableId); sl@0: if(KErrNoMemory == err) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: if(KErrArgument == err) sl@0: { sl@0: result |= EThirdTestPassed; sl@0: } sl@0: image.Close(); sl@0: sl@0: // non-existing drawable id sl@0: err = image.Open(KFakeSgDrawableId); sl@0: if(KErrNoMemory == err) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: if(KErrNotFound == err) sl@0: { sl@0: result |= EFourthTestPassed; sl@0: } sl@0: image.Close(); sl@0: sl@0: err = image.Open(id); sl@0: if(KErrNoMemory == err) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: if(KErrNone == err) sl@0: { sl@0: result |= EFifthTestPassed; sl@0: } sl@0: image.Close(); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadOpenDrawableInvalid sl@0: sl@0: @return One of the system wide error codes or an enumeration of passed tests. sl@0: sl@0: @param TSgresTestInfo* The test parameters sl@0: */ sl@0: TInt SgTestSecondThread::OpenDrawableInvalid(TSgThreadTestInfo* aInfo) sl@0: { sl@0: TInt result = 0; sl@0: RSgDrawable drawable; sl@0: TInt err = drawable.Open(KSgNullDrawableId); sl@0: if(KErrNoMemory == err) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: if(KErrArgument == err) sl@0: { sl@0: result |= EFirstTestPassed; sl@0: } sl@0: drawable.Close(); sl@0: sl@0: // non-existing drawable id sl@0: err = drawable.Open(KFakeSgDrawableId); sl@0: if (KErrNoMemory == err) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: if(KErrNotFound == err) sl@0: { sl@0: result |= ESecondTestPassed; sl@0: } sl@0: drawable.Close(); sl@0: sl@0: // open a non-sharable image - should succeed sl@0: err = drawable.Open(aInfo->iDrawableId); sl@0: sl@0: if(KErrNoMemory == err) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: if(KErrNone == err) sl@0: { sl@0: result |= EThirdTestPassed; sl@0: sl@0: if (KErrInUse == drawable.Open(aInfo->iDrawableId)) sl@0: { sl@0: result |= EFourthTestPassed; sl@0: } sl@0: } sl@0: sl@0: drawable.Close(); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageGetInterfaceInvalidHandle sl@0: sl@0: @panic SGRES2 If the test is successful sl@0: sl@0: @return One of the system wide error codes. sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageGetInterfaceInvalidHandle(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); sl@0: sl@0: MTSgImage_Interface* swInterface = NULL; sl@0: result = image.GetInterface(swInterface); //should panic with SGRES 3 sl@0: aSgDriver.Close(); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageGetInterfaceNoDriver sl@0: sl@0: @panic SGRES1 If the test is successful sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageGetInterfaceNoDriver(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); sl@0: sl@0: aSgDriver.Close(); sl@0: MTSgImage_Interface* swInterface = NULL; sl@0: image.GetInterface(swInterface); // should panic with SGRES 1 sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageCloseInvalidHandle sl@0: sl@0: @panic SGRES2 If the test is successful sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageCloseInvalidHandle(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); sl@0: sl@0: image.Close(); //should panic with SGRES 3 sl@0: aSgDriver.Close(); sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageCloseNoDriver sl@0: sl@0: @panic SGRES1 If the test is successful sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageCloseNoDriver(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); sl@0: aSgDriver.Close(); sl@0: image.Close(); // should panic with SGRES 1 sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageIdIvalidHandle sl@0: sl@0: @panic SGRES2 If the test is successful sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageIdInvalidHandle(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); sl@0: sl@0: image.Id(); //should panic with SGRES 3 sl@0: aSgDriver.Close(); sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageIdNoDriver sl@0: sl@0: @panic SGRES1 If the test is successful sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageIdNoDriver(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); sl@0: sl@0: aSgDriver.Close(); sl@0: image.Id(); // should panic with SGRES 1 sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageDrawableTypeInvalidHandle sl@0: sl@0: @panic SGRES2 If the test is successful sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageDrawableTypeInvalidHandle(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); sl@0: sl@0: image.DrawableType(); //should panic with SGRES 3 sl@0: aSgDriver.Close(); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageDrawableTypeNoDriver sl@0: sl@0: @panic SGRES1 If the test is successful sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageDrawableTypeNoDriver(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); sl@0: aSgDriver.Close(); sl@0: image.DrawableType(); // should panic with SGRES 1 sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageCreateInvalidHandle sl@0: sl@0: @panic SGRES3 If the test is successful sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageCreateInvalidHandle(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); sl@0: sl@0: RSgImage newImage; sl@0: TSgImageInfo info; sl@0: image.GetInfo(info); sl@0: newImage.Create(info, image); //should panic with SGRES 3 sl@0: aSgDriver.Close(); sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageGetInfoInvalidHandle sl@0: sl@0: @panic SGRES3 If the test is successful sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageGetInfoInvalidHandle(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); sl@0: sl@0: TSgImageInfo anotherInfo; sl@0: image.GetInfo(anotherInfo); //should panic with SGRES 3 sl@0: aSgDriver.Close(); sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageNoDriver sl@0: sl@0: @panic SGRES1 If the test is successful sl@0: sl@0: @return One of the system wide error codes or an enumeration of passed tests. sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageGetInfoNoDriver(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image); sl@0: if(KErrNone != ret) sl@0: { sl@0: return ret; sl@0: } sl@0: RSgImage anotherImage; sl@0: Mem::Copy(&anotherImage, &image, sizeof(image)); sl@0: image.Close(); sl@0: aSgDriver.Close(); sl@0: TSgImageInfo anotherInfo; sl@0: anotherImage.GetInfo(anotherInfo); // should panic with SGRES 1 sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageGetAttributeInvalidHandle sl@0: sl@0: @panic SGRES3 If the test is successful sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageGetAttributeInvalidHandle(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); sl@0: sl@0: TInt attrib = KMaxTInt; sl@0: image.GetAttribute(TUid::Uid(1), attrib); //Should panic with SGRES 3 sl@0: sl@0: aSgDriver.Close(); sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicImageGetAttributeNoDriver sl@0: sl@0: @panic SGRES1 If the test is successful sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param RSgDriver An open RSgDriver for the test code to use sl@0: */ sl@0: TInt SgTestSecondThread::PanicImageGetAttributeNoDriver(RSgDriver& aSgDriver) sl@0: { sl@0: RSgImage image; sl@0: TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image); sl@0: if(KErrNone != ret) sl@0: { sl@0: return ret; sl@0: } sl@0: RSgImage anotherImage; sl@0: Mem::Copy(&anotherImage, &image, sizeof(image)); sl@0: image.Close(); sl@0: aSgDriver.Close(); sl@0: TInt attrib = KMaxTInt; sl@0: TUid uid = { 0x12345678 }; sl@0: anotherImage.GetAttribute(uid, attrib); //Should panic with SGRES 1 sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadMultipleThreadStressTest sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param TSgresTestInfo* The test parameters sl@0: */ sl@0: TInt SgTestSecondThread::MultipleThreadStressTest(TSgThreadTestInfo* aInfo) sl@0: { sl@0: TInt result = 0; sl@0: RSgImage image; sl@0: for (TInt i = 0; i < 1000 && result == KErrNone; ++i) sl@0: { sl@0: TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image); sl@0: if (KErrNone != ret) sl@0: { sl@0: result = ret; sl@0: break; sl@0: } sl@0: sl@0: const TInt KMaxOpenCount = 100; sl@0: RSgImage images[KMaxOpenCount]; sl@0: TInt count = Math::Random() % KMaxOpenCount; sl@0: for (TInt k = 0; k < count; ++k) sl@0: { sl@0: ret = images[k].Open(aInfo->iDrawableId); sl@0: if (KErrNone != ret) sl@0: { sl@0: result = ret; sl@0: break; sl@0: } sl@0: } sl@0: image.Close(); sl@0: for (TInt k = 0; k < count; ++k) sl@0: { sl@0: images[k].Close(); sl@0: } sl@0: } sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicAttributeArrayInvalidIndex sl@0: sl@0: @panic SGRES4 If the test is successful sl@0: sl@0: @param TSgresTestInfo* The test parameters sl@0: */ sl@0: void SgTestSecondThread::PanicAttributeArrayInvalidIndexL() sl@0: { sl@0: TSgAttributeArray<5> attribArray; sl@0: TSgAttribute attrib = attribArray[6]; //Should panic with SGRES 4 sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicAttributeArrayInvalidIndex2 sl@0: sl@0: @panic SGRES4 If the test is successful sl@0: sl@0: @param TSgresTestInfo* The test parameters sl@0: */ sl@0: void SgTestSecondThread::PanicAttributeArrayInvalidIndex2L() sl@0: { sl@0: TSgAttributeArray<5> attribArray; sl@0: TSgAttribute attrib = attribArray[-1]; //Should panic with SGRES 4 sl@0: } sl@0: sl@0: /** sl@0: Implementation of SecondThread test ESgresSecondThreadPanicDriverCloseOpenResources sl@0: sl@0: @return One of the system wide error codes sl@0: sl@0: @param RSgImage* A closed or uninitialised RSgImage to use for image creation sl@0: */ sl@0: TInt SgTestSecondThread::CreatePassedImageL(RSgImage* aSgImage) sl@0: { sl@0: TSgImageInfo info; sl@0: info.iSizeInPixels = TSize(8, 8); sl@0: info.iUsage = ESgUsageBitOpenVgImage; sl@0: info.iPixelFormat = EUidPixelFormatRGB_565; sl@0: sl@0: return aSgImage->Create(info, KCrossImageData, KCrossImageDataStride); sl@0: } sl@0: sl@0: /** sl@0: Helper function which Creates an RSgImage and copies to into another RSgImage sl@0: using Mem::Copy; the target of the copy is returned in the open state. sl@0: sl@0: @param aSgImage An uninitialised image which will have an SgImage Mem::Copied into it. sl@0: @return One of the system wide error codes. sl@0: */ sl@0: TInt CTSgTestStepBase::CreateImageAndReturnCopy(RSgImage& aSgImage) sl@0: { sl@0: RSgImage image; sl@0: TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image); sl@0: if(KErrNone != ret) sl@0: { sl@0: return ret; sl@0: } sl@0: Mem::Copy(&aSgImage, &image, sizeof(image)); sl@0: image.Close(); sl@0: sl@0: return ret; sl@0: }