graphicsresourceservices/graphicsresourceimplementation/test/src/tgraphicsresourceteststepbase.cpp
branchRCL_3
changeset 163 bbf46f59e123
equal deleted inserted replaced
150:57c618273d5c 163:bbf46f59e123
       
     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 @param   aInfo1 A TSgImageInfo structure to compare.
       
   343 @param   aInfo2 A TSgImageInfo structure to compare (may have extra usage bits).
       
   344 
       
   345 @return  ETrue if the two are equivalent, EFalse otherwise.
       
   346 */
       
   347 TBool CTSgTestStepBase::CompareInfos(TSgImageInfo& aInfo1, TSgImageInfo& aInfo2)
       
   348 	{
       
   349 	return (aInfo1.iPixelFormat == aInfo2.iPixelFormat
       
   350 		&& aInfo1.iSizeInPixels == aInfo2.iSizeInPixels
       
   351 		// check that all requested usage bits are set in the returned usage bits
       
   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 info;
       
   625 	if(KErrNone == image.GetInfo(info))
       
   626 		{
       
   627 		result |= ESecondTestPassed;
       
   628 		}
       
   629 	if(CTSgTestStepBase::CompareInfos(aInfo->iImageInfo, info))
       
   630 		{
       
   631 		result |= EThirdTestPassed;
       
   632 		}
       
   633 	TSgDrawableId id = image.Id();
       
   634 	if(id != KSgNullDrawableId)
       
   635 		{
       
   636 		result |= EFourthTestPassed;
       
   637 		}
       
   638 	if(id == aInfo->iDrawableId)
       
   639 		{
       
   640 		result |= EFifthTestPassed;
       
   641 		}
       
   642 	TInt attribVal = KMaxTInt;
       
   643 	TUid uid = { 0x12345678 };
       
   644 	if (KErrNotSupported == image.GetAttribute(uid, attribVal))
       
   645 		{
       
   646 		result |= ESixthTestPassed;
       
   647 		}
       
   648 	if (KErrArgument == image.GetAttribute(KNullUid, attribVal))
       
   649 		{
       
   650 		result |= ESeventhTestPassed;
       
   651 		}
       
   652 	image.Close();
       
   653 	aSgDriver.Close();
       
   654 	if (KErrBadHandle == image.GetAttribute(uid, attribVal))
       
   655 		{
       
   656 		result |= EEighthTestPassed;
       
   657 		}
       
   658 	
       
   659 	return result;
       
   660 	}
       
   661 
       
   662 /**
       
   663 Implementation of SecondThread test ESgresSecondThreadOpenDrawable
       
   664 
       
   665 @return One of the system wide error codes or an enumeration of passed tests.
       
   666 
       
   667 @param TSgresTestInfo* The test parameters
       
   668  */
       
   669 TInt SgTestSecondThread::OpenDrawable(TSgThreadTestInfo* aInfo)
       
   670 	{
       
   671 	TInt result = 0;
       
   672 	RSgDrawable drawable;
       
   673 	TInt err = drawable.Open(aInfo->iDrawableId);
       
   674 	if(KErrNoMemory == err)
       
   675 		{
       
   676 		result = KErrNoMemory;
       
   677 		return result;
       
   678 		}
       
   679 	if(KErrNone == err)
       
   680 		{
       
   681 		result |= EFirstTestPassed;
       
   682 		}
       
   683 	TSgDrawableId id = drawable.Id();
       
   684 	if(id != KSgNullDrawableId)
       
   685 		{
       
   686 		result |= ESecondTestPassed;
       
   687 		}
       
   688 	if(id == aInfo->iDrawableId)
       
   689 		{
       
   690 		result |= EThirdTestPassed;
       
   691 		}
       
   692 	drawable.Close();
       
   693 	return result;
       
   694 	}
       
   695 
       
   696 /**
       
   697 Implementation of SecondThread test ESgresSecondThreadOpenImageInvalid
       
   698 
       
   699 @return One of the system wide error codes or an enumeration of passed tests.
       
   700 
       
   701 @param TSgresTestInfo* The test parameters
       
   702  */
       
   703 TInt SgTestSecondThread::OpenImageInvalid(TSgThreadTestInfo* aInfo)
       
   704 	{
       
   705 	TInt result = 0;
       
   706 	RSgImage image;
       
   707 	TSgImageInfo info;
       
   708 	info.iSizeInPixels = TSize(8, 8);
       
   709 	info.iPixelFormat = EUidPixelFormatRGB_565;
       
   710 	info.iUsage = ESgUsageBitOpenVgImage;
       
   711 	
       
   712 	TInt err = image.Create(info, KCrossImageData, KCrossImageDataStride);
       
   713 	if(KErrNoMemory == err)
       
   714 		{
       
   715 		return KErrNoMemory;
       
   716 		}
       
   717 	if(KErrNone == err)
       
   718 		{
       
   719 		result |= EFirstTestPassed;
       
   720 		}
       
   721 	
       
   722 	//  non-empty handle
       
   723 	TSgDrawableId id = aInfo->iDrawableId;
       
   724 	err = image.Open(id);
       
   725 	if(KErrNoMemory == err)
       
   726 		{
       
   727 		return KErrNoMemory;
       
   728 		}
       
   729 	if(KErrInUse == err)
       
   730 		{
       
   731 		result |= ESecondTestPassed;
       
   732 		}
       
   733 	image.Close();
       
   734 	
       
   735 	//  null drawable id    
       
   736 	err = image.Open(KSgNullDrawableId);
       
   737 	if(KErrNoMemory == err)
       
   738 		{
       
   739 		return KErrNoMemory;
       
   740 		}
       
   741 	if(KErrArgument == err)
       
   742 		{
       
   743 		result |= EThirdTestPassed;
       
   744 		}
       
   745 	image.Close();
       
   746 	
       
   747 	//  non-existing drawable id
       
   748 	err = image.Open(KFakeSgDrawableId);
       
   749 	if(KErrNoMemory == err)
       
   750 		{
       
   751 		return KErrNoMemory;
       
   752 		}
       
   753 	if(KErrNotFound == err)
       
   754 		{
       
   755 		result |= EFourthTestPassed;
       
   756 		}
       
   757 	image.Close();
       
   758 	
       
   759 	err = image.Open(id);
       
   760 	if(KErrNoMemory == err)
       
   761 		{
       
   762 		return KErrNoMemory;
       
   763 		}
       
   764 	if(KErrNone == err)
       
   765 		{
       
   766 		result |= EFifthTestPassed;
       
   767 		}
       
   768 	image.Close();
       
   769 	
       
   770 	return result;
       
   771 	}
       
   772 
       
   773 /**
       
   774 Implementation of SecondThread test ESgresSecondThreadOpenDrawableInvalid
       
   775 
       
   776 @return One of the system wide error codes or an enumeration of passed tests.
       
   777 
       
   778 @param TSgresTestInfo* The test parameters
       
   779 */
       
   780 TInt SgTestSecondThread::OpenDrawableInvalid(TSgThreadTestInfo* aInfo)
       
   781 	{
       
   782 	TInt result = 0;
       
   783 	RSgDrawable drawable;
       
   784 	TInt err = drawable.Open(KSgNullDrawableId);
       
   785 	if(KErrNoMemory == err)
       
   786 		{
       
   787 	    return KErrNoMemory;
       
   788 		}
       
   789 	if(KErrArgument == err)
       
   790 		{
       
   791 	    result |= EFirstTestPassed;
       
   792 	    }
       
   793 	drawable.Close();
       
   794 	
       
   795 	//  non-existing drawable id
       
   796 	err = drawable.Open(KFakeSgDrawableId);
       
   797 	if (KErrNoMemory == err)
       
   798 		{
       
   799 		return KErrNoMemory;
       
   800 		}
       
   801 	
       
   802 	if(KErrNotFound == err)
       
   803 		{
       
   804 		result |= ESecondTestPassed;
       
   805 		}
       
   806 	drawable.Close();
       
   807 	
       
   808 	//  open a non-sharable image - should succeed
       
   809 	err = drawable.Open(aInfo->iDrawableId);
       
   810 	
       
   811 	if(KErrNoMemory == err)
       
   812 		{
       
   813 		return KErrNoMemory;
       
   814 		}
       
   815 	if(KErrNone == err)
       
   816 		{
       
   817 		result |= EThirdTestPassed;
       
   818 		
       
   819 		if (KErrInUse == drawable.Open(aInfo->iDrawableId))
       
   820 			{
       
   821 			result |= EFourthTestPassed;
       
   822 			}
       
   823 		}
       
   824 
       
   825 	drawable.Close();
       
   826 	
       
   827 	return result;
       
   828 	}
       
   829 
       
   830 /**
       
   831 Implementation of SecondThread test ESgresSecondThreadPanicImageGetInterfaceInvalidHandle
       
   832 
       
   833 @panic SGRES2 If the test is successful
       
   834 
       
   835 @return One of the system wide error codes.
       
   836 
       
   837 @param RSgDriver An open RSgDriver for the test code to use
       
   838  */
       
   839 TInt SgTestSecondThread::PanicImageGetInterfaceInvalidHandle(RSgDriver& aSgDriver)
       
   840 	{
       
   841 	RSgImage image;
       
   842 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image); 
       
   843 
       
   844 	MTSgImage_Interface* swInterface = NULL;
       
   845 	result = image.GetInterface(swInterface); //should panic with SGRES 3
       
   846 	aSgDriver.Close();
       
   847 	
       
   848 	return result;
       
   849 	}
       
   850 
       
   851 /**
       
   852 Implementation of SecondThread test ESgresSecondThreadPanicImageGetInterfaceNoDriver
       
   853 
       
   854 @panic SGRES1 If the test is successful
       
   855 
       
   856 @return One of the system wide error codes
       
   857 
       
   858 @param RSgDriver An open RSgDriver for the test code to use
       
   859  */
       
   860 TInt SgTestSecondThread::PanicImageGetInterfaceNoDriver(RSgDriver& aSgDriver)
       
   861 	{
       
   862 	RSgImage image;
       
   863 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   864 	
       
   865 	aSgDriver.Close();
       
   866 	MTSgImage_Interface* swInterface = NULL;
       
   867 	image.GetInterface(swInterface); // should panic with SGRES 1
       
   868 	return result;
       
   869 	}
       
   870 
       
   871 /**
       
   872 Implementation of SecondThread test ESgresSecondThreadPanicImageCloseInvalidHandle
       
   873 
       
   874 @panic SGRES2 If the test is successful
       
   875 
       
   876 @return One of the system wide error codes
       
   877 
       
   878 @param RSgDriver An open RSgDriver for the test code to use
       
   879  */
       
   880 TInt SgTestSecondThread::PanicImageCloseInvalidHandle(RSgDriver& aSgDriver)
       
   881 	{
       
   882 	RSgImage image;
       
   883 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   884 	
       
   885 	image.Close(); //should panic with SGRES 3
       
   886 	aSgDriver.Close();
       
   887 	return result;
       
   888 	}
       
   889 
       
   890 /**
       
   891 Implementation of SecondThread test ESgresSecondThreadPanicImageCloseNoDriver
       
   892 
       
   893 @panic SGRES1 If the test is successful
       
   894 
       
   895 @return One of the system wide error codes
       
   896 
       
   897 @param RSgDriver An open RSgDriver for the test code to use
       
   898  */
       
   899 TInt SgTestSecondThread::PanicImageCloseNoDriver(RSgDriver& aSgDriver)
       
   900 	{
       
   901 	RSgImage image;
       
   902 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   903 	aSgDriver.Close();
       
   904 	image.Close(); // should panic with SGRES 1 
       
   905 	return result;
       
   906 	}
       
   907 
       
   908 /**
       
   909 Implementation of SecondThread test ESgresSecondThreadPanicImageIdIvalidHandle
       
   910 
       
   911 @panic SGRES2 If the test is successful
       
   912 
       
   913 @return One of the system wide error codes
       
   914 
       
   915 @param RSgDriver An open RSgDriver for the test code to use
       
   916  */
       
   917 TInt SgTestSecondThread::PanicImageIdInvalidHandle(RSgDriver& aSgDriver)
       
   918 	{
       
   919 	RSgImage image;
       
   920 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   921 	
       
   922 	image.Id(); //should panic with SGRES 3
       
   923 	aSgDriver.Close();
       
   924 	return result;
       
   925 	}
       
   926 
       
   927 /**
       
   928 Implementation of SecondThread test ESgresSecondThreadPanicImageIdNoDriver
       
   929 
       
   930 @panic SGRES1 If the test is successful
       
   931 
       
   932 @return One of the system wide error codes
       
   933 
       
   934 @param RSgDriver An open RSgDriver for the test code to use
       
   935  */
       
   936 TInt SgTestSecondThread::PanicImageIdNoDriver(RSgDriver& aSgDriver)
       
   937 	{
       
   938 	RSgImage image;
       
   939 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   940 
       
   941 	aSgDriver.Close();
       
   942 	image.Id(); // should panic with SGRES 1
       
   943 	return result;
       
   944 	}
       
   945 
       
   946 /**
       
   947 Implementation of SecondThread test ESgresSecondThreadPanicImageDrawableTypeInvalidHandle
       
   948 
       
   949 @panic SGRES2 If the test is successful
       
   950 
       
   951 @return One of the system wide error codes
       
   952 
       
   953 @param RSgDriver An open RSgDriver for the test code to use
       
   954  */
       
   955 TInt SgTestSecondThread::PanicImageDrawableTypeInvalidHandle(RSgDriver& aSgDriver)
       
   956 	{
       
   957 	RSgImage image; 
       
   958 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   959 	
       
   960 	image.DrawableType(); //should panic with SGRES 3
       
   961 	aSgDriver.Close();
       
   962 	
       
   963 	return result;
       
   964 	}
       
   965 
       
   966 /**
       
   967 Implementation of SecondThread test ESgresSecondThreadPanicImageDrawableTypeNoDriver
       
   968 
       
   969 @panic SGRES1 If the test is successful
       
   970 
       
   971 @return One of the system wide error codes
       
   972 
       
   973 @param RSgDriver An open RSgDriver for the test code to use
       
   974  */
       
   975 TInt SgTestSecondThread::PanicImageDrawableTypeNoDriver(RSgDriver& aSgDriver)
       
   976 	{
       
   977 	RSgImage image; 
       
   978 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   979 	aSgDriver.Close();
       
   980 	image.DrawableType(); // should panic with SGRES 1
       
   981 	return result;
       
   982 	}
       
   983 
       
   984 /**
       
   985 Implementation of SecondThread test ESgresSecondThreadPanicImageCreateInvalidHandle
       
   986 
       
   987 @panic SGRES3 If the test is successful
       
   988 
       
   989 @return One of the system wide error codes
       
   990 
       
   991 @param RSgDriver An open RSgDriver for the test code to use
       
   992  */
       
   993 TInt SgTestSecondThread::PanicImageCreateInvalidHandle(RSgDriver& aSgDriver)
       
   994 	{
       
   995 	RSgImage image; 
       
   996 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
   997 	
       
   998 	RSgImage newImage;
       
   999 	TSgImageInfo info;
       
  1000 	image.GetInfo(info);
       
  1001 	newImage.Create(info, image); //should panic with SGRES 3
       
  1002 	aSgDriver.Close();
       
  1003 	return result;
       
  1004 	}
       
  1005 
       
  1006 /**
       
  1007 Implementation of SecondThread test ESgresSecondThreadPanicImageGetInfoInvalidHandle
       
  1008 
       
  1009 @panic SGRES3 If the test is successful
       
  1010 
       
  1011 @return One of the system wide error codes
       
  1012 
       
  1013 @param RSgDriver An open RSgDriver for the test code to use
       
  1014  */
       
  1015 TInt SgTestSecondThread::PanicImageGetInfoInvalidHandle(RSgDriver& aSgDriver)
       
  1016 	{
       
  1017 	RSgImage image; 
       
  1018 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
  1019 	
       
  1020 	TSgImageInfo anotherInfo;
       
  1021 	image.GetInfo(anotherInfo); //should panic with SGRES 3
       
  1022 	aSgDriver.Close();
       
  1023 	return result;
       
  1024 	}
       
  1025 
       
  1026 /**
       
  1027 Implementation of SecondThread test ESgresSecondThreadPanicImageNoDriver
       
  1028 
       
  1029 @panic SGRES1 If the test is successful
       
  1030 
       
  1031 @return One of the system wide error codes or an enumeration of passed tests.
       
  1032 
       
  1033 @param RSgDriver An open RSgDriver for the test code to use
       
  1034  */
       
  1035 TInt SgTestSecondThread::PanicImageGetInfoNoDriver(RSgDriver& aSgDriver)
       
  1036 	{
       
  1037 	RSgImage image; 
       
  1038 	TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image);
       
  1039 	if(KErrNone != ret)
       
  1040 		{
       
  1041 		return ret;
       
  1042 		}
       
  1043 	RSgImage anotherImage;
       
  1044 	Mem::Copy(&anotherImage, &image, sizeof(image));
       
  1045 	image.Close();
       
  1046 	aSgDriver.Close();
       
  1047 	TSgImageInfo anotherInfo;
       
  1048 	anotherImage.GetInfo(anotherInfo); // should panic with SGRES 1
       
  1049 	return ret;
       
  1050 	}
       
  1051 
       
  1052 /**
       
  1053 Implementation of SecondThread test ESgresSecondThreadPanicImageGetAttributeInvalidHandle
       
  1054 
       
  1055 @panic SGRES3 If the test is successful
       
  1056 
       
  1057 @return One of the system wide error codes
       
  1058 
       
  1059 @param RSgDriver An open RSgDriver for the test code to use
       
  1060  */
       
  1061 TInt SgTestSecondThread::PanicImageGetAttributeInvalidHandle(RSgDriver& aSgDriver)
       
  1062 	{
       
  1063 	RSgImage image; 
       
  1064 	TInt result = CTSgTestStepBase::CreateImageAndReturnCopy(image);
       
  1065 	
       
  1066 	TInt attrib = KMaxTInt;
       
  1067 	image.GetAttribute(TUid::Uid(1), attrib); //Should panic with SGRES 3
       
  1068 	
       
  1069 	aSgDriver.Close();
       
  1070 	return result;
       
  1071 	}
       
  1072 
       
  1073 /**
       
  1074 Implementation of SecondThread test ESgresSecondThreadPanicImageGetAttributeNoDriver
       
  1075 
       
  1076 @panic SGRES1 If the test is successful
       
  1077 
       
  1078 @return One of the system wide error codes
       
  1079 
       
  1080 @param RSgDriver An open RSgDriver for the test code to use
       
  1081  */
       
  1082 TInt SgTestSecondThread::PanicImageGetAttributeNoDriver(RSgDriver& aSgDriver)
       
  1083 	{
       
  1084 	RSgImage image; 
       
  1085 	TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image);
       
  1086 	if(KErrNone != ret)
       
  1087 		{
       
  1088 		return ret;
       
  1089 		}
       
  1090 	RSgImage anotherImage;
       
  1091 	Mem::Copy(&anotherImage, &image, sizeof(image));
       
  1092 	image.Close();
       
  1093 	aSgDriver.Close();
       
  1094 	TInt attrib = KMaxTInt;
       
  1095 	TUid uid = { 0x12345678 };
       
  1096 	anotherImage.GetAttribute(uid, attrib); //Should panic with SGRES 1
       
  1097 	return ret;
       
  1098 	}
       
  1099 
       
  1100 /**
       
  1101 Implementation of SecondThread test ESgresSecondThreadMultipleThreadStressTest
       
  1102 
       
  1103 @return One of the system wide error codes
       
  1104 
       
  1105 @param TSgresTestInfo* The test parameters
       
  1106  */
       
  1107 TInt SgTestSecondThread::MultipleThreadStressTest(TSgThreadTestInfo* aInfo)
       
  1108 	{
       
  1109 	TInt result = 0;
       
  1110 	RSgImage image;
       
  1111 	for (TInt i = 0; i < 1000 && result == KErrNone; ++i)
       
  1112 		{
       
  1113 		TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image); 
       
  1114 		if (KErrNone != ret)
       
  1115 			{
       
  1116 			result = ret;
       
  1117 			break;
       
  1118 			}
       
  1119 
       
  1120 		const TInt KMaxOpenCount = 100;
       
  1121 		RSgImage images[KMaxOpenCount];
       
  1122 		TInt count = Math::Random() % KMaxOpenCount;
       
  1123 		for (TInt k = 0; k < count; ++k)
       
  1124 			{
       
  1125 			ret = images[k].Open(aInfo->iDrawableId);
       
  1126 			if (KErrNone != ret)
       
  1127 				{
       
  1128 				result = ret;
       
  1129 				break;
       
  1130 				}
       
  1131 			}
       
  1132 		image.Close();
       
  1133 		for (TInt k = 0; k < count; ++k)
       
  1134 			{
       
  1135 			images[k].Close();
       
  1136 			}
       
  1137 		}
       
  1138 	return result;
       
  1139 	}
       
  1140 
       
  1141 /**
       
  1142 Implementation of SecondThread test ESgresSecondThreadPanicAttributeArrayInvalidIndex
       
  1143 
       
  1144 @panic SGRES4 If the test is successful
       
  1145 
       
  1146 @param TSgresTestInfo* The test parameters
       
  1147  */
       
  1148 void SgTestSecondThread::PanicAttributeArrayInvalidIndexL()
       
  1149 	{
       
  1150 	TSgAttributeArray<5> attribArray;
       
  1151 	TSgAttribute attrib = attribArray[6]; //Should panic with SGRES 4
       
  1152 	}
       
  1153 
       
  1154 /**
       
  1155 Implementation of SecondThread test ESgresSecondThreadPanicAttributeArrayInvalidIndex2
       
  1156 
       
  1157 @panic SGRES4 If the test is successful
       
  1158 
       
  1159 @param TSgresTestInfo* The test parameters
       
  1160  */
       
  1161 void SgTestSecondThread::PanicAttributeArrayInvalidIndex2L()
       
  1162 	{
       
  1163 	TSgAttributeArray<5> attribArray;
       
  1164 	TSgAttribute attrib = attribArray[-1]; //Should panic with SGRES 4
       
  1165 	}
       
  1166 
       
  1167 /**
       
  1168 Implementation of SecondThread test ESgresSecondThreadPanicDriverCloseOpenResources
       
  1169 
       
  1170 @return One of the system wide error codes
       
  1171 
       
  1172 @param RSgImage* A closed or uninitialised RSgImage to use for image creation 
       
  1173  */
       
  1174 TInt SgTestSecondThread::CreatePassedImageL(RSgImage* aSgImage)
       
  1175 	{
       
  1176 	TSgImageInfo info;
       
  1177 	info.iSizeInPixels = TSize(8, 8);
       
  1178 	info.iUsage = ESgUsageBitOpenVgImage;
       
  1179 	info.iPixelFormat = EUidPixelFormatRGB_565;
       
  1180 	
       
  1181 	return aSgImage->Create(info, KCrossImageData, KCrossImageDataStride);
       
  1182 	}
       
  1183 
       
  1184 /**
       
  1185 Helper function which Creates an RSgImage and copies to into another RSgImage 
       
  1186 using Mem::Copy; the target of the copy is returned in the open state.
       
  1187 
       
  1188 @param aSgImage An uninitialised image which will have an SgImage Mem::Copied into it.
       
  1189 @return One of the system wide error codes.
       
  1190  */
       
  1191 TInt CTSgTestStepBase::CreateImageAndReturnCopy(RSgImage& aSgImage)
       
  1192 	{
       
  1193 	RSgImage image; 
       
  1194 	TInt ret = CreateImageWithParameters(8, 8, EUidPixelFormatRGB_565, ESgUsageBitOpenVgImage, image);
       
  1195 	if(KErrNone != ret)
       
  1196 		{
       
  1197 		return ret;
       
  1198 		}
       
  1199 	Mem::Copy(&aSgImage, &image, sizeof(image));
       
  1200 	image.Close();
       
  1201 	
       
  1202 	return ret;
       
  1203 	}