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