os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestInetProUtilsUriServer.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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
// Contains implementation of CTestInetProUtilsUriServer class
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @internalTechnology 
sl@0
    21
*/
sl@0
    22
sl@0
    23
// User Includes
sl@0
    24
// Test Server
sl@0
    25
#include "TestInetProUtilsUriServer.h"
sl@0
    26
sl@0
    27
// Test steps
sl@0
    28
#include "TestNormaliseUriStep.h"
sl@0
    29
#include "TestEscapeEncodeUriStep.h"
sl@0
    30
#include "TestTelUriParsingStep.h"
sl@0
    31
#include "TestTelUriValidationStep.h"
sl@0
    32
sl@0
    33
_LIT(KTxtEPOC32Test, "InetProtUtilsServer");
sl@0
    34
sl@0
    35
#if (!defined EKA2)
sl@0
    36
// The system-wide unique name for the test-server
sl@0
    37
_LIT(KServerName, "TestInetProUtilsUriServer");
sl@0
    38
#endif
sl@0
    39
sl@0
    40
/**
sl@0
    41
  Static factory constructor. Creates and returns instance of the test server
sl@0
    42
  @internalTechnology
sl@0
    43
  @test
sl@0
    44
  @return		A pointer to the newly created CTestInetProUtilsUriServer object
sl@0
    45
*/
sl@0
    46
CTestInetProUtilsUriServer*  CTestInetProUtilsUriServer::NewL()
sl@0
    47
	{
sl@0
    48
	// Construct the server
sl@0
    49
	CTestInetProUtilsUriServer* server = new(ELeave) CTestInetProUtilsUriServer();
sl@0
    50
	CleanupStack::PushL(server);
sl@0
    51
sl@0
    52
	// CServer base class call
sl@0
    53
	// Name the server using the system-wide unique string
sl@0
    54
	// Clients use this to create server sessions.
sl@0
    55
	server->StartL(server->ServerName());
sl@0
    56
sl@0
    57
	CleanupStack::Pop(server);
sl@0
    58
	return server;
sl@0
    59
	}
sl@0
    60
sl@0
    61
sl@0
    62
#if (!defined EKA2)
sl@0
    63
/**
sl@0
    64
  Creates the Active Scheduler, then creates the test-server, synchronises the
sl@0
    65
  thread with the client and then enters the active scheduler.
sl@0
    66
sl@0
    67
  This is EKA1 version of MainL(). Uses sempahore to sync with client
sl@0
    68
  as Rendezvous calls are not available
sl@0
    69
*/
sl@0
    70
LOCAL_C void MainL()
sl@0
    71
	{
sl@0
    72
	// Create and install the active scheduler.
sl@0
    73
	CActiveScheduler* sched = new(ELeave) CActiveScheduler;
sl@0
    74
	CleanupStack::PushL(sched);
sl@0
    75
	CActiveScheduler::Install(sched);
sl@0
    76
sl@0
    77
	// Create the server inside trap harness
sl@0
    78
	CTestInetProUtilsUriServer* server = NULL;
sl@0
    79
	TRAPD(err, server = CTestInetProUtilsUriServer::NewL());
sl@0
    80
	if (!err)
sl@0
    81
		{
sl@0
    82
		CleanupStack::PushL(server);
sl@0
    83
		RSemaphore sem;
sl@0
    84
sl@0
    85
		// The client API of TestExecute will already have created the
sl@0
    86
		// semaphore and will be waiting on it.
sl@0
    87
		User::LeaveIfError(sem.OpenGlobal(KServerName));
sl@0
    88
sl@0
    89
		CleanupStack::Pop(server);
sl@0
    90
sl@0
    91
		// Signal the client
sl@0
    92
		sem.Signal();
sl@0
    93
		sem.Close();
sl@0
    94
sl@0
    95
		// Enter the active scheduler
sl@0
    96
		sched->Start();
sl@0
    97
		}
sl@0
    98
	delete server;
sl@0
    99
	CleanupStack::PopAndDestroy(sched);
sl@0
   100
	}
sl@0
   101
#else
sl@0
   102
/**
sl@0
   103
  EKA2 version of MainL()
sl@0
   104
  Uses the new Rendezvous call isntead of the older semaphore.
sl@0
   105
*/
sl@0
   106
