os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestInetProUtilsUriServer.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestInetProUtilsUriServer.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,288 @@
     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 +// Contains implementation of CTestInetProUtilsUriServer class
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @internalTechnology 
    1.24 +*/
    1.25 +
    1.26 +// User Includes
    1.27 +// Test Server
    1.28 +#include "TestInetProUtilsUriServer.h"
    1.29 +
    1.30 +// Test steps
    1.31 +#include "TestNormaliseUriStep.h"
    1.32 +#include "TestEscapeEncodeUriStep.h"
    1.33 +#include "TestTelUriParsingStep.h"
    1.34 +#include "TestTelUriValidationStep.h"
    1.35 +
    1.36 +_LIT(KTxtEPOC32Test, "InetProtUtilsServer");
    1.37 +
    1.38 +#if (!defined EKA2)
    1.39 +// The system-wide unique name for the test-server
    1.40 +_LIT(KServerName, "TestInetProUtilsUriServer");
    1.41 +#endif
    1.42 +
    1.43 +/**
    1.44 +  Static factory constructor. Creates and returns instance of the test server
    1.45 +  @internalTechnology
    1.46 +  @test
    1.47 +  @return		A pointer to the newly created CTestInetProUtilsUriServer object
    1.48 +*/
    1.49 +CTestInetProUtilsUriServer*  CTestInetProUtilsUriServer::NewL()
    1.50 +	{
    1.51 +	// Construct the server
    1.52 +	CTestInetProUtilsUriServer* server = new(ELeave) CTestInetProUtilsUriServer();
    1.53 +	CleanupStack::PushL(server);
    1.54 +
    1.55 +	// CServer base class call
    1.56 +	// Name the server using the system-wide unique string
    1.57 +	// Clients use this to create server sessions.
    1.58 +	server->StartL(server->ServerName());
    1.59 +
    1.60 +	CleanupStack::Pop(server);
    1.61 +	return server;
    1.62 +	}
    1.63 +
    1.64 +
    1.65 +#if (!defined EKA2)
    1.66 +/**
    1.67 +  Creates the Active Scheduler, then creates the test-server, synchronises the
    1.68 +  thread with the client and then enters the active scheduler.
    1.69 +
    1.70 +  This is EKA1 version of MainL(). Uses sempahore to sync with client
    1.71 +  as Rendezvous calls are not available
    1.72 +*/
    1.73 +LOCAL_C void MainL()
    1.74 +	{
    1.75 +	// Create and install the active scheduler.
    1.76 +	CActiveScheduler* sched = new(ELeave) CActiveScheduler;
    1.77 +	CleanupStack::PushL(sched);
    1.78 +	CActiveScheduler::Install(sched);
    1.79 +
    1.80 +	// Create the server inside trap harness
    1.81 +	CTestInetProUtilsUriServer* server = NULL;
    1.82 +	TRAPD(err, server = CTestInetProUtilsUriServer::NewL());
    1.83 +	if (!err)
    1.84 +		{
    1.85 +		CleanupStack::PushL(server);
    1.86 +		RSemaphore sem;
    1.87 +
    1.88 +		// The client API of TestExecute will already have created the
    1.89 +		// semaphore and will be waiting on it.
    1.90 +		User::LeaveIfError(sem.OpenGlobal(KServerName));
    1.91 +
    1.92 +		CleanupStack::Pop(server);
    1.93 +
    1.94 +		// Signal the client
    1.95 +		sem.Signal();
    1.96 +		sem.Close();
    1.97 +
    1.98 +		// Enter the active scheduler
    1.99 +		sched->Start();
   1.100 +		}
   1.101 +	delete server;
   1.102 +	CleanupStack::PopAndDestroy(sched);
   1.103 +	}
   1.104 +#else
   1.105 +/**
   1.106 +  EKA2 version of MainL()
   1.107 +  Uses the new Rendezvous call isntead of the older semaphore.
   1.108 +*/
   1.109 +LOCAL_C void MainL()
   1.110 +	{
   1.111 +	// For platform security
   1.112 +#if (defined __DATA_CAGING__)
   1.113 +	RProcess().DataCaging(RProcess::EDataCagingOn);
   1.114 +	RProcess().SecureApi(RProcess::ESecureApiOn);
   1.115 +#endif
   1.116 +	CActiveScheduler* sched = new(ELeave) CActiveScheduler;
   1.117 +	CActiveScheduler::Install(sched);
   1.118 +	CTestInetProUtilsUriServer* server = NULL;
   1.119 +
   1.120 +	// Create the test-server
   1.121 +	TRAPD(err, server = CTestInetProUtilsUriServer::NewL());
   1.122 +
   1.123 +	if(!err)
   1.124 +		{
   1.125 +		// Sync with the client and enter the active scheduler
   1.126 +		RProcess::Rendezvous(KErrNone);
   1.127 +		sched->Start();
   1.128 +		}
   1.129 +	delete server;
   1.130 +	delete sched;
   1.131 +	}
   1.132 +#endif		// #if (!defined EKA2)
   1.133 +
   1.134 +
   1.135 +#if (defined __WINS__ && !defined EKA2)
   1.136 +/**
   1.137 +  DLL entry-point for EKA1 emulator builds.
   1.138 +*/
   1.139 +GLDEF_C TInt E32Dll(enum TDllReason /*aDllReason*/)
   1.140 +	{
   1.141 +	return KErrNone;
   1.142 +	}
   1.143 +#else
   1.144 +/**
   1.145 +  Exe entry point code, for EKA1 hardware and EKA2 builds.
   1.146 +*/
   1.147 +GLDEF_C TInt E32Main()
   1.148 +	{
   1.149 +	__UHEAP_MARK;
   1.150 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.151 +	if (cleanup == NULL)
   1.152 +		{
   1.153 +		return KErrNoMemory;
   1.154 +		}
   1.155 +	
   1.156 +	TRAPD(error, MainL());
   1.157 +	__ASSERT_ALWAYS(!error, User::Panic(KTxtEPOC32Test, error));
   1.158 +	delete cleanup;
   1.159 +	__UHEAP_MARKEND;
   1.160 +	return KErrNone;
   1.161 +	}
   1.162 +#endif		// #if (defined __WINS__ && !defined EKA2)
   1.163 +
   1.164 +#if (defined __WINS__ && !defined EKA2)
   1.165 +/**
   1.166 +  For EKA1 emulator builds. This function is called when the thread is first
   1.167 +  resumed. Has the standard thread entry siganture.
   1.168 +  @internalTechnology
   1.169 +  @test
   1.170 +  @return		KErrNone if everything is fine or system-wide error if any
   1.171 +*/
   1.172 +TInt ThreadFunc (TAny* /*aParam*/)
   1.173 +	{
   1.174 +	__UHEAP_MARK;
   1.175 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.176 +	if (cleanup == NULL)
   1.177 +		{
   1.178 +		return KErrNoMemory;
   1.179 +		}
   1.180 +
   1.181 +	TRAPD(err, MainL());
   1.182 +	__ASSERT_ALWAYS(!err, User::Panic(KTxtEPOC32Test, err));
   1.183 +	delete cleanup;
   1.184 +	__UHEAP_MARKEND;
   1.185 +	return KErrNone;
   1.186 +	}
   1.187 +
   1.188 +/**
   1.189 +  For EKA1 emulator builds. Creates and starts a thread for the server to run.
   1.190 +  @internalTechnology
   1.191 +  @test
   1.192 +  @param		None
   1.193 +  @return		Integer value indicating the error code.
   1.194 +*/
   1.195 +EXPORT_C TInt NewServer()
   1.196 +	{
   1.197 +	_LIT(KThread, "Thread");
   1.198 +	RThread thread;
   1.199 +
   1.200 +	// Name the thread as "<Server-Name>Thread" making it hopefully unique
   1.201 +	TBuf<KMaxTestExecuteNameLength> threadName(KServerName);
   1.202 +	threadName.Append(KThread);
   1.203 +
   1.204 +	const TInt KMaxHeapSize = 0x1000000;
   1.205 +
   1.206 +	// Create the thread
   1.207 +	TInt err = thread.Create(threadName, ThreadFunc, KDefaultStackSize,
   1.208 +							 KMinHeapSize, KMaxHeapSize, NULL, EOwnerProcess
   1.209 +							);
   1.210 +	if (err != KErrNone)
   1.211 +		{
   1.212 +		return err;
   1.213 +		}
   1.214 +
   1.215 +	// Start the thread -> effectively calls ThreadFunc
   1.216 +	thread.Resume();
   1.217 +
   1.218 +	thread.Close();
   1.219 +	return KErrNone;
   1.220 +	}
   1.221 +#endif 		// #if (defined __WINS__ && !defined EKA2)
   1.222 +
   1.223 +
   1.224 +/**
   1.225 +  Base class pure virtual
   1.226 +  @internalTechnology
   1.227 +  @test
   1.228 +  @param	Descriptor containing the test-step name
   1.229 +  @return 	Instance of the test step
   1.230 +*/
   1.231 +CTestStep* CTestInetProUtilsUriServer::CreateTestStep(const TDesC& aStepName)
   1.232 +	{
   1.233 +	CTestStep* testStep = NULL;
   1.234 +	TRAPD(err,testStep=CreateTestStepL(aStepName));
   1.235 +	if(err == KErrNone)
   1.236 +		return testStep;
   1.237 +	else
   1.238 +		return NULL;
   1.239 +	}
   1.240 +	
   1.241 +CTestStep* CTestInetProUtilsUriServer::CreateTestStepL(const TDesC& aStepName)
   1.242 +	{
   1.243 +	CTestStep* testStep = NULL;
   1.244 +	
   1.245 +	if (aStepName == KTestNormaliseUriStep)
   1.246 +		{
   1.247 +		testStep = new (ELeave) CTestNormaliseUriStep();
   1.248 +		}
   1.249 +	else if (aStepName == KTestEscapeEncodeUriStep)
   1.250 +		{
   1.251 +		testStep = new (ELeave) CTestEscapeEncodeUriStep();
   1.252 +		}
   1.253 +	else if (aStepName == KTestTelUriParsingStep)
   1.254 +		{
   1.255 +		testStep = new (ELeave) CTestTelUriParsingStep();
   1.256 +		}
   1.257 +	else if (aStepName == KTestTelUriValidationStep)
   1.258 +		{
   1.259 +		testStep = new (ELeave) CTestTelUriValidationStep();
   1.260 +		}
   1.261 +	else if (aStepName == KTestOomNormaliseUriStep)
   1.262 +		{
   1.263 +		testStep = new (ELeave) CTestNormaliseUriOomStep();
   1.264 +		}
   1.265 +	else if (aStepName == KTestOomTelUriValidationStep)
   1.266 +		{
   1.267 +		testStep = new (ELeave) CTestTelUriValidationOomStep();
   1.268 +		}
   1.269 +		
   1.270 +	return testStep;
   1.271 +	}
   1.272 +
   1.273 +/**
   1.274 +  Returns server name based on the EKA version
   1.275 +  @internalTechnology
   1.276 +  @test
   1.277 +  @return	Descriptor containing the servername
   1.278 +*/
   1.279 +const TPtrC CTestInetProUtilsUriServer::ServerName()
   1.280 +	{
   1.281 +#if (!defined EKA2)
   1.282 +	return KServerName();
   1.283 +#else
   1.284 +	// The exe name can be either TestInetProUtilsUriServer or
   1.285 +	// TestInetProUtilsUriServer_Cap based on whether the normal
   1.286 +	// or the security tests are being run. So decide the server
   1.287 +	// name during runtime
   1.288 +	TParsePtrC serverName(RProcess().FileName());
   1.289 +	return serverName.Name();
   1.290 +#endif
   1.291 +	}