|
1 // Copyright (c) 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 // t_logsimid.cpp - Log event tests using the SimId event property |
|
15 // |
|
16 // |
|
17 #include <s32file.h> |
|
18 #include <s32mem.h> |
|
19 #include <e32math.h> |
|
20 #include <bautils.h> |
|
21 #include <logview.h> |
|
22 #include <logcli.h> |
|
23 #include "TEST.H" |
|
24 #include "LogServSqlStrings.h" |
|
25 |
|
26 #undef test //there is a "test" macro which hides "RTest test" declaration. |
|
27 |
|
28 RTest test(_L("LogEng - SimId tests")); |
|
29 |
|
30 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
31 |
|
32 const TLogId KEvId1 = 101; |
|
33 _LIT(KEvDesc1, "Event Type Description 1"); |
|
34 _LIT(KEvRemote1, "Remote Party 1"); |
|
35 |
|
36 //Event type related |
|
37 //KLogCallEventType is used in order to use the "recent list" related functionality on the server side |
|
38 //(KEvDirection1 value also plays important role) |
|
39 const TUid KEvTypeUid = {KLogCallEventType}; |
|
40 //KEvDirection1 together with the KEvTypeUid guarantee that the properties of events being added match the conditions of one |
|
41 //of the LogEng server recent lists and thus the "recent list" related functionality on the server side will be used. |
|
42 _LIT(KEvDirection1, "Missed call"); |
|
43 |
|
44 _LIT(KEvStatus1, "Status 1"); |
|
45 _LIT(KEvSubject1, "Subject 1"); |
|
46 _LIT(KEvNumber1, "11119999"); |
|
47 const TLogDurationType KEvDurationType1 = 1; |
|
48 const TLogDuration KEvDuration1 = 1000; |
|
49 const TLogContactItemId KEvContact1 = 1010; |
|
50 const TLogLink KEvLink1 = 2000; |
|
51 _LIT8(KEvData1, "ABCDEFGH 1"); |
|
52 const TLogFlags KEvFlags1 = 0x5; |
|
53 const TSimId KEvSimId1 = 3000000910U;//Bigger than KMaxTInt, to check that SQL statement formatting works as expected |
|
54 |
|
55 const TInt KDiffEvCount = 10; |
|
56 const TLogDurationType KEvDurationType2 = 2; |
|
57 _LIT(KEvNumber2, "22226666"); |
|
58 |
|
59 const TUid KEvTypeUidLoggingDisabled = {0x447422}; |
|
60 |
|
61 //The default max log size is 1000. But the test timeouts on hardware with max log size of 1000. |
|
62 const TInt KMaxLogSize = 200; |
|
63 const TInt KMaxPlusEvCount = 100; //Added events count on top of the max log size |
|
64 |
|
65 TInt TheAddedEventCount = -1; |
|
66 TInt TheMaxLogSize = -1; |
|
67 |
|
68 enum TLogViewSimId {ELogWithoutSimId, ELogWithSimId, ELogIgnoreSimId, ELogDiffEvents}; |
|
69 |
|
70 TLogId TheEvId = -1; |
|
71 |
|
72 void DoTestEvent1(const CLogEvent& aEvent) |
|
73 { |
|
74 TEST(aEvent.Id() == KEvId1); |
|
75 TEST(aEvent.EventType() == KEvTypeUid); |
|
76 TEST(aEvent.RemoteParty() == KEvRemote1); |
|
77 TEST(aEvent.Direction() == KEvDirection1); |
|
78 TEST(aEvent.DurationType() == KEvDurationType1); |
|
79 TEST(aEvent.Duration() == KEvDuration1); |
|
80 TEST(aEvent.Status() == KEvStatus1); |
|
81 TEST(aEvent.Subject() == KEvSubject1); |
|
82 TEST(aEvent.Number() == KEvNumber1); |
|
83 TEST(aEvent.Contact() == KEvContact1); |
|
84 TEST(aEvent.Link() == KEvLink1); |
|
85 TEST(aEvent.Description() == KEvDesc1); |
|
86 TEST(aEvent.Flags() == KEvFlags1); |
|
87 TEST(aEvent.Data() == KEvData1); |
|
88 TEST(aEvent.SimId() == KEvSimId1); |
|
89 } |
|
90 |
|
91 void DoTestFilter1(const CLogFilter& aFilter) |
|
92 { |
|
93 TEST(aFilter.EventType() == KEvTypeUid); |
|
94 TEST(aFilter.RemoteParty() == KEvRemote1); |
|
95 TEST(aFilter.Direction() == KEvDirection1); |
|
96 TEST(aFilter.DurationType() == KEvDurationType1); |
|
97 TEST(aFilter.Status() == KEvStatus1); |
|
98 TEST(aFilter.Contact() == KEvContact1); |
|
99 TEST(aFilter.Number() == KEvNumber1); |
|
100 TEST(aFilter.Flags() == KEvFlags1); |
|
101 TEST(aFilter.SimId() == KEvSimId1); |
|
102 } |
|
103 |
|
104 /** |
|
105 @SYMTestCaseID PDS-LOGENG-UT-4025 |
|
106 @SYMTestCaseDesc CLogEvent API and SimId test. |
|
107 The test creates an event and checks that event Copy(), Internalize() and Externalize() |
|
108 operations work properly. |
|
109 @SYMTestActions CLogEvent API and SimId test. |
|
110 @SYMTestExpectedResults Test must not fail |
|
111 @SYMTestPriority Medium |
|
112 @SYMREQ REQ12746 |
|
113 */ |
|
114 void LogEventApiTestL() |
|
115 { |
|
116 CLogEvent* event = CLogEvent::NewL(); |
|
117 CleanupStack::PushL(event); |
|
118 |
|
119 event->SetId(KEvId1); |
|
120 event->SetEventType(KEvTypeUid); |
|
121 event->SetRemoteParty(KEvRemote1); |
|
122 event->SetDirection(KEvDirection1); |
|
123 event->SetDurationType(KEvDurationType1); |
|
124 event->SetDuration(KEvDuration1); |
|
125 event->SetStatus(KEvStatus1); |
|
126 event->SetSubject(KEvSubject1); |
|
127 event->SetNumber(KEvNumber1); |
|
128 event->SetContact(KEvContact1); |
|
129 event->SetLink(KEvLink1); |
|
130 event->SetDescription(KEvDesc1); |
|
131 event->SetFlags(KEvFlags1); |
|
132 event->SetDataL(KEvData1); |
|
133 event->SetSimId( KEvSimId1); |
|
134 |
|
135 //Copy event |
|
136 CLogEvent* event2 = CLogEvent::NewL(); |
|
137 CleanupStack::PushL(event2); |
|
138 event2->CopyL(*event); |
|
139 DoTestEvent1(*event2); |
|
140 CleanupStack::PopAndDestroy(event2); |
|
141 |
|
142 //Externalize event |
|
143 TBuf8<512> buf; |
|
144 RDesWriteStream strmOut; |
|
145 strmOut.Open(buf); |
|
146 event->ExternalizeL(strmOut); |
|
147 strmOut.CommitL(); |
|
148 strmOut.Close(); |
|
149 |
|
150 //Internalize event |
|
151 CLogEvent* event3 = CLogEvent::NewL(); |
|
152 CleanupStack::PushL(event3); |
|
153 RDesReadStream strmIn; |
|
154 strmIn.Open(buf); |
|
155 event3->InternalizeL(strmIn); |
|
156 strmIn.Close(); |
|
157 DoTestEvent1(*event3); |
|
158 CleanupStack::PopAndDestroy(event3); |
|
159 |
|
160 CleanupStack::PopAndDestroy(event); |
|
161 } |
|
162 |
|
163 /** |
|
164 @SYMTestCaseID PDS-LOGENG-UT-4026 |
|
165 @SYMTestCaseDesc CLogEvent API and SimId test. |
|
166 The test creates a filter and checks that filter Copy() operation work properly. |
|
167 @SYMTestActions CLogEvent API and SimId test. |
|
168 @SYMTestExpectedResults Test must not fail |
|
169 @SYMTestPriority Medium |
|
170 @SYMREQ REQ12747 |
|
171 */ |
|
172 void LogFilterApiTestL() |
|
173 { |
|
174 CLogFilter* filter = CLogFilter::NewL(); |
|
175 CleanupStack::PushL(filter); |
|
176 |
|
177 filter->SetEventType(KEvTypeUid); |
|
178 filter->SetRemoteParty(KEvRemote1); |
|
179 filter->SetDirection(KEvDirection1); |
|
180 filter->SetDurationType(KEvDurationType1); |
|
181 filter->SetStatus(KEvStatus1); |
|
182 filter->SetContact(KEvContact1); |
|
183 filter->SetNumber(KEvNumber1); |
|
184 filter->SetFlags(KEvFlags1); |
|
185 filter->SetSimId( KEvSimId1); |
|
186 |
|
187 //Copy filter |
|
188 CLogFilter* filter2 = CLogFilter::NewL(); |
|
189 CleanupStack::PushL(filter2); |
|
190 filter2->Copy(*filter); |
|
191 DoTestFilter1(*filter2); |
|
192 CleanupStack::PopAndDestroy(filter2); |
|
193 |
|
194 CleanupStack::PopAndDestroy(filter); |
|
195 } |
|
196 |
|
197 void DoSetNewMaxLogSizeL(CLogClient& aClient, CTestActive& aActive) |
|
198 { |
|
199 //Check what is the max log size. |
|
200 TLogConfig config; |
|
201 aActive.StartL(); |
|
202 aClient.GetConfig(config, aActive.iStatus); |
|
203 CActiveScheduler::Start(); |
|
204 TEST2(aActive.iStatus.Int(), KErrNone); |
|
205 //Set new max log size |
|
206 config.iMaxLogSize = KMaxLogSize; |
|
207 aActive.StartL(); |
|
208 aClient.ChangeConfig(config, aActive.iStatus); |
|
209 CActiveScheduler::Start(); |
|
210 TEST2(aActive.iStatus.Int(), KErrNone); |
|
211 //Test the new max log size |
|
212 aActive.StartL(); |
|
213 aClient.GetConfig(config, aActive.iStatus); |
|
214 CActiveScheduler::Start(); |
|
215 TEST2(aActive.iStatus.Int(), KErrNone); |
|
216 TEST2(config.iMaxLogSize, KMaxLogSize); |
|
217 // |
|
218 TheMaxLogSize = config.iMaxLogSize; |
|
219 TheAddedEventCount = config.iMaxLogSize + KMaxPlusEvCount; |
|
220 } |
|
221 |
|
222 /** |
|
223 @SYMTestCaseID PDS-LOGENG-UT-4027 |
|
224 @SYMTestCaseDesc Add events test. |
|
225 The test adds events to the LogEng database. The events count is bigger than the |
|
226 max log size. Half of the events will be with non-zero SimId property. |
|
227 10 of the events will have different DurationType and Number values than the other events. |
|
228 Apart from checking that the "add event" opertaion works with the new SimId property, this |
|
229 test case also prepares data for the other "view event" test cases. |
|
230 @SYMTestActions Add events test. |
|
231 @SYMTestExpectedResults Test must not fail |
|
232 @SYMTestPriority Medium |
|
233 @SYMREQ REQ12746 |
|
234 */ |
|
235 void LogAddEventsTestL() |
|
236 { |
|
237 CLogClient* client = CLogClient::NewL(theFs); |
|
238 CleanupStack::PushL(client); |
|
239 CTestActive* active = new(ELeave)CTestActive(); |
|
240 CleanupStack::PushL(active); |
|
241 |
|
242 //Set new max log size |
|
243 DoSetNewMaxLogSizeL(*client, *active); |
|
244 |
|
245 //Add TheAddedEventCount events. Some of them with SimId, some - not. |
|
246 //This certainly will involve some log purging operations when the log size reaches the max. |
|
247 CLogEvent* event = CLogEvent::NewL(); |
|
248 CleanupStack::PushL(event); |
|
249 event->SetEventType(KLogCallEventTypeUid); |
|
250 event->SetRemoteParty(KEvRemote1); |
|
251 event->SetDirection(KEvDirection1); |
|
252 event->SetDurationType(KEvDurationType1); |
|
253 event->SetDuration(KEvDuration1); |
|
254 event->SetStatus(KEvStatus1); |
|
255 event->SetSubject(KEvSubject1); |
|
256 event->SetNumber(KEvNumber1); |
|
257 event->SetContact(KEvContact1); |
|
258 event->SetLink(KEvLink1); |
|
259 event->SetDescription(KEvDesc1); |
|
260 event->SetFlags(KEvFlags1); |
|
261 event->SetDataL(KEvData1); |
|
262 |
|
263 TTime st_time; |
|
264 st_time.UniversalTime(); |
|
265 |
|
266 test.Printf(_L("Added events:\n")); |
|
267 TInt diffEvCount = KDiffEvCount; |
|
268 for(TInt i=0;i<TheAddedEventCount;++i) |
|
269 { |
|
270 event->SetSimId(KLogNullSimId); |
|
271 event->SetDurationType(KEvDurationType1); |
|
272 event->SetNumber(KEvNumber1); |
|
273 if((i %2) == 0) |
|
274 { |
|
275 event->SetSimId(KEvSimId1); |
|
276 if((i > TheMaxLogSize / 2 + 1) && (i % 10) == 0 && --diffEvCount >= 0) |
|
277 {//Add after the second half because when the log grows above the max log size, the first events will be deleted |
|
278 event->SetDurationType(KEvDurationType2); |
|
279 event->SetNumber(KEvNumber2); |
|
280 } |
|
281 } |
|
282 active->StartL(); |
|
283 client->AddEvent(*event, active->iStatus); |
|
284 CActiveScheduler::Start(); |
|
285 TEST(!active->IsActive()); |
|
286 TEST2(active->iStatus.Int(), KErrNone); |
|
287 if((i % 50) == 0) |
|
288 { |
|
289 test.Printf(_L("%d\r"), i); |
|
290 } |
|
291 } |
|
292 test.Printf(_L("%d\n"), TheAddedEventCount); |
|
293 |
|
294 TTime end_time; |
|
295 end_time.UniversalTime(); |
|
296 |
|
297 CleanupStack::PopAndDestroy(event); |
|
298 |
|
299 CleanupStack::PopAndDestroy(active); |
|
300 CleanupStack::PopAndDestroy(client); |
|
301 |
|
302 TTimeIntervalMicroSeconds us = end_time.MicroSecondsFrom(st_time); |
|
303 test.Printf(_L("%d events added. Time: %ld milliseconds\n"), TheAddedEventCount, us.Int64() / 1000); |
|
304 } |
|
305 |
|
306 void DoSetFilterL(TLogViewSimId aViewSimId, TInt aExpectedEventCount, |
|
307 CLogViewEvent& aLogView, CLogFilter& aLogFilter, CTestActive& aActive) |
|
308 { |
|
309 switch(aViewSimId) |
|
310 { |
|
311 case ELogWithoutSimId: |
|
312 aLogFilter.SetNullFields(ELogSimIdField); |
|
313 break; |
|
314 case ELogWithSimId: |
|
315 aLogFilter.SetSimId(KEvSimId1); |
|
316 break; |
|
317 case ELogDiffEvents: |
|
318 aLogFilter.SetSimId(KEvSimId1); |
|
319 aLogFilter.SetDurationType(KEvDurationType2); |
|
320 aLogFilter.SetNumber(KEvNumber2); |
|
321 break; |
|
322 case ELogIgnoreSimId: |
|
323 default: |
|
324 break; |
|
325 } |
|
326 TBool res = aLogView.SetFilterL(aLogFilter, aActive.iStatus); |
|
327 TEST(res); |
|
328 aActive.StartL(); |
|
329 CActiveScheduler::Start(); |
|
330 TEST2(aActive.iStatus.Int(), KErrNone); |
|
331 TInt count = aLogView.CountL(); |
|
332 test.Printf(_L("===Events count: %d\n"), count); |
|
333 TEST2(count, aExpectedEventCount); |
|
334 } |
|
335 |
|
336 void DoTestViewEvent(TLogViewSimId aViewSimId, CLogViewEvent& aLogView) |
|
337 { |
|
338 const CLogEvent& e = aLogView.Event(); |
|
339 TSimId simid = e.SimId(); |
|
340 TLogDurationType durationType = e.DurationType(); |
|
341 const TDesC& number = e.Number(); |
|
342 switch(aViewSimId) |
|
343 { |
|
344 case ELogWithoutSimId: |
|
345 TEST2(simid, KLogNullSimId); |
|
346 break; |
|
347 case ELogWithSimId: |
|
348 TEST2U(simid, KEvSimId1); |
|
349 break; |
|
350 case ELogDiffEvents: |
|
351 TEST2U(simid, KEvSimId1); |
|
352 TEST2(durationType, KEvDurationType2); |
|
353 TEST(number == KEvNumber2); |
|
354 break; |
|
355 case ELogIgnoreSimId: |
|
356 default: |
|
357 break; |
|
358 } |
|
359 } |
|
360 |
|
361 /** |
|
362 @SYMTestCaseID PDS-LOGENG-UT-4028 |
|
363 @SYMTestCaseDesc View events test. |
|
364 The test case expects the LogEng database to be already filled with events. |
|
365 Depending what is the value of the aViewSimId, the test will prepare a view and |
|
366 set the view filter to filter in events without SimId, events with SimId, all events, |
|
367 or the events with different DurationType and Number property values. The purpose |
|
368 of the test is to check that the event filtering works as expected with the new SimId |
|
369 property. |
|
370 @SYMTestActions View events test. |
|
371 @SYMTestExpectedResults Test must not fail |
|
372 @SYMTestPriority Medium |
|
373 @SYMREQ REQ12746 |
|
374 */ |
|
375 void LogViewEventsTestL(TLogViewSimId aViewSimId, TInt aExpectedEventCount) |
|
376 { |
|
377 CLogClient* client = CLogClient::NewL(theFs); |
|
378 CleanupStack::PushL(client); |
|
379 CTestActive* active = new(ELeave)CTestActive(); |
|
380 CleanupStack::PushL(active); |
|
381 CLogViewEvent* view = CLogViewEvent::NewL(*client); |
|
382 CleanupStack::PushL(view); |
|
383 CLogFilter* filter = CLogFilter::NewL(); |
|
384 CleanupStack::PushL(filter); |
|
385 |
|
386 TTime st_time; |
|
387 st_time.UniversalTime(); |
|
388 DoSetFilterL(aViewSimId, aExpectedEventCount, *view, *filter, *active); |
|
389 TTime end_time; |
|
390 end_time.UniversalTime(); |
|
391 TTimeIntervalMicroSeconds us = end_time.MicroSecondsFrom(st_time); |
|
392 test.Printf(_L("SetFilter(). Time: %ld milliseconds\n"), us.Int64() / 1000); |
|
393 |
|
394 TInt count = 0; |
|
395 st_time.UniversalTime(); |
|
396 if(view->FirstL(active->iStatus)) |
|
397 { |
|
398 do |
|
399 { |
|
400 active->StartL(); |
|
401 CActiveScheduler::Start(); |
|
402 TEST2(active->iStatus.Int(), KErrNone); |
|
403 DoTestViewEvent(aViewSimId, *view); |
|
404 ++count; |
|
405 } |
|
406 while(view->NextL(active->iStatus)); |
|
407 } |
|
408 end_time.UniversalTime(); |
|
409 us = end_time.MicroSecondsFrom(st_time); |
|
410 test.Printf(_L("Event view walk completed. Events count: %d. Time: %ld milliseconds\n"), count, us.Int64() / 1000); |
|
411 |
|
412 CleanupStack::PopAndDestroy(filter); |
|
413 CleanupStack::PopAndDestroy(view); |
|
414 CleanupStack::PopAndDestroy(active); |
|
415 CleanupStack::PopAndDestroy(client); |
|
416 } |
|
417 |
|
418 //Add a new event type with "logging disabled" |
|
419 void DoAddEventTypeL(CLogClient& aClient, CTestActive& aActive) |
|
420 { |
|
421 CLogEventType* type = CLogEventType::NewL(); |
|
422 CleanupStack::PushL(type); |
|
423 |
|
424 type->SetUid(KEvTypeUidLoggingDisabled); |
|
425 type->SetDescription(_L("110111011011")); |
|
426 type->SetLoggingEnabled(EFalse); |
|
427 |
|
428 aClient.AddEventType(*type, aActive.iStatus); |
|
429 aActive.StartL(); |
|
430 CActiveScheduler::Start(); |
|
431 TEST2(aActive.iStatus.Int(), KErrNone); |
|
432 |
|
433 CleanupStack::PopAndDestroy(type); |
|
434 } |
|
435 |
|
436 void doTestsL() |
|
437 { |
|
438 TestUtils::DeleteDatabaseL(); |
|
439 // |
|
440 test.Start(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4025: CLogEvent API test")); |
|
441 LogEventApiTestL(); |
|
442 test.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4026: CLogFilter API test")); |
|
443 LogFilterApiTestL(); |
|
444 test.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4027: Add events test")); |
|
445 LogAddEventsTestL(); |
|
446 test.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4028: View events without SimId test")); |
|
447 LogViewEventsTestL(ELogWithoutSimId, TheMaxLogSize / 2); |
|
448 test.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4028: View events with SimId test")); |
|
449 LogViewEventsTestL(ELogWithSimId, TheMaxLogSize / 2); |
|
450 test.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4028: View events with or without SimId test")); |
|
451 LogViewEventsTestL(ELogIgnoreSimId, TheMaxLogSize); |
|
452 test.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4028: More complex event view test")); |
|
453 LogViewEventsTestL(ELogDiffEvents, KDiffEvCount); |
|
454 // |
|
455 TestUtils::DeleteDatabaseL(); |
|
456 } |
|
457 |
|
458 #else//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |
|
459 |
|
460 void doTestsL() |
|
461 { |
|
462 test.Start(_L("The t_simid test cases are compiled only when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM macro is defined!")); |
|
463 } |
|
464 |
|
465 #endif//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM |