summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/integration/teststartup/src/teststartupserver.cpp
blob: 2546afe01921a86a0aa8eca4e236e55fe4b7d310 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
* Contact: http://www.qt-project.org/legal
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


#include "teststartupserver.h"
#include "testgetsetviewsettingstep.h"
#include "teststartupexestep.h"
#include "testcontactsdbstep.h"

_LIT(KServerName,"TestStartUpSuite");

/**
 * @return - Instance of the test server
 * Called inside the MainL() function to create and start the
 * CTestServer derived server.
 */
CTestStartUpServer* CTestStartUpServer::NewL()
	{
	CTestStartUpServer* server = new (ELeave) CTestStartUpServer();
	CleanupStack::PushL(server);
	
	// Either use a StartL or ConstructL, the latter will permit
	// Server Logging.

	server-> ConstructL(KServerName);
	CleanupStack::Pop(server);
	return server;
	}


/**
 * Uses the new Rendezvous() call to sync with the client
 */
LOCAL_C void MainL()
	{
	// Leave the hooks in for platform security
#if (defined __DATA_CAGING__)
	RProcess().DataCaging(RProcess::EDataCagingOn);
	RProcess().SecureApi(RProcess::ESecureApiOn);
#endif
	CActiveScheduler* sched = NULL;
	sched = new(ELeave) CActiveScheduler;
	CActiveScheduler::Install(sched);
	CTestStartUpServer* server = NULL;
	// Create the CTestServer derived server
	TRAPD(err,server = CTestStartUpServer::NewL());
	if(KErrNone == err)
		{
		// Sync with the client and enter the active scheduler
		RProcess::Rendezvous(KErrNone);
		sched->Start();
		}
	delete server;
	delete sched;
	}


/**
 * @return - Standard Epoc error code on exit
 */
GLDEF_C TInt E32Main()
	{
	CTrapCleanup* cleanup = CTrapCleanup::New();
	if(cleanup == NULL)
		{
		return KErrNoMemory;
		}
	TRAPD(err,MainL());
	
	if (err != KErrNone)
	    {
	    // Error	
	    }	
	    
	delete cleanup;
	return KErrNone;
    }
    

/**
 * @return - A CTestStep derived instance
 * Implementation of CTestServer pure virtual
 */
CTestStep* CTestStartUpServer::CreateTestStep(const TDesC& aStepName)
	{
	CTestStep* testStep = NULL;

    if (aStepName == KTestGetSetViewSettingStep)
        {
	    testStep = new CTestGetSetViewSettingStep();
        }  
    else if (aStepName == KTestStartUpExeStep)
        {
        testStep = new CTestStartUpExeStep(*this);
        }
    else if (aStepName == KTestContactsDbStep)
        {
        testStep = new CTestContactsDbStep();
        }
                
	return testStep;
	}
	

/**
 * @return - err
 * Implements a method to launch the contacts server.
 * The method is called from a test step but the handle to
 * the new process is stores in the CTestStartUpServer so that
 * other test steps can either terminate or retieve information
 * regarding the startup process.
 * @param aExeName
 * @param aServerMode
 */ 
TInt CTestStartUpServer::LaunchCntsStartUpExe(TPtrC aExeName, TPtrC aServerMode)
    {	
	TInt err=iStartUpProcess.Create(aExeName,aServerMode);

	if (err!=KErrNone)
		{
		return err;
		}

	TRequestStatus stat;
	iStartUpProcess.Rendezvous(stat);
	if (stat!=KRequestPending)
		{
		iStartUpProcess.Kill(0);    // abort startup
		}
	else
		{
		iStartUpProcess.Resume();	// logon OK - start the server
		}
	User::WaitForRequest(stat);		// wait for start or death
	return (err);
    }


/**
 * Implements a method to terminate the contacts server.
 * The method is called from a test step.
 */
void CTestStartUpServer::TermCntsStartUpExe()
    {
	iStartUpProcess.Terminate(0);
    }   


/**
 * @return  TBool
 * @param aExitTypeFromIni
 * @param aExitReasonFromIni
 * Implements a method to check status of the contacts server.
 * The method is called from a test step. The exit type and
 * exit reason are retieved for the startup exe and compared
 * against expected values read from an ini file.
 */  
TBool CTestStartUpServer::CheckCntsStartUpExe(TExitType aExitTypeFromIni, TInt aExitReasonFromIni)
    {	
	TExitType exitType = iStartUpProcess.ExitType();
	TInt exitReason = iStartUpProcess.ExitReason();
	
	_LIT(KExitTypeFromIni,"Expected Exit Type From ini, ExitTypeValue = %d");
	INFO_PRINTF2(KExitTypeFromIni,aExitTypeFromIni);
		
	_LIT(KExitReasonFromIni,"Expected ExitReason from ini, ExitReasonValue = %d");
	INFO_PRINTF2(KExitReasonFromIni,aExitReasonFromIni);
	
	if (exitType == aExitTypeFromIni && exitReason == aExitReasonFromIni)
	    {
	    _LIT(KReasonOK,"Exit Type and reason for process as expected");
	    INFO_PRINTF1(KReasonOK);
	    _LIT(KExitTypeOk,"Exit Type Returned From Server, ExitType = %d");
	    _LIT(KExitReasonOk,"Exit Reason Returned Frrom Server, ExitReason = %d");
	    INFO_PRINTF2(KExitTypeOk,exitType);
	    INFO_PRINTF2(KExitReasonOk,exitReason);
		return (ETrue);
	    }
	else
	    {
	    _LIT(KReasonNotOK,"Exit Type and reason for process not as expected");
	    ERR_PRINTF1(KReasonNotOK);
	    _LIT(KExitTypeNotOk,"Exit Type Returned From Server, ExitType = %d");
	    _LIT(KExitReasonNotOk,"Exit Reason Returned Frrom Server, ExitReason = %d");
	    ERR_PRINTF2(KExitTypeNotOk,exitType);
	    ERR_PRINTF2(KExitReasonNotOk,exitReason);
		return (EFalse);
	    }
    }