os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestInetProUtilsUriServer.cpp
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Contains implementation of CTestInetProUtilsUriServer class
25 #include "TestInetProUtilsUriServer.h"
28 #include "TestNormaliseUriStep.h"
29 #include "TestEscapeEncodeUriStep.h"
30 #include "TestTelUriParsingStep.h"
31 #include "TestTelUriValidationStep.h"
33 _LIT(KTxtEPOC32Test, "InetProtUtilsServer");
36 // The system-wide unique name for the test-server
37 _LIT(KServerName, "TestInetProUtilsUriServer");
41 Static factory constructor. Creates and returns instance of the test server
44 @return A pointer to the newly created CTestInetProUtilsUriServer object
46 CTestInetProUtilsUriServer* CTestInetProUtilsUriServer::NewL()
48 // Construct the server
49 CTestInetProUtilsUriServer* server = new(ELeave) CTestInetProUtilsUriServer();
50 CleanupStack::PushL(server);
52 // CServer base class call
53 // Name the server using the system-wide unique string
54 // Clients use this to create server sessions.
55 server->StartL(server->ServerName());
57 CleanupStack::Pop(server);
64 Creates the Active Scheduler, then creates the test-server, synchronises the
65 thread with the client and then enters the active scheduler.
67 This is EKA1 version of MainL(). Uses sempahore to sync with client
68 as Rendezvous calls are not available
72 // Create and install the active scheduler.
73 CActiveScheduler* sched = new(ELeave) CActiveScheduler;
74 CleanupStack::PushL(sched);
75 CActiveScheduler::Install(sched);
77 // Create the server inside trap harness
78 CTestInetProUtilsUriServer* server = NULL;
79 TRAPD(err, server = CTestInetProUtilsUriServer::NewL());
82 CleanupStack::PushL(server);
85 // The client API of TestExecute will already have created the
86 // semaphore and will be waiting on it.
87 User::LeaveIfError(sem.OpenGlobal(KServerName));
89 CleanupStack::Pop(server);
95 // Enter the active scheduler
99 CleanupStack::PopAndDestroy(sched);
103 EKA2 version of MainL()
104 Uses the new Rendezvous call isntead of the older semaphore.
108 // For platform security
109 #if (defined __DATA_CAGING__)
110 RProcess().DataCaging(RProcess::EDataCagingOn);
111 RProcess().SecureApi(RProcess::ESecureApiOn);
113 CActiveScheduler* sched = new(ELeave) CActiveScheduler;
114 CActiveScheduler::Install(sched);
115 CTestInetProUtilsUriServer* server = NULL;
117 // Create the test-server
118 TRAPD(err, server = CTestInetProUtilsUriServer::NewL());
122 // Sync with the client and enter the active scheduler
123 RProcess::Rendezvous(KErrNone);
129 #endif // #if (!defined EKA2)
132 #if (defined __WINS__ && !defined EKA2)
134 DLL entry-point for EKA1 emulator builds.
136 GLDEF_C TInt E32Dll(enum TDllReason /*aDllReason*/)
142 Exe entry point code, for EKA1 hardware and EKA2 builds.
144 GLDEF_C TInt E32Main()
147 CTrapCleanup* cleanup = CTrapCleanup::New();
153 TRAPD(error, MainL());
154 __ASSERT_ALWAYS(!error, User::Panic(KTxtEPOC32Test, error));
159 #endif // #if (defined __WINS__ && !defined EKA2)
161 #if (defined __WINS__ && !defined EKA2)
163 For EKA1 emulator builds. This function is called when the thread is first
164 resumed. Has the standard thread entry siganture.
167 @return KErrNone if everything is fine or system-wide error if any
169 TInt ThreadFunc (TAny* /*aParam*/)
172 CTrapCleanup* cleanup = CTrapCleanup::New();
179 __ASSERT_ALWAYS(!err, User::Panic(KTxtEPOC32Test, err));
186 For EKA1 emulator builds. Creates and starts a thread for the server to run.
190 @return Integer value indicating the error code.
192 EXPORT_C TInt NewServer()
194 _LIT(KThread, "Thread");
197 // Name the thread as "<Server-Name>Thread" making it hopefully unique
198 TBuf<KMaxTestExecuteNameLength> threadName(KServerName);
199 threadName.Append(KThread);
201 const TInt KMaxHeapSize = 0x1000000;
204 TInt err = thread.Create(threadName, ThreadFunc, KDefaultStackSize,
205 KMinHeapSize, KMaxHeapSize, NULL, EOwnerProcess
212 // Start the thread -> effectively calls ThreadFunc
218 #endif // #if (defined __WINS__ && !defined EKA2)
222 Base class pure virtual
225 @param Descriptor containing the test-step name
226 @return Instance of the test step
228 CTestStep* CTestInetProUtilsUriServer::CreateTestStep(const TDesC& aStepName)
230 CTestStep* testStep = NULL;
231 TRAPD(err,testStep=CreateTestStepL(aStepName));
238 CTestStep* CTestInetProUtilsUriServer::CreateTestStepL(const TDesC& aStepName)
240 CTestStep* testStep = NULL;
242 if (aStepName == KTestNormaliseUriStep)
244 testStep = new (ELeave) CTestNormaliseUriStep();
246 else if (aStepName == KTestEscapeEncodeUriStep)
248 testStep = new (ELeave) CTestEscapeEncodeUriStep();
250 else if (aStepName == KTestTelUriParsingStep)
252 testStep = new (ELeave) CTestTelUriParsingStep();
254 else if (aStepName == KTestTelUriValidationStep)
256 testStep = new (ELeave) CTestTelUriValidationStep();
258 else if (aStepName == KTestOomNormaliseUriStep)
260 testStep = new (ELeave) CTestNormaliseUriOomStep();
262 else if (aStepName == KTestOomTelUriValidationStep)
264 testStep = new (ELeave) CTestTelUriValidationOomStep();
271 Returns server name based on the EKA version
274 @return Descriptor containing the servername
276 const TPtrC CTestInetProUtilsUriServer::ServerName()
279 return KServerName();
281 // The exe name can be either TestInetProUtilsUriServer or
282 // TestInetProUtilsUriServer_Cap based on whether the normal
283 // or the security tests are being run. So decide the server
284 // name during runtime
285 TParsePtrC serverName(RProcess().FileName());
286 return serverName.Name();