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