void CEventLogger::RunL() { // request has completed // delete completed event and check if there is a next event pending // If LogEng is not supported, a dummy logeng just returns error straight on. // but we carry on doing all the requests if (iLogEventQueue->Count() >0) { CLogEvent* nextEventPtr = iLogEventQueue->At(0); __ASSERT_DEBUG((nextEventPtr != NULL), AgentPanic(Agent::ENullCLogEventPointerPresentInLogEventQueue)); if (nextEventPtr->Id() == KGenconnLogWaitingForLogId) { //Id was not available when the update has been entered because addEvent did not return at that time nextEventPtr->SetId(iCurrentLogEvent->Id()); } iCurrentLogEvent->CopyL(*nextEventPtr); iLogWrap->Log().ChangeEvent(*iCurrentLogEvent, iStatus); SetActive(); // delete the ongoing CLogEvent we just copied to currentLogEvent delete nextEventPtr; //remove the pointer from the queue iLogEventQueue->Delete(0); } else if (iNotificationRequestStatus!=NULL) { // We have finished processing all the log event updates in the queue User::RequestComplete(iNotificationRequestStatus, KErrNone); iNotificationRequestStatus = NULL; // did the job, so do need the pointer anymore. } }
/** @SYMTestCaseID SYSLIB-LOGENG-CT-0875 @SYMTestCaseDesc Tests for maximum logging of configuration data @SYMTestPriority High @SYMTestActions Get the event type configuration data.Set the log size to maximum. Change the log engine configuration data with the new one.Add events to the log Set the filter on the view and check for KErrNone flag. Add a new event and disable logging by setting the maximum logging size to zero Clear all the events and test for KErrNone and the total count of events. @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ LOCAL_C void TestMaxLogSizeL(CLogClient& aClient) { TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0875 ")); CLogEvent* event = CLogEvent::NewL(); CleanupStack::PushL(event); event->SetEventType(KLogCallEventTypeUid); CTestActive* active = new(ELeave)CTestActive(); CleanupStack::PushL(active); CLogViewEvent* view = CLogViewEvent::NewL(aClient); CleanupStack::PushL(view); CLogFilter* filter = CLogFilter::NewL(); CleanupStack::PushL(filter); TLogConfig config; // Get log configuration active->StartL(); aClient.GetConfig(config, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); // Set the maximum log size config.iMaxLogSize = KTestEventNum; // Change the log engine config active->StartL(); aClient.ChangeConfig(config, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); // Initialise the view - There should be no events TEST(!view->SetFilterL(*filter, active->iStatus)); // Add the number of allowed events TInt count; for(count = 0; count < KTestEventNum; count++) { active->StartL(); aClient.AddEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); } TEST(view->SetFilterL(*filter, active->iStatus)); active->StartL(); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); // The view should now have the correct number of events TEST(view->CountL() == KTestEventNum); // Add the same number of events again - the old ones should be deleted for(count = 0; count < KTestEventNum; count++) { TEST(view->SetFilterL(*filter, active->iStatus)); active->StartL(); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); // Get the last (oldest) event active->StartL(); view->LastL(active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); // Remember the Id TLogId id = view->Event().Id(); // Add another event - the oldest should be removed active->StartL(); aClient.AddEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); // There should be the same number of events in view TEST(view->CountL() == KTestEventNum); event->SetId(id); // Try and get the old event active->StartL(); aClient.GetEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNotFound); } // Add an event active->StartL(); aClient.AddEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); // Check it's there active->StartL(); aClient.GetEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); // Set the maximum log size to zero, i.e. disable logging config.iMaxLogSize = 0; // Change the log engine config active->StartL(); aClient.ChangeConfig(config, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); // Check the event has gone active->StartL(); aClient.GetEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNotFound);; // Add an event active->StartL(); aClient.AddEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNotSupported); // Check that event doesn't exist active->StartL(); aClient.GetEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNotFound);; User::After(1000000); TTime now; now.UniversalTime(); now+=(TTimeIntervalDays) 1; // Clear all the events active->StartL(); aClient.ClearLog(now, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); TEST(!view->SetFilterL(*filter, active->iStatus)); TEST(view->CountL() == 0); CleanupStack::PopAndDestroy(4); // filter, view, active, event }
EXPORT_C void CEventLogger::LogDataAddEvent(TInt aRConnectionStatusId, const TDesC& aRemote, TInt aLogDir, const TDesC& aTelNum, TUid aDataEventType) { LOGSTRING2("GenConn:\tCEventLogger LogDataAddEvent aRConnectionStatusId:%d", aRConnectionStatusId); //It is possible to add a new logevent with a new log id for the same connection (reconnect case) // assuming that all the next updates will be for the new event and not the old one. // [NeilMa 140403]: This method cannot leave and has no return value, but // performs memory allocations if the event cannot be logged immediately. // Therefore, if the memory alloc fails for any reason, the event is // currently discarded with no record. This method should be replaced by // one which can Leave or returns an error code. See Typhoon DEF022946. TTime time; time.UniversalTime(); if (!IsActive() && (iLogEventQueue->Count() ==0)) { iCurrentLogEvent->SetId(KGenconnLogWaitingForLogId); iCurrentLogEvent->SetTime(time); TBuf<KLogMaxStatusLength > logStatusBuf; iLogWrap->Log().GetString(logStatusBuf, aRConnectionStatusId); // Ignore error - string blank on error which is ok iCurrentLogEvent->SetStatus(logStatusBuf); iCurrentLogEvent->SetRemoteParty(aRemote); TBuf<KLogMaxDirectionLength> logDirBuf; iLogWrap->Log().GetString(logDirBuf, aLogDir); // Ignore error - string blank on error which is ok iCurrentLogEvent->SetDirection(logDirBuf); iCurrentLogEvent->SetNumber(aTelNum); iCurrentLogEvent->SetEventType(aDataEventType); iCurrentLogEvent->SetDurationType(KLogDurationValid); iStatus=KRequestPending; iLogWrap->Log().AddEvent(*iCurrentLogEvent, iStatus); SetActive(); } else { // add the request to the queue, it will be processed asap CLogEvent* eventUpdate = 0; TRAPD(error, eventUpdate = CLogEvent::NewL()); if (KErrNone != error) { return; // event is discarded! } eventUpdate->SetId(KGenconnLogWaitingForLogId); eventUpdate->SetTime(time); TBuf<KLogMaxStatusLength > logStatusBuf; iLogWrap->Log().GetString(logStatusBuf, aRConnectionStatusId); // Ignore error - string blank on error which is ok eventUpdate->SetStatus(logStatusBuf); eventUpdate->SetRemoteParty(aRemote); TBuf<KLogMaxDirectionLength> logDirBuf; iLogWrap->Log().GetString(logDirBuf, aLogDir); // Ignore error - string blank on error which is ok eventUpdate->SetDirection(logDirBuf); eventUpdate->SetNumber(aTelNum); eventUpdate->SetEventType(aDataEventType); eventUpdate->SetDurationType(KLogDurationValid); // add to the queue TRAP(error, iLogEventQueue->AppendL(eventUpdate)); if (KErrNone != error) { delete eventUpdate; // event is discarded! return; } } }
/** @SYMTestCaseID SYSLIB-LOGENG-CT-1009 @SYMTestCaseDesc Tests for CLogEvent::NewL(),SetDataL() functions @SYMTestPriority High @SYMTestActions Tests for creation of log event on heap and test for setting event specific data from the specified stream and try to read the data back. Check for memory errors @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ LOCAL_C void TestEventWithHeapFailL() { TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1009 ")); #ifdef _DEBUG TInt failCount = 0; #endif TInt error; TBool finished = EFalse; CLogEvent* event = NULL; while(!finished) { __UHEAP_FAILNEXT(failCount++); TRAP(error, event = CLogEvent::NewL()); __UHEAP_RESET; if (error == KErrNone) { finished = ETrue; CleanupStack::PushL(event); } else TEST2(error, KErrNoMemory); } _LIT8(KDataTest1, "01234567890123456789"); _LIT8(KDataTest2, "012345678901234567890123456789"); finished = EFalse; #ifdef _DEBUG failCount = 0; #endif event->SetDataL(KNullDesC8); while(!finished) { __UHEAP_FAILNEXT(failCount++); TRAP(error, event->SetDataL(KDataTest1)); __UHEAP_RESET; if (error == KErrNone) { finished = ETrue; TEST(event->Data() == KDataTest1); } else { TEST2(error, KErrNoMemory); TEST(event->Data() == KNullDesC8); } } finished = EFalse; #ifdef _DEBUG failCount = 0; #endif event->SetDataL(KNullDesC8); while(!finished) { __UHEAP_FAILNEXT(failCount++); TRAP(error, event->SetDataL(KDataTest2)); __UHEAP_RESET; if (error == KErrNone) { finished = ETrue; TEST(event->Data() == KDataTest2); } else { TEST2(error, KErrNoMemory); TEST(event->Data() == KNullDesC8); } } finished = EFalse; #ifdef _DEBUG failCount = 0; #endif event->SetDataL(KNullDesC8); // Check we don't get any more failures __UHEAP_FAILNEXT(0); event->SetDataL(KDataTest2); TEST(event->Data() == KDataTest2); event->SetDataL(KDataTest1); TEST(event->Data() == KDataTest1); event->SetDataL(KNullDesC8); TEST(event->Data() == KNullDesC8); __UHEAP_RESET; // streaming TFileName storename = _L("c:\\T_BASIC_DATA"); TUid uid={0x12345678}; // create a store theFs.Delete(storename); CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(theFs, storename, uid); RDictionaryWriteStream write; RDictionaryReadStream read; uid.iUid++; write.AssignL(*store, uid); write << KNullDesC8; write.CommitL(); write.Close(); read.OpenL(*store, uid); #ifdef _DEBUG failCount = 0; #endif finished = EFalse; __UHEAP_FAILNEXT(0); event->SetDataL(read, 0); __UHEAP_RESET; read.Close(); TEST(event->Data() == KNullDesC8); HBufC8* buf8 = TestUtils::CreateBuf8LC(100); uid.iUid++; write.AssignL(*store, uid); write.WriteL(buf8->Des()); write.CommitL(); write.Close(); read.OpenL(*store, uid); while(!finished) { __UHEAP_FAILNEXT(failCount++); TRAP(error, event->SetDataL(read, 100)); __UHEAP_RESET; if (error == KErrNone) { TEST(event->Data() == buf8->Des()); read.Close(); finished = ETrue; } else { TEST2(error, KErrNoMemory); TEST(event->Data() == KNullDesC8); } } event->SetId(0x12345678); event->SetEventType(TUid::Uid(0x12345678)); HBufC* buf = TestUtils::CreateBufLC(KLogMaxRemotePartyLength / 2); event->SetRemoteParty(buf->Des()); CleanupStack::PopAndDestroy(); // buf buf = TestUtils::CreateBufLC(KLogMaxDirectionLength / 2); event->SetDirection(buf->Des()); CleanupStack::PopAndDestroy(); // buf TTime time; time.UniversalTime(); event->SetTime(time); TEST(event->Time() == time); event->SetDurationType(0xf); event->SetDuration(0x12345678); buf = TestUtils::CreateBufLC(KLogMaxStatusLength / 2); event->SetStatus(buf->Des()); CleanupStack::PopAndDestroy(); // buf buf = TestUtils::CreateBufLC(KLogMaxSubjectLength / 2); event->SetSubject(buf->Des()); CleanupStack::PopAndDestroy(); // buf buf = TestUtils::CreateBufLC(KLogMaxNumberLength / 2); event->SetNumber(buf->Des()); CleanupStack::PopAndDestroy(); // buf event->SetContact(0x12345678); event->SetLink(0x12345678); buf = TestUtils::CreateBufLC(KLogMaxDescriptionLength / 2); event->SetDescription(buf->Des()); CleanupStack::PopAndDestroy(); // buf event->SetFlags(0xA); buf8 = TestUtils::CreateBuf8LC(100); event->SetDataL(buf8->Des()); TEST(event->Data() == buf8->Des()); CleanupStack::PopAndDestroy(); // buf8 CLogEvent* event1 = CLogEvent::NewL(); CleanupStack::PushL(event1); CLogEvent* event2 = CLogEvent::NewL(); CleanupStack::PushL(event2); TEST(TestUtils::EventsEqual(*event1, *event2)); finished = EFalse; #ifdef _DEBUG failCount = 0; #endif while(!finished) { __UHEAP_FAILNEXT(failCount++); TRAP(error, event1->CopyL(*event)); __UHEAP_RESET; if (error == KErrNone) { TEST(!TestUtils::EventsEqual(*event1, *event2)); TEST(TestUtils::EventsEqual(*event1, *event)); finished = ETrue; } else { TEST2(error, KErrNoMemory); TEST(TestUtils::EventsEqual(*event1, *event2)); TEST(!TestUtils::EventsEqual(*event1, *event)); } } CleanupStack::PopAndDestroy(5); // buf8, store, event, event1, event2 ::DeleteDataFile(storename); }
/** @SYMTestCaseID SYSLIB-LOGENG-CT-0119 @SYMTestCaseDesc Tests AddEvent, GetEvent, ChangeEvent and DeleteEvent. @SYMTestPriority High @SYMTestActions See the description and expected results. @SYMTestExpectedResults 1. a client with sufficient capability succeed in all cases would expect the following... AddEvent - KErrNone GetEvent - KErrNone ChangeEvent - KErrNone DeleteEvent - KErrNone 2. a client with insufficient capability would expect the following results... AddEvent - KErrPermissionDenied GetEvent - KErrNone ChangeEvent - KErrPermissionDenied DeleteEvent - KErrPermissionDenied @SYMREQ REQ3431 */ LOCAL_C void TestBasicL(CLogClient& aClient) { TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0119 ")); CTestActive* active = new(ELeave)CTestActive(); CleanupStack::PushL(active); CLogEvent* event = CLogEvent::NewL(); CleanupStack::PushL(event); TTime now; now.UniversalTime(); event->SetEventType(KLogCallEventTypeUid); active->StartL(); aClient.AddEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied); if(!TheHiCapability) { TInt eventId = TestUtils::AddEventL(); TEST(eventId >= 0); event->SetId(eventId); } TEST(event->EventType() == KLogCallEventTypeUid); now = event->Time(); TLogId id = event->Id(); event->SetRemoteParty(KTestRemoteParty1); event->SetDirection(KTestDirection1); event->SetDurationType(KTestDurationType1); event->SetDuration(KTestDuration1); event->SetStatus(KTestStatus1); event->SetSubject(KTestSubject1); event->SetNumber(KTestNumber1); event->SetContact(KTestContact1); event->SetLink(KTestLink1); event->SetDataL(KTestData1); active->StartL(); aClient.ChangeEvent(*event, active->iStatus); CActiveScheduler::Start(); TheTest.Printf(_L("TestBasicL(), TheHiCapability=%d, event id=%d\r\n"), TheHiCapability, id); TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied); TEST(event->Id() == id ); TEST(event->EventType() == KLogCallEventTypeUid); if(TheHiCapability) { TEST(event->Description().Length() > 0); TEST(event->Time() == now); TEST(event->RemoteParty() == KTestRemoteParty1); TEST(event->Direction() == KTestDirection1); TEST(event->DurationType() == KTestDurationType1); TEST(event->Duration() == KTestDuration1); TEST(event->Status() == KTestStatus1); TEST(event->Subject() == KTestSubject1); TEST(event->Number() == KTestNumber1); TEST(event->Contact() == KTestContact1); TEST(event->Link() == KTestLink1); TEST(event->Data() == KTestData1); } CleanupStack::PopAndDestroy(); // event; event = CLogEvent::NewL(); CleanupStack::PushL(event); event->SetId(id); active->StartL(); aClient.GetEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied); if(TheHiCapability) { TEST(event->Id() == id); TEST(event->EventType() == KLogCallEventTypeUid); TEST(event->Description().Length() > 0); TEST(event->Time() == now); TEST(event->RemoteParty() == KTestRemoteParty1); TEST(event->Direction() == KTestDirection1); TEST(event->DurationType() == KTestDurationType1); TEST(event->Duration() == KTestDuration1); TEST(event->Status() == KTestStatus1); TEST(event->Subject() == KTestSubject1); TEST(event->Number() == KTestNumber1); TEST(event->Contact() == KTestContact1); TEST(event->Link() == KTestLink1); TEST(event->Data() == KTestData1); } active->StartL(); aClient.DeleteEvent(id, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied); active->StartL(); aClient.GetEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), TheHiCapability ? KErrNotFound : KErrPermissionDenied); // try to delete a non-existent event... active->StartL(); aClient.DeleteEvent(123, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNotFound); CleanupStack::PopAndDestroy(2); // event, active }
/** @SYMTestCaseID SYSLIB-LOGENG-CT-1022 @SYMTestCaseDesc Tests for operations on log database @SYMTestPriority High @SYMTestActions Check by add new event,change the event,and get event and check for integrity of data @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ LOCAL_C void TestEventViewL(CLogClient& aClient) { TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1022 ")); CTestActive* active = new(ELeave)CTestActive(); CleanupStack::PushL(active); CLogViewChangeObserver* changeObs = CLogViewChangeObserver::NewLC(); changeObs->SetActive(); CLogViewEvent* view = CLogViewEvent::NewL(aClient, *changeObs); CleanupStack::PushL(view); CLogEvent* event; TLogId id; TTime now; now.UniversalTime(); TInt count; for(count = 0; count < KTestEventNum; count++) { event = CLogEvent::NewL(); CleanupStack::PushL(event); event->SetEventType(KLogCallEventTypeUid); //User::After(Math::Random() % 100000); User::After(1000000); active->StartL(); aClient.AddEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); TEST(event->EventType() == KLogCallEventTypeUid); TEST(event->Description().Length() > 0); TEST(event->Time() >= now); now = event->Time(); id = event->Id(); event->SetRemoteParty(KTestRemoteParty1); event->SetDirection(KTestDirection1); event->SetDurationType(KTestDurationType1); event->SetDuration(KTestDuration1); event->SetStatus(KTestStatus1); event->SetSubject(KTestSubject1); event->SetNumber(KTestNumber1); event->SetLink(KTestLink1); event->SetDataL(KTestData1); event->SetFlags(KTestFlags1); event->SetContact((TLogContactItemId) count+1); User::After(Math::Random() % 100000); active->StartL(); aClient.ChangeEvent(*event, active->iStatus); CActiveScheduler::Start(); //If the test fails on the next line with -1 or -12 error, it is possible that the contacts database is missing: //c:\private\10003a73\SQLite__Contacts.cdb. Copy it to the specified location and rerun the test. TEST2(active->iStatus.Int(), KErrNone); TEST(event->EventType() == KLogCallEventTypeUid); TEST(event->RemoteParty() == KTestRemoteParty1); TEST(event->Direction() == KTestDirection1); TEST(event->DurationType() == KTestDurationType1); TEST(event->Duration() == KTestDuration1); TEST(event->Status() == KTestStatus1); TEST(event->Subject() == KTestSubject1); TEST(event->Number() == KTestNumber1); TEST(event->Link() == KTestLink1); TEST(event->Data() == KTestData1); TLogFlags eventFlags; if(TheMatchingIsEnabled) { eventFlags=KTestFlags1|KLogEventContactSearched; } else { eventFlags=KTestFlags1; } //If the test fails on the next line, it is quite possible that there is a //z:\private\10202be9a\101f401d.txt file that sets the contacts match count to 0. //Delete the file and run the test again. TEST(event->Flags() == eventFlags); TEST(event->Contact()==(TLogContactItemId) count+1); CleanupStack::PopAndDestroy(); // event; event = CLogEvent::NewL(); CleanupStack::PushL(event); event->SetId(id); active->StartL(); aClient.GetEvent(*event, active->iStatus); CActiveScheduler::Start(); TEST2(active->iStatus.Int(), KErrNone); TEST(event->EventType() == KLogCallEventTypeUid); TEST(event->RemoteParty() == KTestRemoteParty1); TEST(event->Direction() == KTestDirection1); TEST(event->DurationType() == KTestDurationType1); TEST(event->Duration() == KTestDuration1); TEST(event->Status() == KTestStatus1); TEST(event->Subject() == KTestSubject1); TEST(event->Number() == KTestNumber1); TEST(event->Link() == KTestLink1); TEST(event->Data() == KTestData1); TEST(event->Flags() == eventFlags); TEST(event->Contact()==(TLogContactItemId) count+1); CleanupStack::PopAndDestroy(); // event; } CleanupStack::PopAndDestroy(3, active); // Delete view, changeObs, active }