os/graphics/graphicshwdrivers/surfacemgr/test/src/tsurfacemanagermultiprocess.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-processed 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 <e32base.h>
sl@0
    25
#include <e32cons.h>
sl@0
    26
#include <e32test.h>
sl@0
    27
#include <e32std.h>
sl@0
    28
#include <e32cmn.h>
sl@0
    29
#include <e32def.h>
sl@0
    30
#include "tsurfacemanagermultiprocess.h"
sl@0
    31
sl@0
    32
_LIT(KSecondProcess,"tsecondprocess.exe");
sl@0
    33
_LIT(KThirdProcess,"tthirdprocess.exe");
sl@0
    34
sl@0
    35
sl@0
    36
CTSurfaceManagerMultiProcess::CTSurfaceManagerMultiProcess(CTestStep* aStep):
sl@0
    37
	CTGraphicsBase(aStep)
sl@0
    38
	{
sl@0
    39
	}
sl@0
    40
sl@0
    41
CTSurfaceManagerMultiProcess::~CTSurfaceManagerMultiProcess()
sl@0
    42
	{
sl@0
    43
	}
sl@0
    44
sl@0
    45
void CTSurfaceManagerMultiProcess::RunTestCaseL(TInt aCurTestCase)
sl@0
    46
	{
sl@0
    47
	TInt procHandles1  =0;
sl@0
    48
	TInt threadHandles1=0;
sl@0
    49
	RThread().HandleCount(procHandles1, threadHandles1);
sl@0
    50
	((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
    51
sl@0
    52
	switch(aCurTestCase)
sl@0
    53
		{
sl@0
    54
/**
sl@0
    55
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0083
sl@0
    56
@SYMPREQ				PREQ 1879,PREQ1007
sl@0
    57
@SYMREQ					REQ8222,REQ8223
sl@0
    58
@SYMTestPriority		High 
sl@0
    59
@SYMTestCaseDesc		Test mapping a surface created in the existing shared chunk to a different process
sl@0
    60
						Process 1: Create a surface in a new shared chunk with valid attributes
sl@0
    61
						Process 1: Map the surface in the current process to get the chunk handle.
sl@0
    62
						Process 1: Create another surface in the existing chunk (rotation of the first)
sl@0
    63
						Process 2: Open and Map the second surface in and get the second chunk handles
sl@0
    64
						Process 2: Check these two chunks handles are different
sl@0
    65
						Process 2: Get the pixel start address of the pixel data for the second surface via the second chunk handle and write a number to it
sl@0
    66
						Process 1: Get the pixel start address of the pixel data for the first surface via the first chunk handle and read the number.
sl@0
    67
						Process 1: Check the number is identical to what we write to in the second process.						
sl@0
    68
@SYMTestStatus			Implemented
sl@0
    69
@SYMTestActions			Call CreateSurface(),OpenSurface(), MapSurface(), SurfaceInfo()
sl@0
    70
@SYMTestExpectedResults Mapping one surface created in the existing shared chunk to the other process will not alter the surface chunk memory
sl@0
    71
*/
sl@0
    72
	case 1:
sl@0
    73
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0083"));
sl@0
    74
		TestMapSurfaceExistinChunkL();
sl@0
    75
		break;		
sl@0
    76
/**
sl@0
    77
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0084
sl@0
    78
@SYMPREQ				PREQ 1879,PREQ1007
sl@0
    79
@SYMREQ					REQ8222,REQ8223
sl@0
    80
@SYMTestPriority		High 
sl@0
    81
@SYMTestCaseDesc		Test that the API SynchronizeCache() behaves correctly in the multi-process case. 
sl@0
    82
						Process 1: Create the surface in a new shared chunk with valid creation attributes. The cache attribute is set to ECached. 
sl@0
    83
						Process 2: Open the surface and map it in the current process to get the chunk handle
sl@0
    84
						Process 2: Synchronise the cache before the hardware writes to the buffer. Pass TSyncOperation::ESyncBeforeHandwareWrite, valid buffer number and surfaceID in SynchronizeCache()
sl@0
    85
						Process 2: Synchronise again the cache after the hardware write the buffer. Pass TSyncOperation::ESyncAfterHandwareWrite, valid buffer number and surfaceID in SynchronizeCache()
sl@0
    86
						Process 1: Synchronise again the cache before the hardware reads the buffer. Pass TSyncOperation::ESyncBeforeHardwareRead, valid buffer number and surfaceID in SynchronizeCache()
sl@0
    87
@SYMTestStatus			Implemented
sl@0
    88
@SYMTestActions			Call CreateSurface(),OpenSurface(), MapSurface(), SurfaceInfo()
sl@0
    89
@SYMTestExpectedResults All synchronisation operation return KErrNone, the surface memory is synchronised properly with cached contents.
sl@0
    90
*/
sl@0
    91
	case 2:
sl@0
    92
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0084"));
sl@0
    93
		TestSynchronizeCacheMultiProcessL();
sl@0
    94
		break;
sl@0
    95
/**
sl@0
    96
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0046
sl@0
    97
@SYMPREQ				PREQ 1879,PREQ1007
sl@0
    98
@SYMREQ					REQ8222,REQ8223
sl@0
    99
@SYMTestPriority		High 
sl@0
   100
@SYMTestCaseDesc		Testing the behaviour of closing driver channels in multiple processes when the last channel to the device driver is closed
sl@0
   101
						Process 1: Open a channel called as SurfaceManager1 to the LDD by calling RSurfaceManager::Open() 
sl@0
   102
						Process 1: Create a surface SurfaceID1 using SurfaceManager1
sl@0
   103
						Process 1: Open another channel called as SurfaceManager2 to the LDD 
sl@0
   104
						Process 1: Create another surface SurfaceID2 using SurfaceManager2
sl@0
   105
						Process 1: Open SurfaceID1 using both SurfaceManager1 and SurfaceManager2
sl@0
   106
						Process 1: Open SurfaceID2 using both SurfaceManager1 and SurfaceManager2
sl@0
   107
						Process 2: Open a channel to the LDD and open the surfaceID1 in the process 
sl@0
   108
						Process 1: Close both channels to the LDD SurfaceManager1 and SurfaceManager2
sl@0
   109
						Process 2: Call SurfaceInfo() on surfaceID1 and check the return is KErrNone. Call SurfaceInfo() on surfaceID2 and check it returns KErrArgument.
sl@0
   110
						Process 1: Reopen the channel to the LDD.  Call SurfaceInfo() on surfaceID1. The return value is KErrNone. Call SurfaceInfo() on surfaceID2. The return value is KErrArgument.
sl@0
   111
@SYMTestStatus			Implemented
sl@0
   112
@SYMTestActions			Call CreateSurface(),OpenSurface(), MapSurface(), SurfaceInfo()
sl@0
   113
@SYMTestExpectedResults If all the channels to the driver are closed in a process, the surfaces which have been opened in the other process will not be closed. They are still usable when the first process connects to the driver again.  
sl@0
   114
*/
sl@0
   115
	case 3:
sl@0
   116
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0046"));
sl@0
   117
		TestCloseChannelsMultiProcess1L();
sl@0
   118
		break;	
sl@0
   119
/**
sl@0
   120
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0047
sl@0
   121
@SYMPREQ				PREQ 1879,PREQ1007
sl@0
   122
@SYMREQ					REQ8222,REQ8223
sl@0
   123
@SYMTestPriority		High 
sl@0
   124
@SYMTestCaseDesc		Testing the behaviour of closing driver channels and surfaces when the process is killed
sl@0
   125
						Process 2: Open a channel called as SurfaceManager1 to the LDD by calling RSurfaceManager::Open() 
sl@0
   126
						Process 2: Create a surface SurfaceID1 using SurfaceManager1
sl@0
   127
						Process 2: Open another channel called as SurfaceManager2 to the LDD 
sl@0
   128
						Process 2: Create another surface SurfaceID2 using SurfaceManager2
sl@0
   129
						Process 2: Open SurfaceID1 using both SurfaceManager1 and SurfaceManager2
sl@0
   130
						Process 2: Open SurfaceID2 using both SurfaceManager1 and SurfaceManager2
sl@0
   131
						Process 1: Open a channel called as SurfaceManager3 to the LDD and open the surfaceID1 in the process 
sl@0
   132
						Process 2: Kill the process
sl@0
   133
						Process 1: Call OpenSurface() on surfaceID1 using SurfaceManager3 and check it returns KErrNone, as the surfaceID1 is still open
sl@0
   134
						Process 1: Call OpenSurface() on surfaceID2 using SurfaceManager3 and check it returns KErrArgument, as the surfaceID2 is already deleted
sl@0
   135
						Process 1: Close surfaceID1 and SurfaceManager3
sl@0
   136
@SYMTestStatus			Implemented
sl@0
   137
@SYMTestActions			Call CreateSurface(),OpenSurface(), MapSurface(), SurfaceInfo()
sl@0
   138
@SYMTestExpectedResults When the last channel to the surface manager by the process exiting, the surface manager will automatically close the surfaces which are open in that process.  Any surfaces which were only open in that process will be deleted.
sl@0
   139
*/
sl@0
   140
	case 4:
sl@0
   141
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0047"));
sl@0
   142
		TestCloseChannelsMultiProcess2L();
sl@0
   143
		break;		
sl@0
   144
/**
sl@0
   145
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0048
sl@0
   146
@SYMPREQ				PREQ1007
sl@0
   147
@SYMREQ					REQ8222,REQ8223
sl@0
   148
@SYMTestPriority		High 
sl@0
   149
@SYMTestCaseDesc		Multiprocess API testing for getting information using SurfaceInfo
sl@0
   150
						Process 1: Create the Surface
sl@0
   151
						Process 2: Receive the Surface Id 
sl@0
   152
						Process 2: Receive the attributes expected to be used by the surface
sl@0
   153
						Process 2: Open the surface using the id	
sl@0
   154
						Process 2: Map the surface
sl@0
   155
						Process 2: Call SurfaceInfo to get the attributes of the Surface
sl@0
   156
						Process 2: Check if these are equal to the ones received.
sl@0
   157
@SYMTestStatus			Implemented
sl@0
   158
@SYMTestActions			Call CreateSurface(),OpenSurface(), MapSurface(), SurfaceInfo()
sl@0
   159
@SYMTestExpectedResults The surface can be successfully transmitted between processes
sl@0
   160
*/
sl@0
   161
	case 5:
sl@0
   162
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0048"));
sl@0
   163
		TestSurfaceInfoUsingSurfaceIdL();
sl@0
   164
		break;
sl@0
   165
/**
sl@0
   166
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0049
sl@0
   167
@SYMPREQ				PREQ1007
sl@0
   168
@SYMREQ					REQ8222,REQ8223
sl@0
   169
@SYMTestPriority		High 
sl@0
   170
@SYMTestCaseDesc		Multiprocess API testing for opening the Surface using SurfaceId
sl@0
   171
						Priocess 1: Create the surface
sl@0
   172
						Process 2: Receive the Surface id
sl@0
   173
						Process 2: Open the Surface using the stored SurfaceId
sl@0
   174
						Process 2: Check that it returns KErrNone
sl@0
   175
@SYMTestStatus			Implemented
sl@0
   176
@SYMTestActions			Call CreateSurface(),OpenSurface()
sl@0
   177
@SYMTestExpectedResults Check that opening the surface using a recieved id returns KErrNone
sl@0
   178
*/
sl@0
   179
	case 6:
sl@0
   180
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0049"));
sl@0
   181
		TestOpeningSurfaceUsingSurfaceIdL();
sl@0
   182
		break;
sl@0
   183
/**
sl@0
   184
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0050
sl@0
   185
@SYMPREQ				PREQ1007
sl@0
   186
@SYMREQ					REQ8222,REQ8223
sl@0
   187
@SYMTestPriority		High 
sl@0
   188
@SYMTestCaseDesc		Multiprocess test for opening the surface (OpenSurface negative test)
sl@0
   189
						Receive a Surface Id from another process
sl@0
   190
						Change Surface Id by
sl@0
   191
							1. adding 500 to the SurfaceId
sl@0
   192
							2. making the Surface ID negative
sl@0
   193
							3. converting the type of the Surface ID to EInvalidSurface
sl@0
   194
						Call OpenSurface using the new SurfaceId					
sl@0
   195
@SYMTestStatus			Implemented
sl@0
   196
@SYMTestActions			Call CreateSurface(),OpenSurface()
sl@0
   197
@SYMTestExpectedResults Check that opening the surface using a modified id returns KErrArgument
sl@0
   198
*/
sl@0
   199
	case 7:
sl@0
   200
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0050"));
sl@0
   201
		TestOpenSurfaceInvalidParamsL();
sl@0
   202
		break;
sl@0
   203
/**
sl@0
   204
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0051
sl@0
   205
@SYMPREQ				PREQ1007
sl@0
   206
@SYMREQ					REQ8222,REQ8223
sl@0
   207
@SYMTestPriority		High 
sl@0
   208
@SYMTestCaseDesc		Closing an unopened surface in a second process 
sl@0
   209
						Process 1: Create Surface
sl@0
   210
						Process 2: Close Surface 		
sl@0
   211
@SYMTestStatus			Implemented
sl@0
   212
@SYMTestActions			Call CreateSurface(),CloseSurface()
sl@0
   213
@SYMTestExpectedResults Check that CloseSurface() returns KErrAccessDenied		
sl@0
   214
*/
sl@0
   215
	case 8:
sl@0
   216
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0051"));
sl@0
   217
		TestClosingUnopenedSurfaceL();
sl@0
   218
		break;
sl@0
   219
/**
sl@0
   220
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0052
sl@0
   221
@SYMPREQ				PREQ1007
sl@0
   222
@SYMREQ					REQ8222,REQ8223
sl@0
   223
@SYMTestPriority		High 
sl@0
   224
@SYMTestCaseDesc		Accessing an unopened surface in a second process give KErrArgument
sl@0
   225
@SYMTestStatus			Implemented
sl@0
   226
@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo()
sl@0
   227
@SYMTestExpectedResults The surface cant be accessed/closed if it is not opened first in another process.	
sl@0
   228
*/
sl@0
   229
	case 9:
sl@0
   230
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0052"));
sl@0
   231
		TestSurfaceInfoUnopenedSurfaceL();
sl@0
   232
		break;
sl@0
   233
/**
sl@0
   234
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0053
sl@0
   235
@SYMPREQ				PREQ1007
sl@0
   236
@SYMREQ					REQ8222,REQ8223
sl@0
   237
@SYMTestPriority		High 
sl@0
   238
@SYMTestCaseDesc		Create, Open and Close in 3 different processes, 
sl@0
   239
						leaves surface accessible in first 2 processes 
sl@0
   240
@SYMTestStatus			Implemented
sl@0
   241
@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo()
sl@0
   242
@SYMTestExpectedResults The surface cant be accessed/closed if it is not opened first in another process.	
sl@0
   243
*/
sl@0
   244
	case 10:
sl@0
   245
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0053"));
sl@0
   246
		CreateOpenCloseThreeProcessL();
sl@0
   247
		break;
sl@0
   248
/**
sl@0
   249
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0054
sl@0
   250
@SYMPREQ				PREQ1007
sl@0
   251
@SYMREQ					REQ8222,REQ8223
sl@0
   252
@SYMTestPriority		High 
sl@0
   253
@SYMTestCaseDesc		Test surface can be accessed when creating process dies
sl@0
   254
						Process 2: Create Surface
sl@0
   255
						Process 1: Open Surface
sl@0
   256
						Process 2: Kill Process
sl@0
   257
						Process 1: Map Surface 
sl@0
   258
						Process 1: Surface Info
sl@0
   259
@SYMTestStatus			Implemented
sl@0
   260
@SYMTestActions			Call CreateSurface(),OpenSurface(), MapSurface(), SurfaceInfo()
sl@0
   261
@SYMTestExpectedResults It is expected that the surface can be accessed when creating process dies	
sl@0
   262
*/
sl@0
   263
	case 11:
sl@0
   264
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0054"));
sl@0
   265
		TestSurfaceAccessWhenCreatingProcessDiesL();
sl@0
   266
		break;
sl@0
   267
/**
sl@0
   268
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0055
sl@0
   269
@SYMPREQ				PREQ1007
sl@0
   270
@SYMREQ					REQ8222,REQ8223
sl@0
   271
@SYMTestPriority		High 
sl@0
   272
@SYMTestCaseDesc		Test surface can be closed when creating process dies
sl@0
   273
						Process 2: Create Surface
sl@0
   274
						Process 1: Open Surface
sl@0
   275
						Process 2: Kill Process
sl@0
   276
						Process 1: Close Surface 
sl@0
   277
@SYMTestStatus			Implemented
sl@0
   278
@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface()
sl@0
   279
@SYMTestExpectedResults It is expected that the surface can be closed when creating process dies	
sl@0
   280
*/
sl@0
   281
	case 12:
sl@0
   282
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0055"));
sl@0
   283
		TestClosingSurfaceWhenCreatingProcessDiesL();
sl@0
   284
		break;
sl@0
   285
/**
sl@0
   286
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0056
sl@0
   287
@SYMPREQ				PREQ1007
sl@0
   288
@SYMREQ					REQ8222,REQ8223
sl@0
   289
@SYMTestPriority		High 
sl@0
   290
@SYMTestCaseDesc		Test surface can be closed from third process when 
sl@0
   291
						creating process dies and second process closes
sl@0
   292
						Process 2: Create Surface
sl@0
   293
						Process 1: Open Surface
sl@0
   294
						Process 3: Open Surface
sl@0
   295
						Process 2: Kill Process
sl@0
   296
						Process 1: Close Surface - KErrNone
sl@0
   297
						Process 3: Close Surface - KErrNone
sl@0
   298
						Process 3: Open Surface - KErrArgument
sl@0
   299
@SYMTestStatus			Implemented
sl@0
   300
@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface()
sl@0
   301
@SYMTestExpectedResults It is expected that surface can be closed from third process when 
sl@0
   302
						creating process dies and second process closes	
sl@0
   303
*/
sl@0
   304
	case 13:
sl@0
   305
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0056"));
sl@0
   306
		TestCloseSurfaceInThirdProcessL();
sl@0
   307
		break;
sl@0
   308
/**
sl@0
   309
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0057
sl@0
   310
@SYMPREQ				PREQ1007
sl@0
   311
@SYMREQ					REQ8222,REQ8223
sl@0
   312
@SYMTestPriority		High 
sl@0
   313
@SYMTestCaseDesc		Test surface can't be accessed in a second process when open 
sl@0
   314
						and closed in the first process.
sl@0
   315
						Process 2: Create Surface
sl@0
   316
						Process 1: Open Surface
sl@0
   317
						Process 1: Close Surface
sl@0
   318
						Process 2: Kill Process
sl@0
   319
						Process 1: Open Surface 
sl@0
   320
@SYMTestStatus			Implemented
sl@0
   321
@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface()
sl@0
   322
@SYMTestExpectedResults It is expected that test surface can't be accessed when closed (2process)
sl@0
   323
*/
sl@0
   324
	case 14:
sl@0
   325
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0057"));
sl@0
   326
		TestNoAccessWhenSurfaceClosedTwoProcessL();
sl@0
   327
		break;
sl@0
   328
/**
sl@0
   329
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0058
sl@0
   330
@SYMPREQ				PREQ1007
sl@0
   331
@SYMREQ					REQ8222,REQ8223
sl@0
   332
@SYMTestPriority		High 
sl@0
   333
@SYMTestCaseDesc		Test closing on one process doesn't prevent opening on other processes, 
sl@0
   334
						provided one process still owns surface
sl@0
   335
						Process 1: Create Surface
sl@0
   336
						Process 2: Open Surface
sl@0
   337
						Process 2: Close Surface
sl@0
   338
						Process 3: Open Surface - KErrNone
sl@0
   339
@SYMTestStatus			Implemented
sl@0
   340
@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface()
sl@0
   341
@SYMTestExpectedResults It is expected that closing on one process doesn't prevent opening on other processes, 
sl@0
   342
						provided one process still owns surface
sl@0
   343
*/
sl@0
   344
	case 15:
sl@0
   345
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0058"));
sl@0
   346
		TestOpeningOnProcessAfterClosingOnOtherL();
sl@0
   347
		break;
sl@0
   348
/**
sl@0
   349
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0059
sl@0
   350
@SYMPREQ				PREQ1007
sl@0
   351
@SYMREQ					REQ8222,REQ8223
sl@0
   352
@SYMTestPriority		High 
sl@0
   353
@SYMTestCaseDesc		Test closing on one process doesn't prevent access on other 
sl@0
   354
						processes, provided one process still owns surface
sl@0
   355
						Process 1: Create Surface
sl@0
   356
						Process 2: Open Surface
sl@0
   357
						Process 2: Close Surface
sl@0
   358
						Process 1: Map Surface - KErrNone
sl@0
   359
						Process 1: SurfaceInfo - KErrNone
sl@0
   360
@SYMTestStatus			Implemented
sl@0
   361
@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface(), MapSurface(), SurfaceInfo()
sl@0
   362
@SYMTestExpectedResults It is expected that closing on one process doesn't prevent access on other 
sl@0
   363
*/
sl@0
   364
	case 16:
sl@0
   365
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0059"));
sl@0
   366
		TestAccessAfterClosingL();
sl@0
   367
		break;
sl@0
   368
/**
sl@0
   369
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0060
sl@0
   370
@SYMPREQ				PREQ1007
sl@0
   371
@SYMREQ					REQ8222,REQ8223
sl@0
   372
@SYMTestPriority		High 
sl@0
   373
@SYMTestCaseDesc		Test closing a surface in the creating process when it 
sl@0
   374
						has already been closed in a second process 
sl@0
   375
						Process 1: Create Surface
sl@0
   376
						Process 2: Open Surface
sl@0
   377
						Process 2: Close Surface
sl@0
   378
						Process 1: Close Surface 
sl@0
   379
@SYMTestStatus			Implemented
sl@0
   380
@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface()
sl@0
   381
@SYMTestExpectedResults Check Close Surface in process 1 returns KErrNone
sl@0
   382
*/
sl@0
   383
	case 17:
sl@0
   384
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0060"));
sl@0
   385
		TestClosingAfterClosingOnOtherProcessL();
sl@0
   386
		break;
sl@0
   387
/**
sl@0
   388
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0061
sl@0
   389
@SYMPREQ				PREQ1007
sl@0
   390
@SYMREQ					REQ8222,REQ8223
sl@0
   391
@SYMTestPriority		High 
sl@0
   392
@SYMTestCaseDesc		Test a surface cannot be accessed in a second process if not opened
sl@0
   393
						Process 1: Create Surface
sl@0
   394
						Process 2: Map Surface  
sl@0
   395
						Process 2: Surface Info 
sl@0
   396
@SYMTestStatus			Implemented
sl@0
   397
@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface()
sl@0
   398
@SYMTestExpectedResults Check Map Surface and SurfaceInfo in the second process return KErrAccessDenied
sl@0
   399
*/
sl@0
   400
	case 18:
sl@0
   401
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0061"));
sl@0
   402
		TestErrSufaceAccessNotOpenL();
sl@0
   403
		break;
sl@0
   404
/**
sl@0
   405
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0062
sl@0
   406
@SYMPREQ				PREQ1007
sl@0
   407
@SYMREQ					REQ8222,REQ8223
sl@0
   408
@SYMTestPriority		High 
sl@0
   409
@SYMTestCaseDesc		Test surface buffers written to in one process can be read from in another
sl@0
   410
						Process 1: Create Surface
sl@0
   411
						Process 1: Map Surface 
sl@0
   412
						Process 1: Write to buffer
sl@0
   413
						Process 2: Open the surface 
sl@0
   414
						Process 2: Read from buffer 
sl@0
   415
@SYMTestStatus			Implemented
sl@0
   416
@SYMTestActions			Call CreateSurface(),MapSurface(), OpenSurface()
sl@0
   417
@SYMTestExpectedResults Value written to buffer in process 1 is equal to value retrieved from buffer in process 2.
sl@0
   418
*/
sl@0
   419
	case 19:
sl@0
   420
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0062"));
sl@0
   421
		TestReadFromBufferInSecondProcessL();
sl@0
   422
		break;
sl@0
   423
/**
sl@0
   424
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0063
sl@0
   425
@SYMPREQ				PREQ1007, PREQ 1879
sl@0
   426
@SYMREQ					REQ8222,REQ8223
sl@0
   427
@SYMTestPriority		High 
sl@0
   428
@SYMTestCaseDesc		Test that the API GetSurfaceHint() behaves correctly in the multi-process case. 
sl@0
   429
						Process 1: Create the surface in a new shared chunk with valid creation attributes.
sl@0
   430
						Process 2: Set a THintPair with a key value set to 0x124580 and value set to 300, iMutable set to ETrue.
sl@0
   431
						Process 2: Call GetSurfaceHint()and Check it returns KErrAccessDenied
sl@0
   432
						Process 2: Open the surface and then Call SetSurfaceHint(), Check it returns KErrNone.
sl@0
   433
						Process 2: Call GetSurfaceHint() to retrieve the THintPair with the key value 0x124578
sl@0
   434
								   Check the THintPair has the iValue set to 20 and iMutable set to ETrue.
sl@0
   435
@SYMTestStatus			Implemented
sl@0
   436
@SYMTestActions			Call CreateSurface(),OpenSurface(), GetSurfaceHint()
sl@0
   437
@SYMTestExpectedResults GetSurfaceHint() behaves properly in the multiprocess. 
sl@0
   438
*/
sl@0
   439
	case 20:
sl@0
   440
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0063"));
sl@0
   441
		TestGetSurfaceHintMultiProcessL();
sl@0
   442
		break;
sl@0
   443
/**
sl@0
   444
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0064
sl@0
   445
@SYMPREQ				PREQ1007, PREQ 1879
sl@0
   446
@SYMREQ					REQ8222,REQ8223
sl@0
   447
@SYMTestPriority		High 
sl@0
   448
@SYMTestCaseDesc		Test that the API SetSurfaceHint() behaves correctly in the multi-process case. 
sl@0
   449
						Process 1: Create the surface in a new shared chunk with valid creation attributes.
sl@0
   450
						Process 2: Set a THintPair with a key value set to 0x124580 and value set to 300, iMutable set to ETrue.
sl@0
   451
						Process 2: Call SetSurfaceHint()and Check it returns KErrAccessDenied
sl@0
   452
						Process 2: Open the surface and then Call SetSurfaceHint(), Check it returns KErrNone.
sl@0
   453
						Process 2: Call GetSurfaceHint() to retrieve the THintPair with the key value 0x124578
sl@0
   454
								   Check the retrieved THintPair has the iValue set to 300.
sl@0
   455
@SYMTestStatus			Implemented
sl@0
   456
@SYMTestActions			Call CreateSurface(),OpenSurface(), SetSurfaceHint(),GetSurfaceHint()
sl@0
   457
@SYMTestExpectedResults SetSurfaceHint() behaves properly in the multiprocess. 
sl@0
   458
*/
sl@0
   459
	case 21:
sl@0
   460
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0064"));
sl@0
   461
		TestSetSurfaceHintMultiProcessL();
sl@0
   462
		break;
sl@0
   463
/**
sl@0
   464
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0065
sl@0
   465
@SYMPREQ				PREQ1007, PREQ 1879
sl@0
   466
@SYMREQ					REQ8222,REQ8223
sl@0
   467
@SYMTestPriority		High 
sl@0
   468
@SYMTestCaseDesc		Test that the API AddSurfaceHint() behaves correctly in the multi-process case. 
sl@0
   469
						Process 1: Process 1: Create the surface in a new shared chunk with valid creation attributes.
sl@0
   470
						Process 2: Set a THintPair with a key value set to 0x124580 and value set to 300, iMutable set to ETrue.
sl@0
   471
						Process 2: Call AddSurfaceHint()and Check it returns KErrAccessDenied
sl@0
   472
						Process 2: Open the surface and then Call AddSurfaceHint(), Check it returns KErrNone.
sl@0
   473
						Process 2: Call GetSurfaceHint() to retrieve the THintPair with the key value 0x124580
sl@0
   474
								   Check the retrieved THintPair has the iValue set to 300 and iMutable set to ETrue.
sl@0
   475
@SYMTestStatus			Implemented
sl@0
   476
@SYMTestActions			Call CreateSurface(),OpenSurface(), GetSurfaceHint(), AddSurfaceHint()
sl@0
   477
@SYMTestExpectedResults AddSurfaceHint() behaves properly in the multiprocess. 
sl@0
   478
*/
sl@0
   479
	case 22:
sl@0
   480
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0065"));
sl@0
   481
		TestAddSurfaceHintMultiProcessL();
sl@0
   482
		break;
sl@0
   483
/**
sl@0
   484
@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0066
sl@0
   485
@SYMPREQ				PREQ1007, PREQ 1879
sl@0
   486
@SYMREQ					REQ8222,REQ8223
sl@0
   487
@SYMTestPriority		High 
sl@0
   488
@SYMTestCaseDesc		Testing how OpenSurface() and AddConnection() behanves under out of memory conditions 
sl@0
   489
						Process 1: Create a surface and pass it in to the second process
sl@0
   490
						Process 2: Open the surface manager, inducing a kernel alloc failure on each possible kernel alloc with the use of MACRO(__KHEAP_SETFAIL).
sl@0
   491
						Check that returns KerrNoMemory
sl@0
   492
						Process 2: Call OpenSurface() on the new shared chunk, inducing a kernel alloc failure on each possible kernel alloc with the use of MACRO(__KHEAP_SETFAIL).
sl@0
   493
						Check that returns KerrNoMemory
sl@0
   494
@SYMTestStatus			Implemented
sl@0
   495
@SYMTestActions			Call CreateSurface(),OpenSurface(), RSurfaceManager::Open()
sl@0
   496
@SYMTestExpectedResults OpenSurface and AddConnection should return KerrNoMemory. 
sl@0
   497
*/		
sl@0
   498
	case 23:
sl@0
   499
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   500
#ifdef _DEBUG
sl@0
   501
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0066"));
sl@0
   502
		TestOutofMemoryCasesL();
sl@0
   503
#endif
sl@0
   504
		break;
sl@0
   505
	default:
sl@0
   506
		((CTSurfaceManagerMultiProcessStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   507
		((CTSurfaceManagerMultiProcessStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   508
		TestComplete();
sl@0
   509
		break;
sl@0
   510
		}
sl@0
   511
	((CTSurfaceManagerMultiProcessStep*)iStep)->RecordTestResultL();
sl@0
   512
	// Handle check
sl@0
   513
	TInt procHandles2  =0;
sl@0
   514
	TInt threadHandles2=0;
sl@0
   515
	RThread().HandleCount(procHandles2,threadHandles2);
sl@0
   516
	if (threadHandles1 != threadHandles2)
sl@0
   517
		{
sl@0
   518
		User::Leave(KErrGeneral);  // Thread-owned handles not closed
sl@0
   519
		}
sl@0
   520
 
sl@0
   521
	}
sl@0
   522
sl@0
   523
void CTSurfaceManagerMultiProcess::TestMapSurfaceExistinChunkL()
sl@0
   524
	{
sl@0
   525
	// Create a surface in a new shared chunk
sl@0
   526
	INFO_PRINTF1(_L("Test mapping a surface created in the existing shared chunk to a different process\r\n"));
sl@0
   527
	// Open the surface manager
sl@0
   528
	RSurfaceManager surfaceManager;
sl@0
   529
 	User::LeaveIfError(surfaceManager.Open());
sl@0
   530
	CleanupClosePushL(surfaceManager);
sl@0
   531
sl@0
   532
	TRequestStatus status;
sl@0
   533
	// Setup attributes 
sl@0
   534
   	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   535
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
   536
	attributes.iSize = TSize(100,100);
sl@0
   537
	attributes.iBuffers = 1;				// number of buffers in the surface
sl@0
   538
	attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;		// 2bpp
sl@0
   539
	attributes.iStride = 400;				// Number of bytes between start of one line and start of next
sl@0
   540
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
   541
	attributes.iAlignment = 2;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
   542
	attributes.iMappable = ETrue;
sl@0
   543
	
sl@0
   544
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
   545
	attributes.iHintCount = 2;
sl@0
   546
	attributes.iSurfaceHints = hints;
sl@0
   547
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
   548
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
   549
sl@0
   550
	attributes.iContiguous = ETrue;
sl@0
   551
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
   552
	attributes.iOffsetBetweenBuffers = 0;
sl@0
   553
		
sl@0
   554
	// Test create surface doesn't return an error
sl@0
   555
	TSurfaceId surfaceId;
sl@0
   556
	
sl@0
   557
	// Test create surface doesn't return an error
sl@0
   558
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
   559
	
sl@0
   560
	//store all the attributes
sl@0
   561
	RSurfaceManager::TInfoBuf infoBuf;
sl@0
   562
	TEST(KErrNone == surfaceManager.SurfaceInfo(surfaceId, infoBuf));
sl@0
   563
	
sl@0
   564
	//Map the surface in the current processs
sl@0
   565
	RChunk handle;
sl@0
   566
	TEST(KErrNone == surfaceManager.MapSurface(surfaceId,handle));
sl@0
   567
	
sl@0
   568
	// Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
sl@0
   569
  	RSurfaceManager::TSurfaceCreationAttributesBuf buff;
sl@0
   570
	RSurfaceManager::TSurfaceCreationAttributes& attributesNew = buff();
sl@0
   571
sl@0
   572
	attributesNew.iSize = TSize(480,16);
sl@0
   573
	attributesNew.iBuffers = 2;				// number of buffers in the surface
sl@0
   574
	attributesNew.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
   575
	attributesNew.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
   576
	attributesNew.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
   577
	attributesNew.iMappable = ETrue;
sl@0
   578
	
sl@0
   579
	attributes.iHintCount = 1;
sl@0
   580
	attributes.iSurfaceHints = hints;
sl@0
   581
	hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
sl@0
   582
	
sl@0
   583
	attributesNew.iAlignment = RSurfaceManager::EPageAligned;
sl@0
   584
	attributesNew.iOffsetBetweenBuffers = 0;
sl@0
   585
		
sl@0
   586
	// Test create surface doesn't return an error
sl@0
   587
	TSurfaceId surfaceIdNew;
sl@0
   588
	// Test create surface doesn't return an error
sl@0
   589
	// For the time being KErrArgument will be returned as the core codes are
sl@0
   590
	// not ready to check the passed in shared chunk handle.
sl@0
   591
	TEST(KErrNone == surfaceManager.CreateSurface(buff, surfaceIdNew, handle));
sl@0
   592
	
sl@0
   593
	iInfo2.iSurfaceId = surfaceId;
sl@0
   594
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
   595
sl@0
   596
  	// Create a TCleanupItem object
sl@0
   597
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
   598
sl@0
   599
    // Save the surfaceId to the shared chunk
sl@0
   600
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
   601
    chunkWrapper->SetId(surfaceId);
sl@0
   602
   	CleanupStack::Pop();
sl@0
   603
sl@0
   604
    // Create a second process
sl@0
   605
    RProcess process;
sl@0
   606
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
   607
sl@0
   608
	// Specify the test for the second process
sl@0
   609
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ECheckHandle));
sl@0
   610
	// Kick off the second process and wait for it to complete
sl@0
   611
	// The actual testing is done in the second process
sl@0
   612
	process.Logon(status);
sl@0
   613
	process.Resume();
sl@0
   614
	User::WaitForRequest(status);
sl@0
   615
	
sl@0
   616
	// Check the results of the second process tests
sl@0
   617
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
   618
	TEST(result & EFirstTestPassed);
sl@0
   619
	TEST(result & ESecondTestPassed);
sl@0
   620
	TEST(result & EThirdTestPassed);
sl@0
   621
sl@0
   622
	
sl@0
   623
	// Get the adress of this chunk of memory
sl@0
   624
	TUint8* surfaceAdd = handle.Base();
sl@0
   625
	TUint8* bufferAdd = surfaceAdd + attributes.iOffsetToFirstBuffer;
sl@0
   626
	
sl@0
   627
	// Reads from first buffer, and test the value is written
sl@0
   628
	TInt temp = *bufferAdd;
sl@0
   629
	TEST(temp == 20);
sl@0
   630
	
sl@0
   631
	// Delete the chunkWrapper
sl@0
   632
	delete chunkWrapper;
sl@0
   633
	process.Close();	
sl@0
   634
	handle.Close();
sl@0
   635
	CleanupStack::PopAndDestroy(1, &surfaceManager);
sl@0
   636
	}
sl@0
   637
sl@0
   638
void CTSurfaceManagerMultiProcess::TestSynchronizeCacheMultiProcessL()
sl@0
   639
	{
sl@0
   640
	// Create a surface in a new shared chunk
sl@0
   641
	INFO_PRINTF1(_L("Test that the API SynchronizeCache() behaves correctly in the multi-process case\r\n"));
sl@0
   642
	// Open the surface manager
sl@0
   643
	RSurfaceManager surfaceManager;
sl@0
   644
 	User::LeaveIfError(surfaceManager.Open());
sl@0
   645
	CleanupClosePushL(surfaceManager);
sl@0
   646
sl@0
   647
	TRequestStatus status;
sl@0
   648
	// Setup attributes 
sl@0
   649
	
sl@0
   650
   	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   651
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
   652
sl@0
   653
	attributes.iSize = TSize(480,16);
sl@0
   654
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
   655
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
   656
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
   657
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
   658
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
   659
	
sl@0
   660
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
   661
	attributes.iHintCount = 2;
sl@0
   662
	attributes.iSurfaceHints = hints;
sl@0
   663
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
   664
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
   665
	
sl@0
   666
	attributes.iContiguous = ETrue;
sl@0
   667
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
   668
	attributes.iOffsetBetweenBuffers = 0;
sl@0
   669
	attributes.iMappable = ETrue;
sl@0
   670
	
sl@0
   671
	// Test create surface doesn't return an error
sl@0
   672
	TSurfaceId surfaceId;
sl@0
   673
	
sl@0
   674
	// Test create surface doesn't return an error
sl@0
   675
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
   676
	
sl@0
   677
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
   678
	iInfo2.iSurfaceId = surfaceId;		
sl@0
   679
	// Create a TCleanupItem object
sl@0
   680
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
   681
sl@0
   682
    // Save the surfaceId to the shared chunk
sl@0
   683
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
   684
    chunkWrapper->SetId(surfaceId);
sl@0
   685
   	CleanupStack::Pop();
sl@0
   686
sl@0
   687
    // Create a second process
sl@0
   688
    RProcess process;
sl@0
   689
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
   690
sl@0
   691
	// Specify the test for the second process
sl@0
   692
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ESyncOperation));
sl@0
   693
	// Kick off the second process and wait for it to complete
sl@0
   694
	// The actual testing is done in the second process
sl@0
   695
	process.Logon(status);
sl@0
   696
	process.Resume();
sl@0
   697
	User::WaitForRequest(status);
sl@0
   698
	
sl@0
   699
	// Check the results of the second process tests
sl@0
   700
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
   701
	// Only four tests were carried out in the second process
sl@0
   702
	TEST(result & EFirstTestPassed);
sl@0
   703
	TEST(result & ESecondTestPassed);
sl@0
   704
	TEST(result & EThirdTestPassed);
sl@0
   705
	TEST(result & EFourthTestPassed);
sl@0
   706
	// Delete the chunkWrapper
sl@0
   707
	delete chunkWrapper;
sl@0
   708
	process.Close();	
sl@0
   709
	CleanupStack::PopAndDestroy(1, &surfaceManager);
sl@0
   710
sl@0
   711
	}
sl@0
   712
sl@0
   713
sl@0
   714
void CTSurfaceManagerMultiProcess::TestCloseChannelsMultiProcess1L()
sl@0
   715
	{
sl@0
   716
	// Create a surface in a new shared chunk
sl@0
   717
	INFO_PRINTF1(_L("Testing the behaviour of closing driver channels in multiple processes when  the last channel to the device driver is closed\r\n"));
sl@0
   718
	
sl@0
   719
	// Create a semaphore
sl@0
   720
	const TInt initCount = 0;
sl@0
   721
	RSemaphore sem;
sl@0
   722
	TEST(KErrNone == sem.CreateGlobal(KMultiProcessSemaphore, initCount));
sl@0
   723
	CleanupClosePushL(sem);
sl@0
   724
	RSemaphore sem2;
sl@0
   725
	TEST(KErrNone == sem2.CreateGlobal(KMultiProcessSemaphore2, initCount));
sl@0
   726
	CleanupClosePushL(sem2);
sl@0
   727
	
sl@0
   728
	// Open the surface manager
sl@0
   729
	RSurfaceManager surfaceManagerOne;
sl@0
   730
	// Close the surface manager without opening it first
sl@0
   731
	INFO_PRINTF1(_L("Close the surface manager without opening it first\r\n"));
sl@0
   732
	// Is this Ok?
sl@0
   733
//	surfaceManagerOne.Close();
sl@0
   734
 
sl@0
   735
	User::LeaveIfError(surfaceManagerOne.Open());
sl@0
   736
 	CleanupClosePushL(surfaceManagerOne);
sl@0
   737
   	// Store the attributes used to create the Surface
sl@0
   738
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   739
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
   740
	attributes.iSize = TSize(280,301);
sl@0
   741
	attributes.iBuffers = 1;
sl@0
   742
	attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
sl@0
   743
	attributes.iStride = 1;
sl@0
   744
	attributes.iOffsetToFirstBuffer = 1;
sl@0
   745
	attributes.iAlignment = 1;
sl@0
   746
	
sl@0
   747
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
   748
	attributes.iHintCount = 2;
sl@0
   749
	attributes.iSurfaceHints = hints;
sl@0
   750
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
   751
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
   752
	
sl@0
   753
	attributes.iContiguous = ETrue;
sl@0
   754
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
   755
	attributes.iOffsetBetweenBuffers = 0;
sl@0
   756
	attributes.iMappable = ETrue;
sl@0
   757
	
sl@0
   758
	// Create a surface
sl@0
   759
	TSurfaceId surfaceIdOne;
sl@0
   760
	TEST(KErrNone == surfaceManagerOne.CreateSurface(buf, surfaceIdOne));
sl@0
   761
sl@0
   762
	RSurfaceManager surfaceManagerTwo;
sl@0
   763
	User::LeaveIfError(surfaceManagerTwo.Open());
sl@0
   764
	CleanupClosePushL(surfaceManagerTwo);
sl@0
   765
	// Create a surface
sl@0
   766
	TSurfaceId surfaceIdTwo;
sl@0
   767
	TEST(KErrNone == surfaceManagerTwo.CreateSurface(buf,surfaceIdTwo));
sl@0
   768
sl@0
   769
	TEST(KErrNone == surfaceManagerOne.OpenSurface(surfaceIdTwo));
sl@0
   770
	TEST(KErrNone == surfaceManagerTwo.OpenSurface(surfaceIdOne));
sl@0
   771
sl@0
   772
	iInfo2.iSurfaceId = surfaceIdOne;
sl@0
   773
	iInfo2.iSurfaceManager = surfaceManagerOne;
sl@0
   774
	// Create a TCleanupItem object
sl@0
   775
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
   776
sl@0
   777
    // Save the surfaceId to the shared chunk
sl@0
   778
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
   779
    chunkWrapper->SetId(surfaceIdOne);
sl@0
   780
   	CleanupStack::Pop();
sl@0
   781
sl@0
   782
	// Create a second process
sl@0
   783
	RProcess process;
sl@0
   784
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
   785
	
sl@0
   786
	// Kick off the process and wait for it to complete
sl@0
   787
	TRequestStatus status = KRequestPending;
sl@0
   788
	process.Logon(status);
sl@0
   789
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ETestChannelMultiProcess1));
sl@0
   790
	process.Resume();
sl@0
   791
	CleanupClosePushL(process);
sl@0
   792
	
sl@0
   793
	// Passes control to the second process
sl@0
   794
	sem.Wait();
sl@0
   795
	
sl@0
   796
	// Check the results of the second process tests
sl@0
   797
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
   798
	TEST(result & EFirstTestPassed);
sl@0
   799
	TEST(result & ESecondTestPassed);
sl@0
   800
	TEST(result & EThirdTestPassed);
sl@0
   801
	
sl@0
   802
	surfaceManagerOne.Close();
sl@0
   803
	surfaceManagerTwo.Close();
sl@0
   804
sl@0
   805
	// Pass control off to the second process again
sl@0
   806
	chunkWrapper->SetId(surfaceIdTwo);
sl@0
   807
	sem2.Signal();
sl@0
   808
sl@0
   809
	// Wait for the second process to terminate
sl@0
   810
	User::WaitForRequest(status);
sl@0
   811
	
sl@0
   812
sl@0
   813
	// Copme back from the second process - find the surfaceId
sl@0
   814
	// Check that the tests in the second process have passed 
sl@0
   815
	result = chunkWrapper->GetSecondProcessResults();
sl@0
   816
	TEST(result & EFourthTestPassed);
sl@0
   817
	TEST(result & EFifthTestPassed);
sl@0
   818
	//More things to check in here
sl@0
   819
//	TEST(KErrNone == surfaceManagerOne.Open()));
sl@0
   820
	
sl@0
   821
	// Delete the chunkWrapper and the semaphore
sl@0
   822
	delete chunkWrapper;
sl@0
   823
	CleanupStack::PopAndDestroy(5, &sem);
sl@0
   824
	
sl@0
   825
sl@0
   826
	}
