os/graphics/graphicshwdrivers/surfacemgr/test/src/tthirdprocess.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Surface manager multi-processed test code
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @test
    21  @internalComponent - Internal Symbian test code
    22 */
    23 
    24 #include <e32test.h>
    25 #include <e32std.h>
    26 #include <graphics/surface.h>
    27 #include <graphics/surfacemanager.h>
    28 #include "tsmgmultprocessshared.h"
    29 
    30 LOCAL_D RTest test(_L("TThirdProcess"));
    31 
    32 
    33 class CTestDriverThirdProcess : public CTestDriver
    34 {
    35 public:
    36 	CTestDriverThirdProcess();
    37 	static CTestDriverThirdProcess* NewL();
    38 public:
    39 	void CloseSurface();
    40 	void SurfaceInfo();
    41 	void OpenWaitCloseOpen();
    42 	void OpenSurface();
    43 };
    44 
    45 CTestDriverThirdProcess::CTestDriverThirdProcess():CTestDriver()
    46 	{}
    47 
    48 
    49 CTestDriverThirdProcess* CTestDriverThirdProcess::NewL()
    50 	{
    51 	CTestDriverThirdProcess * driver = new (ELeave) CTestDriverThirdProcess();
    52 	CleanupStack::PushL(driver);
    53 	driver->CTestDriver::ConstructL();
    54 	CleanupStack::Pop(driver);
    55 	return driver;
    56 	}
    57 
    58 void CTestDriverThirdProcess::CloseSurface()
    59 	{
    60 	TSurfaceId id = iChunkWrapper->GetId();
    61 	// Close Surface
    62 	if(KErrAccessDenied == iSurfaceManager.CloseSurface(id))
    63 		{
    64 		iTestResult |= EFirstTestPassed;
    65 		}
    66 	
    67 	iChunkWrapper->SetThirdProcessResults(iTestResult);
    68 	}
    69 
    70 void CTestDriverThirdProcess::SurfaceInfo()
    71 	{
    72 	TSurfaceId id = iChunkWrapper->GetId();
    73 	// SurfaceInfo
    74 	// Call Surface Info on the surface in this process
    75 	RSurfaceManager::TInfoBuf infoBuf;
    76 	if(KErrAccessDenied == iSurfaceManager.SurfaceInfo(id,infoBuf))// This is correct?
    77 		{
    78 		iTestResult |= EFirstTestPassed;
    79 		}
    80 	
    81 	iChunkWrapper->SetThirdProcessResults(iTestResult);
    82 	}
    83 
    84 /**
    85 Test 25: Test surface can be accessed from third process when creating 
    86 			process dies and second process closes
    87 
    88 ...			
    89 Process 3: Open Surface
    90 ...
    91 Process 3: Close Surface - KErrNone
    92 Process 3: Open Surface - KErrArgument
    93 */	
    94 void CTestDriverThirdProcess::OpenWaitCloseOpen()
    95 	{
    96 	TSurfaceId id = iChunkWrapper->GetId();
    97 	
    98 	// Open the surface using the surfaceId
    99 	if(KErrNone == iSurfaceManager.OpenSurface(id))
   100 		{
   101 		iTestResult |= EFirstTestPassed;
   102 		}
   103 	
   104 	// Pass control back to the first process
   105     RSemaphore sem3;
   106 	if(KErrNone == sem3.OpenGlobal(KMultiProcessSemaphore3))
   107 		{
   108 		iTestResult |= ESecondTestPassed;
   109 		}
   110 
   111     User::After(100000);
   112     sem3.Signal();
   113     
   114     RSemaphore sem4;
   115 	if(KErrNone == sem4.OpenGlobal(KMultiProcessSemaphore4))
   116 		{
   117 		iTestResult |= EThirdTestPassed;
   118 		}
   119 
   120     sem4.Wait();
   121 	
   122 	// Close the surface
   123 	if(KErrNone == iSurfaceManager.CloseSurface(id))
   124 		{
   125 		iTestResult |= EFourthTestPassed;
   126 		}
   127 	
   128 	// Open the surface
   129 	if(KErrArgument == iSurfaceManager.CloseSurface(id))
   130 		{
   131 		iTestResult |= EFifthTestPassed;
   132 		}
   133 	
   134 	iChunkWrapper->SetThirdProcessResults(iTestResult);
   135 	
   136 	sem3.Close();
   137 	sem4.Close();
   138 	}
   139 
   140 /**
   141 Test 27: Test closing on one process doesn't prevent opening on other processes, 
   142 			provided one process still owns surface
   143 
   144 ...
   145 Process 3: Open Surface - KErrNone
   146 ...
   147 */	
   148 void CTestDriverThirdProcess::OpenSurface()
   149 	{	
   150 	TSurfaceId id = iChunkWrapper->GetId();
   151 	
   152 	// Open Surface
   153 	if(KErrNone == iSurfaceManager.OpenSurface(id))
   154 		{
   155 		iTestResult |= EFirstTestPassed;
   156 		}
   157 	
   158 	iChunkWrapper->SetThirdProcessResults(iTestResult);
   159 	
   160 	}
   161 
   162 // Real main function
   163 void MainL()
   164 	{
   165 	test.Title();
   166 
   167 	test.Start(_L("Staring 3rd process"));
   168 	TInt testCase;
   169 	User::GetTIntParameter(EMultiProcessSecondSlot, testCase);
   170 	
   171 	CTestDriverThirdProcess* testDriver = CTestDriverThirdProcess::NewL(); 
   172 
   173 	switch(testCase)
   174 		{
   175 	case ECloseSurface:
   176 		testDriver->CloseSurface();
   177 		break;
   178 	case ESurfaceInfo:
   179 		testDriver->SurfaceInfo();
   180 		break;
   181 	case EOpenWaitCloseOpen:
   182 		testDriver->OpenWaitCloseOpen();
   183 		break;
   184 	case EOpenSurface:
   185 		testDriver->OpenSurface();
   186 		break;
   187 	default:
   188 		User::Leave(KErrArgument);
   189 		break;
   190 		}
   191 
   192 	delete testDriver;
   193 	test.End();
   194 	test.Close();
   195 	}
   196 
   197 // Cleanup stack harness
   198 GLDEF_C TInt E32Main()
   199 	{
   200 	__UHEAP_MARK;
   201 	CTrapCleanup* cleanupStack = CTrapCleanup::New();
   202 	TRAPD(error, MainL());
   203 	_LIT(KTThirdProcessPanic,"tthirdprocessmain");
   204 	__ASSERT_ALWAYS(!error, User::Panic(KTThirdProcessPanic, error));
   205 	delete cleanupStack;
   206 	__UHEAP_MARKEND;
   207 	return 0;
   208 	}