sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Implementation of test execute steps for log engine backup and restore
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
/**
|
sl@0
|
19 |
@file
|
sl@0
|
20 |
@internalComponent
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
#ifndef __BACKUPRESTORESTEP_H__
|
sl@0
|
23 |
#define __BACKUPRESTORESTEP_H__
|
sl@0
|
24 |
|
sl@0
|
25 |
#include "backuprestorestep.h"
|
sl@0
|
26 |
#include "LogCliServShared.h"
|
sl@0
|
27 |
#include "LogServShared.h"
|
sl@0
|
28 |
|
sl@0
|
29 |
const TUid KTestEventUid1 = {0x10005393};
|
sl@0
|
30 |
_LIT(KTestEventDesc1, "Event Type Description");
|
sl@0
|
31 |
const TUid KTestEventUid2 = {0x10005394};
|
sl@0
|
32 |
_LIT(KTestEventDesc2, "Second Event Type Description");
|
sl@0
|
33 |
_LIT(KLogDatabaseName,"c:\\private\\101f401d\\Logdbu.dat");
|
sl@0
|
34 |
#ifndef _DEBUG
|
sl@0
|
35 |
_LIT(KLogEngineServerName,"LogServ*");
|
sl@0
|
36 |
#endif
|
sl@0
|
37 |
|
sl@0
|
38 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
39 |
////////////// CBackupRestoreStepBase //////////////////////////////////////////////////////////////////////////
|
sl@0
|
40 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
41 |
|
sl@0
|
42 |
/**
|
sl@0
|
43 |
Override of base class virtual
|
sl@0
|
44 |
Initializes members needed for test
|
sl@0
|
45 |
*/
|
sl@0
|
46 |
TVerdict CBackupRestoreStepBase::doTestStepPreambleL()
|
sl@0
|
47 |
{
|
sl@0
|
48 |
__UHEAP_MARK;
|
sl@0
|
49 |
|
sl@0
|
50 |
iScheduler = new(ELeave)CActiveScheduler();
|
sl@0
|
51 |
CActiveScheduler::Install(iScheduler);
|
sl@0
|
52 |
|
sl@0
|
53 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
54 |
|
sl@0
|
55 |
iClient = CLogClient::NewL(iFs);
|
sl@0
|
56 |
|
sl@0
|
57 |
iActive = new(ELeave) CTestActive();
|
sl@0
|
58 |
|
sl@0
|
59 |
return EPass;
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
CBackupRestoreStepBase::~CBackupRestoreStepBase()
|
sl@0
|
63 |
{
|
sl@0
|
64 |
delete iActive;
|
sl@0
|
65 |
iActive = NULL;
|
sl@0
|
66 |
|
sl@0
|
67 |
delete iClient;
|
sl@0
|
68 |
iClient = NULL;
|
sl@0
|
69 |
|
sl@0
|
70 |
iFs.Close();
|
sl@0
|
71 |
|
sl@0
|
72 |
CActiveScheduler::Install(NULL);
|
sl@0
|
73 |
delete iScheduler;
|
sl@0
|
74 |
iScheduler = NULL;
|
sl@0
|
75 |
|
sl@0
|
76 |
__UHEAP_MARKEND;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
void CBackupRestoreStepBase::GetDataFromConfigL(TUid& aEventUid, TPtrC& aEventDesctiption)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
TInt dataSet = 0;
|
sl@0
|
82 |
const TDesC& section = ConfigSection();
|
sl@0
|
83 |
TInt err = GetIntFromConfig(section, _L("DataSet"), dataSet);
|
sl@0
|
84 |
if(err < 0 || dataSet < 1 || dataSet > 2)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
ERR_PRINTF1(_L("Failed to read mandatory setting (DataSet) from testexecute config file."));
|
sl@0
|
87 |
User::Leave(KErrNotFound);
|
sl@0
|
88 |
}
|
sl@0
|
89 |
if (dataSet == 1)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
aEventUid = KTestEventUid1;
|
sl@0
|
92 |
aEventDesctiption.Set(KTestEventDesc1);
|
sl@0
|
93 |
}
|
sl@0
|
94 |
else if (dataSet == 2)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
aEventUid = KTestEventUid2;
|
sl@0
|
97 |
aEventDesctiption.Set(KTestEventDesc2);
|
sl@0
|
98 |
}
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
|
sl@0
|
102 |
/**
|
sl@0
|
103 |
Adds test entry to the log engine
|
sl@0
|
104 |
*/
|
sl@0
|
105 |
void CBackupRestoreStepBase::TestAddEventTypeL()
|
sl@0
|
106 |
{
|
sl@0
|
107 |
INFO_PRINTF1(_L("Add test entry to log engine\n"));
|
sl@0
|
108 |
|
sl@0
|
109 |
TUid eventUid;
|
sl@0
|
110 |
TPtrC eventDescription;
|
sl@0
|
111 |
GetDataFromConfigL(eventUid, eventDescription);
|
sl@0
|
112 |
|
sl@0
|
113 |
CLogEventType *type = CLogEventType::NewL();
|
sl@0
|
114 |
CleanupStack::PushL(type);
|
sl@0
|
115 |
|
sl@0
|
116 |
type->SetUid(eventUid);
|
sl@0
|
117 |
type->SetDescription(eventDescription);
|
sl@0
|
118 |
type->SetLoggingEnabled(ETrue);
|
sl@0
|
119 |
|
sl@0
|
120 |
iActive->Start();
|
sl@0
|
121 |
iClient->AddEventType(*type, iActive->iStatus);
|
sl@0
|
122 |
CActiveScheduler::Start();
|
sl@0
|
123 |
TESTL((iActive->iStatus == KErrNone)||(iActive->iStatus == KErrAlreadyExists));
|
sl@0
|
124 |
|
sl@0
|
125 |
CleanupStack::PopAndDestroy(type);
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
/**
|
sl@0
|
129 |
Checks whether the test entry added by TestAddEventTypeL exists or not
|
sl@0
|
130 |
*/
|
sl@0
|
131 |
void CBackupRestoreStepBase::TestGetEventTypeL(TInt aExpectedError)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
INFO_PRINTF1(_L("Make sure test entry is retrieved successfully from log engine\n"));
|
sl@0
|
134 |
|
sl@0
|
135 |
TUid eventUid;
|
sl@0
|
136 |
TPtrC eventDescription;
|
sl@0
|
137 |
GetDataFromConfigL(eventUid, eventDescription);
|
sl@0
|
138 |
|
sl@0
|
139 |
CLogEventType *type = CLogEventType::NewL();
|
sl@0
|
140 |
CleanupStack::PushL(type);
|
sl@0
|
141 |
|
sl@0
|
142 |
type->SetUid(eventUid);
|
sl@0
|
143 |
|
sl@0
|
144 |
iActive->Start();
|
sl@0
|
145 |
iClient->GetEventType(*type, iActive->iStatus);
|
sl@0
|
146 |
CActiveScheduler::Start();
|
sl@0
|
147 |
TEST_CHECKL(iActive->iStatus.Int(), aExpectedError, _L("Error retrieving log event"));
|
sl@0
|
148 |
|
sl@0
|
149 |
if(aExpectedError == KErrNone)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
TEST_CHECKL(type->Uid().iUid, eventUid.iUid, _L("UID retrieved from log event does not match"));
|
sl@0
|
152 |
TEST_CHECKL(type->Description().Compare(eventDescription), 0, _L("Description retrieved from log event does not match"));
|
sl@0
|
153 |
TEST_CHECKL(type->LoggingEnabled(), ETrue, _L("Logging enabled value retreived from log event does not match"));
|
sl@0
|
154 |
}
|
sl@0
|
155 |
CleanupStack::PopAndDestroy(type);
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
159 |
////////////// CBackupRestoreInitializeStep ////////////////////////////////////////////////////////////////////
|
sl@0
|
160 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
161 |
|
sl@0
|
162 |
CBackupRestoreInitializeStep::~CBackupRestoreInitializeStep()
|
sl@0
|
163 |
{
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
CBackupRestoreInitializeStep::CBackupRestoreInitializeStep()
|
sl@0
|
167 |
{
|
sl@0
|
168 |
SetTestStepName(KBackupRestoreInitializeStep);
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
/**
|
sl@0
|
172 |
Override of base class pure virtual
|
sl@0
|
173 |
Adds an entry to the log engine then tests that it was added successfully
|
sl@0
|
174 |
*/
|
sl@0
|
175 |
TVerdict CBackupRestoreInitializeStep::doTestStepL()
|
sl@0
|
176 |
{
|
sl@0
|
177 |
TestAddEventTypeL();
|
sl@0
|
178 |
|
sl@0
|
179 |
TestGetEventTypeL(KErrNone);
|
sl@0
|
180 |
|
sl@0
|
181 |
return TestStepResult();
|
sl@0
|
182 |
}
|
sl@0
|
183 |
|
sl@0
|
184 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
185 |
////////////// CBackupRestoreVerifyStep ////////////////////////////////////////////////////////////////////////
|
sl@0
|
186 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
187 |
|
sl@0
|
188 |
CBackupRestoreVerifyStep::~CBackupRestoreVerifyStep()
|
sl@0
|
189 |
{
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
CBackupRestoreVerifyStep::CBackupRestoreVerifyStep()
|
sl@0
|
193 |
{
|
sl@0
|
194 |
SetTestStepName(KBackupRestoreVerifyStep);
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@0
|
197 |
/**
|
sl@0
|
198 |
Override of base class pure virtual
|
sl@0
|
199 |
Tests that entry added in CBackupRestoreInitializeStep exists
|
sl@0
|
200 |
*/
|
sl@0
|
201 |
TVerdict CBackupRestoreVerifyStep::doTestStepL()
|
sl@0
|
202 |
{
|
sl@0
|
203 |
TestGetEventTypeL(KErrNone);
|
sl@0
|
204 |
|
sl@0
|
205 |
return TestStepResult();
|
sl@0
|
206 |
}
|
sl@0
|
207 |
|
sl@0
|
208 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
209 |
////////////// CBackupRestoreVerifyStep2 ///////////////////////////////////////////////////////////////////////
|
sl@0
|
210 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
211 |
|
sl@0
|
212 |
CBackupRestoreVerifyStep2::~CBackupRestoreVerifyStep2()
|
sl@0
|
213 |
{
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|
sl@0
|
216 |
CBackupRestoreVerifyStep2::CBackupRestoreVerifyStep2()
|
sl@0
|
217 |
{
|
sl@0
|
218 |
SetTestStepName(KBackupRestoreVerifyStep2);
|
sl@0
|
219 |
}
|
sl@0
|
220 |
|
sl@0
|
221 |
/**
|
sl@0
|
222 |
Override of base class pure virtual.
|
sl@0
|
223 |
Tests that the entry added after the backup but before the restore operation - that entry
|
sl@0
|
224 |
does not exist anymore.
|
sl@0
|
225 |
*/
|
sl@0
|
226 |
TVerdict CBackupRestoreVerifyStep2::doTestStepL()
|
sl@0
|
227 |
{
|
sl@0
|
228 |
TestGetEventTypeL(KErrNotFound);
|
sl@0
|
229 |
|
sl@0
|
230 |
return TestStepResult();
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
234 |
////////////// CStopLogServerStep //////////////////////////////////////////////////////////////////////////////
|
sl@0
|
235 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
236 |
|
sl@0
|
237 |
CStopLogServerStep::~CStopLogServerStep()
|
sl@0
|
238 |
{
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
CStopLogServerStep::CStopLogServerStep()
|
sl@0
|
242 |
{
|
sl@0
|
243 |
SetTestStepName(KStopLogServerStep);
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
/**
|
sl@0
|
247 |
Override of base class pure virtual
|
sl@0
|
248 |
Causes the the log engine server to exit
|
sl@0
|
249 |
*/
|
sl@0
|
250 |
TVerdict CStopLogServerStep::doTestStepL()
|
sl@0
|
251 |
{
|
sl@0
|
252 |
TInt err;
|
sl@0
|
253 |
//making the server transient only works on UDEB builds
|
sl@0
|
254 |
#ifdef _DEBUG
|
sl@0
|
255 |
INFO_PRINTF1(_L("Stopping the log engine server\n"));
|
sl@0
|
256 |
TInt error = iLogServ.Connect();
|
sl@0
|
257 |
// Is the server running?
|
sl@0
|
258 |
if (error != KErrNotFound && error != KErrNone)
|
sl@0
|
259 |
{
|
sl@0
|
260 |
INFO_PRINTF1(_L("Error connecting to log engine server\n"));
|
sl@0
|
261 |
User::Leave(error);
|
sl@0
|
262 |
}
|
sl@0
|
263 |
|
sl@0
|
264 |
// Make the server transient
|
sl@0
|
265 |
TInt p0=1;
|
sl@0
|
266 |
TIpcArgs ipcArgs(p0);
|
sl@0
|
267 |
User::LeaveIfError(iLogServ.Send(ELogMakeTransient,ipcArgs));
|
sl@0
|
268 |
|
sl@0
|
269 |
iLogServ.Close();
|
sl@0
|
270 |
User::After(6 * 1000000); // Enough time for the server to exit
|
sl@0
|
271 |
|
sl@0
|
272 |
#else
|
sl@0
|
273 |
//"ELogMakeTransient" IPC message is compiled in _DEUG mode only.
|
sl@0
|
274 |
//The logengine server could hold the database, then deleting its file will return an error
|
sl@0
|
275 |
//We force the killing of Logengine server here.
|
sl@0
|
276 |
// Find process and Kill
|
sl@0
|
277 |
// Note: this needs CAPABILITY PowerMgmt
|
sl@0
|
278 |
INFO_PRINTF1(_L("Killing the log engine server...\n"));
|
sl@0
|
279 |
TFindProcess findProcess(KLogEngineServerName);
|
sl@0
|
280 |
TFullName result;
|
sl@0
|
281 |
err = findProcess.Next(result);
|
sl@0
|
282 |
if (err == KErrNone)
|
sl@0
|
283 |
{
|
sl@0
|
284 |
RProcess server;
|
sl@0
|
285 |
User::LeaveIfError( server.Open(findProcess, EOwnerProcess) );
|
sl@0
|
286 |
server.Kill(0);
|
sl@0
|
287 |
INFO_PRINTF1(_L("Logengine server killed...\n"));
|
sl@0
|
288 |
User::After(6000000);
|
sl@0
|
289 |
}
|
sl@0
|
290 |
else
|
sl@0
|
291 |
{
|
sl@0
|
292 |
INFO_PRINTF1(_L("Unable to find the process linked to Logengine server.\n"));
|
sl@0
|
293 |
}
|
sl@0
|
294 |
|
sl@0
|
295 |
#endif//_DEBUG
|
sl@0
|
296 |
|
sl@0
|
297 |
RFs fs;
|
sl@0
|
298 |
CleanupClosePushL(fs);
|
sl@0
|
299 |
err = fs.Connect();
|
sl@0
|
300 |
TEST_CHECKL(err, KErrNone, _L("RFs::Connect() failed"));
|
sl@0
|
301 |
INFO_PRINTF1(_L("Deleting log engine database...\n"));
|
sl@0
|
302 |
err = fs.Delete(KLogDatabaseName);
|
sl@0
|
303 |
if(err != KErrNone)
|
sl@0
|
304 |
{
|
sl@0
|
305 |
INFO_PRINTF2(_L("Unable to delete log engine database, err=%d.\n"), err);
|
sl@0
|
306 |
}
|
sl@0
|
307 |
INFO_PRINTF1(_L("Log engine database deleted...\n"));
|
sl@0
|
308 |
CleanupStack::PopAndDestroy(&fs);
|
sl@0
|
309 |
|
sl@0
|
310 |
return EPass;
|
sl@0
|
311 |
}
|
sl@0
|
312 |
|
sl@0
|
313 |
#endif //__BACKUPRESTORESTEP_H__
|
sl@0
|
314 |
|