os/persistentdata/loggingservices/eventlogger/test/tef/teflogengbur/src/backuprestorestep.cpp
Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Implementation of test execute steps for log engine backup and restore
22 #ifndef __BACKUPRESTORESTEP_H__
23 #define __BACKUPRESTORESTEP_H__
25 #include "backuprestorestep.h"
26 #include "LogCliServShared.h"
27 #include "LogServShared.h"
29 const TUid KTestEventUid1 = {0x10005393};
30 _LIT(KTestEventDesc1, "Event Type Description");
31 const TUid KTestEventUid2 = {0x10005394};
32 _LIT(KTestEventDesc2, "Second Event Type Description");
33 _LIT(KLogDatabaseName,"c:\\private\\101f401d\\Logdbu.dat");
35 _LIT(KLogEngineServerName,"LogServ*");
38 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
39 ////////////// CBackupRestoreStepBase //////////////////////////////////////////////////////////////////////////
40 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
43 Override of base class virtual
44 Initializes members needed for test
46 TVerdict CBackupRestoreStepBase::doTestStepPreambleL()
50 iScheduler = new(ELeave)CActiveScheduler();
51 CActiveScheduler::Install(iScheduler);
53 User::LeaveIfError(iFs.Connect());
55 iClient = CLogClient::NewL(iFs);
57 iActive = new(ELeave) CTestActive();
62 CBackupRestoreStepBase::~CBackupRestoreStepBase()
72 CActiveScheduler::Install(NULL);
79 void CBackupRestoreStepBase::GetDataFromConfigL(TUid& aEventUid, TPtrC& aEventDesctiption)
82 const TDesC& section = ConfigSection();
83 TInt err = GetIntFromConfig(section, _L("DataSet"), dataSet);
84 if(err < 0 || dataSet < 1 || dataSet > 2)
86 ERR_PRINTF1(_L("Failed to read mandatory setting (DataSet) from testexecute config file."));
87 User::Leave(KErrNotFound);
91 aEventUid = KTestEventUid1;
92 aEventDesctiption.Set(KTestEventDesc1);
94 else if (dataSet == 2)
96 aEventUid = KTestEventUid2;
97 aEventDesctiption.Set(KTestEventDesc2);
103 Adds test entry to the log engine
105 void CBackupRestoreStepBase::TestAddEventTypeL()
107 INFO_PRINTF1(_L("Add test entry to log engine\n"));
110 TPtrC eventDescription;
111 GetDataFromConfigL(eventUid, eventDescription);
113 CLogEventType *type = CLogEventType::NewL();
114 CleanupStack::PushL(type);
116 type->SetUid(eventUid);
117 type->SetDescription(eventDescription);
118 type->SetLoggingEnabled(ETrue);
121 iClient->AddEventType(*type, iActive->iStatus);
122 CActiveScheduler::Start();
123 TESTL((iActive->iStatus == KErrNone)||(iActive->iStatus == KErrAlreadyExists));
125 CleanupStack::PopAndDestroy(type);
129 Checks whether the test entry added by TestAddEventTypeL exists or not
131 void CBackupRestoreStepBase::TestGetEventTypeL(TInt aExpectedError)
133 INFO_PRINTF1(_L("Make sure test entry is retrieved successfully from log engine\n"));
136 TPtrC eventDescription;
137 GetDataFromConfigL(eventUid, eventDescription);
139 CLogEventType *type = CLogEventType::NewL();
140 CleanupStack::PushL(type);
142 type->SetUid(eventUid);
145 iClient->GetEventType(*type, iActive->iStatus);
146 CActiveScheduler::Start();
147 TEST_CHECKL(iActive->iStatus.Int(), aExpectedError, _L("Error retrieving log event"));
149 if(aExpectedError == KErrNone)
151 TEST_CHECKL(type->Uid().iUid, eventUid.iUid, _L("UID retrieved from log event does not match"));
152 TEST_CHECKL(type->Description().Compare(eventDescription), 0, _L("Description retrieved from log event does not match"));
153 TEST_CHECKL(type->LoggingEnabled(), ETrue, _L("Logging enabled value retreived from log event does not match"));
155 CleanupStack::PopAndDestroy(type);
158 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
159 ////////////// CBackupRestoreInitializeStep ////////////////////////////////////////////////////////////////////
160 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
162 CBackupRestoreInitializeStep::~CBackupRestoreInitializeStep()
166 CBackupRestoreInitializeStep::CBackupRestoreInitializeStep()
168 SetTestStepName(KBackupRestoreInitializeStep);
172 Override of base class pure virtual
173 Adds an entry to the log engine then tests that it was added successfully
175 TVerdict CBackupRestoreInitializeStep::doTestStepL()
179 TestGetEventTypeL(KErrNone);
181 return TestStepResult();
184 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
185 ////////////// CBackupRestoreVerifyStep ////////////////////////////////////////////////////////////////////////
186 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
188 CBackupRestoreVerifyStep::~CBackupRestoreVerifyStep()
192 CBackupRestoreVerifyStep::CBackupRestoreVerifyStep()
194 SetTestStepName(KBackupRestoreVerifyStep);
198 Override of base class pure virtual
199 Tests that entry added in CBackupRestoreInitializeStep exists
201 TVerdict CBackupRestoreVerifyStep::doTestStepL()
203 TestGetEventTypeL(KErrNone);
205 return TestStepResult();
208 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
209 ////////////// CBackupRestoreVerifyStep2 ///////////////////////////////////////////////////////////////////////
210 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
212 CBackupRestoreVerifyStep2::~CBackupRestoreVerifyStep2()
216 CBackupRestoreVerifyStep2::CBackupRestoreVerifyStep2()
218 SetTestStepName(KBackupRestoreVerifyStep2);
222 Override of base class pure virtual.
223 Tests that the entry added after the backup but before the restore operation - that entry
224 does not exist anymore.
226 TVerdict CBackupRestoreVerifyStep2::doTestStepL()
228 TestGetEventTypeL(KErrNotFound);
230 return TestStepResult();
233 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
234 ////////////// CStopLogServerStep //////////////////////////////////////////////////////////////////////////////
235 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
237 CStopLogServerStep::~CStopLogServerStep()
241 CStopLogServerStep::CStopLogServerStep()
243 SetTestStepName(KStopLogServerStep);
247 Override of base class pure virtual
248 Causes the the log engine server to exit
250 TVerdict CStopLogServerStep::doTestStepL()
253 //making the server transient only works on UDEB builds
255 INFO_PRINTF1(_L("Stopping the log engine server\n"));
256 TInt error = iLogServ.Connect();
257 // Is the server running?
258 if (error != KErrNotFound && error != KErrNone)
260 INFO_PRINTF1(_L("Error connecting to log engine server\n"));
264 // Make the server transient
266 TIpcArgs ipcArgs(p0);
267 User::LeaveIfError(iLogServ.Send(ELogMakeTransient,ipcArgs));
270 User::After(6 * 1000000); // Enough time for the server to exit
273 //"ELogMakeTransient" IPC message is compiled in _DEUG mode only.
274 //The logengine server could hold the database, then deleting its file will return an error
275 //We force the killing of Logengine server here.
276 // Find process and Kill
277 // Note: this needs CAPABILITY PowerMgmt
278 INFO_PRINTF1(_L("Killing the log engine server...\n"));
279 TFindProcess findProcess(KLogEngineServerName);
281 err = findProcess.Next(result);
285 User::LeaveIfError( server.Open(findProcess, EOwnerProcess) );
287 INFO_PRINTF1(_L("Logengine server killed...\n"));
288 User::After(6000000);
292 INFO_PRINTF1(_L("Unable to find the process linked to Logengine server.\n"));
298 CleanupClosePushL(fs);
300 TEST_CHECKL(err, KErrNone, _L("RFs::Connect() failed"));
301 INFO_PRINTF1(_L("Deleting log engine database...\n"));
302 err = fs.Delete(KLogDatabaseName);
305 INFO_PRINTF2(_L("Unable to delete log engine database, err=%d.\n"), err);
307 INFO_PRINTF1(_L("Log engine database deleted...\n"));
308 CleanupStack::PopAndDestroy(&fs);
313 #endif //__BACKUPRESTORESTEP_H__