612 if ( newKey.length() || newValue.length()) |
612 if ( newKey.length() || newValue.length()) |
613 { |
613 { |
614 QString testnewVal = aPresenceBuddyInfo->getAnyField( newKey ); |
614 QString testnewVal = aPresenceBuddyInfo->getAnyField( newKey ); |
615 QVERIFY ( testnewVal== newValue ); |
615 QVERIFY ( testnewVal== newValue ); |
616 } |
616 } |
617 |
617 } |
618 |
618 |
619 |
|
620 } |
|
621 void EntityTests::handlePresenceReadInClient(bool success, QList<PrcPresenceBuddyInfoQt*> buddyInfoList) |
619 void EntityTests::handlePresenceReadInClient(bool success, QList<PrcPresenceBuddyInfoQt*> buddyInfoList) |
622 { |
620 { |
623 int cnt = buddyInfoList.count(); |
621 int cnt = buddyInfoList.count(); |
624 QVERIFY(iNumberOfBuddiesInService == cnt ); |
622 QVERIFY(iNumberOfBuddiesInService == cnt ); |
625 if(true == success) |
623 if(true == success) |
634 QVERIFY(true == isPresent); |
632 QVERIFY(true == isPresent); |
635 iBuddiesInService.removeOne(identity); |
633 iBuddiesInService.removeOne(identity); |
636 } |
634 } |
637 |
635 |
638 } |
636 } |
639 void EntityTests::handlePresencewriteInclient(bool success) |
637 void EntityTests::handlePresencewriteInclient(bool success) |
640 |
|
641 { |
638 { |
642 if(success == true) |
639 if(success == true) |
643 { |
640 { |
644 iNotificationReceived = true; |
641 iNotificationReceived = true; |
645 } |
642 } |
646 |
643 |
647 } |
644 } |
|
645 |
|
646 /*! |
|
647 * A helper function for the test threads used in EntityTests::test9 |
|
648 * Basically just creates a presence reader and records wether or not |
|
649 * succesfull |
|
650 */ |
|
651 |
|
652 TInt EntityTests::startupTestThreadFunction(TAny* any) |
|
653 { |
|
654 // 1. Add cleanup stack support. |
|
655 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
656 |
|
657 // 2. Add support for active objects |
|
658 CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler; |
|
659 CActiveScheduler::Install(activeScheduler); |
|
660 |
|
661 // 3. create reader, which will cause the server startup (provided it is not running) |
|
662 PrcPresenceReader* reader = PrcPresenceReader::createReader(); |
|
663 |
|
664 // 4. If reader created correctly, increase provided results counter |
|
665 if (reader) |
|
666 { |
|
667 TInt* count = (TInt*) any; |
|
668 (*count)++; |
|
669 } |
|
670 |
|
671 delete reader; |
|
672 |
|
673 return(KErrNone); |
|
674 } |
|
675 |
|
676 /*! |
|
677 * Special server startup test. |
|
678 * |
|
679 * 1. This test first waits that the presence server timeouts and shuts down. |
|
680 * 2. Then two test threads are created which simultaneously try to create |
|
681 * presence reader instances. |
|
682 * 3. That causes two server instances trying to start at the same time and |
|
683 * the latter fails with KErrAlreadyExists |
|
684 * 4. We check that is handled correctly by checking that neither test thread |
|
685 * panics and succesfully creates the reader |
|
686 */ |
|
687 void EntityTests::test9() |
|
688 { |
|
689 // this will hold the count of succesfully created readers |
|
690 TInt readerCount=0; |
|
691 |
|
692 // 1. Wait so the server time outs and shuts down. |
|
693 // (we want to start fresh for this test) |
|
694 User::After(3000000); |
|
695 |
|
696 // 2. Create two test threads and start them |
|
697 _LIT(KMyThread1, "PresenceTestThread1"); |
|
698 TBufC<48> threadName(KMyThread1); |
|
699 RThread thread1; |
|
700 TRequestStatus thread1Status; |
|
701 |
|
702 _LIT(KMyThread2, "PresenceTestThread2"); |
|
703 TBufC<48> threadName2(KMyThread2); |
|
704 RThread thread2; |
|
705 TRequestStatus thread2Status; |
|
706 |
|
707 TInt r=thread1.Create(KMyThread1, |
|
708 EntityTests::startupTestThreadFunction, |
|
709 KDefaultStackSize, |
|
710 NULL, |
|
711 &readerCount); |
|
712 |
|
713 TInt x=thread2.Create(KMyThread2, |
|
714 EntityTests::startupTestThreadFunction, |
|
715 KDefaultStackSize, |
|
716 NULL, |
|
717 &readerCount); |
|
718 |
|
719 thread1.Logon(thread1Status); |
|
720 thread2.Logon(thread2Status); |
|
721 thread1.Resume(); |
|
722 thread2.Resume(); |
|
723 |
|
724 // 3. When threads are ready, verify results |
|
725 User::WaitForRequest(thread1Status); |
|
726 User::WaitForRequest(thread2Status); |
|
727 |
|
728 // verify that neither thread paniced |
|
729 QVERIFY(thread1.ExitType() != EExitPanic); |
|
730 QVERIFY(thread2.ExitType() != EExitPanic); |
|
731 // verify that both succesfully created presence readers |
|
732 QVERIFY(readerCount == 2); |
|
733 |
|
734 thread1.Close(); |
|
735 thread2.Close(); |
|
736 } |