os/graphics/graphicshwdrivers/surfacemgr/test/src/tthirdprocess.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicshwdrivers/surfacemgr/test/src/tthirdprocess.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,208 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Surface manager multi-processed test code
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @test
    1.24 + @internalComponent - Internal Symbian test code
    1.25 +*/
    1.26 +
    1.27 +#include <e32test.h>
    1.28 +#include <e32std.h>
    1.29 +#include <graphics/surface.h>
    1.30 +#include <graphics/surfacemanager.h>
    1.31 +#include "tsmgmultprocessshared.h"
    1.32 +
    1.33 +LOCAL_D RTest test(_L("TThirdProcess"));
    1.34 +
    1.35 +
    1.36 +class CTestDriverThirdProcess : public CTestDriver
    1.37 +{
    1.38 +public:
    1.39 +	CTestDriverThirdProcess();
    1.40 +	static CTestDriverThirdProcess* NewL();
    1.41 +public:
    1.42 +	void CloseSurface();
    1.43 +	void SurfaceInfo();
    1.44 +	void OpenWaitCloseOpen();
    1.45 +	void OpenSurface();
    1.46 +};
    1.47 +
    1.48 +CTestDriverThirdProcess::CTestDriverThirdProcess():CTestDriver()
    1.49 +	{}
    1.50 +
    1.51 +
    1.52 +CTestDriverThirdProcess* CTestDriverThirdProcess::NewL()
    1.53 +	{
    1.54 +	CTestDriverThirdProcess * driver = new (ELeave) CTestDriverThirdProcess();
    1.55 +	CleanupStack::PushL(driver);
    1.56 +	driver->CTestDriver::ConstructL();
    1.57 +	CleanupStack::Pop(driver);
    1.58 +	return driver;
    1.59 +	}
    1.60 +
    1.61 +void CTestDriverThirdProcess::CloseSurface()
    1.62 +	{
    1.63 +	TSurfaceId id = iChunkWrapper->GetId();
    1.64 +	// Close Surface
    1.65 +	if(KErrAccessDenied == iSurfaceManager.CloseSurface(id))
    1.66 +		{
    1.67 +		iTestResult |= EFirstTestPassed;
    1.68 +		}
    1.69 +	
    1.70 +	iChunkWrapper->SetThirdProcessResults(iTestResult);
    1.71 +	}
    1.72 +
    1.73 +void CTestDriverThirdProcess::SurfaceInfo()
    1.74 +	{
    1.75 +	TSurfaceId id = iChunkWrapper->GetId();
    1.76 +	// SurfaceInfo
    1.77 +	// Call Surface Info on the surface in this process
    1.78 +	RSurfaceManager::TInfoBuf infoBuf;
    1.79 +	if(KErrAccessDenied == iSurfaceManager.SurfaceInfo(id,infoBuf))// This is correct?
    1.80 +		{
    1.81 +		iTestResult |= EFirstTestPassed;
    1.82 +		}
    1.83 +	
    1.84 +	iChunkWrapper->SetThirdProcessResults(iTestResult);
    1.85 +	}
    1.86 +
    1.87 +/**
    1.88 +Test 25: Test surface can be accessed from third process when creating 
    1.89 +			process dies and second process closes
    1.90 +
    1.91 +...			
    1.92 +Process 3: Open Surface
    1.93 +...
    1.94 +Process 3: Close Surface - KErrNone
    1.95 +Process 3: Open Surface - KErrArgument
    1.96 +*/	
    1.97 +void CTestDriverThirdProcess::OpenWaitCloseOpen()
    1.98 +	{
    1.99 +	TSurfaceId id = iChunkWrapper->GetId();
   1.100 +	
   1.101 +	// Open the surface using the surfaceId
   1.102 +	if(KErrNone == iSurfaceManager.OpenSurface(id))
   1.103 +		{
   1.104 +		iTestResult |= EFirstTestPassed;
   1.105 +		}
   1.106 +	
   1.107 +	// Pass control back to the first process
   1.108 +    RSemaphore sem3;
   1.109 +	if(KErrNone == sem3.OpenGlobal(KMultiProcessSemaphore3))
   1.110 +		{
   1.111 +		iTestResult |= ESecondTestPassed;
   1.112 +		}
   1.113 +
   1.114 +    User::After(100000);
   1.115 +    sem3.Signal();
   1.116 +    
   1.117 +    RSemaphore sem4;
   1.118 +	if(KErrNone == sem4.OpenGlobal(KMultiProcessSemaphore4))
   1.119 +		{
   1.120 +		iTestResult |= EThirdTestPassed;
   1.121 +		}
   1.122 +
   1.123 +    sem4.Wait();
   1.124 +	
   1.125 +	// Close the surface
   1.126 +	if(KErrNone == iSurfaceManager.CloseSurface(id))
   1.127 +		{
   1.128 +		iTestResult |= EFourthTestPassed;
   1.129 +		}
   1.130 +	
   1.131 +	// Open the surface
   1.132 +	if(KErrArgument == iSurfaceManager.CloseSurface(id))
   1.133 +		{
   1.134 +		iTestResult |= EFifthTestPassed;
   1.135 +		}
   1.136 +	
   1.137 +	iChunkWrapper->SetThirdProcessResults(iTestResult);
   1.138 +	
   1.139 +	sem3.Close();
   1.140 +	sem4.Close();
   1.141 +	}
   1.142 +
   1.143 +/**
   1.144 +Test 27: Test closing on one process doesn't prevent opening on other processes, 
   1.145 +			provided one process still owns surface
   1.146 +
   1.147 +...
   1.148 +Process 3: Open Surface - KErrNone
   1.149 +...
   1.150 +*/	
   1.151 +void CTestDriverThirdProcess::OpenSurface()
   1.152 +	{	
   1.153 +	TSurfaceId id = iChunkWrapper->GetId();
   1.154 +	
   1.155 +	// Open Surface
   1.156 +	if(KErrNone == iSurfaceManager.OpenSurface(id))
   1.157 +		{
   1.158 +		iTestResult |= EFirstTestPassed;
   1.159 +		}
   1.160 +	
   1.161 +	iChunkWrapper->SetThirdProcessResults(iTestResult);
   1.162 +	
   1.163 +	}
   1.164 +
   1.165 +// Real main function
   1.166 +void MainL()
   1.167 +	{
   1.168 +	test.Title();
   1.169 +
   1.170 +	test.Start(_L("Staring 3rd process"));
   1.171 +	TInt testCase;
   1.172 +	User::GetTIntParameter(EMultiProcessSecondSlot, testCase);
   1.173 +	
   1.174 +	CTestDriverThirdProcess* testDriver = CTestDriverThirdProcess::NewL(); 
   1.175 +
   1.176 +	switch(testCase)
   1.177 +		{
   1.178 +	case ECloseSurface:
   1.179 +		testDriver->CloseSurface();
   1.180 +		break;
   1.181 +	case ESurfaceInfo:
   1.182 +		testDriver->SurfaceInfo();
   1.183 +		break;
   1.184 +	case EOpenWaitCloseOpen:
   1.185 +		testDriver->OpenWaitCloseOpen();
   1.186 +		break;
   1.187 +	case EOpenSurface:
   1.188 +		testDriver->OpenSurface();
   1.189 +		break;
   1.190 +	default:
   1.191 +		User::Leave(KErrArgument);
   1.192 +		break;
   1.193 +		}
   1.194 +
   1.195 +	delete testDriver;
   1.196 +	test.End();
   1.197 +	test.Close();
   1.198 +	}
   1.199 +
   1.200 +// Cleanup stack harness
   1.201 +GLDEF_C TInt E32Main()
   1.202 +	{
   1.203 +	__UHEAP_MARK;
   1.204 +	CTrapCleanup* cleanupStack = CTrapCleanup::New();
   1.205 +	TRAPD(error, MainL());
   1.206 +	_LIT(KTThirdProcessPanic,"tthirdprocessmain");
   1.207 +	__ASSERT_ALWAYS(!error, User::Panic(KTThirdProcessPanic, error));
   1.208 +	delete cleanupStack;
   1.209 +	__UHEAP_MARKEND;
   1.210 +	return 0;
   1.211 +	}