os/persistentdata/loggingservices/eventlogger/test/tef/teflogengbur/src/backuprestorestep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Implementation of test execute steps for log engine backup and restore
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @internalComponent
    21 */
    22 #ifndef __BACKUPRESTORESTEP_H__
    23 #define __BACKUPRESTORESTEP_H__
    24 
    25 #include "backuprestorestep.h"
    26 #include "LogCliServShared.h"
    27 #include "LogServShared.h"
    28 
    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");
    34 #ifndef _DEBUG
    35 _LIT(KLogEngineServerName,"LogServ*");
    36 #endif
    37 
    38 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    39 //////////////  CBackupRestoreStepBase  //////////////////////////////////////////////////////////////////////////
    40 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    41 
    42 /**
    43 Override of base class virtual
    44 Initializes members needed for test
    45 */
    46 TVerdict CBackupRestoreStepBase::doTestStepPreambleL()
    47 	{
    48 	__UHEAP_MARK;
    49 	
    50 	iScheduler = new(ELeave)CActiveScheduler();
    51 	CActiveScheduler::Install(iScheduler);
    52 	
    53 	User::LeaveIfError(iFs.Connect());
    54 	
    55 	iClient = CLogClient::NewL(iFs);
    56 
    57 	iActive = new(ELeave) CTestActive();
    58 
    59 	return EPass;
    60 	}
    61 
    62 CBackupRestoreStepBase::~CBackupRestoreStepBase()
    63 	{
    64 	delete iActive;
    65 	iActive = NULL;
    66 	
    67 	delete iClient;
    68 	iClient = NULL;
    69 	
    70 	iFs.Close();
    71 	
    72 	CActiveScheduler::Install(NULL);
    73 	delete iScheduler;
    74 	iScheduler = NULL;
    75 	
    76 	__UHEAP_MARKEND;
    77 	}
    78 
    79 void CBackupRestoreStepBase::GetDataFromConfigL(TUid& aEventUid, TPtrC& aEventDesctiption)
    80 	{
    81 	TInt dataSet = 0;
    82 	const TDesC& section = ConfigSection();
    83 	TInt err = GetIntFromConfig(section, _L("DataSet"), dataSet);
    84 	if(err < 0 || dataSet < 1 || dataSet > 2)
    85 		{
    86 		ERR_PRINTF1(_L("Failed to read mandatory setting (DataSet) from testexecute config file."));
    87 		User::Leave(KErrNotFound);
    88 		}
    89 	if (dataSet == 1)
    90 		{
    91 		aEventUid = KTestEventUid1;
    92 		aEventDesctiption.Set(KTestEventDesc1);
    93 		}
    94 	else if (dataSet == 2)
    95 		{
    96 		aEventUid = KTestEventUid2;
    97 		aEventDesctiption.Set(KTestEventDesc2);
    98 		}
    99 	}
   100 	
   101 
   102 /**
   103 Adds test entry to the log engine
   104 */
   105 void CBackupRestoreStepBase::TestAddEventTypeL()
   106 	{
   107 	INFO_PRINTF1(_L("Add test entry to log engine\n"));
   108 
   109 	TUid eventUid;
   110 	TPtrC eventDescription;
   111 	GetDataFromConfigL(eventUid, eventDescription);
   112 	
   113 	CLogEventType *type = CLogEventType::NewL();
   114 	CleanupStack::PushL(type);
   115 
   116 	type->SetUid(eventUid);
   117 	type->SetDescription(eventDescription);
   118 	type->SetLoggingEnabled(ETrue);
   119 
   120 	iActive->Start();
   121 	iClient->AddEventType(*type, iActive->iStatus);
   122 	CActiveScheduler::Start();
   123 	TESTL((iActive->iStatus == KErrNone)||(iActive->iStatus == KErrAlreadyExists));
   124 
   125 	CleanupStack::PopAndDestroy(type);
   126 	}
   127 
   128 /**
   129 Checks whether the test entry added by TestAddEventTypeL exists or not
   130 */
   131 void CBackupRestoreStepBase::TestGetEventTypeL(TInt aExpectedError)
   132 	{
   133 	INFO_PRINTF1(_L("Make sure test entry is retrieved successfully from log engine\n"));
   134 	
   135 	TUid eventUid;
   136 	TPtrC eventDescription;
   137 	GetDataFromConfigL(eventUid, eventDescription);
   138 	
   139 	CLogEventType *type = CLogEventType::NewL();
   140 	CleanupStack::PushL(type);
   141 
   142 	type->SetUid(eventUid);
   143 
   144 	iActive->Start();
   145 	iClient->GetEventType(*type, iActive->iStatus);
   146 	CActiveScheduler::Start();
   147 	TEST_CHECKL(iActive->iStatus.Int(), aExpectedError, _L("Error retrieving log event"));
   148 
   149 	if(aExpectedError == KErrNone)
   150 		{
   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"));
   154 		}
   155 	CleanupStack::PopAndDestroy(type);
   156 	}
   157 
   158 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   159 //////////////  CBackupRestoreInitializeStep  ////////////////////////////////////////////////////////////////////
   160 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   161 
   162 CBackupRestoreInitializeStep::~CBackupRestoreInitializeStep()
   163 	{
   164 	}
   165 
   166 CBackupRestoreInitializeStep::CBackupRestoreInitializeStep()
   167 	{
   168 	SetTestStepName(KBackupRestoreInitializeStep);
   169 	}
   170 
   171 /**
   172 Override of base class pure virtual
   173 Adds an entry to the log engine then tests that it was added successfully
   174 */
   175 TVerdict CBackupRestoreInitializeStep::doTestStepL()
   176 	{
   177 	TestAddEventTypeL();
   178 	
   179 	TestGetEventTypeL(KErrNone);
   180 
   181 	return TestStepResult();
   182 	}
   183 
   184 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   185 //////////////  CBackupRestoreVerifyStep  ////////////////////////////////////////////////////////////////////////
   186 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   187 
   188 CBackupRestoreVerifyStep::~CBackupRestoreVerifyStep()
   189 	{
   190 	}
   191 
   192 CBackupRestoreVerifyStep::CBackupRestoreVerifyStep()
   193 	{
   194 	SetTestStepName(KBackupRestoreVerifyStep);
   195 	}
   196 
   197 /**
   198 Override of base class pure virtual
   199 Tests that entry added in CBackupRestoreInitializeStep exists
   200 */
   201 TVerdict CBackupRestoreVerifyStep::doTestStepL()
   202 	{
   203 	TestGetEventTypeL(KErrNone);
   204 
   205 	return TestStepResult();
   206 	}
   207 
   208 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   209 //////////////  CBackupRestoreVerifyStep2  ///////////////////////////////////////////////////////////////////////
   210 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   211 
   212 CBackupRestoreVerifyStep2::~CBackupRestoreVerifyStep2()
   213 	{
   214 	}
   215 
   216 CBackupRestoreVerifyStep2::CBackupRestoreVerifyStep2()
   217 	{
   218 	SetTestStepName(KBackupRestoreVerifyStep2);
   219 	}
   220 
   221 /**
   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.
   225 */
   226 TVerdict CBackupRestoreVerifyStep2::doTestStepL()
   227 	{
   228 	TestGetEventTypeL(KErrNotFound);
   229 
   230 	return TestStepResult();
   231 	}
   232 
   233 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   234 //////////////  CStopLogServerStep  //////////////////////////////////////////////////////////////////////////////
   235 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   236 
   237 CStopLogServerStep::~CStopLogServerStep()
   238 	{
   239 	}
   240 
   241 CStopLogServerStep::CStopLogServerStep()
   242 	{
   243 	SetTestStepName(KStopLogServerStep);
   244 	}
   245 
   246 /**
   247 Override of base class pure virtual
   248 Causes the the log engine server to exit
   249 */
   250 TVerdict CStopLogServerStep::doTestStepL()
   251 	{
   252 	TInt err;
   253 	//making the server transient only works on UDEB builds
   254 #ifdef _DEBUG
   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)
   259 		{
   260 		INFO_PRINTF1(_L("Error connecting to log engine server\n"));
   261 		User::Leave(error);
   262 		}
   263 
   264 	// Make the server transient
   265 	TInt p0=1;
   266 	TIpcArgs  ipcArgs(p0);
   267 	User::LeaveIfError(iLogServ.Send(ELogMakeTransient,ipcArgs));
   268 
   269 	iLogServ.Close();
   270 	User::After(6 * 1000000); // Enough time for the server to exit
   271 		
   272 #else
   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);
   280 	TFullName result;
   281 	err = findProcess.Next(result);
   282     if (err == KErrNone)
   283     	{
   284     	RProcess server;
   285     	User::LeaveIfError( server.Open(findProcess, EOwnerProcess) );
   286     	server.Kill(0);		
   287     	INFO_PRINTF1(_L("Logengine server killed...\n"));
   288     	User::After(6000000);
   289     	}
   290     else
   291     	{
   292     	INFO_PRINTF1(_L("Unable to find the process linked to Logengine server.\n"));
   293     	}
   294     
   295 #endif//_DEBUG
   296     
   297     RFs fs;
   298     CleanupClosePushL(fs);
   299     err = fs.Connect();
   300 	TEST_CHECKL(err, KErrNone, _L("RFs::Connect() failed"));
   301 	INFO_PRINTF1(_L("Deleting log engine database...\n"));
   302 	err = fs.Delete(KLogDatabaseName);
   303 	if(err != KErrNone)
   304 		{
   305 		INFO_PRINTF2(_L("Unable to delete log engine database, err=%d.\n"), err);
   306 		}
   307 	INFO_PRINTF1(_L("Log engine database deleted...\n"));
   308 	CleanupStack::PopAndDestroy(&fs);
   309 	    
   310 	return EPass;
   311 	}
   312 
   313 #endif //__BACKUPRESTORESTEP_H__
   314