sl@0: // Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include "t_logutil2.h" sl@0: sl@0: //Define "TheTest" variable used in the test cpp files sl@0: extern RTest TheTest; sl@0: sl@0: _LIT(KHelperExeName, "t_LogHiCapHelper.exe"); sl@0: sl@0: //====================================================================================================== sl@0: sl@0: #ifdef LOGGING_ENABLED sl@0: sl@0: void Log::New() sl@0: { sl@0: _LIT(KNewLogText, "===== NEW LOG ====="); sl@0: // sl@0: RFileLogger logger; sl@0: TInt ret=logger.Connect(); sl@0: if (ret==KErrNone) sl@0: { sl@0: logger.CreateLog(KLogFolder, KLogFileName, EFileLoggingModeOverwrite); sl@0: logger.Write(KNewLogText); sl@0: } sl@0: logger.Close(); sl@0: } sl@0: sl@0: void Log::Write(const TDesC& aText) sl@0: { sl@0: PruneLogFile(); sl@0: sl@0: RFileLogger logger; sl@0: TInt ret=logger.Connect(); sl@0: if (ret==KErrNone) sl@0: { sl@0: logger.SetDateAndTime(EFalse,EFalse); sl@0: logger.CreateLog(KLogFolder, KLogFileName,EFileLoggingModeAppend); sl@0: TBuf buf; sl@0: TTime now; sl@0: now.HomeTime(); sl@0: TDateTime dateTime; sl@0: dateTime = now.DateTime(); sl@0: buf.Format(KTimeFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); sl@0: buf.AppendFormat(KTextFormat,&aText); sl@0: sl@0: logger.Write(buf); sl@0: } sl@0: sl@0: logger.Close(); sl@0: } sl@0: sl@0: void Log::WriteFormat(TRefByValue aFmt, ...) sl@0: { sl@0: VA_LIST list; sl@0: VA_START(list,aFmt); sl@0: sl@0: PruneLogFile(); sl@0: sl@0: TBuf<2*KLogEngLogBufferSize> buf; sl@0: buf.SetMax(); sl@0: buf.FillZ(); sl@0: TTime now; sl@0: now.HomeTime(); sl@0: TDateTime dateTime; sl@0: dateTime = now.DateTime(); sl@0: buf.Format(KTimeFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); sl@0: buf.AppendFormatList(aFmt, list ); sl@0: sl@0: RFileLogger logger; sl@0: TInt ret=logger.Connect(); sl@0: if (ret==KErrNone) sl@0: { sl@0: logger.SetDateAndTime(EFalse,EFalse); sl@0: logger.CreateLog(KLogFolder, KLogFileName,EFileLoggingModeAppend); sl@0: logger.Write(buf); sl@0: } sl@0: sl@0: logger.Close(); sl@0: } sl@0: sl@0: void Log::PruneLogFile() sl@0: { sl@0: const TInt KMaxLogSize = 1024 * 500; sl@0: _LIT(KDriveLetter, "C:\\Logs\\"); sl@0: // sl@0: TFileName fileName(KDriveLetter); sl@0: fileName.Append(KLogFolder); sl@0: fileName.Append(KLogFileName); sl@0: // sl@0: RFs fsSession; sl@0: if (fsSession.Connect() == KErrNone) sl@0: { sl@0: TEntry entry; sl@0: if (fsSession.Entry(fileName, entry) == KErrNone) sl@0: { sl@0: // Check size and delete if its too big sl@0: if (entry.iSize >= KMaxLogSize) sl@0: fsSession.Delete(fileName); // ignore error sl@0: } sl@0: } sl@0: fsSession.Close(); sl@0: } sl@0: sl@0: #endif sl@0: sl@0: // Globals sl@0: GLDEF_D CTrapCleanup* theCleanup; sl@0: GLDEF_D CActiveScheduler *testScheduler; sl@0: GLDEF_D RFs theFs; sl@0: GLDEF_D TFileName theLogName; sl@0: GLDEF_D RFile theLog; sl@0: GLDEF_D RLogTestSession theLogServ; sl@0: sl@0: //********************************** sl@0: // CTestActive sl@0: //********************************** sl@0: sl@0: CTestActive::CTestActive(TInt aPriority) sl@0: : CActive(aPriority) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: iDelayTime=0; sl@0: } sl@0: sl@0: CTestActive::~CTestActive() sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: void CTestActive::DoCancel() sl@0: { sl@0: TRequestStatus* s=&iStatus; sl@0: User::RequestComplete(s, KErrNone); sl@0: } sl@0: sl@0: void CTestActive::StartL() sl@0: { sl@0: iDelayCompletion=EFalse; sl@0: iDelayTime=0; sl@0: iStatus = KRequestPending; sl@0: SetActive(); sl@0: } sl@0: sl@0: void CTestActive::StartL(TInt aDelay) sl@0: { sl@0: iDelayCompletion=ETrue; sl@0: iDelayTime=aDelay; sl@0: iStatus = KRequestPending; sl@0: SetActive(); sl@0: } sl@0: sl@0: void CTestActive::RunL() sl@0: { sl@0: if(iDelayCompletion && iDelayTime) sl@0: { sl@0: // Wait for events in other threads to have a go.... sl@0: User::After(iDelayTime); sl@0: iDelayTime=0; sl@0: iStoredStatus=iStatus; sl@0: SetActive(); sl@0: TRequestStatus* s=&iStatus; sl@0: User::RequestComplete(s, KErrNone); sl@0: } sl@0: else sl@0: { sl@0: if(iDelayCompletion) sl@0: iStatus=iStoredStatus; sl@0: sl@0: LOGTEXT("CTestActive::RunL() - Stopping the scheduler"); sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: } sl@0: sl@0: //********************************** sl@0: // CTestTimer sl@0: //********************************** sl@0: sl@0: CTestTimer::CTestTimer() sl@0: : CTimer(EPriorityLow) sl@0: {} sl@0: sl@0: void CTestTimer::RunL() sl@0: { sl@0: LOGTEXT("CTestTimer::RunL() - Stopping the scheduler"); sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: CTestTimer* CTestTimer::NewL() sl@0: { sl@0: CTestTimer* self = new(ELeave) CTestTimer(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); // CTimer sl@0: CActiveScheduler::Add(self); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: //********************************** sl@0: // TestUtils sl@0: //********************************** sl@0: sl@0: void TestUtils::Initialize(const TDesC& aName) sl@0: { sl@0: TheTest.Title(); sl@0: TheTest.Printf(_L("%S\r\n"), &aName); sl@0: User::RenameThread(aName); sl@0: } sl@0: sl@0: TBool TestUtils::FileExists(const TDesC& aFile) sl@0: { sl@0: TEntry entry; sl@0: return theFs.Entry(aFile, entry) == KErrNone; sl@0: } sl@0: sl@0: //Loads t_loghihelper process and passes for execution to t_loghihelper "aCommandLineArg" command line. sl@0: //t_loghihelper will run, execute the command and die, returning the result of the command execution. sl@0: //TestUtils::ExecuteRemoteL() will leave if error and return the result of the remote cmd execution to the caller. sl@0: TInt TestUtils::ExecuteRemoteL(const TDesC& aCommandLineArg) sl@0: { sl@0: RProcess process; sl@0: LEAVE_IF_ERROR(process.Create(KHelperExeName, aCommandLineArg)); sl@0: sl@0: TRequestStatus status; sl@0: process.Logon(status); sl@0: process.Resume(); sl@0: sl@0: User::WaitForRequest(status); sl@0: TInt exitReason = process.ExitReason(); sl@0: sl@0: process.Close(); sl@0: LEAVE_IF_ERROR(exitReason); sl@0: sl@0: return exitReason; sl@0: } sl@0: sl@0: //Runs t_loghihelper. t_loghihelper will execute the "delete LogEng database" command. sl@0: //The "delete LogEng database" is a complex operation. The request is sent via the backup server sl@0: //which will send a request to the LogEng server to release the LogEng database file locks and close the file. sl@0: //After that the database will be deleted. sl@0: //In the same call the LogEng server will restarted and the LogEng server will re-create the database during the sl@0: //server startup. sl@0: // sl@0: //If "aCloseBeforeDelete" flag is false, then the database wil be only deleted. sl@0: //The default value of "aCloseBeforeDelete" is true: the database will be closed, deleted and re-created. sl@0: //But some of the LogEng tests create a CBaBackupSessionWrapper object and call CloseFileL() with the logeng sl@0: //database name as a parameter. In this case, if another process, as t_loghicaphelper for example, attempts sl@0: //to call CloseFileL() with the same file name as a parameter, then the caller will get KErrServerBusy error. sl@0: //See how CBaBackupSessionWrapper::CloseFileL() is implemented on the server side. sl@0: void TestUtils::DeleteDatabaseL(TBool aCloseBeforeDelete) sl@0: { sl@0: _LIT(KCmdLine1, "-delete_db1"); sl@0: _LIT(KCmdLine2, "-delete_db2"); sl@0: (void)ExecuteRemoteL(aCloseBeforeDelete ? KCmdLine1 : KCmdLine2); sl@0: } sl@0: sl@0: //Runs t_loghihelper. t_loghihelper will check and return whether the LogEng database is open or not. sl@0: TBool TestUtils::IsDatabaseOpenL() sl@0: { sl@0: _LIT(KCmdLine, "-db_is_open"); sl@0: TInt result = ExecuteRemoteL(KCmdLine); sl@0: return result != 0; sl@0: } sl@0: sl@0: //Runs t_loghihelper. t_loghihelper will add an event type to the LogEng database. sl@0: void TestUtils::AddEventTypeL() sl@0: { sl@0: _LIT(KCmdLine, "-add_event_type"); sl@0: (void)ExecuteRemoteL(KCmdLine); sl@0: } sl@0: sl@0: //Runs t_loghihelper. t_loghihelper will add an event to the LogEng database. sl@0: TInt TestUtils::AddEventL() sl@0: { sl@0: _LIT(KCmdLine, "-add_event"); sl@0: return ExecuteRemoteL(KCmdLine); sl@0: } sl@0: sl@0: //Runs t_loghihelper. t_loghihelper will add events to the LogEng database. sl@0: void TestUtils::AddViewTestEventsL() sl@0: { sl@0: _LIT(KCmdLine, "-add_view_test_events"); sl@0: (void)ExecuteRemoteL(KCmdLine); sl@0: } sl@0: sl@0: //Runs t_loghihelper. t_loghihelper will return the size of the LogEng database. sl@0: TInt TestUtils::DatabaseSizeL() sl@0: { sl@0: _LIT(KCmdLine, "-db_size"); sl@0: return ExecuteRemoteL(KCmdLine); sl@0: } sl@0: sl@0: //Runs t_loghihelper. t_loghihelper will replace the LogEng database with a corrupted database (for testing purposes). sl@0: //The LogEng server will be stopped before that. The function can be used only in debug mode. sl@0: #ifdef _DEBUG sl@0: void TestUtils::CopyCorruptDbL() sl@0: { sl@0: sl@0: _LIT(KCmdLine, "-copy_corrupt"); sl@0: (void)ExecuteRemoteL(KCmdLine); sl@0: } sl@0: sl@0: //Runs t_loghihelper. t_loghihelper will replace the LogEng database with a corrupted database (for testing purposes). sl@0: //The LogEng server will be stopped before that. The function can be used only in debug mode. sl@0: void TestUtils::CopyCorruptDamagedDbL() sl@0: { sl@0: sl@0: _LIT(KCmdLine, "-copy_corrupt_damaged"); sl@0: (void)ExecuteRemoteL(KCmdLine); sl@0: } sl@0: sl@0: //Runs t_loghihelper. t_loghihelper will replace the LogEng database with an old format database sl@0: //(no SimId column, phone number length is different). The LogEng server will be stopped before that. sl@0: //The function can be used only in debug mode. sl@0: void TestUtils::CopyOldDbL() sl@0: { sl@0: _LIT(KCmdLine, "-copy_old"); sl@0: (void)ExecuteRemoteL(KCmdLine); sl@0: } sl@0: #else //_DEBUG sl@0: void TestUtils::CopyCorruptDbL() sl@0: { sl@0: TheTest.Printf(_L("TestUtils::CopyCorruptDbL() has a meaningfull implementation in debug builds only.\n")); sl@0: } sl@0: sl@0: void TestUtils::CopyCorruptDamagedDbL() sl@0: { sl@0: TheTest.Printf(_L("TestUtils::CopyCorruptDamagedDbL() has a meaningfull implementation in debug builds only.\n")); sl@0: } sl@0: sl@0: void TestUtils::CopyOldDbL() sl@0: { sl@0: TheTest.Printf(_L("TestUtils::CopyOldDbL() has a meaningfull implementation in debug builds only.\n")); sl@0: } sl@0: sl@0: #endif//_DEBUG sl@0: sl@0: //Runs t_loghihelper. t_loghihelper will re-create the LogEng database and check whether LogEng client can connect to the server. sl@0: void TestUtils::TestInvalidSchemaL() sl@0: { sl@0: _LIT(KCmdLine, "-invalid_schema"); sl@0: (void)ExecuteRemoteL(KCmdLine); sl@0: } sl@0: sl@0: //Runs t_loghihelper. t_loghihelper checks whether the phone number mathcing is enabled. sl@0: TBool TestUtils::MatchingEnabledL() sl@0: { sl@0: _LIT(KCmdLine, "-is_matching_enabled"); sl@0: return ExecuteRemoteL(KCmdLine) != 0; sl@0: } sl@0: sl@0: //Creates HBufC object and puts it on the cleanup stack. sl@0: //The buffer will be filled with (' ' + pos) characters, where pos is the character position in the buffer. sl@0: HBufC* TestUtils::CreateBufLC(TInt aLength) sl@0: { sl@0: HBufC* buf = HBufC::NewLC(aLength); sl@0: TPtr ptr = buf->Des(); sl@0: for(TInt pos=0;posDes(); sl@0: for(TInt pos=0;posAfter(aDelay); sl@0: sl@0: CTestActive* wait = new(ELeave)CTestActive; sl@0: CleanupStack::PushL(wait); sl@0: wait->StartL(); sl@0: sl@0: // Wait for key press sl@0: TheTest.Console()->Read(wait->iStatus); sl@0: CActiveScheduler::Start(); sl@0: sl@0: // If timer still active a key was pressed sl@0: TBool keyPressed = timer->IsActive(); sl@0: sl@0: if (keyPressed) sl@0: { sl@0: // Get the key pressed sl@0: aKeyCode = TheTest.Console()->KeyCode(); sl@0: sl@0: // Cancel timer sl@0: timer->Cancel(); sl@0: } sl@0: else sl@0: { sl@0: // Cancel wait for character sl@0: TheTest.Console()->ReadCancel(); sl@0: User::WaitForRequest(wait->iStatus); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2); // wait, timer sl@0: return keyPressed; sl@0: } sl@0: sl@0: //Used for LogEng server side heap failure testing. sl@0: #ifdef _DEBUG sl@0: void TestUtils::SetLogServHeapFailureL(RHeap::TAllocFail aType, TInt aRate) sl@0: { sl@0: //this function doesn't have any effect on UREL builds sl@0: //get rid of warnings in release builds sl@0: aType = aType; sl@0: aRate = aRate; sl@0: if (!theLogServ.Handle()) sl@0: LEAVE_IF_ERROR(theLogServ.Connect()); sl@0: sl@0: TIpcArgs ipcArgs(aType,aRate) ; sl@0: LEAVE_IF_ERROR(theLogServ.Send(ELogSetHeapFail, ipcArgs)); sl@0: } sl@0: #else sl@0: void TestUtils::SetLogServHeapFailureL(RHeap::TAllocFail, TInt) sl@0: { sl@0: } sl@0: #endif//_DEBUG sl@0: sl@0: //********************************** sl@0: // CLogViewChangeObserver sl@0: //********************************** sl@0: sl@0: CLogViewChangeObserver* CLogViewChangeObserver::NewLC() sl@0: { sl@0: CLogViewChangeObserver* self = new(ELeave) CLogViewChangeObserver(); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: CLogViewChangeObserver::~CLogViewChangeObserver() sl@0: { sl@0: Cancel(); sl@0: delete iChanges; sl@0: } sl@0: sl@0: CLogViewChangeObserver::CLogViewChangeObserver() sl@0: : CActive(EPriorityStandard) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: sl@0: CLogChangeDefinition* CLogViewChangeObserver::WaitForChangesLC(TStopType aType, TInt aCount) sl@0: { sl@0: __ASSERT_ALWAYS(!iSchedulerStarted, User::Invariant()); sl@0: Reset(); sl@0: // sl@0: iExpectedChangeCount = aCount; sl@0: iType = aType; sl@0: if (aType != EStopOnChanges) sl@0: SetActive(); sl@0: // sl@0: iSchedulerStarted = ETrue; sl@0: CActiveScheduler::Start(); sl@0: iSchedulerStarted = EFalse; sl@0: // sl@0: CLogChangeDefinition* ret = iChanges; sl@0: TEST(iChanges != NULL); sl@0: iChanges = NULL; sl@0: CleanupStack::PushL(ret); sl@0: return ret; sl@0: } sl@0: sl@0: CLogChangeDefinition* CLogViewChangeObserver::WaitForChangesLC(TCallBack aCallBack, TStopType aType, TInt aCount) sl@0: { sl@0: iHaveCallBack = ETrue; sl@0: iCallBack = aCallBack; sl@0: return WaitForChangesLC(aType, aCount); sl@0: } sl@0: sl@0: void CLogViewChangeObserver::HandleLogViewChangeEventAddedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount) sl@0: { sl@0: AddChangeL(ELogChangeTypeEventAdded, aId, aViewIndex); sl@0: if (aChangeIndex == aTotalChangeCount-1) sl@0: CheckForSchedulerStop(); sl@0: } sl@0: sl@0: void CLogViewChangeObserver::HandleLogViewChangeEventChangedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount) sl@0: { sl@0: AddChangeL(ELogChangeTypeEventChanged, aId, aViewIndex); sl@0: if (aChangeIndex == aTotalChangeCount-1) sl@0: CheckForSchedulerStop(); sl@0: } sl@0: sl@0: void CLogViewChangeObserver::HandleLogViewChangeEventDeletedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount) sl@0: { sl@0: AddChangeL(ELogChangeTypeEventDeleted, aId, aViewIndex); sl@0: if (aChangeIndex == aTotalChangeCount-1) sl@0: CheckForSchedulerStop(); sl@0: } sl@0: sl@0: void CLogViewChangeObserver::RunL() sl@0: { sl@0: __ASSERT_ALWAYS(iType == EStopOnRunL || iType == EStopOnBoth, User::Invariant()); sl@0: iHaveFinishedOperation = ETrue; sl@0: CheckForSchedulerStop(); sl@0: } sl@0: sl@0: void CLogViewChangeObserver::DoCancel() sl@0: { sl@0: TRequestStatus* s=&iStatus; sl@0: User::RequestComplete(s, KErrCancel); sl@0: } sl@0: sl@0: void CLogViewChangeObserver::Reset() sl@0: { sl@0: iExpectedChangeCount = 0; sl@0: iHaveFinishedOperation = EFalse; sl@0: iHaveObtainedChanges = EFalse; sl@0: iSchedulerStarted = EFalse; sl@0: iType = EStopOnChanges; sl@0: delete iChanges; sl@0: iChanges = NULL; sl@0: } sl@0: sl@0: void CLogViewChangeObserver::CheckForSchedulerStop() sl@0: { sl@0: if(iSchedulerStarted) sl@0: { sl@0: if (iHaveCallBack) sl@0: { sl@0: iCallBack.CallBack(); sl@0: iCallBack.iFunction = NULL; sl@0: iCallBack.iPtr = NULL; sl@0: iHaveCallBack = EFalse; sl@0: } sl@0: // sl@0: TBool stopScheduler = EFalse; sl@0: switch(iType) sl@0: { sl@0: case EStopOnChanges: sl@0: stopScheduler = iHaveObtainedChanges; sl@0: break; sl@0: case EStopOnRunL: sl@0: stopScheduler = iHaveFinishedOperation; sl@0: break; sl@0: case EStopOnBoth: sl@0: stopScheduler = (iHaveObtainedChanges && iHaveFinishedOperation); sl@0: break; sl@0: case EStopOnCount: sl@0: if (iChanges) sl@0: { sl@0: TEST(iChanges->Count() <= iExpectedChangeCount); sl@0: stopScheduler = (iChanges->Count() == iExpectedChangeCount); sl@0: } sl@0: case EDontStopScheduler: sl@0: break; sl@0: } sl@0: sl@0: if (stopScheduler) sl@0: { sl@0: LOGTEXT("CLogViewChangeObserver::CheckForSchedulerStop() - Stopping the scheduler"); sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CLogViewChangeObserver::AddChangeL(TLogDatabaseChangeType aType, TLogId aId, TInt aViewIndex) sl@0: { sl@0: CLogChangeDefinition* changes; sl@0: sl@0: if (iChanges) sl@0: changes = iChanges; sl@0: else sl@0: { sl@0: changes = CLogChangeDefinition::NewL(); sl@0: CleanupStack::PushL(changes); sl@0: } sl@0: // sl@0: changes->AddL(aId, aType, aViewIndex); sl@0: // sl@0: if (!iChanges) sl@0: { sl@0: delete iChanges; sl@0: iChanges = changes; sl@0: CleanupStack::Pop(changes); sl@0: } sl@0: // sl@0: iHaveObtainedChanges = ETrue; sl@0: } sl@0: sl@0: //********************************** sl@0: // CLogViewChangeObserverErrorTest sl@0: //********************************** sl@0: CLogViewChangeObserverErrorTest* CLogViewChangeObserverErrorTest::NewLC() sl@0: { sl@0: CLogViewChangeObserverErrorTest* self = new(ELeave) CLogViewChangeObserverErrorTest(); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: CLogViewChangeObserverErrorTest::CLogViewChangeObserverErrorTest() sl@0: {} sl@0: sl@0: void CLogViewChangeObserverErrorTest::HandleLogViewChangeEventAddedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount) sl@0: { sl@0: // DEF108741L - the error condition tested here is that a leave is dealt with sl@0: // gracefully without any panics. sl@0: sl@0: // Add a new event to the log sl@0: AddChangeL(ELogChangeTypeEventAdded, aId, aViewIndex); sl@0: if (aChangeIndex == aTotalChangeCount-1) sl@0: CheckForSchedulerStop(); sl@0: sl@0: // In the test case for DEF108741L this method will be effectively sl@0: // invoked 3 times. This code forces a leave on the middle event to sl@0: // ensure that the leave is dealt with and the rest of the test sl@0: // completes successfully. sl@0: if (aId == 1) sl@0: { sl@0: LEAVE(KErrGeneral); sl@0: } sl@0: } sl@0: sl@0: //********************************** sl@0: // CLogSchedulerTimer sl@0: //********************************** sl@0: sl@0: CLogSchedulerTimer* CLogSchedulerTimer::NewLC() sl@0: { sl@0: CLogSchedulerTimer* self = new(ELeave) CLogSchedulerTimer(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: CLogSchedulerTimer::~CLogSchedulerTimer() sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: CLogSchedulerTimer::CLogSchedulerTimer() sl@0: : CTimer(0) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: void CLogSchedulerTimer::ConstructL() sl@0: { sl@0: CTimer::ConstructL(); sl@0: } sl@0: sl@0: void CLogSchedulerTimer::Wait(TTimeIntervalMicroSeconds32 aTime) sl@0: { sl@0: After(aTime); sl@0: CActiveScheduler::Start(); sl@0: } sl@0: sl@0: void CLogSchedulerTimer::RunL() sl@0: { sl@0: LOGTEXT("CLogSchedulerTimer::RunL() - Stopping the scheduler"); sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: //********************************** sl@0: // CLogChangeNotifier sl@0: //********************************** sl@0: sl@0: CLogChangeNotifier* CLogChangeNotifier::NewL() sl@0: { sl@0: CLogChangeNotifier* self = new(ELeave)CLogChangeNotifier(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CLogChangeNotifier::~CLogChangeNotifier() sl@0: { sl@0: Cancel(); sl@0: delete iClient; sl@0: } sl@0: sl@0: CLogChangeNotifier::CLogChangeNotifier() sl@0: : CActive(EPriorityStandard) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: void CLogChangeNotifier::ConstructL() sl@0: { sl@0: iClient = CLogClient::NewL(theFs); sl@0: sl@0: iStart.UniversalTime(); sl@0: iClient->NotifyChange(10000000, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CLogChangeNotifier::RunL() sl@0: { sl@0: TTime now; sl@0: now.UniversalTime(); sl@0: TTimeIntervalSeconds seconds; sl@0: now.SecondsFrom(iStart, seconds); sl@0: sl@0: TBuf<256> buf; sl@0: const TInt error = iStatus.Int(); sl@0: if (error == KErrServerTerminated) sl@0: { sl@0: buf.Format(_L("KErrServerTerminated")); sl@0: User::InfoPrint(buf); sl@0: return; sl@0: } sl@0: sl@0: buf.Format(_L("%d seconds"), seconds.Int()); sl@0: User::InfoPrint(buf); sl@0: sl@0: iStart.UniversalTime(); sl@0: iClient->NotifyChange(10000000, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CLogChangeNotifier::DoCancel() sl@0: { sl@0: iClient->NotifyChangeCancel(); sl@0: } sl@0: sl@0: //********************************** sl@0: // Global sl@0: //********************************** sl@0: sl@0: void SetupSchedulerL() sl@0: { sl@0: testScheduler = new (ELeave) CActiveScheduler; sl@0: CleanupStack::PushL( testScheduler ); sl@0: CActiveScheduler::Install( testScheduler ); sl@0: } sl@0: sl@0: void CloseScheduler() sl@0: { sl@0: CleanupStack::PopAndDestroy(); // Scheduler sl@0: testScheduler = NULL; sl@0: } sl@0: sl@0: static void CreateLogL() sl@0: { sl@0: LEAVE_IF_ERROR(theFs.Connect()); sl@0: sl@0: theLogName.Copy(RProcess().FileName()); sl@0: TInt start = theLogName.LocateReverse('\\'); sl@0: TInt end = theLogName.LocateReverse('.'); sl@0: theLogName = theLogName.Mid(start + 1, end - start - 1); sl@0: sl@0: // create the log filename sl@0: theLogName.Insert(0, _L("C:\\")); sl@0: #if defined(__WINS__) sl@0: theLogName.Append(_L(".WINS.")); sl@0: #else sl@0: theLogName.Append(_L(".MARM.")); sl@0: #endif sl@0: #if defined(_UNICODE) sl@0: theLogName.Append(_L("UNICODE.")); sl@0: #else sl@0: theLogName.Append(_L("ASCII.")); sl@0: #endif sl@0: #if defined(_DEBUG) sl@0: theLogName.Append(_L("DEB.")); sl@0: #else sl@0: theLogName.Append(_L("REL.")); sl@0: #endif sl@0: theLogName.Append(_L("LOG")); sl@0: sl@0: // create the logfile sl@0: LEAVE_IF_ERROR(theLog.Replace(theFs, theLogName, EFileWrite|EFileShareExclusive)); sl@0: TBuf8<256> text; sl@0: text.Copy(theLogName); sl@0: theLog.Write(text); sl@0: theLog.Write(_L8("\nTest results\n")); sl@0: } sl@0: sl@0: static void CloseLog() sl@0: { sl@0: theLog.Write(_L8("Tests completed\n")); sl@0: TheTest.Printf(_L("Results saved in %S\n"), &theLogName); sl@0: theLog.Close(); sl@0: theFs.Close(); sl@0: } sl@0: sl@0: void DeleteDataFile(const TDesC& aFullName) sl@0: { sl@0: RFs fsSession; sl@0: TInt err = fsSession.Connect(); sl@0: if(err == KErrNone) sl@0: { sl@0: TEntry entry; sl@0: if(fsSession.Entry(aFullName, entry) == KErrNone) sl@0: { sl@0: TheTest.Printf(_L("Deleting \"%S\" file.\n"), &aFullName); sl@0: err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly); sl@0: if(err != KErrNone) sl@0: { sl@0: TheTest.Printf(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName); sl@0: } sl@0: err = fsSession.Delete(aFullName); sl@0: if(err != KErrNone) sl@0: { sl@0: TheTest.Printf(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName); sl@0: } sl@0: } sl@0: fsSession.Close(); sl@0: } sl@0: else sl@0: { sl@0: TheTest.Printf(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName); sl@0: } sl@0: } sl@0: sl@0: static void Cleanup(void*) sl@0: { sl@0: TRAP_IGNORE(TestUtils::DeleteDatabaseL()); sl@0: ::DeleteDataFile(theLogName); sl@0: } sl@0: sl@0: static void DoMainL() sl@0: { sl@0: ::SetupSchedulerL(); sl@0: TCleanupItem cleanup(&Cleanup, NULL); sl@0: CleanupStack::PushL(cleanup); sl@0: CreateLogL(); sl@0: ::doTestsL(); sl@0: CloseLog(); sl@0: CleanupStack::PopAndDestroy();//cleanup sl@0: ::CloseScheduler(); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: theCleanup = CTrapCleanup::New(); sl@0: if(!theCleanup) sl@0: { sl@0: _LIT(KLogHiCapHelperPanic, "LogTestPanic"); sl@0: User::Panic(KLogHiCapHelperPanic, KErrNoMemory); sl@0: } sl@0: sl@0: TRAPD(err, ::DoMainL()); sl@0: TEST2(err, KErrNone); sl@0: sl@0: delete theCleanup; sl@0: sl@0: TheTest.Console()->SetPos(0, 13); sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: