graphicsresourceservices/graphicsresourceimplementation/test/src/tgraphicsresourceteststepbase.cpp
changeset 36 01a6848ebfd7
child 103 2717213c588a
equal deleted inserted replaced
0:5d03bc08d59c 36:01a6848ebfd7
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Graphics Resource API Conformance Test Suite
       
    20 */
       
    21 
       
    22 #include "tgraphicsresourceteststepbase.h"
       
    23 #include <e32math.h>
       
    24 
       
    25 CTSgTestStepBase::CTSgTestStepBase(TBool aConformanceTests) :
       
    26 	iEnableConformanceTests(aConformanceTests)
       
    27 	{
       
    28 	}
       
    29 
       
    30 CTSgTestStepBase::~CTSgTestStepBase()
       
    31 	{
       
    32 	iSecondThread.Close();
       
    33 	iPixelFormatArray.Close();
       
    34 	User::Free(iDiagonalImageData);
       
    35 	iSgDriver.Close();
       
    36 	}
       
    37 
       
    38 /**
       
    39 Overrides of base class virtual
       
    40 @leave Gets system wide error code
       
    41 @return - TVerdict code
       
    42 */
       
    43 TVerdict CTSgTestStepBase::doTestStepPreambleL()
       
    44 	{
       
    45 	// Set the logger to shared so that secondary threads can write to the log
       
    46 	User::LeaveIfError(Logger().ShareAuto());	
       
    47 	SetTestStepResult(EPass);
       
    48 	iDiagonalImageData = static_cast<TUint32*>(User::AllocL(KDiagonalImageSize * KDiagonalImageDataStride));
       
    49 	// Populate iDiagonalImageData with green diagonal from top-left to bottom-right on white background
       
    50 	Mem::Fill(iDiagonalImageData, KDiagonalImageSize * KDiagonalImageDataStride, 0xFF);
       
    51 	for (TInt i = 0; i < KDiagonalImageSize; ++i)
       
    52 		{
       
    53 		iDiagonalImageData[i * (KDiagonalImageSize + 1)] = 0xFF00FF00;
       
    54 		}
       
    55 	return TestStepResult();
       
    56 	}
       
    57 
       
    58 /**
       
    59 Override of base class virtual
       
    60 @leave Gets system wide error code
       
    61 @return - TVerdict code
       
    62 */
       
    63 TVerdict CTSgTestStepBase::doTestStepPostambleL()
       
    64 	{
       
    65 	User::Free(iDiagonalImageData);
       
    66 	iDiagonalImageData = NULL;
       
    67 	return TestStepResult();
       
    68 	}
       
    69 
       
    70 /**
       
    71 Creates an image with some predefined parameters.
       
    72 @param aImage output image handle
       
    73 @leave Gets system wide error code
       
    74 */
       
    75 void CTSgTestStepBase::CreateImageL(RSgImage& aImage)
       
    76 	{
       
    77 	TSgImageInfo info;
       
    78 	info.iSizeInPixels = TSize(8, 8);
       
    79 	info.iUsage = ESgUsageBitOpenVgImage;
       
    80 	info.iPixelFormat = EUidPixelFormatRGB_565;
       
    81 	
       
    82 	CheckErrorL(KErrNone, aImage.Create(info, KCrossImageData, KCrossImageDataStride), (TText8*)__FILE__, __LINE__);
       
    83 	}
       
    84 
       
    85 /**
       
    86 Creates a second process and do some tests in it.
       
    87 @param aProcessName The name of the new process
       
    88 @param aTestInfo The information for the tests
       
    89 @return A bitwise mask of test passes (never an error code)
       
    90 @leave Gets system wide error code
       
    91 */
       
    92 TInt CTSgTestStepBase::CreateSecondProcessAndDoTestL(const TDesC &aProcessName, TSgProcessTestInfo& aTestInfo)
       
    93 	{
       
    94 	// Create a second process
       
    95 	RProcess process;
       
    96 	TInt err = process.Create(aProcessName, KNullDesC);
       
    97 	User::LeaveIfError(err);
       
    98 	CleanupClosePushL(process);
       
    99 
       
   100 	// Specify the id passed to the second process
       
   101 	TPckg<TSgProcessTestInfo> ptr(aTestInfo);
       
   102 	TESTL(KErrNone == process.SetParameter(KSecondProcessParametersSlot, ptr));
       
   103 	
       
   104 	// Kick off the second process and wait for it to complete
       
   105 	// The actual testing is done in the second process
       
   106 	TRequestStatus status = KRequestPending;
       
   107 	process.Logon(status);
       
   108 	process.Resume();
       
   109 	User::WaitForRequest(status);
       
   110 
       
   111 	// exitreason could either be a negative error code or a bitwise
       
   112 	// mask of test passes.
       
   113 	TInt exitreason = process.ExitReason();
       
   114 	
       
   115 	CleanupStack::PopAndDestroy();
       
   116 	
       
   117 	if (exitreason < KErrNone)
       
   118 		{
       
   119 		INFO_PRINTF2(_L("The second process returned error code %d"), exitreason);
       
   120 		TEST(EFalse);
       
   121 		exitreason = 0;
       
   122 		}
       
   123 	//return test result
       
   124 	return exitreason;
       
   125 	}
       
   126 
       
   127 /**
       
   128 Creates a second process, runs the requested test and ensures that
       
   129 the specified panic occurs.
       
   130 
       
   131 @param aTestInfo The specification for this test
       
   132 @param aPanicCode The expected panic code
       
   133 @param aExitCategory The expected panic category
       
   134 @param aProcessName The name of the new process
       
   135 
       
   136 @leave One of the system wide error codes
       
   137 */
       
   138 void CTSgTestStepBase::CreateSecondProcessAndCheckPanicL(TSgProcessTestInfo& aTestInfo, TInt aPanicCode, TExitCategoryName aExitCategory, const TDesC &aProcessName)
       
   139 	{
       
   140 	// Create a second process
       
   141 	RProcess process;
       
   142 	User::LeaveIfError(process.Create(aProcessName, KNullDesC));
       
   143 	CleanupClosePushL(process);
       
   144 
       
   145 	// Specify the id passed to the second process
       
   146 	TPckg<TSgProcessTestInfo> ptr(aTestInfo);
       
   147 	TESTL(KErrNone == process.SetParameter(KSecondProcessParametersSlot, ptr));
       
   148 	
       
   149 	// Kick off the second process and wait for it to complete
       
   150 	// The actual testing is done in the second process
       
   151 	TRequestStatus status = KRequestPending;
       
   152 	process.Logon(status);
       
   153 	process.Resume();
       
   154 	User::WaitForRequest(status);
       
   155 	
       
   156 	if(EExitPanic != process.ExitType())
       
   157 		{
       
   158 		ERR_PRINTF3(_L("Expected exit type: %d, Actual exit type: %d"), EExitPanic, process.ExitType());
       
   159 		TEST(EFalse);
       
   160 		}
       
   161 	
       
   162 	if(aPanicCode != process.ExitReason())
       
   163 		{
       
   164 		ERR_PRINTF3(_L("Expected panic code: %d, Actual panic code: %d"), aPanicCode, process.ExitReason());
       
   165 		TEST(EFalse);
       
   166 		}
       
   167 	
       
   168 	TExitCategoryName secondProcessExitCategory = process.ExitCategory();
       
   169 	if(aExitCategory != secondProcessExitCategory)
       
   170 		{
       
   171 		ERR_PRINTF3(_L("Expected panic category: %S, Actual panic category: %S"), &aExitCategory, &secondProcessExitCategory);
       
   172 		TEST(EFalse);
       
   173 		}
       
   174 	
       
   175 	CleanupStack::PopAndDestroy();
       
   176 	}
       
   177 
       
   178 /**
       
   179 Creates a second thread and do some tests in it.
       
   180 @param aTestInfo The information for the tests
       
   181 @leave Gets system wide error code
       
   182 */
       
   183 TInt CTSgTestStepBase::CreateSecondThreadAndDoTestL(TSgThreadTestInfo aTestInfo)
       
   184 	{
       
   185 	//create a semaphore
       
   186 	RSemaphore sem;
       
   187 	User::LeaveIfError(sem.CreateGlobal(KSecondThreadSemaphore, 0, EOwnerThread));
       
   188 	CleanupClosePushL(sem);
       
   189 	
       
   190 	aTestInfo.iTestStep = this;
       
   191 	
       
   192 	User::LeaveIfError(iSecondThread.Create(KSecondThread, SgTestSecondThread::ThreadStart, KDefaultStackSize, KSecondThreadMinHeapSize, KSecondThreadMaxHeapSize, &aTestInfo));
       
   193 	// Launch second thread
       
   194 	TRequestStatus statusSecondThread;
       
   195 	iSecondThread.Logon(statusSecondThread);
       
   196 	iSecondThread.SetPriority(EPriorityLess);
       
   197 	iSecondThread.Resume();	
       
   198 	
       
   199 	User::WaitForRequest(statusSecondThread);
       
   200 	
       
   201 	TExitCategoryName exitCategory = iSecondThread.ExitCategory();
       
   202 	if (exitCategory.Compare(_L("Kill")) != 0)
       
   203 		{
       
   204 		ERR_PRINTF2(_L("Second thread terminated with reason category '%S'"), &exitCategory);
       
   205 		SetTestStepResult(EFail);
       
   206 		}
       
   207 	TInt result = iSecondThread.ExitReason();
       
   208 	
       
   209 	//Close the handle
       
   210 	CleanupStack::PopAndDestroy(1, &sem);
       
   211 	iSecondThread.Close();
       
   212 		
       
   213 	return result;
       
   214 	}
       
   215 
       
   216 /**
       
   217 Creates a second thread and do some panic tests in it.
       
   218 @param aTestInfo The information for the tests
       
   219 @param aPanicCode The expected panic code
       
   220 @param aExitCategory The expected panic category
       
   221 @param aThreadName The name of the new thread
       
   222 @leave Gets system wide error code
       
   223 */
       
   224 void CTSgTestStepBase::CreateSecondThreadAndCheckPanicL(TSgThreadTestInfo aTestInfo, TInt aPanicCode, TExitCategoryName aExitCategory, const TDesC &aThreadName)
       
   225 	{
       
   226 	aTestInfo.iTestStep = this;
       
   227 	User::LeaveIfError(iSecondThread.Create(aThreadName, SgTestSecondThread::ThreadStart, KDefaultStackSize, KSecondThreadMinHeapSize, KSecondThreadMaxHeapSize, &aTestInfo));
       
   228 	
       
   229 	// Launch second thread
       
   230 	TRequestStatus statusSecondThread;
       
   231 	iSecondThread.Logon(statusSecondThread);
       
   232 	iSecondThread.SetPriority(EPriorityLess);
       
   233 	iSecondThread.Resume();	
       
   234 	
       
   235 	User::WaitForRequest(statusSecondThread);
       
   236 	
       
   237 	if(EExitPanic != iSecondThread.ExitType())
       
   238 		{
       
   239 		ERR_PRINTF3(_L("Expected exit type: %d, Actual exit type: %d"), EExitPanic, iSecondThread.ExitType());
       
   240 		TEST(EFalse);
       
   241 		}
       
   242 	
       
   243 	if(aPanicCode != iSecondThread.ExitReason())
       
   244 		{
       
   245 		ERR_PRINTF3(_L("Expected panic code: %d, Actual panic code: %d"), aPanicCode, iSecondThread.ExitReason());
       
   246 		TEST(EFalse);
       
   247 		}
       
   248 	
       
   249 	TExitCategoryName secondThreadExitCategory = iSecondThread.ExitCategory();
       
   250 	if(aExitCategory != secondThreadExitCategory)
       
   251 		{
       
   252 		ERR_PRINTF3(_L("Expected panic category: %S, Actual panic category: %S"), &aExitCategory, &secondThreadExitCategory);
       
   253 		TEST(EFalse);
       
   254 		}
       
   255 	
       
   256 	//Close the handle
       
   257 	iSecondThread.Close();
       
   258 	}
       
   259 
       
   260 /**
       
   261 Gets the supporting pixel formats according to the specified usage bit.
       
   262 @leave Gets system wide error code
       
   263 */
       
   264 void CTSgTestStepBase::CallGetPixelFormatsL(TUint32 aUsage)
       
   265 	{
       
   266 	iPixelFormatArray.Reset();
       
   267 	CheckErrorL(KErrNone, RSgImage::GetPixelFormats(aUsage, iPixelFormatArray), (TText8*)__FILE__, __LINE__);
       
   268 	}
       
   269 
       
   270 /**
       
   271 Checks the pixel formats returned against the compatibility guarantee table.
       
   272 @leave Gets system wide error code
       
   273 */
       
   274 void CTSgTestStepBase::TestGetPixelFormatCompatibilityGuaranteesL()
       
   275 	{
       
   276 	_LIT(KLibOpenGLES2, "libGLESv2.dll");
       
   277 	
       
   278 	RLibrary lib;
       
   279 	TBool supportGLES2 = (lib.Load(KLibOpenGLES2) == KErrNone);
       
   280 	lib.Close();
       
   281 
       
   282 	// OpenVG - Mandatory support
       
   283 	CallGetPixelFormatsL(ESgUsageBitOpenVgImage);
       
   284 	TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888_PRE));
       
   285 	TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888));
       
   286 	TEST(CheckPixelFormatPresent(ESgPixelFormatXRGB_8888));
       
   287 	TEST(CheckPixelFormatPresent(ESgPixelFormatRGB_565));
       
   288 	TEST(CheckPixelFormatPresent(ESgPixelFormatA_8));
       
   289 	CallGetPixelFormatsL(ESgUsageBitOpenVgSurface);
       
   290 	TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888_PRE));
       
   291 	TEST(CheckPixelFormatPresent(ESgPixelFormatXRGB_8888));
       
   292 	TEST(CheckPixelFormatPresent(ESgPixelFormatRGB_565));
       
   293 	
       
   294 	// OpenGL ES - Not mandatory, but should cause no errors. 
       
   295 	CallGetPixelFormatsL(ESgUsageBitOpenGlesTexture2D);
       
   296 	CallGetPixelFormatsL(ESgUsageBitOpenGlesSurface);
       
   297 
       
   298 	// OpenGL ES 2 - Mandatory if present.
       
   299 	CallGetPixelFormatsL(ESgUsageBitOpenGles2Texture2D);
       
   300 	if (supportGLES2)
       
   301 	    {
       
   302         TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888_PRE));
       
   303         TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888));
       
   304         TEST(CheckPixelFormatPresent(ESgPixelFormatXRGB_8888));
       
   305         TEST(CheckPixelFormatPresent(ESgPixelFormatRGB_565));
       
   306         TEST(CheckPixelFormatPresent(ESgPixelFormatA_8));
       
   307 	    }
       
   308 	CallGetPixelFormatsL(ESgUsageBitOpenGles2Surface);
       
   309 	if (supportGLES2)
       
   310 	    {
       
   311 	    TEST(CheckPixelFormatPresent(ESgPixelFormatARGB_8888_PRE));
       
   312 	    TEST(CheckPixelFormatPresent(ESgPixelFormatXRGB_8888));
       
   313 	    TEST(CheckPixelFormatPresent(ESgPixelFormatRGB_565));
       
   314 	    }
       
   315 
       
   316 	iPixelFormatArray.Reset();
       
   317 	}
       
   318 
       
   319 /**
       
   320 Helper function to check if a certain pixel format is present
       
   321 in the pixel formats array retrieved by CallGetPixelFormatsL().
       
   322 
       
   323 @param aPixelFormat The pixelformat to check
       
   324 @return ETrue if the pixel format is present, otherwise EFalse
       
   325 @see CTsgTestStepBase::CallGetPixelFormats()
       
   326 */
       
   327 TBool CTSgTestStepBase::CheckPixelFormatPresent(TSgPixelFormat aPixelFormat)
       
   328 	{
       
   329 	for(TInt i=0; i<iPixelFormatArray.Count(); ++i)
       
   330 		{		
       
   331 		if(aPixelFormat == iPixelFormatArray[i])
       
   332 			{
       
   333 			return ETrue;
       
   334 			}
       
   335 		}
       
   336 	return EFalse;
       
   337 	}
       
   338 
       
   339 /**
       
   340 Helper function to test the equivalence of two TSgImageInfo structures.
       
   341 
       
   342 @see     CTDirectGdiContextTarget::CompareInfos
       
   343 @param   aInfo1 A TSgImageInfo structure to compare.
       
   344 @param   aInfo2 A TSgImageInfo structure to compare.
       
   345 
       
   346 @return  ETrue if the two are identical, EFalse otherwise.
       
   347 */
       
   348 TBool CTSgTestStepBase::CompareInfos(TSgImageInfo& aInfo1, TSgImageInfo& aInfo2)
       
   349 	{
       
   350 	return (aInfo1.iPixelFormat == aInfo2.iPixelFormat
       
   351 		&& aInfo1.iSizeInPixels == aInfo2.iSizeInPixels
       
   352 		&& aInfo1.iUsage == aInfo2.iUsage);
       
   353 	}
       
   354 
       
   355 /**
       
   356 Wrapper function to open the graphics resource driver.
       
   357 Only opens the driver if the test step has been constructed for use
       
   358 as the conformance tests.
       
   359 
       
   360 @leave One of the system wide error codes
       
   361 */
       
   362 void CTSgTestStepBase::TestOpenDriverL()
       
   363 	{
       
   364 	if (iEnableConformanceTests)
       
   365 		CheckErrorL(KErrNone, iSgDriver.Open(), (TText8*)__FILE__, __LINE__);
       
   366 	}
       
   367 
       
   368 /**
       
   369 Wrapper function to close the graphics resource driver.
       
   370 
       
   371 Only closes the driver if the test step has been constructed for use
       
   372 as the conformance tests.
       
   373 */
       
   374 void CTSgTestStepBase::TestCloseDriver()
       
   375 	{
       
   376 	if (iEnableConformanceTests)
       
   377 		iSgDriver.Close();
       
   378 	}
       
   379 
       
   380 /**
       
   381 Creates an image with specified parameters.
       
   382 @param aImage output image handle
       
   383 @return KErrNone if the image was created successfully, otherwise one of the system-wide error codes
       
   384 */
       
   385 TInt CreateImageWithParameters(TInt aWidth, TInt aHeight, TUidPixelFormat aPixelFormat, TUint32 aUsage, RSgImage& aImage)
       
   386 	{
       
   387 	TSgImageInfo info;
       
   388 	info.iSizeInPixels = TSize(aWidth, aHeight);
       
   389 	info.iPixelFormat = aPixelFormat;
       
   390 	info.iUsage = aUsage;
       
   391 	return aImage.Create(info, NULL, 0);
       
   392 	}
       
   393 
       
   394 /**
       
   395 Second thread entry function.
       
   396 */
       
   397 TInt SgTestSecondThread::ThreadStart(TAny* aInfo)
       
   398 	{
       
   399 	__UHEAP_MARK;
       
   400 	
       
   401 	CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
   402 	if (!cleanupStack)
       
   403 		{
       
   404 		return KErrNoMemory;
       
   405 		}
       
   406 	
       
   407 	TSgThreadTestInfo* testInfo = static_cast<TSgThreadTestInfo*>(aInfo);
       
   408 
       
   409 	RSemaphore sem;
       
   410 	TInt openSem = sem.OpenGlobal(KSecondThreadSemaphore, EOwnerThread);
       
   411 
       
   412 	TInt result = KErrNone;
       
   413 	TRAPD(leaveCode, result = SgTestSecondThread::ThreadMainL(testInfo));
       
   414 	if (KErrNone == openSem)
       
   415 		{
       
   416 		sem.Signal();
       
   417 		}
       
   418 	sem.Close();
       
   419 	
       
   420 	if (leaveCode != KErrNone)
       
   421 		{
       
   422 		testInfo->iTestStep->ERR_PRINTF2(_L("Second thread caused Leave (%d)"), leaveCode);
       
   423 		testInfo->iTestStep->SetTestStepResult(EFail);
       
   424 		result = leaveCode;
       
   425 		}
       
   426 	
       
   427 	delete cleanupStack;
       
   428 
       
   429 	__UHEAP_MARKEND;
       
   430 	
       
   431 	return result;
       
   432 	}
       
   433 
       
   434 /**
       
   435 Run the test contained within the TSgresTestInfo object. A new thread is
       
   436 created for each test and only one of the cases in the switch statements
       
   437 below will be used.
       
   438 
       
   439 The first switch statement contains tests that must have no driver open,
       
   440 the second set require an open driver to initiate the test but may
       
   441 close it part way through.
       
   442 
       
   443 @param aInfo The parameters for the test
       
   444 @return One of the system wide error codes or an enumeration of passed tests.
       
   445  */
       
   446 TInt SgTestSecondThread::ThreadMainL(TSgThreadTestInfo* aInfo)
       
   447 	{
       
   448 	TInt result = 0;
       
   449 
       
   450 	TSgresTestCase testcase = ((TSgThreadTestInfo*)aInfo)->iTestCase;
       
   451 
       
   452 	RSgDriver driver;
       
   453 	CleanupClosePushL(driver);
       
   454 	TInt ret = driver.Open();
       
   455 	if(KErrNoMemory == ret)
       
   456 		{
       
   457 		return KErrNoMemory;
       
   458 		}
       
   459 	//test cases without the need of an initialised driver
       
   460 	switch (testcase)
       
   461 	{
       
   462 	case ESgresSecondThreadPanicDrawableOpenNoDriver:
       
   463 		{
       
   464 		driver.Close();
       
   465 		RSgDrawable drawable;
       
   466 		drawable.Open(KFakeSgDrawableId); // should panic with SGRES 1
       
   467 		}
       
   468 		break;
       
   469 	case ESgresSecondThreadPanicImageOpenNoDriver:
       
   470 		{
       
   471 		driver.Close();
       
   472 		RSgImage image;
       
   473 		image.Open(KFakeSgDrawableId); // should panic with SGRES 1
       
   474 		image.Close();
       
   475 		}
       
   476 	case ESgresSecondThreadPanicImageCreateNoDriver1:
       
   477 		{
       
   478 		driver.Close();
       
   479 		RSgImage image;
       
   480 		image.Create(KSgImageInfo1, NULL, 0); // should panic with SGRES 1
       
   481 		image.Close();
       
   482 		}
       
   483 		break;
       
   484 	case ESgresSecondThreadPanicImageCreateNoDriver2:
       
   485 		{
       
   486 		driver.Close();
       
   487 		RSgImage image;
       
   488 		RSgImage tempImage;
       
   489 		image.Create(KSgImageInfo1, tempImage); // should panic with SGRES 1
       
   490 		image.Close();
       
   491 		}
       
   492 		break;
       
   493 	case ESgresSecondThreadOpenImage:
       
   494 		result = OpenImage(((TSgThreadTestInfo*)aInfo), driver);
       
   495 		break;
       
   496 	case ESgresSecondThreadOpenDrawable:
       
   497 		result = OpenDrawable(((TSgThreadTestInfo*)aInfo));
       
   498 		break;
       
   499 	case ESgresSecondThreadOpenImageInvalid:
       
   500 		result = OpenImageInvalid(((TSgThreadTestInfo*)aInfo));
       
   501 		break;
       
   502 	case ESgresSecondThreadOpenDrawableInvalid: 
       
   503 		result = OpenDrawableInvalid(((TSgThreadTestInfo*)aInfo));
       
   504 		break;
       
   505 	case ESgresSecondThreadPanicImageGetInterfaceInvalidHandle:
       
   506 		result = PanicImageGetInterfaceInvalidHandle(driver);
       
   507 		break;
       
   508 	case ESgresSecondThreadPanicImageGetInterfaceNoDriver:
       
   509 		result = PanicImageGetInterfaceNoDriver(driver);
       
   510 		break;
       
   511 	case ESgresSecondThreadPanicImageCloseInvalidHandle:
       
   512 		result = PanicImageCloseInvalidHandle(driver);
       
   513 		break;
       
   514 	case ESgresSecondThreadPanicImageCloseNoDriver:
       
   515 		result = PanicImageCloseNoDriver(driver);
       
   516 		break;
       
   517 	case ESgresSecondThreadPanicImageIdInvalidHandle:
       
   518 		result = PanicImageIdInvalidHandle(driver);
       
   519 		break;
       
   520 	case ESgresSecondThreadPanicImageIdNoDriver:
       
   521 		result = PanicImageIdNoDriver(driver);
       
   522 		break;
       
   523 	case ESgresSecondThreadPanicImageDrawableTypeInvalidHandle:
       
   524 		result = PanicImageDrawableTypeInvalidHandle(driver);
       
   525 		break;
       
   526 	case ESgresSecondThreadPanicImageDrawableTypeNoDriver:
       
   527 		result = PanicImageDrawableTypeNoDriver(driver);
       
   528 		break;  
       
   529 	case ESgresSecondThreadPanicImageCreateInvalidHandle:
       
   530 		result = PanicImageCreateInvalidHandle(driver);
       
   531 		break;
       
   532 	case ESgresSecondThreadPanicImageGetInfoInvalidHandle:
       
   533 		result = PanicImageGetInfoInvalidHandle(driver);
       
   534 		break;
       
   535 	case ESgresSecondThreadPanicImageGetInfoNoDriver:
       
   536 		result = PanicImageGetInfoNoDriver(driver);
       
   537 		break;
       
   538 	case ESgresSecondThreadPanicImageGetAttributeInvalidHandle:
       
   539 		result = PanicImageGetAttributeInvalidHandle(driver);
       
   540 		break;
       
   541 	case ESgresSecondThreadPanicImageGetAttributeNoDriver:
       
   542 		result = PanicImageGetAttributeNoDriver(driver);
       
   543 		break;
       
   544 	case ESgresMultipleThreadStressTest:
       
   545 		result = MultipleThreadStressTest(((TSgThreadTestInfo*)aInfo));
       
   546 		break;
       
   547 	case ESgresSecondThreadPanicAttributeArrayInvalidIndex:
       
   548 		PanicAttributeArrayInvalidIndexL();
       
   549 		break;
       
   550 	case ESgresSecondThreadPanicAttributeArrayInvalidIndex2:
       
   551 		PanicAttributeArrayInvalidIndex2L();
       
   552 		break;
       
   553 	case ESgresSecondThreadOpenPassedDriver:
       
   554 		result = ((TSgThreadTestInfo*)aInfo)->iSgDriver->Open();
       
   555 		break;
       
   556 	case ESgresSecondThreadClosePassedDriver:
       
   557 		((TSgThreadTestInfo*)aInfo)->iSgDriver->Close();
       
   558 		break;
       
   559 	case ESgresSecondThreadCreatePassedImage:
       
   560 		result = CreatePassedImageL(((TSgThreadTestInfo*)aInfo)->iSgImage);
       
   561 		break;
       
   562 	case ESgresSecondThreadOpenPassedImage:
       
   563 		((TSgThreadTestInfo*)aInfo)->iSgImage->Open(((TSgThreadTestInfo*)aInfo)->iDrawableId);
       
   564 		break;
       
   565 	case ESgresSecondThreadClosePassedImage:
       
   566 		((TSgThreadTestInfo*)aInfo)->iSgImage->Close();
       
   567 		break;
       
   568 	};
       
   569 
       
   570 	CleanupStack::PopAndDestroy(&driver);
       
   571 
       
   572 	return result;
       
   573 	}
       
   574 
       
   575 /**
       
   576 Checks the function for the passed error codes and logs an error if the codes do not match. 
       
   577 If run under OOM testing, this function will leave if KErrNoMemory or KErrNoGraphicsMemory was 
       
   578 the actual error; this is essential for OOM testing.
       
   579 
       
   580 @leave One of the System Wide Error Codes
       
   581 
       
   582 @param aExpectedErrorCode The expected error code to check against
       
   583 @param aActualErrorCode The actual error code
       
   584 @param aFile The filename to use when reporting the error
       
   585 @param aLine The line number to use when reporting the error
       
   586 */
       
   587 void CTSgTestStepBase::CheckErrorL(TInt aExpectedErrorCode, TInt aActualErrorCode, const TText8* aFile, TInt aLine)
       
   588 	{
       
   589 	if (iEnableConformanceTests)
       
   590 		{
       
   591 		TESTWITHFILENAMEANDLINENUMBERL(aExpectedErrorCode == aActualErrorCode, aFile, aLine);
       
   592 		}
       
   593 	else
       
   594 		{
       
   595 		//OOM Tests Enabled - Also test for KErrNoMemory/KErrNoGraphicsMemory
       
   596 		TESTWITHFILENAMEANDLINENUMBERL((aExpectedErrorCode == aActualErrorCode) || (KErrNoMemory == aActualErrorCode) || (KErrNoGraphicsMemory == aActualErrorCode), aFile, aLine);
       
   597 		if (aActualErrorCode == KErrNoMemory || aActualErrorCode == KErrNoGraphicsMemory)
       
   598 			{
       
   599 			User::Leave(aActualErrorCode);
       
   600 			}
       
   601 		}
       
   602 	}
       
   603 /**
       
   604 Implementation of SecondThread test ESgresSecondThreadOpenImage
       
   605 
       
   606 @return One of the system wide error codes or an enumeration of passed tests.
       
   607 
       
   608 @param TSgresTestInfo* The test parameters
       
   609 @param RSgDriver An open RSgDriver for the test code to use
       
   610  */
       
   611 TInt SgTestSecondThread::OpenImage(TSgThreadTestInfo* aInfo, RSgDriver& aSgDriver)
       
   612 	{
       
   613 	RSgImage image;
       
   614 	TInt result = 0;
       
   615 	TInt err = image.Open(aInfo->iDrawableId);
       
   616 	if(KErrNoMemory == err)
       
   617 		{
       
   618 		return KErrNoMemory;
       
   619 		}
       
   620 	if(KErrNone == err)
       
   621 		{
       
   622 		result |= EFirstTestPassed;
       
   623 		}
       
   624 	TSgImageInfo info3;
       
   625 	if(KErrNone == image.GetInfo(info3))
       
   626 		{
       
   627 		result |= ESecondTestPassed;
       
   628 		}
       
   629 	TSgImageInfo info4 = aInfo->iImageInfo;
       
   630 	if(CTSgTestStepBase::CompareInfos(info4, info3))
       
   631 		{
       
   632 		result |= EThirdTestPassed;
       
   633 		}
       
   634 	TSgDrawableId id = image.Id();
       
   635 	if(id != KSgNullDrawableId)
       
   636 		{
       
   637 		result |= EFourthTestPassed;
       
   638 		}
       
   639 	if(id == aInfo->iDrawableId)
       
   640 		{
       
   641 		result |= EFifthTestPassed;
       
   642 		}
       
   643 	TInt attribVal = KMaxTInt;
       
   644 	TUid uid = { 0x12345678 };
       
   645 	if (KErrNotSupported == image.GetAttribute(uid, attribVal))
       
   646 		{
       
   647 		result |= ESixthTestPassed;
       
   648 		}
       
   649 	if (KErrArgument == image.GetAttribute(KNullUid, attribVal))
       
   650 		{
       
   651 		result |= ESeventhTestPassed;
       
   652 		}
       
   653 	image.Close();
       
   654 	aSgDriver.Close();
       
   655 	if (KErrBadHandle == image.GetAttribute(uid, attribVal))
       
   656 		{
       
   657 		result |= EEighthTestPassed;
       
   658 		}
       
   659 	
       
   660 	return result;
       
   661 	}
       
   662 
       
   663 /**
       
   664 Implementation of SecondThread test ESgresSecondThreadOpenDrawable
       
   665 
       
   666 @return One of the system wide error codes or an enumeration of passed tests.
       
   667 
       
   668 @param TSgresTestInfo* The test parameters
       
   669  */
       
   670 TInt SgTestSecondThread::OpenDrawable(TSgThreadTestInfo* aInfo)
       
   671 	{
       
   672 	TInt result = 0;
       
   673 	RSgDrawable drawable;
       
   674 	TInt err = drawable.Open(aInfo->iDrawableId);
       
   675 	if(KErrNoMemory == err)
       
   676 		{
       
   677 		result = KErrNoMemory;
       
   678 		return result;
       
   679 		}
       
   680 	if(KErrNone == err)
       
   681 		{
       
   682 		result |= EFirstTestPassed;
       
   683 		}
       
   684 	TSgDrawableId id = drawable.Id();
       
   685 	if(id != KSgNullDrawableId)
       
   686 		{
       
   687 		result |= ESecondTestPassed;
       
   688 		}
       
   689 	if(id == aInfo->iDrawableId)
       
   690 		{
       
   691 		result |= EThirdTestPassed;
       
   692 		}
       
   693 	drawable.Close();
       
   694 	return result;
       
   695 	}
       
   696 
       
   697 /**
       
   698 Implementation of SecondThread test ESgresSecondThreadOpenImageInvalid
       
   699 
       
   700 @return One of the system wide error codes or an enumeration of passed tests.
       
   701 
       
   702 @param TSgresTestInfo* The test parameters
       
   703  */
       
   704 TInt SgTestSecondThread::OpenImageInvalid(TSgThreadTestInfo* aInfo)
       
   705 	{
       
   706 	TInt result = 0;
       
   707 	RSgImage image;
       
   708 	TSgImageInfo info;
       
   709 	info.iSizeInPixels = TSize(8, 8);
       
   710 	info.iPixelFormat = EUidPixelFormatRGB_565;
       
   711 	info.iUsage = ESgUsageBitOpenVgImage;
       
   712 	
       
   713 	TInt err = image.Create(info, KCrossImageData, KCrossImageDataStride);
       
   714 	if(KErrNoMemory == err)
       
   715 		{
       
   716 		return KErrNoMemory;
       
   717 		}
       
   718 	if(KErrNone == err)
       
   719 		{
       
   720 		result |= EFirstTestPassed;
       
   721 		}
       
   722 	
       
   723 	//  non-empty handle
       
   724 	TSgDrawableId id = aInfo->iDrawableId;
       
   725 	err = image.Open(id);
       
   726 	if(KErrNoMemory == err)
       
   727 		{
       
   728 		return KErrNoMemory;
       
   729 		}
       
   730 	if(KErrInUse == err)
       
   731 		{
       
   732 		result |= ESecondTestPassed;
       
   733 		}
       
   734 	image.Close();
       
   735 	
       
   736 	//  null drawable id    
       
   737 	err = image.Open(KSgNullDrawableId);
       
   738 	if(KErrNoMemory == err)
       
   739 		{
       
   740 		return KErrNoMemory;
       
   741 		}
       
   742 	if(KErrArgument == err)
       
   743 		{
       
   744 		result |= EThirdTestPassed;
       
   745 		}
       
   746 	image.Close();
       
   747 	
       
   748 	//  non-existing drawable id
       
   749 	err = image.Open(KFakeSgDrawableId);
       
   750 	if(KErrNoMemory == err)
       
   751 		{
       
   752 		return KErrNoMemory;
       
   753 		}
       
   754 	if(KErrNotFound == err)
       
   755 		{
       
   756 		result |= EFourthTestPassed;
       
   757 		}
       
   758 	image.Close();
       
   759 	
       
   760 	err = image.Open(id);
       
   761 	if(KErrNoMemory == err)
       
   762 		{
       
   763 		return KErrNoMemory;
       
   764 		}
       
   765 	if(KErrNone == err)
       
   766 		{
       
   767 		result |= EFifthTestPassed;
       
   768 		}
       
   769 	image.Close();
       
   770 	
       
   771 	return result;
       
   772 	}
       
   773 
       
   774 /**
       
   775 Implementation of SecondThread test ESgresSecondThreadOpenDrawableInvalid
       
   776 
       
   777 @return One of the system wide error codes or an enumeration of passed tests.
       
   778 
       
   779 @param TSgresTestInfo* The test parameters
       
   780 */
       
   781 TInt SgTestSecondThread::OpenDrawableInvalid(TSgThreadTestInfo* aInfo)
       
   782 	{
       
   783 	TInt result = 0;
       
   784 	RSgDrawable drawable;
       
   785 	TInt err = drawable.Open(KSgNullDrawableId);
       
   786 	if(KErrNoMemory == err)
       
   787 		{
       
   788 	    return KErrNoMemory;
       
   789 		}
       
   790 	if(KErrArgument == err)
       
   791 		{
       
   792 	    result |= EFirstTestPassed;
       
   793 	    }
       
   794 	drawable.Close();
       
   795 	
       
   796 	//  non-existing drawable id
       
   797 	err = drawable.Open(KFakeSgDrawableId);
       
   798 	if (KErrNoMemory == err)
       
   799 		{
       
   800 		return KErrNoMemory;
       
   801 		}
       
   802 	
       
   803 	if(KErrNotFound == err)
       
   804 		{
       
   805 		result |= ESecondTestPassed;
       
   806 		}
       
   807 	drawable.Close();
       
   808 	
       
   809 	//  open a non-sharable image - should succeed
       
   810 	err = drawable.Open(aInfo->iDrawableId);
       
   811 	
       
   812 	if(KErrNoMemory == err)
       
   813 		{
       
   814 		return KErrNoMemory;
       
   815 		}
       
   816 	if(KErrNone == err)
       
   817 		{
       
   818 		result |= EThirdTestPassed;
       
   819 		
       
   820 		if (KErrInUse == drawable.Open(aInfo->iDrawableId))
       
   821 			{
       
   822 			result |= EFourthTestPassed;
       
   823 			}
       
   824 		}
       
   825 
       
   826 	drawable.Close();
       
   827 	
       
   828 	return result;
       
   829 	}
       
   830 
       
   831 /**
       
   832 Implementation of SecondThread test ESgresSecondThreadPanicImageGetInterfaceInvalidHandle
       
   833 
       
   834 @panic SGRES2 If the test is successful
       
   835 
       
   836 @return One of the system wide error codes.
       
   837 
       
   838 @param RSgDriver An open RSgDriver for the test code to use
       
   839  */
       
   840 TInt SgTestSecondThread::PanicImageGetInterfaceInvalidHandle(RSgDriver& aSgDriver)
       
   841 	{
       
   842 	RSgImage image;
       
   843 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); 
       
   844 
       
   845 	MTSgImage_Interface* swInterface = NULL;
       
   846 	result = image.GetInterface(swInterface); //should panic with SGRES 3
       
   847 	aSgDriver.Close();
       
   848 	
       
   849 	return result;
       
   850 	}
       
   851 
       
   852 /**
       
   853 Implementation of SecondThread test ESgresSecondThreadPanicImageGetInterfaceNoDriver
       
   854 
       
   855 @panic SGRES1 If the test is successful
       
   856 
       
   857 @return One of the system wide error codes
       
   858 
       
   859 @param RSgDriver An open RSgDriver for the test code to use
       
   860  */
       
   861 TInt SgTestSecondThread::PanicImageGetInterfaceNoDriver(RSgDriver& aSgDriver)
       
   862 	{
       
   863 	RSgImage image;
       
   864 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   865 	
       
   866 	aSgDriver.Close();
       
   867 	MTSgImage_Interface* swInterface = NULL;
       
   868 	image.GetInterface(swInterface); // should panic with SGRES 1
       
   869 	return result;
       
   870 	}
       
   871 
       
   872 /**
       
   873 Implementation of SecondThread test ESgresSecondThreadPanicImageCloseInvalidHandle
       
   874 
       
   875 @panic SGRES2 If the test is successful
       
   876 
       
   877 @return One of the system wide error codes
       
   878 
       
   879 @param RSgDriver An open RSgDriver for the test code to use
       
   880  */
       
   881 TInt SgTestSecondThread::PanicImageCloseInvalidHandle(RSgDriver& aSgDriver)
       
   882 	{
       
   883 	RSgImage image;
       
   884 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   885 	
       
   886 	image.Close(); //should panic with SGRES 3
       
   887 	aSgDriver.Close();
       
   888 	return result;
       
   889 	}
       
   890 
       
   891 /**
       
   892 Implementation of SecondThread test ESgresSecondThreadPanicImageCloseNoDriver
       
   893 
       
   894 @panic SGRES1 If the test is successful
       
   895 
       
   896 @return One of the system wide error codes
       
   897 
       
   898 @param RSgDriver An open RSgDriver for the test code to use
       
   899  */
       
   900 TInt SgTestSecondThread::PanicImageCloseNoDriver(RSgDriver& aSgDriver)
       
   901 	{
       
   902 	RSgImage image;
       
   903 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   904 	aSgDriver.Close();
       
   905 	image.Close(); // should panic with SGRES 1 
       
   906 	return result;
       
   907 	}
       
   908 
       
   909 /**
       
   910 Implementation of SecondThread test ESgresSecondThreadPanicImageIdIvalidHandle
       
   911 
       
   912 @panic SGRES2 If the test is successful
       
   913 
       
   914 @return One of the system wide error codes
       
   915 
       
   916 @param RSgDriver An open RSgDriver for the test code to use
       
   917  */
       
   918 TInt SgTestSecondThread::PanicImageIdInvalidHandle(RSgDriver& aSgDriver)
       
   919 	{
       
   920 	RSgImage image;
       
   921 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   922 	
       
   923 	image.Id(); //should panic with SGRES 3
       
   924 	aSgDriver.Close();
       
   925 	return result;
       
   926 	}
       
   927 
       
   928 /**
       
   929 Implementation of SecondThread test ESgresSecondThreadPanicImageIdNoDriver
       
   930 
       
   931 @panic SGRES1 If the test is successful
       
   932 
       
   933 @return One of the system wide error codes
       
   934 
       
   935 @param RSgDriver An open RSgDriver for the test code to use
       
   936  */
       
   937 TInt SgTestSecondThread::PanicImageIdNoDriver(RSgDriver& aSgDriver)
       
   938 	{
       
   939 	RSgImage image;
       
   940 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   941 
       
   942 	aSgDriver.Close();
       
   943 	image.Id(); // should panic with SGRES 1
       
   944 	return result;
       
   945 	}
       
   946 
       
   947 /**
       
   948 Implementation of SecondThread test ESgresSecondThreadPanicImageDrawableTypeInvalidHandle
       
   949 
       
   950 @panic SGRES2 If the test is successful
       
   951 
       
   952 @return One of the system wide error codes
       
   953 
       
   954 @param RSgDriver An open RSgDriver for the test code to use
       
   955  */
       
   956 TInt SgTestSecondThread::PanicImageDrawableTypeInvalidHandle(RSgDriver& aSgDriver)
       
   957 	{
       
   958 	RSgImage image; 
       
   959 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   960 	
       
   961 	image.DrawableType(); //should panic with SGRES 3
       
   962 	aSgDriver.Close();
       
   963 	
       
   964 	return result;
       
   965 	}
       
   966 
       
   967 /**
       
   968 Implementation of SecondThread test ESgresSecondThreadPanicImageDrawableTypeNoDriver
       
   969 
       
   970 @panic SGRES1 If the test is successful
       
   971 
       
   972 @return One of the system wide error codes
       
   973 
       
   974 @param RSgDriver An open RSgDriver for the test code to use
       
   975  */
       
   976 TInt SgTestSecondThread::PanicImageDrawableTypeNoDriver(RSgDriver& aSgDriver)
       
   977 	{
       
   978 	RSgImage image; 
       
   979 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   980 	aSgDriver.Close();
       
   981 	image.DrawableType(); // should panic with SGRES 1
       
   982 	return result;
       
   983 	}
       
   984 
       
   985 /**
       
   986 Implementation of SecondThread test ESgresSecondThreadPanicImageCreateInvalidHandle
       
   987 
       
   988 @panic SGRES3 If the test is successful
       
   989 
       
   990 @return One of the system wide error codes
       
   991 
       
   992 @param RSgDriver An open RSgDriver for the test code to use
       
   993  */
       
   994 TInt SgTestSecondThread::PanicImageCreateInvalidHandle(RSgDriver& aSgDriver)
       
   995 	{
       
   996 	RSgImage image; 
       
   997 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   998 	
       
   999 	RSgImage newImage;
       
  1000 	TSgImageInfo info;
       
  1001 	image.GetInfo(info);
       
  1002 	newImage.Create(info, image); //should panic with SGRES 3
       
  1003 	aSgDriver.Close();
       
  1004 	return result;
       
  1005 	}
       
  1006 
       
  1007 /**
       
  1008 Implementation of SecondThread test ESgresSecondThreadPanicImageGetInfoInvalidHandle
       
  1009 
       
  1010 @panic SGRES3 If the test is successful
       
  1011 
       
  1012 @return One of the system wide error codes
       
  1013 
       
  1014 @param RSgDriver An open RSgDriver for the test code to use
       
  1015  */
       
  1016 TInt SgTestSecondThread::PanicImageGetInfoInvalidHandle(RSgDriver& aSgDriver)
       
  1017 	{
       
  1018 	RSgImage image; 
       
  1019 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
  1020 	
       
  1021 	TSgImageInfo anotherInfo;
       
  1022 	image.GetInfo(anotherInfo); //should panic with SGRES 3
       
  1023 	aSgDriver.Close();
       
  1024 	return result;
       
  1025 	}
       
  1026 
       
  1027 /**
       
  1028 Implementation of SecondThread test ESgresSecondThreadPanicImageNoDriver
       
  1029 
       
  1030 @panic SGRES1 If the test is successful
       
  1031 
       
  1032 @return One of the system wide error codes or an enumeration of passed tests.
       
  1033 
       
  1034 @param RSgDriver An open RSgDriver for the test code to use
       
  1035  */
       
  1036 TInt SgTestSecondThread::PanicImageGetInfoNoDriver(RSgDriver& aSgDriver)
       
  1037 	{
       
  1038 	RSgImage image; 
       
  1039 	TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image);
       
  1040 	if(KErrNone != ret)
       
  1041 		{
       
  1042 		return ret;
       
  1043 		}
       
  1044 	RSgImage anotherImage;
       
  1045 	Mem::Copy(&anotherImage, &image, sizeof(image));
       
  1046 	image.Close();
       
  1047 	aSgDriver.Close();
       
  1048 	TSgImageInfo anotherInfo;
       
  1049 	anotherImage.GetInfo(anotherInfo); // should panic with SGRES 1
       
  1050 	return ret;
       
  1051 	}
       
  1052 
       
  1053 /**
       
  1054 Implementation of SecondThread test ESgresSecondThreadPanicImageGetAttributeInvalidHandle
       
  1055 
       
  1056 @panic SGRES3 If the test is successful
       
  1057 
       
  1058 @return One of the system wide error codes
       
  1059 
       
  1060 @param RSgDriver An open RSgDriver for the test code to use
       
  1061  */
       
  1062 TInt SgTestSecondThread::PanicImageGetAttributeInvalidHandle(RSgDriver& aSgDriver)
       
  1063 	{
       
  1064 	RSgImage image; 
       
  1065 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
  1066 	
       
  1067 	TInt attrib = KMaxTInt;
       
  1068 	image.GetAttribute(TUid::Uid(1), attrib); //Should panic with SGRES 3
       
  1069 	
       
  1070 	aSgDriver.Close();
       
  1071 	return result;
       
  1072 	}
       
  1073 
       
  1074 /**
       
  1075 Implementation of SecondThread test ESgresSecondThreadPanicImageGetAttributeNoDriver
       
  1076 
       
  1077 @panic SGRES1 If the test is successful
       
  1078 
       
  1079 @return One of the system wide error codes
       
  1080 
       
  1081 @param RSgDriver An open RSgDriver for the test code to use
       
  1082  */
       
  1083 TInt SgTestSecondThread::PanicImageGetAttributeNoDriver(RSgDriver& aSgDriver)
       
  1084 	{
       
  1085 	RSgImage image; 
       
  1086 	TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image);
       
  1087 	if(KErrNone != ret)
       
  1088 		{
       
  1089 		return ret;
       
  1090 		}
       
  1091 	RSgImage anotherImage;
       
  1092 	Mem::Copy(&anotherImage, &image, sizeof(image));
       
  1093 	image.Close();
       
  1094 	aSgDriver.Close();
       
  1095 	TInt attrib = KMaxTInt;
       
  1096 	TUid uid = { 0x12345678 };
       
  1097 	anotherImage.GetAttribute(uid, attrib); //Should panic with SGRES 1
       
  1098 	return ret;
       
  1099 	}
       
  1100 
       
  1101 /**
       
  1102 Implementation of SecondThread test ESgresSecondThreadMultipleThreadStressTest
       
  1103 
       
  1104 @return One of the system wide error codes
       
  1105 
       
  1106 @param TSgresTestInfo* The test parameters
       
  1107  */
       
  1108 TInt SgTestSecondThread::MultipleThreadStressTest(TSgThreadTestInfo* aInfo)
       
  1109 	{
       
  1110 	TInt result = 0;
       
  1111 	RSgImage image;
       
  1112 	for (TInt i = 0; i < 1000 && result == KErrNone; ++i)
       
  1113 		{
       
  1114 		TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image); 
       
  1115 		if (KErrNone != ret)
       
  1116 			{
       
  1117 			result = ret;
       
  1118 			break;
       
  1119 			}
       
  1120 
       
  1121 		const TInt KMaxOpenCount = 100;
       
  1122 		RSgImage images[KMaxOpenCount];
       
  1123 		TInt count = Math::Random() % KMaxOpenCount;
       
  1124 		for (TInt k = 0; k < count; ++k)
       
  1125 			{
       
  1126 			ret = images[k].Open(aInfo->iDrawableId);
       
  1127 			if (KErrNone != ret)
       
  1128 				{
       
  1129 				result = ret;
       
  1130 				break;
       
  1131 				}
       
  1132 			}
       
  1133 		image.Close();
       
  1134 		for (TInt k = 0; k < count; ++k)
       
  1135 			{
       
  1136 			images[k].Close();
       
  1137 			}
       
  1138 		}
       
  1139 	return result;
       
  1140 	}
       
  1141 
       
  1142 /**
       
  1143 Implementation of SecondThread test ESgresSecondThreadPanicAttributeArrayInvalidIndex
       
  1144 
       
  1145 @panic SGRES4 If the test is successful
       
  1146 
       
  1147 @param TSgresTestInfo* The test parameters
       
  1148  */
       
  1149 void SgTestSecondThread::PanicAttributeArrayInvalidIndexL()
       
  1150 	{
       
  1151 	TSgAttributeArray<5> attribArray;
       
  1152 	TSgAttribute attrib = attribArray[6]; //Should panic with SGRES 4
       
  1153 	}
       
  1154 
       
  1155 /**
       
  1156 Implementation of SecondThread test ESgresSecondThreadPanicAttributeArrayInvalidIndex2
       
  1157 
       
  1158 @panic SGRES4 If the test is successful
       
  1159 
       
  1160 @param TSgresTestInfo* The test parameters
       
  1161  */
       
  1162 void SgTestSecondThread::PanicAttributeArrayInvalidIndex2L()
       
  1163 	{
       
  1164 	TSgAttributeArray<5> attribArray;
       
  1165 	TSgAttribute attrib = attribArray[-1]; //Should panic with SGRES 4
       
  1166 	}
       
  1167 
       
  1168 /**
       
  1169 Implementation of SecondThread test ESgresSecondThreadPanicDriverCloseOpenResources
       
  1170 
       
  1171 @return One of the system wide error codes
       
  1172 
       
  1173 @param RSgImage* A closed or uninitialised RSgImage to use for image creation 
       
  1174  */
       
  1175 TInt SgTestSecondThread::CreatePassedImageL(RSgImage* aSgImage)
       
  1176 	{
       
  1177 	TSgImageInfo info;
       
  1178 	info.iSizeInPixels = TSize(8, 8);
       
  1179 	info.iUsage = ESgUsageBitOpenVgImage;
       
  1180 	info.iPixelFormat = EUidPixelFormatRGB_565;
       
  1181 	
       
  1182 	return aSgImage->Create(info, KCrossImageData, KCrossImageDataStride);
       
  1183 	}
       
  1184 
       
  1185 /**
       
  1186 Helper function which Creates an RSgImage and copies to into another RSgImage 
       
  1187 using Mem::Copy; the target of the copy is returned in the open state.
       
  1188 
       
  1189 @param aSgImage An uninitialised image which will have an SgImage Mem::Copied into it.
       
  1190 @return One of the system wide error codes.
       
  1191  */
       
  1192 TInt CTSgTestStepBase::CreateImageAndReturnCopy(RSgImage& aSgImage)
       
  1193 	{
       
  1194 	RSgImage image; 
       
  1195 	TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image);
       
  1196 	if(KErrNone != ret)
       
  1197 		{
       
  1198 		return ret;
       
  1199 		}
       
  1200 	Mem::Copy(&aSgImage, &image, sizeof(image));
       
  1201 	image.Close();
       
  1202 	
       
  1203 	return ret;
       
  1204 	}