|
1 // Copyright (c) 1997-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 // |
|
15 |
|
16 #include "t_currentdb.h" |
|
17 |
|
18 // System includes |
|
19 #include <e32std.h> |
|
20 #include <e32twin.h> |
|
21 #include <e32test.h> |
|
22 #include <cntdbobs.h> |
|
23 #include "coreappstest/testserver.h" |
|
24 |
|
25 // User includes |
|
26 #include "T_UTILS.H" |
|
27 |
|
28 // Globals |
|
29 static RTest TheTest(_L("T_CURRENTDB - Test CntModel current DB support")); |
|
30 static CTrapCleanup* TheCleanup; |
|
31 |
|
32 // Constants (literal) |
|
33 _LIT(KThreadTestFormat, "\nThread %d running test %d\n"); |
|
34 _LIT(KThreadTestOkFormat, "\nThread %d completed test %d OK\n"); |
|
35 |
|
36 // Configure database location |
|
37 _LIT(KTestDatabaseFile, "C:Contacts.cdb"); |
|
38 _LIT(KTestDatabaseFile2, "C:LotsOfContacts.cdb"); |
|
39 |
|
40 // Configure .ini file location |
|
41 _LIT(KContactsModelIniFile, "c:\\private\\10003A73\\CntModel.ini"); |
|
42 |
|
43 _LIT(KTestSemaphoreOne, "T_CURRENTDB_SEMAPHORE_ONE"); |
|
44 _LIT(KTestSemaphoreTwo, "T_CURRENTDB_SEMAPHORE_TWO"); |
|
45 _LIT(KSpeedDialPhoneNumber, "020 11111111"); |
|
46 _LIT(KSpeedDialPhoneNumber2, "020 22222222"); |
|
47 const TInt KSpeedDialPositionOne = 1; |
|
48 const TInt KSpeedDialPositionTwo = 2; |
|
49 |
|
50 const TInt KTestSteps = 100; |
|
51 |
|
52 // |
|
53 // -------> CTestActiveScheduler (header) |
|
54 // |
|
55 class CTestActiveScheduler : public CActiveScheduler |
|
56 { |
|
57 // |
|
58 public: |
|
59 // |
|
60 void Error (TInt aError) const; |
|
61 }; |
|
62 |
|
63 |
|
64 // |
|
65 // -------> CTestActiveScheduler (source) |
|
66 // |
|
67 void CTestActiveScheduler::Error(TInt aError) const |
|
68 { |
|
69 User::Panic(_L("AScheduler"),aError); |
|
70 } |
|
71 |
|
72 |
|
73 // |
|
74 // -------> CTestBase (source) |
|
75 // |
|
76 CTestBase::CTestBase(CTestManager& aTester, TInt aClientNumber, TThreadPriority aThreadPriority, TInt aPriority) |
|
77 : CActive(aPriority), iTestCoordinator(aTester), iClientNumber(aClientNumber), iThreadPriority(aThreadPriority) |
|
78 { |
|
79 } |
|
80 |
|
81 CTestBase::~CTestBase() |
|
82 { |
|
83 Cancel(); |
|
84 iThread.Close(); |
|
85 } |
|
86 |
|
87 void CTestBase::ConstructL(const TDesC& aName) |
|
88 { |
|
89 User::LeaveIfError(iThread.Create(aName, ThreadFunction, KDefaultStackSize, 0x2000, 0x20000, this, EOwnerThread)); |
|
90 iThread.Resume(); |
|
91 iThread.SetPriority(iThreadPriority); |
|
92 } |
|
93 |
|
94 // |
|
95 // |
|
96 // |
|
97 |
|
98 void CTestBase::Complete(TInt aReason) |
|
99 { |
|
100 // Complete the request with the specified reason. |
|
101 __ASSERT_ALWAYS(IsActive() && iStatus.Int() == KRequestPending, User::Invariant()); |
|
102 TRequestStatus* status = &iStatus; |
|
103 iThread.RequestComplete(status, aReason); |
|
104 } |
|
105 |
|
106 // |
|
107 // |
|
108 // |
|
109 |
|
110 void CTestBase::RunL() |
|
111 { |
|
112 _LIT(KThreadTestCompleteFormat, "Thread %d finished tests"); |
|
113 |
|
114 if (iWaiting || iWaitingForAnyEvent) |
|
115 { |
|
116 CActiveScheduler::Stop(); // stop nested scheduler |
|
117 iWaiting = iWaitingForAnyEvent = EFalse; |
|
118 return; |
|
119 } |
|
120 |
|
121 // Increment test number |
|
122 ++iCurrentTest; |
|
123 |
|
124 if (iStatus.Int() < KErrNone) // Can this happen? |
|
125 { |
|
126 User::Invariant(); |
|
127 } |
|
128 |
|
129 switch(iStatus.Int()) |
|
130 { |
|
131 case EEndTests: |
|
132 { |
|
133 TBuf<50> buf; |
|
134 buf.Format(KThreadTestCompleteFormat, iClientNumber); |
|
135 iTest->Next(buf); |
|
136 CActiveScheduler::Stop(); |
|
137 break; |
|
138 } |
|
139 default: |
|
140 { |
|
141 // Call the framework to handle the specific test number |
|
142 DoTestL(iStatus.Int()); |
|
143 |
|
144 TBuf<200> buf; |
|
145 buf.Format(KThreadTestOkFormat, iClientNumber, iStatus.Int()); |
|
146 iTest->Printf(buf); |
|
147 |
|
148 // Re issue another asynch request |
|
149 ReadyForNextTest(); |
|
150 break; |
|
151 } |
|
152 } |
|
153 } |
|
154 |
|
155 void CTestBase::DoCancel() |
|
156 { |
|
157 iWaitTimer.Cancel(); |
|
158 |
|
159 // Cancel any outstanding request |
|
160 if (!(iWaiting || iWaitingForAnyEvent)) |
|
161 { |
|
162 Complete(KErrCancel); |
|
163 } |
|
164 } |
|
165 |
|
166 // |
|
167 // |
|
168 // |
|
169 |
|
170 TInt CTestBase::ThreadFunction(TAny* aParam) |
|
171 { |
|
172 CTestBase* self = STATIC_CAST(CTestBase*, aParam); |
|
173 |
|
174 // Prepare the stuff required before we start the |
|
175 // active scheduler. |
|
176 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
177 |
|
178 if (!cleanup) |
|
179 { |
|
180 return KErrNoMemory; |
|
181 } |
|
182 |
|
183 // Call virtual handler which does anything that needs doing as |
|
184 // a result of the thread function from being created. |
|
185 TRAPD(err, self->RunTestsL()); |
|
186 |
|
187 delete cleanup; |
|
188 return err; |
|
189 } |
|
190 |
|
191 void CTestBase::RunTestsL() |
|
192 { |
|
193 User::LeaveIfError(iWaitTimer.CreateLocal()); |
|
194 |
|
195 OpenSemaphoreL(); |
|
196 |
|
197 HandleThreadCreationL(); |
|
198 ReadyForNextTest(); |
|
199 CActiveScheduler::Start(); |
|
200 HandleThreadDeletionL(); |
|
201 |
|
202 CloseSemaphore(); |
|
203 |
|
204 iWaitTimer.Cancel(); |
|
205 iWaitTimer.Close(); |
|
206 } |
|
207 |
|
208 TInt CTestBase::HandleThreadCreationL() |
|
209 { |
|
210 // Create and name an RTest |
|
211 TBuf<100> threadName; |
|
212 threadName.Format(_L("Test thread %d"), iClientNumber); |
|
213 iTest = new(ELeave) RTest(threadName); |
|
214 iTest->Start(_L("Starting test")); |
|
215 |
|
216 // Position our console window |
|
217 TSize size = iTest->Console()->ScreenSize(); |
|
218 size.iWidth = size.iWidth - 4; |
|
219 size.iHeight = (size.iHeight / 2) - 3; |
|
220 |
|
221 iConsole = Console::NewL(threadName, size); |
|
222 delete (CONST_CAST(RTest*, iTest)->Console()); |
|
223 iTest->SetConsole(iConsole); |
|
224 iConsole->ClearScreen(); |
|
225 |
|
226 // Create contacts db session |
|
227 iTest->Next(_L("Creating contacts test utility")); |
|
228 iContactsTest = new(ELeave) CCntTest(); |
|
229 OpenDatabaseL(); |
|
230 |
|
231 // Add the CTestBase object |
|
232 // to it. Has to be done in this function, otherwise the AO can |
|
233 // end up being added to the wrong active scheduler |
|
234 CActiveScheduler::Add(this); |
|
235 |
|
236 return KErrNone; |
|
237 } |
|
238 |
|
239 void CTestBase::HandleThreadDeletionL() |
|
240 { |
|
241 iContactsTest->EndTestLib(KErrNone); |
|
242 } |
|
243 |
|
244 // |
|
245 // |
|
246 // |
|
247 |
|
248 void CTestBase::ReadyForNextTest() |
|
249 // |
|
250 // Requests another test be executed |
|
251 // |
|
252 { |
|
253 __ASSERT_ALWAYS(!iWaiting && !iWaitingForAnyEvent, User::Invariant()); |
|
254 SetActive(); |
|
255 iStatus = KRequestPending; |
|
256 } |
|
257 |
|
258 void CTestBase::WaitForContactsEvent(TContactDbObserverEventType aEvent, TInt aTimeInSecondsToWaitFor) |
|
259 { |
|
260 iWaiting = ETrue; |
|
261 iEvent = aEvent; |
|
262 TTimeIntervalMicroSeconds32 time(aTimeInSecondsToWaitFor * 1000000); |
|
263 iWaitTimer.After(iStatus, time); |
|
264 SetActive(); |
|
265 CActiveScheduler::Start(); |
|
266 } |
|
267 |
|
268 void CTestBase::WaitForAnyContactsEvent(TInt aTimeInSecondsToWaitFor) |
|
269 { |
|
270 iWaitingForAnyEvent = ETrue; |
|
271 TTimeIntervalMicroSeconds32 time(aTimeInSecondsToWaitFor * 1000000); |
|
272 iWaitTimer.After(iStatus, time); |
|
273 SetActive(); |
|
274 CActiveScheduler::Start(); |
|
275 } |
|
276 |
|
277 void CTestBase::HandleDatabaseEventL(TContactDbObserverEvent aEvent) |
|
278 { |
|
279 __ASSERT_ALWAYS(iWaiting || iWaitingForAnyEvent, User::Invariant()); |
|
280 |
|
281 iLastEvent=aEvent; |
|
282 switch(aEvent.iType) |
|
283 { |
|
284 case EContactDbObserverEventNull: |
|
285 iTest->Printf(_L("Event: EContactDbObserverEventNull\n")); |
|
286 break; |
|
287 case EContactDbObserverEventUnused: |
|
288 iTest->Printf(_L("Event: EContactDbObserverEventUnused\n")); |
|
289 break; |
|
290 case EContactDbObserverEventContactChanged: |
|
291 iTest->Printf(_L("Event: EContactDbObserverEventContactChanged\n")); |
|
292 break; |
|
293 case EContactDbObserverEventContactDeleted: |
|
294 iTest->Printf(_L("Event: EContactDbObserverEventContactDeleted\n")); |
|
295 break; |
|
296 case EContactDbObserverEventContactAdded: |
|
297 iTest->Printf(_L("Event: EContactDbObserverEventContactAdded\n")); |
|
298 break; |
|
299 case EContactDbObserverEventUnknownChanges: |
|
300 iTest->Printf(_L("Event: EContactDbObserverEventUnknownChanges\n")); |
|
301 break; |
|
302 case EContactDbObserverEventRecover: |
|
303 iTest->Printf(_L("Event: EContactDbObserverEventRecover\n")); |
|
304 break; |
|
305 case EContactDbObserverEventRollback: |
|
306 iTest->Printf(_L("Event: EContactDbObserverEventRollback\n")); |
|
307 break; |
|
308 case EContactDbObserverEventTablesClosed: |
|
309 iTest->Printf(_L("Event: EContactDbObserverEventTablesClosed\n")); |
|
310 break; |
|
311 case EContactDbObserverEventTablesOpened: |
|
312 iTest->Printf(_L("Event: EContactDbObserverEventTablesOpened\n")); |
|
313 break; |
|
314 case EContactDbObserverEventTemplateChanged: |
|
315 iTest->Printf(_L("Event: EContactDbObserverEventTemplateChanged\n")); |
|
316 break; |
|
317 case EContactDbObserverEventTemplateDeleted: |
|
318 iTest->Printf(_L("Event: EContactDbObserverEventTemplateDeleted\n")); |
|
319 break; |
|
320 case EContactDbObserverEventTemplateAdded: |
|
321 iTest->Printf(_L("Event: EContactDbObserverEventTemplateAdded\n")); |
|
322 break; |
|
323 case EContactDbObserverEventCurrentItemDeleted: |
|
324 iTest->Printf(_L("Event: EContactDbObserverEventCurrentItemDeleted\n")); |
|
325 break; |
|
326 case EContactDbObserverEventCurrentItemChanged: |
|
327 (*iTest)(aEvent.iContactId != KNullContactId); |
|
328 iTest->Printf(_L("Event: EContactDbObserverEventCurrentItemChanged\n")); |
|
329 break; |
|
330 case EContactDbObserverEventOwnCardChanged: |
|
331 iTest->Printf(_L("Event: EContactDbObserverEventOwnCardChanged\n")); |
|
332 break; |
|
333 case EContactDbObserverEventPreferredTemplateChanged: |
|
334 iTest->Printf(_L("Event: EContactDbObserverEventPreferredTemplateChanged\n")); |
|
335 break; |
|
336 case EContactDbObserverEventOwnCardDeleted: |
|
337 iTest->Printf(_L("Event: EContactDbObserverEventOwnCardDeleted\n")); |
|
338 break; |
|
339 case EContactDbObserverEventGroupAdded: |
|
340 iTest->Printf(_L("Event: EContactDbObserverEventGroupAdded\n")); |
|
341 break; |
|
342 case EContactDbObserverEventGroupChanged: |
|
343 iTest->Printf(_L("Event: EContactDbObserverEventGroupChanged\n")); |
|
344 break; |
|
345 case EContactDbObserverEventGroupDeleted: |
|
346 iTest->Printf(_L("Event: EContactDbObserverEventGroupDeleted\n")); |
|
347 break; |
|
348 case EContactDbObserverEventCurrentDatabaseChanged: |
|
349 iTest->Printf(_L("Event: EContactDbObserverEventCurrentDatabaseChanged\n")); |
|
350 break; |
|
351 case EContactDbObserverEventSpeedDialsChanged: |
|
352 iTest->Printf(_L("Event: EContactDbObserverEventSpeedDialsChanged\n")); |
|
353 break; |
|
354 default: |
|
355 iTest->Printf(_L("Unhandled Event\n")); |
|
356 User::Invariant(); |
|
357 } |
|
358 |
|
359 if ((aEvent.iType == iEvent) || iWaitingForAnyEvent) |
|
360 { |
|
361 Cancel(); |
|
362 iWaiting = iWaitingForAnyEvent = EFalse; |
|
363 CActiveScheduler::Stop(); |
|
364 return; |
|
365 } |
|
366 else if (aEvent.iType != iEvent) |
|
367 { |
|
368 iTest->Printf(_L("Got an Unexpected Event.\n")); |
|
369 } |
|
370 |
|
371 |
|
372 } |
|
373 |
|
374 void CTestBase::OpenSemaphoreL() |
|
375 { |
|
376 TInt error = iSemaphoreOne.CreateGlobal(KTestSemaphoreOne(), 0); |
|
377 if (error == KErrAlreadyExists || error == KErrNone) |
|
378 { |
|
379 iSemaphoreOne.OpenGlobal(KTestSemaphoreOne()); |
|
380 } |
|
381 else |
|
382 { |
|
383 User::Leave(error); |
|
384 } |
|
385 |
|
386 error = iSemaphoreTwo.CreateGlobal(KTestSemaphoreTwo(), 0); |
|
387 if (error == KErrAlreadyExists || error == KErrNone) |
|
388 { |
|
389 iSemaphoreTwo.OpenGlobal(KTestSemaphoreTwo()); |
|
390 } |
|
391 else |
|
392 { |
|
393 User::Leave(error); |
|
394 } |
|
395 } |
|
396 |
|
397 void CTestBase::CloseSemaphore() |
|
398 { |
|
399 iSemaphoreOne.Close(); |
|
400 iSemaphoreTwo.Close(); |
|
401 } |
|
402 |
|
403 |
|
404 // |
|
405 // -------> CTestThreadOne (source) |
|
406 // |
|
407 CTestThreadOne::CTestThreadOne(CTestManager& aTester, TInt aClientNumber, TThreadPriority aThreadPriority, TInt aPriority) |
|
408 : CTestBase(aTester, aClientNumber, aThreadPriority, aPriority) |
|
409 { |
|
410 } |
|
411 |
|
412 CTestThreadOne* CTestThreadOne::NewL(TInt aClientNumber, const TDesC& aName, CTestManager& aTester, TThreadPriority aThreadPriority, TInt aPriority) |
|
413 { |
|
414 CTestThreadOne* self = new(ELeave) CTestThreadOne(aTester, aClientNumber, aThreadPriority, aPriority); |
|
415 CleanupStack::PushL(self); |
|
416 self->ConstructL(aName); |
|
417 CleanupStack::Pop(); // self |
|
418 return self; |
|
419 } |
|
420 |
|
421 void CTestThreadOne::OpenDatabaseL() |
|
422 { |
|
423 TBuf<200> buf; |
|
424 buf.Format(_L("Constructing test utilities with database set as %S"), &KTestDatabaseFile); |
|
425 iTest->Next(buf); |
|
426 iContactsTest->ConstructL(*iTest, KTestDatabaseFile); |
|
427 } |
|
428 |
|
429 // |
|
430 // |
|
431 // |
|
432 |
|
433 void CTestThreadOne::DoTestL(TInt aTestNumber) |
|
434 { |
|
435 TBuf<50> buf; |
|
436 buf.Format(KThreadTestFormat, iClientNumber, aTestNumber); |
|
437 iTest->Next(buf); |
|
438 |
|
439 switch(aTestNumber) |
|
440 { |
|
441 case ETest1: |
|
442 DoTest1L(); |
|
443 break; |
|
444 case ETest2: |
|
445 DoTest2L(); |
|
446 break; |
|
447 case ETest3: |
|
448 DoTest3L(); |
|
449 break; |
|
450 case ETest4: |
|
451 DoTest4L(); |
|
452 break; |
|
453 case ETest5: |
|
454 DoTest5L(); |
|
455 break; |
|
456 case ETest6: |
|
457 DoTest6L(); |
|
458 break; |
|
459 case ETest7: |
|
460 DoTest7L(); |
|
461 break; |
|
462 case ETest8: |
|
463 DoTest8L(); |
|
464 break; |
|
465 case ETest9: |
|
466 DoTest9L(); |
|
467 break; |
|
468 default: |
|
469 User::Invariant(); |
|
470 } |
|
471 } |
|
472 |
|
473 // |
|
474 // |
|
475 // |
|
476 |
|
477 void CTestThreadOne::DoTest1L() |
|
478 { |
|
479 // This thread has a higher priority than thread 2 so it should run first, |
|
480 // hence this test should work. |
|
481 iSemaphoreOne.Wait(); |
|
482 |
|
483 iTest->Next(_L("Opening the database and check the current db is null\n")); |
|
484 iContactsTest->OpenDatabaseL(); |
|
485 |
|
486 iTest->Printf(_L("Fetching the current database...\n")); |
|
487 TFileName currentDb; |
|
488 User::LeaveIfError(iContactsTest->Db()->GetCurrentDatabase(currentDb)); |
|
489 iTest->Printf(_L("Current database reported as %S\n"), ¤tDb); |
|
490 (*iTest)(currentDb.CompareF(KNullDesC) == 0); |
|
491 |
|
492 // Because there was no ini file found, we now set this database to be the |
|
493 // current. |
|
494 iTest->Printf(_L("\tSetting thread one's database as the current db\n")); |
|
495 User::LeaveIfError(iContactsTest->Db()->SetCurrentDatabase(KTestDatabaseFile)); |
|
496 |
|
497 // Check that it is the current db now |
|
498 User::LeaveIfError(iContactsTest->Db()->GetCurrentDatabase(currentDb)); |
|
499 iTest->Printf(_L("Current database reported as %S\n"), ¤tDb); |
|
500 (*iTest)(currentDb.CompareF(KTestDatabaseFile) == 0); |
|
501 iSemaphoreTwo.Signal(); |
|
502 |
|
503 // Pause this thread |
|
504 iSemaphoreTwo.Signal(); |
|
505 iSemaphoreOne.Wait(); |
|
506 } |
|
507 |
|
508 void CTestThreadOne::DoTest2L() |
|
509 { |
|
510 iSemaphoreOne.Wait(); |
|
511 iSemaphoreTwo.Signal(); |
|
512 iTest->Next(_L("\tWaiting for thread 2 to change current db\n")); |
|
513 // Thread two is going to change the current database to 'it's' db. |
|
514 // Wait for notification... |
|
515 |
|
516 // !! Why on Earth do we need one of these? Talk about bad design. |
|
517 CContactChangeNotifier* changeNotifier = CContactChangeNotifier::NewL(*iContactsTest->Db(), this); |
|
518 CleanupStack::PushL(changeNotifier); |
|
519 WaitForContactsEvent(EContactDbObserverEventCurrentDatabaseChanged); |
|
520 CleanupStack::PopAndDestroy(); // changeNotifier |
|
521 iTest->Printf(_L("\tCurrent database change was reported correctly\n")); |
|
522 |
|
523 // Pause this thread |
|
524 iSemaphoreTwo.Signal(); |
|
525 iSemaphoreOne.Wait(); |
|
526 } |
|
527 |
|
528 void CTestThreadOne::DoTest3L() |
|
529 { |
|
530 iSemaphoreOne.Wait(); |
|
531 |
|
532 iTest->Next(_L("Setting the current db a lot of times\n")); |
|
533 for(TInt i = 0; i < KTestSteps; ++i) |
|
534 { |
|
535 // Open and close our database setting it as the default |
|
536 iTest->Printf(_L("\tClosing thread one's database\n")); |
|
537 iContactsTest->CloseDatabase(); |
|
538 |
|
539 iTest->Printf(_L("\tOpening thread one's database\n")); |
|
540 iContactsTest->OpenDatabaseL(); |
|
541 |
|
542 // Set our db |
|
543 iTest->Printf(_L("\tSetting thread one's database as the current db\n")); |
|
544 User::LeaveIfError(iContactsTest->Db()->SetCurrentDatabase(KTestDatabaseFile)); |
|
545 |
|
546 // Pause this thread |
|
547 iSemaphoreTwo.Signal(); |
|
548 iSemaphoreOne.Wait(); |
|
549 } |
|
550 |
|
551 iSemaphoreOne.Wait(); |
|
552 // Check that the current db is KTestDatabaseFile2 (because thread two has just closed the |
|
553 // previous current db, which was KTestDatabaseFile2). |
|
554 TFileName currentDb; |
|
555 User::LeaveIfError(iContactsTest->Db()->GetCurrentDatabase(currentDb)); |
|
556 iTest->Printf(_L("Current database reported as %S\n"), ¤tDb); |
|
557 (*iTest)(currentDb.CompareF(KTestDatabaseFile2) == 0); |
|
558 |
|
559 iTest->Printf(_L("\tClosing thread one's database\n")); |
|
560 iContactsTest->CloseDatabase(); |
|
561 |
|
562 // Pause this thread |
|
563 iSemaphoreTwo.Signal(); |
|
564 iSemaphoreOne.Wait(); |
|
565 } |
|
566 |
|
567 void CTestThreadOne::DoTest4L() |
|
568 { |
|
569 iSemaphoreOne.Wait(); |
|
570 |
|
571 iTest->Next(_L("Checking that after closing all sessions, the current database is remembered\n")); |
|
572 |
|
573 iTest->Printf(_L("\tOpening thread one's database\n")); |
|
574 iContactsTest->OpenDatabaseL(); |
|
575 |
|
576 iTest->Printf(_L("\tClosing thread one's database\n")); |
|
577 iContactsTest->CloseDatabase(); |
|
578 |
|
579 iTest->Printf(_L("\tDeleting CntModel.ini and checking server still able to cope\n")); |
|
580 // Secure Server waits 5s from last connection |
|
581 // to write the .ini file and close |
|
582 User::After(6000000); |
|
583 |
|
584 RPIMTestServer serv; |
|
585 User::LeaveIfError(serv.Connect()); |
|
586 TRAPD(err,serv.DeleteFileL(KContactsModelIniFile)); |
|
587 if (err != KErrNotFound) |
|
588 { |
|
589 User::LeaveIfError(err); |
|
590 } |
|
591 serv.Close(); |
|
592 |
|
593 iTest->Printf(_L("\tAttempt to re-open thread one's database\n")); |
|
594 iContactsTest->OpenDatabaseL(); |
|
595 |
|
596 iTest->Printf(_L("\tCheck that the current database is null in this instance\n")); |
|
597 TFileName currentDb; |
|
598 User::LeaveIfError(iContactsTest->Db()->GetCurrentDatabase(currentDb)); |
|
599 iTest->Printf(_L("\tCurrent database reported as %S\n"), ¤tDb); |
|
600 |
|
601 iTest->Printf(_L("\tSet the current db again\n")); |
|
602 User::LeaveIfError(iContactsTest->Db()->SetCurrentDatabase(KTestDatabaseFile)); |
|
603 |
|
604 iTest->Printf(_L("\tWait for change notification\n")); |
|
605 iTest->Printf(_L("\tClosing thread one's database\n")); |
|
606 iContactsTest->CloseDatabase(); |
|
607 |
|
608 iTest->Printf(_L("\tOpening thread one's database again to check correct restoration of current db\n")); |
|
609 iContactsTest->OpenDatabaseL(); |
|
610 |
|
611 User::LeaveIfError(iContactsTest->Db()->GetCurrentDatabase(currentDb)); |
|
612 iTest->Printf(_L("Current database reported as %S\n"), ¤tDb); |
|
613 (*iTest)(currentDb.CompareF(KTestDatabaseFile) == 0); |
|
614 |
|
615 iTest->Printf(_L("\tClosing thread one's database\n")); |
|
616 iContactsTest->CloseDatabase(); |
|
617 |
|
618 // Pause this thread |
|
619 iSemaphoreTwo.Signal(); |
|
620 iSemaphoreOne.Wait(); |
|
621 } |
|
622 |
|
623 |
|
624 /** |
|
625 * Speeddial test |
|
626 * Open contacts database |
|
627 * Wait for notification that the other client has opened the database |
|
628 * Add a new speeddial |
|
629 * Wait for confirmation the update was received |
|
630 */ |
|
631 void CTestThreadOne::DoTest5L() |
|
632 { |
|
633 iSemaphoreOne.Wait(); |
|
634 |
|
635 iContactsTest->OpenDatabaseL(); |
|
636 |
|
637 iTest->Printf(_L("we've both got the database open")); |
|
638 |
|
639 // Add a contact and set the speeddial |
|
640 CContactItem* item=CContactCard::NewLC(); |
|
641 SetNameL(*item,KUidContactFieldGivenName, KUidContactFieldVCardMapUnusedN, _L("Given"), ETrue); |
|
642 SetNameL(*item,KUidContactFieldPhoneNumber, KUidContactFieldVCardMapTEL, KSpeedDialPhoneNumber, ETrue); |
|
643 SetNameL(*item,KUidContactFieldPhoneNumber, KUidContactFieldVCardMapTEL, _L("020 22222222"), ETrue); |
|
644 SetNameL(*item,KUidContactFieldPhoneNumber, KUidContactFieldVCardMapCELL, _L("07747 065000"), ETrue); |
|
645 TContactItemId id = iContactsTest->Db()->AddNewContactL(*item); |
|
646 iContactsTest->Db()->SetCurrentItem(id); |
|
647 CleanupStack::PopAndDestroy(item); |
|
648 |
|
649 // Set speeddial |
|
650 TInt fieldId=1; |
|
651 const CContactIdArray* sortedItems = iContactsTest->Db()->SortedItemsL(); |
|
652 |
|
653 // First item in position 1 |
|
654 CContactItem* firstItem = iContactsTest->Db()->OpenContactL((*sortedItems)[0]); |
|
655 CleanupStack::PushL(firstItem); |
|
656 iContactsTest->Db()->SetFieldAsSpeedDialL(*firstItem, fieldId, KSpeedDialPositionOne); |
|
657 CleanupStack::PopAndDestroy(firstItem); |
|
658 iSemaphoreTwo.Signal(); |
|
659 iSemaphoreOne.Wait(); |
|
660 |
|
661 TBuf<32> phoneNumber; |
|
662 TContactItemId id2 = iContactsTest->Db()->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
663 TheTest(phoneNumber==KSpeedDialPhoneNumber); |
|
664 TheTest(id2 == id); |
|
665 iTest->Printf(_L("ThreadOne : set contact with speed dial at position 1, awaiting notification.\n")); |
|
666 |
|
667 iContactsTest->Db()->DeleteContactL(id); |
|
668 iContactsTest->Db()->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
669 iTest->Printf(_L("ThreadOne : deleted contact, waiting for notification\n")); |
|
670 |
|
671 iContactsTest->CloseDatabase(); |
|
672 |
|
673 // Pause this thread |
|
674 iSemaphoreTwo.Signal(); |
|
675 iSemaphoreOne.Wait(); |
|
676 } |
|
677 |
|
678 /** |
|
679 * Speeddial test |
|
680 * Open contacts database |
|
681 * Wait for notification that the other client has opened the database |
|
682 * Remove a speeddial |
|
683 * Wait for confirmation the update was received |
|
684 */ |
|
685 void CTestThreadOne::DoTest6L() |
|
686 { |
|
687 iSemaphoreOne.Wait(); |
|
688 |
|
689 iContactsTest->OpenDatabaseL(); |
|
690 iTest->Printf(_L("we've both got the database open")); |
|
691 |
|
692 // Add a contact and set the speeddial |
|
693 CContactItem* item=CContactCard::NewLC(); |
|
694 SetNameL(*item,KUidContactFieldGivenName, KUidContactFieldVCardMapUnusedN, _L("Given"), ETrue); |
|
695 SetNameL(*item,KUidContactFieldPhoneNumber, KUidContactFieldVCardMapTEL, KSpeedDialPhoneNumber, ETrue); |
|
696 SetNameL(*item,KUidContactFieldPhoneNumber, KUidContactFieldVCardMapTEL, _L("020 22222222"), ETrue); |
|
697 SetNameL(*item,KUidContactFieldPhoneNumber, KUidContactFieldVCardMapCELL, _L("07747 065000"), ETrue); |
|
698 TContactItemId id = iContactsTest->Db()->AddNewContactL(*item); |
|
699 iContactsTest->Db()->SetCurrentItem(id); |
|
700 CleanupStack::PopAndDestroy(item); |
|
701 |
|
702 // Set speeddial |
|
703 TInt fieldId=1; |
|
704 const CContactIdArray* sortedItems = iContactsTest->Db()->SortedItemsL(); |
|
705 |
|
706 // First item in position 1 |
|
707 CContactItem* firstItem = iContactsTest->Db()->OpenContactL((*sortedItems)[0]); |
|
708 CleanupStack::PushL(firstItem); |
|
709 iContactsTest->Db()->SetFieldAsSpeedDialL(*firstItem, fieldId, KSpeedDialPositionOne); |
|
710 CleanupStack::PopAndDestroy(firstItem); |
|
711 |
|
712 iSemaphoreTwo.Signal(); |
|
713 iSemaphoreOne.Wait(); |
|
714 |
|
715 TBuf<32> phoneNumber; |
|
716 TContactItemId id2= iContactsTest->Db()->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
717 TheTest(phoneNumber==KSpeedDialPhoneNumber); |
|
718 TheTest(id2==id); |
|
719 iTest->Printf(_L("ThreadOne : set contact with speed dial at position 1, awaiting notification.\n")); |
|
720 |
|
721 iTest->Printf(_L("ThreadOne : removing speed dial that was just added.... ")); |
|
722 iContactsTest->Db()->RemoveSpeedDialFieldL(id, KSpeedDialPositionOne); |
|
723 iContactsTest->Db()->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
724 iTest->Printf(_L("done\n")); |
|
725 |
|
726 iSemaphoreTwo.Signal(); |
|
727 iContactsTest->CloseDatabase(); |
|
728 |
|
729 // Pause this thread |
|
730 iSemaphoreTwo.Signal(); |
|
731 iSemaphoreOne.Wait(); |
|
732 } |
|
733 |
|
734 /** |
|
735 * Group add test |
|
736 * Open contacts database |
|
737 * Wait for notification that the other client has opened the database |
|
738 * Add a new group |
|
739 * Wait for confirmation the update was received |
|
740 * Delete the new group |
|
741 * Wait for confirmation the update was received |
|
742 */ |
|
743 void CTestThreadOne::DoTest7L() |
|
744 { |
|
745 iSemaphoreOne.Wait(); |
|
746 |
|
747 iContactsTest->OpenDatabaseL(); |
|
748 iTest->Printf(_L("we've both got the database open")); |
|
749 |
|
750 CContactItem* tempGroup = iContactsTest->Db()->CreateContactGroupL(_L("NEW GROUP")); |
|
751 delete tempGroup; |
|
752 |
|
753 CContactIdArray* groupIdList = iContactsTest->Db()->GetGroupIdListL(); |
|
754 CleanupStack::PushL(groupIdList); |
|
755 iContactsTest->Db()->DeleteContactL((*groupIdList)[0]); |
|
756 CleanupStack::PopAndDestroy(groupIdList); |
|
757 iContactsTest->CloseDatabase(); |
|
758 iSemaphoreTwo.Signal(); |
|
759 |
|
760 // Pause this thread |
|
761 iSemaphoreTwo.Signal(); |
|
762 iSemaphoreOne.Wait(); |
|
763 } |
|
764 |
|
765 void CTestThreadOne::DoTest8L() |
|
766 { |
|
767 iSemaphoreOne.Wait(); |
|
768 |
|
769 iContactsTest->OpenDatabaseL(); |
|
770 iTest->Printf(_L("we've both got the database open")); |
|
771 |
|
772 // Add a contact and set the speeddial |
|
773 CContactItem* item=CContactCard::NewLC(); |
|
774 SetNameL(*item,KUidContactFieldGivenName, KUidContactFieldVCardMapUnusedN, _L("Given"), ETrue); |
|
775 SetNameL(*item,KUidContactFieldPhoneNumber, KUidContactFieldVCardMapTEL, KSpeedDialPhoneNumber, ETrue); |
|
776 TContactItemId id = iContactsTest->Db()->AddNewContactL(*item); |
|
777 CleanupStack::PopAndDestroy(item); |
|
778 |
|
779 // Set speeddial - Case:1 |
|
780 TInt fieldId=1; |
|
781 CContactItem* firstItem = iContactsTest->Db()->OpenContactL(id); |
|
782 CleanupStack::PushL(firstItem); |
|
783 iContactsTest->Db()->SetFieldAsSpeedDialL(*firstItem, fieldId, KSpeedDialPositionOne); |
|
784 CleanupStack::PopAndDestroy(firstItem); |
|
785 |
|
786 TBuf<32> phoneNumber; |
|
787 TContactItemId id2= iContactsTest->Db()->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
788 TheTest(phoneNumber==KSpeedDialPhoneNumber); |
|
789 TheTest(id2==id); |
|
790 iTest->Printf(_L("ThreadOne : set contact with speed dial at position 1, awaiting notification.\n")); |
|
791 |
|
792 // Pause this thread |
|
793 iSemaphoreTwo.Signal(); |
|
794 iSemaphoreOne.Wait(); |
|
795 |
|
796 // changing the name to see the type of notifications emitted. - Case:2 |
|
797 CContactItem* editItem = iContactsTest->Db()->OpenContactL(id); |
|
798 CleanupStack::PushL(editItem); |
|
799 SetNameL(*editItem, KUidContactFieldGivenName, KUidContactFieldVCardMapUnusedN, _L("changed"), EFalse); |
|
800 iContactsTest->Db()->CommitContactL(*editItem); |
|
801 CleanupStack::PopAndDestroy(editItem); |
|
802 iTest->Printf(_L("ThreadOne : Changing name of contact at position 1, awaiting notification.\n")); |
|
803 |
|
804 // changing the name & phone number, to see the type of notifications emitted. - Case:3 |
|
805 editItem = iContactsTest->Db()->OpenContactL(id); |
|
806 CleanupStack::PushL(editItem); |
|
807 SetNameL(*editItem, KUidContactFieldGivenName, KUidContactFieldVCardMapUnusedN, _L("changed"), EFalse); |
|
808 SetNameL(*editItem, KUidContactFieldPhoneNumber, KUidContactFieldVCardMapTEL, _L("020 88888888"), EFalse); |
|
809 iContactsTest->Db()->CommitContactL(*editItem); |
|
810 CleanupStack::PopAndDestroy(editItem); |
|
811 iTest->Printf(_L("ThreadOne : Changing name & phone no. of contact at position 1, awaiting notification.\n")); |
|
812 |
|
813 iContactsTest->Db()->DeleteContactL(id); |
|
814 iTest->Printf(_L("ThreadOne : deleted contact, waiting for notification\n")); |
|
815 |
|
816 // Pause this thread |
|
817 iSemaphoreTwo.Signal(); |
|
818 iSemaphoreOne.Wait(); |
|
819 |
|
820 //add 2 contacts, set them to speed dail, change details & commit, and check notifications, |
|
821 // & delete - Case:4 |
|
822 item=CContactCard::NewLC(); |
|
823 SetNameL(*item,KUidContactFieldGivenName, KUidContactFieldVCardMapUnusedN, _L("Contact-1"), ETrue); |
|
824 SetNameL(*item,KUidContactFieldPhoneNumber, KUidContactFieldVCardMapTEL, KSpeedDialPhoneNumber, ETrue); |
|
825 id = iContactsTest->Db()->AddNewContactL(*item); |
|
826 CleanupStack::PopAndDestroy(item); |
|
827 |
|
828 item=CContactCard::NewLC(); |
|
829 SetNameL(*item,KUidContactFieldGivenName, KUidContactFieldVCardMapUnusedN, _L("Contact-2"), ETrue); |
|
830 SetNameL(*item,KUidContactFieldPhoneNumber, KUidContactFieldVCardMapTEL, KSpeedDialPhoneNumber2, ETrue); |
|
831 id2 = iContactsTest->Db()->AddNewContactL(*item); |
|
832 CleanupStack::PopAndDestroy(item); |
|
833 |
|
834 // speeddial for the both the contacts, |
|
835 firstItem = iContactsTest->Db()->OpenContactL(id); |
|
836 CleanupStack::PushL(firstItem); |
|
837 iContactsTest->Db()->SetFieldAsSpeedDialL(*firstItem, fieldId, KSpeedDialPositionOne); |
|
838 CleanupStack::PopAndDestroy(firstItem); |
|
839 |
|
840 CContactItem* secondItem = iContactsTest->Db()->OpenContactL(id2); |
|
841 CleanupStack::PushL(secondItem); |
|
842 iContactsTest->Db()->SetFieldAsSpeedDialL(*secondItem, fieldId, KSpeedDialPositionTwo); |
|
843 CleanupStack::PopAndDestroy(secondItem); |
|
844 |
|
845 //change details, for second contact 1st and then the first contact. |
|
846 editItem = iContactsTest->Db()->OpenContactL(id2); |
|
847 CleanupStack::PushL(editItem); |
|
848 SetNameL(*editItem, KUidContactFieldGivenName, KUidContactFieldVCardMapUnusedN, _L("changed second"), EFalse); |
|
849 SetNameL(*editItem, KUidContactFieldPhoneNumber, KUidContactFieldVCardMapTEL, _L("020 77777777"), EFalse); |
|
850 iContactsTest->Db()->CommitContactL(*editItem); |
|
851 CleanupStack::PopAndDestroy(editItem); |
|
852 |
|
853 editItem = iContactsTest->Db()->OpenContactL(id); |
|
854 CleanupStack::PushL(editItem); |
|
855 SetNameL(*editItem, KUidContactFieldGivenName, KUidContactFieldVCardMapUnusedN, _L("changed first"), EFalse); |
|
856 SetNameL(*editItem, KUidContactFieldPhoneNumber, KUidContactFieldVCardMapTEL, _L("020 66666666"), EFalse); |
|
857 iContactsTest->Db()->CommitContactL(*editItem); |
|
858 CleanupStack::PopAndDestroy(editItem); |
|
859 |
|
860 iContactsTest->Db()->DeleteContactL(id); |
|
861 iContactsTest->Db()->DeleteContactL(id2); |
|
862 iTest->Printf(_L("ThreadOne : Added 2 contacts, set speed dail for both, changed contact details for both & deleted both the contacts, waiting for notification\n")); |
|
863 |
|
864 //Case:5, Add contact, set speed dail, remove speed dail, delete contact |
|
865 // Add a contact and set the speeddial |
|
866 item=CContactCard::NewLC(); |
|
867 SetNameL(*item,KUidContactFieldGivenName, KUidContactFieldVCardMapUnusedN, _L("Given"), ETrue); |
|
868 SetNameL(*item,KUidContactFieldPhoneNumber, KUidContactFieldVCardMapTEL, KSpeedDialPhoneNumber, ETrue); |
|
869 id = iContactsTest->Db()->AddNewContactL(*item); |
|
870 CleanupStack::PopAndDestroy(item); |
|
871 |
|
872 // Set speeddial |
|
873 firstItem = iContactsTest->Db()->OpenContactL(id); |
|
874 CleanupStack::PushL(firstItem); |
|
875 iContactsTest->Db()->SetFieldAsSpeedDialL(*firstItem, fieldId, KSpeedDialPositionOne); |
|
876 CleanupStack::PopAndDestroy(firstItem); |
|
877 |
|
878 iSemaphoreTwo.Signal(); |
|
879 |
|
880 // Remove speed dail |
|
881 id2= iContactsTest->Db()->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
882 TheTest(phoneNumber==KSpeedDialPhoneNumber); |
|
883 TheTest(id2==id); |
|
884 |
|
885 iContactsTest->Db()->RemoveSpeedDialFieldL(id, KSpeedDialPositionOne); |
|
886 iContactsTest->Db()->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
887 TheTest(phoneNumber==KNullDesC); |
|
888 iContactsTest->Db()->DeleteContactL(id); |
|
889 iTest->Printf(_L("ThreadOne : Add contacts, set speed dail, remove speed dial, and delete, waiting for notification\n")); |
|
890 |
|
891 iContactsTest->CloseDatabase(); |
|
892 |
|
893 // Pause this thread |
|
894 iSemaphoreTwo.Signal(); |
|
895 iSemaphoreOne.Wait(); |
|
896 } |
|
897 |
|
898 /* |
|
899 Teststep to test fix for INC116664 |
|
900 1)Add contact items to database |
|
901 2)Add contact template to database |
|
902 3)Delete contact template from database |
|
903 Result:Contact template should be deleted without any panic. |
|
904 */ |
|
905 |
|
906 void CTestThreadOne::DoTest9L() |
|
907 { |
|
908 iSemaphoreOne.Wait(); |
|
909 |
|
910 iContactsTest->OpenDatabaseL(); |
|
911 iTest->Printf(_L("we've both got the database open")); |
|
912 |
|
913 iTest->Printf(_L("Add new contact data\n")); |
|
914 |
|
915 CContactDatabase* db = iContactsTest->Db(); |
|
916 |
|
917 TContactItemId id = AddContactL(db, KUidContactFieldFamilyName, KUidContactFieldVCardMapUnusedN, _L("3333")); |
|
918 iTest->Printf(_L("Contact Added with Id = %d\n"), id); |
|
919 |
|
920 id = AddContactL(db, KUidContactFieldFamilyName, KUidContactFieldVCardMapUnusedN, _L("2222")); |
|
921 iTest->Printf(_L("Contact Added with Id = %d\n"), id); |
|
922 |
|
923 id = AddContactL(db, KUidContactFieldFamilyName, KUidContactFieldVCardMapUnusedN, _L("1111")); |
|
924 iTest->Printf(_L("Contact Added with Id = %d\n"), id); |
|
925 iSemaphoreTwo.Signal(); |
|
926 iSemaphoreOne.Wait(); |
|
927 |
|
928 CContactItem* contactTemplate = iContactsTest->Db()->CreateContactCardTemplateLC(_L("TestINC116664")); |
|
929 id = contactTemplate->Id(); |
|
930 iTest->Printf(_L("Contact Template Created with Id = %d\n"),id); |
|
931 iSemaphoreTwo.Signal(); |
|
932 iSemaphoreOne.Wait(); |
|
933 |
|
934 iContactsTest->Db()->AddNewContactL(*contactTemplate); |
|
935 iSemaphoreTwo.Signal(); |
|
936 iSemaphoreOne.Wait(); |
|
937 CleanupStack::PopAndDestroy(contactTemplate); |
|
938 |
|
939 iTest->Printf(_L("Deleting Contact Template now\n")); |
|
940 iContactsTest->Db()->DeleteContactL(id); |
|
941 iSemaphoreTwo.Signal(); |
|
942 |
|
943 iContactsTest->CloseDatabase(); |
|
944 } |
|
945 |
|
946 // |
|
947 // -------> CTestThreadTwo (source) |
|
948 // |
|
949 CTestThreadTwo::CTestThreadTwo(CTestManager& aTester, TInt aClientNumber, TThreadPriority aThreadPriority, TInt aPriority) |
|
950 : CTestBase(aTester, aClientNumber, aThreadPriority, aPriority) |
|
951 { |
|
952 } |
|
953 |
|
954 CTestThreadTwo* CTestThreadTwo::NewL(TInt aClientNumber, const TDesC& aName, CTestManager& aTester, TThreadPriority aThreadPriority, TInt aPriority) |
|
955 { |
|
956 CTestThreadTwo* self = new(ELeave) CTestThreadTwo(aTester, aClientNumber, aThreadPriority, aPriority); |
|
957 CleanupStack::PushL(self); |
|
958 self->ConstructL(aName); |
|
959 CleanupStack::Pop(); // self |
|
960 return self; |
|
961 } |
|
962 |
|
963 void CTestThreadTwo::OpenDatabaseL() |
|
964 { |
|
965 TBuf<200> buf; |
|
966 buf.Format(_L("Constructing test utilities with database set as %S"), &KTestDatabaseFile); |
|
967 iTest->Next(buf); |
|
968 iContactsTest->ConstructL(*iTest, KTestDatabaseFile2); |
|
969 } |
|
970 |
|
971 // |
|
972 // |
|
973 // |
|
974 |
|
975 void CTestThreadTwo::DoTestL(TInt aTestNumber) |
|
976 { |
|
977 TBuf<50> buf; |
|
978 buf.Format(KThreadTestFormat, iClientNumber, aTestNumber); |
|
979 iTest->Next(buf); |
|
980 |
|
981 switch(aTestNumber) |
|
982 { |
|
983 case ETest1: |
|
984 DoTest1L(); |
|
985 break; |
|
986 case ETest2: |
|
987 DoTest2L(); |
|
988 break; |
|
989 case ETest3: |
|
990 DoTest3L(); |
|
991 break; |
|
992 case ETest4: |
|
993 DoTest4L(); |
|
994 break; |
|
995 case ETest5: |
|
996 DoTest5L(); |
|
997 break; |
|
998 case ETest6: |
|
999 DoTest6L(); |
|
1000 break; |
|
1001 case ETest7: |
|
1002 DoTest7L(); |
|
1003 break; |
|
1004 case ETest8: |
|
1005 DoTest8L(); |
|
1006 break; |
|
1007 case ETest9: |
|
1008 DoTest9L(); |
|
1009 break; |
|
1010 default: |
|
1011 User::Invariant(); |
|
1012 } |
|
1013 } |
|
1014 |
|
1015 // |
|
1016 // |
|
1017 // |
|
1018 |
|
1019 void CTestThreadTwo::DoTest1L() |
|
1020 { |
|
1021 iSemaphoreOne.Signal(); |
|
1022 // This thread has a lower priority than thread 1 so it should run second, |
|
1023 // hence this test should work. |
|
1024 iSemaphoreTwo.Wait(); |
|
1025 iTest->Next(_L("Opening the database and check it is not made the current db\n")); |
|
1026 iContactsTest->OpenDatabaseL(); |
|
1027 |
|
1028 iTest->Printf(_L("\tFetching the current database...\n")); |
|
1029 TFileName currentDb; |
|
1030 User::LeaveIfError(iContactsTest->Db()->GetCurrentDatabase(currentDb)); |
|
1031 iTest->Printf(_L("\tCurrent database reported as %S\n"), ¤tDb); |
|
1032 |
|
1033 // The current database should still be the normal 'contacts.cdb' |
|
1034 (*iTest)(currentDb.CompareF(KTestDatabaseFile) == 0); |
|
1035 |
|
1036 // Pause this thread |
|
1037 iSemaphoreOne.Signal(); |
|
1038 iSemaphoreTwo.Wait(); |
|
1039 } |
|
1040 |
|
1041 void CTestThreadTwo::DoTest2L() |
|
1042 { |
|
1043 iSemaphoreOne.Signal(); |
|
1044 |
|
1045 iTest->Next(_L("Setting the current database and check...")); |
|
1046 |
|
1047 // Set our database as the current (it was thread 1's)... |
|
1048 User::LeaveIfError(iContactsTest->Db()->SetCurrentDatabase(KTestDatabaseFile2)); |
|
1049 |
|
1050 // Check it's been changed... |
|
1051 iTest->Printf(_L("\tFetching the current database...\n")); |
|
1052 TFileName currentDb; |
|
1053 User::LeaveIfError(iContactsTest->Db()->GetCurrentDatabase(currentDb)); |
|
1054 iTest->Printf(_L("\tCurrent database reported as %S\n"), ¤tDb); |
|
1055 (*iTest)(currentDb.CompareF(KTestDatabaseFile2) == 0); |
|
1056 |
|
1057 // Pause this thread |
|
1058 iSemaphoreOne.Signal(); |
|
1059 iSemaphoreTwo.Wait(); |
|
1060 } |
|
1061 |
|
1062 void CTestThreadTwo::DoTest3L() |
|
1063 { |
|
1064 iSemaphoreOne.Signal(); |
|
1065 |
|
1066 iTest->Next(_L("Waiting for thread 1 to set the current db a lot of times\n")); |
|
1067 for(TInt i = 0; i < KTestSteps; ++i) |
|
1068 { |
|
1069 CContactChangeNotifier* changeNotifier = CContactChangeNotifier::NewL(*iContactsTest->Db(), this); |
|
1070 CleanupStack::PushL(changeNotifier); |
|
1071 |
|
1072 // This will wait for it |
|
1073 iTest->Printf(_L("\tWaiting for change notification...\n")); |
|
1074 WaitForContactsEvent(EContactDbObserverEventCurrentDatabaseChanged); |
|
1075 iTest->Printf(_L("\tNotification complete...\n")); |
|
1076 CleanupStack::PopAndDestroy(); // changeNotifier |
|
1077 |
|
1078 iSemaphoreOne.Signal(); |
|
1079 iSemaphoreTwo.Wait(); |
|
1080 } |
|
1081 |
|
1082 // Set our database as the current (it was thread 1's)... |
|
1083 User::LeaveIfError(iContactsTest->Db()->SetCurrentDatabase(KTestDatabaseFile2)); |
|
1084 |
|
1085 // Now close our db |
|
1086 iTest->Printf(_L("\tClosing thread two's database\n")); |
|
1087 iContactsTest->CloseDatabase(); |
|
1088 iSemaphoreOne.Signal(); |
|
1089 |
|
1090 // Pause this thread |
|
1091 iSemaphoreOne.Signal(); |
|
1092 iSemaphoreTwo.Wait(); |
|
1093 } |
|
1094 |
|
1095 void CTestThreadTwo::DoTest4L() |
|
1096 { |
|
1097 iSemaphoreOne.Signal(); |
|
1098 iTest->Next(_L("Thread two, simple wait for notification to aid thread one\n")); |
|
1099 |
|
1100 iTest->Printf(_L("\tOpening thread two's database\n")); |
|
1101 iContactsTest->OpenDatabaseL(); |
|
1102 |
|
1103 // This will wait notification |
|
1104 CContactChangeNotifier* changeNotifier = CContactChangeNotifier::NewL(*iContactsTest->Db(), this); |
|
1105 CleanupStack::PushL(changeNotifier); |
|
1106 iTest->Printf(_L("\tWaiting for change notification...\n")); |
|
1107 WaitForContactsEvent(EContactDbObserverEventCurrentDatabaseChanged); |
|
1108 iTest->Printf(_L("\tNotification complete...\n")); |
|
1109 CleanupStack::PopAndDestroy(); // changeNotifier |
|
1110 |
|
1111 // Close our db |
|
1112 iTest->Printf(_L("\tClosing thread two's database\n")); |
|
1113 iContactsTest->CloseDatabase(); |
|
1114 |
|
1115 // Pause this thread |
|
1116 iSemaphoreOne.Signal(); |
|
1117 iSemaphoreTwo.Wait(); |
|
1118 } |
|
1119 |
|
1120 |
|
1121 /** |
|
1122 * Speeddial test |
|
1123 * Open thread one's contacts database |
|
1124 * Wait for notification that the other client added a speeddial |
|
1125 * Check that it is possible to read the speeddial |
|
1126 */ |
|
1127 void CTestThreadTwo::DoTest5L() |
|
1128 { |
|
1129 iTest->Printf(_L("\tOpening thread one's database\n")); |
|
1130 CContactDatabase* threadTwoDb = iContactsTest->Db()->OpenL(KTestDatabaseFile); |
|
1131 CleanupStack::PushL(threadTwoDb); |
|
1132 |
|
1133 // This will wait notification |
|
1134 CContactChangeNotifier* changeNotifier = CContactChangeNotifier::NewL(*threadTwoDb, this); |
|
1135 CleanupStack::PushL(changeNotifier); |
|
1136 iSemaphoreOne.Signal(); // indicate we've got the same database open |
|
1137 iSemaphoreTwo.Wait(); |
|
1138 iSemaphoreTwo.Wait(); |
|
1139 |
|
1140 iTest->Printf(_L("\tThreadTwo : Waiting for change notification...\n")); |
|
1141 WaitForContactsEvent(EContactDbObserverEventContactAdded); |
|
1142 WaitForContactsEvent(EContactDbObserverEventCurrentItemChanged); |
|
1143 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1144 iTest->Printf(_L("\tThreadTwo : We expect a speed dial to have been added... ")); |
|
1145 TheTest(iLastEvent.iContactId==1); |
|
1146 iTest->Printf(_L("correct.\n")); |
|
1147 |
|
1148 TBuf<32> phoneNumber; |
|
1149 TContactItemId id = threadTwoDb->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
1150 TheTest(phoneNumber == KSpeedDialPhoneNumber); |
|
1151 TheTest(id == 1); |
|
1152 |
|
1153 iSemaphoreOne.Signal(); |
|
1154 |
|
1155 iTest->Printf(_L("\tThreadTwo : Waiting for change notification...\n")); |
|
1156 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1157 iTest->Printf(_L("\tThreadTwo : We expect the contact owning the speed dial to have been deleted... ")); |
|
1158 TheTest(iLastEvent.iContactId == id); // Speed dial has been deleted by CTestThreadOne::DoTest5L(), |
|
1159 //event returns ID on deletion |
|
1160 iTest->Printf(_L("\n\tSpeed dial contact has been deleted by CTestThreadOne::DoTest5L(),.\n")); |
|
1161 iTest->Printf(_L("correct.\n")); |
|
1162 CleanupStack::PopAndDestroy(); // changeNotifier |
|
1163 |
|
1164 id = threadTwoDb->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
1165 TheTest(phoneNumber == KNullDesC); |
|
1166 TheTest(id==-1); |
|
1167 |
|
1168 CleanupStack::PopAndDestroy(); |
|
1169 |
|
1170 // Signal thread 1 |
|
1171 iSemaphoreOne.Signal(); |
|
1172 iSemaphoreTwo.Wait(); |
|
1173 } |
|
1174 |
|
1175 |
|
1176 /** |
|
1177 * Speeddial test |
|
1178 * Open thread one's contacts database |
|
1179 * Wait for notification that the other client removed a speeddial |
|
1180 * Check that it is possible to read the speeddial |
|
1181 */ |
|
1182 void CTestThreadTwo::DoTest6L() |
|
1183 { |
|
1184 iTest->Printf(_L("\tOpening thread one's database\n")); |
|
1185 CContactDatabase* threadOneDb = iContactsTest->Db()->OpenL(KTestDatabaseFile); |
|
1186 CleanupStack::PushL(threadOneDb); |
|
1187 |
|
1188 // This will wait notification |
|
1189 CContactChangeNotifier* changeNotifier = CContactChangeNotifier::NewL(*threadOneDb, this); |
|
1190 CleanupStack::PushL(changeNotifier); |
|
1191 |
|
1192 iSemaphoreOne.Signal(); // indicate we've got the same database open |
|
1193 iSemaphoreTwo.Wait(); |
|
1194 |
|
1195 iTest->Printf(_L("\tWaiting for change notification...\n")); |
|
1196 WaitForContactsEvent(EContactDbObserverEventContactAdded); |
|
1197 WaitForContactsEvent(EContactDbObserverEventCurrentItemChanged); |
|
1198 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1199 iTest->Printf(_L("\tSpeedDial Notification complete\n")); |
|
1200 TheTest(iLastEvent.iContactId==2); // we deleted contact 1 |
|
1201 |
|
1202 TBuf<32> phoneNumber; |
|
1203 TContactItemId id = threadOneDb->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
1204 TheTest(phoneNumber==KSpeedDialPhoneNumber); |
|
1205 TheTest(id==2); |
|
1206 |
|
1207 iSemaphoreOne.Signal(); // indicate we've got the same database open |
|
1208 iSemaphoreTwo.Wait(); |
|
1209 |
|
1210 WaitForContactsEvent(EContactDbObserverEventContactChanged); |
|
1211 TheTest(iLastEvent.iContactId==id); //speed dial has been removed by CTestThreadOne::DoTest6L(), |
|
1212 // event returns ID on removal |
|
1213 iTest->Printf(_L("\n\tspeed dial has been removed by CTestThreadOne::DoTest6L(), \n")); |
|
1214 CleanupStack::PopAndDestroy(); // changeNotifier |
|
1215 |
|
1216 id = threadOneDb->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
1217 TheTest(phoneNumber==KNullDesC); |
|
1218 TheTest(id==-1); |
|
1219 |
|
1220 CleanupStack::PopAndDestroy(); // threadOneDb |
|
1221 |
|
1222 // Pause this thread |
|
1223 iSemaphoreOne.Signal(); |
|
1224 iSemaphoreTwo.Wait(); |
|
1225 } |
|
1226 |
|
1227 /** |
|
1228 * Group test |
|
1229 * Open thread one's contacts database |
|
1230 * Wait for notification that the other client added a contact group |
|
1231 * and acknowledge the same |
|
1232 * Wait for notification that the other client deleted a contact group |
|
1233 * and acknowledge the same |
|
1234 */ |
|
1235 void CTestThreadTwo::DoTest7L() |
|
1236 { |
|
1237 iTest->Printf(_L("\tOpening thread one's database\n")); |
|
1238 CContactDatabase* threadOneDb = iContactsTest->Db()->OpenL(KTestDatabaseFile); |
|
1239 CleanupStack::PushL(threadOneDb); |
|
1240 |
|
1241 // This will wait notification |
|
1242 CContactChangeNotifier* changeNotifier = CContactChangeNotifier::NewL(*threadOneDb, this); |
|
1243 CleanupStack::PushL(changeNotifier); |
|
1244 |
|
1245 iSemaphoreOne.Signal(); // indicate we've got the same database open |
|
1246 iSemaphoreTwo.Wait(); |
|
1247 |
|
1248 |
|
1249 WaitForContactsEvent(EContactDbObserverEventGroupAdded); |
|
1250 TheTest(threadOneDb->GroupCount()==1); |
|
1251 |
|
1252 WaitForContactsEvent(EContactDbObserverEventGroupDeleted); |
|
1253 TheTest(threadOneDb->GroupCount()==0); |
|
1254 |
|
1255 CleanupStack::PopAndDestroy(2); // threadOneDb, changeNotifier |
|
1256 |
|
1257 // Signal thread 1 |
|
1258 iSemaphoreOne.Signal(); |
|
1259 iSemaphoreTwo.Wait(); |
|
1260 } |
|
1261 |
|
1262 void CTestThreadTwo::DoTest8L() |
|
1263 { |
|
1264 iTest->Printf(_L("\tOpening thread one's database\n")); |
|
1265 CContactDatabase* threadOneDb = iContactsTest->Db()->OpenL(KTestDatabaseFile); |
|
1266 CleanupStack::PushL(threadOneDb); |
|
1267 |
|
1268 // This will wait notification |
|
1269 CContactChangeNotifier* changeNotifier = CContactChangeNotifier::NewL(*threadOneDb, this); |
|
1270 CleanupStack::PushL(changeNotifier); |
|
1271 |
|
1272 iSemaphoreOne.Signal(); // indicate we've got the same database open |
|
1273 iSemaphoreTwo.Wait(); |
|
1274 |
|
1275 iTest->Printf(_L("\tThreadTwo : Waiting for change notification...\n")); |
|
1276 WaitForContactsEvent(EContactDbObserverEventContactAdded); |
|
1277 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1278 iTest->Printf(_L("\tThreadTwo : We expect a speed dial to have been added... ")); |
|
1279 TheTest(iLastEvent.iContactId == 4); |
|
1280 iTest->Printf(_L("correct.\n")); |
|
1281 |
|
1282 TBuf<32> phoneNumber; |
|
1283 TContactItemId id = threadOneDb->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
1284 TheTest(phoneNumber==KSpeedDialPhoneNumber); |
|
1285 TheTest(id == 4); |
|
1286 |
|
1287 // Pause this thread |
|
1288 iSemaphoreOne.Signal(); |
|
1289 iSemaphoreTwo.Wait(); |
|
1290 |
|
1291 iTest->Printf(_L("\tThreadTwo : Waiting for change notification...\n")); |
|
1292 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1293 WaitForContactsEvent(EContactDbObserverEventContactChanged); |
|
1294 iTest->Printf(_L("\tThreadTwo : We expect a contact having speed dial to have been modified... ")); |
|
1295 TheTest(iLastEvent.iContactId == 4); |
|
1296 iTest->Printf(_L("correct.\n")); |
|
1297 |
|
1298 //changed both name & phone no. of contact with speed dial |
|
1299 iTest->Printf(_L("\tThreadTwo : Waiting for change notification...\n")); |
|
1300 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1301 WaitForContactsEvent(EContactDbObserverEventContactChanged); |
|
1302 iTest->Printf(_L("\tThreadTwo : Both contact having speed dial have been modified ... ")); |
|
1303 TheTest(iLastEvent.iContactId == 4); |
|
1304 iTest->Printf(_L("correct.\n")); |
|
1305 |
|
1306 iTest->Printf(_L("\tThreadTwo : Waiting for change notification...\n")); |
|
1307 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1308 WaitForContactsEvent(EContactDbObserverEventContactDeleted); |
|
1309 iTest->Printf(_L("\tThreadTwo : We expect the contact owning the speed dial to have been deleted... ")); |
|
1310 TheTest(iLastEvent.iContactId==id); // Speed dial has been deleted by CTestThreadOne::DoTest5L(), |
|
1311 //event returns ID on deletion |
|
1312 iTest->Printf(_L("\n\tSpeed dial contact has been deleted by CTestThreadOne::DoTest8L(),.\n")); |
|
1313 id = threadOneDb->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
1314 TheTest(phoneNumber==KNullDesC); |
|
1315 TheTest(id==-1); |
|
1316 iTest->Printf(_L("correct.\n")); |
|
1317 |
|
1318 // Pause this thread |
|
1319 iSemaphoreOne.Signal(); |
|
1320 iSemaphoreTwo.Wait(); |
|
1321 |
|
1322 //case-4 |
|
1323 iTest->Printf(_L("\tThreadTwo : Waiting for change notification for case-4...\n")); |
|
1324 WaitForContactsEvent(EContactDbObserverEventContactAdded); |
|
1325 TheTest(iLastEvent.iContactId==5); |
|
1326 WaitForContactsEvent(EContactDbObserverEventContactAdded); |
|
1327 iTest->Printf(_L("\tThreadTwo : We expect a 2 contacts to have been added... ")); |
|
1328 TheTest(iLastEvent.iContactId==6); |
|
1329 iTest->Printf(_L("correct.\n")); |
|
1330 |
|
1331 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1332 TheTest(iLastEvent.iContactId==5); |
|
1333 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1334 iTest->Printf(_L("\tThreadTwo : We expect a speed dial to have been set for both the contacts... ")); |
|
1335 TheTest(iLastEvent.iContactId==6); |
|
1336 iTest->Printf(_L("correct.\n")); |
|
1337 |
|
1338 //changed name & phone no. of both the contact with speed dial |
|
1339 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1340 WaitForContactsEvent(EContactDbObserverEventContactChanged); |
|
1341 TheTest(iLastEvent.iContactId == 6); |
|
1342 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1343 WaitForContactsEvent(EContactDbObserverEventContactChanged); |
|
1344 iTest->Printf(_L("\tThreadTwo : Both contacts having speed dial have been modified ... ")); |
|
1345 TheTest(iLastEvent.iContactId == 5); |
|
1346 iTest->Printf(_L("correct.\n")); |
|
1347 |
|
1348 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1349 WaitForContactsEvent(EContactDbObserverEventContactDeleted); |
|
1350 TheTest(iLastEvent.iContactId==5); // Speed dial has been deleted |
|
1351 iTest->Printf(_L("\tSpeed dial for contact-1 has been deleted by CTestThreadOne::DoTest8L(),.\n")); |
|
1352 id = threadOneDb->GetSpeedDialFieldL(KSpeedDialPositionOne, phoneNumber); |
|
1353 TheTest(phoneNumber==KNullDesC); |
|
1354 TheTest(id==-1); |
|
1355 iTest->Printf(_L("correct.\n")); |
|
1356 |
|
1357 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1358 WaitForContactsEvent(EContactDbObserverEventContactDeleted); |
|
1359 id = threadOneDb->GetSpeedDialFieldL(KSpeedDialPositionTwo, phoneNumber); |
|
1360 TheTest(iLastEvent.iContactId==6); // Speed dial has been deleted |
|
1361 iTest->Printf(_L("\tSpeed dial for contact-2 has been deleted by CTestThreadOne::DoTest8L(),.\n")); |
|
1362 id = threadOneDb->GetSpeedDialFieldL(KSpeedDialPositionTwo, phoneNumber); |
|
1363 TheTest(phoneNumber==KNullDesC); |
|
1364 TheTest(id==-1); |
|
1365 iTest->Printf(_L("correct.\n")); |
|
1366 iTest->Printf(_L("\tThreadTwo : We expect the contact owning the speed dial to have been deleted... ")); |
|
1367 |
|
1368 iTest->Printf(_L("\tThreadTwo : Waiting for change notification...\n")); |
|
1369 WaitForContactsEvent(EContactDbObserverEventContactAdded); |
|
1370 WaitForContactsEvent(EContactDbObserverEventSpeedDialsChanged); |
|
1371 WaitForContactsEvent(EContactDbObserverEventContactChanged); |
|
1372 WaitForContactsEvent(EContactDbObserverEventContactDeleted); |
|
1373 iTest->Printf(_L("\tThreadTwo : We expect a speed dial to have been added and removed... ")); |
|
1374 TheTest(iLastEvent.iContactId == 7); |
|
1375 iTest->Printf(_L("correct.\n")); |
|
1376 |
|
1377 CleanupStack::PopAndDestroy(); // changeNotifier, |
|
1378 CleanupStack::PopAndDestroy(); // threadOneDb |
|
1379 |
|
1380 // Signal thread 1 |
|
1381 iSemaphoreOne.Signal(); |
|
1382 iSemaphoreTwo.Wait(); |
|
1383 } |
|
1384 |
|
1385 |
|
1386 /* |
|
1387 Teststep to test fix for INC116664 |
|
1388 1)Open database and wait for notifications |
|
1389 Result: Notifications for contact and template addition along with template deletion should be recieved. |
|
1390 */ |
|
1391 void CTestThreadTwo::DoTest9L() |
|
1392 { |
|
1393 iTest->Printf(_L("\tOpening thread one's database\n")); |
|
1394 CContactDatabase* threadOneDb = iContactsTest->Db()->OpenL(KTestDatabaseFile); |
|
1395 CleanupStack::PushL(threadOneDb); |
|
1396 |
|
1397 // This will wait notification |
|
1398 CContactChangeNotifier* changeNotifier = CContactChangeNotifier::NewL(*threadOneDb, this); |
|
1399 CleanupStack::PushL(changeNotifier); |
|
1400 iSemaphoreOne.Signal(); // indicate we've got the same database open |
|
1401 iSemaphoreTwo.Wait(); |
|
1402 |
|
1403 WaitForContactsEvent(EContactDbObserverEventContactAdded); |
|
1404 |
|
1405 WaitForContactsEvent(EContactDbObserverEventContactAdded); |
|
1406 |
|
1407 WaitForContactsEvent(EContactDbObserverEventContactAdded); |
|
1408 iSemaphoreOne.Signal(); |
|
1409 iSemaphoreTwo.Wait(); |
|
1410 |
|
1411 WaitForContactsEvent(EContactDbObserverEventTemplateAdded); |
|
1412 iSemaphoreOne.Signal(); |
|
1413 iSemaphoreTwo.Wait(); |
|
1414 |
|
1415 WaitForContactsEvent(EContactDbObserverEventTemplateAdded); |
|
1416 iSemaphoreOne.Signal(); |
|
1417 iSemaphoreTwo.Wait(); |
|
1418 |
|
1419 WaitForContactsEvent(EContactDbObserverEventTemplateDeleted); |
|
1420 iSemaphoreOne.Signal(); |
|
1421 |
|
1422 CleanupStack::PopAndDestroy(2); // threadOneDb, changeNotifier |
|
1423 } |
|
1424 |
|
1425 // |
|
1426 // -------> CTestManager (source) |
|
1427 // |
|
1428 CTestManager::CTestManager(TInt aPriority) |
|
1429 : CTimer(aPriority) |
|
1430 { |
|
1431 CActiveScheduler::Add(this); |
|
1432 } |
|
1433 |
|
1434 CTestManager::~CTestManager() |
|
1435 { |
|
1436 Cancel(); |
|
1437 delete iClient1; |
|
1438 delete iClient2; |
|
1439 } |
|
1440 |
|
1441 void CTestManager::ConstructL() |
|
1442 { |
|
1443 CTimer::ConstructL(); |
|
1444 |
|
1445 iClient2 = CTestThreadTwo::NewL(2, _L("Client-2"), *this, EPriorityLess); // lower |
|
1446 iClient1 = CTestThreadOne::NewL(1, _L("Client-1"), *this, EPriorityMore); |
|
1447 |
|
1448 IssueTimerRequest(); |
|
1449 CActiveScheduler::Start(); |
|
1450 } |
|
1451 |
|
1452 CTestManager* CTestManager::NewL() |
|
1453 { |
|
1454 CTestManager* self = NewLC(); |
|
1455 CleanupStack::Pop(); // self |
|
1456 return self; |
|
1457 } |
|
1458 |
|
1459 CTestManager* CTestManager::NewLC() |
|
1460 { |
|
1461 CTestManager* self = new (ELeave) CTestManager(); |
|
1462 CleanupStack::PushL(self); |
|
1463 self->ConstructL(); |
|
1464 return self; |
|
1465 } |
|
1466 |
|
1467 // |
|
1468 // |
|
1469 // |
|
1470 |
|
1471 void CTestManager::RunL() |
|
1472 { |
|
1473 if ( iClient1->IsActive() && iClient2->IsActive() |
|
1474 && iClient1->CurrentTest() == iClient2->CurrentTest() |
|
1475 && !(iClient1->Waiting() || iClient2->Waiting()) |
|
1476 ) |
|
1477 // We can only complete a request if the active objects are ready. This is |
|
1478 // determined using IsActive() |
|
1479 { |
|
1480 if (iTestNumber >= CTestBase::EEndTests) |
|
1481 // Have we run all the tests? |
|
1482 { |
|
1483 TRequestStatus thread1, thread2; |
|
1484 |
|
1485 // Log on to the threads so that we'll be notified when they die |
|
1486 // Must do this before telling threads to end! |
|
1487 iClient1->Thread().Logon(thread1); |
|
1488 iClient2->Thread().Logon(thread2); |
|
1489 |
|
1490 iClient1->Complete(CTestBase::EEndTests); |
|
1491 iClient2->Complete(CTestBase::EEndTests); |
|
1492 |
|
1493 // Wait for them both to die... |
|
1494 User::WaitForRequest(thread2); |
|
1495 User::WaitForRequest(thread1); |
|
1496 |
|
1497 CActiveScheduler::Stop(); |
|
1498 return; // prevent from starting timer again |
|
1499 } |
|
1500 |
|
1501 _LIT(KNextTestFormatTitle, "Test %d"); |
|
1502 TBuf<20> testBuf; |
|
1503 testBuf.Format(KNextTestFormatTitle, iTestNumber); |
|
1504 |
|
1505 TheTest.Next(_L(" ")); |
|
1506 |
|
1507 iClient1->Complete(iTestNumber); |
|
1508 iClient2->Complete(iTestNumber); |
|
1509 |
|
1510 // We've just requested a test be completed, so we have to increment this |
|
1511 // so that it's ready for the next test... |
|
1512 iTestNumber++; |
|
1513 } |
|
1514 |
|
1515 // Re-issue the asynchronous request to the CTimer |
|
1516 IssueTimerRequest(); |
|
1517 } |
|
1518 |
|
1519 // |
|
1520 // |
|
1521 // |
|
1522 |
|
1523 void CTestManager::IssueTimerRequest() |
|
1524 { |
|
1525 const TInt KOneSecond = 1000000; |
|
1526 After(KOneSecond); |
|
1527 } |
|
1528 |
|
1529 |
|
1530 // |
|
1531 // -------> Static global functions (source) |
|
1532 // |
|
1533 static void doMainL() |
|
1534 { |
|
1535 CTestActiveScheduler* scheduler = new (ELeave) CTestActiveScheduler; |
|
1536 CleanupStack::PushL(scheduler); |
|
1537 CActiveScheduler::Install(scheduler); |
|
1538 |
|
1539 RPIMTestServer serv; |
|
1540 User::LeaveIfError(serv.Connect()); |
|
1541 CleanupClosePushL(serv); |
|
1542 |
|
1543 RFs fsSession; |
|
1544 User::LeaveIfError(fsSession.Connect()); |
|
1545 CleanupClosePushL(fsSession); |
|
1546 |
|
1547 CTestRegister* TempFiles = CTestRegister::NewLC(); |
|
1548 TempFiles->RegisterL(KTestDatabaseFile2, EFileTypeCnt); |
|
1549 |
|
1550 // Create two contacts databases - ignore return value |
|
1551 CContactDatabase* db1 = CContactDatabase::ReplaceL(KTestDatabaseFile); |
|
1552 delete db1; |
|
1553 CContactDatabase* db2 = CContactDatabase::ReplaceL(KTestDatabaseFile2); |
|
1554 delete db2; |
|
1555 |
|
1556 // Secure Server waits 5s from last connection |
|
1557 // to write the .ini file and close |
|
1558 User::After(6000000); |
|
1559 |
|
1560 // Delete any existing ini file so that we can be sure this test is ok |
|
1561 serv.DeleteFileL(KContactsModelIniFile); |
|
1562 serv.Close(); |
|
1563 |
|
1564 CTestManager::NewLC(); |
|
1565 CleanupStack::PopAndDestroy(5, scheduler); // tester, TempFiles, fsSession |
|
1566 } |
|
1567 |
|
1568 |
|
1569 /** |
|
1570 |
|
1571 @SYMTestCaseID PIM-T-CURRENTDB-0001 |
|
1572 |
|
1573 */ |
|
1574 |
|
1575 GLDEF_C TInt E32Main() |
|
1576 { |
|
1577 __UHEAP_MARK; |
|
1578 TheTest.Start(_L("@SYMTESTCaseID:PIM-T-CURRENTDB-0001 Multi session testcode")); |
|
1579 |
|
1580 TheTest.Title(); |
|
1581 TheCleanup = CTrapCleanup::New(); |
|
1582 TRAPD(ret, doMainL()); |
|
1583 TheTest(ret == KErrNone); |
|
1584 delete TheCleanup; |
|
1585 |
|
1586 TheTest.End(); |
|
1587 TheTest.Close(); |
|
1588 __UHEAP_MARKEND; |
|
1589 return(KErrNone); |
|
1590 } |