|
1 #if defined(OS_POSIX) |
|
2 #include <unistd.h> // sleep() |
|
3 #endif |
|
4 |
|
5 #include "TestSyncWakeup.h" |
|
6 |
|
7 #include "IPDLUnitTests.h" // fail etc. |
|
8 |
|
9 namespace mozilla { |
|
10 namespace _ipdltest { |
|
11 |
|
12 //----------------------------------------------------------------------------- |
|
13 // parent |
|
14 |
|
15 TestSyncWakeupParent::TestSyncWakeupParent() |
|
16 { |
|
17 MOZ_COUNT_CTOR(TestSyncWakeupParent); |
|
18 } |
|
19 |
|
20 TestSyncWakeupParent::~TestSyncWakeupParent() |
|
21 { |
|
22 MOZ_COUNT_DTOR(TestSyncWakeupParent); |
|
23 } |
|
24 |
|
25 void |
|
26 TestSyncWakeupParent::Main() |
|
27 { |
|
28 if (!SendStart()) |
|
29 fail("sending Start()"); |
|
30 } |
|
31 |
|
32 bool |
|
33 TestSyncWakeupParent::AnswerStackFrame() |
|
34 { |
|
35 if (!CallStackFrame()) |
|
36 fail("calling StackFrame()"); |
|
37 return true; |
|
38 } |
|
39 |
|
40 bool |
|
41 TestSyncWakeupParent::RecvSync1() |
|
42 { |
|
43 if (!SendNote1()) |
|
44 fail("sending Note1()"); |
|
45 |
|
46 // XXX ugh ... need to ensure that the async message and sync |
|
47 // reply come in "far enough" apart that this test doesn't pass on |
|
48 // accident |
|
49 #if defined(OS_POSIX) |
|
50 // NB: can't use PR_Sleep (i.e. Sleep() on windows) because it's |
|
51 // only spec'd to block the current thread, not the current |
|
52 // process. We need the IO thread to sleep as well. |
|
53 puts(" (sleeping for 5 seconds. sorry!)"); |
|
54 sleep(5); |
|
55 #endif |
|
56 |
|
57 return true; |
|
58 } |
|
59 |
|
60 bool |
|
61 TestSyncWakeupParent::RecvSync2() |
|
62 { |
|
63 if (!SendNote2()) |
|
64 fail("sending Note2()"); |
|
65 |
|
66 #if defined(OS_POSIX) |
|
67 // see above |
|
68 sleep(5); |
|
69 puts(" (sleeping for 5 seconds. sorry!)"); |
|
70 #endif |
|
71 |
|
72 return true; |
|
73 } |
|
74 |
|
75 //----------------------------------------------------------------------------- |
|
76 // child |
|
77 |
|
78 TestSyncWakeupChild::TestSyncWakeupChild() : mDone(false) |
|
79 { |
|
80 MOZ_COUNT_CTOR(TestSyncWakeupChild); |
|
81 } |
|
82 |
|
83 TestSyncWakeupChild::~TestSyncWakeupChild() |
|
84 { |
|
85 MOZ_COUNT_DTOR(TestSyncWakeupChild); |
|
86 } |
|
87 |
|
88 bool |
|
89 TestSyncWakeupChild::RecvStart() |
|
90 { |
|
91 // First test: the parent fires back an async message while |
|
92 // replying to a sync one |
|
93 if (!SendSync1()) |
|
94 fail("sending Sync()"); |
|
95 |
|
96 // drop back into the event loop to get Note1(), then kick off the |
|
97 // second test |
|
98 return true; |
|
99 } |
|
100 |
|
101 bool |
|
102 TestSyncWakeupChild::RecvNote1() |
|
103 { |
|
104 // Second test: the parent fires back an async message while |
|
105 // replying to a sync one, with a frame on the RPC stack |
|
106 if (!CallStackFrame()) |
|
107 fail("calling StackFrame()"); |
|
108 |
|
109 if (!mDone) |
|
110 fail("should have received Note2()!"); |
|
111 |
|
112 Close(); |
|
113 |
|
114 return true; |
|
115 } |
|
116 |
|
117 bool |
|
118 TestSyncWakeupChild::AnswerStackFrame() |
|
119 { |
|
120 if (!SendSync2()) |
|
121 fail("sending Sync()"); |
|
122 |
|
123 return true; |
|
124 } |
|
125 |
|
126 bool |
|
127 TestSyncWakeupChild::RecvNote2() |
|
128 { |
|
129 mDone = true; |
|
130 return true; |
|
131 } |
|
132 |
|
133 } // namespace _ipdltest |
|
134 } // namespace mozilla |