sl@0
   827
sl@0
   828
void CTSurfaceManagerMultiProcess::TestCloseChannelsMultiProcess2L()
sl@0
   829
	{
sl@0
   830
	// Create a surface in a new shared chunk
sl@0
   831
	INFO_PRINTF1(_L("Testing the behaviour of closing driver channels in multiple processes when  the last channel to the device driver is closed\r\n"));
sl@0
   832
	
sl@0
   833
	// Create a semaphore
sl@0
   834
	const TInt initCount = 0;
sl@0
   835
	RSemaphore sem;
sl@0
   836
	TEST(KErrNone == sem.CreateGlobal(KMultiProcessSemaphore, initCount));
sl@0
   837
	CleanupClosePushL(sem);
sl@0
   838
	RSemaphore sem2;
sl@0
   839
	TEST(KErrNone == sem2.CreateGlobal(KMultiProcessSemaphore2, initCount));
sl@0
   840
	CleanupClosePushL(sem2);
sl@0
   841
	
sl@0
   842
	// Create a second process
sl@0
   843
	RProcess process;
sl@0
   844
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
   845
	
sl@0
   846
	// Kick off the process and wait for it to complete
sl@0
   847
	TRequestStatus status = KRequestPending;
sl@0
   848
	process.Logon(status);
sl@0
   849
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ETestChannelMultiProcess2));
sl@0
   850
	process.Resume();
