os/graphics/graphicshwdrivers/surfacemgr/test/src/tsurfacemanagermultithread.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
// Surface manager multi-threaded test code
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @test
sl@0
    21
 @internalComponent - Internal Symbian test code
sl@0
    22
*/
sl@0
    23
sl@0
    24
#include "tsurfacemanagermultithread.h"
sl@0
    25
#include <e32base.h>
sl@0
    26
#include <e32cons.h>
sl@0
    27
#include <e32test.h>
sl@0
    28
#include <e32std.h>
sl@0
    29
#include <e32cmn.h>
sl@0
    30
#include <e32def.h>	  
sl@0
    31
sl@0
    32
static TSurfaceId globalSurfaceId;	
sl@0
    33
static TInt testResult;
sl@0
    34
sl@0
    35
typedef CTSurfaceManagerMultiThread::TInfo TInfo;
sl@0
    36
sl@0
    37
CTSurfaceManagerMultiThread::CTSurfaceManagerMultiThread(CTestStep* aStep):
sl@0
    38
	CTGraphicsBase(aStep)
sl@0
    39
	{
sl@0
    40
	
sl@0
    41
	}
sl@0
    42
sl@0
    43
CTSurfaceManagerMultiThread::~CTSurfaceManagerMultiThread()
sl@0
    44
	{
sl@0
    45
	iSurfaceManager.Close();
sl@0
    46
	}
sl@0
    47
sl@0
    48