LOCAL_C void MainL()
sl@0
   107
	{
sl@0
   108
	// For platform security
sl@0
   109
#if (defined __DATA_CAGING__)
sl@0
   110
	RProcess().DataCaging(RProcess::EDataCagingOn);
sl@0
   111
	RProcess().SecureApi(RProcess::ESecureApiOn);
sl@0
   112
#endif
sl@0
   113
	CActiveScheduler* sched = new(ELeave) CActiveScheduler;
sl@0
   114
	CActiveScheduler::Install(sched);
sl@0
   115
	CTestInetProUtilsUriServer* server = NULL;
sl@0
   116
sl@0
   117
	// Create the test-server
sl@0
   118
	TRAPD(err, server = CTestInetProUtilsUriServer::NewL());
sl@0
   119
sl@0
   120
	if(!err)
sl@0
   121
		{
sl@0
   122
		// Sync with the client and enter the active scheduler
sl@0
   123
		RProcess::Rendezvous(KErrNone);
sl@0
   124
		sched->Start();
sl@0
   125
		}
sl@0
   126
	delete server;
sl@0
   127
	delete sched;
sl@0
   128
	}
sl@0
   129
#endif		// #if (!defined EKA2)
sl@0
   130
sl@0
   131
sl@0
   132
#if (defined __WINS__ && !defined EKA2)
sl@0
   133
/**
sl@0
   134
  DLL entry-point for EKA1 emulator builds.
sl@0
   135
*/
sl@0
   136
GLDEF_C TInt E32Dll(enum TDllReason /*aDllReason*/)
sl@0
   137
	{
sl@0
   138
	return KErrNone;
sl@0
   139
	}
sl@0
   140
#else
sl@0
   141
/**
sl@0
   142
  Exe entry point code, for EKA1 hardware and EKA2 builds.
sl@0
   143
*/
sl@0
   144
GLDEF_C TInt E32Main()
sl@0
   145
	{
sl@0
   146
	__UHEAP_MARK;
sl@0
   147
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   148
	if (cleanup == NULL)
sl@0
   149
		{
sl@0
   150
		return KErrNoMemory;
sl@0
   151
		}
sl@0
   152
	
sl@0
   153
	TRAPD(error, MainL());
sl@0
   154
	__ASSERT_ALWAYS(!error, User::Panic(KTxtEPOC32Test, error));
sl@0
   155
	delete cleanup;
sl@0
   156
	__UHEAP_MARKEND;
sl@0
   157
	return KErrNone;
sl@0
   158
	}
sl@0
   159
#endif		// #if (defined __WINS__ && !defined EKA2)
sl@0
   160
sl@0
   161
#if (defined __WINS__ && !defined EKA2)
sl@0
   162
/**
sl@0
   163
  For EKA1 emulator builds. This function is called when the thread is first
sl@0
   164
  resumed. Has the standard thread entry siganture.
sl@0
   165
  @internalTechnology
sl@0
   166
  @test
sl@0
   167
  @return		KErrNone if everything is fine or system-wide error if any
sl@0
   168
*/
sl@0
   169
TInt ThreadFunc (TAny* /*aParam*/)
sl@0
   170
	{
sl@0
   171
	__UHEAP_MARK;
sl@0
   172
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   173
	if (cleanup == NULL)
sl@0
   174
		{
sl@0
   175
		return KErrNoMemory;
sl@0
   176
		}
sl@0
   177
sl@0
   178
	TRAPD(err, MainL());
sl@0
   179
	__ASSERT_ALWAYS(!err, User::Panic(KTxtEPOC32Test, err));
sl@0
   180
	delete cleanup;
sl@0
   181
	__UHEAP_MARKEND;
sl@0
   182
	return KErrNone;
sl@0
   183
	}
sl@0
   184
sl@0
   185
/**
sl@0
   186
  For EKA1 emulator builds. Creates and starts a thread for the server to run.
sl@0
   187
  @internalTechnology
sl@0
   188
  @test
sl@0
   189
  @param		None
sl@0
   190
  @return		Integer value indicating the error code.
sl@0
   191
*/
sl@0
   192