sl@0
   851
	CleanupClosePushL(process);
sl@0
   852
	
sl@0
   853
	// Passes control to the second process
sl@0
   854
	sem.Wait();
sl@0
   855
		
sl@0
   856
	// Open the chunk wrapper and get the surfaceId
sl@0
   857
	CChunkWrapper* chunkWrapper = CChunkWrapper::OpenL(KSharedChunkName, ETrue);
sl@0
   858
	TSurfaceId surfaceIdOne = chunkWrapper->GetId();
sl@0
   859
	// Check the results of the second process tests
sl@0
   860
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
   861
	TEST(result & EFirstTestPassed);
sl@0
   862
	TEST(result & ESecondTestPassed);
sl@0
   863
	TEST(result & EThirdTestPassed);
sl@0
   864
	TEST(result & EFourthTestPassed);
sl@0
   865
sl@0
   866
	// Open the surface manager
sl@0
   867
	RSurfaceManager surfaceManagerThree;
sl@0
   868
 	User::LeaveIfError(surfaceManagerThree.Open());
sl@0
   869
	CleanupClosePushL(surfaceManagerThree);
sl@0
   870
	
sl@0
   871
	TEST(KErrNone == surfaceManagerThree.OpenSurface(surfaceIdOne));
sl@0
   872
	// Pass control off to the second process again