void CTSurfaceManagerMultiThread::RunTestCaseL(TInt aCurTestCase)
sl@0
    49
	{
sl@0
    50
	TInt procHandles1  =0;
sl@0
    51
	TInt threadHandles1=0;
sl@0
    52
	RThread().HandleCount(procHandles1, threadHandles1);
sl@0
    53
	((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
    54
	switch(aCurTestCase)
sl@0
    55
		{
sl@0
    56
/**
sl@0
    57
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0078
sl@0
    58
@SYMPREQ				PREQ1879, PREQ1007
sl@0
    59
@SYMREQ					REQ8222,REQ8223
sl@0
    60
@SYMTestPriority		High 
sl@0
    61
@SYMTestCaseDesc		Test accessing surface in another thread without opening it
sl@0
    62
						Thread 1: Create Surface 
sl@0
    63
						Thread 2: Map Surface - KErrNone (still accessible)
sl@0
    64
						Thread 2: SurfaceInfo - KErrNone (still accessible)
sl@0
    65
@SYMTestStatus			Implemented
sl@0
    66
@SYMTestActions			Call CreateSurface(),MapSurface(), SurfaceInfo()
sl@0
    67
@SYMTestExpectedResults The surface can be successfully accessed in other threads without first opening it.
sl@0
    68
*/
sl@0
    69
	case 1:
sl@0
    70
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0078"));
sl@0
    71
		TestAccessSurfaceWithoutOpeningL();
sl@0
    72
		break;
sl@0
    73
/**
sl@0
    74
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0079
sl@0
    75
@SYMPREQ				PREQ1879, PREQ1007
sl@0
    76
@SYMREQ					REQ8222,REQ8223
sl@0
    77
@SYMTestPriority		High 
sl@0
    78
@SYMTestCaseDesc		Test accessing a surface created in the existing shared chunk in another thread without opening it.
sl@0
    79
						Thread 1: Create a Surface in the new chunk with valid creation attributes
sl@0
    80
						Thread 1: Map the surface in the current process to get the chunk handle
sl@0
    81
						Thread 1: Create a new surface in the existing chunk with valid creation attributes
sl@0
    82
						Thread 2: Map the second Surface – KErrNone (still accessible)
sl@0
    83
						Thread 2: SurfaceInfo – KErrNone (still accessible)
sl@0
    84
@SYMTestStatus			Implemented
sl@0
    85
@SYMTestActions			Call CreateSurface(),MapSurface(), SurfaceInfo()
sl@0
    86
@SYMTestExpectedResults MapSurface, SurfaceInfo return KerrNone
sl@0
    87
*/	
sl@0
    88
	case 2:
sl@0
    89
        ((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0079"));
sl@0
    90
		TestAccessSurfaceInExistingSharedChunkL();
sl@0
    91
		break;
sl@0
    92
/**
sl@0
    93
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0080
sl@0
    94
@SYMPREQ				PREQ1879, PREQ1007
sl@0
    95
@SYMREQ					REQ8222,REQ8223
sl@0
    96
@SYMTestPriority		High 
sl@0
    97
@SYMTestCaseDesc		Test closing surface in another thread without opening it
sl@0
    98
						Thread 1: Create Surface 
sl@0
    99
						Thread 2: Close Surface - KErrNone
sl@0
   100
@SYMTestStatus			Implemented
sl@0
   101
@SYMTestActions			Call CreateSurface(),CloseSurface()
sl@0
   102
@SYMTestExpectedResults The surface can be successfully closed in other threads without first opening it.
sl@0
   103
*/
sl@0
   104
	case 3:
sl@0
   105
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0080"));
sl@0
   106
		TestCloseSurfaceWithoutOpeningL();
sl@0
   107
		break;
sl@0
   108
/**
sl@0
   109
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0081
sl@0
   110
@SYMPREQ				PREQ1879, PREQ1007
sl@0
   111
@SYMREQ					REQ8222,REQ8223
sl@0
   112
@SYMTestPriority		High 
sl@0
   113
@SYMTestCaseDesc		Test accessing an surface which is created in another thread but closed in current thread 
sl@0
   114
						Thread 2: Create Surface
sl@0
   115
						Thread 1: Close Surface - KerrNone
sl@0
   116
						Thread 2: Map Surface - KErrArgument
sl@0
   117
						Thread 2: SurfaceInfo - KErrArgument
sl@0
   118
@SYMTestStatus			Implemented
sl@0
   119
@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo()
sl@0
   120
@SYMTestExpectedResults The surface cant be accessd even after it is closed in other threads.
sl@0
   121
*/
sl@0
   122
	case 4:
sl@0
   123
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0081"));
sl@0
   124
		TestAccessSurfaceClosedThreadL();
sl@0
   125
		break;
sl@0
   126
/**
sl@0
   127
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0067
sl@0
   128
@SYMPREQ				PREQ1879, PREQ1007
sl@0
   129
@SYMREQ					REQ8222,REQ8223
sl@0
   130
@SYMTestPriority		High 
sl@0
   131
@SYMTestCaseDesc		Test closing surface created in the existing chunk in another thread without opening it 
sl@0
   132
						Thread 1: Create a Surface in a new shared chunk with valid attributes
sl@0
   133
						Thread 1: Map the surface in the process to get the shared chunk handle
sl@0
   134
						Thread 1: Create a new surface in the existing shared chunk
sl@0
   135
						Thread 2: Close the second surface – KErrNone (the second surface is deleted)
sl@0
   136
						Thread 2: Call SurfaceInfo to the first surface and it returns KErrNone, but it returns KErrArgument to the second surface.
sl@0
   137
						Thread 2: Close the first surface and check it returns KErrNone (the first surface is deleted).
sl@0
   138
						Thread 1: Call SurfaceInfo to both surfaces and return KErrArgument
sl@0
   139
						Thread 1: Check the chunk is still accessible by calling RChunk::Base() 
sl@0
   140
						Thread 1: Close the chunk handle  
sl@0
   141
@SYMTestStatus			Implemented
sl@0
   142
@SYMTestActions			Call CreateSurface(),CloseSurface()
sl@0
   143
@SYMTestExpectedResults CloseSurface returns KErrNone. The chunk handle is not closed even when both surfaces are deleted.
sl@0
   144
*/		
sl@0
   145
	case 5:
sl@0
   146
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0067"));
sl@0
   147
		TestCloseSurfaceExistingSharedChunkL();
sl@0
   148
		break;
sl@0
   149
sl@0
   150
/**
sl@0
   151
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0068
sl@0
   152
@SYMPREQ				PREQ1007
sl@0
   153
@SYMREQ					REQ8222,REQ8223
sl@0
   154
@SYMTestPriority		High 
sl@0
   155
@SYMTestCaseDesc		Test closing an surface which is already closed in other thread return KErrArgument 
sl@0
   156
						Thread 2: Create Surface
sl@0
   157
						Thread 1: Close Surface - KerrNone
sl@0
   158
						Thread 2: Close Surface - KErrArgument
sl@0
   159
@SYMTestStatus			Implemented
sl@0
   160
@SYMTestActions			Call CreateSurface(),CloseSurface()
sl@0
   161
@SYMTestExpectedResults The surface cant be closed again.
sl@0
   162
*/
sl@0
   163
	case 6:
sl@0
   164
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0068"));
sl@0
   165
		TestCloseSurfaceClosedThreadL();
sl@0
   166
		break;
sl@0
   167
/**
sl@0
   168
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0069
sl@0
   169
@SYMPREQ				PREQ1007
sl@0
   170
@SYMREQ					REQ8222,REQ8223
sl@0
   171
@SYMTestPriority		High 
sl@0
   172
@SYMTestCaseDesc		Test accessing an surface which is already opened and closed in another thread, given that the process still owns the surface 
sl@0
   173
						Thread 1: Create Surface
sl@0
   174
						Thread 2: Open Surface -- KErrNone
sl@0
   175
						Thread 2: Close Surface -- KErrNone
sl@0
   176
						Thread 1: Map Surface - KErrNone
sl@0
   177
						Thread 1: SurfaceInfo - KErrNone
sl@0
   178
@SYMTestStatus			Implemented
sl@0
   179
@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo, OpenSurface()
sl@0
   180
@SYMTestExpectedResults The surface is still accessible in the thread residing the owning process
sl@0
   181
*/
sl@0
   182
	case 7:
sl@0
   183
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0069"));
sl@0
   184
		TestAccessSurfaceOpenedClosedThreadL();
sl@0
   185
		break;
sl@0
   186
/**
sl@0
   187
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0070
sl@0
   188
@SYMPREQ				PREQ1007
sl@0
   189
@SYMREQ					REQ8222,REQ8223
sl@0
   190
@SYMTestPriority		High 
sl@0
   191
@SYMTestCaseDesc		Test closing an surface which is already opened and closed in another thread, given that the process still owns the surface
sl@0
   192
    					Thread 1: Create Surface
sl@0
   193
						Thread 2: Open Surface
sl@0
   194
						Thread 2: Close Surface
sl@0
   195
						Thread 1: Close Surface - KErrNone
sl@0
   196
@SYMTestStatus			Implemented
sl@0
   197
@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface()
sl@0
   198
@SYMTestExpectedResults The surface is still closible in the thread residing in the owning process
sl@0
   199
*/
sl@0
   200
	case 8:
sl@0
   201
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0070"));
sl@0
   202
		TestCloseSurfaceOpenedClosedThreadL();
sl@0
   203
		break;
sl@0
   204
/**
sl@0
   205
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0071
sl@0
   206
@SYMPREQ				PREQ1007
sl@0
   207
@SYMREQ					REQ8222,REQ8223
sl@0
   208
@SYMTestPriority		High 
sl@0
   209
@SYMTestCaseDesc		Test accessing surface in another thread when the opening thread is killed   
sl@0
   210
						Thread 1: Create Surface 
sl@0
   211
						Thread 2: Open Surface
sl@0
   212
						Thread 2: Kill the thread
sl@0
   213
						Thread 1: Map Surface - KErrNone
sl@0
   214
						Thread 1: Surface Info -- KErrNone
sl@0
   215
@SYMTestStatus			Implemented
sl@0
   216
@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo(), OpenSurface()
sl@0
   217
@SYMTestExpectedResults The surface is accessible when the opening thread is killed
sl@0
   218
*/
sl@0
   219
	case 9:
sl@0
   220
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0071"));
sl@0
   221
		TestAccessSurfaceOpenedKilledThreadL();
sl@0
   222
		break;
sl@0
   223
/**
sl@0
   224
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0072
sl@0
   225
@SYMPREQ				PREQ1007
sl@0
   226
@SYMREQ					REQ8222,REQ8223
sl@0
   227
@SYMTestPriority		High 
sl@0
   228
@SYMTestCaseDesc		Test closing surface in another thread when the opening thread is killed   
sl@0
   229
						Thread 1: Create Surface 
sl@0
   230
						Thread 2: Open Surface
sl@0
   231
						Thread 2: Kill the thread
sl@0
   232
						Thread 1: Close Surface - KErrNone
sl@0
   233
@SYMTestStatus			Implemented
sl@0
   234
@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface()
sl@0
   235
@SYMTestExpectedResults The surface is closible when the opening thread is killed
sl@0
   236
*/
sl@0
   237
	case 10:
sl@0
   238
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0072"));
sl@0
   239
		TestCloseSurfaceOpenedKilledThreadL();
sl@0
   240
		break;
sl@0
   241
/**
sl@0
   242
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0073
sl@0
   243
@SYMPREQ				PREQ1007
sl@0
   244
@SYMREQ					REQ8222,REQ8223
sl@0
   245
@SYMTestPriority		High 
sl@0
   246
@SYMTestCaseDesc		Test accessing surface in another thread when the creating thread is killed and it is closed in other threads
sl@0
   247
						Thread 2: Create Surface
sl@0
   248
						Thread 1: Close Surface
sl@0
   249
						Thread 2: Kill Thread
sl@0
   250
						Thread 1: Map Surface - KErrArgument
sl@0
   251
						Thread 1: Surface Info - KErrArgument
sl@0
   252
@SYMTestStatus			Implemented
sl@0
   253
@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo(),
sl@0
   254
@SYMTestExpectedResults The surface is accessible when the creating thread is killed and it is closed in other threads
sl@0
   255
*/
sl@0
   256
	case 11:
sl@0
   257
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0073"));
sl@0
   258
		TestAccessSurfaceCreateKilledThreadL();
sl@0
   259
		break;
sl@0
   260
/**
sl@0
   261
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0074
sl@0
   262
@SYMPREQ				PREQ1007
sl@0
   263
@SYMREQ					REQ8222,REQ8223
sl@0
   264
@SYMTestPriority		High 
sl@0
   265
@SYMTestCaseDesc		Test accessing surface in another thread when the creating thread is killed and it is closed in other threads
sl@0
   266
						Thread 2: Create Surface
sl@0
   267
						Thread 1: Close Surface
sl@0
   268
						Thread 2: Kill Thread
sl@0
   269
						Thread 1: Close Surface - KErrArgument
sl@0
   270
@SYMTestStatus			Implemented
sl@0
   271
@SYMTestActions			Call CreateSurface(),CloseSurface()
sl@0
   272
@SYMTestExpectedResults The surface is accessible when the creating thread is killed and it is closed in other threads
sl@0
   273
*/
sl@0
   274
	case 12:
sl@0
   275
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0074"));
sl@0
   276
		TestCloseSurfaceCreateKilledThreadL();
sl@0
   277
		break;
sl@0
   278
/**
sl@0
   279
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0075
sl@0
   280
@SYMPREQ				PREQ1007
sl@0
   281
@SYMREQ					REQ8222,REQ8223
sl@0
   282
@SYMTestPriority		High 
sl@0
   283
@SYMTestCaseDesc		Test closing on one thread doesn't prevent opening on other Threads, provided one Thread still owns surface
sl@0
   284
    					Thread 1: Create Surface
sl@0
   285
						Thread 2: Open Surface
sl@0
   286
						Thread 2: Close Surface
sl@0
   287
						Thread 3: Open Surface - KerrNone
sl@0
   288
						Thread 3: Map Surface - KerrNone
sl@0
   289
						Thread 3: SurfaceInfo -- KErrNone
sl@0
   290
@SYMTestStatus			Implemented
sl@0
   291
@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo(),
sl@0
   292
@SYMTestExpectedResults It is expected that closing on one thread doesn't prevent opening on other Threads, provided one Thread still owns surface
sl@0
   293
*/
sl@0
   294
	case 13:
sl@0
   295
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0075"));
sl@0
   296
		TestAccessSurfaceThreeThreadsL();
sl@0
   297
		break;	
sl@0
   298
/**
sl@0
   299
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0076
sl@0
   300
@SYMPREQ				PREQ1007
sl@0
   301
@SYMREQ					REQ8222,REQ8223
sl@0
   302
@SYMTestPriority		High 
sl@0
   303
@SYMTestCaseDesc		Test surface can be accessed from third thread when creating thread dies and second thread closes
sl@0
   304
    					Thread 2: Create Surface
sl@0
   305
						Thread 1: Open Surface
sl@0
   306
						Thread 3: Open Surface
sl@0
   307
						Thread 1: Close Surface
sl@0
   308
						Thread 2: Kill Thread
sl@0
   309
 					 	Thread 3: Close Surface
sl@0
   310
						Thread 3: Map Surface - KerrNone
sl@0
   311
						Thread 3: SurfaceInfo -- KErrNone
sl@0
   312
@SYMTestStatus			Implemented
sl@0
   313
@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo(), OpenSurface()
sl@0
   314
@SYMTestExpectedResults It is expected that surface can be accessed from third thread when creating thread dies and second thread closes
sl@0
   315
*/
sl@0
   316
	case 14:
sl@0
   317
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0076"));
sl@0
   318
		TestAccessSurfaceDieCloseOtherThreadsL();
sl@0
   319
		break;
sl@0
   320
/**
sl@0
   321
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0077
sl@0
   322
@SYMPREQ				PREQ1007
sl@0
   323
@SYMREQ					REQ8222,REQ8223
sl@0
   324
@SYMTestPriority		High 
sl@0
   325
@SYMTestCaseDesc		Test that the surface can be opened from the third Thread after creating thread dies and second and third thread close the surface
sl@0
   326
   						Thread 2: Create Surface
sl@0
   327
						Thread 1: Open Surface
sl@0
   328
						Thread 3: Open Surface
sl@0
   329
						Thread 1: Close Surface
sl@0
   330
						Thread 2: Kill Thread
sl@0
   331
 					    Thread 3: Close Surface
sl@0
   332
						Thread 3: Open Surface - KerrNone
sl@0
   333
@SYMTestStatus			Implemented
sl@0
   334
@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface()
sl@0
   335
@SYMTestExpectedResults It is expected that the surface can be opened from the third Thread after creating thread dies and second and third thread close the surface
sl@0
   336
*/
sl@0
   337
	case 15:
sl@0
   338
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0077"));
sl@0
   339
		TestOpenSurfaceDieCloseOtherThreadsL();
sl@0
   340
		break;
sl@0
   341
	default:
sl@0
   342
		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   343
		((CTSurfaceManagerMultiThreadStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   344
		TestComplete();
sl@0
   345
		break;
sl@0
   346
		}
sl@0
   347
	((CTSurfaceManagerMultiThreadStep*)iStep)->RecordTestResultL();
sl@0
   348
	// Handle check
sl@0
   349
	TInt procHandles2  =0;
sl@0
   350
	TInt threadHandles2=0;
sl@0
   351
	RThread().HandleCount(procHandles2,threadHandles2);
sl@0
   352
	if (threadHandles1 != threadHandles2)
sl@0
   353
		{
sl@0
   354
		User::Leave(KErrGeneral);  // Thread-owned handles not closed
sl@0
   355
		}
sl@0
   356
 	}
sl@0
   357
sl@0
   358
void CTSurfaceManagerMultiThread::CloseSurfaceWhenLeave(TAny* aInfo) 
sl@0
   359
	{
sl@0
   360
	TInt err1 = ((TInfo*)aInfo)->iSurfaceManager.CloseSurface(((TInfo*)aInfo)->iSurfaceId);
sl@0
   361
	TInt err2 = ((TInfo*)aInfo)->iSurfaceManager.CloseSurface(((TInfo*)aInfo)->iSurfaceIdNew);
sl@0
   362
	if (err1!=KErrNone || err2!=KErrNone)
sl@0
   363
	   	RDebug::Print(_L("Error closing surfaces err1= %d, err2= %d\n"),err1,err2);	
sl@0
   364
	}
sl@0
   365
sl@0
   366
void CTSurfaceManagerMultiThread::TestAccessSurfaceWithoutOpeningL()
sl@0
   367
	{
sl@0
   368
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
   369
    
sl@0
   370
	// Setup attributes
sl@0
   371
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   372
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
   373
	attributes.iSize = TSize(480,16);
sl@0
   374
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
   375
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
   376
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
   377
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
   378
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
   379
sl@0
   380
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
   381
	attributes.iHintCount = 2;
sl@0
   382
	attributes.iSurfaceHints = hints;
sl@0
   383
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
   384
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
   385
	
sl@0
   386
	attributes.iContiguous = ETrue;
sl@0
   387
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
   388
	attributes.iMappable = ETrue;
sl@0
   389
	
sl@0
   390
	// Test create surface doesn't return an error
sl@0
   391
	TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
sl@0
   392
    // Logging info   
sl@0
   393
    INFO_PRINTF1(_L("Test accessing surface in another thread without opening it\r\n"));
sl@0
   394
    // Create a semaphore
sl@0
   395
	RSemaphore sem;
sl@0
   396
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
   397
	CleanupClosePushL(sem);	
sl@0
   398
	
sl@0
   399
	// Create a second thread in the current process and opens the handle
sl@0
   400
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
   401
	iInfo.iSurfaceId = iSurfaceId;
sl@0
   402
	iInfo.iSurfaceIdNew = TSurfaceId::CreateNullId();
sl@0
   403
	iInfo.iThreadTestCase = EMapSurfaceInfo;		
sl@0
   404
	// Create a TCleanupItem object
sl@0
   405
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
   406
		
sl@0
   407
    RThread thread1;
sl@0
   408
    _LIT(KNameThreadSecond1, "Test_SurfaceManager_ThreadSecond1");
sl@0
   409
	User::LeaveIfError(thread1.Create(KNameThreadSecond1,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
   410
   	CleanupStack::Pop();
sl@0
   411
    // Launch second thread
sl@0
   412
	TRequestStatus statusThreadSecond;
sl@0
   413
	thread1.Logon(statusThreadSecond);
sl@0
   414
	thread1.SetPriority(EPriorityLess);
sl@0
   415
	thread1.Resume();	
sl@0
   416
	testResult = EAllZero;
sl@0
   417
	// Passes control to the second process
sl@0
   418
	sem.Wait();
sl@0
   419
	thread1.Suspend();
sl@0
   420
sl@0
   421
	// Test results in second thread
sl@0
   422
	TEST (testResult = (EMapSurfaceTestPassed | ESurfaceInfoTestPassed));
sl@0
   423
sl@0
   424
	// Pass control off to the second process again
sl@0
   425
	thread1.Resume();
sl@0
   426
sl@0
   427
	// Wait for a second for the second thread to terminate
sl@0
   428
	User::WaitForRequest(statusThreadSecond);
sl@0
   429
sl@0
   430
	//Close the handles
sl@0
   431
    CleanupStack::PopAndDestroy(1, &sem);  //invoke surface manager to close the surface also close the handle to RSemaphore
sl@0
   432
    thread1.Close();
sl@0
   433
    iSurfaceManager.Close();
sl@0
   434
	}
sl@0
   435
sl@0
   436
void CTSurfaceManagerMultiThread::TestAccessSurfaceInExistingSharedChunkL()
sl@0
   437
    {
sl@0
   438
    // Logging info   
sl@0
   439
    INFO_PRINTF1(_L("Test accessing a surface created in the existing shared chunk in another thread without opening it\r\n"));
sl@0
   440
sl@0
   441
    User::LeaveIfError(iSurfaceManager.Open());
sl@0
   442
    
sl@0
   443
    // Setup attributes 
sl@0
   444
    
sl@0
   445
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   446
    RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
   447
sl@0
   448
    attributes.iSize = TSize(100,100);
sl@0
   449
    attributes.iBuffers = 1;                // number of buffers in the surface
sl@0
   450
    attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;     // 2bpp
sl@0
   451
    attributes.iStride = 400;               // Number of bytes between start of one line and start of next
sl@0
   452
    attributes.iOffsetToFirstBuffer = 0;    // way of reserving space before the surface pixel data
sl@0
   453
    attributes.iAlignment = 2;          // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
   454
sl@0
   455
    RSurfaceManager::THintPair hints[2];    // two hint pairs specified
sl@0
   456
    attributes.iHintCount = 2;
sl@0
   457
    attributes.iSurfaceHints = hints;
sl@0
   458
    hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
   459
    hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
   460
    
sl@0
   461
    attributes.iContiguous = ETrue;
sl@0
   462
    attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
   463
    attributes.iOffsetBetweenBuffers = 0;
sl@0
   464
    attributes.iMappable = ETrue;
sl@0
   465
sl@0
   466
    // Test create surface doesn't return an error
sl@0
   467
    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
sl@0
   468
    
sl@0
   469
    //Map the surface in the current processs
sl@0
   470
    RChunk handle;
sl@0
   471
    TEST(KErrNone == iSurfaceManager.MapSurface(iSurfaceId,handle));
sl@0
   472
    
sl@0
   473
    // Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
sl@0
   474
    RSurfaceManager::TSurfaceCreationAttributesBuf buff;
sl@0
   475
    RSurfaceManager::TSurfaceCreationAttributes& attributesNew = buff();
sl@0
   476
sl@0
   477
    attributesNew.iSize = TSize(480,16);
sl@0
   478
    attributesNew.iBuffers = 2;             // number of buffers in the surface
sl@0
   479
    attributesNew.iPixelFormat = EUidPixelFormatYUV_422Reversed;        // 2bpp
sl@0
   480
    attributesNew.iStride = 1013;               // Number of bytes between start of one line and start of next
sl@0
   481
    attributesNew.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
sl@0
   482
    
sl@0
   483
    attributesNew.iHintCount = 1;
sl@0
   484
    attributesNew.iSurfaceHints = hints;
sl@0
   485
    hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
sl@0
   486
    
sl@0
   487
    attributesNew.iAlignment = 2;
sl@0
   488
    attributesNew.iOffsetBetweenBuffers = 0;
sl@0
   489
    attributes.iMappable = ETrue;
sl@0
   490
    
sl@0
   491
    // Test create surface doesn't return an error
sl@0
   492
    // For the time being KErrArgument will be returned as the core codes are
sl@0
   493
    // not ready to check the passed in shared chunk handle.
sl@0
   494
    TEST(KErrNone == iSurfaceManager.CreateSurface(buff, iSurfaceIdNew, handle));
sl@0
   495
sl@0
   496
sl@0
   497
    // Create a semaphore
sl@0
   498
    RSemaphore sem;
sl@0
   499
    TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
   500
    CleanupClosePushL(sem); 
sl@0
   501
    
sl@0
   502
    // Create a second thread in the current process and opens the handle
sl@0
   503
    iInfo.iSurfaceManager = iSurfaceManager;
sl@0
   504
    iInfo.iSurfaceId = iSurfaceIdNew;
sl@0
   505
    iInfo.iSurfaceIdNew = iSurfaceId;
sl@0
   506
    iInfo.iThreadTestCase = EMapSurfaceInfo;    
sl@0
   507
    // Create a TCleanupItem object
sl@0
   508
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
   509
    
sl@0
   510
    RThread thread2;
sl@0
   511
    _LIT(KNameThreadSecond2, "Test_SurfaceManager_ThreadSecond2");
sl@0
   512
    User::LeaveIfError(thread2.Create(KNameThreadSecond2,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
   513
 
sl@0
   514
    CleanupStack::Pop();
sl@0
   515
    // Launch second thread
sl@0
   516
    TRequestStatus statusThreadSecond;
sl@0
   517
    thread2.Logon(statusThreadSecond);
sl@0
   518
    thread2.SetPriority(EPriorityLess);
sl@0
   519
    thread2.Resume();   
sl@0
   520
    testResult = EAllZero;
sl@0
   521
    // Passes control to the second process
sl@0
   522
    sem.Wait();
sl@0
   523
    thread2.Suspend();
sl@0
   524
sl@0
   525
    // Test results in second thread
sl@0
   526
    TEST (testResult = (EMapSurfaceTestPassed | ESurfaceInfoTestPassed));
sl@0
   527
sl@0
   528
    // Pass control off to the second process again
sl@0
   529
    thread2.Resume();
sl@0
   530
sl@0
   531
    // Wait for a second for the second thread to terminate
sl@0
   532
    User::WaitForRequest(statusThreadSecond);
sl@0
   533
    
sl@0
   534
    //Close the handles
sl@0
   535
    CleanupStack::PopAndDestroy(1, &sem);  //invoke surface manager to close the surface also close the handle to RSemaphore
sl@0
   536
    handle.Close();
sl@0
   537
    thread2.Close();
sl@0
   538
    iSurfaceManager.Close();
sl@0
   539
    
sl@0
   540
    }
sl@0
   541
sl@0
   542
void CTSurfaceManagerMultiThread::TestCloseSurfaceWithoutOpeningL()
sl@0
   543
	{
sl@0
   544
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
   545
    
sl@0
   546
	// Setup attributes
sl@0
   547
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   548
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
   549
	
sl@0
   550
	attributes.iSize = TSize(480,16);
sl@0
   551
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
   552
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
   553
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
   554
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
   555
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
   556
sl@0
   557
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
   558
	attributes.iHintCount = 2;
sl@0
   559
	attributes.iSurfaceHints = hints;
sl@0
   560
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
   561
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
   562
	
sl@0
   563
	attributes.iContiguous = ETrue;
sl@0
   564
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
   565
	attributes.iMappable = ETrue;
sl@0
   566
	
sl@0
   567
	// Test create surface doesn't return an error
sl@0
   568
    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
sl@0
   569
   
sl@0
   570
    INFO_PRINTF1(_L("Test closing surface in another thread without opening it\r\n"));
sl@0
   571
	
sl@0
   572
	// Create a semaphore
sl@0
   573
	RSemaphore sem;
sl@0
   574
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
   575
   	CleanupClosePushL(sem);	
sl@0
   576
sl@0
   577
  	// Creates a second thread in the current process and opens the handle
sl@0
   578
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
   579
	iInfo.iSurfaceId = iSurfaceId;
sl@0
   580
	iInfo.iThreadTestCase = ECloseSurfaces;	
sl@0
   581
   	// Create a TCleanupItem object
sl@0
   582
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
   583
sl@0
   584
    RThread thread3;
sl@0
   585
    _LIT(KNameThreadSecond3, "Test_SurfaceManager_ThreadSecond3");
sl@0
   586
	User::LeaveIfError(thread3.Create(KNameThreadSecond3,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
   587
    CleanupStack::Pop();
sl@0
   588
    // Launch second thread to close the surface
sl@0
   589
	TRequestStatus statusThreadSecond;
sl@0
   590
	thread3.Logon(statusThreadSecond);
sl@0
   591
	thread3.SetPriority(EPriorityLess);
sl@0
   592
	thread3.Resume();	
sl@0
   593
	testResult = EAllZero;
sl@0
   594
	// Passes control to the second thread
sl@0
   595
	sem.Wait();
sl@0
   596
	thread3.Suspend();
sl@0
   597
sl@0
   598
	// Test the results in the second thread
sl@0
   599
	TEST(testResult == ECloseSurfaceTestPassed);
sl@0
   600
	
sl@0
   601
	thread3.Resume();
sl@0
   602
	// Wait for a second for the second process to terminate
sl@0
   603
	User::WaitForRequest(statusThreadSecond);
sl@0
   604
	
sl@0
   605
	//Close the handle
sl@0
   606
    CleanupStack::PopAndDestroy(1, &sem);
sl@0
   607
    thread3.Close();
sl@0
   608
	iSurfaceManager.Close();
sl@0
   609
	}
sl@0
   610
sl@0
   611
void CTSurfaceManagerMultiThread::TestAccessSurfaceClosedThreadL()
sl@0
   612
	{
sl@0
   613
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
   614
    // Logging info
sl@0
   615
    INFO_PRINTF1(_L("Test accessing an surface which is created in another thread but closed in current thread\r\n"));
sl@0
   616
    
sl@0
   617
    // Create a semaphore
sl@0
   618
	RSemaphore sem;
sl@0
   619
	RSemaphore semMain;
sl@0
   620
	
sl@0
   621
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
   622
    CleanupClosePushL(sem);	
sl@0
   623
    TEST(KErrNone == semMain.CreateGlobal(KMainThreadSemaphore, 0));
sl@0
   624
    CleanupClosePushL(semMain);	
sl@0
   625
sl@0
   626
	// Creates a second thread in the current process and opens the handle
sl@0
   627
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
   628
	iInfo.iSurfaceId = iSurfaceId;
sl@0
   629
	iInfo.iThreadTestCase = ECreateSurfaceMapInfo;	
sl@0
   630
	// Create a TCleanupItem object
sl@0
   631
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
   632
sl@0
   633
    RThread thread4;
sl@0
   634
    _LIT(KNameThreadSecond4, "Test_SurfaceManager_ThreadSecond4");
sl@0
   635
	User::LeaveIfError(thread4.Create(KNameThreadSecond4,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
   636
    CleanupStack::Pop();
sl@0
   637
    // Launch the second trhead
sl@0
   638
	TRequestStatus statusThreadSecond;
sl@0
   639
	thread4.Logon(statusThreadSecond);
sl@0
   640
	thread4.SetPriority(EPriorityLess);
sl@0
   641
	thread4.Resume();	
sl@0
   642
    
sl@0
   643
    testResult = EAllZero;
sl@0
   644
  	// Passes control to the second process
sl@0
   645
    sem.Wait(); 
sl@0
   646
	// Test creating surface in second thread
sl@0
   647
   	TEST(testResult == ECreateSurfaceTestPassed);
sl@0
   648
   	// Reset testResult
sl@0
   649
    testResult = EAllZero;
sl@0
   650
    // Test closing surface
sl@0
   651
    iSurfaceId = globalSurfaceId;
sl@0
   652
	TEST(KErrNone == iSurfaceManager.CloseSurface(globalSurfaceId));
sl@0
   653
	semMain.Signal();
sl@0
   654
    // Wait the second thread to terminate
sl@0
   655
    User::WaitForRequest(statusThreadSecond);
sl@0
   656
sl@0
   657
	// Test mapsurface and surfaceinfo executed in the second thread
sl@0
   658
	TEST(testResult == (EMapSurfaceTestFailed|ESurfaceInfoTestFailed));
sl@0
   659
	// Close all the handles
sl@0
   660
    CleanupStack::PopAndDestroy(2, &sem);
sl@0
   661
    thread4.Close();
sl@0
   662
	iSurfaceManager.Close();
sl@0
   663
sl@0
   664
	}
sl@0
   665
sl@0
   666
void CTSurfaceManagerMultiThread::TestCloseSurfaceExistingSharedChunkL()
sl@0
   667
    {
sl@0
   668
    // Logging info   
sl@0
   669
    INFO_PRINTF1(_L("Test closing surface created in the existing chunk in another thread without opening it\r\n"));
sl@0
   670
 
sl@0
   671
    User::LeaveIfError(iSurfaceManager.Open());
sl@0
   672
    // Setup attributes 
sl@0
   673
    
sl@0
   674
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   675
    RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
   676
sl@0
   677
    attributes.iSize = TSize(100,100);
sl@0
   678
    attributes.iBuffers = 1;                // number of buffers in the surface
sl@0
   679
    attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;     // 2bpp
sl@0
   680
    attributes.iStride = 400;               // Number of bytes between start of one line and start of next
sl@0
   681
    attributes.iOffsetToFirstBuffer = 0;    // way of reserving space before the surface pixel data
sl@0
   682
    attributes.iAlignment = 2;          // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
   683
sl@0
   684
    RSurfaceManager::THintPair hints[2];    // two hint pairs specified
sl@0
   685
    attributes.iHintCount = 2;
sl@0
   686
    attributes.iSurfaceHints = hints;
sl@0
   687
    hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
   688
    hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
   689
sl@0
   690
    attributes.iContiguous = ETrue;
sl@0
   691
    attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
   692
    attributes.iOffsetBetweenBuffers = 0;
sl@0
   693
    attributes.iMappable = ETrue;
sl@0
   694
    
sl@0
   695
    // Test create surface doesn't return an error
sl@0
   696
    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
sl@0
   697
    
sl@0
   698
    //Map the surface in the current processs
sl@0
   699
    RChunk handle;
sl@0
   700
    TEST(KErrNone == iSurfaceManager.MapSurface(iSurfaceId,handle));
sl@0
   701
    
sl@0
   702
    // Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
sl@0
   703
    RSurfaceManager::TSurfaceCreationAttributesBuf buff;
sl@0
   704
    RSurfaceManager::TSurfaceCreationAttributes& attributesNew = buff();
sl@0
   705
sl@0
   706
    attributesNew.iSize = TSize(480,16);
sl@0
   707
    attributesNew.iBuffers = 2;             // number of buffers in the surface
sl@0
   708
    attributesNew.iPixelFormat = EUidPixelFormatYUV_422Reversed;        // 2bpp
sl@0
   709
    attributesNew.iStride = 1013;               // Number of bytes between start of one line and start of next
sl@0
   710
    attributesNew.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
sl@0
   711
    
sl@0
   712
    attributesNew.iHintCount = 1;
sl@0
   713
    attributesNew.iSurfaceHints = hints;
sl@0
   714
    hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
sl@0
   715
sl@0
   716
    attributesNew.iAlignment = 2;
sl@0
   717
    attributesNew.iOffsetBetweenBuffers = 0;
sl@0
   718
    attributesNew.iMappable = ETrue;
sl@0
   719
sl@0
   720
    // Test create surface doesn't return an error
sl@0
   721
    // For the time being KErrArgument will be returned as the core codes are
sl@0
   722
    // not ready to check the passed in shared chunk handle.
sl@0
   723
    TEST(KErrNone == iSurfaceManager.CreateSurface(buff, iSurfaceIdNew, handle));
sl@0
   724
sl@0
   725
    // Create a semaphore
sl@0
   726
    RSemaphore sem;
sl@0
   727
    TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
   728
    CleanupClosePushL(sem); 
sl@0
   729
    
sl@0
   730
    // Create a second thread in the current process and opens the handle
sl@0
   731
    iInfo.iSurfaceManager = iSurfaceManager;
sl@0
   732
    iInfo.iSurfaceId = iSurfaceId;
sl@0
   733
    iInfo.iSurfaceIdNew = iSurfaceIdNew;
sl@0
   734
    iInfo.iThreadTestCase = ECloseBothSurfaces; 
sl@0
   735
    // Create a TCleanupItem object
sl@0
   736
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
   737
        
sl@0
   738
    RThread thread5;
sl@0
   739
    _LIT(KNameThreadSecond5, "Test_SurfaceManager_ThreadSecond5");
sl@0
   740
    User::LeaveIfError(thread5.Create(KNameThreadSecond5,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
   741
    CleanupStack::Pop();
sl@0
   742
    // Launch second thread
sl@0
   743
    TRequestStatus statusThreadSecond;
sl@0
   744
    thread5.Logon(statusThreadSecond);
sl@0
   745
    thread5.SetPriority(EPriorityLess);
sl@0
   746
    thread5.Resume();   
sl@0
   747
    testResult = EAllZero;
sl@0
   748
    // Passes control to the second process
sl@0
   749
    sem.Wait();
sl@0
   750
    thread5.Suspend();
sl@0
   751
sl@0
   752
    // Test results in second thread
sl@0
   753
    TEST (testResult = (ECloseSurfaceTestPassed | ESurfaceInfoTestPassed | ESurfaceInfoTestPassed2));
sl@0
   754
    RSurfaceManager::TInfoBuf infoBuf;
sl@0
   755
    TEST (KErrArgument == iSurfaceManager.SurfaceInfo(iSurfaceId, infoBuf));
sl@0
   756
    TEST (KErrArgument == iSurfaceManager.SurfaceInfo(iSurfaceIdNew, infoBuf));
sl@0
   757
sl@0
   758
    // Pass control off to the second process again
sl@0
   759
    thread5.Resume();
sl@0
   760
sl@0
   761
    // Wait for a second for the second thread to terminate
sl@0
   762
    User::WaitForRequest(statusThreadSecond);
sl@0
   763
sl@0
   764
    CleanupStack::PopAndDestroy(1, &sem);  //invoke surface manager to close the surface also close the handle to RSemaphore
sl@0
   765
    handle.Close();
sl@0
   766
    thread5.Close();
sl@0
   767
    iSurfaceManager.Close();
sl@0
   768
    }
sl@0
   769
sl@0
   770
void CTSurfaceManagerMultiThread::TestCloseSurfaceClosedThreadL()
sl@0
   771
	{
sl@0
   772
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
   773
    
sl@0
   774
	// Setup attributes
sl@0
   775
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   776
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
   777
	
sl@0
   778
	attributes.iSize = TSize(480,16);
sl@0
   779
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
   780
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
   781
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
   782
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
   783
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
   784
sl@0
   785
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
   786
	attributes.iHintCount = 2;
sl@0
   787
	attributes.iSurfaceHints = hints;
sl@0
   788
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
   789
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
   790
	
sl@0
   791
	attributes.iContiguous = ETrue;
sl@0
   792
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
   793
	attributes.iOffsetBetweenBuffers = 0;
sl@0
   794
	attributes.iMappable = ETrue;
sl@0
   795
    // Logging info
sl@0
   796
    INFO_PRINTF1(_L("Test closing an surface which is already closed in other thread return KErrArgument\r\n"));
sl@0
   797
    // Create a semaphore
sl@0
   798
	RSemaphore sem;
sl@0
   799
	RSemaphore semMain;
sl@0
   800
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
   801
    CleanupClosePushL(sem);	
sl@0
   802
    TEST(KErrNone == semMain.CreateGlobal(KMainThreadSemaphore, 0));
sl@0
   803
    CleanupClosePushL(semMain);	
sl@0
   804
sl@0
   805
 	// Creates a second thread in the current process and opens the handle
sl@0
   806
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
   807
	iInfo.iSurfaceId = iSurfaceId;
sl@0
   808
	iInfo.iThreadTestCase = ECreateSurfaceClose;	
sl@0
   809
	
sl@0
   810
	// Create a TCleanupItem object
sl@0
   811
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
   812
sl@0
   813
    RThread thread6;
sl@0
   814
    _LIT(KNameThreadSecond6, "Test_SurfaceManager_ThreadSecond6");
sl@0
   815
	User::LeaveIfError(thread6.Create(KNameThreadSecond6,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
   816
    CleanupStack::Pop();
sl@0
   817
    // Launch second thread
sl@0
   818
	TRequestStatus statusThreadSecond;
sl@0
   819
	thread6.Logon(statusThreadSecond);
sl@0
   820
	thread6.SetPriority(EPriorityLess);
sl@0
   821
	thread6.Resume();	
sl@0
   822
	testResult = EAllZero;
sl@0
   823
  	// Passes control to the second thread
sl@0
   824
    sem.Wait(); 
sl@0
   825
    // Test creating surface in second thread
sl@0
   826
   	TEST(testResult == ECreateSurfaceTestPassed);
sl@0
   827
   	testResult = EAllZero;
sl@0
   828
    // Test closing surface
sl@0
   829
    iSurfaceId = globalSurfaceId;
sl@0
   830
	TEST(KErrNone == iSurfaceManager.CloseSurface(globalSurfaceId));
sl@0
   831
    	
sl@0
   832
	semMain.Signal();
sl@0
   833
	// Wait for a second for the second process to terminate
sl@0
   834
    User::WaitForRequest(statusThreadSecond);
sl@0
   835
sl@0
   836
    TEST(testResult == ECloseSurfaceTestFailed);
sl@0
   837
    // Close all the handles
sl@0
   838
    CleanupStack::PopAndDestroy(2, &sem);
sl@0
   839
    thread6.Close();
sl@0
   840
	iSurfaceManager.Close();
sl@0
   841
	}
sl@0
   842
sl@0
   843
void CTSurfaceManagerMultiThread::TestAccessSurfaceOpenedClosedThreadL()
sl@0
   844
	{
sl@0
   845
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
   846
    
sl@0
   847
	// Setup attributes
sl@0
   848
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   849
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
   850
	
sl@0
   851
	attributes.iSize = TSize(480,16);
sl@0
   852
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
   853
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
   854
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
   855
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
   856
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
   857
sl@0
   858
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
   859
	attributes.iHintCount = 2;
sl@0
   860
	attributes.iSurfaceHints = hints;
sl@0
   861
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
   862
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
   863
	
sl@0
   864
	attributes.iContiguous = ETrue;
sl@0
   865
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
   866
	attributes.iOffsetBetweenBuffers = 0;
sl@0
   867
	attributes.iMappable = ETrue;
sl@0
   868
	
sl@0
   869
	// Test create surface doesn't return an error
sl@0
   870
	TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
sl@0
   871
    // Logging info
sl@0
   872
    INFO_PRINTF1(_L("Test accessing an surface which is already opened and closed in another thread, given that the process still owns the surface\r\n"));
sl@0
   873
 	// Create a semaphore
sl@0
   874
	RSemaphore sem;
sl@0
   875
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
   876
    CleanupClosePushL(sem);	
sl@0
   877
sl@0
   878
	// Creates a second thread in the current process and opens the handle
sl@0
   879
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
   880
	iInfo.iSurfaceId = iSurfaceId;
sl@0
   881
	iInfo.iThreadTestCase = EOpenCloseSurface;	
sl@0
   882
 	// Create a TCleanupItem object
sl@0
   883
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
   884
	
sl@0
   885
    RThread thread7;
sl@0
   886
    _LIT(KNameThreadSecond7, "Test_SurfaceManager_ThreadSecond7");
sl@0
   887
	User::LeaveIfError(thread7.Create(KNameThreadSecond7,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
   888
   	CleanupStack::Pop();
sl@0
   889
   	
sl@0
   890
    // Launch the second thread
sl@0
   891
	TRequestStatus statusThreadSecond;
sl@0
   892
	thread7.Logon(statusThreadSecond);
sl@0
   893
	thread7.SetPriority(EPriorityLess);
sl@0
   894
	thread7.Resume();
sl@0
   895
	testResult = EAllZero;
sl@0
   896
	sem.Wait();	  
sl@0
   897
	
sl@0
   898
	thread7.Suspend();
sl@0
   899
	// Test open and close surface in the second thread
sl@0
   900
	TEST(testResult == (EOpenSurfaceTestPassed|ECloseSurfaceTestPassed));
sl@0
   901
	
sl@0
   902
	RChunk handle;
sl@0
   903
	// To prove killing threads doesnt affect the ref count...
sl@0
   904
	TEST(KErrNone == iSurfaceManager.MapSurface(iSurfaceId, handle));
sl@0
   905
	handle.Close();
sl@0
   906
	
sl@0
   907
	RSurfaceManager::TInfoBuf infoBuf;
sl@0
   908
	TEST(KErrNone ==iSurfaceManager.SurfaceInfo(iSurfaceId, infoBuf));
sl@0
   909
	
sl@0
   910
	thread7.Resume();
sl@0
   911
	
sl@0
   912
	// Wait for a second for the second process to terminate
sl@0
   913
    User::WaitForRequest(statusThreadSecond);
sl@0
   914
sl@0
   915
	// Close all the handles
sl@0
   916
    CleanupStack::PopAndDestroy(1, &sem);
sl@0
   917
    thread7.Close();
sl@0
   918
	iSurfaceManager.Close();
sl@0
   919
	}	
sl@0
   920
sl@0
   921
void CTSurfaceManagerMultiThread::TestCloseSurfaceOpenedClosedThreadL()
sl@0
   922
	{
sl@0
   923
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
   924
    
sl@0
   925
	// Setup attributes
sl@0
   926
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   927
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
   928
	
sl@0
   929
	attributes.iSize = TSize(480,16);
sl@0
   930
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
   931
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
   932
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
   933
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
   934
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
   935
sl@0
   936
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
   937
	attributes.iHintCount = 2;
sl@0
   938
	attributes.iSurfaceHints = hints;
sl@0
   939
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
   940
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
   941
	
sl@0
   942
	attributes.iContiguous = ETrue;
sl@0
   943
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
   944
	attributes.iOffsetBetweenBuffers = 0;
sl@0
   945
	attributes.iMappable = ETrue;
sl@0
   946
sl@0
   947
	// Test create surface doesn't return an error
sl@0
   948
    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
sl@0
   949
    
sl@0
   950
    INFO_PRINTF1(_L("Test closing an surface which is already opened and closed in another thread, given that the process still owns the surface\r\n"));
sl@0
   951
	RSemaphore sem;
sl@0
   952
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
   953
   	CleanupClosePushL(sem);
sl@0
   954
sl@0
   955
	// Creates a second thread in the current process and opens the handle
sl@0
   956
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
   957
	iInfo.iSurfaceId = iSurfaceId;
sl@0
   958
	iInfo.iThreadTestCase = EOpenCloseSurface;	
sl@0
   959
 
sl@0
   960
	// Create a TCleanupItem object
sl@0
   961
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
   962
sl@0
   963
    RThread thread8;
sl@0
   964
    _LIT(KNameThreadSecond8, "Test_SurfaceManager_ThreadSecond8");
sl@0
   965
	User::LeaveIfError(thread8.Create(KNameThreadSecond8,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
   966
    CleanupStack::Pop();
sl@0
   967
	TRequestStatus statusThreadSecond;
sl@0
   968
	thread8.Logon(statusThreadSecond);
sl@0
   969
	thread8.SetPriority(EPriorityLess);
sl@0
   970
	thread8.Resume();
sl@0
   971
	testResult = EAllZero;
sl@0
   972
	sem.Wait();	
sl@0
   973
	thread8.Suspend();
sl@0
   974
	// Test open and close surface in the second thread
sl@0
   975
	TEST(testResult == (EOpenSurfaceTestPassed|ECloseSurfaceTestPassed));
sl@0
   976
sl@0
   977
	thread8.Resume();
sl@0
   978
	// Wait for a second for the second process to terminate
sl@0
   979
    User::WaitForRequest(statusThreadSecond);
sl@0
   980
sl@0
   981
	// Close all the handles 
sl@0
   982
    CleanupStack::PopAndDestroy(1, &sem);
sl@0
   983
    thread8.Close();
sl@0
   984
	iSurfaceManager.Close();
sl@0
   985
	}
sl@0
   986
sl@0
   987
void CTSurfaceManagerMultiThread::TestAccessSurfaceOpenedKilledThreadL()
sl@0
   988
	{
sl@0
   989
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
   990
    
sl@0
   991
	// Setup attributes
sl@0
   992
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   993
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
   994
	attributes.iSize = TSize(480,16);
sl@0
   995
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
   996
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
   997
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
   998
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
   999
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
  1000
sl@0
  1001
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1002
	attributes.iHintCount = 2;
sl@0
  1003
	attributes.iSurfaceHints = hints;
sl@0
  1004
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  1005
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  1006
	
sl@0
  1007
	attributes.iContiguous = ETrue;
sl@0
  1008
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  1009
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1010
	attributes.iMappable = ETrue;
sl@0
  1011
sl@0
  1012
	// Test create surface doesn't return an error
sl@0
  1013
    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
sl@0
  1014
    
sl@0
  1015
    INFO_PRINTF1(_L("Test accessing surface in another thread when the opening thread is killed\r\n"));
sl@0
  1016
    // Create a semaphore
sl@0
  1017
	RSemaphore sem;
sl@0
  1018
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
  1019
	CleanupClosePushL(sem);
sl@0
  1020
sl@0
  1021
	// Creates a second thread in the current process and opens the handle
sl@0
  1022
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
  1023
	iInfo.iSurfaceId = iSurfaceId;
sl@0
  1024
	iInfo.iThreadTestCase = EOpenKillSurface;	
sl@0
  1025
	// Create a TCleanupItem object
sl@0
  1026
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
  1027
sl@0
  1028
    RThread thread9;
sl@0
  1029
    _LIT(KNameThreadSecond9, "Test_SurfaceManager_ThreadSecond9");
sl@0
  1030
	User::LeaveIfError(thread9.Create(KNameThreadSecond9,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
  1031
	CleanupStack::Pop();
sl@0
  1032
	// Launch the second thraed
sl@0
  1033
	TRequestStatus statusThreadSecond;
sl@0
  1034
	thread9.Logon(statusThreadSecond);
sl@0
  1035
	thread9.SetPriority(EPriorityLess);
sl@0
  1036
	thread9.Resume();
sl@0
  1037
	// Waiting the second thread to terminate
sl@0
  1038
    User::WaitForRequest(statusThreadSecond);
sl@0
  1039
sl@0
  1040
   	RChunk handle;
sl@0
  1041
	// Test the surface is still accessible
sl@0
  1042
	TEST(KErrNone == iSurfaceManager.MapSurface(iSurfaceId, handle));
sl@0
  1043
	handle.Close();
sl@0
  1044
	
sl@0
  1045
	RSurfaceManager::TInfoBuf infoBuf;
sl@0
  1046
	TEST(KErrNone ==iSurfaceManager.SurfaceInfo(iSurfaceId, infoBuf));
sl@0
  1047
	
sl@0
  1048
    // Close all the handles
sl@0
  1049
    CleanupStack::PopAndDestroy(1, &sem);
sl@0
  1050
    thread9.Close();
sl@0
  1051
	iSurfaceManager.Close();
sl@0
  1052
	}
sl@0
  1053
sl@0
  1054
void CTSurfaceManagerMultiThread::TestCloseSurfaceOpenedKilledThreadL()
sl@0
  1055
	{
sl@0
  1056
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
  1057
    
sl@0
  1058
	// Setup attributes
sl@0
  1059
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1060
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1061
	attributes.iSize = TSize(480,16);
sl@0
  1062
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
  1063
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
  1064
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
  1065
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
  1066
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
  1067
sl@0
  1068
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1069
	attributes.iHintCount = 2;
sl@0
  1070
	attributes.iSurfaceHints = hints;
sl@0
  1071
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  1072
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  1073
	
sl@0
  1074
	attributes.iContiguous = ETrue;
sl@0
  1075
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  1076
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1077
	attributes.iMappable = ETrue;
sl@0
  1078
	
sl@0
  1079
	// Create a semaphore
sl@0
  1080
	RSemaphore sem;
sl@0
  1081
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
  1082
	CleanupClosePushL(sem);
sl@0
  1083
	
sl@0
  1084
	// Test create surface doesn't return an error
sl@0
  1085
    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
sl@0
  1086
    // Logging info
sl@0
  1087
    INFO_PRINTF1(_L("Test closing surface in another thread when the opening thread is killed\r\n"));
sl@0
  1088
  	// Creates a second thread in the current process and opens the handle
sl@0
  1089
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
  1090
	iInfo.iSurfaceId = iSurfaceId;
sl@0
  1091
	iInfo.iThreadTestCase = EOpenKillSurface;	
sl@0
  1092
sl@0
  1093
	// Create a TCleanupItem object
sl@0
  1094
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
  1095
sl@0
  1096
    RThread thread10;
sl@0
  1097
    _LIT(KNameThreadSecond10, "Test_SurfaceManager_ThreadSecond10");
sl@0
  1098
	User::LeaveIfError(thread10.Create(KNameThreadSecond10,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
  1099
   	CleanupStack::Pop();
sl@0
  1100
	// Launch the second thread
sl@0
  1101
	TRequestStatus statusThreadSecond;
sl@0
  1102
	thread10.Logon(statusThreadSecond);
sl@0
  1103
	thread10.SetPriority(EPriorityLess);
sl@0
  1104
	thread10.Resume();
sl@0
  1105
	// Waiting the second thread to terminate
sl@0
  1106
    User::WaitForRequest(statusThreadSecond);
sl@0
  1107
sl@0
  1108
    // Test closing surface
sl@0
  1109
	TEST(KErrNone ==iSurfaceManager.CloseSurface(iSurfaceId));
sl@0
  1110
	
sl@0
  1111
	// Close all the handles
sl@0
  1112
	CleanupStack::PopAndDestroy(1, &sem);
sl@0
  1113
	thread10.Close();
sl@0
  1114
	iSurfaceManager.Close();
sl@0
  1115
	}
sl@0
  1116
sl@0
  1117
void CTSurfaceManagerMultiThread::TestAccessSurfaceCreateKilledThreadL()
sl@0
  1118
	{
sl@0
  1119
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
  1120
    
sl@0
  1121
	// Setup attributes
sl@0
  1122
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1123
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1124
	attributes.iSize = TSize(480,16);
sl@0
  1125
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
  1126
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
  1127
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
  1128
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
  1129
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
  1130
sl@0
  1131
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1132
	attributes.iHintCount = 2;
sl@0
  1133
	attributes.iSurfaceHints = hints;
sl@0
  1134
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  1135
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  1136
	
sl@0
  1137
	attributes.iContiguous = ETrue;
sl@0
  1138
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  1139
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1140
	attributes.iMappable = ETrue;
sl@0
  1141
	
sl@0
  1142
    // Logging info
sl@0
  1143
    INFO_PRINTF1(_L("Test accessing surface in another thread when the creating thread is killed\r\n"));
sl@0
  1144
    // Create a semaphore
sl@0
  1145
	RSemaphore sem;
sl@0
  1146
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
  1147
	CleanupClosePushL(sem);
sl@0
  1148
sl@0
  1149
  	// Creates a second thread in the current process and opens the handle
sl@0
  1150
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
  1151
	iInfo.iSurfaceId = iSurfaceId;
sl@0
  1152
	iInfo.iThreadTestCase = ECreateKillSurface;	
sl@0
  1153
sl@0
  1154
	// Create a TCleanupItem object
sl@0
  1155
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
  1156
sl@0
  1157
    RThread thread11;
sl@0
  1158
    _LIT(KNameThreadSecond11, "Test_SurfaceManager_ThreadSecond11");
sl@0
  1159
	User::LeaveIfError(thread11.Create(KNameThreadSecond11,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
  1160
   	CleanupStack::Pop();
sl@0
  1161
    // Launch the second thread
sl@0
  1162
	TRequestStatus statusThreadSecond;
sl@0
  1163
	thread11.Logon(statusThreadSecond);
sl@0
  1164
	thread11.SetPriority(EPriorityLess);
sl@0
  1165
	thread11.Resume();
sl@0
  1166
	testResult = EAllZero;
sl@0
  1167
	sem.Wait();	
sl@0
  1168
	// Test creating surface in the second thread
sl@0
  1169
	TEST(testResult = ECreateSurfaceTestPassed);
sl@0
  1170
    // Test closing surface
sl@0
  1171
   	TEST(KErrNone == iSurfaceManager.CloseSurface(globalSurfaceId));
sl@0
  1172
    // Wait the second thread to terminate
sl@0
  1173
    User::WaitForRequest(statusThreadSecond);
sl@0
  1174
sl@0
  1175
    // Test the surface is not accessible any more
sl@0
  1176
   	RChunk handle;
sl@0
  1177
	TEST(KErrArgument == iSurfaceManager.MapSurface(globalSurfaceId, handle));
sl@0
  1178
	handle.Close();
sl@0
  1179
	RSurfaceManager::TInfoBuf infoBuf;
sl@0
  1180
	TEST(KErrArgument ==iSurfaceManager.SurfaceInfo(globalSurfaceId, infoBuf));
sl@0
  1181
 	// Close all the handles
sl@0
  1182
	CleanupStack::PopAndDestroy(1, &sem);
sl@0
  1183
	thread11.Close();
sl@0
  1184
	iSurfaceManager.Close();
sl@0
  1185
    }
sl@0
  1186
	
sl@0
  1187
/**
sl@0
  1188
	210 Test closing surface in another thread when the creating thread is killed
sl@0
  1189
	Thread 2: Create Surface 
sl@0
  1190
	Thread 1: Close Surface
sl@0
  1191
	Thread 2: Kill the thread
sl@0
  1192
	Thread 1: Close Surface - KErrArgument
sl@0
  1193
*/
sl@0
  1194
void CTSurfaceManagerMultiThread::TestCloseSurfaceCreateKilledThreadL()
sl@0
  1195
	{
sl@0
  1196
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
  1197
    
sl@0
  1198
	// Setup attributes
sl@0
  1199
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1200
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1201
	attributes.iSize = TSize(480,16);
sl@0
  1202
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
  1203
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
  1204
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
  1205
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
  1206
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
  1207
sl@0
  1208
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1209
	attributes.iHintCount = 2;
sl@0
  1210
	attributes.iSurfaceHints = hints;
sl@0
  1211
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  1212
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  1213
		
sl@0
  1214
	attributes.iContiguous = ETrue;
sl@0
  1215
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  1216
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1217
	attributes.iMappable = ETrue;
sl@0
  1218
sl@0
  1219
    // Logging info
sl@0
  1220
    INFO_PRINTF1(_L("Test closing surface in another thread when the creating thread is killed\r\n"));
sl@0
  1221
    // Create a semaphore
sl@0
  1222
	RSemaphore sem;
sl@0
  1223
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
  1224
	CleanupClosePushL(sem);
sl@0
  1225
sl@0
  1226
  	// Creates a second thread in the current process and opens the handle
sl@0
  1227
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
  1228
	iInfo.iSurfaceId = iSurfaceId;
sl@0
  1229
	iInfo.iThreadTestCase = ECreateKillSurface;	
sl@0
  1230
sl@0
  1231
	// Create a TCleanupItem object
sl@0
  1232
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
  1233
sl@0
  1234
    RThread thread12;
sl@0
  1235
    _LIT(KNameThreadSecond12, "Test_SurfaceManager_ThreadSecond12");
sl@0
  1236
	User::LeaveIfError(thread12.Create(KNameThreadSecond12,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
  1237
   	CleanupStack::Pop();
sl@0
  1238
    // Launch the second thread
sl@0
  1239
	TRequestStatus statusThreadSecond;
sl@0
  1240
	thread12.Logon(statusThreadSecond);
sl@0
  1241
	thread12.SetPriority(EPriorityLess);
sl@0
  1242
	thread12.Resume();
sl@0
  1243
	sem.Wait();	
sl@0
  1244
	// Test creating surface in the second thread
sl@0
  1245
	TEST(testResult = ECreateSurfaceTestPassed);
sl@0
  1246
    // Test closing surface
sl@0
  1247
   	TEST(KErrNone == iSurfaceManager.CloseSurface(globalSurfaceId));
sl@0
  1248
    // Wait the second thread to terminate
sl@0
  1249
    User::WaitForRequest(statusThreadSecond);
sl@0
  1250
     
sl@0
  1251
	// Test the surface is removed and not closable   	
sl@0
  1252
	TEST(KErrArgument ==iSurfaceManager.CloseSurface(globalSurfaceId));
sl@0
  1253
    // Close the handles
sl@0
  1254
   	CleanupStack::PopAndDestroy(1, &sem);
sl@0
  1255
   	thread12.Close();
sl@0
  1256
	iSurfaceManager.Close();
sl@0
  1257
	}
sl@0
  1258
	
sl@0
  1259
void CTSurfaceManagerMultiThread::TestAccessSurfaceThreeThreadsL()
sl@0
  1260
	{
sl@0
  1261
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
  1262
    
sl@0
  1263
	// Setup attributes
sl@0
  1264
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1265
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1266
	attributes.iSize = TSize(480,16);
sl@0
  1267
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
  1268
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
  1269
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
  1270
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
  1271
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
  1272
sl@0
  1273
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1274
	attributes.iHintCount = 2;
sl@0
  1275
	attributes.iSurfaceHints = hints;
sl@0
  1276
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  1277
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  1278
	
sl@0
  1279
	attributes.iContiguous = ETrue;
sl@0
  1280
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  1281
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1282
	attributes.iMappable = ETrue;
sl@0
  1283
	
sl@0
  1284
	// Test create surface doesn't return an error
sl@0
  1285
    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
sl@0
  1286
    // Logging info
sl@0
  1287
    INFO_PRINTF1(_L("Test closing on one thread doesn't prevent opening on other Threads, provided one Thread still owns surface\r\n"));
sl@0
  1288
    // Create a semaphore
sl@0
  1289
	RSemaphore sem;
sl@0
  1290
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore,0));
sl@0
  1291
	CleanupClosePushL(sem);
sl@0
  1292
sl@0
  1293
   	// Creates a second thread in the current process and opens the handle
sl@0
  1294
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
  1295
	iInfo.iSurfaceId = iSurfaceId;
sl@0
  1296
	iInfo.iThreadTestCase = EOpenCloseSurfaceMultiThread;	
sl@0
  1297
	// Create a TCleanupItem object
sl@0
  1298
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
  1299
sl@0
  1300
    RThread thread13;
sl@0
  1301
    _LIT(KNameThreadSecond13, "Test_SurfaceManager_ThreadSecond13");
sl@0
  1302
	User::LeaveIfError(thread13.Create(KNameThreadSecond13,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
  1303
   	CleanupStack::Pop();
sl@0
  1304
    // Launch the second thread
sl@0
  1305
	TRequestStatus statusThreadSecond;
sl@0
  1306
	thread13.Logon(statusThreadSecond);
sl@0
  1307
	thread13.SetPriority(EPriorityLess);
sl@0
  1308
	thread13.Resume();
sl@0
  1309
	testResult = EAllZero;
sl@0
  1310
	sem.Wait();	
sl@0
  1311
	TEST(testResult == EOpenSurfaceTestPassed);
sl@0
  1312
	testResult = EAllZero;
sl@0
  1313
sl@0
  1314
	// Create a third thread in the same process and opens the handle
sl@0
  1315
	iInfo2 = iInfo;
sl@0
  1316
	iInfo2.iThreadTestCase = EOpenMapSurfaceInfoMultiThread;	
sl@0
  1317
	// Create a TCleanupItem object
sl@0
  1318
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  1319
sl@0
  1320
    RThread thread13_2;
sl@0
  1321
    _LIT(KNameThreadSecond13_2, "Test_SurfaceManager_ThreadSecond13_2");
sl@0
  1322
	User::LeaveIfError(thread13_2.Create(KNameThreadSecond13_2,ThreadThirdStart, KDefaultStackSize, &User::Heap(), &iInfo2));
sl@0
  1323
	CleanupStack::Pop();
sl@0
  1324
	// Launch the third thread
sl@0
  1325
	TRequestStatus statusThreadThird;
sl@0
  1326
	thread13_2.Logon(statusThreadThird);
sl@0
  1327
	thread13_2.SetPriority(EPriorityLess);
sl@0
  1328
	thread13_2.Resume();
sl@0
  1329
	sem.Wait();
sl@0
  1330
	TEST(testResult == EOpenSurfaceTestPassed);
sl@0
  1331
	testResult = EAllZero;
sl@0
  1332
	thread13.Resume();
sl@0
  1333
    User::WaitForRequest(statusThreadSecond);
sl@0
  1334
sl@0
  1335
	TEST(testResult == ECloseSurfaceTestPassed);
sl@0
  1336
	testResult = EAllZero;
sl@0
  1337
sl@0
  1338
	thread13_2.Resume();
sl@0
  1339
    User::WaitForRequest(statusThreadThird);
sl@0
  1340
sl@0
  1341
	TEST(testResult == (EMapSurfaceTestPassed|ESurfaceInfoTestPassed));
sl@0
  1342
sl@0
  1343
	// Close all the handles
sl@0
  1344
	CleanupStack::PopAndDestroy(1, &sem);
sl@0
  1345
sl@0
  1346
	thread13.Close();
sl@0
  1347
	thread13_2.Close();
sl@0
  1348
	iSurfaceManager.Close();
sl@0
  1349
	}
sl@0
  1350
sl@0
  1351
void CTSurfaceManagerMultiThread::TestAccessSurfaceDieCloseOtherThreadsL()
sl@0
  1352
	{
sl@0
  1353
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
  1354
    
sl@0
  1355
    // Logging info
sl@0
  1356
    INFO_PRINTF1(_L("Test surface can be accessed from third thread when creating thread dies and second thread closes\r\n"));
sl@0
  1357
    // Create a semaphore
sl@0
  1358
	RSemaphore sem;
sl@0
  1359
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
  1360
	CleanupClosePushL(sem);
sl@0
  1361
sl@0
  1362
	// Create a second thread and opens the handle
sl@0
  1363
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
  1364
	iInfo.iSurfaceId = iSurfaceId;
sl@0
  1365
	iInfo.iThreadTestCase = ECreateKillSurface;	
sl@0
  1366
sl@0
  1367
	// Create a TCleanupItem object
sl@0
  1368
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
  1369
sl@0
  1370
    RThread thread14;
sl@0
  1371
    _LIT(KNameThreadSecond14, "Test_SurfaceManager_ThreadSecond14");
sl@0
  1372
	User::LeaveIfError(thread14.Create(KNameThreadSecond14,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
  1373
   	CleanupStack::Pop();
sl@0
  1374
	// Launch the second thread
sl@0
  1375
	TRequestStatus statusThreadSecond;
sl@0
  1376
	thread14.Logon(statusThreadSecond);
sl@0
  1377
	thread14.SetPriority(EPriorityLess);
sl@0
  1378
	thread14.Resume();
sl@0
  1379
	testResult = EAllZero;
sl@0
  1380
	sem.Wait();	
sl@0
  1381
	//suspend the 2nd thread
sl@0
  1382
	thread14.Suspend(); 
sl@0
  1383
	
sl@0
  1384
	TEST(testResult == ECreateSurfaceTestPassed);
sl@0
  1385
	testResult = EAllZero;
sl@0
  1386
	
sl@0
  1387
	TEST(KErrNone == iSurfaceManager.OpenSurface(globalSurfaceId));
sl@0
  1388
sl@0
  1389
    // Create a third thread in the current process and opens the handle 
sl@0
  1390
	iInfo2.iSurfaceManager = iSurfaceManager;
sl@0
  1391
	iInfo2.iSurfaceId = globalSurfaceId;
sl@0
  1392
	iInfo2.iSurfaceIdNew = iSurfaceId;
sl@0
  1393
	iInfo2.iThreadTestCase = EOpenCloseMapSurfaceInfoMultiThread;	
sl@0
  1394
	// Create a TCleanupItem object
sl@0
  1395
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  1396
sl@0
  1397
    RThread thread14_2;
sl@0
  1398
    _LIT(KNameThreadSecond14_2, "Test_SurfaceManager_ThreadSecond14_2");
sl@0
  1399
	User::LeaveIfError(thread14_2.Create(KNameThreadSecond14_2,ThreadThirdStart, KDefaultStackSize, &User::Heap(), &iInfo2));
sl@0
  1400
   	CleanupStack::Pop();
sl@0
  1401
    // Launch the third thread
sl@0
  1402
	TRequestStatus statusThreadThird;
sl@0
  1403
	thread14_2.Logon(statusThreadThird);
sl@0
  1404
	thread14_2.SetPriority(EPriorityLess);
sl@0
  1405
	thread14_2.Resume();
sl@0
  1406
	sem.Wait();
sl@0
  1407
	// Test opening the surface in the second thread
sl@0
  1408
	TEST(testResult == EOpenSurfaceTestPassed);
sl@0
  1409
	testResult = EAllZero;
sl@0
  1410
    // Test closing the surface in the main thread
sl@0
  1411
	TEST(KErrNone == iSurfaceManager.CloseSurface(globalSurfaceId));
sl@0
  1412
sl@0
  1413
	thread14.Resume();
sl@0
  1414
    User::WaitForRequest(statusThreadSecond);
sl@0
  1415
sl@0
  1416
    thread14_2.Resume();
sl@0
  1417
    User::WaitForRequest(statusThreadThird);
sl@0
  1418
sl@0
  1419
	// Test the execution results in the third thread
sl@0
  1420
	TEST(testResult == (ECloseSurfaceTestPassed|EMapSurfaceTestPassed|ESurfaceInfoTestPassed));	
sl@0
  1421
sl@0
  1422
    // Close all the handles
sl@0
  1423
    CleanupStack::PopAndDestroy(1, &sem);
sl@0
  1424
    thread14.Close();
sl@0
  1425
    thread14_2.Close();
sl@0
  1426
	iSurfaceManager.Close();
sl@0
  1427
sl@0
  1428
	}
sl@0
  1429
sl@0
  1430
void CTSurfaceManagerMultiThread::TestOpenSurfaceDieCloseOtherThreadsL()
sl@0
  1431
	{
sl@0
  1432
	User::LeaveIfError(iSurfaceManager.Open());
sl@0
  1433
    
sl@0
  1434
	// Setup attributes
sl@0
  1435
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1436
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1437
	attributes.iSize = TSize(480,16);
sl@0
  1438
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
  1439
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
  1440
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
  1441
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
  1442
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
  1443
sl@0
  1444
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1445
	attributes.iHintCount = 2;
sl@0
  1446
	attributes.iSurfaceHints = hints;
sl@0
  1447
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  1448
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  1449
		
sl@0
  1450
	attributes.iContiguous = ETrue;
sl@0
  1451
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  1452
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1453
	attributes.iMappable = ETrue;
sl@0
  1454
sl@0
  1455
    // Logging info
sl@0
  1456
    INFO_PRINTF1(_L("Test that the surface can be opened from the third Thread after creating thread dies and second and third thread close the surface\r\n"));
sl@0
  1457
    // Create a semaphore
sl@0
  1458
	RSemaphore sem;
sl@0
  1459
	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
sl@0
  1460
	CleanupClosePushL(sem);
sl@0
  1461
sl@0
  1462
    // Create a second thread and opens the handle
sl@0
  1463
	iInfo.iSurfaceManager = iSurfaceManager;
sl@0
  1464
	iInfo.iSurfaceId = iSurfaceId;
sl@0
  1465
	iInfo.iThreadTestCase = ECreateKillSurface;	
sl@0
  1466
sl@0
  1467
	// Create a TCleanupItem object
sl@0
  1468
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
sl@0
  1469
    RThread thread15;
sl@0
  1470
    _LIT(KNameThreadSecond15, "Test_SurfaceManager_ThreadSecond15");
sl@0
  1471
	User::LeaveIfError(thread15.Create(KNameThreadSecond15,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
sl@0
  1472
   	CleanupStack::Pop();
sl@0
  1473
   	// Launch the second thread
sl@0
  1474
	TRequestStatus statusThreadSecond;
sl@0
  1475
	thread15.Logon(statusThreadSecond);
sl@0
  1476
	thread15.SetPriority(EPriorityLess);
sl@0
  1477
	thread15.Resume();
sl@0
  1478
	testResult = EAllZero;
sl@0
  1479
	sem.Wait();	
sl@0
  1480
sl@0
  1481
	thread15.Suspend(); //suspend the 2nd thread
sl@0
  1482
sl@0
  1483
	TEST(testResult == ECreateSurfaceTestPassed);
sl@0
  1484
	testResult = EAllZero;
sl@0
  1485
	// Test creating the surface in the second thread	
sl@0
  1486
	TEST(KErrNone == iSurfaceManager.OpenSurface(globalSurfaceId));
sl@0
  1487
sl@0
  1488
	// Create a third thread and opens the handle
sl@0
  1489
	iInfo2.iSurfaceManager = iSurfaceManager;
sl@0
  1490
	iInfo2.iSurfaceId = globalSurfaceId;
sl@0
  1491
	iInfo2.iSurfaceIdNew = iSurfaceId;
sl@0
  1492
	iInfo2.iThreadTestCase = EOpenCloseOpenMultiThread;	
sl@0
  1493
sl@0
  1494
	// Create a TCleanupItem object
sl@0
  1495
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  1496
    RThread thread15_2;
sl@0
  1497
    _LIT(KNameThreadSecond15_2, "Test_SurfaceManager_ThreadSecond15_2");
sl@0
  1498
	User::LeaveIfError(thread15_2.Create(KNameThreadSecond15_2,ThreadThirdStart, KDefaultStackSize, &User::Heap(), &iInfo2));
sl@0
  1499
   	CleanupStack::Pop();
sl@0
  1500
	// Launch the third thread
sl@0
  1501
	TRequestStatus statusThreadThird;
sl@0
  1502
	thread15_2.Logon(statusThreadThird);
sl@0
  1503
	thread15_2.SetPriority(EPriorityLess);
sl@0
  1504
	thread15_2.Resume();
sl@0
  1505
	sem.Wait();
sl@0
  1506
	// Test opening the surface in the third thread
sl@0
  1507
	TEST(testResult == EOpenSurfaceTestPassed);
sl@0
  1508
	// Test closing the surface in the main thread	
sl@0
  1509
	TEST(KErrNone == iSurfaceManager.CloseSurface(globalSurfaceId));
sl@0
  1510
	thread15.Resume();
sl@0
  1511
    User::WaitForRequest(statusThreadSecond);
sl@0
  1512
sl@0
  1513
    thread15_2.Resume();
sl@0
  1514
    User::WaitForRequest(statusThreadThird);
sl@0
  1515
sl@0
  1516
    // Test the surface is still accessible in the third thread
sl@0
  1517
	TEST(testResult == (ECloseSurfaceTestPassed | EOpenSurfaceTestPassed));
sl@0
  1518
    // Close the handles
sl@0
  1519
	CleanupStack::PopAndDestroy(1, &sem);
sl@0
  1520
	thread15.Close();
sl@0
  1521
	thread15_2.Close();
sl@0
  1522
	iSurfaceManager.Close();
sl@0
  1523
sl@0
  1524
	}
sl@0
  1525
	
sl@0
  1526
sl@0
  1527
/**
sl@0
  1528
The second thread entry point
sl@0
  1529
*/
sl@0
  1530
TInt CTSurfaceManagerMultiThread::ThreadSecondStart(TAny* aInfo)
sl@0
  1531
	{
sl@0
  1532
	TInt procHandles1  =0;
sl@0
  1533
	TInt threadHandles1=0;
sl@0
  1534
	RThread().HandleCount(procHandles1, threadHandles1);
sl@0
  1535
	__UHEAP_MARK;
sl@0
  1536
		
sl@0
  1537
	CChildThreadWrapper* newThread = new CChildThreadWrapper(aInfo);
sl@0
  1538
	if (newThread==NULL)
sl@0
  1539
		{
sl@0
  1540
		return KErrNoMemory;
sl@0
  1541
		}
sl@0
  1542
sl@0
  1543
    RSemaphore sem;
sl@0
  1544
    RSemaphore semMain;
sl@0
  1545
 	TInt ret = sem.OpenGlobal(KMultiThreadSemaphore);
sl@0
  1546
    if (ret == KErrNone)
sl@0
  1547
    	{
sl@0
  1548
   		TThreadTestCase testCase = newThread->iThreadTestCase;
sl@0
  1549
		switch (testCase)
sl@0
  1550
			{
sl@0
  1551
			case ECreateSurfaceMapInfo:
sl@0
  1552
				User::LeaveIfError(semMain.OpenGlobal(KMainThreadSemaphore));
sl@0
  1553
				newThread->CreateSurfaceThread();
sl@0
  1554
				sem.Signal();
sl@0
  1555
				semMain.Wait();
sl@0
  1556
				newThread->MapSurfaceInfo();
sl@0
  1557
				delete newThread;
sl@0
  1558
				semMain.Close();
sl@0
  1559
				break;
sl@0
  1560
			case ECreateSurfaceClose:
sl@0
  1561
				User::LeaveIfError(semMain.OpenGlobal(KMainThreadSemaphore));
sl@0
  1562
				newThread->CreateSurfaceThread();
sl@0
  1563
				sem.Signal();
sl@0
  1564
				semMain.Wait();
sl@0
  1565
				newThread->CloseSurface();
sl@0
  1566
				delete newThread;
sl@0
  1567
				semMain.Close();
sl@0
  1568
				break;
sl@0
  1569
			case EMapSurfaceInfo:
sl@0
  1570
		 		newThread->MapSurfaceInfo();
sl@0
  1571
		 		sem.Signal();
sl@0
  1572
				delete newThread;
sl@0
  1573
				break;
sl@0
  1574
			case ECloseSurfaces:
sl@0
  1575
				newThread->CloseSurface();
sl@0
  1576
				sem.Signal();
sl@0
  1577
				delete newThread;
sl@0
  1578
				break;
sl@0
  1579
			case EOpenCloseSurface:
sl@0
  1580
				newThread->OpenSurface();
sl@0
  1581
				newThread->CloseSurface();
sl@0
  1582
				sem.Signal();
sl@0
  1583
				delete newThread;
sl@0
  1584
				break;
sl@0
  1585
			case EOpenKillSurface:
sl@0
  1586
				newThread->OpenSurface();
sl@0
  1587
				delete newThread;
sl@0
  1588
    			sem.Close();
sl@0
  1589
    			RThread().Kill(ret);
sl@0
  1590
				break;
sl@0
  1591
			case ECreateKillSurface:
sl@0
  1592
				newThread->CreateSurfaceThread();
sl@0
  1593
				sem.Signal();
sl@0
  1594
				delete newThread;
sl@0
  1595
    			sem.Close();
sl@0
  1596
    			RThread().Kill(ret);
sl@0
  1597
				break;
sl@0
  1598
			case EOpenCloseSurfaceMultiThread:
sl@0
  1599
				newThread->OpenSurface(); 
sl@0
  1600
				sem.Signal();
sl@0
  1601
				RThread().Suspend();
sl@0
  1602
				newThread->CloseSurface();
sl@0
  1603
				delete newThread;
sl@0
  1604
				sem.Close();
sl@0
  1605
				return ret;
sl@0
  1606
			case ECloseBothSurfaces:
sl@0
  1607
				newThread->CloseBothSurfaces();
sl@0
  1608
				sem.Signal();
sl@0
  1609
				delete newThread;
sl@0
  1610
				break;
sl@0
  1611
			default:
sl@0
  1612
				break;
sl@0
  1613
			}
sl@0
  1614
sl@0
  1615
		}
sl@0
  1616
sl@0
  1617
	__UHEAP_MARKEND;
sl@0
  1618
     
sl@0
  1619
	sem.Close();	
sl@0
  1620
	TInt procHandles2  =0;
sl@0
  1621
	TInt threadHandles2=0;
sl@0
  1622
	RThread().HandleCount(procHandles2,threadHandles2);
sl@0
  1623
	if (threadHandles1 != threadHandles2)
sl@0
  1624
		{
sl@0
  1625
		ret = KErrGeneral;  // Thread-owned handles not closed
sl@0
  1626
		}
sl@0
  1627
sl@0
  1628
	return ret;
sl@0
  1629
	}
sl@0
  1630
	
sl@0
  1631
// Implementation of CChildThreadWrapper class 
sl@0
  1632
CChildThreadWrapper::CChildThreadWrapper(TAny* aInfo) :
sl@0
  1633
	iSurfaceManager    (((TInfo*)aInfo)->iSurfaceManager),
sl@0
  1634
	iSurfaceId(((TInfo*)aInfo)->iSurfaceId),
sl@0
  1635
	iSurfaceIdNew(((TInfo*)aInfo)->iSurfaceIdNew),
sl@0
  1636
	iThreadTestCase(((TInfo*)aInfo)->iThreadTestCase)
sl@0
  1637
	{
sl@0
  1638
	}
sl@0
  1639
sl@0
  1640
CChildThreadWrapper::~CChildThreadWrapper()
sl@0
  1641
	{
sl@0
  1642
	}
sl@0
  1643
sl@0
  1644
void CChildThreadWrapper::CreateSurfaceThread()
sl@0
  1645
	{
sl@0
  1646
	// Setup attributes
sl@0
  1647
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1648
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1649
	
sl@0
  1650
	attributes.iSize = TSize(200,200);
sl@0
  1651
	attributes.iBuffers = 1;				
sl@0
  1652
	attributes.iPixelFormat = EUidPixelFormatARGB_1555;		
sl@0
  1653
	attributes.iStride = 1024;				
sl@0
  1654
	attributes.iOffsetToFirstBuffer = 80;	
sl@0
  1655
	attributes.iAlignment = 8;			
sl@0
  1656
	attributes.iContiguous=ETrue;
sl@0
  1657
sl@0
  1658
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1659
	attributes.iHintCount = 2;
sl@0
  1660
	attributes.iSurfaceHints = hints;
sl@0
  1661
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  1662
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  1663
sl@0
  1664
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  1665
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1666
	attributes.iMappable = ETrue;
sl@0
  1667
sl@0
  1668
	if (KErrNone == iSurfaceManager.CreateSurface(buf,iSurfaceId))
sl@0
  1669
		{
sl@0
  1670
		testResult |= ECreateSurfaceTestPassed;
sl@0
  1671
		}
sl@0
  1672
    else
sl@0
  1673
    	{
sl@0
  1674
    	testResult |= ECreateSurfaceTestFailed;	
sl@0
  1675
	   	}
sl@0
  1676
		
sl@0
  1677
	// record the surfaceId as a global variable
sl@0
  1678
	globalSurfaceId = iSurfaceId;
sl@0
  1679
	}
sl@0
  1680
	
sl@0
  1681
void CChildThreadWrapper::MapSurfaceInfo()
sl@0
  1682
	{
sl@0
  1683
	// Access the surface and pass back the test results to the main thread
sl@0
  1684
	RChunk handle;
sl@0
  1685
	// Call Map Surface
sl@0
  1686
	if (iSurfaceManager.MapSurface(iSurfaceId,handle)== KErrNone)
sl@0
  1687
		{
sl@0
  1688
		testResult |= EMapSurfaceTestPassed;
sl@0
  1689
		}
sl@0
  1690
	else 
sl@0
  1691
		{
sl@0
  1692
		testResult |= EMapSurfaceTestFailed;
sl@0
  1693
		}
sl@0
  1694
	handle.Close();
sl@0
  1695
sl@0
  1696
	RSurfaceManager::TInfoBuf infoBuf;
sl@0
  1697
	// Call Surface Info
sl@0
  1698
	if (iSurfaceManager.SurfaceInfo(iSurfaceId, infoBuf) == KErrNone)
sl@0
  1699
		{
sl@0
  1700
		testResult |= ESurfaceInfoTestPassed;
sl@0
  1701
		}
sl@0
  1702
	else 
sl@0
  1703
		{
sl@0
  1704
		testResult |= ESurfaceInfoTestFailed;
sl@0
  1705
		}
sl@0
  1706
	} 
sl@0
  1707
			   
sl@0
  1708
void CChildThreadWrapper::CloseSurface()
sl@0
  1709
	{
sl@0
  1710
	// Call close surface and pass back the results to the main thread
sl@0
  1711
	if (iSurfaceManager.CloseSurface(iSurfaceId) == KErrNone)
sl@0
  1712
		{
sl@0
  1713
		testResult |= ECloseSurfaceTestPassed;
sl@0
  1714
		}
sl@0
  1715
	else 
sl@0
  1716
		{
sl@0
  1717
		testResult |= ECloseSurfaceTestFailed;
sl@0
  1718
		}
sl@0
  1719
	} 
sl@0
  1720
sl@0
  1721
void CChildThreadWrapper::OpenSurface()
sl@0
  1722
	{
sl@0
  1723
	// Call close surface and pass back the results to the main thread
sl@0
  1724
	if (iSurfaceManager.OpenSurface(iSurfaceId) == KErrNone)
sl@0
  1725
		{
sl@0
  1726
		testResult |= EOpenSurfaceTestPassed;
sl@0
  1727
		}
sl@0
  1728
	else
sl@0
  1729
		{
sl@0
  1730
		testResult |= EOpenSurfaceTestFailed;
sl@0
  1731
		}
sl@0
  1732
	} 
sl@0
  1733
		 
sl@0
  1734
void CChildThreadWrapper::CloseBothSurfaces()
sl@0
  1735
	{
sl@0
  1736
	// Call close surface and pass back the results to the main thread
sl@0
  1737
	if (iSurfaceManager.CloseSurface(iSurfaceIdNew) == KErrNone)
sl@0
  1738
		{
sl@0
  1739
		testResult |= ECloseSurfaceTestPassed;
sl@0
  1740
		}
sl@0
  1741
	else 
sl@0
  1742
		{
sl@0
  1743
		testResult |= ECloseSurfaceTestFailed;
sl@0
  1744
		}
sl@0
  1745
	RSurfaceManager::TInfoBuf infoBuf;
sl@0
  1746
	// Call Surface Info
sl@0
  1747
	if (iSurfaceManager.SurfaceInfo(iSurfaceId, infoBuf) == KErrNone)
sl@0
  1748
		{
sl@0
  1749
		testResult |= ESurfaceInfoTestPassed;
sl@0
  1750
		}
sl@0
  1751
	else 
sl@0
  1752
		{
sl@0
  1753
		testResult |= ESurfaceInfoTestFailed;
sl@0
  1754
		}
sl@0
  1755
	
sl@0
  1756
	if (iSurfaceManager.SurfaceInfo(iSurfaceIdNew, infoBuf) == KErrArgument)
sl@0
  1757
		{
sl@0
  1758
		testResult |= ESurfaceInfoTestPassed2;
sl@0
  1759
		}
sl@0
  1760
	else 
sl@0
  1761
		{
sl@0
  1762
		testResult |= ESurfaceInfoTestFailed2;
sl@0
  1763
		}
sl@0
  1764
	iSurfaceManager.CloseSurface(iSurfaceId);
sl@0
  1765
	}
sl@0
  1766
/**
sl@0
  1767
The third thread entry point
sl@0
  1768
*/
sl@0
  1769
TInt CTSurfaceManagerMultiThread::ThreadThirdStart(TAny* aInfo)
sl@0
  1770
	{
sl@0
  1771
	TInt procHandles1  =0;
sl@0
  1772
	TInt threadHandles1=0;
sl@0
  1773
	RThread().HandleCount(procHandles1, threadHandles1);
sl@0
  1774
	__UHEAP_MARK;
sl@0
  1775
	CTrapCleanup* cleanupStack=CTrapCleanup::New();
sl@0
  1776
	if (cleanupStack==NULL)
sl@0
  1777
		{
sl@0
  1778
		return KErrNoMemory;
sl@0
  1779
		}
sl@0
  1780
		
sl@0
  1781
	CChildThreadWrapper* newThread = new CChildThreadWrapper(aInfo);
sl@0
  1782
	if (newThread==NULL)
sl@0
  1783
		{
sl@0
  1784
		delete cleanupStack;
sl@0
  1785
		return KErrNoMemory;
sl@0
  1786
		}
sl@0
  1787
		
sl@0
  1788
	// Pass control back to the first process
sl@0
  1789
    RSemaphore sem;
sl@0
  1790
	TInt ret = sem.OpenGlobal(KMultiThreadSemaphore);
sl@0
  1791
	if (ret!=KErrNone)
sl@0
  1792
		return ret;
sl@0
  1793
		
sl@0
  1794
	TInt err = KErrNone;
sl@0
  1795
    TThreadTestCase testCase = newThread->iThreadTestCase;
sl@0
  1796
	switch (testCase)
sl@0
  1797
		{
sl@0
  1798
		case EOpenMapSurfaceInfoMultiThread:
sl@0
  1799
			newThread->OpenSurface();
sl@0
  1800
			sem.Signal();
sl@0
  1801
			RThread().Suspend();
sl@0
  1802
			newThread->MapSurfaceInfo();
sl@0
  1803
			break;
sl@0
  1804
		case EOpenCloseMapSurfaceInfoMultiThread:
sl@0
  1805
			newThread->OpenSurface();
sl@0
  1806
			sem.Signal();
sl@0
  1807
			RThread().Suspend();
sl@0
  1808
			newThread->CloseSurface();
sl@0
  1809
			newThread->MapSurfaceInfo();
sl@0
  1810
			break;
sl@0
  1811
		case EOpenCloseOpenMultiThread:
sl@0
  1812
			newThread->OpenSurface();
sl@0
  1813
			sem.Signal();
sl@0
  1814
			RThread().Suspend();
sl@0
  1815
			newThread->CloseSurface();
sl@0
  1816
			newThread->OpenSurface();
sl@0
  1817
			break;
sl@0
  1818
		default:
sl@0
  1819
			break;
sl@0
  1820
		}
sl@0
  1821
sl@0
  1822
   	delete newThread;
sl@0
  1823
	delete cleanupStack;
sl@0
  1824
	__UHEAP_MARKEND;
sl@0
  1825
	
sl@0
  1826
    sem.Close();	
sl@0
  1827
	TInt procHandles2  =0;
sl@0
  1828
	TInt threadHandles2=0;
sl@0
  1829
	RThread().HandleCount(procHandles2,threadHandles2);
sl@0
  1830
	if (threadHandles1 != threadHandles2)
sl@0
  1831
		{
sl@0
  1832
		err = KErrGeneral;  // Thread-owned handles not closed
sl@0
  1833
		}
sl@0
  1834
sl@0
  1835
	return err;
sl@0
  1836
	}
sl@0
  1837
sl@0
  1838
sl@0
  1839
	
sl@0
  1840
//--------------
sl@0
  1841
__CONSTRUCT_STEP__(SurfaceManagerMultiThread)
sl@0
  1842
sl@0
  1843
void CTSurfaceManagerMultiThreadStep::TestSetupL()
sl@0
  1844
	{
sl@0
  1845
    }
sl@0
  1846
sl@0
  1847
void CTSurfaceManagerMultiThreadStep::TestClose()
sl@0
  1848
	{
sl@0
  1849
	}