Update contrib.
1 // Copyright (c) 2002-2010 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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "t_logutil2.h"
19 RTest TheTest(_L("t_lognotify"));
21 _LIT(KTestRemoteParty1, "Remote Party");
22 _LIT(KTestDirection1, "Direction");
23 const TLogDurationType KTestDurationType1 = 1;
24 const TLogDuration KTestDuration1 = 0x1234;
25 _LIT(KTestStatus1, "Status");
26 _LIT(KTestSubject1, "Subject");
27 _LIT(KTestNumber1, "TheNumber");
28 const TLogContactItemId KTestContact1 = 0x1234;
29 const TLogLink KTestLink1 = 0x1234;
30 _LIT8(KTestData1, "ABCDEFGH");
31 const TLogFlags KTestFlags1 = 0x5;
34 @SYMTestCaseID SYSLIB-LOGENG-CT-0926
35 @SYMTestCaseDesc Tests for CLogClient::NotifyChange() function
37 @SYMTestActions Tests for notification of changes to the logengine database.
38 Add events within the time intervals ,check for the notification of an event
39 @SYMTestExpectedResults Test must not fail
42 LOCAL_C void TestNotificationL()
44 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0926 "));
45 CLogClient* client = CLogClient::NewL(theFs);
46 CleanupStack::PushL(client);
48 CTestActive* active1 = new(ELeave)CTestActive;
49 CleanupStack::PushL(active1);
51 CTestActive* active2 = new(ELeave)CTestActive;
52 CleanupStack::PushL(active2);
54 CLogEvent* event = CLogEvent::NewL();
55 CleanupStack::PushL(event);
57 event->SetEventType(KLogCallEventTypeUid);
58 event->SetRemoteParty(KTestRemoteParty1);
59 event->SetDirection(KTestDirection1);
60 event->SetDurationType(KTestDurationType1);
61 event->SetDuration(KTestDuration1);
62 event->SetStatus(KTestStatus1);
63 event->SetSubject(KTestSubject1);
64 event->SetNumber(KTestNumber1);
65 event->SetContact(KTestContact1);
66 event->SetLink(KTestLink1);
67 event->SetDataL(KTestData1);
68 event->SetFlags(KTestFlags1);
70 // *** Notification when change made - no delay
72 client->NotifyChange(0, active1->iStatus);
76 client->AddEvent(*event, active2->iStatus);
78 // Not sure which will finish first
79 CActiveScheduler::Start();
80 if (!active1->IsActive())
82 TEST(active2->IsActive());
83 TEST(active1->iStatus.Int() >= 0);
84 CActiveScheduler::Start();
85 TEST2(active2->iStatus.Int(), KErrNone);
89 TEST2(active2->iStatus.Int(), KErrNone);
90 CActiveScheduler::Start();
91 TEST(active1->iStatus.Int() >= 0);
96 before.UniversalTime();
98 const TTimeIntervalMicroSeconds32 delay = 3000000;
100 // *** Notification when change made - with long delay
102 client->NotifyChange(delay, active1->iStatus);
106 client->AddEvent(*event, active2->iStatus);
108 // We can be fairly certain that the function will complete first
109 CActiveScheduler::Start();
110 TEST2(active2->iStatus.Int(), KErrNone);
111 TEST(active1->IsActive());
112 CActiveScheduler::Start();
113 TEST(active1->iStatus.Int() >= 0);
115 User::After(1000000);
119 after.UniversalTime();
120 TEST(before + delay <= after);
122 before.UniversalTime();
124 // *** Notification when change made - with long delay - multiple changes
126 client->NotifyChange(delay, active1->iStatus);
130 client->AddEvent(*event, active2->iStatus);
132 // The function should complete
133 CActiveScheduler::Start();
134 TEST(active1->IsActive());
135 TEST2(active2->iStatus.Int(), KErrNone);
139 client->ChangeEvent(*event, active2->iStatus);
141 // The function should complete
142 CActiveScheduler::Start();
143 TEST(active1->IsActive());
144 TEST2(active2->iStatus.Int(), KErrNone);
146 // The notification should complete
147 CActiveScheduler::Start();
148 TEST(active1->iStatus.Int() >= 0);
151 User::After(1000000);
155 after.UniversalTime();
156 TEST(before + TTimeIntervalMicroSeconds32(delay) <= after);
158 // *** Notification when change made - after long delay
160 client->NotifyChange(delay, active1->iStatus);
162 // Wait around for a time equal to the delay
163 CTestTimer* timer = CTestTimer::NewL();
165 CActiveScheduler::Start();
170 client->AddEvent(*event, active2->iStatus);
172 // Not sure which will finish first
173 CActiveScheduler::Start();
174 if (!active1->IsActive())
176 TEST(active2->IsActive());
177 TEST(active1->iStatus.Int() >= 0);
178 CActiveScheduler::Start();
179 TEST2(active2->iStatus.Int(), KErrNone);
183 TEST2(active2->iStatus.Int(), KErrNone);
184 CActiveScheduler::Start();
185 TEST(active1->iStatus.Int() >= 0);
188 CleanupStack::PopAndDestroy(4); // event, active2, active1, client
192 @SYMTestCaseID SYSLIB-LOGENG-CT-0927
193 @SYMTestCaseDesc Tests for CLogClient::NotifyChangeCancel() function
194 @SYMTestPriority High
195 @SYMTestActions Tests for cancelling of any outstanding notification requests for changes to log engine database
196 @SYMTestExpectedResults Test must not fail
199 LOCAL_C void TestCancelNotificationL()
201 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0927 "));
202 CLogClient* client = CLogClient::NewL(theFs);
203 CleanupStack::PushL(client);
205 CTestActive* active1 = new(ELeave)CTestActive;
206 CleanupStack::PushL(active1);
208 // *** Cancel without delay
210 client->NotifyChange(0, active1->iStatus);
211 client->NotifyChangeCancel();
212 CActiveScheduler::Start();
213 TEST2(active1->iStatus.Int(), KErrCancel);
215 const TInt delay = 3000000;
217 // *** Cancel with delay
219 client->NotifyChange(delay, active1->iStatus);
221 // Wait around for a bit
222 CTestTimer* timer = CTestTimer::NewL();
223 timer->After(delay / 2);
224 CActiveScheduler::Start();
227 client->NotifyChangeCancel();
228 CActiveScheduler::Start();
229 TEST2(active1->iStatus.Int(), KErrCancel);
231 // *** Cancel with long delay
233 client->NotifyChange(delay, active1->iStatus);
235 // Wait around for a bit
236 timer = CTestTimer::NewL();
237 timer->After(delay * 2);
238 CActiveScheduler::Start();
241 client->NotifyChangeCancel();
242 CActiveScheduler::Start();
243 TEST2(active1->iStatus.Int(), KErrCancel);
245 // *** Cancel after change
246 CLogEvent* event = CLogEvent::NewL();
247 CleanupStack::PushL(event);
248 event->SetEventType(KLogCallEventTypeUid);
251 client->NotifyChange(delay, active1->iStatus);
253 CTestActive* active2 = new(ELeave)CTestActive;
254 CleanupStack::PushL(active2);
257 client->AddEvent(*event, active2->iStatus);
258 CActiveScheduler::Start();
259 TEST(active1->IsActive());
260 TEST2(active2->iStatus.Int(), KErrNone);
262 client->NotifyChangeCancel();
263 CActiveScheduler::Start();
264 TEST2(active1->iStatus.Int(), KErrCancel);
266 // *** Cancel after change and delay
268 client->NotifyChange(delay, active1->iStatus);
270 // Wait around for a bit
271 timer = CTestTimer::NewL();
272 timer->After(delay / 2);
273 CActiveScheduler::Start();
277 client->AddEvent(*event, active2->iStatus);
278 CActiveScheduler::Start();
279 TEST(active1->IsActive());
280 TEST2(active2->iStatus.Int(), KErrNone);
282 client->NotifyChangeCancel();
283 CActiveScheduler::Start();
284 TEST2(active1->iStatus.Int(), KErrCancel);
286 // *** Cancel after change and delay
288 client->NotifyChange(delay, active1->iStatus);
291 client->AddEvent(*event, active2->iStatus);
292 CActiveScheduler::Start();
293 TEST(active1->IsActive());
294 TEST2(active2->iStatus.Int(), KErrNone);
296 // Wait around for a bit
297 timer = CTestTimer::NewL();
298 timer->After(delay / 2);
299 CActiveScheduler::Start();
302 client->NotifyChangeCancel();
303 CActiveScheduler::Start();
304 TEST2(active1->iStatus.Int(), KErrCancel);
306 // *** Cancel when not active
307 client->NotifyChangeCancel();
309 CleanupStack::PopAndDestroy(4); // active2, event, active, client
313 @SYMTestCaseID SYSLIB-LOGENG-CT-0928
314 @SYMTestCaseDesc Tests for notification requests on view purge
315 @SYMTestPriority High
316 @SYMTestActions Notify changes on log view event
317 @SYMTestExpectedResults Test must not fail
320 LOCAL_C void TestViewPurgeNotifyL()
322 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0928 "));
323 CTestTimer* timer = CTestTimer::NewL();
324 CleanupStack::PushL(timer);
326 CTestActive* active = new(ELeave)CTestActive();
327 CleanupStack::PushL(active);
329 CLogClient* client = CLogClient::NewL(theFs);
330 CleanupStack::PushL(client);
332 CLogViewEvent* view = CLogViewEvent::NewL(*client);
333 CleanupStack::PushL(view);
335 CLogFilter* filter = CLogFilter::NewL();
336 CleanupStack::PushL(filter);
338 CTestActive* notify = new(ELeave)CTestActive;
339 CleanupStack::PushL(notify);
343 client->NotifyChange(1000000, notify->iStatus);
345 // Wait for 10 seconds
346 TEST(notify->IsActive());
347 timer = CTestTimer::NewL();
348 timer->After(7000000);
349 CActiveScheduler::Start();
353 TEST(notify->IsActive());
354 if (view->SetFilterL(*filter, active->iStatus))
357 CActiveScheduler::Start();
358 TEST(view->CountL() > 0);
361 // Wait for 10 seconds
362 TEST(notify->IsActive());
363 timer = CTestTimer::NewL();
364 timer->After(10000000);
365 CActiveScheduler::Start();
368 // We shouldn't be notified because nothing has changed
369 TEST(notify->IsActive());
370 client->NotifyChangeCancel();
371 CActiveScheduler::Start();
372 TEST2(notify->iStatus.Int(), KErrCancel);
374 CleanupStack::PopAndDestroy(6); // notify, client, filter, view, active, timer
378 INC045485 - AV20 Messaging App crashes when attempting to write New SMS
380 @SYMTestCaseID SYSLIB-LOGENG-CT-0929
381 @SYMTestCaseDesc Tests for defect number INC045485L.
382 @SYMTestPriority High
383 @SYMTestActions Tests by adding a fax event type
384 @SYMTestExpectedResults Test must not fail
387 LOCAL_C void INC045485L()
389 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0929 "));
390 const TInt KEventCnt = 5;//test events count
391 const TInt KSizeOfEventData = 400;//should be bigger than KLogSizeOfEventGuess constant
392 //Create client, active, event
393 CLogClient* client = CLogClient::NewL(theFs);
394 CleanupStack::PushL(client);
395 CTestActive* active = new (ELeave) CTestActive;
396 CleanupStack::PushL(active);
397 CLogEvent* event = CLogEvent::NewL();
398 CleanupStack::PushL(event);
399 //Add KEventCnt events
400 for(TInt i=0;i<KEventCnt;++i)
402 event->SetId(0x13579 + i);
403 event->SetEventType(KLogFaxEventTypeUid);
404 TUint8 buf[KSizeOfEventData];
405 Mem::Fill(buf, KSizeOfEventData, TChar('1' + i));
406 TPtr8 ptr(buf, KSizeOfEventData, KSizeOfEventData);
407 event->SetDataL(ptr);
410 client->AddEvent(*event, active->iStatus);
411 CActiveScheduler::Start();
412 TEST(!active->IsActive());
414 TEST2(active->iStatus.Int(), KErrNone);
416 //Create LogViewEvent, CLogFilter
417 CLogViewEvent* view = CLogViewEvent::NewL(*client);
418 CleanupStack::PushL(view);
419 CLogFilter* filter = CLogFilter::NewL();
420 CleanupStack::PushL(filter);
421 filter->SetEventType(KLogFaxEventTypeUid);//the same as the type UID of added events
423 if(view->SetFilterL(*filter, active->iStatus))
426 CActiveScheduler::Start();
427 TEST(view->CountL() == KEventCnt);
431 TEST(view->FirstL(active->iStatus));
435 CActiveScheduler::Start();
436 TEST2(active->iStatus.Int(), KErrNone);//If the defect is not fixed this check fails with "KErrOverflow"
437 const CLogEvent& e = view->Event();
438 TheTest.Printf(_L("View Entry[%d]: Id:%d, Type:%x\n"), j, e.Id(), e.EventType().iUid);
439 const TDesC8& data = e.Data();
440 TEST(data.Length() == KSizeOfEventData);
442 for(TInt k=0;k<KSizeOfEventData;++k)
445 TEST(c >= TChar('1') && c < TChar('1' + KEventCnt));
449 while(view->NextL(active->iStatus));
450 //Destroy filter, view, event, active, client
451 CleanupStack::PopAndDestroy(filter);
452 CleanupStack::PopAndDestroy(view);
453 CleanupStack::PopAndDestroy(event);
454 CleanupStack::PopAndDestroy(active);
455 CleanupStack::PopAndDestroy(client);
458 //DEF060381 Propagated: Receiving Chinese SMSes causes the battery to drain too fast
459 static void DEF060381L()
461 const TInt KSizeOfEventData = 1025; //should be bigger than KLogSizeOfEventGuess constant
463 //Create two clients. The first one will be used to send one message to the server,
464 //which length is too big. The second client will be used to receive the message from
466 //If the defect is not fixed, the function hangs and its return point is never reached.
467 CLogClient* client1 = CLogClient::NewL(theFs);
468 CleanupStack::PushL(client1);
470 CLogClient* client2 = CLogClient::NewL(theFs);
471 CleanupStack::PushL(client2);
473 CTestActive* active = new (ELeave) CTestActive;
474 CleanupStack::PushL(active);
476 //Create one SMS event, which holds a block of data with size bigger than the default
477 //size of the client side buffer (KLogSizeOfEventGuess).
478 CLogEvent* event = CLogEvent::NewL();
479 CleanupStack::PushL(event);
481 event->SetId(0x9991118);
482 event->SetEventType(KLogShortMessageEventTypeUid);
483 TUint8 buf[KSizeOfEventData];
484 for(TInt i=0;i<KSizeOfEventData;++i)
486 buf[i] = static_cast <TUint8> (i % 256);
488 TPtr8 ptr(buf, KSizeOfEventData, KSizeOfEventData);
489 event->SetDataL(ptr);
491 //Send the created event to the server unsing the first client.
493 client1->AddEvent(*event, active->iStatus);
494 CActiveScheduler::Start();
495 TEST(!active->IsActive());
496 TEST2(active->iStatus.Int(), KErrNone);
498 //Create a view using the second client.
499 //Create a filter for SMS messages.
500 CLogViewEvent* view = CLogViewEvent::NewL(*client2);
501 CleanupStack::PushL(view);
502 CLogFilter* filter = CLogFilter::NewL();
503 CleanupStack::PushL(filter);
504 filter->SetEventType(KLogShortMessageEventTypeUid);//the same as the type UID of added events
506 if(view->SetFilterL(*filter, active->iStatus))
509 CActiveScheduler::Start();//Here the test fucntion hangs and never returns, if the defect is not fixed.
510 TEST(view->CountL() == 1);
514 TEST(view->FirstL(active->iStatus));
518 CActiveScheduler::Start();
519 TEST2(active->iStatus.Int(), KErrNone);
520 const CLogEvent& e = view->Event();
521 TheTest.Printf(_L("View Entry[%d]: Id:%d, Type:%x\n"), j, e.Id(), e.EventType().iUid);
522 const TDesC8& data = e.Data();
523 TEST(data.Length() == KSizeOfEventData);
525 for(TInt k=0;k<KSizeOfEventData;++k)
528 TEST(c == static_cast <TUint8> (k % 256));
532 while(view->NextL(active->iStatus));
534 CleanupStack::PopAndDestroy(filter);
535 CleanupStack::PopAndDestroy(view);
536 CleanupStack::PopAndDestroy(event);
537 CleanupStack::PopAndDestroy(active);
538 CleanupStack::PopAndDestroy(client2);
539 CleanupStack::PopAndDestroy(client1);
544 TestUtils::Initialize(_L("t_lognotify"));
545 TestUtils::DeleteDatabaseL();
547 TheTest.Start(_L("Notifications"));
549 theLog.Write(_L8("Test 1 OK\n"));
551 TheTest.Next(_L("INC045485"));
554 TheTest.Next(_L("Cancelling Notifications"));
555 TestCancelNotificationL();
556 theLog.Write(_L8("Test 2 OK\n"));
558 TheTest.Next(_L("Notify with View Purge"));
559 TestViewPurgeNotifyL();
560 theLog.Write(_L8("Test 3 OK\n"));
562 TheTest.Next(_L("DEF060381"));