sl@0
   873
	sem2.Signal();
sl@0
   874
sl@0
   875
	// Wait for the second process to terminate
sl@0
   876
	User::WaitForRequest(status);
sl@0
   877
	
sl@0
   878
	TSurfaceId surfaceIdTwo = chunkWrapper->GetId();
sl@0
   879
	
sl@0
   880
	// Call OpenSurface() on surfaceID1 using SurfaceManager3 and check it returns KErrNone, as the surfaceID1 is still open
sl@0
   881
	TEST(KErrNone == surfaceManagerThree.OpenSurface(surfaceIdOne));
sl@0
   882
	// Call OpenSurface() on surfaceID1 using SurfaceManager3 and check it returns KErrNone, as the surfaceID1 is still open
sl@0
   883
	TEST(KErrArgument == surfaceManagerThree.OpenSurface(surfaceIdTwo));
sl@0
   884
sl@0
   885
	// Delete the chunkWrapper and the semaphore
sl@0
   886
	delete chunkWrapper;
sl@0
   887
	CleanupStack::PopAndDestroy(4, &sem);
sl@0
   888
	}
sl@0
   889
sl@0
   890
sl@0
   891
void CTSurfaceManagerMultiProcess::TestSurfaceInfoUsingSurfaceIdL()
sl@0
   892
	{
sl@0
   893
	INFO_PRINTF1(_L("Receiving a surface and querying SurfaceInfo for surface properties\r\n"));
sl@0
   894
	// Open the surface manager
sl@0
   895
	RSurfaceManager surfaceManager;
sl@0
   896
 	User::LeaveIfError(surfaceManager.Open());
sl@0
   897
	CleanupClosePushL(surfaceManager);
sl@0
   898
sl@0
   899
	TRequestStatus status;
sl@0
   900
	
sl@0
   901
	// Set attributs for creating the surface
sl@0
   902
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   903
	RSurfaceManager::TSurfaceCreationAttributes& attributes=buf();
sl@0
   904
    attributes.iSize = TSize(100,100);
sl@0
   905
    attributes.iBuffers = 1;                // number of buffers in the surface
sl@0
   906
    attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;     // 2bpp
sl@0
   907
    attributes.iStride = 400;               // Number of bytes between start of one line and start of next
sl@0
   908
    attributes.iOffsetToFirstBuffer = 0;    // way of reserving space before the surface pixel data
sl@0
   909
    attributes.iAlignment = 2;          // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
   910
    attributes.iContiguous=ETrue; 
sl@0
   911
	
sl@0
   912
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
   913
	attributes.iHintCount = 2;
sl@0
   914
	attributes.iSurfaceHints = hints;
sl@0
   915
	hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
sl@0
   916
	hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
sl@0
   917
	
sl@0
   918
	attributes.iOffsetBetweenBuffers = 0;
sl@0
   919
	attributes.iCacheAttrib = RSurfaceManager::ENotCached;
sl@0
   920
	attributes.iMappable = ETrue;
sl@0
   921
	
sl@0
   922
	// Create the surface
sl@0
   923
	TSurfaceId surfaceId;
sl@0
   924
    TEST(KErrNone == surfaceManager.CreateSurface(attributes, surfaceId));
sl@0
   925
sl@0
   926
    iInfo2.iSurfaceId = surfaceId;
sl@0
   927
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
   928
	// Create a TCleanupItem object
sl@0
   929
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
   930
sl@0
   931
    // Save the surfaceId to the shared chunk
sl@0
   932
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
   933
    chunkWrapper->SetId(surfaceId);
sl@0
   934
   	CleanupStack::Pop();
sl@0
   935
sl@0
   936
    // Create a second process
sl@0
   937
    RProcess process;
sl@0
   938
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
   939
sl@0
   940
	// Specify the test for the second process
sl@0
   941
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ETestInfoReceivedSurface));
sl@0
   942
	// Kick off the second process and wait for it to complete
sl@0
   943
	// The actual testing is done in the second process
sl@0
   944
	process.Logon(status);
sl@0
   945
	process.Resume();
sl@0
   946
	User::WaitForRequest(status);
sl@0
   947
	
sl@0
   948
	// Check the results of the second process tests
sl@0
   949
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
   950
	TEST(result & EFirstTestPassed);
sl@0
   951
	TEST(result & ESecondTestPassed);
sl@0
   952
	TEST(result & EThirdTestPassed);
sl@0
   953
	TEST(result & EFourthTestPassed);
sl@0
   954
	TEST(result & EFifthTestPassed);
sl@0
   955
	TEST(result & ESixthTestPassed);
sl@0
   956
	TEST(result & ESeventhTestPassed);
sl@0
   957
	TEST(result & EEighthTestPassed);
sl@0
   958
	TEST(result & ENinthTestPassed);
sl@0
   959
sl@0
   960
	// Delete the chunkWrapper
sl@0
   961
	delete chunkWrapper;
sl@0
   962
	process.Close();	
sl@0
   963
	CleanupStack::PopAndDestroy(1, &surfaceManager);
sl@0
   964
sl@0
   965
	}
sl@0
   966
	
sl@0
   967
void CTSurfaceManagerMultiProcess::TestOpeningSurfaceUsingSurfaceIdL()
sl@0
   968
	{
sl@0
   969
	INFO_PRINTF1(_L("Test Opening a surface using surfaceId (passed from this to another process)\r\n"));
sl@0
   970
	// Open the surface manager
sl@0
   971
	RSurfaceManager surfaceManager;
sl@0
   972
 	User::LeaveIfError(surfaceManager.Open());
sl@0
   973
	CleanupClosePushL(surfaceManager);
sl@0
   974
sl@0
   975
	TRequestStatus status;
sl@0
   976
	
sl@0
   977
	// Set attributs for creating the surface
sl@0
   978
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
   979
	RSurfaceManager::TSurfaceCreationAttributes& attributes=buf();
sl@0
   980
	attributes.iSize = TSize(200,200);
sl@0
   981
	attributes.iBuffers = 1;				
sl@0
   982
	attributes.iPixelFormat = EUidPixelFormatARGB_1555;		
sl@0
   983
	attributes.iStride = 1600;				
sl@0
   984
	attributes.iOffsetToFirstBuffer = 80;	
sl@0
   985
	attributes.iAlignment = 8;			
sl@0
   986
	attributes.iContiguous = ETrue;
sl@0
   987
	
sl@0
   988
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
   989
	attributes.iHintCount = 2;
sl@0
   990
	attributes.iSurfaceHints = hints;
sl@0
   991
	hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
sl@0
   992
	hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
sl@0
   993
sl@0
   994
	attributes.iOffsetBetweenBuffers = 0;
sl@0
   995
	attributes.iMappable = ETrue;
sl@0
   996
sl@0
   997
	// Create the surface
sl@0
   998
	TSurfaceId surfaceId;
sl@0
   999
    TEST(KErrNone == surfaceManager.CreateSurface(attributes, surfaceId));
sl@0
  1000
sl@0
  1001
	iInfo2.iSurfaceId = surfaceId;
sl@0
  1002
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  1003
	// Create a TCleanupItem object
sl@0
  1004
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  1005
sl@0
  1006
    // Save the surfaceId to the shared chunk
sl@0
  1007
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  1008
    chunkWrapper->SetId(surfaceId);
sl@0
  1009
   	CleanupStack::Pop();
sl@0
  1010
 
sl@0
  1011
    // Create a second process
sl@0
  1012
    RProcess process;
sl@0
  1013
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  1014
sl@0
  1015
	// Specify the test for the second process
sl@0
  1016
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ETestOpenReceivedSurface));	
sl@0
  1017
	process.Logon(status);
sl@0
  1018
	process.Resume();
sl@0
  1019
	User::WaitForRequest(status);
sl@0
  1020
	
sl@0
  1021
	// Check the test results of the second process
sl@0
  1022
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  1023
	TEST(result & EFirstTestPassed);
sl@0
  1024
sl@0
  1025
	// Delete the chunkWrapper
sl@0
  1026
	delete chunkWrapper;
sl@0
  1027
	process.Close();
sl@0
  1028
	CleanupStack::PopAndDestroy(1, &surfaceManager);
sl@0
  1029
sl@0
  1030
	}
sl@0
  1031
sl@0
  1032
void CTSurfaceManagerMultiProcess::TestOpenSurfaceInvalidParamsL()
sl@0
  1033
	{
sl@0
  1034
   	INFO_PRINTF1(_L("Opening a surface with invalid parameters\r\n"));
sl@0
  1035
   	RSurfaceManager surfaceManager;
sl@0
  1036
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1037
	CleanupClosePushL(surfaceManager);
sl@0
  1038
sl@0
  1039
	// Store the attributes used to create the Surface
sl@0
  1040
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1041
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1042
	
sl@0
  1043
	attributes.iSize = TSize(150,412);
sl@0
  1044
	attributes.iBuffers = 3;
sl@0
  1045
	attributes.iPixelFormat = EUidPixelFormatARGB_1555; // 2bpp
sl@0
  1046
	attributes.iStride = 1000;
sl@0
  1047
	attributes.iOffsetToFirstBuffer = 5;
sl@0
  1048
	attributes.iAlignment = 1;
sl@0
  1049
	attributes.iContiguous=EFalse;
sl@0
  1050
	
sl@0
  1051
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1052
	attributes.iHintCount = 2;
sl@0
  1053
	attributes.iSurfaceHints = hints;
sl@0
  1054
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  1055
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  1056
	
sl@0
  1057
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  1058
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1059
	attributes.iMappable = ETrue;
sl@0
  1060
	
sl@0
  1061
	// Create a surface - increments reference count by 1
sl@0
  1062
	TSurfaceId surfaceId;
sl@0
  1063
    TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  1064
		
sl@0
  1065
	iInfo2.iSurfaceId = surfaceId;
sl@0
  1066
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  1067
	// Create a TCleanupItem object
sl@0
  1068
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  1069
sl@0
  1070
    // Save the surfaceId to the shared chunk
sl@0
  1071
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  1072
    chunkWrapper->SetId(surfaceId);
sl@0
  1073
sl@0
  1074
   	CleanupStack::Pop();
sl@0
  1075
sl@0
  1076
    // Create a second process
sl@0
  1077
    RProcess process;
sl@0
  1078
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  1079
sl@0
  1080
	// Specify the test for the second process
sl@0
  1081
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ETestOpenSurfaceInvalidParams));
sl@0
  1082
	// Kick off the second process and wait for it to complete
sl@0
  1083
	// The actual testing is done in the second process
sl@0
  1084
	TRequestStatus status;
sl@0
  1085
	process.Logon(status);
sl@0
  1086
	process.Resume();
sl@0
  1087
	User::WaitForRequest(status);
sl@0
  1088
	
sl@0
  1089
	// Check the results of the second process tests
sl@0
  1090
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  1091
	TEST(result & EFirstTestPassed);
sl@0
  1092
	TEST(result & ESecondTestPassed);
sl@0
  1093
	TEST(result & EThirdTestPassed);
sl@0
  1094
sl@0
  1095
	// Tidy up
sl@0
  1096
	delete chunkWrapper;
sl@0
  1097
	process.Close();
sl@0
  1098
	CleanupStack::PopAndDestroy(1, &surfaceManager);
sl@0
  1099
	}
sl@0
  1100
sl@0
  1101
void CTSurfaceManagerMultiProcess::TestClosingUnopenedSurfaceL()
sl@0
  1102
	{
sl@0
  1103
	INFO_PRINTF1(_L("Closing an unopened surface in a second process\r\n"));
sl@0
  1104
	// Open the surface manager
sl@0
  1105
	RSurfaceManager surfaceManager;
sl@0
  1106
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1107
	CleanupClosePushL(surfaceManager);
sl@0
  1108
sl@0
  1109
	// Store the attributes used to create the Surface
sl@0
  1110
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1111
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1112
	
sl@0
  1113
	attributes.iSize = TSize(280,301);
sl@0
  1114
	attributes.iBuffers = 3;
sl@0
  1115
	attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
sl@0
  1116
	attributes.iStride = 605;
sl@0
  1117
	attributes.iOffsetToFirstBuffer = 4;
sl@0
  1118
	attributes.iAlignment = 4;
sl@0
  1119
	attributes.iContiguous=EFalse;
sl@0
  1120
	
sl@0
  1121
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1122
	attributes.iHintCount = 2;
sl@0
  1123
	attributes.iSurfaceHints = hints;
sl@0
  1124
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  1125
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  1126
sl@0
  1127
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  1128
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1129
	attributes.iMappable = ETrue;
sl@0
  1130
sl@0
  1131
	// Create the surface
sl@0
  1132
	TSurfaceId surfaceId;
sl@0
  1133
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  1134
sl@0
  1135
	iInfo2.iSurfaceId = surfaceId;
sl@0
  1136
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  1137
	// Create a TCleanupItem object
sl@0
  1138
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  1139
sl@0
  1140
	// Save the surfaceId to the shared chunk
sl@0
  1141
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  1142
    chunkWrapper->SetId(surfaceId);
sl@0
  1143
   	CleanupStack::Pop();
sl@0
  1144
sl@0
  1145
	// Create a second process
sl@0
  1146
	RProcess process;
sl@0
  1147
	TEST(KErrNone == process.Create(KThirdProcess, KNullDesC));
sl@0
  1148
sl@0
  1149
	// Kick off the process and wait for it to complete
sl@0
  1150
	TRequestStatus status = KRequestPending;
sl@0
  1151
	process.Logon(status);
sl@0
  1152
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ECloseSurface));
sl@0
  1153
	process.Resume();
sl@0
  1154
	User::WaitForRequest(status);
sl@0
  1155
	
sl@0
  1156
	// Check the result
sl@0
  1157
	TInt result = chunkWrapper->GetThirdProcessResults();
sl@0
  1158
	TEST(result & EFirstTestPassed);
sl@0
  1159
	
sl@0
  1160
	// Delete the chunkWrapper
sl@0
  1161
	delete chunkWrapper;
sl@0
  1162
	process.Close();
sl@0
  1163
	CleanupStack::PopAndDestroy(1, &surfaceManager);
sl@0
  1164
	}
sl@0
  1165
sl@0
  1166
sl@0
  1167
void CTSurfaceManagerMultiProcess::TestSurfaceInfoUnopenedSurfaceL()
sl@0
  1168
	{
sl@0
  1169
	INFO_PRINTF1(_L("Access an unopened surface in a second process\r\n"));
sl@0
  1170
	// Open the surface manager
sl@0
  1171
	RSurfaceManager surfaceManager;
sl@0
  1172
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1173
	CleanupClosePushL(surfaceManager);
sl@0
  1174
sl@0
  1175
	// Store the attributes used to create the Surface
sl@0
  1176
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1177
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1178
	
sl@0
  1179
	attributes.iSize = TSize(280,301);
sl@0
  1180
	attributes.iBuffers = 3;
sl@0
  1181
	attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
sl@0
  1182
	attributes.iStride = 605;
sl@0
  1183
	attributes.iOffsetToFirstBuffer = 4;
sl@0
  1184
	attributes.iAlignment = 4;
sl@0
  1185
	attributes.iContiguous=EFalse;
sl@0
  1186
	
sl@0
  1187
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1188
	attributes.iHintCount = 2;
sl@0
  1189
	attributes.iSurfaceHints = hints;
sl@0
  1190
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  1191
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  1192
sl@0
  1193
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  1194
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1195
	attributes.iMappable = ETrue;
sl@0
  1196
sl@0
  1197
	// Create the surface
sl@0
  1198
	TSurfaceId surfaceId;
sl@0
  1199
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  1200
	
sl@0
  1201
	iInfo2.iSurfaceId = surfaceId;
sl@0
  1202
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  1203
	// Create a TCleanupItem object
sl@0
  1204
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  1205
sl@0
  1206
	// Save the surfaceId to the shared chunk
sl@0
  1207
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  1208
    chunkWrapper->SetId(surfaceId);
sl@0
  1209
   	CleanupStack::Pop();
sl@0
  1210
sl@0
  1211
	// Create a second process
sl@0
  1212
	RProcess process;
sl@0
  1213
	TEST(KErrNone == process.Create(KThirdProcess, KNullDesC));
sl@0
  1214
sl@0
  1215
	// Kick off the process and wait for it to complete
sl@0
  1216
	TRequestStatus status = KRequestPending;
sl@0
  1217
	process.Logon(status);
sl@0
  1218
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ESurfaceInfo));
sl@0
  1219
	process.Resume();
sl@0
  1220
	User::WaitForRequest(status);
sl@0
  1221
	
sl@0
  1222
	// Check the result
sl@0
  1223
	TInt result = chunkWrapper->GetThirdProcessResults();
sl@0
  1224
	TEST(result & EFirstTestPassed);
sl@0
  1225
	
sl@0
  1226
	// Delete the chunkWrapper
sl@0
  1227
	delete chunkWrapper;
sl@0
  1228
	process.Close();
sl@0
  1229
	CleanupStack::PopAndDestroy(1, &surfaceManager);
sl@0
  1230
sl@0
  1231
	}
sl@0
  1232
	
sl@0
  1233
void CTSurfaceManagerMultiProcess::CreateOpenCloseThreeProcessL()
sl@0
  1234
	{
sl@0
  1235
	INFO_PRINTF1(_L("Create Open close across 3 processes\r\n"));
sl@0
  1236
	// Open the surface manager
sl@0
  1237
	RSurfaceManager surfaceManager;
sl@0
  1238
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1239
	CleanupClosePushL(surfaceManager);
sl@0
  1240
	
sl@0
  1241
	// Store the attributes used to create the Surface
sl@0
  1242
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1243
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1244
	
sl@0
  1245
	attributes.iSize = TSize(280,230);
sl@0
  1246
	attributes.iBuffers = 3;
sl@0
  1247
	attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
sl@0
  1248
	attributes.iStride = 1100;
sl@0
  1249
	attributes.iOffsetToFirstBuffer = 4;
sl@0
  1250
	attributes.iAlignment = 4;
sl@0
  1251
	attributes.iContiguous=EFalse;
sl@0
  1252
	
sl@0
  1253
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1254
	attributes.iHintCount = 2;
sl@0
  1255
	attributes.iSurfaceHints = hints;
sl@0
  1256
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  1257
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  1258
sl@0
  1259
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  1260
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1261
	attributes.iMappable = ETrue;
sl@0
  1262
sl@0
  1263
	// Create the surface
sl@0
  1264
	TSurfaceId surfaceId;
sl@0
  1265
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  1266
	
sl@0
  1267
	// Create a semaphore
sl@0
  1268
	const TInt initCount = 0;
sl@0
  1269
	RSemaphore sem;
sl@0
  1270
	TEST(KErrNone == sem.CreateGlobal(KMultiProcessSemaphore, initCount));
sl@0
  1271
	CleanupClosePushL(sem);
sl@0
  1272
	RSemaphore sem2;
sl@0
  1273
	TEST(KErrNone == sem2.CreateGlobal(KMultiProcessSemaphore2, initCount));
sl@0
  1274
	CleanupClosePushL(sem2);
sl@0
  1275
	
sl@0
  1276
sl@0
  1277
	iInfo2.iSurfaceId = surfaceId;
sl@0
  1278
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  1279
	// Create a TCleanupItem object
sl@0
  1280
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  1281
sl@0
  1282
	// Save the surfaceId to the shared chunk
sl@0
  1283
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  1284
    chunkWrapper->SetId(surfaceId);
sl@0
  1285
   	CleanupStack::Pop();
sl@0
  1286
sl@0
  1287
	// Create a second process
sl@0
  1288
	RProcess process2;
sl@0
  1289
	TEST(KErrNone == process2.Create(KSecondProcess, KNullDesC));
sl@0
  1290
sl@0
  1291
	// Kick off the process and wait for it to complete
sl@0
  1292
	TRequestStatus status2 = KRequestPending;
sl@0
  1293
	process2.Logon(status2);
sl@0
  1294
	process2.SetParameter(EMultiProcessSecondSlot, EOpenWaitMap);
sl@0
  1295
	process2.Resume();
sl@0
  1296
	
sl@0
  1297
	// Passes control to the second process
sl@0
  1298
	sem.Wait();
sl@0
  1299
	
sl@0
  1300
	// Create a third process
sl@0
  1301
	RProcess process3;
sl@0
  1302
	TEST(KErrNone == process3.Create(KThirdProcess, KNullDesC));
sl@0
  1303
sl@0
  1304
	// Kick off the process and wait for it to complete
sl@0
  1305
	TRequestStatus status3 = KRequestPending;
sl@0
  1306
	process3.Logon(status3);
sl@0
  1307
	process3.SetParameter(EMultiProcessSecondSlot, ECloseSurface);
sl@0
  1308
	process3.Resume();
sl@0
  1309
	
sl@0
  1310
	// Let the second process continue its work - calling MapSurface
sl@0
  1311
	sem2.Signal();
sl@0
  1312
	
sl@0
  1313
	// Call Surface Info on the surface in this process
sl@0
  1314
	RSurfaceManager::TInfoBuf infoBuf;
sl@0
  1315
	TEST(KErrNone == surfaceManager.SurfaceInfo(surfaceId, infoBuf));
sl@0
  1316
	
sl@0
  1317
	// Wait for the second process to terminate
sl@0
  1318
	User::WaitForRequest(status2);
sl@0
  1319
	
sl@0
  1320
	// Check that the tests in the second process have passed
sl@0
  1321
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  1322
	TEST(result & EFirstTestPassed);
sl@0
  1323
	TEST(result & ESecondTestPassed);
sl@0
  1324
	TEST(result & EThirdTestPassed);
sl@0
  1325
	TEST(result & EFourthTestPassed);
sl@0
  1326
	
sl@0
  1327
	// Wait for the third process to terminate and chaeck the results
sl@0
  1328
	User::WaitForRequest(status3);
sl@0
  1329
	result = chunkWrapper->GetThirdProcessResults();
sl@0
  1330
	TEST(result & EFirstTestPassed);
sl@0
  1331
	
sl@0
  1332
	// Delete the chunkWrapper and the semaphore
sl@0
  1333
	delete chunkWrapper;
sl@0
  1334
	process2.Close();
sl@0
  1335
	process3.Close();
sl@0
  1336
sl@0
  1337
	CleanupStack::PopAndDestroy(3, &surfaceManager);
sl@0
  1338
	}
sl@0
  1339
sl@0
  1340
void CTSurfaceManagerMultiProcess::TestSurfaceAccessWhenCreatingProcessDiesL()
sl@0
  1341
	{
sl@0
  1342
	INFO_PRINTF1(_L("Test surface can be accessed when creating process dies\r\n"));
sl@0
  1343
	// Create two semaphores
sl@0
  1344
	const TInt initCount = 0;
sl@0
  1345
	RSemaphore sem;
sl@0
  1346
	TEST(KErrNone == sem.CreateGlobal(KMultiProcessSemaphore, initCount));
sl@0
  1347
	CleanupClosePushL(sem);
sl@0
  1348
	RSemaphore sem2;
sl@0
  1349
	TEST(KErrNone == sem2.CreateGlobal(KMultiProcessSemaphore2, initCount));
sl@0
  1350
	CleanupClosePushL(sem2);
sl@0
  1351
	
sl@0
  1352
	// Create a second process
sl@0
  1353
	RProcess process;
sl@0
  1354
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  1355
sl@0
  1356
	// Kick off the process and wait for it to complete
sl@0
  1357
	TRequestStatus status = KRequestPending;
sl@0
  1358
	process.Logon(status);
sl@0
  1359
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ECreateWaitKill));
sl@0
  1360
	process.Resume();
sl@0
  1361
	CleanupClosePushL(process);
sl@0
  1362
	
sl@0
  1363
	// Passes control to the second process
sl@0
  1364
	sem.Wait();
sl@0
  1365
		
sl@0
  1366
	// Copme back from the second process - find the surfaceId
sl@0
  1367
	CChunkWrapper* chunkWrapper = CChunkWrapper::OpenL(KSharedChunkName, ETrue);
sl@0
  1368
	TSurfaceId surfaceId = chunkWrapper->GetId();
sl@0
  1369
	
sl@0
  1370
	// Open the surface manager
sl@0
  1371
	RSurfaceManager surfaceManager;
sl@0
  1372
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1373
	CleanupClosePushL(surfaceManager);
sl@0
  1374
sl@0
  1375
	// Open the surface
sl@0
  1376
	TEST(KErrNone == surfaceManager.OpenSurface(surfaceId));
sl@0
  1377
	
sl@0
  1378
	// Pass control off to the second process again
sl@0
  1379
	sem2.Signal();
sl@0
  1380
	
sl@0
  1381
	// Wait for the second process to terminate
sl@0
  1382
	User::WaitForRequest(status);
sl@0
  1383
	
sl@0
  1384
	// Check that the tests in the second process have passed 
sl@0
  1385
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  1386
	TEST(result & EFirstTestPassed);
sl@0
  1387
	TEST(result & ESecondTestPassed);
sl@0
  1388
	TEST(result & EThirdTestPassed);
sl@0
  1389
	
sl@0
  1390
	// Map Surface
sl@0
  1391
	RChunk handle;
sl@0
  1392
	TEST(KErrNone == surfaceManager.MapSurface(surfaceId, handle));
sl@0
  1393
	handle.Close();
sl@0
  1394
	// Surface Info
sl@0
  1395
	RSurfaceManager::TInfoBuf infoBuf;
sl@0
  1396
	TEST(KErrNone == surfaceManager.SurfaceInfo(surfaceId, infoBuf));
sl@0
  1397
	
sl@0
  1398
	TEST(KErrNone == surfaceManager.CloseSurface(surfaceId));
sl@0
  1399
sl@0
  1400
	// Delete the chunkWrapper and the semaphore
sl@0
  1401
	delete chunkWrapper;
sl@0
  1402
	CleanupStack::PopAndDestroy(4, &sem);
sl@0
  1403
	}
sl@0
  1404
sl@0
  1405
void CTSurfaceManagerMultiProcess::TestClosingSurfaceWhenCreatingProcessDiesL()
sl@0
  1406
	{
sl@0
  1407
	INFO_PRINTF1(_L("Test surface can be closed when creating process dies\r\n"));
sl@0
  1408
	// Create a semaphore
sl@0
  1409
	const TInt initCount = 0;
sl@0
  1410
	RSemaphore sem;
sl@0
  1411
	TEST(KErrNone == sem.CreateGlobal(KMultiProcessSemaphore, initCount));
sl@0
  1412
	CleanupClosePushL(sem);
sl@0
  1413
	RSemaphore sem2;
sl@0
  1414
	TEST(KErrNone == sem2.CreateGlobal(KMultiProcessSemaphore2, initCount));
sl@0
  1415
	CleanupClosePushL(sem2);
sl@0
  1416
	
sl@0
  1417
	// Create a second process
sl@0
  1418
	RProcess process;
sl@0
  1419
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  1420
	
sl@0
  1421
	// Kick off the process and wait for it to complete
sl@0
  1422
	TRequestStatus status = KRequestPending;
sl@0
  1423
	process.Logon(status);
sl@0
  1424
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ECreateWaitKill));
sl@0
  1425
	process.Resume();
sl@0
  1426
	CleanupClosePushL(process);
sl@0
  1427
	
sl@0
  1428
	// Passes control to the second process
sl@0
  1429
	sem.Wait();
sl@0
  1430
		
sl@0
  1431
	// Copme back from the second process - find the surfaceId
sl@0
  1432
	CChunkWrapper* chunkWrapper = CChunkWrapper::OpenL(KSharedChunkName, ETrue);
sl@0
  1433
	TSurfaceId surfaceId = chunkWrapper->GetId();
sl@0
  1434
	
sl@0
  1435
	// Open the surface manager
sl@0
  1436
	RSurfaceManager surfaceManager;
sl@0
  1437
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1438
	CleanupClosePushL(surfaceManager);
sl@0
  1439
	
sl@0
  1440
	// Open the surface
