testexecmdw/tef/tef/tefunit/src/ctefunitserver.cpp
branchRCL_3
changeset 3 9397a16b6eb8
parent 1 6edeef394eb7
equal deleted inserted replaced
1:6edeef394eb7 3:9397a16b6eb8
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 * Example file/test code to demonstrate how to develop a TestExecute Server
       
    16 * Developers should take this project as a template and substitute their own
       
    17 * code at the __EDIT_ME__ tags
       
    18 * for (WINS && !EKA2) versions will be xxxServer.Dll and require a thread to be started
       
    19 * in the process of the client. The client initialises the server by calling the
       
    20 * one and only ordinal.
       
    21 *
       
    22 */
       
    23 
       
    24 
       
    25 
       
    26 /**
       
    27  @file CTEFUnitServer.cpp
       
    28 */
       
    29 #include "ctefunitserver.h"
       
    30 #include "ctestcommand.h"
       
    31 #include "tefunit.h"
       
    32 
       
    33 _LIT(KTEFUnitStepNamePrefix, "tefunit.");
       
    34 GLREF_D const TTestName ServerName();
       
    35 GLREF_D CTestSuite* CreateTestSuiteL();
       
    36 GLREF_D CTestStep* CreateTEFTestStep(const TDesC& aStepName, CTEFUnitServer& aServer);
       
    37 
       
    38 // __EDIT_ME__ - Use your own server class name
       
    39 CTEFUnitServer* CTEFUnitServer::NewL()
       
    40 /**
       
    41  * @return - Instance of the test server
       
    42  * Called inside the MainL() function to create and start the
       
    43  * CTestServer derived server.
       
    44  */
       
    45 	{
       
    46 	// __EDIT_ME__ new your server class here
       
    47 	CTEFUnitServer * server = new (ELeave) CTEFUnitServer();
       
    48 	CleanupStack::PushL(server);
       
    49 	
       
    50 	// Either use a StartL or ConstructL, the latter will permit
       
    51 	// Server Logging.
       
    52 
       
    53 	//server->StartL(ServerName());
       
    54 	server->ConstructL(ServerName());
       
    55 	server->iSuite = CreateTestSuiteL();
       
    56 	CleanupStack::Pop(server);
       
    57 	return server;
       
    58 	}
       
    59 
       
    60 CTEFUnitServer::~CTEFUnitServer()
       
    61 	{
       
    62 	delete iSuite;
       
    63 	iSuite = NULL;
       
    64 	}
       
    65 
       
    66 // EKA2 much simpler
       
    67 // Just an E32Main and a MainL()
       
    68 LOCAL_C void MainL()
       
    69 /**
       
    70  * Much simpler, uses the new Rendezvous() call to sync with the client
       
    71  */
       
    72 	{
       
    73 	// Leave the hooks in for platform security
       
    74 #if (defined __DATA_CAGING__)
       
    75 	RProcess().DataCaging(RProcess::EDataCagingOn);
       
    76 	RProcess().SecureApi(RProcess::ESecureApiOn);
       
    77 #endif
       
    78 	CActiveScheduler* sched=NULL;
       
    79 	sched=new(ELeave) CActiveScheduler;
       
    80 	CActiveScheduler::Install(sched);
       
    81 	// __EDIT_ME__ Your server name
       
    82 	CTEFUnitServer* server = NULL;
       
    83 	// Create the CTestServer derived server
       
    84 	// __EDIT_ME__ Your server name
       
    85 	TRAPD(err,server = CTEFUnitServer::NewL());
       
    86 	if(!err)
       
    87 		{
       
    88 		// Sync with the client and enter the active scheduler
       
    89 		RProcess::Rendezvous(KErrNone);
       
    90 		sched->Start();
       
    91 		}
       
    92 	delete server;
       
    93 	server = NULL;
       
    94 	delete sched;
       
    95 //	sched = NULL:
       
    96 	}
       
    97 
       
    98 
       
    99 GLDEF_C TInt E32Main()
       
   100 /**
       
   101  * @return - Standard Epoc error code on exit
       
   102  */
       
   103 	{
       
   104 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   105 	if(cleanup == NULL)
       
   106 		{
       
   107 		return KErrNoMemory;
       
   108 		}
       
   109 	TRAP_IGNORE(MainL());
       
   110 	delete cleanup;
       
   111 	cleanup = NULL;
       
   112 	return KErrNone;
       
   113     }
       
   114 
       
   115 // Create a thread in the calling process
       
   116 
       
   117 // __EDIT_ME__ - Use your own server class name
       
   118 CTestStep* CTEFUnitServer::CreateTestStep(const TDesC& aStepName)
       
   119 /**
       
   120  * @return - A CTestStep derived instance
       
   121  * Implementation of CTestServer pure virtual
       
   122  */
       
   123 	{
       
   124 	CTestStep* testStep = NULL;
       
   125 
       
   126 	TBuf<9> stepNamePrefix;
       
   127 	if (aStepName.Length() > KMinTEFUnitStepNameSize)
       
   128 		{
       
   129 		stepNamePrefix.Copy(aStepName.Mid(0,KMinTEFUnitStepNameSize));
       
   130 		stepNamePrefix.LowerCase();
       
   131 		}
       
   132 
       
   133 	// If StepName prefix with TEFUnit. Create a CTestCommand here with the aStepName passed in
       
   134 		//   note: aStepName will actually be the path of the the test
       
   135 		//         in the suite hirarchy
       
   136 	// Else Call Global CreateTEFTestStep() which proceeds with legacy Test Step creation
       
   137 		// Refer Example TEFUnitTE test component for implementation
       
   138 		// CreateTEFTestStep() should return NULL if TEF steps are not used
       
   139 	if (stepNamePrefix.Length() && stepNamePrefix == KTEFUnitStepNamePrefix)
       
   140 		{
       
   141 		TTestPath aStepPath(aStepName.Mid(KMinTEFUnitStepNameSize));
       
   142 		testStep = new CTestCommand( aStepPath, iSuite );
       
   143 		}
       
   144 	else
       
   145 		{
       
   146 		testStep = CreateTEFTestStep(aStepName, *this);
       
   147 		}
       
   148 
       
   149 	return testStep;
       
   150 	}
       
   151