os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tgraphicsresourceteststepbase.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tgraphicsresourceteststepbase.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1203 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 + @internalComponent - Graphics Resource API Conformance Test Suite
    1.23 +*/
    1.24 +
    1.25 +#include "tgraphicsresourceteststepbase.h"
    1.26 +#include <e32math.h>
    1.27 +
    1.28 +CTSgTestStepBase::CTSgTestStepBase(TBool aConformanceTests) :
    1.29 +	iEnableConformanceTests(aConformanceTests)
    1.30 +	{
    1.31 +	}
    1.32 +
    1.33 +CTSgTestStepBase::~CTSgTestStepBase()
    1.34 +	{
    1.35 +	iSecondThread.Close();
    1.36 +	iPixelFormatArray.Close();
    1.37 +	User::Free(iDiagonalImageData);
    1.38 +	iSgDriver.Close();
    1.39 +	}
    1.40 +
    1.41 +/**
    1.42 +Overrides of base class virtual
    1.43 +@leave Gets system wide error code
    1.44 +@return - TVerdict code
    1.45 +*/
    1.46 +TVerdict CTSgTestStepBase::doTestStepPreambleL()
    1.47 +	{
    1.48 +	// Set the logger to shared so that secondary threads can write to the log
    1.49 +	User::LeaveIfError(Logger().ShareAuto());	
    1.50 +	SetTestStepResult(EPass);
    1.51 +	iDiagonalImageData = static_cast<TUint32*>(User::AllocL(KDiagonalImageSize * KDiagonalImageDataStride));
    1.52 +	// Populate iDiagonalImageData with green diagonal from top-left to bottom-right on white background
    1.53 +	Mem::Fill(iDiagonalImageData, KDiagonalImageSize * KDiagonalImageDataStride, 0xFF);
    1.54 +	for (TInt i = 0; i < KDiagonalImageSize; ++i)
    1.55 +		{
    1.56 +		iDiagonalImageData[i * (KDiagonalImageSize + 1)] = 0xFF00FF00;
    1.57 +		}
    1.58 +	return TestStepResult();
    1.59 +	}
    1.60 +
    1.61 +/**
    1.62 +Override of base class virtual
    1.63 +@leave Gets system wide error code
    1.64 +@return - TVerdict code
    1.65 +*/
    1.66 +TVerdict CTSgTestStepBase::doTestStepPostambleL()
    1.67 +	{
    1.68 +	User::Free(iDiagonalImageData);
    1.69 +	iDiagonalImageData = NULL;
    1.70 +	return TestStepResult();
    1.71 +	}
    1.72 +
    1.73 +/**
    1.74 +Creates an image with some predefined parameters.
    1.75 +@param aImage output image handle
    1.76 +@leave Gets system wide error code
    1.77 +*/
    1.78 +void CTSgTestStepBase::CreateImageL(RSgImage& aImage)
    1.79 +	{
    1.80 +	TSgImageInfo info;
    1.81 +	info.iSizeInPixels = TSize(8, 8);
    1.82 +	info.iUsage = ESgUsageBitOpenVgImage;
    1.83 +	info.iPixelFormat = EUidPixelFormatRGB_565;
    1.84 +	
    1.85 +	CheckErrorL(KErrNone, aImage.Create(info, KCrossImageData, KCrossImageDataStride), (TText8*)__FILE__, __LINE__);
    1.86 +	}
    1.87 +
    1.88 +/**
    1.89 +Creates a second process and do some tests in it.
    1.90 +@param aProcessName The name of the new process
    1.91 +@param aTestInfo The information for the tests
    1.92 +@return A bitwise mask of test passes (never an error code)
    1.93 +@leave Gets system wide error code
    1.94 +*/
    1.95 +TInt CTSgTestStepBase::CreateSecondProcessAndDoTestL(const TDesC &aProcessName, TSgProcessTestInfo& aTestInfo)
    1.96 +	{
    1.97 +	// Create a second process
    1.98 +	RProcess process;
    1.99 +	TInt err = process.Create(aProcessName, KNullDesC);
   1.100 +	User::LeaveIfError(err);
   1.101 +	CleanupClosePushL(process);
   1.102 +
   1.103 +	// Specify the id passed to the second process
   1.104 +	TPckg<TSgProcessTestInfo> ptr(aTestInfo);
   1.105 +	TESTL(KErrNone == process.SetParameter(KSecondProcessParametersSlot, ptr));
   1.106 +	
   1.107 +	// Kick off the second process and wait for it to complete
   1.108 +	// The actual testing is done in the second process
   1.109 +	TRequestStatus status = KRequestPending;
   1.110 +	process.Logon(status);
   1.111 +	process.Resume();
   1.112 +	User::WaitForRequest(status);
   1.113 +
   1.114 +	// exitreason could either be a negative error code or a bitwise
   1.115 +	// mask of test passes.
   1.116 +	TInt exitreason = process.ExitReason();
   1.117 +	
   1.118 +	CleanupStack::PopAndDestroy();
   1.119 +	
   1.120 +	if (exitreason < KErrNone)
   1.121 +		{
   1.122 +		INFO_PRINTF2(_L("The second process returned error code %d"), exitreason);
   1.123 +		TEST(EFalse);
   1.124 +		exitreason = 0;
   1.125 +		}
   1.126 +	//return test result
   1.127 +	return exitreason;
   1.128 +	}
   1.129 +
   1.130 +/**
   1.131 +Creates a second process, runs the requested test and ensures that
   1.132 +the specified panic occurs.
   1.133 +
   1.134 +@param aTestInfo The specification for this test
   1.135 +@param aPanicCode The expected panic code
   1.136 +@param aExitCategory The expected panic category
   1.137 +@param aProcessName The name of the new process
   1.138 +
   1.139 +@leave One of the system wide error codes
   1.140 +*/
   1.141 +void CTSgTestStepBase::CreateSecondProcessAndCheckPanicL(TSgProcessTestInfo& aTestInfo, TInt aPanicCode, TExitCategoryName aExitCategory, const TDesC &aProcessName)
   1.142 +	{
   1.143 +	// Create a second process
   1.144 +	RProcess process;
   1.145 +	User::LeaveIfError(process.Create(aProcessName, KNullDesC));
   1.146 +	CleanupClosePushL(process);
   1.147 +
   1.148 +	// Specify the id passed to the second process
   1.149 +	TPckg<TSgProcessTestInfo> ptr(aTestInfo);
   1.150 +	TESTL(KErrNone == process.SetParameter(KSecondProcessParametersSlot, ptr));
   1.151 +	
   1.152 +	// Kick off the second process and wait for it to complete
   1.153 +	// The actual testing is done in the second process
   1.154 +	TRequestStatus status = KRequestPending;
   1.155 +	process.Logon(status);
   1.156 +	process.Resume();
   1.157 +	User::WaitForRequest(status);
   1.158 +	
   1.159 +	if(EExitPanic != process.ExitType())
   1.160 +		{
   1.161 +		ERR_PRINTF3(_L("Expected exit type: %d, Actual exit type: %d"), EExitPanic, process.ExitType());
   1.162 +		TEST(EFalse);
   1.163 +		}
   1.164 +	
   1.165 +	if(aPanicCode != process.ExitReason())
   1.166 +		{
   1.167 +		ERR_PRINTF3(_L("Expected panic code: %d, Actual panic code: %d"), aPanicCode, process.ExitReason());
   1.168 +		TEST(EFalse);
   1.169 +		}
   1.170 +	
   1.171 +	TExitCategoryName secondProcessExitCategory = process.ExitCategory();
   1.172 +	if(aExitCategory != secondProcessExitCategory)
   1.173 +		{
   1.174 +		ERR_PRINTF3(_L("Expected panic category: %S, Actual panic category: %S"), &aExitCategory, &secondProcessExitCategory);
   1.175 +		TEST(EFalse);
   1.176 +		}
   1.177 +	
   1.178 +	CleanupStack::PopAndDestroy();
   1.179 +	}
   1.180 +
   1.181 +/**
   1.182 +Creates a second thread and do some tests in it.
   1.183 +@param aTestInfo The information for the tests
   1.184 +@leave Gets system wide error code
   1.185 +*/
   1.186 +TInt CTSgTestStepBase::CreateSecondThreadAndDoTestL(TSgThreadTestInfo aTestInfo)
   1.187 +	{
   1.188 +	//create a semaphore
   1.189 +	RSemaphore sem;
   1.190 +	User::LeaveIfError(sem.CreateGlobal(KSecondThreadSemaphore, 0, EOwnerThread));
   1.191 +	CleanupClosePushL(sem);
   1.192 +	
   1.193 +	aTestInfo.iTestStep = this;
   1.194 +	
   1.195 +	User::LeaveIfError(iSecondThread.Create(KSecondThread, SgTestSecondThread::ThreadStart, KDefaultStackSize, KSecondThreadMinHeapSize, KSecondThreadMaxHeapSize, &aTestInfo));
   1.196 +	// Launch second thread
   1.197 +	TRequestStatus statusSecondThread;
   1.198 +	iSecondThread.Logon(statusSecondThread);
   1.199 +	iSecondThread.SetPriority(EPriorityLess);
   1.200 +	iSecondThread.Resume();	
   1.201 +	
   1.202 +	User::WaitForRequest(statusSecondThread);
   1.203 +	
   1.204 +	TExitCategoryName exitCategory = iSecondThread.ExitCategory();
   1.205 +	if (exitCategory.Compare(_L("Kill")) != 0)
   1.206 +		{
   1.207 +		ERR_PRINTF2(_L("Second thread terminated with reason category '%S'"), &exitCategory);
   1.208 +		SetTestStepResult(EFail);
   1.209 +		}
   1.210 +	TInt result = iSecondThread.ExitReason();
   1.211 +	
   1.212 +	//Close the handle
   1.213 +	CleanupStack::PopAndDestroy(1, &sem);
   1.214 +	iSecondThread.Close();
   1.215 +		
   1.216 +	return result;
   1.217 +	}
   1.218 +
   1.219 +/**
   1.220 +Creates a second thread and do some panic tests in it.
   1.221 +@param aTestInfo The information for the tests
   1.222 +@param aPanicCode The expected panic code
   1.223 +@param aExitCategory The expected panic category
   1.224 +@param aThreadName The name of the new thread
   1.225 +@leave Gets system wide error code
   1.226 +*/
   1.227 +void CTSgTestStepBase::CreateSecondThreadAndCheckPanicL(TSgThreadTestInfo aTestInfo, TInt aPanicCode, TExitCategoryName aExitCategory, const TDesC &aThreadName)
   1.228 +	{
   1.229 +	aTestInfo.iTestStep = this;
   1.230 +	User::LeaveIfError(iSecondThread.Create(aThreadName, SgTestSecondThread::ThreadStart, KDefaultStackSize, KSecondThreadMinHeapSize, KSecondThreadMaxHeapSize, &aTestInfo));
   1.231 +	
   1.232 +	// Launch second thread
   1.233 +	TRequestStatus statusSecondThread;
   1.234 +	iSecondThread.Logon(statusSecondThread);
   1.235 +	iSecondThread.SetPriority(EPriorityLess);
   1.236 +	iSecondThread.Resume();	
   1.237 +	
   1.238 +	User::WaitForRequest(statusSecondThread);
   1.239 +	
   1.240 +	if(EExitPanic != iSecondThread.ExitType())
   1.241 +		{
   1.242 +		ERR_PRINTF3(_L("Expected exit type: %d, Actual exit type: %d"), EExitPanic, iSecondThread.ExitType());
   1.243 +		TEST(EFalse);
   1.244 +		}
   1.245 +	
   1.246 +	if(aPanicCode != iSecondThread.ExitReason())
   1.247 +		{
   1.248 +		ERR_PRINTF3(_L("Expected panic code: %d, Actual panic code: %d"), aPanicCode, iSecondThread.ExitReason());
   1.249 +		TEST(EFalse);
   1.250 +		}
   1.251 +	
   1.252 +	TExitCategoryName secondThreadExitCategory = iSecondThread.ExitCategory();
   1.253 +	if(aExitCategory != secondThreadExitCategory)
   1.254 +		{
   1.255 +		ERR_PRINTF3(_L("Expected panic category: %S, Actual panic category: %S"), &aExitCategory, &secondThreadExitCategory);
   1.256 +		TEST(EFalse);
   1.257 +		}
   1.258 +	
   1.259 +	//Close the handle
   1.260 +	iSecondThread.Close();
   1.261 +	}
   1.262 +
   1.263 +/**
   1.264 +Gets the supporting pixel formats according to the specified usage bit.
   1.265 +@leave Gets system wide error code
   1.266 +*/
   1.267 +void CTSgTestStepBase::CallGetPixelFormatsL(TUint32 aUsage)
   1.268 +	{
   1.269 +	iPixelFormatArray.Reset();
   1.270 +	CheckErrorL(KErrNone, RSgImage::GetPixelFormats(aUsage, iPixelFormatArray), (TText8*)__FILE__, __LINE__);
   1.271 +	}
   1.272 +
   1.273 +/**
   1.274 +Checks the pixel formats returned against the compatibility guarantee table.
   1.275 +@leave Gets system wide error code
   1.276 +*/
   1.277 +void CTSgTestStepBase::TestGetPixelFormatCompatibilityGuaranteesL()
   1.278 +	{
   1.279 +	_LIT(KLibOpenGLES2, "libGLESv2.dll");
   1.280 +	
   1.281 +	RLibrary lib;
   1.282 +	TBool supportGLES2 = (lib.Load(KLibOpenGLES2) == KErrNone);
   1.283 +	lib.Close();
   1.284 +
   1.285 +	// OpenVG - Mandatory support
   1.286 +	CallGetPixelFormatsL(ESgUsageBitOpenVgImage);
   1.287 +	TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888_PRE));
   1.288 +	TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888));
   1.289 +	TEST(CheckPixelFormatPresent(ESgPixelFormatXRGB_8888));
   1.290 +	TEST(CheckPixelFormatPresent(ESgPixelFormatRGB_565));
   1.291 +	TEST(CheckPixelFormatPresent(ESgPixelFormatA_8));
   1.292 +	CallGetPixelFormatsL(ESgUsageBitOpenVgSurface);
   1.293 +	TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888_PRE));
   1.294 +	TEST(CheckPixelFormatPresent(ESgPixelFormatXRGB_8888));
   1.295 +	TEST(CheckPixelFormatPresent(ESgPixelFormatRGB_565));
   1.296 +	
   1.297 +	// OpenGL ES - Not mandatory, but should cause no errors. 
   1.298 +	CallGetPixelFormatsL(ESgUsageBitOpenGlesTexture2D);
   1.299 +	CallGetPixelFormatsL(ESgUsageBitOpenGlesSurface);
   1.300 +
   1.301 +	// OpenGL ES 2 - Mandatory if present.
   1.302 +	CallGetPixelFormatsL(ESgUsageBitOpenGles2Texture2D);
   1.303 +	if (supportGLES2)
   1.304 +	    {
   1.305 +        TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888_PRE));
   1.306 +        TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888));
   1.307 +        TEST(CheckPixelFormatPresent(ESgPixelFormatXRGB_8888));
   1.308 +        TEST(CheckPixelFormatPresent(ESgPixelFormatRGB_565));
   1.309 +        TEST(CheckPixelFormatPresent(ESgPixelFormatA_8));
   1.310 +	    }
   1.311 +	CallGetPixelFormatsL(ESgUsageBitOpenGles2Surface);
   1.312 +	if (supportGLES2)
   1.313 +	    {
   1.314 +	    TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888_PRE));
   1.315 +	    TEST(CheckPixelFormatPresent(ESgPixelFormatXRGB_8888));
   1.316 +	    TEST(CheckPixelFormatPresent(ESgPixelFormatRGB_565));
   1.317 +	    }
   1.318 +
   1.319 +	iPixelFormatArray.Reset();
   1.320 +	}
   1.321 +
   1.322 +/**
   1.323 +Helper function to check if a certain pixel format is present
   1.324 +in the pixel formats array retrieved by CallGetPixelFormatsL().
   1.325 +
   1.326 +@param aPixelFormat The pixelformat to check
   1.327 +@return ETrue if the pixel format is present, otherwise EFalse
   1.328 +@see CTsgTestStepBase::CallGetPixelFormats()
   1.329 +*/
   1.330 +TBool CTSgTestStepBase::CheckPixelFormatPresent(TSgPixelFormat aPixelFormat)
   1.331 +	{
   1.332 +	for(TInt i=0; i<iPixelFormatArray.Count(); ++i)
   1.333 +		{		
   1.334 +		if(aPixelFormat == iPixelFormatArray[i])
   1.335 +			{
   1.336 +			return ETrue;
   1.337 +			}
   1.338 +		}
   1.339 +	return EFalse;
   1.340 +	}
   1.341 +
   1.342 +/**
   1.343 +Helper function to test the equivalence of two TSgImageInfo structures.
   1.344 +
   1.345 +@param   aInfo1 A TSgImageInfo structure to compare.
   1.346 +@param   aInfo2 A TSgImageInfo structure to compare (may have extra usage bits).
   1.347 +
   1.348 +@return  ETrue if the two are equivalent, EFalse otherwise.
   1.349 +*/
   1.350 +TBool CTSgTestStepBase::CompareInfos(TSgImageInfo& aInfo1, TSgImageInfo& aInfo2)
   1.351 +	{
   1.352 +	return (aInfo1.iPixelFormat == aInfo2.iPixelFormat
   1.353 +		&& aInfo1.iSizeInPixels == aInfo2.iSizeInPixels
   1.354 +		// check that all requested usage bits are set in the returned usage bits
   1.355 +		&& !(aInfo1.iUsage & ~aInfo2.iUsage));
   1.356 +	}
   1.357 +
   1.358 +/**
   1.359 +Wrapper function to open the graphics resource driver.
   1.360 +Only opens the driver if the test step has been constructed for use
   1.361 +as the conformance tests.
   1.362 +
   1.363 +@leave One of the system wide error codes
   1.364 +*/
   1.365 +void CTSgTestStepBase::TestOpenDriverL()
   1.366 +	{
   1.367 +	if (iEnableConformanceTests)
   1.368 +		CheckErrorL(KErrNone, iSgDriver.Open(), (TText8*)__FILE__, __LINE__);
   1.369 +	}
   1.370 +
   1.371 +/**
   1.372 +Wrapper function to close the graphics resource driver.
   1.373 +
   1.374 +Only closes the driver if the test step has been constructed for use
   1.375 +as the conformance tests.
   1.376 +*/
   1.377 +void CTSgTestStepBase::TestCloseDriver()
   1.378 +	{
   1.379 +	if (iEnableConformanceTests)
   1.380 +		iSgDriver.Close();
   1.381 +	}
   1.382 +
   1.383 +/**
   1.384 +Creates an image with specified parameters.
   1.385 +@param aImage output image handle
   1.386 +@return KErrNone if the image was created successfully, otherwise one of the system-wide error codes
   1.387 +*/
   1.388 +TInt CreateImageWithParameters(TInt aWidth, TInt aHeight, TUidPixelFormat aPixelFormat, TUint32 aUsage, RSgImage& aImage)
   1.389 +	{
   1.390 +	TSgImageInfo info;
   1.391 +	info.iSizeInPixels = TSize(aWidth, aHeight);
   1.392 +	info.iPixelFormat = aPixelFormat;
   1.393 +	info.iUsage = aUsage;
   1.394 +	return aImage.Create(info, NULL, 0);
   1.395 +	}
   1.396 +
   1.397 +/**
   1.398 +Second thread entry function.
   1.399 +*/
   1.400 +TInt SgTestSecondThread::ThreadStart(TAny* aInfo)
   1.401 +	{
   1.402 +	__UHEAP_MARK;
   1.403 +	
   1.404 +	CTrapCleanup* cleanupStack = CTrapCleanup::New();
   1.405 +	if (!cleanupStack)
   1.406 +		{
   1.407 +		return KErrNoMemory;
   1.408 +		}
   1.409 +	
   1.410 +	TSgThreadTestInfo* testInfo = static_cast<TSgThreadTestInfo*>(aInfo);
   1.411 +
   1.412 +	RSemaphore sem;
   1.413 +	TInt openSem = sem.OpenGlobal(KSecondThreadSemaphore, EOwnerThread);
   1.414 +
   1.415 +	TInt result = KErrNone;
   1.416 +	TRAPD(leaveCode, result = SgTestSecondThread::ThreadMainL(testInfo));
   1.417 +	if (KErrNone == openSem)
   1.418 +		{
   1.419 +		sem.Signal();
   1.420 +		}
   1.421 +	sem.Close();
   1.422 +	
   1.423 +	if (leaveCode != KErrNone)
   1.424 +		{
   1.425 +		testInfo->iTestStep->ERR_PRINTF2(_L("Second thread caused Leave (%d)"), leaveCode);
   1.426 +		testInfo->iTestStep->SetTestStepResult(EFail);
   1.427 +		result = leaveCode;
   1.428 +		}
   1.429 +	
   1.430 +	delete cleanupStack;
   1.431 +
   1.432 +	__UHEAP_MARKEND;
   1.433 +	
   1.434 +	return result;
   1.435 +	}
   1.436 +
   1.437 +/**
   1.438 +Run the test contained within the TSgresTestInfo object. A new thread is
   1.439 +created for each test and only one of the cases in the switch statements
   1.440 +below will be used.
   1.441 +
   1.442 +The first switch statement contains tests that must have no driver open,
   1.443 +the second set require an open driver to initiate the test but may
   1.444 +close it part way through.
   1.445 +
   1.446 +@param aInfo The parameters for the test
   1.447 +@return One of the system wide error codes or an enumeration of passed tests.
   1.448 + */
   1.449 +TInt SgTestSecondThread::ThreadMainL(TSgThreadTestInfo* aInfo)
   1.450 +	{
   1.451 +	TInt result = 0;
   1.452 +
   1.453 +	TSgresTestCase testcase = ((TSgThreadTestInfo*)aInfo)->iTestCase;
   1.454 +
   1.455 +	RSgDriver driver;
   1.456 +	CleanupClosePushL(driver);
   1.457 +	TInt ret = driver.Open();
   1.458 +	if(KErrNoMemory == ret)
   1.459 +		{
   1.460 +		return KErrNoMemory;
   1.461 +		}
   1.462 +	//test cases without the need of an initialised driver
   1.463 +	switch (testcase)
   1.464 +	{
   1.465 +	case ESgresSecondThreadPanicDrawableOpenNoDriver:
   1.466 +		{
   1.467 +		driver.Close();
   1.468 +		RSgDrawable drawable;
   1.469 +		drawable.Open(KFakeSgDrawableId); // should panic with SGRES 1
   1.470 +		}
   1.471 +		break;
   1.472 +	case ESgresSecondThreadPanicImageOpenNoDriver:
   1.473 +		{
   1.474 +		driver.Close();
   1.475 +		RSgImage image;
   1.476 +		image.Open(KFakeSgDrawableId); // should panic with SGRES 1
   1.477 +		image.Close();
   1.478 +		}
   1.479 +	case ESgresSecondThreadPanicImageCreateNoDriver1:
   1.480 +		{
   1.481 +		driver.Close();
   1.482 +		RSgImage image;
   1.483 +		image.Create(KSgImageInfo1, NULL, 0); // should panic with SGRES 1
   1.484 +		image.Close();
   1.485 +		}
   1.486 +		break;
   1.487 +	case ESgresSecondThreadPanicImageCreateNoDriver2:
   1.488 +		{
   1.489 +		driver.Close();
   1.490 +		RSgImage image;
   1.491 +		RSgImage tempImage;
   1.492 +		image.Create(KSgImageInfo1, tempImage); // should panic with SGRES 1
   1.493 +		image.Close();
   1.494 +		}
   1.495 +		break;
   1.496 +	case ESgresSecondThreadOpenImage:
   1.497 +		result = OpenImage(((TSgThreadTestInfo*)aInfo), driver);
   1.498 +		break;
   1.499 +	case ESgresSecondThreadOpenDrawable:
   1.500 +		result = OpenDrawable(((TSgThreadTestInfo*)aInfo));
   1.501 +		break;
   1.502 +	case ESgresSecondThreadOpenImageInvalid:
   1.503 +		result = OpenImageInvalid(((TSgThreadTestInfo*)aInfo));
   1.504 +		break;
   1.505 +	case ESgresSecondThreadOpenDrawableInvalid: 
   1.506 +		result = OpenDrawableInvalid(((TSgThreadTestInfo*)aInfo));
   1.507 +		break;
   1.508 +	case ESgresSecondThreadPanicImageGetInterfaceInvalidHandle:
   1.509 +		result = PanicImageGetInterfaceInvalidHandle(driver);
   1.510 +		break;
   1.511 +	case ESgresSecondThreadPanicImageGetInterfaceNoDriver:
   1.512 +		result = PanicImageGetInterfaceNoDriver(driver);
   1.513 +		break;
   1.514 +	case ESgresSecondThreadPanicImageCloseInvalidHandle:
   1.515 +		result = PanicImageCloseInvalidHandle(driver);
   1.516 +		break;
   1.517 +	case ESgresSecondThreadPanicImageCloseNoDriver:
   1.518 +		result = PanicImageCloseNoDriver(driver);
   1.519 +		break;
   1.520 +	case ESgresSecondThreadPanicImageIdInvalidHandle:
   1.521 +		result = PanicImageIdInvalidHandle(driver);
   1.522 +		break;
   1.523 +	case ESgresSecondThreadPanicImageIdNoDriver:
   1.524 +		result = PanicImageIdNoDriver(driver);
   1.525 +		break;
   1.526 +	case ESgresSecondThreadPanicImageDrawableTypeInvalidHandle:
   1.527 +		result = PanicImageDrawableTypeInvalidHandle(driver);
   1.528 +		break;
   1.529 +	case ESgresSecondThreadPanicImageDrawableTypeNoDriver:
   1.530 +		result = PanicImageDrawableTypeNoDriver(driver);
   1.531 +		break;  
   1.532 +	case ESgresSecondThreadPanicImageCreateInvalidHandle:
   1.533 +		result = PanicImageCreateInvalidHandle(driver);
   1.534 +		break;
   1.535 +	case ESgresSecondThreadPanicImageGetInfoInvalidHandle:
   1.536 +		result = PanicImageGetInfoInvalidHandle(driver);
   1.537 +		break;
   1.538 +	case ESgresSecondThreadPanicImageGetInfoNoDriver:
   1.539 +		result = PanicImageGetInfoNoDriver(driver);
   1.540 +		break;
   1.541 +	case ESgresSecondThreadPanicImageGetAttributeInvalidHandle:
   1.542 +		result = PanicImageGetAttributeInvalidHandle(driver);
   1.543 +		break;
   1.544 +	case ESgresSecondThreadPanicImageGetAttributeNoDriver:
   1.545 +		result = PanicImageGetAttributeNoDriver(driver);
   1.546 +		break;
   1.547 +	case ESgresMultipleThreadStressTest:
   1.548 +		result = MultipleThreadStressTest(((TSgThreadTestInfo*)aInfo));
   1.549 +		break;
   1.550 +	case ESgresSecondThreadPanicAttributeArrayInvalidIndex:
   1.551 +		PanicAttributeArrayInvalidIndexL();
   1.552 +		break;
   1.553 +	case ESgresSecondThreadPanicAttributeArrayInvalidIndex2:
   1.554 +		PanicAttributeArrayInvalidIndex2L();
   1.555 +		break;
   1.556 +	case ESgresSecondThreadOpenPassedDriver:
   1.557 +		result = ((TSgThreadTestInfo*)aInfo)->iSgDriver->Open();
   1.558 +		break;
   1.559 +	case ESgresSecondThreadClosePassedDriver:
   1.560 +		((TSgThreadTestInfo*)aInfo)->iSgDriver->Close();
   1.561 +		break;
   1.562 +	case ESgresSecondThreadCreatePassedImage:
   1.563 +		result = CreatePassedImageL(((TSgThreadTestInfo*)aInfo)->iSgImage);
   1.564 +		break;
   1.565 +	case ESgresSecondThreadOpenPassedImage:
   1.566 +		((TSgThreadTestInfo*)aInfo)->iSgImage->Open(((TSgThreadTestInfo*)aInfo)->iDrawableId);
   1.567 +		break;
   1.568 +	case ESgresSecondThreadClosePassedImage:
   1.569 +		((TSgThreadTestInfo*)aInfo)->iSgImage->Close();
   1.570 +		break;
   1.571 +	};
   1.572 +
   1.573 +	CleanupStack::PopAndDestroy(&driver);
   1.574 +
   1.575 +	return result;
   1.576 +	}
   1.577 +
   1.578 +/**
   1.579 +Checks the function for the passed error codes and logs an error if the codes do not match. 
   1.580 +If run under OOM testing, this function will leave if KErrNoMemory or KErrNoGraphicsMemory was 
   1.581 +the actual error; this is essential for OOM testing.
   1.582 +
   1.583 +@leave One of the System Wide Error Codes
   1.584 +
   1.585 +@param aExpectedErrorCode The expected error code to check against
   1.586 +@param aActualErrorCode The actual error code
   1.587 +@param aFile The filename to use when reporting the error
   1.588 +@param aLine The line number to use when reporting the error
   1.589 +*/
   1.590 +void CTSgTestStepBase::CheckErrorL(TInt aExpectedErrorCode, TInt aActualErrorCode, const TText8* aFile, TInt aLine)
   1.591 +	{
   1.592 +	if (iEnableConformanceTests)
   1.593 +		{
   1.594 +		TESTWITHFILENAMEANDLINENUMBERL(aExpectedErrorCode == aActualErrorCode, aFile, aLine);
   1.595 +		}
   1.596 +	else
   1.597 +		{
   1.598 +		//OOM Tests Enabled - Also test for KErrNoMemory/KErrNoGraphicsMemory
   1.599 +		TESTWITHFILENAMEANDLINENUMBERL((aExpectedErrorCode == aActualErrorCode) || (KErrNoMemory == aActualErrorCode) || (KErrNoGraphicsMemory == aActualErrorCode), aFile, aLine);
   1.600 +		if (aActualErrorCode == KErrNoMemory || aActualErrorCode == KErrNoGraphicsMemory)
   1.601 +			{
   1.602 +			User::Leave(aActualErrorCode);
   1.603 +			}
   1.604 +		}
   1.605 +	}
   1.606 +/**
   1.607 +Implementation of SecondThread test ESgresSecondThreadOpenImage
   1.608 +
   1.609 +@return One of the system wide error codes or an enumeration of passed tests.
   1.610 +
   1.611 +@param TSgresTestInfo* The test parameters
   1.612 +@param RSgDriver An open RSgDriver for the test code to use
   1.613 + */
   1.614 +TInt SgTestSecondThread::OpenImage(TSgThreadTestInfo* aInfo, RSgDriver& aSgDriver)
   1.615 +	{
   1.616 +	RSgImage image;
   1.617 +	TInt result = 0;
   1.618 +	TInt err = image.Open(aInfo->iDrawableId);
   1.619 +	if(KErrNoMemory == err)
   1.620 +		{
   1.621 +		return KErrNoMemory;
   1.622 +		}
   1.623 +	if(KErrNone == err)
   1.624 +		{
   1.625 +		result |= EFirstTestPassed;
   1.626 +		}
   1.627 +	TSgImageInfo info;
   1.628 +	if(KErrNone == image.GetInfo(info))
   1.629 +		{
   1.630 +		result |= ESecondTestPassed;
   1.631 +		}
   1.632 +	if(CTSgTestStepBase::CompareInfos(aInfo->iImageInfo, info))
   1.633 +		{
   1.634 +		result |= EThirdTestPassed;
   1.635 +		}
   1.636 +	TSgDrawableId id = image.Id();
   1.637 +	if(id != KSgNullDrawableId)
   1.638 +		{
   1.639 +		result |= EFourthTestPassed;
   1.640 +		}
   1.641 +	if(id == aInfo->iDrawableId)
   1.642 +		{
   1.643 +		result |= EFifthTestPassed;
   1.644 +		}
   1.645 +	TInt attribVal = KMaxTInt;
   1.646 +	TUid uid = { 0x12345678 };
   1.647 +	if (KErrNotSupported == image.GetAttribute(uid, attribVal))
   1.648 +		{
   1.649 +		result |= ESixthTestPassed;
   1.650 +		}
   1.651 +	if (KErrArgument == image.GetAttribute(KNullUid, attribVal))
   1.652 +		{
   1.653 +		result |= ESeventhTestPassed;
   1.654 +		}
   1.655 +	image.Close();
   1.656 +	aSgDriver.Close();
   1.657 +	if (KErrBadHandle == image.GetAttribute(uid, attribVal))
   1.658 +		{
   1.659 +		result |= EEighthTestPassed;
   1.660 +		}
   1.661 +	
   1.662 +	return result;
   1.663 +	}
   1.664 +
   1.665 +/**
   1.666 +Implementation of SecondThread test ESgresSecondThreadOpenDrawable
   1.667 +
   1.668 +@return One of the system wide error codes or an enumeration of passed tests.
   1.669 +
   1.670 +@param TSgresTestInfo* The test parameters
   1.671 + */
   1.672 +TInt SgTestSecondThread::OpenDrawable(TSgThreadTestInfo* aInfo)
   1.673 +	{
   1.674 +	TInt result = 0;
   1.675 +	RSgDrawable drawable;
   1.676 +	TInt err = drawable.Open(aInfo->iDrawableId);
   1.677 +	if(KErrNoMemory == err)
   1.678 +		{
   1.679 +		result = KErrNoMemory;
   1.680 +		return result;
   1.681 +		}
   1.682 +	if(KErrNone == err)
   1.683 +		{
   1.684 +		result |= EFirstTestPassed;
   1.685 +		}
   1.686 +	TSgDrawableId id = drawable.Id();
   1.687 +	if(id != KSgNullDrawableId)
   1.688 +		{
   1.689 +		result |= ESecondTestPassed;
   1.690 +		}
   1.691 +	if(id == aInfo->iDrawableId)
   1.692 +		{
   1.693 +		result |= EThirdTestPassed;
   1.694 +		}
   1.695 +	drawable.Close();
   1.696 +	return result;
   1.697 +	}
   1.698 +
   1.699 +/**
   1.700 +Implementation of SecondThread test ESgresSecondThreadOpenImageInvalid
   1.701 +
   1.702 +@return One of the system wide error codes or an enumeration of passed tests.
   1.703 +
   1.704 +@param TSgresTestInfo* The test parameters
   1.705 + */
   1.706 +TInt SgTestSecondThread::OpenImageInvalid(TSgThreadTestInfo* aInfo)
   1.707 +	{
   1.708 +	TInt result = 0;
   1.709 +	RSgImage image;
   1.710 +	TSgImageInfo info;
   1.711 +	info.iSizeInPixels = TSize(8, 8);
   1.712 +	info.iPixelFormat = EUidPixelFormatRGB_565;
   1.713 +	info.iUsage = ESgUsageBitOpenVgImage;
   1.714 +	
   1.715 +	TInt err = image.Create(info, KCrossImageData, KCrossImageDataStride);
   1.716 +	if(KErrNoMemory == err)
   1.717 +		{
   1.718 +		return KErrNoMemory;
   1.719 +		}
   1.720 +	if(KErrNone == err)
   1.721 +		{
   1.722 +		result |= EFirstTestPassed;
   1.723 +		}
   1.724 +	
   1.725 +	//  non-empty handle
   1.726 +	TSgDrawableId id = aInfo->iDrawableId;
   1.727 +	err = image.Open(id);
   1.728 +	if(KErrNoMemory == err)
   1.729 +		{
   1.730 +		return KErrNoMemory;
   1.731 +		}
   1.732 +	if(KErrInUse == err)
   1.733 +		{
   1.734 +		result |= ESecondTestPassed;
   1.735 +		}
   1.736 +	image.Close();
   1.737 +	
   1.738 +	//  null drawable id    
   1.739 +	err = image.Open(KSgNullDrawableId);
   1.740 +	if(KErrNoMemory == err)
   1.741 +		{
   1.742 +		return KErrNoMemory;
   1.743 +		}
   1.744 +	if(KErrArgument == err)
   1.745 +		{
   1.746 +		result |= EThirdTestPassed;
   1.747 +		}
   1.748 +	image.Close();
   1.749 +	
   1.750 +	//  non-existing drawable id
   1.751 +	err = image.Open(KFakeSgDrawableId);
   1.752 +	if(KErrNoMemory == err)
   1.753 +		{
   1.754 +		return KErrNoMemory;
   1.755 +		}
   1.756 +	if(KErrNotFound == err)
   1.757 +		{
   1.758 +		result |= EFourthTestPassed;
   1.759 +		}
   1.760 +	image.Close();
   1.761 +	
   1.762 +	err = image.Open(id);
   1.763 +	if(KErrNoMemory == err)
   1.764 +		{
   1.765 +		return KErrNoMemory;
   1.766 +		}
   1.767 +	if(KErrNone == err)
   1.768 +		{
   1.769 +		result |= EFifthTestPassed;
   1.770 +		}
   1.771 +	image.Close();
   1.772 +	
   1.773 +	return result;
   1.774 +	}
   1.775 +
   1.776 +/**
   1.777 +Implementation of SecondThread test ESgresSecondThreadOpenDrawableInvalid
   1.778 +
   1.779 +@return One of the system wide error codes or an enumeration of passed tests.
   1.780 +
   1.781 +@param TSgresTestInfo* The test parameters
   1.782 +*/
   1.783 +TInt SgTestSecondThread::OpenDrawableInvalid(TSgThreadTestInfo* aInfo)
   1.784 +	{
   1.785 +	TInt result = 0;
   1.786 +	RSgDrawable drawable;
   1.787 +	TInt err = drawable.Open(KSgNullDrawableId);
   1.788 +	if(KErrNoMemory == err)
   1.789 +		{
   1.790 +	    return KErrNoMemory;
   1.791 +		}
   1.792 +	if(KErrArgument == err)
   1.793 +		{
   1.794 +	    result |= EFirstTestPassed;
   1.795 +	    }
   1.796 +	drawable.Close();
   1.797 +	
   1.798 +	//  non-existing drawable id
   1.799 +	err = drawable.Open(KFakeSgDrawableId);
   1.800 +	if (KErrNoMemory == err)
   1.801 +		{
   1.802 +		return KErrNoMemory;
   1.803 +		}
   1.804 +	
   1.805 +	if(KErrNotFound == err)
   1.806 +		{
   1.807 +		result |= ESecondTestPassed;
   1.808 +		}
   1.809 +	drawable.Close();
   1.810 +	
   1.811 +	//  open a non-sharable image - should succeed
   1.812 +	err = drawable.Open(aInfo->iDrawableId);
   1.813 +	
   1.814 +	if(KErrNoMemory == err)
   1.815 +		{
   1.816 +		return KErrNoMemory;
   1.817 +		}
   1.818 +	if(KErrNone == err)
   1.819 +		{
   1.820 +		result |= EThirdTestPassed;
   1.821 +		
   1.822 +		if (KErrInUse == drawable.Open(aInfo->iDrawableId))
   1.823 +			{
   1.824 +			result |= EFourthTestPassed;
   1.825 +			}
   1.826 +		}
   1.827 +
   1.828 +	drawable.Close();
   1.829 +	
   1.830 +	return result;
   1.831 +	}
   1.832 +
   1.833 +/**
   1.834 +Implementation of SecondThread test ESgresSecondThreadPanicImageGetInterfaceInvalidHandle
   1.835 +
   1.836 +@panic SGRES2 If the test is successful
   1.837 +
   1.838 +@return One of the system wide error codes.
   1.839 +
   1.840 +@param RSgDriver An open RSgDriver for the test code to use
   1.841 + */
   1.842 +TInt SgTestSecondThread::PanicImageGetInterfaceInvalidHandle(RSgDriver& aSgDriver)
   1.843 +	{
   1.844 +	RSgImage image;
   1.845 +	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); 
   1.846 +
   1.847 +	MTSgImage_Interface* swInterface = NULL;
   1.848 +	result = image.GetInterface(swInterface); //should panic with SGRES 3
   1.849 +	aSgDriver.Close();
   1.850 +	
   1.851 +	return result;
   1.852 +	}
   1.853 +
   1.854 +/**
   1.855 +Implementation of SecondThread test ESgresSecondThreadPanicImageGetInterfaceNoDriver
   1.856 +
   1.857 +@panic SGRES1 If the test is successful
   1.858 +
   1.859 +@return One of the system wide error codes
   1.860 +
   1.861 +@param RSgDriver An open RSgDriver for the test code to use
   1.862 + */
   1.863 +TInt SgTestSecondThread::PanicImageGetInterfaceNoDriver(RSgDriver& aSgDriver)
   1.864 +	{
   1.865 +	RSgImage image;
   1.866 +	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
   1.867 +	
   1.868 +	aSgDriver.Close();
   1.869 +	MTSgImage_Interface* swInterface = NULL;
   1.870 +	image.GetInterface(swInterface); // should panic with SGRES 1
   1.871 +	return result;
   1.872 +	}
   1.873 +
   1.874 +/**
   1.875 +Implementation of SecondThread test ESgresSecondThreadPanicImageCloseInvalidHandle
   1.876 +
   1.877 +@panic SGRES2 If the test is successful
   1.878 +
   1.879 +@return One of the system wide error codes
   1.880 +
   1.881 +@param RSgDriver An open RSgDriver for the test code to use
   1.882 + */
   1.883 +TInt SgTestSecondThread::PanicImageCloseInvalidHandle(RSgDriver& aSgDriver)
   1.884 +	{
   1.885 +	RSgImage image;
   1.886 +	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
   1.887 +	
   1.888 +	image.Close(); //should panic with SGRES 3
   1.889 +	aSgDriver.Close();
   1.890 +	return result;
   1.891 +	}
   1.892 +
   1.893 +/**
   1.894 +Implementation of SecondThread test ESgresSecondThreadPanicImageCloseNoDriver
   1.895 +
   1.896 +@panic SGRES1 If the test is successful
   1.897 +
   1.898 +@return One of the system wide error codes
   1.899 +
   1.900 +@param RSgDriver An open RSgDriver for the test code to use
   1.901 + */
   1.902 +TInt SgTestSecondThread::PanicImageCloseNoDriver(RSgDriver& aSgDriver)
   1.903 +	{
   1.904 +	RSgImage image;
   1.905 +	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
   1.906 +	aSgDriver.Close();
   1.907 +	image.Close(); // should panic with SGRES 1 
   1.908 +	return result;
   1.909 +	}
   1.910 +
   1.911 +/**
   1.912 +Implementation of SecondThread test ESgresSecondThreadPanicImageIdIvalidHandle
   1.913 +
   1.914 +@panic SGRES2 If the test is successful
   1.915 +
   1.916 +@return One of the system wide error codes
   1.917 +
   1.918 +@param RSgDriver An open RSgDriver for the test code to use
   1.919 + */
   1.920 +TInt SgTestSecondThread::PanicImageIdInvalidHandle(RSgDriver& aSgDriver)
   1.921 +	{
   1.922 +	RSgImage image;
   1.923 +	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
   1.924 +	
   1.925 +	image.Id(); //should panic with SGRES 3
   1.926 +	aSgDriver.Close();
   1.927 +	return result;
   1.928 +	}
   1.929 +
   1.930 +/**
   1.931 +Implementation of SecondThread test ESgresSecondThreadPanicImageIdNoDriver
   1.932 +
   1.933 +@panic SGRES1 If the test is successful
   1.934 +
   1.935 +@return One of the system wide error codes
   1.936 +
   1.937 +@param RSgDriver An open RSgDriver for the test code to use
   1.938 + */
   1.939 +TInt SgTestSecondThread::PanicImageIdNoDriver(RSgDriver& aSgDriver)
   1.940 +	{
   1.941 +	RSgImage image;
   1.942 +	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
   1.943 +
   1.944 +	aSgDriver.Close();
   1.945 +	image.Id(); // should panic with SGRES 1
   1.946 +	return result;
   1.947 +	}
   1.948 +
   1.949 +/**
   1.950 +Implementation of SecondThread test ESgresSecondThreadPanicImageDrawableTypeInvalidHandle
   1.951 +
   1.952 +@panic SGRES2 If the test is successful
   1.953 +
   1.954 +@return One of the system wide error codes
   1.955 +
   1.956 +@param RSgDriver An open RSgDriver for the test code to use
   1.957 + */
   1.958 +TInt SgTestSecondThread::PanicImageDrawableTypeInvalidHandle(RSgDriver& aSgDriver)
   1.959 +	{
   1.960 +	RSgImage image; 
   1.961 +	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
   1.962 +	
   1.963 +	image.DrawableType(); //should panic with SGRES 3
   1.964 +	aSgDriver.Close();
   1.965 +	
   1.966 +	return result;
   1.967 +	}
   1.968 +
   1.969 +/**
   1.970 +Implementation of SecondThread test ESgresSecondThreadPanicImageDrawableTypeNoDriver
   1.971 +
   1.972 +@panic SGRES1 If the test is successful
   1.973 +
   1.974 +@return One of the system wide error codes
   1.975 +
   1.976 +@param RSgDriver An open RSgDriver for the test code to use
   1.977 + */
   1.978 +TInt SgTestSecondThread::PanicImageDrawableTypeNoDriver(RSgDriver& aSgDriver)
   1.979 +	{
   1.980 +	RSgImage image; 
   1.981 +	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
   1.982 +	aSgDriver.Close();
   1.983 +	image.DrawableType(); // should panic with SGRES 1
   1.984 +	return result;
   1.985 +	}
   1.986 +
   1.987 +/**
   1.988 +Implementation of SecondThread test ESgresSecondThreadPanicImageCreateInvalidHandle
   1.989 +
   1.990 +@panic SGRES3 If the test is successful
   1.991 +
   1.992 +@return One of the system wide error codes
   1.993 +
   1.994 +@param RSgDriver An open RSgDriver for the test code to use
   1.995 + */
   1.996 +TInt SgTestSecondThread::PanicImageCreateInvalidHandle(RSgDriver& aSgDriver)
   1.997 +	{
   1.998 +	RSgImage image; 
   1.999 +	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
  1.1000 +	
  1.1001 +	RSgImage newImage;
  1.1002 +	TSgImageInfo info;
  1.1003 +	image.GetInfo(info);
  1.1004 +	newImage.Create(info, image); //should panic with SGRES 3
  1.1005 +	aSgDriver.Close();
  1.1006 +	return result;
  1.1007 +	}
  1.1008 +
  1.1009 +/**
  1.1010 +Implementation of SecondThread test ESgresSecondThreadPanicImageGetInfoInvalidHandle
  1.1011 +
  1.1012 +@panic SGRES3 If the test is successful
  1.1013 +
  1.1014 +@return One of the system wide error codes
  1.1015 +
  1.1016 +@param RSgDriver An open RSgDriver for the test code to use
  1.1017 + */
  1.1018 +TInt SgTestSecondThread::PanicImageGetInfoInvalidHandle(RSgDriver& aSgDriver)
  1.1019 +	{
  1.1020 +	RSgImage image; 
  1.1021 +	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
  1.1022 +	
  1.1023 +	TSgImageInfo anotherInfo;
  1.1024 +	image.GetInfo(anotherInfo); //should panic with SGRES 3
  1.1025 +	aSgDriver.Close();
  1.1026 +	return result;
  1.1027 +	}
  1.1028 +
  1.1029 +/**
  1.1030 +Implementation of SecondThread test ESgresSecondThreadPanicImageNoDriver
  1.1031 +
  1.1032 +@panic SGRES1 If the test is successful
  1.1033 +
  1.1034 +@return One of the system wide error codes or an enumeration of passed tests.
  1.1035 +
  1.1036 +@param RSgDriver An open RSgDriver for the test code to use
  1.1037 + */
  1.1038 +TInt SgTestSecondThread::PanicImageGetInfoNoDriver(RSgDriver& aSgDriver)
  1.1039 +	{
  1.1040 +	RSgImage image; 
  1.1041 +	TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image);
  1.1042 +	if(KErrNone != ret)
  1.1043 +		{
  1.1044 +		return ret;
  1.1045 +		}
  1.1046 +	RSgImage anotherImage;
  1.1047 +	Mem::Copy(&anotherImage, &image, sizeof(image));
  1.1048 +	image.Close();
  1.1049 +	aSgDriver.Close();
  1.1050 +	TSgImageInfo anotherInfo;
  1.1051 +	anotherImage.GetInfo(anotherInfo); // should panic with SGRES 1
  1.1052 +	return ret;
  1.1053 +	}
  1.1054 +
  1.1055 +/**
  1.1056 +Implementation of SecondThread test ESgresSecondThreadPanicImageGetAttributeInvalidHandle
  1.1057 +
  1.1058 +@panic SGRES3 If the test is successful
  1.1059 +
  1.1060 +@return One of the system wide error codes
  1.1061 +
  1.1062 +@param RSgDriver An open RSgDriver for the test code to use
  1.1063 + */
  1.1064 +TInt SgTestSecondThread::PanicImageGetAttributeInvalidHandle(RSgDriver& aSgDriver)
  1.1065 +	{
  1.1066 +	RSgImage image; 
  1.1067 +	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
  1.1068 +	
  1.1069 +	TInt attrib = KMaxTInt;
  1.1070 +	image.GetAttribute(TUid::Uid(1), attrib); //Should panic with SGRES 3
  1.1071 +	
  1.1072 +	aSgDriver.Close();
  1.1073 +	return result;
  1.1074 +	}
  1.1075 +
  1.1076 +/**
  1.1077 +Implementation of SecondThread test ESgresSecondThreadPanicImageGetAttributeNoDriver
  1.1078 +
  1.1079 +@panic SGRES1 If the test is successful
  1.1080 +
  1.1081 +@return One of the system wide error codes
  1.1082 +
  1.1083 +@param RSgDriver An open RSgDriver for the test code to use
  1.1084 + */
  1.1085 +TInt SgTestSecondThread::PanicImageGetAttributeNoDriver(RSgDriver& aSgDriver)
  1.1086 +	{
  1.1087 +	RSgImage image; 
  1.1088 +	TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image);
  1.1089 +	if(KErrNone != ret)
  1.1090 +		{
  1.1091 +		return ret;
  1.1092 +		}
  1.1093 +	RSgImage anotherImage;
  1.1094 +	Mem::Copy(&anotherImage, &image, sizeof(image));
  1.1095 +	image.Close();
  1.1096 +	aSgDriver.Close();
  1.1097 +	TInt attrib = KMaxTInt;
  1.1098 +	TUid uid = { 0x12345678 };
  1.1099 +	anotherImage.GetAttribute(uid, attrib); //Should panic with SGRES 1
  1.1100 +	return ret;
  1.1101 +	}
  1.1102 +
  1.1103 +/**
  1.1104 +Implementation of SecondThread test ESgresSecondThreadMultipleThreadStressTest
  1.1105 +
  1.1106 +@return One of the system wide error codes
  1.1107 +
  1.1108 +@param TSgresTestInfo* The test parameters
  1.1109 + */
  1.1110 +TInt SgTestSecondThread::MultipleThreadStressTest(TSgThreadTestInfo* aInfo)
  1.1111 +	{
  1.1112 +	TInt result = 0;
  1.1113 +	RSgImage image;
  1.1114 +	for (TInt i = 0; i < 1000 && result == KErrNone; ++i)
  1.1115 +		{
  1.1116 +		TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image); 
  1.1117 +		if (KErrNone != ret)
  1.1118 +			{
  1.1119 +			result = ret;
  1.1120 +			break;
  1.1121 +			}
  1.1122 +
  1.1123 +		const TInt KMaxOpenCount = 100;
  1.1124 +		RSgImage images[KMaxOpenCount];
  1.1125 +		TInt count = Math::Random() % KMaxOpenCount;
  1.1126 +		for (TInt k = 0; k < count; ++k)
  1.1127 +			{
  1.1128 +			ret = images[k].Open(aInfo->iDrawableId);
  1.1129 +			if (KErrNone != ret)
  1.1130 +				{
  1.1131 +				result = ret;
  1.1132 +				break;
  1.1133 +				}
  1.1134 +			}
  1.1135 +		image.Close();
  1.1136 +		for (TInt k = 0; k < count; ++k)
  1.1137 +			{
  1.1138 +			images[k].Close();
  1.1139 +			}
  1.1140 +		}
  1.1141 +	return result;
  1.1142 +	}
  1.1143 +
  1.1144 +/**
  1.1145 +Implementation of SecondThread test ESgresSecondThreadPanicAttributeArrayInvalidIndex
  1.1146 +
  1.1147 +@panic SGRES4 If the test is successful
  1.1148 +
  1.1149 +@param TSgresTestInfo* The test parameters
  1.1150 + */
  1.1151 +void SgTestSecondThread::PanicAttributeArrayInvalidIndexL()
  1.1152 +	{
  1.1153 +	TSgAttributeArray<5> attribArray;
  1.1154 +	TSgAttribute attrib = attribArray[6]; //Should panic with SGRES 4
  1.1155 +	}
  1.1156 +
  1.1157 +/**
  1.1158 +Implementation of SecondThread test ESgresSecondThreadPanicAttributeArrayInvalidIndex2
  1.1159 +
  1.1160 +@panic SGRES4 If the test is successful
  1.1161 +
  1.1162 +@param TSgresTestInfo* The test parameters
  1.1163 + */
  1.1164 +void SgTestSecondThread::PanicAttributeArrayInvalidIndex2L()
  1.1165 +	{
  1.1166 +	TSgAttributeArray<5> attribArray;
  1.1167 +	TSgAttribute attrib = attribArray[-1]; //Should panic with SGRES 4
  1.1168 +	}
  1.1169 +
  1.1170 +/**
  1.1171 +Implementation of SecondThread test ESgresSecondThreadPanicDriverCloseOpenResources
  1.1172 +
  1.1173 +@return One of the system wide error codes
  1.1174 +
  1.1175 +@param RSgImage* A closed or uninitialised RSgImage to use for image creation 
  1.1176 + */
  1.1177 +TInt SgTestSecondThread::CreatePassedImageL(RSgImage* aSgImage)
  1.1178 +	{
  1.1179 +	TSgImageInfo info;
  1.1180 +	info.iSizeInPixels = TSize(8, 8);
  1.1181 +	info.iUsage = ESgUsageBitOpenVgImage;
  1.1182 +	info.iPixelFormat = EUidPixelFormatRGB_565;
  1.1183 +	
  1.1184 +	return aSgImage->Create(info, KCrossImageData, KCrossImageDataStride);
  1.1185 +	}
  1.1186 +
  1.1187 +/**
  1.1188 +Helper function which Creates an RSgImage and copies to into another RSgImage 
  1.1189 +using Mem::Copy; the target of the copy is returned in the open state.
  1.1190 +
  1.1191 +@param aSgImage An uninitialised image which will have an SgImage Mem::Copied into it.
  1.1192 +@return One of the system wide error codes.
  1.1193 + */
  1.1194 +TInt CTSgTestStepBase::CreateImageAndReturnCopy(RSgImage& aSgImage)
  1.1195 +	{
  1.1196 +	RSgImage image; 
  1.1197 +	TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image);
  1.1198 +	if(KErrNone != ret)
  1.1199 +		{
  1.1200 +		return ret;
  1.1201 +		}
  1.1202 +	Mem::Copy(&aSgImage, &image, sizeof(image));
  1.1203 +	image.Close();
  1.1204 +	
  1.1205 +	return ret;
  1.1206 +	}