sl@0
  1441
	TEST(KErrNone == surfaceManager.OpenSurface(surfaceId));
sl@0
  1442
	
sl@0
  1443
	// Pass control off to the second process again
sl@0
  1444
	sem2.Signal();
sl@0
  1445
sl@0
  1446
	// Wait for the second process to terminate
sl@0
  1447
	User::WaitForRequest(status);
sl@0
  1448
sl@0
  1449
	
sl@0
  1450
	// Check that the tests in the second process have passed 
sl@0
  1451
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  1452
	TEST(result & EFirstTestPassed);
sl@0
  1453
	TEST(result & ESecondTestPassed);
sl@0
  1454
	TEST(result & EThirdTestPassed);
sl@0
  1455
	
sl@0
  1456
	TEST(KErrNone == surfaceManager.CloseSurface(surfaceId));
sl@0
  1457
	
sl@0
  1458
	// Delete the chunkWrapper and the semaphore
sl@0
  1459
	delete chunkWrapper;
sl@0
  1460
	CleanupStack::PopAndDestroy(4, &sem);
sl@0
  1461
	}
sl@0
  1462
	
sl@0
  1463
void CTSurfaceManagerMultiProcess::TestCloseSurfaceInThirdProcessL()
sl@0
  1464
	{
sl@0
  1465
	INFO_PRINTF1(_L("Test surface access in a third process\r\n"));
sl@0
  1466
	// Create 2 semaphores for signalling between process 1 and process 2
sl@0
  1467
	const TInt initCount = 0;
sl@0
  1468
	RSemaphore sem;
sl@0
  1469
	TEST(KErrNone == sem.CreateGlobal(KMultiProcessSemaphore, initCount));
sl@0
  1470
	CleanupClosePushL(sem);
sl@0
  1471
	RSemaphore sem2;
sl@0
  1472
	TEST(KErrNone == sem2.CreateGlobal(KMultiProcessSemaphore2, initCount));
sl@0
  1473
	CleanupClosePushL(sem2);
sl@0
  1474
	
sl@0
  1475
	// Create a second process
sl@0
  1476
	RProcess process2;
sl@0
  1477
	TEST(KErrNone == process2.Create(KSecondProcess, KNullDesC));
sl@0
  1478
	
sl@0
  1479
	// Kick off the process and wait for it to complete
sl@0
  1480
	TRequestStatus status2 = KRequestPending;
sl@0
  1481
	process2.Logon(status2);
sl@0
  1482
	process2.SetParameter(EMultiProcessSecondSlot, ECreateWaitKill);
sl@0
  1483
	process2.Resume();
sl@0
  1484
	CleanupClosePushL(process2);
sl@0
  1485
	
sl@0
  1486
	// Passes control to the second process
sl@0
  1487
	sem.Wait();
sl@0
  1488
		
sl@0
  1489
	// Come back from the second process - find the surfaceId
sl@0
  1490
	CChunkWrapper* chunkWrapper = CChunkWrapper::OpenL(KSharedChunkName, ETrue);
sl@0
  1491
	TSurfaceId surfaceId = chunkWrapper->GetId();
sl@0
  1492
	
sl@0
  1493
	// Open the surface manager
sl@0
  1494
	RSurfaceManager surfaceManager;
sl@0
  1495
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1496
	CleanupClosePushL(surfaceManager);
sl@0
  1497
	
sl@0
  1498
	// Open the surface
sl@0
  1499
	TEST(KErrNone == surfaceManager.OpenSurface(surfaceId));
sl@0
  1500
	
sl@0
  1501
	// Create another two semaphores for signalling between process 1 and process 3
sl@0
  1502
	RSemaphore sem3;
sl@0
  1503
	TEST(KErrNone == sem3.CreateGlobal(KMultiProcessSemaphore3, initCount));
sl@0
  1504
sl@0
  1505
	RSemaphore sem4;
sl@0
  1506
	TEST(KErrNone == sem4.CreateGlobal(KMultiProcessSemaphore4, initCount));
sl@0
  1507
sl@0
  1508
	// Create a third process
sl@0
  1509
	RProcess process3;
sl@0
  1510
	TEST(KErrNone == process3.Create(KThirdProcess, KNullDesC));
sl@0
  1511
	
sl@0
  1512
	// Kick off the process and wait for it to complete
sl@0
  1513
	TRequestStatus status3 = KRequestPending;
sl@0
  1514
	process3.Logon(status3);
sl@0
  1515
	process3.SetParameter(EMultiProcessSecondSlot, EOpenWaitCloseOpen);
sl@0
  1516
	process3.Resume();
sl@0
  1517
sl@0
  1518
	// Passes control to the third process - opens the surface
sl@0
  1519
	sem3.Wait();
sl@0
  1520
	
sl@0
  1521
	// Pass control to the second process again - kill the process
sl@0
  1522
	sem2.Signal();
sl@0
  1523
	
sl@0
  1524
	// Wait for the third process to terminate
sl@0
  1525
	User::WaitForRequest(status2);
sl@0
  1526
	
sl@0
  1527
	// Check that the tests in the second process have passed 
sl@0
  1528
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  1529
	TEST(result & EFirstTestPassed);
sl@0
  1530
	TEST(result & ESecondTestPassed);
sl@0
  1531
	TEST(result & EThirdTestPassed);
sl@0
  1532
	
sl@0
  1533
	// Close the surface
sl@0
  1534
	TEST(KErrNone == surfaceManager.CloseSurface(surfaceId));
sl@0
  1535
	
sl@0
  1536
	// Pass control to the third process - close the surface
sl@0
  1537
	sem4.Signal();	
sl@0
  1538
	
sl@0
  1539
	// Wait for the third process to terminate
sl@0
  1540
	User::WaitForRequest(status3);
sl@0
  1541
	
sl@0
  1542
	// Check that the tests in the third process have passed 
sl@0
  1543
	result = chunkWrapper->GetThirdProcessResults();
sl@0
  1544
	TEST(result & EFirstTestPassed);
sl@0
  1545
	TEST(result & ESecondTestPassed);
sl@0
  1546
	TEST(result & EThirdTestPassed);
sl@0
  1547
	TEST(result & EFourthTestPassed);
sl@0
  1548
	TEST(result & EFifthTestPassed);
sl@0
  1549
//	TEST(result & ESixthTestPassed);
sl@0
  1550
	
sl@0
  1551
	// Cleanup
sl@0
  1552
	delete chunkWrapper;
sl@0
  1553
	sem3.Close();
sl@0
  1554
	sem4.Close();
sl@0
  1555
	process3.Close();
sl@0
  1556
sl@0
  1557
	CleanupStack::PopAndDestroy(4, &sem);
sl@0
  1558
	}
sl@0
  1559
sl@0
  1560
void CTSurfaceManagerMultiProcess::TestNoAccessWhenSurfaceClosedTwoProcessL()
sl@0
  1561
	{
sl@0
  1562
	INFO_PRINTF1(_L("Test surface can't be accessed when closed (2process)\r\n"));
sl@0
  1563
	// Create a semaphore
sl@0
  1564
	const TInt initCount = 0;
sl@0
  1565
	RSemaphore sem;
sl@0
  1566
	TEST(KErrNone == sem.CreateGlobal(KMultiProcessSemaphore, initCount));
sl@0
  1567
	CleanupClosePushL(sem);
sl@0
  1568
	RSemaphore sem2;
sl@0
  1569
	TEST(KErrNone == sem2.CreateGlobal(KMultiProcessSemaphore2, initCount));
sl@0
  1570
	CleanupClosePushL(sem2);
sl@0
  1571
	
sl@0
  1572
	// Create a second process
sl@0
  1573
	RProcess process;
sl@0
  1574
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  1575
	
sl@0
  1576
	// Kick off the process and wait for it to complete
sl@0
  1577
	TRequestStatus status = KRequestPending;
sl@0
  1578
	process.Logon(status);
sl@0
  1579
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ECreateWaitKill));
sl@0
  1580
	process.Resume();
sl@0
  1581
	CleanupClosePushL(process);
sl@0
  1582
	
sl@0
  1583
	// Passes control to the second process
sl@0
  1584
	sem.Wait();
sl@0
  1585
		
sl@0
  1586
	// Come back from the second process - find the surfaceId
sl@0
  1587
	CChunkWrapper* chunkWrapper = CChunkWrapper::OpenL(KSharedChunkName, ETrue);
sl@0
  1588
	TSurfaceId surfaceId = chunkWrapper->GetId();
sl@0
  1589
	
sl@0
  1590
	// Open the surface manager
sl@0
  1591
	RSurfaceManager surfaceManager;
sl@0
  1592
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1593
	CleanupClosePushL(surfaceManager);   
sl@0
  1594
	// Open the surface
sl@0
  1595
	TEST(KErrNone == surfaceManager.OpenSurface(surfaceId));
sl@0
  1596
	
sl@0
  1597
	// Close the surface
sl@0
  1598
	TEST(KErrNone == surfaceManager.CloseSurface(surfaceId));
sl@0
  1599
	
sl@0
  1600
	// Pass control off to the second process again
sl@0
  1601
	sem2.Signal();
sl@0
  1602
	
sl@0
  1603
	// Wait for the third process to terminate
sl@0
  1604
	User::WaitForRequest(status);
sl@0
  1605
	
sl@0
  1606
	// Check that the tests in the second process have passed 
sl@0
  1607
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  1608
	TEST(result & EFirstTestPassed);
sl@0
  1609
	TEST(result & ESecondTestPassed);
sl@0
  1610
	TEST(result & EThirdTestPassed);
sl@0
  1611
	
sl@0
  1612
	TEST(KErrArgument == surfaceManager.OpenSurface(surfaceId));
sl@0
  1613
	
sl@0
  1614
	// Delete the chunkWrapper and the semaphore
sl@0
  1615
	delete chunkWrapper;
sl@0
  1616
	CleanupStack::PopAndDestroy(4, &sem);
sl@0
  1617
	}
sl@0
  1618
void CTSurfaceManagerMultiProcess::TestOpeningOnProcessAfterClosingOnOtherL()
sl@0
  1619
	{
sl@0
  1620
	INFO_PRINTF1(_L("Test closing on one process doesn't prevent opening on another\r\n"));
sl@0
  1621
	// Open the surface manager
sl@0
  1622
	RSurfaceManager surfaceManager;
sl@0
  1623
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1624
	CleanupClosePushL(surfaceManager);   
sl@0
  1625
sl@0
  1626
	// Store the attributes used to create the Surface
sl@0
  1627
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1628
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1629
	
sl@0
  1630
	attributes.iSize = TSize(280,15);
sl@0
  1631
	attributes.iBuffers = 3;
sl@0
  1632
	attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
sl@0
  1633
	attributes.iStride = 901;
sl@0
  1634
	attributes.iOffsetToFirstBuffer = 4;
sl@0
  1635
	attributes.iAlignment = 4;
sl@0
  1636
	attributes.iContiguous=EFalse;
sl@0
  1637
	
sl@0
  1638
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1639
	attributes.iHintCount = 2;
sl@0
  1640
	attributes.iSurfaceHints = hints;
sl@0
  1641
	hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
sl@0
  1642
	hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
sl@0
  1643
sl@0
  1644
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1645
	attributes.iMappable = ETrue;
sl@0
  1646
sl@0
  1647
	// Create the surface
sl@0
  1648
	TSurfaceId surfaceId;
sl@0
  1649
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  1650
	
sl@0
  1651
	// Create a semaphore
sl@0
  1652
	const TInt initCount = 0;
sl@0
  1653
	RSemaphore sem;
sl@0
  1654
	TEST(KErrNone == sem.CreateGlobal(KMultiProcessSemaphore, initCount));
sl@0
  1655
	CleanupClosePushL(sem);
sl@0
  1656
	RSemaphore sem2;
sl@0
  1657
	TEST(KErrNone == sem2.CreateGlobal(KMultiProcessSemaphore2, initCount));
sl@0
  1658
	CleanupClosePushL(sem2);
sl@0
  1659
	
sl@0
  1660
	iInfo2.iSurfaceId = surfaceId;
sl@0
  1661
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  1662
	// Create a TCleanupItem object
sl@0
  1663
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  1664
sl@0
  1665
	// Save the surfaceId to the shared chunk
sl@0
  1666
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  1667
    chunkWrapper->SetId(surfaceId);
sl@0
  1668
   	CleanupStack::Pop();
sl@0
  1669
	
sl@0
  1670
	// Create a second process
sl@0
  1671
	RProcess process2;
sl@0
  1672
	TEST(KErrNone == process2.Create(KSecondProcess, KNullDesC));
sl@0
  1673
sl@0
  1674
	// Kick off the process and wait for it to complete
sl@0
  1675
	TRequestStatus status2 = KRequestPending;
sl@0
  1676
	process2.Logon(status2);
sl@0
  1677
	process2.SetParameter(EMultiProcessSecondSlot, EOpenClose);
sl@0
  1678
	process2.Resume();
sl@0
  1679
	
sl@0
  1680
	// Passes control to the second process
sl@0
  1681
	sem.Wait();
sl@0
  1682
	
sl@0
  1683
	// Create a third process
sl@0
  1684
	RProcess process3;
sl@0
  1685
	TEST(KErrNone == process3.Create(KThirdProcess, KNullDesC));
sl@0
  1686
	
sl@0
  1687
	// Kick off the process and wait for it to complete
sl@0
  1688
	TRequestStatus status3 = KRequestPending;
sl@0
  1689
	process3.Logon(status3);
sl@0
  1690
	process3.SetParameter(EMultiProcessSecondSlot, EOpenSurface);
sl@0
  1691
	process3.Resume();
sl@0
  1692
	
sl@0
  1693
	// Pass control off to the second process again
sl@0
  1694
	sem2.Signal();
sl@0
  1695
	
sl@0
  1696
	// Wait for the second process to terminate
sl@0
  1697
	User::WaitForRequest(status2);
sl@0
  1698
	
sl@0
  1699
	// Check that the tests in the second process have passed 
sl@0
  1700
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  1701
	TEST(result & EFirstTestPassed);
sl@0
  1702
	TEST(result & ESecondTestPassed);
sl@0
  1703
	TEST(result & EThirdTestPassed);
sl@0
  1704
	TEST(result & EFourthTestPassed);
sl@0
  1705
	
sl@0
  1706
	// Wait for the third process to terminate
sl@0
  1707
	User::WaitForRequest(status3);
sl@0
  1708
	
sl@0
  1709
	// Test results
sl@0
  1710
	result = chunkWrapper->GetThirdProcessResults();
sl@0
  1711
	TEST(result & EFirstTestPassed);
sl@0
  1712
sl@0
  1713
	// Delete the chunkWrapper and the semaphore
sl@0
  1714
	delete chunkWrapper;
sl@0
  1715
	process2.Close();
sl@0
  1716
	process3.Close();
sl@0
  1717
	CleanupStack::PopAndDestroy(3, &surfaceManager);
sl@0
  1718
	}
sl@0
  1719
sl@0
  1720
