os/graphics/graphicsresourceservices/graphicsresource/test/tgraphicsresourceteststepbase.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresource/test/tgraphicsresourceteststepbase.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1366 @@
     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 - Internal Symbian test code 
    1.23 +*/
    1.24 +
    1.25 +#include "tgraphicsresourceteststepbase.h"
    1.26 +#include <e32math.h>
    1.27 +
    1.28 +CTSgTestStepBase::CTSgTestStepBase()
    1.29 +	{
    1.30 +	}
    1.31 +
    1.32 +CTSgTestStepBase::~CTSgTestStepBase()
    1.33 +	{
    1.34 +	iSecondThread.Close();
    1.35 +	}
    1.36 +
    1.37 +/**
    1.38 +Overrides of base class virtual
    1.39 +@leave Gets system wide error code
    1.40 +@return - TVerdict code
    1.41 +*/
    1.42 +TVerdict CTSgTestStepBase::doTestStepPreambleL()
    1.43 +	{
    1.44 +	SetTestStepResult(EPass);
    1.45 +	return TestStepResult();
    1.46 +	}
    1.47 +
    1.48 +/**
    1.49 +Override of base class virtual
    1.50 +@leave Gets system wide error code
    1.51 +@return - TVerdict code
    1.52 +*/
    1.53 +TVerdict CTSgTestStepBase::doTestStepPostambleL()
    1.54 +	{
    1.55 +	return TestStepResult();
    1.56 +	}
    1.57 +
    1.58 +/**
    1.59 +Override of function from CTestStep so that each test failure is reported in output.
    1.60 +*/
    1.61 +EXPORT_C void CTSgTestStepBase::testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine) 
    1.62 +	{
    1.63 +	TRAP_IGNORE(testBooleanTrueL(aCondition, aFile, aLine, ETrue));
    1.64 +	}
    1.65 +
    1.66 +/**
    1.67 +Creates an image with some predefined parametres.
    1.68 +@param aImage output image handle
    1.69 +@leave Gets system wide error code
    1.70 +*/
    1.71 +void CTSgTestStepBase::CreateImageL(RSgImage& aImage)
    1.72 +	{
    1.73 +	TSgImageInfo info;
    1.74 +	info.iSizeInPixels = TSize(8, 8);
    1.75 +	info.iUsage = ESgUsageDirectGdiSource;
    1.76 +	info.iPixelFormat = EUidPixelFormatRGB_565;
    1.77 +	info.iCpuAccess = ESgCpuAccessReadWrite;
    1.78 +	info.iShareable = ETrue;
    1.79 +	
    1.80 +	CheckErrorL(KErrNone, aImage.Create(info, KImageData, 16), (TText8*)__FILE__, __LINE__);
    1.81 +	}
    1.82 +
    1.83 +/**
    1.84 +Creates an image collection with some predefined parametres.
    1.85 +@param aCollection output image collection handle
    1.86 +@leave Gets system wide error code
    1.87 +*/
    1.88 +void CTSgTestStepBase::CreateImageCollectionL(RSgImageCollection& aCollection)
    1.89 +	{
    1.90 +	TSgImageInfo info;
    1.91 +	info.iSizeInPixels = TSize(8, 8);
    1.92 +	info.iUsage = ESgUsageDirectGdiSource;
    1.93 +	info.iPixelFormat = EUidPixelFormatRGB_565;
    1.94 +	info.iCpuAccess = ESgCpuAccessReadWrite;
    1.95 +	CheckErrorL(KErrNone, aCollection.Create(info, KNumImagesInCollection), (TText8*)__FILE__, __LINE__);
    1.96 +	TEST(!aCollection.IsNull());
    1.97 +	}
    1.98 +
    1.99 +/**
   1.100 +Creates a second process and do some tests in it.
   1.101 +@param aProcessName The name of the new process
   1.102 +@param aTestInfo The information for the tests
   1.103 +@leave Gets system wide error code
   1.104 +*/
   1.105 +TInt CTSgTestStepBase::CreateSecondProcessAndDoTestL(const TDesC &aProcessName, TSgresTestInfo& aTestInfo)
   1.106 +	{
   1.107 +	// Create a second process
   1.108 +    RProcess process;
   1.109 +    User::LeaveIfError(process.Create(aProcessName, KNullDesC));
   1.110 +	CleanupClosePushL(process);
   1.111 +
   1.112 +	// Specify the test for the second process
   1.113 +	TESTL(KErrNone == process.SetParameter(KSecondProcessFunctionSlot, ((TSgresTestInfo)aTestInfo).iTestCase));
   1.114 +	// Specify the id passed to the second process
   1.115 +	TPckg<TSgresTestInfo> ptr(aTestInfo);
   1.116 +	
   1.117 +	TESTL(KErrNone == process.SetParameter(KSecondProcessParametersSlot, ptr));
   1.118 +	// Kick off the second process and wait for it to complete
   1.119 +	// The actual testing is done in the second process
   1.120 +	TRequestStatus status = KRequestPending;
   1.121 +	process.Logon(status);
   1.122 +	process.Resume();
   1.123 +	User::WaitForRequest(status);
   1.124 +	
   1.125 +	TInt exitreason = process.ExitReason();
   1.126 +	
   1.127 +	CleanupStack::PopAndDestroy();
   1.128 +	
   1.129 +	//return test result
   1.130 +	return exitreason;
   1.131 +	}
   1.132 +
   1.133 +/**
   1.134 +Creates a second thread and do some tests in it.
   1.135 +@param aTestInfo The information for the tests
   1.136 +@leave Gets system wide error code
   1.137 +*/
   1.138 +TInt CTSgTestStepBase::CreateSecondThreadAndDoTestL(TSgresTestInfo aTestInfo)
   1.139 +	{
   1.140 +	//create a semaphore
   1.141 +	RSemaphore sem;
   1.142 +	User::LeaveIfError(sem.CreateGlobal(KSecondThreadSemaphore, 0, EOwnerThread));
   1.143 +	CleanupClosePushL(sem);
   1.144 +	
   1.145 +	User::LeaveIfError(iSecondThread.Create(KSecondThread, SecondThreadStart, KDefaultStackSize, &User::Heap(), &aTestInfo));
   1.146 +	// Launch second thread
   1.147 +	TRequestStatus statusSecondThread;
   1.148 +	iSecondThread.Logon(statusSecondThread);
   1.149 +	iSecondThread.SetPriority(EPriorityLess);
   1.150 +	iSecondThread.Resume();	
   1.151 +	
   1.152 +	User::WaitForRequest(statusSecondThread);
   1.153 +	
   1.154 +	TInt result = iSecondThread.ExitReason();
   1.155 +	
   1.156 +	//Close the handle
   1.157 +    CleanupStack::PopAndDestroy(1, &sem);
   1.158 +    iSecondThread.Close();
   1.159 +	
   1.160 +	return result;
   1.161 +	}
   1.162 +
   1.163 +/**
   1.164 +Creates a second thread and do some panic tests in it.
   1.165 +@param aTestInfo The information for the tests
   1.166 +@param aPanicCode The expected panic code
   1.167 +@param aExitCategory The expected panic category
   1.168 +@param aThreadName The name of the new thread
   1.169 +@leave Gets system wide error code
   1.170 +*/
   1.171 +void CTSgTestStepBase::CreateSecondThreadAndCheckPanicL(TSgresTestInfo aTestInfo, TInt aPanicCode, TExitCategoryName aExitCategory, const TDesC &aThreadName)
   1.172 +	{
   1.173 +	User::LeaveIfError(iSecondThread.Create(aThreadName, SecondThreadStart, KDefaultStackSize, 0x100, 0x100, &aTestInfo));
   1.174 +	// Launch second thread
   1.175 +	TRequestStatus statusSecondThread;
   1.176 +	iSecondThread.Logon(statusSecondThread);
   1.177 +	iSecondThread.SetPriority(EPriorityLess);
   1.178 +	iSecondThread.Resume();	
   1.179 +	
   1.180 +	User::WaitForRequest(statusSecondThread);
   1.181 +	
   1.182 +	if(EExitPanic != iSecondThread.ExitType())
   1.183 +		{
   1.184 +		ERR_PRINTF3(_L("Expected exit type: %d, Actual exit type: %d"), EExitPanic, iSecondThread.ExitType());
   1.185 +		TEST(EFalse);
   1.186 +		}
   1.187 +	
   1.188 +	if(aPanicCode != iSecondThread.ExitReason())
   1.189 +		{
   1.190 +		ERR_PRINTF3(_L("Expected panic code: %d, Actual panic code: %d"), aPanicCode, iSecondThread.ExitReason());
   1.191 +		TEST(EFalse);
   1.192 +		}
   1.193 +	
   1.194 +	TExitCategoryName secondThreadExitCategory = iSecondThread.ExitCategory();
   1.195 +	if(aExitCategory != secondThreadExitCategory)
   1.196 +		{
   1.197 +		ERR_PRINTF3(_L("Expected panic category: %S, Actual panic category: %S"), &aExitCategory, &secondThreadExitCategory);
   1.198 +		TEST(EFalse);
   1.199 +		}
   1.200 +	
   1.201 +	 //close the driver if the second thread exited with type EExitKill
   1.202 +	 //assumming the second thread only calls SgDriver::Open() once
   1.203 +	 if(iSecondThread.ExitType() != EExitKill)
   1.204 +	   	{
   1.205 +	   	SgDriver::Close();
   1.206 +	   	}
   1.207 +	
   1.208 +	//Close the handle
   1.209 +    iSecondThread.Close();
   1.210 +	}
   1.211 +
   1.212 +/**
   1.213 +Creates a second process and do some panic tests in it.
   1.214 +@param aTestInfo The information for the tests
   1.215 +@param aPanicCode The expected panic code
   1.216 +@param aExitCategory The expected panic category
   1.217 +@param aProcessName The name of the new process
   1.218 +@leave Gets system wide error code
   1.219 +*/
   1.220 +void CTSgTestStepBase::CreateSecondProcessAndCheckPanicL(TSgresTestInfo aTestInfo, TInt aPanicCode, TExitCategoryName aExitCategory, const TDesC &aProcessName)
   1.221 +	{
   1.222 +	// Create a second process
   1.223 +    RProcess process;
   1.224 +    User::LeaveIfError(process.Create(KSecondProcess, aProcessName));
   1.225 +	CleanupClosePushL(process);
   1.226 +
   1.227 +	// Specify the test for the second process
   1.228 +	TESTL(KErrNone == process.SetParameter(KSecondProcessFunctionSlot, ((TSgresTestInfo)aTestInfo).iTestCase));
   1.229 +	// Specify the id passed to the second process
   1.230 +	TPckg<TSgresTestInfo> ptr(aTestInfo);
   1.231 +	
   1.232 +	TESTL(KErrNone == process.SetParameter(KSecondProcessParametersSlot, ptr));
   1.233 +	// Kick off the second process and wait for it to complete
   1.234 +	// The actual testing is done in the second process
   1.235 +	TRequestStatus status;
   1.236 +	process.Logon(status);
   1.237 +	process.Resume();
   1.238 +	User::WaitForRequest(status);
   1.239 +	
   1.240 +	if(EExitPanic != process.ExitType())
   1.241 +		{
   1.242 +		ERR_PRINTF3(_L("Expected exit type: %d, Actual exit type: %d"), EExitPanic, process.ExitType());
   1.243 +		TEST(EFalse);
   1.244 +		}
   1.245 +	if(aPanicCode != process.ExitReason())
   1.246 +		{
   1.247 +		ERR_PRINTF3(_L("Expected panic code: %d, Actual panic code: %d"), aPanicCode, process.ExitReason());
   1.248 +		TEST(EFalse);
   1.249 +		}
   1.250 +	
   1.251 +	_LIT(KMemoryLeakCategory, "SGALLOC");
   1.252 +	TExitCategoryName processExitCategory = process.ExitCategory();
   1.253 +	TBool matchCategory;
   1.254 +	if (aExitCategory != KMemoryLeakCategory)
   1.255 +		{
   1.256 +		matchCategory = aExitCategory == processExitCategory;
   1.257 +		}
   1.258 +	else
   1.259 +		{
   1.260 +		matchCategory = processExitCategory.Left(KMemoryLeakCategory().Length()) == KMemoryLeakCategory;
   1.261 +		}
   1.262 +	if (!matchCategory)
   1.263 +		{
   1.264 +		ERR_PRINTF3(_L("Expected panic category: %S, Actual panic category: %S"), &aExitCategory, &processExitCategory);
   1.265 +		TEST(EFalse);
   1.266 +		}
   1.267 +	
   1.268 +	CleanupStack::PopAndDestroy();
   1.269 +	}
   1.270 +
   1.271 +/**
   1.272 +Gets the supporting pixel formats according to the specified cpu access, usage, shareability and screen id flags.
   1.273 +@leave Gets system wide error code
   1.274 +*/
   1.275 +void CTSgTestStepBase::CallGetPixelFormatsL(TSgCpuAccess aCpuAccess, TUint32 aUsage, TBool aShareable, TInt aScreenId)
   1.276 +	{
   1.277 +	TSgImageInfo info;
   1.278 +	info.iCpuAccess = aCpuAccess;
   1.279 +	info.iUsage = aUsage;
   1.280 +	info.iShareable = aShareable;
   1.281 +	info.iScreenId = aScreenId;
   1.282 +	info.iSizeInPixels = TSize(10, 10);
   1.283 +	iPixelFormatCount = KMaxPixelFormats;
   1.284 +	Mem::FillZ(iPixelFormatArray, KMaxPixelFormats * sizeof(TUidPixelFormat));
   1.285 +	CheckErrorL(KErrNone, RSgImage::GetPixelFormats(info, iPixelFormatArray, iPixelFormatCount), (TText8*)__FILE__, __LINE__);
   1.286 +	}
   1.287 +
   1.288 +/**
   1.289 +Checks the pixel formats returned against the compatibility guarantee table.
   1.290 +@leave Gets system wide error code
   1.291 +*/
   1.292 +void CTSgTestStepBase::TestGetPixelFormatCompatibilityGuaranteesL()
   1.293 +	{
   1.294 +	CallGetPixelFormatsL(ESgCpuAccessNone, ESgUsageDirectGdiSource, ETrue, KSgScreenIdAny);
   1.295 +	CheckPixelFormatPresent(EUidPixelFormatARGB_8888_PRE);
   1.296 +	CheckPixelFormatPresent(EUidPixelFormatXRGB_8888);
   1.297 +	CheckPixelFormatPresent(EUidPixelFormatRGB_565);
   1.298 +
   1.299 +	CallGetPixelFormatsL(ESgCpuAccessReadWrite, ESgUsageDirectGdiSource, ETrue, KSgScreenIdMain);
   1.300 +	CheckPixelFormatPresent(EUidPixelFormatARGB_8888_PRE);
   1.301 +	CheckPixelFormatPresent(EUidPixelFormatXRGB_8888);
   1.302 +	CheckPixelFormatPresent(EUidPixelFormatRGB_565);
   1.303 +	
   1.304 +	CallGetPixelFormatsL(ESgCpuAccessNone, ESgUsageDirectGdiSource|ESgUsageDirectGdiTarget, ETrue, KSgScreenIdMain);
   1.305 +	CheckPixelFormatPresent(EUidPixelFormatARGB_8888_PRE);
   1.306 +	CheckPixelFormatPresent(EUidPixelFormatXRGB_8888);	
   1.307 +	
   1.308 +	CallGetPixelFormatsL(ESgCpuAccessNone, ESgUsageDirectGdiSource|ESgUsageOpenGlesTarget, ETrue, KSgScreenIdMain);
   1.309 +	CheckPixelFormatPresent(EUidPixelFormatARGB_8888_PRE);
   1.310 +	CheckPixelFormatPresent(EUidPixelFormatXRGB_8888);
   1.311 +	
   1.312 +	CallGetPixelFormatsL(ESgCpuAccessNone, ESgUsageDirectGdiSource|ESgUsageOpenVgTarget, ETrue, KSgScreenIdMain);
   1.313 +	CheckPixelFormatPresent(EUidPixelFormatARGB_8888_PRE);
   1.314 +	CheckPixelFormatPresent(EUidPixelFormatXRGB_8888);
   1.315 +	
   1.316 +	CallGetPixelFormatsL(ESgCpuAccessNone, ESgUsageDirectGdiSource|ESgUsageOpenGles2Target, ETrue, KSgScreenIdMain);
   1.317 +	CheckPixelFormatPresent(EUidPixelFormatARGB_8888_PRE);
   1.318 +	CheckPixelFormatPresent(EUidPixelFormatXRGB_8888);
   1.319 +	}
   1.320 +
   1.321 +/**
   1.322 +Helper function to check if a certain pixel format is present
   1.323 +in the returned pixel formats array.
   1.324 +@param aPixelFormat The pixelformat to check
   1.325 +*/
   1.326 +void CTSgTestStepBase::CheckPixelFormatPresent(TUidPixelFormat aPixelFormat)
   1.327 +	{
   1.328 +	for(TInt i=0; i<iPixelFormatCount; ++i)
   1.329 +		{		
   1.330 +		if(aPixelFormat == iPixelFormatArray[i])
   1.331 +			{
   1.332 +			return;
   1.333 +			}
   1.334 +		}
   1.335 +	TEST(EFalse);
   1.336 +	}
   1.337 +
   1.338 +/**
   1.339 +Helper function to test the equivalence of two TSgImageInfo structures.
   1.340 +
   1.341 +@see     CTDirectGdiContextTarget::CompareInfos
   1.342 +@param   aInfo1 A TSgImageInfo structure to compare.
   1.343 +@param   aInfo2 A TSgImageInfo structure to compare.
   1.344 +
   1.345 +@return  ETrue if the two are identical, EFalse otherwise.
   1.346 +*/
   1.347 +TBool CTSgTestStepBase::CompareInfos(TSgImageInfo& aInfo1, TSgImageInfo& aInfo2)
   1.348 +	{
   1.349 +	TBool result = EFalse;
   1.350 +	if(aInfo1.iCpuAccess == aInfo2.iCpuAccess 
   1.351 +		&& aInfo1.iPixelFormat == aInfo2.iPixelFormat
   1.352 +		&& aInfo1.iScreenId == aInfo2.iScreenId
   1.353 +		&& aInfo1.iShareable == aInfo2.iShareable
   1.354 +		&& aInfo1.iSizeInPixels == aInfo2.iSizeInPixels
   1.355 +		&& aInfo1.iUsage | aInfo2.iUsage
   1.356 +		&& aInfo1.iUserAttributeCount == aInfo2.iUserAttributeCount)
   1.357 +		{
   1.358 +		for(TInt i=0; i<aInfo1.iUserAttributeCount; ++i)
   1.359 +			{
   1.360 +			if(aInfo1.iUserAttributes[i].iUid != aInfo2.iUserAttributes[i].iUid)
   1.361 +				{
   1.362 +				break;
   1.363 +				}
   1.364 +			}
   1.365 +		result = ETrue;
   1.366 +		}
   1.367 +	return result;
   1.368 +	}
   1.369 +
   1.370 +/**
   1.371 +Wrapper function to open the graphics resource driver and puts an cleanup item
   1.372 +on the cleanup stack.
   1.373 +@leave Gets system wide error code
   1.374 +*/
   1.375 +void CTSgTestStepBase::TestOpenDriverL()
   1.376 +	{
   1.377 +	CheckErrorL(KErrNone, SgDriver::Open(), (TText8*)__FILE__, __LINE__);
   1.378 +	CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseDriverWhenLeave, NULL));
   1.379 +	}
   1.380 +
   1.381 +/**
   1.382 +Wrapper function to close the graphics resource driver.
   1.383 +*/
   1.384 +void CTSgTestStepBase::TestCloseDriver()
   1.385 +	{
   1.386 +	CleanupStack::PopAndDestroy();
   1.387 +	}
   1.388 +
   1.389 +/**
   1.390 +Creates an image with specified parametres.
   1.391 +@param aImage output image handle
   1.392 +@return KErrNone if the image was created successfully, otherwise one of the system-wide error codes
   1.393 +*/
   1.394 +TInt CreateImageWithParameters(TInt aWidth, TInt aHeight, TUidPixelFormat aPixelFormat, TUint32 aUsage, TBool aShareable, TSgCpuAccess aCpuAccess, RSgImage& aImage)
   1.395 +	{
   1.396 +	TSgImageInfo info;
   1.397 +	info.iSizeInPixels = TSize(aWidth, aHeight);
   1.398 +	info.iPixelFormat = aPixelFormat;
   1.399 +	info.iUsage = aUsage;
   1.400 +	info.iCpuAccess = aCpuAccess;
   1.401 +	info.iShareable = aShareable;
   1.402 +	return aImage.Create(info, NULL, 0);
   1.403 +	}
   1.404 +
   1.405 +/**
   1.406 +Creates an image collection with some predefined parametres.
   1.407 +@param aCollection output image collection handle
   1.408 +@return KErrNone if the image was created successfully, otherwise one of the system-wide error codes
   1.409 +*/
   1.410 +TInt CreateImageCollectionWithParameters(TInt aWidth, TInt aHeight, TUidPixelFormat aPixelFormat, TUint32 aUsage, TBool aShareable, TSgCpuAccess aCpuAccess, RSgImageCollection& aCollection)
   1.411 +	{
   1.412 +	TSgImageInfo info;
   1.413 +	info.iSizeInPixels = TSize(aWidth, aHeight);
   1.414 +	info.iPixelFormat = aPixelFormat;
   1.415 +	info.iUsage = aUsage;
   1.416 +	info.iCpuAccess = aCpuAccess;
   1.417 +	info.iShareable = aShareable;
   1.418 +	return aCollection.Create(info, KNumImagesInCollection);
   1.419 +	}
   1.420 +
   1.421 +
   1.422 +/**
   1.423 +Second thread entry function.
   1.424 +*/
   1.425 +TInt CTSgTestStepBase::SecondThreadStart(TAny* aInfo)
   1.426 +	{
   1.427 +	TInt procHandles1  =0;
   1.428 +	TInt threadHandles1=0;
   1.429 +	RThread().HandleCount(procHandles1, threadHandles1);
   1.430 +	__UHEAP_MARK;
   1.431 +	
   1.432 +	RSemaphore sem;
   1.433 +	TInt result = 0;
   1.434 +	
   1.435 +	TInt openSem = sem.OpenGlobal(KSecondThreadSemaphore, EOwnerThread);
   1.436 +	
   1.437 +	TSgresTestCase testcase = ((TSgresTestInfo*)aInfo)->iTestCase;
   1.438 +	
   1.439 +	RSgImage image;
   1.440 +	RSgDrawable drawable;
   1.441 +	TSgImageInfo info1;
   1.442 +	TSgImageInfo info2;
   1.443 +	TSgDrawableId id;
   1.444 +	const TAny* dataAddressRead;
   1.445 +	TAny* dataAddressWrite;
   1.446 +	TInt dataStride;
   1.447 +	TSgDrawableId fakeid = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
   1.448 +
   1.449 +	//test cases without the need of an initialised driver
   1.450 +	switch (testcase)
   1.451 +	{
   1.452 +	case ESgresSecondThreadPanicResourceCountNoDriver:
   1.453 +		{
   1.454 +		SgDriver::ResourceCount(); // should panic with SGRES 5
   1.455 +		}
   1.456 +		break;
   1.457 +	case ESgresSecondThreadPanicAllocMarkStartNoDriver:
   1.458 +		{
   1.459 +		SgDriver::AllocMarkStart(); // should panic with SGRES 5
   1.460 +		}
   1.461 +		break;
   1.462 +	case ESgresSecondThreadPanicAllocMarkEndNoDriver:
   1.463 +		{
   1.464 +		SgDriver::AllocMarkEnd(0); // should panic with SGRES 5
   1.465 +		}
   1.466 +		break;	
   1.467 +	case ESgresSecondThreadPanicSetAllocFailNoDriver:
   1.468 +		{
   1.469 +		SgDriver::SetAllocFail(RAllocator::EFailNext, 1); // should panic with SGRES 5
   1.470 +		}
   1.471 +		break;	
   1.472 +	case ESgresSecondThreadPanicDrawableOpenNoDriver:
   1.473 +		{
   1.474 +		drawable.Open(KSgNullDrawableId); // should panic with SGRES 5
   1.475 +		}
   1.476 +		break;
   1.477 +	case ESgresSecondThreadPanicImageOpenNoDriver1:
   1.478 +		{
   1.479 +		image.Open(KSgNullDrawableId); // should panic with SGRES 5
   1.480 +		}
   1.481 +		break;
   1.482 +	case ESgresSecondThreadPanicImageOpenNoDriver2:
   1.483 +		{
   1.484 +		image.Open(KSgNullDrawableId, ESgDoNotRestrictUsage); // should panic with SGRES 5
   1.485 +		}
   1.486 +		break;		
   1.487 +	case ESgresSecondThreadPanicImageCreateNoDriver1:
   1.488 +		{
   1.489 +		image.Create(info1, NULL, 0); // should panic with SGRES 5
   1.490 +		}
   1.491 +		break;
   1.492 +	case ESgresSecondThreadPanicImageCreateNoDriver2:
   1.493 +		{
   1.494 +		RSgImage tempImage;
   1.495 +		image.Create(info1, tempImage); // should panic with SGRES 5
   1.496 +		}
   1.497 +		break;
   1.498 +	case ESgresSecondThreadPanicImageGetPixelFormatsNoDriver:
   1.499 +		{
   1.500 +		TInt count = 0;
   1.501 +		RSgImage::GetPixelFormats(info1, NULL, count); // should panic with SGRES 5
   1.502 +		}
   1.503 +		break;
   1.504 +	case ESgresSecondThreadPanicImageCollectionCreateNoDriver1:
   1.505 +		{
   1.506 +		RSgImageCollection c;
   1.507 +		c.Create(info1, 0); // should panic with SGRES 5
   1.508 +		}
   1.509 +		break;
   1.510 +	case ESgresSecondThreadPanicImageCollectionCreateNoDriver2:
   1.511 +		{
   1.512 +		RSgImageCollection c;
   1.513 +		c.Create(NULL, 0, NULL, 0); // should panic with SGRES 5
   1.514 +		}
   1.515 +		break;
   1.516 +	}
   1.517 +	
   1.518 +	
   1.519 +	//open driver
   1.520 +	TInt ret = SgDriver::Open();
   1.521 +	if(KErrNoMemory == ret)
   1.522 +		{
   1.523 +		sem.Close();
   1.524 +		return KErrNoMemory;
   1.525 +		}
   1.526 +	if(KErrNone == ret)
   1.527 +		{			
   1.528 +		switch (testcase)
   1.529 +			{
   1.530 +			case ESgresSecondThreadOpenImage:
   1.531 +				{
   1.532 +				TInt err = image.Open(((TSgresTestInfo*)aInfo)->iDrawableId);
   1.533 +				if(KErrNoMemory == err)
   1.534 +					{
   1.535 +					result = KErrNoMemory;
   1.536 +					break;
   1.537 +					}
   1.538 +				if(KErrNone == err)
   1.539 +					{
   1.540 +					result |= EFirstTestPassed;
   1.541 +					}
   1.542 +				if(KErrNone == image.GetInfo(info2))
   1.543 +					{
   1.544 +					result |= ESecondTestPassed;
   1.545 +					}
   1.546 +				info1 = ((TSgresTestInfo*)aInfo)->iImageInfo;
   1.547 +				if(CompareInfos(info1, info2))
   1.548 +					{
   1.549 +					result |= EThirdTestPassed;
   1.550 +					}
   1.551 +				id = image.Id();
   1.552 +				if(id != KSgNullDrawableId)
   1.553 +					{
   1.554 +					result |= EFourthTestPassed;
   1.555 +					}
   1.556 +				if(id == ((TSgresTestInfo*)aInfo)->iDrawableId)
   1.557 +					{
   1.558 +					result |= EFifthTestPassed;
   1.559 +					}
   1.560 +				}					
   1.561 +				break;
   1.562 +			case ESgresSecondThreadOpenDrawable:
   1.563 +				{
   1.564 +				TInt err = drawable.Open(((TSgresTestInfo*)aInfo)->iDrawableId);
   1.565 +				if(KErrNoMemory == err)
   1.566 +					{
   1.567 +					result = KErrNoMemory;
   1.568 +					break;
   1.569 +					}
   1.570 +				if(KErrNone == err)
   1.571 +					{
   1.572 +					result |= EFirstTestPassed;
   1.573 +					}
   1.574 +				id = drawable.Id();
   1.575 +				if(id != KSgNullDrawableId)
   1.576 +					{
   1.577 +					result |= ESecondTestPassed;
   1.578 +					}
   1.579 +				if(id == ((TSgresTestInfo*)aInfo)->iDrawableId)
   1.580 +					{
   1.581 +					result |= EThirdTestPassed;
   1.582 +					}
   1.583 +				}
   1.584 +				break;
   1.585 +			case ESgresSecondThreadOpenImageInvalid:
   1.586 +				{
   1.587 +				TSgImageInfo info;
   1.588 +				info.iSizeInPixels = TSize(8, 8);
   1.589 +				info.iUsage = ESgUsageDirectGdiSource;
   1.590 +				info.iPixelFormat = EUidPixelFormatRGB_565;
   1.591 +				info.iCpuAccess = ESgCpuAccessReadWrite;
   1.592 +				
   1.593 +				TInt err = image.Create(info, KImageData, 16);
   1.594 +				if(KErrNoMemory == err)
   1.595 +					{
   1.596 +					result = KErrNoMemory;
   1.597 +					break;
   1.598 +					}
   1.599 +				if(KErrNone == err)
   1.600 +					{
   1.601 +					result |= EFirstTestPassed;
   1.602 +					}
   1.603 +				
   1.604 +				//  non-empty handle
   1.605 +				id = ((TSgresTestInfo*)aInfo)->iDrawableId;
   1.606 +				err = image.Open(id);
   1.607 +				if(KErrNoMemory == err)
   1.608 +					{
   1.609 +					result = KErrNoMemory;
   1.610 +					break;
   1.611 +					}
   1.612 +				if(KErrInUse == err)
   1.613 +					{
   1.614 +					result |= ESecondTestPassed;
   1.615 +					}
   1.616 +				image.Close();
   1.617 +				
   1.618 +				//  null drawable id	
   1.619 +				err = image.Open(KSgNullDrawableId);
   1.620 +				if(KErrNoMemory == err)
   1.621 +					{
   1.622 +					result = KErrNoMemory;
   1.623 +					break;
   1.624 +					}
   1.625 +				if(KErrArgument == err)
   1.626 +					{
   1.627 +					result |= EThirdTestPassed;
   1.628 +					}
   1.629 +				image.Close();
   1.630 +				
   1.631 +				//  non-existing drawable id
   1.632 +				err = image.Open(fakeid);
   1.633 +				if(KErrNoMemory == err)
   1.634 +					{
   1.635 +					result = KErrNoMemory;
   1.636 +					break;
   1.637 +					}
   1.638 +				if(KErrNotFound == err)
   1.639 +					{
   1.640 +					result |= EFourthTestPassed;
   1.641 +					}
   1.642 +				image.Close();
   1.643 +				
   1.644 +				//  open a non-sharable image
   1.645 +				err = image.Open(id);
   1.646 +				if(KErrNoMemory == err)
   1.647 +					{
   1.648 +					result = KErrNoMemory;
   1.649 +					break;
   1.650 +					}
   1.651 +				if(KErrNone == err)
   1.652 +					{
   1.653 +					result |= EFifthTestPassed;
   1.654 +					}
   1.655 +				image.Close();
   1.656 +				}
   1.657 +				break;
   1.658 +			case ESgresSecondThreadOpenDrawableInvalid:	
   1.659 +				//  null drawable id	
   1.660 +				{
   1.661 +				TInt err = drawable.Open(KSgNullDrawableId);
   1.662 +				if(KErrNoMemory == err)
   1.663 +					{
   1.664 +					result = KErrNoMemory;
   1.665 +					break;
   1.666 +					}
   1.667 +				if(KErrArgument == err)
   1.668 +					{
   1.669 +					result |= EFirstTestPassed;
   1.670 +					}
   1.671 +				drawable.Close();
   1.672 +				
   1.673 +				//  non-existing drawable id
   1.674 +				err = drawable.Open(fakeid);
   1.675 +				if(KErrNoMemory == err)
   1.676 +					{
   1.677 +					result = KErrNoMemory;
   1.678 +					break;
   1.679 +					}
   1.680 +				
   1.681 +				if(KErrNotFound == err)
   1.682 +					{
   1.683 +					result |= ESecondTestPassed;
   1.684 +					}
   1.685 +				drawable.Close();
   1.686 +				
   1.687 +				//  open a non-sharable image - should succeed
   1.688 +				id = ((TSgresTestInfo*)aInfo)->iDrawableId;
   1.689 +				err = drawable.Open(id);
   1.690 +				if(KErrNoMemory == err)
   1.691 +					{
   1.692 +					result = KErrNoMemory;
   1.693 +					break;
   1.694 +					}
   1.695 +				if(KErrNone == err)
   1.696 +					{
   1.697 +					result |= EThirdTestPassed;
   1.698 +					}
   1.699 +									
   1.700 +				//  non-empty handle
   1.701 +				if(KErrInUse == drawable.Open(id))
   1.702 +					{
   1.703 +					result |= EFourthTestPassed;
   1.704 +					}
   1.705 +				drawable.Close();
   1.706 +				}
   1.707 +				break;
   1.708 +			case ESgresSecondThreadMapImage:
   1.709 +				{
   1.710 +				id = ((TSgresTestInfo*)aInfo)->iDrawableId;
   1.711 +				TInt err = image.Open(id);		
   1.712 +				if(KErrNoMemory == err)
   1.713 +					{
   1.714 +					result = KErrNoMemory;
   1.715 +					break;
   1.716 +					}
   1.717 +				if(KErrNone == err)
   1.718 +					{
   1.719 +					result |= EFirstTestPassed;
   1.720 +					}
   1.721 +				if(KErrNone == image.MapReadOnly(dataAddressRead, dataStride))
   1.722 +					{
   1.723 +					result |= ESecondTestPassed;
   1.724 +					}
   1.725 +				if(KErrNone == image.Unmap())
   1.726 +					{
   1.727 +					result |= EThirdTestPassed;
   1.728 +					}
   1.729 +				if(KErrNone == image.MapWriteOnly(dataAddressWrite, dataStride))
   1.730 +					{
   1.731 +					result |= EFourthTestPassed;
   1.732 +					}
   1.733 +				if(KErrNone == image.Unmap())
   1.734 +					{
   1.735 +					result |= EFifthTestPassed;
   1.736 +					}
   1.737 +				if(KErrNone == image.MapReadWrite(dataAddressWrite, dataStride))
   1.738 +					{
   1.739 +					result |= ESixthTestPassed;
   1.740 +					}
   1.741 +				if(KErrNone == image.Unmap())
   1.742 +					{
   1.743 +					result |= ESeventhTestPassed;
   1.744 +					}
   1.745 +				}					
   1.746 +				break;
   1.747 +			case ESgresSecondThreadUnmapImage:
   1.748 +				{
   1.749 +				id = ((TSgresTestInfo*)aInfo)->iDrawableId;
   1.750 +				TInt err = image.Open(id);
   1.751 +				if(KErrNoMemory == err)
   1.752 +					{
   1.753 +					result = KErrNoMemory;
   1.754 +					break;
   1.755 +					}
   1.756 +				if(KErrNone == err)
   1.757 +					{
   1.758 +					result |= EFirstTestPassed;
   1.759 +					}
   1.760 +				if(KErrNone == image.Unmap())
   1.761 +					{
   1.762 +					result |= ESecondTestPassed;
   1.763 +					}
   1.764 +				}					
   1.765 +				break;
   1.766 +			case ESgresSecondThreadPanicImageGetInterfaceInvalidHandle:
   1.767 +				{
   1.768 +				RSgImage image;	
   1.769 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.770 +				if(KErrNone != ret)
   1.771 +					{
   1.772 +					result = ret;
   1.773 +					break;
   1.774 +					}					
   1.775 +				RSgImage anotherImage;
   1.776 +				anotherImage = image;
   1.777 +				image.Close();
   1.778 +				
   1.779 +				MSgImage_Sw* swInterface = NULL;
   1.780 +				ret = anotherImage.GetInterface(swInterface); //should panic with SGRES 2
   1.781 +				SgDriver::Close();
   1.782 +				}
   1.783 +				break;
   1.784 +			case ESgresSecondThreadPanicImageGetInterfaceNoDriver:
   1.785 +				{
   1.786 +				RSgImage image;	
   1.787 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.788 +				if(KErrNone != ret)
   1.789 +					{
   1.790 +					result = ret;
   1.791 +					break;
   1.792 +					}					
   1.793 +				RSgImage anotherImage;
   1.794 +				anotherImage = image;
   1.795 +				image.Close();
   1.796 +				
   1.797 +				SgDriver::Close();
   1.798 +				MSgImage_Sw* swInterface = NULL;
   1.799 +				anotherImage.GetInterface(swInterface); // should panic with SGRES 5
   1.800 +				}
   1.801 +				break;
   1.802 +			case ESgresSecondThreadPanicImageCloseInvalidHandle:
   1.803 +				{
   1.804 +				RSgImage image;	
   1.805 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.806 +				if(KErrNone != ret)
   1.807 +					{
   1.808 +					result = ret;
   1.809 +					break;
   1.810 +					}					
   1.811 +				RSgImage anotherImage;
   1.812 +				anotherImage = image;
   1.813 +				image.Close();
   1.814 +				
   1.815 +				anotherImage.Close(); //should panic with SGRES 2
   1.816 +				SgDriver::Close();
   1.817 +				}
   1.818 +				break;
   1.819 +			case ESgresSecondThreadPanicImageCloseNoDriver:
   1.820 +				{
   1.821 +				RSgImage image;	
   1.822 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.823 +				if(KErrNone != ret)
   1.824 +					{
   1.825 +					result = ret;
   1.826 +					break;
   1.827 +					}					
   1.828 +				RSgImage anotherImage;
   1.829 +				anotherImage = image;
   1.830 +				image.Close();
   1.831 +				SgDriver::Close();
   1.832 +				anotherImage.Close(); // should panic with SGRES 5					
   1.833 +				}
   1.834 +				break;
   1.835 +			case ESgresSecondThreadPanicImageIdInvalidHandle:
   1.836 +				{
   1.837 +				RSgImage image;	
   1.838 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.839 +				if(KErrNone != ret)
   1.840 +					{
   1.841 +					result = ret;
   1.842 +					break;
   1.843 +					}					
   1.844 +				RSgImage anotherImage;
   1.845 +				anotherImage = image;
   1.846 +				image.Close();
   1.847 +				
   1.848 +				anotherImage.Id(); //should panic with SGRES 2
   1.849 +				SgDriver::Close();
   1.850 +				}
   1.851 +				break;
   1.852 +			case ESgresSecondThreadPanicImageIdNoDriver:
   1.853 +				{
   1.854 +				RSgImage image;	
   1.855 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.856 +				if(KErrNone != ret)
   1.857 +					{
   1.858 +					result = ret;
   1.859 +					break;
   1.860 +					}					
   1.861 +				RSgImage anotherImage;
   1.862 +				anotherImage = image;
   1.863 +				image.Close();
   1.864 +				SgDriver::Close();					
   1.865 +				anotherImage.Id(); // should panic with SGRES 5
   1.866 +				}
   1.867 +				break;
   1.868 +			case ESgresSecondThreadPanicImageDrawableTypeInvalidHandle:
   1.869 +				{
   1.870 +				RSgImage image;	
   1.871 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.872 +				if(KErrNone != ret)
   1.873 +					{
   1.874 +					result = ret;
   1.875 +					break;
   1.876 +					}					
   1.877 +				RSgImage anotherImage;
   1.878 +				anotherImage = image;
   1.879 +				image.Close();
   1.880 +				
   1.881 +				anotherImage.DrawableType(); //should panic with SGRES 2
   1.882 +				SgDriver::Close();
   1.883 +				}
   1.884 +				break;
   1.885 +			case ESgresSecondThreadPanicImageDrawableTypeNoDriver:
   1.886 +				{
   1.887 +				RSgImage image;	
   1.888 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.889 +				if(KErrNone != ret)
   1.890 +					{
   1.891 +					result = ret;
   1.892 +					break;
   1.893 +					}					
   1.894 +				RSgImage anotherImage;
   1.895 +				anotherImage = image;
   1.896 +				image.Close();
   1.897 +				SgDriver::Close();					
   1.898 +				anotherImage.DrawableType(); // should panic with SGRES 5
   1.899 +				}
   1.900 +				break;	
   1.901 +			case ESgresSecondThreadPanicImageCreateInvalidHandle:
   1.902 +				{
   1.903 +				RSgImage image;	
   1.904 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.905 +				if(KErrNone != ret)
   1.906 +					{
   1.907 +					result = ret;
   1.908 +					break;
   1.909 +					}					
   1.910 +				RSgImage anotherImage;
   1.911 +				anotherImage = image;
   1.912 +				image.Close();
   1.913 +				
   1.914 +				RSgImage newImage;
   1.915 +				TSgImageInfo info;
   1.916 +				image.GetInfo(info);
   1.917 +				newImage.Create(info, anotherImage); //should panic with SGRES 3
   1.918 +				SgDriver::Close();
   1.919 +				}
   1.920 +				break;
   1.921 +			case ESgresSecondThreadPanicImageGetInfoInvalidHandle:
   1.922 +				{
   1.923 +				RSgImage image;	
   1.924 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.925 +				if(KErrNone != ret)
   1.926 +					{
   1.927 +					result = ret;
   1.928 +					break;
   1.929 +					}					
   1.930 +				RSgImage anotherImage;
   1.931 +				anotherImage = image;
   1.932 +				image.Close();
   1.933 +				
   1.934 +				TSgImageInfo anotherInfo;
   1.935 +				anotherImage.GetInfo(anotherInfo); //should panic with SGRES 3
   1.936 +				SgDriver::Close();
   1.937 +				}
   1.938 +				break;
   1.939 +			case ESgresSecondThreadPanicImageGetInfoNoDriver:
   1.940 +				{
   1.941 +				RSgImage image;	
   1.942 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.943 +				if(KErrNone != ret)
   1.944 +					{
   1.945 +					result = ret;
   1.946 +					break;
   1.947 +					}					
   1.948 +				RSgImage anotherImage;
   1.949 +				anotherImage = image;
   1.950 +				image.Close();
   1.951 +				SgDriver::Close();
   1.952 +				TSgImageInfo anotherInfo;
   1.953 +				anotherImage.GetInfo(anotherInfo); // should panic with SGRES 5
   1.954 +				}
   1.955 +				break;
   1.956 +			case ESgresSecondThreadPanicImageMapReadOnlyInvalidHandle:
   1.957 +				{
   1.958 +				RSgImage image;	
   1.959 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.960 +				if(KErrNone != ret)
   1.961 +					{
   1.962 +					result = ret;
   1.963 +					break;
   1.964 +					}					
   1.965 +				RSgImage anotherImage;
   1.966 +				anotherImage = image;
   1.967 +				image.Close();
   1.968 +				
   1.969 +				anotherImage.MapReadOnly(dataAddressRead, dataStride); //should panic with SGRES 3
   1.970 +				SgDriver::Close();
   1.971 +				}
   1.972 +				break;
   1.973 +			case ESgresSecondThreadPanicImageMapReadOnlyNoDriver:
   1.974 +				{
   1.975 +				RSgImage image;	
   1.976 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.977 +				if(KErrNone != ret)
   1.978 +					{
   1.979 +					result = ret;
   1.980 +					break;
   1.981 +					}					
   1.982 +				RSgImage anotherImage;
   1.983 +				anotherImage = image;
   1.984 +				image.Close();
   1.985 +				SgDriver::Close();
   1.986 +				anotherImage.MapReadOnly(dataAddressRead, dataStride); // should panic with SGRES 5
   1.987 +				}
   1.988 +				break;
   1.989 +			case ESgresSecondThreadPanicImageMapWriteOnlyInvalidHandle:
   1.990 +				{
   1.991 +				RSgImage image;	
   1.992 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
   1.993 +				if(KErrNone != ret)
   1.994 +					{
   1.995 +					result = ret;
   1.996 +					break;
   1.997 +					}					
   1.998 +				RSgImage anotherImage;
   1.999 +				anotherImage = image;
  1.1000 +				image.Close();
  1.1001 +				
  1.1002 +				anotherImage.MapWriteOnly(dataAddressWrite, dataStride); //should panic with SGRES 3
  1.1003 +				SgDriver::Close();
  1.1004 +				}
  1.1005 +				break;
  1.1006 +			case ESgresSecondThreadPanicImageMapWriteOnlyNoDriver:
  1.1007 +				{
  1.1008 +				RSgImage image;	
  1.1009 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
  1.1010 +				if(KErrNone != ret)
  1.1011 +					{
  1.1012 +					result = ret;
  1.1013 +					break;
  1.1014 +					}					
  1.1015 +				RSgImage anotherImage;
  1.1016 +				anotherImage = image;
  1.1017 +				image.Close();
  1.1018 +				SgDriver::Close();					
  1.1019 +				anotherImage.MapWriteOnly(dataAddressWrite, dataStride); // should panic with SGRES 5
  1.1020 +				}
  1.1021 +				break;
  1.1022 +			case ESgresSecondThreadPanicImageMapReadWriteInvalidHandle:
  1.1023 +				{
  1.1024 +				RSgImage image;	
  1.1025 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
  1.1026 +				if(KErrNone != ret)
  1.1027 +					{
  1.1028 +					result = ret;
  1.1029 +					break;
  1.1030 +					}					
  1.1031 +				RSgImage anotherImage;
  1.1032 +				anotherImage = image;
  1.1033 +				image.Close();
  1.1034 +				
  1.1035 +				anotherImage.MapReadWrite(dataAddressWrite, dataStride); //should panic with SGRES 3
  1.1036 +				SgDriver::Close();
  1.1037 +				}
  1.1038 +				break;
  1.1039 +			case ESgresSecondThreadPanicImageMapReadWriteNoDriver:
  1.1040 +				{
  1.1041 +				RSgImage image;	
  1.1042 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
  1.1043 +				if(KErrNone != ret)
  1.1044 +					{
  1.1045 +					result = ret;
  1.1046 +					break;
  1.1047 +					}					
  1.1048 +				RSgImage anotherImage;
  1.1049 +				anotherImage = image;
  1.1050 +				image.Close();
  1.1051 +				SgDriver::Close();					
  1.1052 +				anotherImage.MapReadWrite(dataAddressWrite, dataStride); // should panic with SGRES 5
  1.1053 +				}
  1.1054 +				break;
  1.1055 +			case ESgresSecondThreadPanicImageUnmapInvalidHandle:
  1.1056 +				{
  1.1057 +				RSgImage image;	
  1.1058 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
  1.1059 +				if(KErrNone != ret)
  1.1060 +					{
  1.1061 +					result = ret;
  1.1062 +					break;
  1.1063 +					}					
  1.1064 +				RSgImage anotherImage;
  1.1065 +				anotherImage = image;
  1.1066 +				image.Close();
  1.1067 +				
  1.1068 +				anotherImage.Unmap(); //should panic with SGRES 3
  1.1069 +				SgDriver::Close();
  1.1070 +				}
  1.1071 +				break;
  1.1072 +			case ESgresSecondThreadPanicImageUnmapNoDriver:
  1.1073 +				{
  1.1074 +				RSgImage image;	
  1.1075 +				TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
  1.1076 +				if(KErrNone != ret)
  1.1077 +					{
  1.1078 +					result = ret;
  1.1079 +					break;
  1.1080 +					}					
  1.1081 +				RSgImage anotherImage;
  1.1082 +				anotherImage = image;
  1.1083 +				image.Close();
  1.1084 +				SgDriver::Close();
  1.1085 +				anotherImage.Unmap(); // should panic with SGRES 5
  1.1086 +				}
  1.1087 +				break;
  1.1088 +			case ESgresSecondThreadPanicImageCollectionCloseInvalidHandle:
  1.1089 +				{
  1.1090 +				RSgImageCollection collection;
  1.1091 +				TInt ret = CreateImageCollectionWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, EFalse, ESgCpuAccessReadWrite, collection);
  1.1092 +				if(KErrNone != ret)
  1.1093 +					{
  1.1094 +					result = ret;
  1.1095 +					break;
  1.1096 +					}
  1.1097 +				
  1.1098 +				RSgImageCollection anotherCollection;
  1.1099 +				anotherCollection = collection;
  1.1100 +				collection.Close();
  1.1101 +				anotherCollection.Close(); //should panic with SGRES 4
  1.1102 +				SgDriver::Close();
  1.1103 +				}
  1.1104 +				break;
  1.1105 +			case ESgresSecondThreadPanicImageCollectionCloseNoDriver:
  1.1106 +				{
  1.1107 +				RSgImageCollection collection;
  1.1108 +				TInt ret = CreateImageCollectionWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, EFalse, ESgCpuAccessReadWrite, collection);
  1.1109 +				if(KErrNone != ret)
  1.1110 +					{
  1.1111 +					result = ret;
  1.1112 +					break;
  1.1113 +					}
  1.1114 +				
  1.1115 +				RSgImageCollection anotherCollection;
  1.1116 +				anotherCollection = collection;
  1.1117 +				collection.Close();
  1.1118 +				SgDriver::Close();
  1.1119 +				anotherCollection.Close(); // should panic with SGRES 5
  1.1120 +				}
  1.1121 +				break;
  1.1122 +			case ESgresSecondThreadPanicImageCollectionSurfaceIdInvalidHandle:
  1.1123 +				{
  1.1124 +				RSgImageCollection collection;
  1.1125 +				TInt ret = CreateImageCollectionWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, EFalse, ESgCpuAccessReadWrite, collection);
  1.1126 +				if(KErrNone != ret)
  1.1127 +					{
  1.1128 +					result = ret;
  1.1129 +					break;
  1.1130 +					}
  1.1131 +				
  1.1132 +				RSgImageCollection anotherCollection;
  1.1133 +				anotherCollection = collection;
  1.1134 +				collection.Close();
  1.1135 +				anotherCollection.SurfaceId(); //should panic with SGRES 4
  1.1136 +				SgDriver::Close();
  1.1137 +				}
  1.1138 +				break;
  1.1139 +			case ESgresSecondThreadPanicImageCollectionSurfaceIdNoDriver:
  1.1140 +				{
  1.1141 +				RSgImageCollection collection;
  1.1142 +				TInt ret = CreateImageCollectionWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, EFalse, ESgCpuAccessReadWrite, collection);
  1.1143 +				if(KErrNone != ret)
  1.1144 +					{
  1.1145 +					result = ret;
  1.1146 +					break;
  1.1147 +					}
  1.1148 +				
  1.1149 +				RSgImageCollection anotherCollection;
  1.1150 +				anotherCollection = collection;
  1.1151 +				collection.Close();
  1.1152 +				SgDriver::Close();
  1.1153 +				anotherCollection.SurfaceId(); // should panic with SGRES 5
  1.1154 +				}
  1.1155 +				break;
  1.1156 +			case ESgresSecondThreadPanicImageCollectionGetInfoInvalidHandle:
  1.1157 +				{
  1.1158 +				RSgImageCollection collection;
  1.1159 +				TInt ret = CreateImageCollectionWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, EFalse, ESgCpuAccessReadWrite, collection);
  1.1160 +				if(KErrNone != ret)
  1.1161 +					{
  1.1162 +					result = ret;
  1.1163 +					break;
  1.1164 +					}
  1.1165 +				
  1.1166 +				RSgImageCollection anotherCollection;
  1.1167 +				anotherCollection = collection;
  1.1168 +				collection.Close();
  1.1169 +				TSgImageInfo anotherInfo;
  1.1170 +				anotherCollection.GetInfo(anotherInfo); //should panic with SGRES 4
  1.1171 +				SgDriver::Close();
  1.1172 +				}
  1.1173 +				break;
  1.1174 +			case ESgresSecondThreadPanicImageCollectionGetInfoNoDriver:
  1.1175 +				{
  1.1176 +				RSgImageCollection collection;
  1.1177 +				TInt ret = CreateImageCollectionWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, EFalse, ESgCpuAccessReadWrite, collection);
  1.1178 +				if(KErrNone != ret)
  1.1179 +					{
  1.1180 +					result = ret;
  1.1181 +					break;
  1.1182 +					}
  1.1183 +				
  1.1184 +				RSgImageCollection anotherCollection;
  1.1185 +				anotherCollection = collection;
  1.1186 +				collection.Close();
  1.1187 +				TSgImageInfo anotherInfo;
  1.1188 +				SgDriver::Close();
  1.1189 +				anotherCollection.GetInfo(anotherInfo); // should panic with SGRES 5
  1.1190 +				}
  1.1191 +				break;
  1.1192 +			case ESgresSecondThreadPanicImageCollectionCountInvalidHandle:
  1.1193 +				{
  1.1194 +				RSgImageCollection collection;
  1.1195 +				TInt ret = CreateImageCollectionWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, EFalse, ESgCpuAccessReadWrite, collection);
  1.1196 +				if(KErrNone != ret)
  1.1197 +					{
  1.1198 +					result = ret;
  1.1199 +					break;
  1.1200 +					}
  1.1201 +				
  1.1202 +				RSgImageCollection anotherCollection;
  1.1203 +				anotherCollection = collection;
  1.1204 +				collection.Close();
  1.1205 +				anotherCollection.Count(); //should panic with SGRES 4
  1.1206 +				SgDriver::Close();
  1.1207 +				}
  1.1208 +				break;
  1.1209 +			case ESgresSecondThreadPanicImageCollectionCountNoDriver:
  1.1210 +				{
  1.1211 +				RSgImageCollection collection;
  1.1212 +				TInt ret = CreateImageCollectionWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, EFalse, ESgCpuAccessReadWrite, collection);
  1.1213 +				if(KErrNone != ret)
  1.1214 +					{
  1.1215 +					result = ret;
  1.1216 +					break;
  1.1217 +					}
  1.1218 +				
  1.1219 +				RSgImageCollection anotherCollection;
  1.1220 +				anotherCollection = collection;
  1.1221 +				collection.Close();
  1.1222 +				SgDriver::Close();
  1.1223 +				anotherCollection.Count(); // should panic with SGRES 5
  1.1224 +				}
  1.1225 +				break;
  1.1226 +			case ESgresSecondThreadPanicImageCollectionOpenImageInvalidHandle:
  1.1227 +				{
  1.1228 +				RSgImageCollection collection;
  1.1229 +				TInt ret = CreateImageCollectionWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, EFalse, ESgCpuAccessReadWrite, collection);
  1.1230 +				if(KErrNone != ret)
  1.1231 +					{
  1.1232 +					result = ret;
  1.1233 +					break;
  1.1234 +					}
  1.1235 +				
  1.1236 +				RSgImageCollection anotherCollection;
  1.1237 +				anotherCollection = collection;
  1.1238 +				collection.Close();
  1.1239 +				RSgImage image;
  1.1240 +				anotherCollection.OpenImage(0, image); //should panic with SGRES 4
  1.1241 +				SgDriver::Close();
  1.1242 +				}
  1.1243 +				break;
  1.1244 +			case ESgresSecondThreadPanicImageCollectionOpenImageNoDriver:
  1.1245 +				{
  1.1246 +				RSgImageCollection collection;
  1.1247 +				TInt ret = CreateImageCollectionWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, EFalse, ESgCpuAccessReadWrite, collection);
  1.1248 +				if(KErrNone != ret)
  1.1249 +					{
  1.1250 +					result = ret;
  1.1251 +					break;
  1.1252 +					}
  1.1253 +				
  1.1254 +				RSgImageCollection anotherCollection;
  1.1255 +				anotherCollection = collection;
  1.1256 +				collection.Close();
  1.1257 +				RSgImage image;
  1.1258 +				SgDriver::Close();
  1.1259 +				anotherCollection.OpenImage(0, image); // should panic with SGRES 5
  1.1260 +				}
  1.1261 +				break;
  1.1262 +			case ESgresMultipleThreadStressTest:
  1.1263 +				{
  1.1264 +				for (TInt i = 0; i < 1000 && result == KErrNone; ++i)
  1.1265 +					{
  1.1266 +					TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageDirectGdiSource, ETrue, ESgCpuAccessReadWrite, image);
  1.1267 +					if (KErrNone != ret)
  1.1268 +						{
  1.1269 +						result = ret;
  1.1270 +						break;
  1.1271 +						}
  1.1272 +					const TInt KMaxOpenCount = 100;
  1.1273 +					RSgImage images[KMaxOpenCount];
  1.1274 +					TInt count = Math::Random() % KMaxOpenCount;
  1.1275 +					for (TInt k = 0; k < count; ++k)
  1.1276 +						{
  1.1277 +						ret = images[k].Open(((TSgresTestInfo*)aInfo)->iDrawableId);
  1.1278 +						if (KErrNone != ret)
  1.1279 +							{
  1.1280 +							result = ret;
  1.1281 +							break;
  1.1282 +							}
  1.1283 +						}
  1.1284 +					image.Close();
  1.1285 +					for (TInt k = 0; k < count; ++k)
  1.1286 +						{
  1.1287 +						images[k].Close();
  1.1288 +						}
  1.1289 +					}
  1.1290 +				}
  1.1291 +				break;
  1.1292 +			};
  1.1293 +		}
  1.1294 +	image.Close();
  1.1295 +	drawable.Close();
  1.1296 +	SgDriver::Close();
  1.1297 +	if (KErrNone == openSem)
  1.1298 +		{
  1.1299 +		sem.Signal();
  1.1300 +		}
  1.1301 +	__UHEAP_MARKEND;
  1.1302 +	sem.Close();	
  1.1303 +	TInt procHandles2  =0;
  1.1304 +	TInt threadHandles2=0;
  1.1305 +	RThread().HandleCount(procHandles2,threadHandles2);
  1.1306 +	if (threadHandles1 != threadHandles2)
  1.1307 +		{
  1.1308 +		result = KErrGeneral;  // Thread-owned handles not closed
  1.1309 +		}
  1.1310 +
  1.1311 +	return result;
  1.1312 +	}
  1.1313 +
  1.1314 +/**
  1.1315 +Static function used by the cleanup item to close the driver.
  1.1316 +*/
  1.1317 +void CTSgTestStepBase::CloseDriverWhenLeave(TAny* /*aInfo*/)
  1.1318 +	{
  1.1319 +	SgDriver::Close();
  1.1320 +	}
  1.1321 +
  1.1322 +/**
  1.1323 +Checks the function for the passed error codes and logs an error if the codes do not match. 
  1.1324 +If the test is running out of memory tests, KErrNoMemory is also an expected error code and 
  1.1325 +the function would just leave with KErrNoMemory in that case.
  1.1326 +
  1.1327 +@param aExpectedErrorCode The expected error code to check against
  1.1328 +@param aActualErrorCode The actual error code
  1.1329 +@param aFile The filename to use when reporting the error
  1.1330 +@param aLine The line number to use when reporting the error
  1.1331 +*/
  1.1332 +void CTSgTestStepBase::CheckErrorL(TInt aExpectedErrorCode, TInt aActualErrorCode, const TText8* aFile, TInt aLine)
  1.1333 +	{
  1.1334 +	if(iRunningOomTests && KErrNoMemory == aActualErrorCode)
  1.1335 +		{
  1.1336 +		User::Leave(KErrNoMemory);
  1.1337 +		}
  1.1338 +	TESTWITHFILENAMEANDLINENUMBERL(aExpectedErrorCode == aActualErrorCode, aFile, aLine);
  1.1339 +	}
  1.1340 +
  1.1341 +/**
  1.1342 +Out of memory tests.
  1.1343 +*/
  1.1344 +void CTSgTestStepBase::TestOOM()
  1.1345 +	{
  1.1346 +	SgDriver::Open();
  1.1347 +	TInt err = KErrNone;
  1.1348 +	TInt tryCount = 0;
  1.1349 +	iRunningOomTests = ETrue;
  1.1350 +	do
  1.1351 +		{
  1.1352 +		SgDriver::SetAllocFail(RAllocator::EFailNext, ++tryCount);
  1.1353 +		TRAP(err, DoMemoryTestsL());
  1.1354 +		} 
  1.1355 +	while(err == KErrNoMemory);
  1.1356 +	
  1.1357 +	SgDriver::SetAllocFail(RAllocator::ENone, 0);
  1.1358 +	iRunningOomTests = EFalse;
  1.1359 +	SgDriver::Close();
  1.1360 +	INFO_PRINTF2(_L("- server succeeded at private heap failure rate of %i\n"), tryCount);
  1.1361 +	}
  1.1362 +
  1.1363 +/**
  1.1364 +Specifies which functions to run in out of memory conditions.
  1.1365 +To be overridden by the derived test classes.
  1.1366 +*/
  1.1367 +void CTSgTestStepBase::DoMemoryTestsL()
  1.1368 +	{
  1.1369 +	}