76 |
76 |
77 |
77 |
78 class CTestSession : public CSession2 |
78 class CTestSession : public CSession2 |
79 { |
79 { |
80 public: |
80 public: |
81 enum {EStop,ETestInt,ETestPtr,ETestClient,ETestComplete,ETestPtrComplete,ETestCompletePanic,ETestOtherSession,ETestCompleteAfter,ETestMessageConstruction, ETestRMessagePtr2LeavingInterface}; |
81 enum {EStop,ETestInt,ETestPtr,ETestClient,ETestComplete,ETestPtrComplete,ETestCompletePanic,ETestOtherSession,ETestCompleteAfter,ETestMessageConstruction, |
|
82 ETestRMessagePtr2LeavingInterface, ETestKillCompletePanic}; |
82 //Override pure virtual |
83 //Override pure virtual |
83 IMPORT_C virtual void ServiceL(const RMessage2& aMessage); |
84 IMPORT_C virtual void ServiceL(const RMessage2& aMessage); |
84 private: |
85 private: |
85 void TestInt(const RMessage2& aMessage); |
86 void TestInt(const RMessage2& aMessage); |
86 void TestPtr(const RMessage2& aMessage); |
87 void TestPtr(const RMessage2& aMessage); |
573 test.Next(_L("Assignment operator")); |
595 test.Next(_L("Assignment operator")); |
574 messagePtr1=messagePtr2; |
596 messagePtr1=messagePtr2; |
575 |
597 |
576 test.End(); |
598 test.End(); |
577 } |
599 } |
578 |
600 |
579 |
601 void TestServerCompleteTwicePanic(void) |
580 GLDEF_C TInt E32Main() |
602 { |
581 { |
603 TRequestStatus clientStat,serverStat; |
582 test.Title(); |
604 |
583 |
|
584 test.Start(_L("Simple RMessage2 tests")); |
|
585 SimpleRMessage(); |
|
586 |
|
587 test.Next(_L("Simple RMessagePtr2 tests")); |
|
588 SimpleRMessagePtr(); |
|
589 |
|
590 test.Next(_L("Sending messages between two threads")); |
|
591 test.Start(_L("Create client and server threads")); |
|
592 clientThread.Create(_L("Client Thread"),ClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
|
593 serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
|
594 |
|
595 test.Next(_L("Logon to the threads")); |
|
596 TRequestStatus clientStat,serverStat; |
|
597 clientThread.Logon(clientStat); |
|
598 serverThread.Logon(serverStat); |
|
599 |
|
600 test.Next(_L("Start the threads")); |
|
601 sem.CreateLocal(0); |
|
602 clientThread.Resume(); |
|
603 serverThread.Resume(); |
|
604 |
|
605 test.Next(_L("Wait for the threads to stop")); |
|
606 if(clientStat==KRequestPending) |
|
607 User::WaitForRequest(clientStat); |
|
608 if(serverStat==KRequestPending) |
|
609 User::WaitForRequest(serverStat); |
|
610 switch (clientThread.ExitType()) |
|
611 { |
|
612 case EExitKill: |
|
613 test.Printf(_L(" Client thread killed\n")); |
|
614 break; |
|
615 case EExitTerminate: |
|
616 test.Printf(_L("!!Client thread terminated:")); |
|
617 test.Panic(clientThread.ExitCategory(), clientThread.ExitReason()); |
|
618 case EExitPanic: |
|
619 test.Panic(_L("!!Client thread panicked:")); |
|
620 test.Panic(clientThread.ExitCategory(), clientThread.ExitReason()); |
|
621 default: |
|
622 test.Panic(_L("!!Client thread did something bizarre"), clientThread.ExitReason()); |
|
623 } |
|
624 switch (serverThread.ExitType()) |
|
625 { |
|
626 case EExitKill: |
|
627 test.Printf(_L(" Server thread killed\n")); |
|
628 break; |
|
629 case EExitTerminate: |
|
630 test.Printf(_L("!!Server thread terminated:")); |
|
631 test.Panic(serverThread.ExitCategory(), serverThread.ExitReason()); |
|
632 case EExitPanic: |
|
633 test.Printf(_L("!!Server thread panicked:")); |
|
634 test.Panic(serverThread.ExitCategory(), serverThread.ExitReason()); |
|
635 // |
|
636 // To catch a panic put a breakpoint in User::Panic() (in UCDT\UC_UNC.CPP). |
|
637 // |
|
638 default: |
|
639 test.Panic(_L("!!Server thread did something bizarre"), serverThread.ExitReason()); |
|
640 } |
|
641 |
|
642 test.Next(_L("Close the threads")); |
|
643 CLOSE_AND_WAIT(serverThread); |
|
644 CLOSE_AND_WAIT(clientThread); |
|
645 test.End(); |
|
646 |
|
647 TBool justInTime=User::JustInTime(); |
605 TBool justInTime=User::JustInTime(); |
648 |
606 |
649 test.Next(_L("Check it Panics if you try to Complete a message twice")); |
607 test.Next(_L("Check server panics if you try to complete a message twice")); |
650 test.Start(_L("Create client and server threads")); |
608 test.Start(_L("Create client and server threads")); |
651 clientThread.Create(_L("Client Thread1"),CompletePanicClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
609 clientThread.Create(_L("Client Thread1"),CompletePanicClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
652 serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
610 serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
653 |
611 |
654 test.Next(_L("Logon to the threads")); |
612 test.Next(_L("Logon to the threads")); |
676 |
634 |
677 test.Next(_L("Close the threads")); |
635 test.Next(_L("Close the threads")); |
678 CLOSE_AND_WAIT(serverThread); |
636 CLOSE_AND_WAIT(serverThread); |
679 CLOSE_AND_WAIT(clientThread); |
637 CLOSE_AND_WAIT(clientThread); |
680 test.End(); |
638 test.End(); |
|
639 } |
|
640 |
|
641 void TestServerKillCompletePanic(void) |
|
642 { |
|
643 TRequestStatus clientStat,serverStat; |
|
644 |
|
645 TBool justInTime=User::JustInTime(); |
|
646 |
|
647 test.Next(_L("Check Server panics if you try to panic a client using a completed message")); |
|
648 test.Start(_L("Create client and server threads")); |
|
649 clientThread.Create(_L("Client Thread2"),KillCompletePanicClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
|
650 serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
|
651 |
|
652 test.Next(_L("Logon to the threads")); |
|
653 clientThread.Logon(clientStat); |
|
654 serverThread.Logon(serverStat); |
|
655 |
|
656 test.Next(_L("Start the threads")); |
|
657 sem.CreateLocal(0); |
|
658 User::SetJustInTime(EFalse); |
|
659 clientThread.Resume(); |
|
660 serverThread.Resume(); |
|
661 |
|
662 test.Next(_L("Wait for the threads to stop")); |
|
663 User::WaitForRequest(clientStat); |
|
664 User::WaitForRequest(serverStat); |
|
665 User::SetJustInTime(justInTime); |
|
666 test.Next(_L("Check the exit categories")); |
|
667 test(clientThread.ExitType()==EExitKill); |
|
668 test(clientThread.ExitCategory().Compare(_L("Kill"))==0); |
|
669 test(clientThread.ExitReason()==KErrNone); |
|
670 |
|
671 test(serverThread.ExitType()==EExitPanic); |
|
672 test(serverThread.ExitCategory().Compare(_L("KERN-EXEC"))==0); |
|
673 test(serverThread.ExitReason()==EBadMessageHandle); |
|
674 |
|
675 test.Next(_L("Close the threads")); |
|
676 CLOSE_AND_WAIT(serverThread); |
|
677 CLOSE_AND_WAIT(clientThread); |
|
678 test.End(); |
|
679 } |
|
680 |
|
681 GLDEF_C TInt E32Main() |
|
682 { |
|
683 test.Title(); |
|
684 |
|
685 test.Start(_L("Simple RMessage2 tests")); |
|
686 SimpleRMessage(); |
|
687 |
|
688 test.Next(_L("Simple RMessagePtr2 tests")); |
|
689 SimpleRMessagePtr(); |
|
690 |
|
691 test.Next(_L("Sending messages between two threads")); |
|
692 test.Start(_L("Create client and server threads")); |
|
693 clientThread.Create(_L("Client Thread"),ClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
|
694 serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
|
695 |
|
696 test.Next(_L("Logon to the threads")); |
|
697 TRequestStatus clientStat,serverStat; |
|
698 clientThread.Logon(clientStat); |
|
699 serverThread.Logon(serverStat); |
|
700 |
|
701 test.Next(_L("Start the threads")); |
|
702 sem.CreateLocal(0); |
|
703 clientThread.Resume(); |
|
704 serverThread.Resume(); |
|
705 |
|
706 test.Next(_L("Wait for the threads to stop")); |
|
707 if(clientStat==KRequestPending) |
|
708 User::WaitForRequest(clientStat); |
|
709 if(serverStat==KRequestPending) |
|
710 User::WaitForRequest(serverStat); |
|
711 switch (clientThread.ExitType()) |
|
712 { |
|
713 case EExitKill: |
|
714 test.Printf(_L(" Client thread killed\n")); |
|
715 break; |
|
716 case EExitTerminate: |
|
717 test.Printf(_L("!!Client thread terminated:")); |
|
718 test.Panic(clientThread.ExitCategory(), clientThread.ExitReason()); |
|
719 case EExitPanic: |
|
720 test.Panic(_L("!!Client thread panicked:")); |
|
721 test.Panic(clientThread.ExitCategory(), clientThread.ExitReason()); |
|
722 default: |
|
723 test.Panic(_L("!!Client thread did something bizarre"), clientThread.ExitReason()); |
|
724 } |
|
725 switch (serverThread.ExitType()) |
|
726 { |
|
727 case EExitKill: |
|
728 test.Printf(_L(" Server thread killed\n")); |
|
729 break; |
|
730 case EExitTerminate: |
|
731 test.Printf(_L("!!Server thread terminated:")); |
|
732 test.Panic(serverThread.ExitCategory(), serverThread.ExitReason()); |
|
733 case EExitPanic: |
|
734 test.Printf(_L("!!Server thread panicked:")); |
|
735 test.Panic(serverThread.ExitCategory(), serverThread.ExitReason()); |
|
736 // |
|
737 // To catch a panic put a breakpoint in User::Panic() (in UCDT\UC_UNC.CPP). |
|
738 // |
|
739 default: |
|
740 test.Panic(_L("!!Server thread did something bizarre"), serverThread.ExitReason()); |
|
741 } |
|
742 |
|
743 test.Next(_L("Close the threads")); |
|
744 CLOSE_AND_WAIT(serverThread); |
|
745 CLOSE_AND_WAIT(clientThread); |
|
746 test.End(); |
|
747 |
|
748 TestServerCompleteTwicePanic(); |
|
749 |
|
750 TestServerKillCompletePanic(); |
681 |
751 |
682 test.End(); |
752 test.End(); |
683 |
753 |
684 return (KErrNone); |
754 return (KErrNone); |
685 } |
755 } |