EXPORT_C TInt NewServer()
sl@0
   193
	{
sl@0
   194
	_LIT(KThread, "Thread");
sl@0
   195
	RThread thread;
sl@0
   196
sl@0
   197
	// Name the thread as "<Server-Name>Thread" making it hopefully unique
sl@0
   198
	TBuf<KMaxTestExecuteNameLength> threadName(KServerName);
sl@0
   199
	threadName.Append(KThread);
sl@0
   200
sl@0
   201
	const TInt KMaxHeapSize = 0x1000000;
sl@0
   202
sl@0
   203
	// Create the thread
sl@0
   204
	TInt err = thread.Create(threadName, ThreadFunc, KDefaultStackSize,
sl@0
   205
							 KMinHeapSize, KMaxHeapSize, NULL, EOwnerProcess
sl@0
   206
							);
sl@0
   207
	if (err != KErrNone)
sl@0
   208
		{
sl@0
   209
		return err;
sl@0
   210
		}
sl@0
   211
sl@0
   212
	// Start the thread -> effectively calls ThreadFunc
sl@0
   213
	thread.Resume();
sl@0
   214
sl@0
   215
	thread.Close();
sl@0
   216
	return KErrNone;
sl@0
   217
	}
sl@0
   218
#endif 		// #if (defined __WINS__ && !defined EKA2)
sl@0
   219
sl@0
   220
sl@0
   221
/**
sl@0
   222
  Base class pure virtual
sl@0
   223
  @internalTechnology
sl@0
   224
  @test
sl@0
   225
  @param	Descriptor containing the test-step name
sl@0
   226
  @return 	Instance of the test step
sl@0
   227
*/
sl@0
   228
CTestStep* CTestInetProUtilsUriServer::CreateTestStep(const TDesC& aStepName)
sl@0
   229
	{
sl@0
   230
	CTestStep* testStep = NULL;
sl@0
   231
	TRAPD(err,testStep=CreateTestStepL(aStepName));
sl@0
   232
	if(err == KErrNone)
sl@0
   233
		return testStep;
sl@0
   234
	else
sl@0
   235
		return NULL;
sl@0
   236
	}
sl@0
   237
	
sl@0
   238
CTestStep* CTestInetProUtilsUriServer::CreateTestStepL(const TDesC& aStepName)
sl@0
   239
	{
sl@0
   240
	CTestStep* testStep = NULL;
sl@0
   241
	
sl@0
   242
	if (aStepName == KTestNormaliseUriStep)
sl@0
   243
		{
sl@0
   244
		testStep = new (ELeave) CTestNormaliseUriStep();
sl@0
   245
		}
sl@0
   246
	else if (aStepName == KTestEscapeEncodeUriStep)
sl@0
   247
		{
sl@0
   248
		testStep = new (ELeave) CTestEscapeEncodeUriStep();
sl@0
   249
		}
sl@0
   250
	else if (aStepName == KTestTelUriParsingStep)
sl@0
   251
		{
sl@0
   252
		testStep = new (ELeave) CTestTelUriParsingStep();
sl@0
   253
		}
sl@0
   254
	else if (aStepName == KTestTelUriValidationStep)
sl@0
   255
		{
sl@0
   256
		testStep = new (ELeave) CTestTelUriValidationStep();
sl@0
   257
		}
sl@0
   258
	else if (aStepName == KTestOomNormaliseUriStep)
sl@0
   259
		{
sl@0
   260
		testStep = new (ELeave) CTestNormaliseUriOomStep();
sl@0
   261
		}
sl@0
   262
	else if (aStepName == KTestOomTelUriValidationStep)
sl@0
   263
		{
sl@0
   264
		testStep = new (ELeave) CTestTelUriValidationOomStep();
sl@0
   265
		}
sl@0
   266
		
sl@0
   267
	return testStep;
sl@0
   268
	}
sl@0
   269
sl@0
   270
/**
sl@0
   271
  Returns server name based on the EKA version
sl@0
   272
  @internalTechnology
sl@0
   273
  @test
sl@0
   274
  @return	Descriptor containing the servername
sl@0
   275
*/
sl@0
   276
const TPtrC CTestInetProUtilsUriServer::ServerName()
sl@0
   277
	{
sl@0
   278
#if (!defined EKA2)
sl@0
   279
	return KServerName();
sl@0
   280
#else
sl@0
   281
	// The exe name can be either TestInetProUtilsUriServer or
sl@0
   282
	// TestInetProUtilsUriServer_Cap based on whether the normal
sl@0
   283
	// or the security tests are being run. So decide the server
sl@0
   284
	// name during runtime
sl@0
   285
	TParsePtrC serverName(RProcess().FileName());
sl@0
   286
	return serverName.Name();
sl@0
   287
#endif
sl@0
   288
	}