sl@0: // Copyright (c) 2009-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: // t_logsimid.cpp - Log event tests using the SimId event property sl@0: // sl@0: // sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_logutil2.h" sl@0: #include "LogServSqlStrings.h" sl@0: sl@0: RTest TheTest(_L("t_logsimid")); sl@0: sl@0: #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM sl@0: sl@0: const TLogId KEvId1 = 101; sl@0: _LIT(KEvDesc1, "Event Type Description 1"); sl@0: _LIT(KEvRemote1, "Remote Party 1"); sl@0: sl@0: //Event type related sl@0: //KLogCallEventType is used in order to use the "recent list" related functionality on the server side sl@0: //(KEvDirection1 value also plays important role) sl@0: const TUid KEvTypeUid = {KLogCallEventType}; sl@0: //KEvDirection1 together with the KEvTypeUid guarantee that the properties of events being added match the conditions of one sl@0: //of the LogEng server recent lists and thus the "recent list" related functionality on the server side will be used. sl@0: _LIT(KEvDirection1, "Missed call"); sl@0: sl@0: _LIT(KEvStatus1, "Status 1"); sl@0: _LIT(KEvSubject1, "Subject 1"); sl@0: _LIT(KEvNumber1, "11119999"); sl@0: const TLogDurationType KEvDurationType1 = 1; sl@0: const TLogDuration KEvDuration1 = 1000; sl@0: const TLogContactItemId KEvContact1 = 1010; sl@0: const TLogLink KEvLink1 = 2000; sl@0: _LIT8(KEvData1, "ABCDEFGH 1"); sl@0: const TLogFlags KEvFlags1 = 0x5; sl@0: const TSimId KEvSimId1 = 3000000910U;//Bigger than KMaxTInt, to check that SQL statement formatting works as expected sl@0: sl@0: const TInt KDiffEvCount = 10; sl@0: const TLogDurationType KEvDurationType2 = 2; sl@0: _LIT(KEvNumber2, "22226666"); sl@0: sl@0: const TUid KEvTypeUidLoggingDisabled = {0x447422}; sl@0: sl@0: //The default max log size is 1000. But the test timeouts on hardware with max log size of 1000. sl@0: const TInt KMaxLogSize = 200; sl@0: const TInt KMaxPlusEvCount = 100; //Added events count on top of the max log size sl@0: sl@0: TInt TheAddedEventCount = -1; sl@0: TInt TheMaxLogSize = -1; sl@0: sl@0: enum TLogViewSimId {ELogWithoutSimId, ELogWithSimId, ELogIgnoreSimId, ELogDiffEvents}; sl@0: sl@0: TLogId TheEvId = -1; sl@0: sl@0: void DoTestEvent1(const CLogEvent& aEvent) sl@0: { sl@0: TEST(aEvent.Id() == KEvId1); sl@0: TEST(aEvent.EventType() == KEvTypeUid); sl@0: TEST(aEvent.RemoteParty() == KEvRemote1); sl@0: TEST(aEvent.Direction() == KEvDirection1); sl@0: TEST(aEvent.DurationType() == KEvDurationType1); sl@0: TEST(aEvent.Duration() == KEvDuration1); sl@0: TEST(aEvent.Status() == KEvStatus1); sl@0: TEST(aEvent.Subject() == KEvSubject1); sl@0: TEST(aEvent.Number() == KEvNumber1); sl@0: TEST(aEvent.Contact() == KEvContact1); sl@0: TEST(aEvent.Link() == KEvLink1); sl@0: TEST(aEvent.Description() == KEvDesc1); sl@0: TEST(aEvent.Flags() == KEvFlags1); sl@0: TEST(aEvent.Data() == KEvData1); sl@0: TEST(aEvent.SimId() == KEvSimId1); sl@0: } sl@0: sl@0: void DoTestFilter1(const CLogFilter& aFilter) sl@0: { sl@0: TEST(aFilter.EventType() == KEvTypeUid); sl@0: TEST(aFilter.RemoteParty() == KEvRemote1); sl@0: TEST(aFilter.Direction() == KEvDirection1); sl@0: TEST(aFilter.DurationType() == KEvDurationType1); sl@0: TEST(aFilter.Status() == KEvStatus1); sl@0: TEST(aFilter.Contact() == KEvContact1); sl@0: TEST(aFilter.Number() == KEvNumber1); sl@0: TEST(aFilter.Flags() == KEvFlags1); sl@0: TEST(aFilter.SimId() == KEvSimId1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-LOGENG-UT-4025 sl@0: @SYMTestCaseDesc CLogEvent API and SimId test. sl@0: The test creates an event and checks that event Copy(), Internalize() and Externalize() sl@0: operations work properly. sl@0: @SYMTestActions CLogEvent API and SimId test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority Medium sl@0: @SYMREQ REQ12746 sl@0: */ sl@0: void LogEventApiTestL() sl@0: { sl@0: CLogEvent* event = CLogEvent::NewL(); sl@0: CleanupStack::PushL(event); sl@0: sl@0: event->SetId(KEvId1); sl@0: event->SetEventType(KEvTypeUid); sl@0: event->SetRemoteParty(KEvRemote1); sl@0: event->SetDirection(KEvDirection1); sl@0: event->SetDurationType(KEvDurationType1); sl@0: event->SetDuration(KEvDuration1); sl@0: event->SetStatus(KEvStatus1); sl@0: event->SetSubject(KEvSubject1); sl@0: event->SetNumber(KEvNumber1); sl@0: event->SetContact(KEvContact1); sl@0: event->SetLink(KEvLink1); sl@0: event->SetDescription(KEvDesc1); sl@0: event->SetFlags(KEvFlags1); sl@0: event->SetDataL(KEvData1); sl@0: event->SetSimId( KEvSimId1); sl@0: sl@0: //Copy event sl@0: CLogEvent* event2 = CLogEvent::NewL(); sl@0: CleanupStack::PushL(event2); sl@0: event2->CopyL(*event); sl@0: DoTestEvent1(*event2); sl@0: CleanupStack::PopAndDestroy(event2); sl@0: sl@0: //Externalize event sl@0: TBuf8<512> buf; sl@0: RDesWriteStream strmOut; sl@0: strmOut.Open(buf); sl@0: event->ExternalizeL(strmOut); sl@0: strmOut.CommitL(); sl@0: strmOut.Close(); sl@0: sl@0: //Internalize event sl@0: CLogEvent* event3 = CLogEvent::NewL(); sl@0: CleanupStack::PushL(event3); sl@0: RDesReadStream strmIn; sl@0: strmIn.Open(buf); sl@0: event3->InternalizeL(strmIn); sl@0: strmIn.Close(); sl@0: DoTestEvent1(*event3); sl@0: CleanupStack::PopAndDestroy(event3); sl@0: sl@0: CleanupStack::PopAndDestroy(event); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-LOGENG-UT-4026 sl@0: @SYMTestCaseDesc CLogEvent API and SimId test. sl@0: The test creates a filter and checks that filter Copy() operation work properly. sl@0: @SYMTestActions CLogEvent API and SimId test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority Medium sl@0: @SYMREQ REQ12747 sl@0: */ sl@0: void LogFilterApiTestL() sl@0: { sl@0: CLogFilter* filter = CLogFilter::NewL(); sl@0: CleanupStack::PushL(filter); sl@0: sl@0: filter->SetEventType(KEvTypeUid); sl@0: filter->SetRemoteParty(KEvRemote1); sl@0: filter->SetDirection(KEvDirection1); sl@0: filter->SetDurationType(KEvDurationType1); sl@0: filter->SetStatus(KEvStatus1); sl@0: filter->SetContact(KEvContact1); sl@0: filter->SetNumber(KEvNumber1); sl@0: filter->SetFlags(KEvFlags1); sl@0: filter->SetSimId( KEvSimId1); sl@0: sl@0: //Copy filter sl@0: CLogFilter* filter2 = CLogFilter::NewL(); sl@0: CleanupStack::PushL(filter2); sl@0: filter2->Copy(*filter); sl@0: DoTestFilter1(*filter2); sl@0: CleanupStack::PopAndDestroy(filter2); sl@0: sl@0: CleanupStack::PopAndDestroy(filter); sl@0: } sl@0: sl@0: void DoSetNewMaxLogSizeL(CLogClient& aClient, CTestActive& aActive) sl@0: { sl@0: //Check what is the max log size. sl@0: TLogConfig config; sl@0: aActive.StartL(); sl@0: aClient.GetConfig(config, aActive.iStatus); sl@0: CActiveScheduler::Start(); sl@0: TEST2(aActive.iStatus.Int(), KErrNone); sl@0: //Set new max log size sl@0: config.iMaxLogSize = KMaxLogSize; sl@0: aActive.StartL(); sl@0: aClient.ChangeConfig(config, aActive.iStatus); sl@0: CActiveScheduler::Start(); sl@0: TEST2(aActive.iStatus.Int(), KErrNone); sl@0: //Test the new max log size sl@0: aActive.StartL(); sl@0: aClient.GetConfig(config, aActive.iStatus); sl@0: CActiveScheduler::Start(); sl@0: TEST2(aActive.iStatus.Int(), KErrNone); sl@0: TEST2(config.iMaxLogSize, KMaxLogSize); sl@0: // sl@0: TheMaxLogSize = config.iMaxLogSize; sl@0: TheAddedEventCount = config.iMaxLogSize + KMaxPlusEvCount; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-LOGENG-UT-4027 sl@0: @SYMTestCaseDesc Add events test. sl@0: The test adds events to the LogEng database. The events count is bigger than the sl@0: max log size. Half of the events will be with non-zero SimId property. sl@0: 10 of the events will have different DurationType and Number values than the other events. sl@0: Apart from checking that the "add event" opertaion works with the new SimId property, this sl@0: test case also prepares data for the other "view event" test cases. sl@0: @SYMTestActions Add events test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority Medium sl@0: @SYMREQ REQ12746 sl@0: */ sl@0: void LogAddEventsTestL() sl@0: { sl@0: CLogClient* client = CLogClient::NewL(theFs); sl@0: CleanupStack::PushL(client); sl@0: CTestActive* active = new(ELeave)CTestActive(); sl@0: CleanupStack::PushL(active); sl@0: sl@0: //Set new max log size sl@0: DoSetNewMaxLogSizeL(*client, *active); sl@0: sl@0: //Add TheAddedEventCount events. Some of them with SimId, some - not. sl@0: //This certainly will involve some log purging operations when the log size reaches the max. sl@0: CLogEvent* event = CLogEvent::NewL(); sl@0: CleanupStack::PushL(event); sl@0: event->SetEventType(KLogCallEventTypeUid); sl@0: event->SetRemoteParty(KEvRemote1); sl@0: event->SetDirection(KEvDirection1); sl@0: event->SetDurationType(KEvDurationType1); sl@0: event->SetDuration(KEvDuration1); sl@0: event->SetStatus(KEvStatus1); sl@0: event->SetSubject(KEvSubject1); sl@0: event->SetNumber(KEvNumber1); sl@0: event->SetContact(KEvContact1); sl@0: event->SetLink(KEvLink1); sl@0: event->SetDescription(KEvDesc1); sl@0: event->SetFlags(KEvFlags1); sl@0: event->SetDataL(KEvData1); sl@0: sl@0: TTime st_time; sl@0: st_time.UniversalTime(); sl@0: sl@0: TheTest.Printf(_L("Added events:\n")); sl@0: TInt diffEvCount = KDiffEvCount; sl@0: for(TInt i=0;iSetSimId(KLogNullSimId); sl@0: event->SetDurationType(KEvDurationType1); sl@0: event->SetNumber(KEvNumber1); sl@0: if((i %2) == 0) sl@0: { sl@0: event->SetSimId(KEvSimId1); sl@0: if((i > TheMaxLogSize / 2 + 1) && (i % 10) == 0 && --diffEvCount >= 0) sl@0: {//Add after the second half because when the log grows above the max log size, the first events will be deleted sl@0: event->SetDurationType(KEvDurationType2); sl@0: event->SetNumber(KEvNumber2); sl@0: } sl@0: } sl@0: active->StartL(); sl@0: client->AddEvent(*event, active->iStatus); sl@0: CActiveScheduler::Start(); sl@0: TEST(!active->IsActive()); sl@0: TEST2(active->iStatus.Int(), KErrNone); sl@0: if((i % 50) == 0) sl@0: { sl@0: TheTest.Printf(_L("%d\r"), i); sl@0: } sl@0: } sl@0: TheTest.Printf(_L("%d\n"), TheAddedEventCount); sl@0: sl@0: TTime end_time; sl@0: end_time.UniversalTime(); sl@0: sl@0: CleanupStack::PopAndDestroy(event); sl@0: sl@0: CleanupStack::PopAndDestroy(active); sl@0: CleanupStack::PopAndDestroy(client); sl@0: sl@0: TTimeIntervalMicroSeconds us = end_time.MicroSecondsFrom(st_time); sl@0: TheTest.Printf(_L("%d events added. Time: %ld milliseconds\n"), TheAddedEventCount, us.Int64() / 1000); sl@0: } sl@0: sl@0: void DoSetFilterL(TLogViewSimId aViewSimId, TInt aExpectedEventCount, sl@0: CLogViewEvent& aLogView, CLogFilter& aLogFilter, CTestActive& aActive) sl@0: { sl@0: switch(aViewSimId) sl@0: { sl@0: case ELogWithoutSimId: sl@0: aLogFilter.SetNullFields(ELogSimIdField); sl@0: break; sl@0: case ELogWithSimId: sl@0: aLogFilter.SetSimId(KEvSimId1); sl@0: break; sl@0: case ELogDiffEvents: sl@0: aLogFilter.SetSimId(KEvSimId1); sl@0: aLogFilter.SetDurationType(KEvDurationType2); sl@0: aLogFilter.SetNumber(KEvNumber2); sl@0: break; sl@0: case ELogIgnoreSimId: sl@0: default: sl@0: break; sl@0: } sl@0: TBool res = aLogView.SetFilterL(aLogFilter, aActive.iStatus); sl@0: TEST(res); sl@0: aActive.StartL(); sl@0: CActiveScheduler::Start(); sl@0: TEST2(aActive.iStatus.Int(), KErrNone); sl@0: TInt count = aLogView.CountL(); sl@0: TheTest.Printf(_L("===Events count: %d\n"), count); sl@0: TEST2(count, aExpectedEventCount); sl@0: } sl@0: sl@0: void DoTestViewEvent(TLogViewSimId aViewSimId, CLogViewEvent& aLogView) sl@0: { sl@0: const CLogEvent& e = aLogView.Event(); sl@0: TSimId simid = e.SimId(); sl@0: TLogDurationType durationType = e.DurationType(); sl@0: const TDesC& number = e.Number(); sl@0: switch(aViewSimId) sl@0: { sl@0: case ELogWithoutSimId: sl@0: TEST2(simid, KLogNullSimId); sl@0: break; sl@0: case ELogWithSimId: sl@0: TEST2U(simid, KEvSimId1); sl@0: break; sl@0: case ELogDiffEvents: sl@0: TEST2U(simid, KEvSimId1); sl@0: TEST2(durationType, KEvDurationType2); sl@0: TEST(number == KEvNumber2); sl@0: break; sl@0: case ELogIgnoreSimId: sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-LOGENG-UT-4028 sl@0: @SYMTestCaseDesc View events test. sl@0: The test case expects the LogEng database to be already filled with events. sl@0: Depending what is the value of the aViewSimId, the test will prepare a view and sl@0: set the view filter to filter in events without SimId, events with SimId, all events, sl@0: or the events with different DurationType and Number property values. The purpose sl@0: of the test is to check that the event filtering works as expected with the new SimId sl@0: property. sl@0: @SYMTestActions View events test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority Medium sl@0: @SYMREQ REQ12746 sl@0: */ sl@0: void LogViewEventsTestL(TLogViewSimId aViewSimId, TInt aExpectedEventCount) sl@0: { sl@0: CLogClient* client = CLogClient::NewL(theFs); sl@0: CleanupStack::PushL(client); sl@0: CTestActive* active = new(ELeave)CTestActive(); sl@0: CleanupStack::PushL(active); sl@0: CLogViewEvent* view = CLogViewEvent::NewL(*client); sl@0: CleanupStack::PushL(view); sl@0: CLogFilter* filter = CLogFilter::NewL(); sl@0: CleanupStack::PushL(filter); sl@0: sl@0: TTime st_time; sl@0: st_time.UniversalTime(); sl@0: DoSetFilterL(aViewSimId, aExpectedEventCount, *view, *filter, *active); sl@0: TTime end_time; sl@0: end_time.UniversalTime(); sl@0: TTimeIntervalMicroSeconds us = end_time.MicroSecondsFrom(st_time); sl@0: TheTest.Printf(_L("SetFilter(). Time: %ld milliseconds\n"), us.Int64() / 1000); sl@0: sl@0: TInt count = 0; sl@0: st_time.UniversalTime(); sl@0: if(view->FirstL(active->iStatus)) sl@0: { sl@0: do sl@0: { sl@0: active->StartL(); sl@0: CActiveScheduler::Start(); sl@0: TEST2(active->iStatus.Int(), KErrNone); sl@0: DoTestViewEvent(aViewSimId, *view); sl@0: ++count; sl@0: } sl@0: while(view->NextL(active->iStatus)); sl@0: } sl@0: end_time.UniversalTime(); sl@0: us = end_time.MicroSecondsFrom(st_time); sl@0: TheTest.Printf(_L("Event view walk completed. Events count: %d. Time: %ld milliseconds\n"), count, us.Int64() / 1000); sl@0: sl@0: CleanupStack::PopAndDestroy(filter); sl@0: CleanupStack::PopAndDestroy(view); sl@0: CleanupStack::PopAndDestroy(active); sl@0: CleanupStack::PopAndDestroy(client); sl@0: } sl@0: sl@0: //Add a new event type with "logging disabled" sl@0: void DoAddEventTypeL(CLogClient& aClient, CTestActive& aActive) sl@0: { sl@0: CLogEventType* type = CLogEventType::NewL(); sl@0: CleanupStack::PushL(type); sl@0: sl@0: type->SetUid(KEvTypeUidLoggingDisabled); sl@0: type->SetDescription(_L("110111011011")); sl@0: type->SetLoggingEnabled(EFalse); sl@0: sl@0: aClient.AddEventType(*type, aActive.iStatus); sl@0: aActive.StartL(); sl@0: CActiveScheduler::Start(); sl@0: TEST2(aActive.iStatus.Int(), KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(type); sl@0: } sl@0: sl@0: void doTestsL() sl@0: { sl@0: TestUtils::Initialize(_L("t_logsimid")); sl@0: TestUtils::DeleteDatabaseL(); sl@0: // sl@0: TheTest.Start(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4025: CLogEvent API test")); sl@0: LogEventApiTestL(); sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4026: CLogFilter API test")); sl@0: LogFilterApiTestL(); sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4027: Add events test")); sl@0: LogAddEventsTestL(); sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4028: View events without SimId test")); sl@0: LogViewEventsTestL(ELogWithoutSimId, TheMaxLogSize / 2); sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4028: View events with SimId test")); sl@0: LogViewEventsTestL(ELogWithSimId, TheMaxLogSize / 2); sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4028: View events with or without SimId test")); sl@0: LogViewEventsTestL(ELogIgnoreSimId, TheMaxLogSize); sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4028: More complex event view test")); sl@0: LogViewEventsTestL(ELogDiffEvents, KDiffEvCount); sl@0: // sl@0: TestUtils::DeleteDatabaseL(); sl@0: } sl@0: sl@0: #else//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM sl@0: sl@0: void doTestsL() sl@0: { sl@0: TestUtils::Initialize(_L("t_logsimid")); sl@0: TheTest.Start(_L("The t_simid test cases are compiled only when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM macro is defined!")); sl@0: } sl@0: sl@0: #endif//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM