phonebookengines/contactsmodel/tsrc/Integration/TestStartUp/src/TestStartUpServer.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2005-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "TestStartUpServer.h"
       
    17 #include "TestGetSetViewSettingStep.h"
       
    18 #include "TestStartUpExeStep.h"
       
    19 #include "TestContactsDbStep.h"
       
    20 
       
    21 _LIT(KServerName,"TestStartUpSuite");
       
    22 
       
    23 /**
       
    24  * @return - Instance of the test server
       
    25  * Called inside the MainL() function to create and start the
       
    26  * CTestServer derived server.
       
    27  */
       
    28 CTestStartUpServer* CTestStartUpServer::NewL()
       
    29 	{
       
    30 	CTestStartUpServer* server = new (ELeave) CTestStartUpServer();
       
    31 	CleanupStack::PushL(server);
       
    32 	
       
    33 	// Either use a StartL or ConstructL, the latter will permit
       
    34 	// Server Logging.
       
    35 
       
    36 	server-> ConstructL(KServerName);
       
    37 	CleanupStack::Pop(server);
       
    38 	return server;
       
    39 	}
       
    40 
       
    41 
       
    42 /**
       
    43  * Uses the new Rendezvous() call to sync with the client
       
    44  */
       
    45 LOCAL_C void MainL()
       
    46 	{
       
    47 	// Leave the hooks in for platform security
       
    48 #if (defined __DATA_CAGING__)
       
    49 	RProcess().DataCaging(RProcess::EDataCagingOn);
       
    50 	RProcess().SecureApi(RProcess::ESecureApiOn);
       
    51 #endif
       
    52 	CActiveScheduler* sched = NULL;
       
    53 	sched = new(ELeave) CActiveScheduler;
       
    54 	CActiveScheduler::Install(sched);
       
    55 	CTestStartUpServer* server = NULL;
       
    56 	// Create the CTestServer derived server
       
    57 	TRAPD(err,server = CTestStartUpServer::NewL());
       
    58 	if(KErrNone == err)
       
    59 		{
       
    60 		// Sync with the client and enter the active scheduler
       
    61 		RProcess::Rendezvous(KErrNone);
       
    62 		sched->Start();
       
    63 		}
       
    64 	delete server;
       
    65 	delete sched;
       
    66 	}
       
    67 
       
    68 
       
    69 /**
       
    70  * @return - Standard Epoc error code on exit
       
    71  */
       
    72 GLDEF_C TInt E32Main()
       
    73 	{
       
    74 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
    75 	if(cleanup == NULL)
       
    76 		{
       
    77 		return KErrNoMemory;
       
    78 		}
       
    79 	TRAPD(err,MainL());
       
    80 	
       
    81 	if (err != KErrNone)
       
    82 	    {
       
    83 	    // Error	
       
    84 	    }	
       
    85 	    
       
    86 	delete cleanup;
       
    87 	return KErrNone;
       
    88     }
       
    89     
       
    90 
       
    91 /**
       
    92  * @return - A CTestStep derived instance
       
    93  * Implementation of CTestServer pure virtual
       
    94  */
       
    95 CTestStep* CTestStartUpServer::CreateTestStep(const TDesC& aStepName)
       
    96 	{
       
    97 	CTestStep* testStep = NULL;
       
    98 
       
    99     if (aStepName == KTestGetSetViewSettingStep)
       
   100         {
       
   101 	    testStep = new CTestGetSetViewSettingStep();
       
   102         }  
       
   103     else if (aStepName == KTestStartUpExeStep)
       
   104         {
       
   105         testStep = new CTestStartUpExeStep(*this);
       
   106         }
       
   107     else if (aStepName == KTestContactsDbStep)
       
   108         {
       
   109         testStep = new CTestContactsDbStep();
       
   110         }
       
   111                 
       
   112 	return testStep;
       
   113 	}
       
   114 	
       
   115 
       
   116 /**
       
   117  * @return - err
       
   118  * Implements a method to launch the contacts server.
       
   119  * The method is called from a test step but the handle to
       
   120  * the new process is stores in the CTestStartUpServer so that
       
   121  * other test steps can either terminate or retieve information
       
   122  * regarding the startup process.
       
   123  * @param aExeName
       
   124  * @param aServerMode
       
   125  */ 
       
   126 TInt CTestStartUpServer::LaunchCntsStartUpExe(TPtrC aExeName, TPtrC aServerMode)
       
   127     {	
       
   128 	TInt err=iStartUpProcess.Create(aExeName,aServerMode);
       
   129 
       
   130 	if (err!=KErrNone)
       
   131 		{
       
   132 		return err;
       
   133 		}
       
   134 
       
   135 	TRequestStatus stat;
       
   136 	iStartUpProcess.Rendezvous(stat);
       
   137 	if (stat!=KRequestPending)
       
   138 		{
       
   139 		iStartUpProcess.Kill(0);    // abort startup
       
   140 		}
       
   141 	else
       
   142 		{
       
   143 		iStartUpProcess.Resume();	// logon OK - start the server
       
   144 		}
       
   145 	User::WaitForRequest(stat);		// wait for start or death
       
   146 	return (err);
       
   147     }
       
   148 
       
   149 
       
   150 /**
       
   151  * Implements a method to terminate the contacts server.
       
   152  * The method is called from a test step.
       
   153  */
       
   154 void CTestStartUpServer::TermCntsStartUpExe()
       
   155     {
       
   156 	iStartUpProcess.Terminate(0);
       
   157     }   
       
   158 
       
   159 
       
   160 /**
       
   161  * @return  TBool
       
   162  * @param aExitTypeFromIni
       
   163  * @param aExitReasonFromIni
       
   164  * Implements a method to check status of the contacts server.
       
   165  * The method is called from a test step. The exit type and
       
   166  * exit reason are retieved for the startup exe and compared
       
   167  * against expected values read from an ini file.
       
   168  */  
       
   169 TBool CTestStartUpServer::CheckCntsStartUpExe(TExitType aExitTypeFromIni, TInt aExitReasonFromIni)
       
   170     {	
       
   171 	TExitType exitType = iStartUpProcess.ExitType();
       
   172 	TInt exitReason = iStartUpProcess.ExitReason();
       
   173 	
       
   174 	_LIT(KExitTypeFromIni,"Expected Exit Type From ini, ExitTypeValue = %d");
       
   175 	INFO_PRINTF2(KExitTypeFromIni,aExitTypeFromIni);
       
   176 		
       
   177 	_LIT(KExitReasonFromIni,"Expected ExitReason from ini, ExitReasonValue = %d");
       
   178 	INFO_PRINTF2(KExitReasonFromIni,aExitReasonFromIni);
       
   179 	
       
   180 	if (exitType == aExitTypeFromIni && exitReason == aExitReasonFromIni)
       
   181 	    {
       
   182 	    _LIT(KReasonOK,"Exit Type and reason for process as expected");
       
   183 	    INFO_PRINTF1(KReasonOK);
       
   184 	    _LIT(KExitTypeOk,"Exit Type Returned From Server, ExitType = %d");
       
   185 	    _LIT(KExitReasonOk,"Exit Reason Returned Frrom Server, ExitReason = %d");
       
   186 	    INFO_PRINTF2(KExitTypeOk,exitType);
       
   187 	    INFO_PRINTF2(KExitReasonOk,exitReason);
       
   188 		return (ETrue);
       
   189 	    }
       
   190 	else
       
   191 	    {
       
   192 	    _LIT(KReasonNotOK,"Exit Type and reason for process not as expected");
       
   193 	    ERR_PRINTF1(KReasonNotOK);
       
   194 	    _LIT(KExitTypeNotOk,"Exit Type Returned From Server, ExitType = %d");
       
   195 	    _LIT(KExitReasonNotOk,"Exit Reason Returned Frrom Server, ExitReason = %d");
       
   196 	    ERR_PRINTF2(KExitTypeNotOk,exitType);
       
   197 	    ERR_PRINTF2(KExitReasonNotOk,exitReason);
       
   198 		return (EFalse);
       
   199 	    }
       
   200     }
       
   201 
       
   202