sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Contains implementation of CTestInetProUtilsUriServer class sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: // User Includes sl@0: // Test Server sl@0: #include "TestInetProUtilsUriServer.h" sl@0: sl@0: // Test steps sl@0: #include "TestNormaliseUriStep.h" sl@0: #include "TestEscapeEncodeUriStep.h" sl@0: #include "TestTelUriParsingStep.h" sl@0: #include "TestTelUriValidationStep.h" sl@0: sl@0: _LIT(KTxtEPOC32Test, "InetProtUtilsServer"); sl@0: sl@0: #if (!defined EKA2) sl@0: // The system-wide unique name for the test-server sl@0: _LIT(KServerName, "TestInetProUtilsUriServer"); sl@0: #endif sl@0: sl@0: /** sl@0: Static factory constructor. Creates and returns instance of the test server sl@0: @internalTechnology sl@0: @test sl@0: @return A pointer to the newly created CTestInetProUtilsUriServer object sl@0: */ sl@0: CTestInetProUtilsUriServer* CTestInetProUtilsUriServer::NewL() sl@0: { sl@0: // Construct the server sl@0: CTestInetProUtilsUriServer* server = new(ELeave) CTestInetProUtilsUriServer(); sl@0: CleanupStack::PushL(server); sl@0: sl@0: // CServer base class call sl@0: // Name the server using the system-wide unique string sl@0: // Clients use this to create server sessions. sl@0: server->StartL(server->ServerName()); sl@0: sl@0: CleanupStack::Pop(server); sl@0: return server; sl@0: } sl@0: sl@0: sl@0: #if (!defined EKA2) sl@0: /** sl@0: Creates the Active Scheduler, then creates the test-server, synchronises the sl@0: thread with the client and then enters the active scheduler. sl@0: sl@0: This is EKA1 version of MainL(). Uses sempahore to sync with client sl@0: as Rendezvous calls are not available sl@0: */ sl@0: LOCAL_C void MainL() sl@0: { sl@0: // Create and install the active scheduler. sl@0: CActiveScheduler* sched = new(ELeave) CActiveScheduler; sl@0: CleanupStack::PushL(sched); sl@0: CActiveScheduler::Install(sched); sl@0: sl@0: // Create the server inside trap harness sl@0: CTestInetProUtilsUriServer* server = NULL; sl@0: TRAPD(err, server = CTestInetProUtilsUriServer::NewL()); sl@0: if (!err) sl@0: { sl@0: CleanupStack::PushL(server); sl@0: RSemaphore sem; sl@0: sl@0: // The client API of TestExecute will already have created the sl@0: // semaphore and will be waiting on it. sl@0: User::LeaveIfError(sem.OpenGlobal(KServerName)); sl@0: sl@0: CleanupStack::Pop(server); sl@0: sl@0: // Signal the client sl@0: sem.Signal(); sl@0: sem.Close(); sl@0: sl@0: // Enter the active scheduler sl@0: sched->Start(); sl@0: } sl@0: delete server; sl@0: CleanupStack::PopAndDestroy(sched); sl@0: } sl@0: #else sl@0: /** sl@0: EKA2 version of MainL() sl@0: Uses the new Rendezvous call isntead of the older semaphore. sl@0: */ sl@0: LOCAL_C void MainL() sl@0: { sl@0: // For platform security sl@0: #if (defined __DATA_CAGING__) sl@0: RProcess().DataCaging(RProcess::EDataCagingOn); sl@0: RProcess().SecureApi(RProcess::ESecureApiOn); sl@0: #endif sl@0: CActiveScheduler* sched = new(ELeave) CActiveScheduler; sl@0: CActiveScheduler::Install(sched); sl@0: CTestInetProUtilsUriServer* server = NULL; sl@0: sl@0: // Create the test-server sl@0: TRAPD(err, server = CTestInetProUtilsUriServer::NewL()); sl@0: sl@0: if(!err) sl@0: { sl@0: // Sync with the client and enter the active scheduler sl@0: RProcess::Rendezvous(KErrNone); sl@0: sched->Start(); sl@0: } sl@0: delete server; sl@0: delete sched; sl@0: } sl@0: #endif // #if (!defined EKA2) sl@0: sl@0: sl@0: #if (defined __WINS__ && !defined EKA2) sl@0: /** sl@0: DLL entry-point for EKA1 emulator builds. sl@0: */ sl@0: GLDEF_C TInt E32Dll(enum TDllReason /*aDllReason*/) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: #else sl@0: /** sl@0: Exe entry point code, for EKA1 hardware and EKA2 builds. sl@0: */ sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: if (cleanup == NULL) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: TRAPD(error, MainL()); sl@0: __ASSERT_ALWAYS(!error, User::Panic(KTxtEPOC32Test, error)); sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: return KErrNone; sl@0: } sl@0: #endif // #if (defined __WINS__ && !defined EKA2) sl@0: sl@0: #if (defined __WINS__ && !defined EKA2) sl@0: /** sl@0: For EKA1 emulator builds. This function is called when the thread is first sl@0: resumed. Has the standard thread entry siganture. sl@0: @internalTechnology sl@0: @test sl@0: @return KErrNone if everything is fine or system-wide error if any sl@0: */ sl@0: TInt ThreadFunc (TAny* /*aParam*/) sl@0: { sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: if (cleanup == NULL) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: TRAPD(err, MainL()); sl@0: __ASSERT_ALWAYS(!err, User::Panic(KTxtEPOC32Test, err)); sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: For EKA1 emulator builds. Creates and starts a thread for the server to run. sl@0: @internalTechnology sl@0: @test sl@0: @param None sl@0: @return Integer value indicating the error code. sl@0: */ sl@0: EXPORT_C TInt NewServer() sl@0: { sl@0: _LIT(KThread, "Thread"); sl@0: RThread thread; sl@0: sl@0: // Name the thread as "Thread" making it hopefully unique sl@0: TBuf threadName(KServerName); sl@0: threadName.Append(KThread); sl@0: sl@0: const TInt KMaxHeapSize = 0x1000000; sl@0: sl@0: // Create the thread sl@0: TInt err = thread.Create(threadName, ThreadFunc, KDefaultStackSize, sl@0: KMinHeapSize, KMaxHeapSize, NULL, EOwnerProcess sl@0: ); sl@0: if (err != KErrNone) sl@0: { sl@0: return err; sl@0: } sl@0: sl@0: // Start the thread -> effectively calls ThreadFunc sl@0: thread.Resume(); sl@0: sl@0: thread.Close(); sl@0: return KErrNone; sl@0: } sl@0: #endif // #if (defined __WINS__ && !defined EKA2) sl@0: sl@0: sl@0: /** sl@0: Base class pure virtual sl@0: @internalTechnology sl@0: @test sl@0: @param Descriptor containing the test-step name sl@0: @return Instance of the test step sl@0: */ sl@0: CTestStep* CTestInetProUtilsUriServer::CreateTestStep(const TDesC& aStepName) sl@0: { sl@0: CTestStep* testStep = NULL; sl@0: TRAPD(err,testStep=CreateTestStepL(aStepName)); sl@0: if(err == KErrNone) sl@0: return testStep; sl@0: else sl@0: return NULL; sl@0: } sl@0: sl@0: CTestStep* CTestInetProUtilsUriServer::CreateTestStepL(const TDesC& aStepName) sl@0: { sl@0: CTestStep* testStep = NULL; sl@0: sl@0: if (aStepName == KTestNormaliseUriStep) sl@0: { sl@0: testStep = new (ELeave) CTestNormaliseUriStep(); sl@0: } sl@0: else if (aStepName == KTestEscapeEncodeUriStep) sl@0: { sl@0: testStep = new (ELeave) CTestEscapeEncodeUriStep(); sl@0: } sl@0: else if (aStepName == KTestTelUriParsingStep) sl@0: { sl@0: testStep = new (ELeave) CTestTelUriParsingStep(); sl@0: } sl@0: else if (aStepName == KTestTelUriValidationStep) sl@0: { sl@0: testStep = new (ELeave) CTestTelUriValidationStep(); sl@0: } sl@0: else if (aStepName == KTestOomNormaliseUriStep) sl@0: { sl@0: testStep = new (ELeave) CTestNormaliseUriOomStep(); sl@0: } sl@0: else if (aStepName == KTestOomTelUriValidationStep) sl@0: { sl@0: testStep = new (ELeave) CTestTelUriValidationOomStep(); sl@0: } sl@0: sl@0: return testStep; sl@0: } sl@0: sl@0: /** sl@0: Returns server name based on the EKA version sl@0: @internalTechnology sl@0: @test sl@0: @return Descriptor containing the servername sl@0: */ sl@0: const TPtrC CTestInetProUtilsUriServer::ServerName() sl@0: { sl@0: #if (!defined EKA2) sl@0: return KServerName(); sl@0: #else sl@0: // The exe name can be either TestInetProUtilsUriServer or sl@0: // TestInetProUtilsUriServer_Cap based on whether the normal sl@0: // or the security tests are being run. So decide the server sl@0: // name during runtime sl@0: TParsePtrC serverName(RProcess().FileName()); sl@0: return serverName.Name(); sl@0: #endif sl@0: }