1 #ifndef mozilla__ipdltest_TestDemon_h
2 #define mozilla__ipdltest_TestDemon_h 1
3 
4 #include "mozilla/_ipdltest/IPDLUnitTests.h"
5 
6 #include "mozilla/_ipdltest/PTestDemonParent.h"
7 #include "mozilla/_ipdltest/PTestDemonChild.h"
8 
9 using namespace mozilla::ipc;
10 
11 namespace mozilla {
12 namespace _ipdltest {
13 
14 
15 class TestDemonParent :
16     public PTestDemonParent
17 {
18 public:
19     TestDemonParent();
20     virtual ~TestDemonParent();
21 
RunTestInProcesses()22     static bool RunTestInProcesses() { return true; }
RunTestInThreads()23     static bool RunTestInThreads() { return true; }
24 
25     void Main();
26 
27 #ifdef DEBUG
28     bool ShouldContinueFromReplyTimeout() override;
29     bool ArtificialTimeout() override;
30 
NeedArtificialSleep()31     bool NeedArtificialSleep() override { return true; }
32     void ArtificialSleep() override;
33 #endif
34 
35     mozilla::ipc::IPCResult RecvAsyncMessage(const int& n) override;
36     mozilla::ipc::IPCResult RecvHiPrioSyncMessage() override;
37 
38     mozilla::ipc::IPCResult RecvSyncMessage(const int& n) override;
39     mozilla::ipc::IPCResult RecvUrgentAsyncMessage(const int& n) override;
40     mozilla::ipc::IPCResult RecvUrgentSyncMessage(const int& n) override;
41 
ActorDestroy(ActorDestroyReason why)42     virtual void ActorDestroy(ActorDestroyReason why) override
43     {
44 	mDone = true;
45 	printf("Parent ActorDestroy\n");
46         passed("ok");
47         QuitParent();
48     }
49 
50 private:
51     bool mDone;
52     int mIncoming[3];
53     int mOutgoing[3];
54 
55     enum {
56 	ASYNC_ONLY = 1,
57     };
58 
59     void RunUnlimitedSequence();
60     void RunLimitedSequence(int flags = 0);
61     bool DoAction(int flags = 0);
62 };
63 
64 
65 class TestDemonChild :
66     public PTestDemonChild
67 {
68 public:
69     TestDemonChild();
70     virtual ~TestDemonChild();
71 
72     mozilla::ipc::IPCResult RecvStart() override;
73 
74 #ifdef DEBUG
NeedArtificialSleep()75     bool NeedArtificialSleep() override { return true; }
76     void ArtificialSleep() override;
77 #endif
78 
79     mozilla::ipc::IPCResult RecvAsyncMessage(const int& n) override;
80     mozilla::ipc::IPCResult RecvHiPrioSyncMessage() override;
81 
ActorDestroy(ActorDestroyReason why)82     virtual void ActorDestroy(ActorDestroyReason why) override
83     {
84 	_exit(0);
85     }
86 
IntentionalCrash()87     virtual void IntentionalCrash() override
88     {
89 	_exit(0);
90     }
91 
92 private:
93     int mIncoming[3];
94     int mOutgoing[3];
95 
96     void RunUnlimitedSequence();
97     void RunLimitedSequence();
98     bool DoAction();
99 };
100 
101 
102 } // namespace _ipdltest
103 } // namespace mozilla
104 
105 
106 #endif // ifndef mozilla__ipdltest_TestDemon_h
107