void CTSurfaceManagerMultiProcess::TestAccessAfterClosingL()
sl@0
  1721
	{
sl@0
  1722
	INFO_PRINTF1(_L("Test closing doesn't prevent access\r\n"));
sl@0
  1723
	// Open the surface manager
sl@0
  1724
	RSurfaceManager surfaceManager;
sl@0
  1725
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1726
	CleanupClosePushL(surfaceManager);   
sl@0
  1727
sl@0
  1728
	// Store the attributes used to create the Surface
sl@0
  1729
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1730
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1731
	
sl@0
  1732
	attributes.iSize = TSize(280,199);
sl@0
  1733
	attributes.iBuffers = 3;
sl@0
  1734
	attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
sl@0
  1735
	attributes.iStride = 711;
sl@0
  1736
	attributes.iOffsetToFirstBuffer = 4;
sl@0
  1737
	attributes.iAlignment = 4;
sl@0
  1738
	attributes.iContiguous=EFalse;
sl@0
  1739
	
sl@0
  1740
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1741
	attributes.iHintCount = 2;
sl@0
  1742
	attributes.iSurfaceHints = hints;
sl@0
  1743
	hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
sl@0
  1744
	hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
sl@0
  1745
	
sl@0
  1746
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1747
	attributes.iCacheAttrib = RSurfaceManager::ENotCached;
sl@0
  1748
	attributes.iMappable = ETrue;
sl@0
  1749
sl@0
  1750
	// Create the surface
sl@0
  1751
	TSurfaceId surfaceId;
sl@0
  1752
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  1753
	
sl@0
  1754
	// Create a semaphore
sl@0
  1755
	const TInt initCount = 0;
sl@0
  1756
	RSemaphore sem;
sl@0
  1757
	TEST(KErrNone == sem.CreateGlobal(KMultiProcessSemaphore, initCount));
sl@0
  1758
	CleanupClosePushL(sem);
sl@0
  1759
	RSemaphore sem2;
sl@0
  1760
	TEST(KErrNone == sem2.CreateGlobal(KMultiProcessSemaphore2, initCount));
sl@0
  1761
	CleanupClosePushL(sem2);
sl@0
  1762
sl@0
  1763
	iInfo2.iSurfaceId = surfaceId;
sl@0
  1764
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  1765
	// Create a TCleanupItem object
sl@0
  1766
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  1767
	
sl@0
  1768
	// Save the surfaceId to the shared chunk
sl@0
  1769
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  1770
    chunkWrapper->SetId(surfaceId);
sl@0
  1771
   	CleanupStack::Pop();
sl@0
  1772
sl@0
  1773
	// Create a second process
sl@0
  1774
	RProcess process;
sl@0
  1775
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  1776
sl@0
  1777
	// Kick off the process and wait for it to complete
sl@0
  1778
	TRequestStatus status = KRequestPending;
sl@0
  1779
	process.Logon(status);
sl@0
  1780
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, EOpenClose));
sl@0
  1781
	process.Resume();
sl@0
  1782
	
sl@0
  1783
	// Passes control to the second process
sl@0
  1784
	sem.Wait();
sl@0
  1785
	
sl@0
  1786
	// Map Surface
sl@0
  1787
	RChunk handle;
sl@0
  1788
	TEST(KErrNone == surfaceManager.MapSurface(surfaceId, handle));
sl@0
  1789
	handle.Close();
sl@0
  1790
	// Surface Info
sl@0
  1791
	RSurfaceManager::TInfoBuf infoBuf;
sl@0
  1792
	TEST(KErrNone == surfaceManager.SurfaceInfo(surfaceId, infoBuf));
sl@0
  1793
	
sl@0
  1794
	// Pass control off to the second process again
sl@0
  1795
	sem2.Signal();
sl@0
  1796
	
sl@0
  1797
	// Wait for the second process to terminate
sl@0
  1798
	User::WaitForRequest(status);
sl@0
  1799
	
sl@0
  1800
	// Check that the tests in the second process have passed 
sl@0
  1801
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  1802
	TEST(result & EFirstTestPassed);
sl@0
  1803
	TEST(result & ESecondTestPassed);
sl@0
  1804
	TEST(result & EThirdTestPassed);
sl@0
  1805
	TEST(result & EFourthTestPassed);
sl@0
  1806
	
sl@0
  1807
	// Delete the chunkWrapper and the semaphore
sl@0
  1808
	delete chunkWrapper;
sl@0
  1809
	process.Close();
sl@0
  1810
	CleanupStack::PopAndDestroy(3, &surfaceManager);
sl@0
  1811
	}
sl@0
  1812
	
sl@0
  1813
void CTSurfaceManagerMultiProcess::TestClosingAfterClosingOnOtherProcessL()
sl@0
  1814
	{
sl@0
  1815
	INFO_PRINTF1(_L("Test can close in two processes\r\n"));
sl@0
  1816
	// Open the surface manager
sl@0
  1817
	RSurfaceManager surfaceManager;
sl@0
  1818
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1819
	CleanupClosePushL(surfaceManager);   
sl@0
  1820
	
sl@0
  1821
	// Store the attributes used to create the Surface
sl@0
  1822
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1823
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1824
	
sl@0
  1825
	attributes.iSize = TSize(280,301);
sl@0
  1826
	attributes.iBuffers = 3;
sl@0
  1827
	attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
sl@0
  1828
	attributes.iStride = 768;
sl@0
  1829
	attributes.iOffsetToFirstBuffer = 4;
sl@0
  1830
	attributes.iAlignment = 4;
sl@0
  1831
	attributes.iContiguous=EFalse;
sl@0
  1832
	
sl@0
  1833
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1834
	attributes.iHintCount = 2;
sl@0
  1835
	attributes.iSurfaceHints = hints;
sl@0
  1836
	hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
sl@0
  1837
	hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
sl@0
  1838
sl@0
  1839
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1840
	attributes.iCacheAttrib = RSurfaceManager::ENotCached;
sl@0
  1841
	attributes.iMappable = ETrue;
sl@0
  1842
sl@0
  1843
	// Create the surface
sl@0
  1844
	TSurfaceId surfaceId;
sl@0
  1845
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  1846
	
sl@0
  1847
	// Create a semaphore
sl@0
  1848
	const TInt initCount = 0;
sl@0
  1849
	RSemaphore sem;
sl@0
  1850
	TEST(KErrNone == sem.CreateGlobal(KMultiProcessSemaphore, initCount));
sl@0
  1851
	CleanupClosePushL(sem);
sl@0
  1852
	RSemaphore sem2;
sl@0
  1853
	TEST(KErrNone == sem2.CreateGlobal(KMultiProcessSemaphore2, initCount));
sl@0
  1854
	CleanupClosePushL(sem2);
sl@0
  1855
	
sl@0
  1856
	iInfo2.iSurfaceId = surfaceId;
sl@0
  1857
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  1858
	// Create a TCleanupItem object
sl@0
  1859
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  1860
sl@0
  1861
	
sl@0
  1862
	// Save the surfaceId to the shared chunk
sl@0
  1863
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  1864
    chunkWrapper->SetId(surfaceId);
sl@0
  1865
   	CleanupStack::Pop();
sl@0
  1866
	
sl@0
  1867
	// Create a second process
sl@0
  1868
	RProcess process;
sl@0
  1869
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  1870
sl@0
  1871
	// Kick off the process and wait for it to complete
sl@0
  1872
	TRequestStatus status = KRequestPending;
sl@0
  1873
	process.Logon(status);
sl@0
  1874
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, EOpenClose));
sl@0
  1875
	process.Resume();
sl@0
  1876
	
sl@0
  1877
	// Passes control to the second process
sl@0
  1878
	sem.Wait();
sl@0
  1879
	
sl@0
  1880
	// Test closing the surface manager
sl@0
  1881
	TEST(KErrNone == surfaceManager.CloseSurface(surfaceId));
sl@0
  1882
	
sl@0
  1883
	// Pass control off to the second process again
sl@0
  1884
	sem2.Signal();
sl@0
  1885
	
sl@0
  1886
	// Wait for the second process to terminate
sl@0
  1887
	User::WaitForRequest(status);
sl@0
  1888
	
sl@0
  1889
	// Check that the tests in the second process have passed 
sl@0
  1890
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  1891
	TEST(result & EFirstTestPassed);
sl@0
  1892
	TEST(result & ESecondTestPassed);
sl@0
  1893
	TEST(result & EThirdTestPassed);
sl@0
  1894
	TEST(result & EFourthTestPassed);
sl@0
  1895
	
sl@0
  1896
	// Delete the chunkWrapper and the semaphore
sl@0
  1897
	delete chunkWrapper;
sl@0
  1898
	process.Close();
sl@0
  1899
	CleanupStack::PopAndDestroy(3, &surfaceManager);
sl@0
  1900
	}
sl@0
  1901
	
sl@0
  1902
void CTSurfaceManagerMultiProcess::TestErrSufaceAccessNotOpenL()
sl@0
  1903
	{
sl@0
  1904
	INFO_PRINTF1(_L("Test a surface cannot be accessed in a second process if not opened\r\n"));
sl@0
  1905
	// Open the surface manager
sl@0
  1906
	RSurfaceManager surfaceManager;
sl@0
  1907
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1908
	CleanupClosePushL(surfaceManager);
sl@0
  1909
	// Store the attributes used to create the Surface
sl@0
  1910
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1911
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1912
	
sl@0
  1913
	attributes.iSize = TSize(280,301);
sl@0
  1914
	attributes.iBuffers = 3;
sl@0
  1915
	attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
sl@0
  1916
	attributes.iStride = 1400;
sl@0
  1917
	attributes.iOffsetToFirstBuffer = 4;
sl@0
  1918
	attributes.iAlignment = 4;
sl@0
  1919
	attributes.iContiguous=EFalse;
sl@0
  1920
	
sl@0
  1921
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  1922
	attributes.iHintCount = 2;
sl@0
  1923
	attributes.iSurfaceHints = hints;
sl@0
  1924
	hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
sl@0
  1925
	hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
sl@0
  1926
	
sl@0
  1927
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  1928
	attributes.iMappable = ETrue;
sl@0
  1929
sl@0
  1930
	// Create the surface
sl@0
  1931
	TSurfaceId surfaceId;
sl@0
  1932
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  1933
	
sl@0
  1934
	// Create a semaphore
sl@0
  1935
	const TInt initCount = 0;
sl@0
  1936
	RSemaphore sem;
sl@0
  1937
	TEST(KErrNone == sem.CreateGlobal(KMultiProcessSemaphore, initCount));
sl@0
  1938
	CleanupClosePushL(sem);
sl@0
  1939
	RSemaphore sem2;
sl@0
  1940
	TEST(KErrNone == sem2.CreateGlobal(KMultiProcessSemaphore2, initCount));
sl@0
  1941
	CleanupClosePushL(sem2);
sl@0
  1942
sl@0
  1943
	iInfo2.iSurfaceId = surfaceId;
sl@0
  1944
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  1945
	// Create a TCleanupItem object
sl@0
  1946
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  1947
sl@0
  1948
sl@0
  1949
	// Save the surfaceId to the shared chunk
sl@0
  1950
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  1951
    chunkWrapper->SetId(surfaceId);
sl@0
  1952
   	CleanupStack::Pop();
sl@0
  1953
sl@0
  1954
	// Create a second process
sl@0
  1955
	RProcess process;
sl@0
  1956
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  1957
	// Kick off the process and wait for it to complete
sl@0
  1958
	TRequestStatus status = KRequestPending;
sl@0
  1959
	process.Logon(status);
sl@0
  1960
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, EMapSurfaceInfoCantAccess));
sl@0
  1961
	process.Resume();
sl@0
  1962
	
sl@0
  1963
	// Passes control to the second process - to test MapSurface and SurfaceInfo
sl@0
  1964
	sem.Wait();
sl@0
  1965
	
sl@0
  1966
	// Pass control off to the second process again - to allow it to terminate
sl@0
  1967
	sem2.Signal();
sl@0
  1968
	
sl@0
  1969
	// Wait for the second process to terminate
sl@0
  1970
	User::WaitForRequest(status);
sl@0
  1971
	
sl@0
  1972
	// Check that the tests in the second process have passed 
sl@0
  1973
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  1974
	TEST(result & EFirstTestPassed);
sl@0
  1975
	TEST(result & ESecondTestPassed);
sl@0
  1976
	TEST(result & EThirdTestPassed);
sl@0
  1977
	TEST(result & EFourthTestPassed);
sl@0
  1978
	
sl@0
  1979
	// Delete the chunkWrapper and the semaphore
sl@0
  1980
	delete chunkWrapper;
sl@0
  1981
	process.Close();
sl@0
  1982
	CleanupStack::PopAndDestroy(3, &surfaceManager);
sl@0
  1983
	}
sl@0
  1984
	
sl@0
  1985
void CTSurfaceManagerMultiProcess::TestReadFromBufferInSecondProcessL()
sl@0
  1986
	{
sl@0
  1987
	INFO_PRINTF1(_L("Writing to a buffer and reading from another process\r\n"));
sl@0
  1988
	// Open the surface manager
sl@0
  1989
	RSurfaceManager surfaceManager;
sl@0
  1990
	User::LeaveIfError(surfaceManager.Open());
sl@0
  1991
	CleanupClosePushL(surfaceManager);
sl@0
  1992
	
sl@0
  1993
	// Setup attributes, setting iBuffers to 2
sl@0
  1994
    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  1995
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  1996
	
sl@0
  1997
	attributes.iSize = TSize(12,80);    	// w > 0, h > 0
sl@0
  1998
	attributes.iBuffers = 2; 				// > 0, <= 4
sl@0
  1999
	attributes.iPixelFormat = EUidPixelFormatARGB_1555;	// 2bpp
sl@0
  2000
	attributes.iStride = 25;				// > 0, > width * bpp
sl@0
  2001
	attributes.iOffsetToFirstBuffer = 20;	// > 0, divisible by alignment
sl@0
  2002
	attributes.iAlignment = 4;				// 1 || 2 || 4 || 8
sl@0
  2003
	attributes.iContiguous = ETrue;
sl@0
  2004
	
sl@0
  2005
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  2006
	attributes.iHintCount = 2;
sl@0
  2007
	attributes.iSurfaceHints = hints;
sl@0
  2008
	hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
sl@0
  2009
	hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
sl@0
  2010
	
sl@0
  2011
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  2012
	attributes.iCacheAttrib = RSurfaceManager::ENotCached;
sl@0
  2013
	attributes.iMappable = ETrue;
sl@0
  2014
	
sl@0
  2015
	// Create the surface
sl@0
  2016
	TSurfaceId surfaceId;
sl@0
  2017
    TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  2018
	
sl@0
  2019
	// Map the surface to a chunk of memory
sl@0
  2020
	RChunk handle;
sl@0
  2021
	TEST(KErrNone == surfaceManager.MapSurface(surfaceId, handle));
sl@0
  2022
	CleanupClosePushL(handle);
sl@0
  2023
	
sl@0
  2024
	// Get the adress of this chunk of memory
sl@0
  2025
	TUint8* surfaceAdd = handle.Base();
sl@0
  2026
	TUint8* bufferAdd = surfaceAdd + attributes.iOffsetToFirstBuffer;
sl@0
  2027
	
sl@0
  2028
	// Write to the buffer
sl@0
  2029
	*bufferAdd = 134;
sl@0
  2030
sl@0
  2031
   	iInfo2.iSurfaceId = surfaceId;
sl@0
  2032
  	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  2033
	// Create a TCleanupItem object
sl@0
  2034
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  2035
sl@0
  2036
	
sl@0
  2037
	// Save the surfaceId to the shared chunk
sl@0
  2038
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  2039
    chunkWrapper->SetId(surfaceId);
sl@0
  2040
   	CleanupStack::Pop();
sl@0
  2041
sl@0
  2042
	// Create a second process
sl@0
  2043
	RProcess process;
sl@0
  2044
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  2045
	// Kick off the process and wait for it to complete
sl@0
  2046
	TRequestStatus status = KRequestPending;
sl@0
  2047
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, EReadFromBuffer));
sl@0
  2048
	process.Logon(status);
sl@0
  2049
	process.Resume();
sl@0
  2050
	
sl@0
  2051
	// Wait for the second process to terminate
sl@0
  2052
	User::WaitForRequest(status);
sl@0
  2053
	
sl@0
  2054
	// Check that the tests in the second process have passed 
sl@0
  2055
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  2056
	TEST(result & EFirstTestPassed);
sl@0
  2057
	TEST(result & ESecondTestPassed);
sl@0
  2058
	TEST(result & EThirdTestPassed);
sl@0
  2059
	TEST(result & EFourthTestPassed);
sl@0
  2060
	
sl@0
  2061
	// Delete the chunkWrapper and the semaphore
sl@0
  2062
	delete chunkWrapper;
sl@0
  2063
	process.Close();
sl@0
  2064
	CleanupStack::PopAndDestroy(2, &surfaceManager);
sl@0
  2065
	}
sl@0
  2066
sl@0
  2067
void CTSurfaceManagerMultiProcess::TestGetSurfaceHintMultiProcessL()
sl@0
  2068
	{
sl@0
  2069
	// Create a surface in a new shared chunk
sl@0
  2070
	INFO_PRINTF1(_L("Test that the GetSurfaceHint() behaves properly in the multiprocesses\r\n"));
sl@0
  2071
	// Open the surface manager
sl@0
  2072
	RSurfaceManager surfaceManager;
sl@0
  2073
 	User::LeaveIfError(surfaceManager.Open());
sl@0
  2074
	CleanupClosePushL(surfaceManager);
sl@0
  2075
sl@0
  2076
	TRequestStatus status;
sl@0
  2077
	// Setup attributes 
sl@0
  2078
	
sl@0
  2079
   	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  2080
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  2081
sl@0
  2082
	attributes.iSize = TSize(480,16);
sl@0
  2083
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
  2084
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
  2085
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
  2086
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
  2087
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
  2088
sl@0
  2089
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  2090
	attributes.iHintCount = 2;
sl@0
  2091
	attributes.iSurfaceHints = hints;
sl@0
  2092
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  2093
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  2094
sl@0
  2095
	attributes.iContiguous = ETrue;
sl@0
  2096
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  2097
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  2098
	attributes.iMappable = ETrue;
sl@0
  2099
sl@0
  2100
	// Test create surface doesn't return an error
sl@0
  2101
	TSurfaceId surfaceId;
sl@0
  2102
	
sl@0
  2103
	// Test create surface doesn't return an error
sl@0
  2104
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  2105
	
sl@0
  2106
	iInfo2.iSurfaceId = surfaceId;
sl@0
  2107
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  2108
	// Create a TCleanupItem object
sl@0
  2109
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  2110
sl@0
  2111
    // Save the surfaceId to the shared chunk
sl@0
  2112
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  2113
    chunkWrapper->SetId(surfaceId);
sl@0
  2114
   	CleanupStack::Pop();
sl@0
  2115
sl@0
  2116
    // Create a second process
sl@0
  2117
    RProcess process;
sl@0
  2118
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  2119
sl@0
  2120
	// Specify the test for the second process
sl@0
  2121
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, EGetSurfaceHint));
sl@0
  2122
	// Kick off the second process and wait for it to complete
sl@0
  2123
	// The actual testing is done in the second process
sl@0
  2124
	process.Logon(status);
sl@0
  2125
	process.Resume();
sl@0
  2126
	User::WaitForRequest(status);
sl@0
  2127
	
sl@0
  2128
	// Check the results of the second process tests
sl@0
  2129
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  2130
	// Only four tests were carried out in the second process
sl@0
  2131
	TEST(result & EFirstTestPassed);
sl@0
  2132
	TEST(result & ESecondTestPassed);
sl@0
  2133
	TEST(result & EThirdTestPassed);
sl@0
  2134
	
sl@0
  2135
	// Delete the chunkWrapper
sl@0
  2136
	delete chunkWrapper;
sl@0
  2137
	process.Close();	
sl@0
  2138
	CleanupStack::PopAndDestroy(1, &surfaceManager);
sl@0
  2139
sl@0
  2140
	}
sl@0
  2141
sl@0
  2142
void CTSurfaceManagerMultiProcess::TestSetSurfaceHintMultiProcessL()
sl@0
  2143
	{
sl@0
  2144
	// Create a surface in a new shared chunk
sl@0
  2145
	INFO_PRINTF1(_L("Test that the SetSurfaceHint() behaves properly in the multiprocesses\r\n"));
sl@0
  2146
	// Open the surface manager
sl@0
  2147
	RSurfaceManager surfaceManager;
sl@0
  2148
 	User::LeaveIfError(surfaceManager.Open());
sl@0
  2149
	CleanupClosePushL(surfaceManager);
sl@0
  2150
sl@0
  2151
	TRequestStatus status;
sl@0
  2152
	// Setup attributes 
sl@0
  2153
	
sl@0
  2154
   	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  2155
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  2156
sl@0
  2157
	attributes.iSize = TSize(480,16);
sl@0
  2158
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
  2159
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
  2160
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
  2161
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
  2162
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
  2163
sl@0
  2164
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  2165
	attributes.iHintCount = 2;
sl@0
  2166
	attributes.iSurfaceHints = hints;
sl@0
  2167
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  2168
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  2169
	
sl@0
  2170
	attributes.iContiguous = ETrue;
sl@0
  2171
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  2172
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  2173
	attributes.iMappable = ETrue;
sl@0
  2174
		
sl@0
  2175
	// Test create surface doesn't return an error
sl@0
  2176
	TSurfaceId surfaceId;
sl@0
  2177
	
sl@0
  2178
	// Test create surface doesn't return an error
sl@0
  2179
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  2180
	
sl@0
  2181
	iInfo2.iSurfaceId = surfaceId;
sl@0
  2182
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  2183
	// Create a TCleanupItem object
sl@0
  2184
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  2185
sl@0
  2186
    // Save the surfaceId to the shared chunk
sl@0
  2187
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  2188
    chunkWrapper->SetId(surfaceId);
sl@0
  2189
   	CleanupStack::Pop();
sl@0
  2190
sl@0
  2191
    // Create a second process
sl@0
  2192
    RProcess process;
sl@0
  2193
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  2194
sl@0
  2195
	// Specify the test for the second process
sl@0
  2196
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ESetSurfaceHint));
sl@0
  2197
	// Kick off the second process and wait for it to complete
sl@0
  2198
	// The actual testing is done in the second process
sl@0
  2199
	process.Logon(status);
sl@0
  2200
	process.Resume();
sl@0
  2201
	User::WaitForRequest(status);
sl@0
  2202
	
sl@0
  2203
	// Check the results of the second process tests
sl@0
  2204
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  2205
	// Only four tests were carried out in the second process
sl@0
  2206
	TEST(result & EFirstTestPassed);
sl@0
  2207
	TEST(result & ESecondTestPassed);
sl@0
  2208
	TEST(result & EThirdTestPassed);
sl@0
  2209
	TEST(result & EFourthTestPassed);
sl@0
  2210
	// Delete the chunkWrapper
sl@0
  2211
	delete chunkWrapper;
sl@0
  2212
	process.Close();	
sl@0
  2213
	CleanupStack::PopAndDestroy(1, &surfaceManager);
sl@0
  2214
sl@0
  2215
	}
sl@0
  2216
	
sl@0
  2217
void CTSurfaceManagerMultiProcess::TestAddSurfaceHintMultiProcessL()
sl@0
  2218
	{
sl@0
  2219
	// Create a surface in a new shared chunk
sl@0
  2220
	INFO_PRINTF1(_L("Test that the AddSurfaceHint() behaves properly in the multiprocesses\r\n"));
sl@0
  2221
	// Open the surface manager
sl@0
  2222
	RSurfaceManager surfaceManager;
sl@0
  2223
 	User::LeaveIfError(surfaceManager.Open());
sl@0
  2224
	CleanupClosePushL(surfaceManager);
sl@0
  2225
sl@0
  2226
	TRequestStatus status;
sl@0
  2227
	// Setup attributes 
sl@0
  2228
	
sl@0
  2229
   	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  2230
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  2231
sl@0
  2232
	attributes.iSize = TSize(480,16);
sl@0
  2233
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
  2234
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
  2235
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
  2236
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
  2237
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
  2238
sl@0
  2239
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  2240
	attributes.iHintCount = 2;
sl@0
  2241
	attributes.iSurfaceHints = hints;
sl@0
  2242
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  2243
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  2244
	
sl@0
  2245
	attributes.iContiguous = ETrue;
sl@0
  2246
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  2247
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  2248
	attributes.iMappable = ETrue;
sl@0
  2249
		
sl@0
  2250
	// Test create surface doesn't return an error
sl@0
  2251
	TSurfaceId surfaceId;
sl@0
  2252
	
sl@0
  2253
	// Test create surface doesn't return an error
sl@0
  2254
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  2255
	
sl@0
  2256
	iInfo2.iSurfaceId = surfaceId;
sl@0
  2257
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  2258
	// Create a TCleanupItem object
sl@0
  2259
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  2260
sl@0
  2261
    // Save the surfaceId to the shared chunk
sl@0
  2262
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  2263
    chunkWrapper->SetId(surfaceId);
sl@0
  2264
   	CleanupStack::Pop();
sl@0
  2265
sl@0
  2266
    // Create a second process
sl@0
  2267
    RProcess process;
sl@0
  2268
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  2269
sl@0
  2270
	// Specify the test for the second process
sl@0
  2271
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, EAddSurfaceHint));
sl@0
  2272
	// Kick off the second process and wait for it to complete
sl@0
  2273
	// The actual testing is done in the second process
sl@0
  2274
	process.Logon(status);
sl@0
  2275
	process.Resume();
sl@0
  2276
	User::WaitForRequest(status);
sl@0
  2277
	
sl@0
  2278
	// Check the results of the second process tests
sl@0
  2279
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  2280
	// Only four tests were carried out in the second process
sl@0
  2281
	TEST(result & EFirstTestPassed);
sl@0
  2282
	TEST(result & ESecondTestPassed);
sl@0
  2283
	TEST(result & EThirdTestPassed);
sl@0
  2284
	TEST(result & EFourthTestPassed);
sl@0
  2285
	// Delete the chunkWrapper
sl@0
  2286
	delete chunkWrapper;
sl@0
  2287
	process.Close();	
sl@0
  2288
	CleanupStack::PopAndDestroy(1, &surfaceManager);
sl@0
  2289
	
sl@0
  2290
	}
sl@0
  2291
sl@0
  2292
void CTSurfaceManagerMultiProcess::TestOutofMemoryCasesL()
sl@0
  2293
	{
sl@0
  2294
	
sl@0
  2295
	RDebug::Printf("test 45 start");
sl@0
  2296
	INFO_PRINTF1(_L("Test OutofMemory conditions in OpenSurface()and AddConnection()\r\n"));
sl@0
  2297
	// Open the surface manager
sl@0
  2298
	RSurfaceManager surfaceManager;
sl@0
  2299
 	User::LeaveIfError(surfaceManager.Open());
sl@0
  2300
	CleanupClosePushL(surfaceManager);
sl@0
  2301
sl@0
  2302
	TRequestStatus status;
sl@0
  2303
	// Setup attributes 
sl@0
  2304
	
sl@0
  2305
   	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
sl@0
  2306
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
sl@0
  2307
sl@0
  2308
	attributes.iSize = TSize(480,16);
sl@0
  2309
	attributes.iBuffers = 2;				// number of buffers in the surface
sl@0
  2310
	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
sl@0
  2311
	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
sl@0
  2312
	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
sl@0
  2313
	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
sl@0
  2314
sl@0
  2315
	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
sl@0
  2316
	attributes.iHintCount = 2;
sl@0
  2317
	attributes.iSurfaceHints = hints;
sl@0
  2318
	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
sl@0
  2319
	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
sl@0
  2320
	
sl@0
  2321
	attributes.iContiguous = ETrue;
sl@0
  2322
	attributes.iCacheAttrib = RSurfaceManager::ECached;
sl@0
  2323
	attributes.iOffsetBetweenBuffers = 0;
sl@0
  2324
	attributes.iMappable = ETrue;
sl@0
  2325
	
sl@0
  2326
	// Test create surface doesn't return an error
sl@0
  2327
	TSurfaceId surfaceId;
sl@0
  2328
	
sl@0
  2329
	// Test create surface doesn't return an error
sl@0
  2330
	TEST(KErrNone == surfaceManager.CreateSurface(buf, surfaceId));
sl@0
  2331
	
sl@0
  2332
	iInfo2.iSurfaceId = surfaceId;
sl@0
  2333
	iInfo2.iSurfaceManager = surfaceManager;
sl@0
  2334
	// Create a TCleanupItem object
sl@0
  2335
    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
sl@0
  2336
sl@0
  2337
    // Save the surfaceId to the shared chunk
sl@0
  2338
	CChunkWrapper* chunkWrapper = CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
sl@0
  2339
    chunkWrapper->SetId(surfaceId);
sl@0
  2340
   	CleanupStack::Pop();
sl@0
  2341
sl@0
  2342
    // Create a second process
sl@0
  2343
    RProcess process;
sl@0
  2344
	TEST(KErrNone == process.Create(KSecondProcess, KNullDesC));
sl@0
  2345
sl@0
  2346
	// Specify the test for the second process
sl@0
  2347
	TEST(KErrNone == process.SetParameter(EMultiProcessSecondSlot, ECheckOutofMemory));
sl@0
  2348
	// Kick off the second process and wait for it to complete
sl@0
  2349
	// The actual testing is done in the second process
sl@0
  2350
	process.Logon(status);
sl@0
  2351
	process.Resume();
sl@0
  2352
	User::WaitForRequest(status);
sl@0
  2353
	
sl@0
  2354
	// Check the results of the second process tests
sl@0
  2355
	TInt result = chunkWrapper->GetSecondProcessResults();
sl@0
  2356
	// Only four tests were carried out in the second process
sl@0
  2357
	TEST(result & EFirstTestPassed);
sl@0
  2358
	TEST(result & ESecondTestPassed);
sl@0
  2359
sl@0
  2360
	// Delete the chunkWrapper
sl@0
  2361
	delete chunkWrapper;
sl@0
  2362
	process.Close();	
sl@0
  2363
	CleanupStack::PopAndDestroy(1, &surfaceManager);
sl@0
  2364
sl@0
  2365
	}
sl@0
  2366
sl@0
  2367
//--------------
sl@0
  2368
__CONSTRUCT_STEP__(SurfaceManagerMultiProcess)
sl@0
  2369
sl@0
  2370
void CTSurfaceManagerMultiProcessStep::TestSetupL()
sl@0
  2371
	{
sl@0
  2372
    }
sl@0
  2373
sl@0
  2374
void CTSurfaceManagerMultiProcessStep::TestClose()
sl@0
  2375
	{
sl@0
  2376
	}
sl@0
  2377