|
1 #include "TestStackHooks.h" |
|
2 |
|
3 #include "IPDLUnitTests.h" // fail etc. |
|
4 |
|
5 |
|
6 |
|
7 namespace mozilla { |
|
8 namespace _ipdltest { |
|
9 |
|
10 //----------------------------------------------------------------------------- |
|
11 // parent |
|
12 |
|
13 TestStackHooksParent::TestStackHooksParent() : |
|
14 mOnStack(false), mIncallDepth(0) |
|
15 { |
|
16 MOZ_COUNT_CTOR(TestStackHooksParent); |
|
17 } |
|
18 |
|
19 TestStackHooksParent::~TestStackHooksParent() |
|
20 { |
|
21 MOZ_COUNT_DTOR(TestStackHooksParent); |
|
22 } |
|
23 |
|
24 void |
|
25 TestStackHooksParent::Main() |
|
26 { |
|
27 if (!SendStart()) |
|
28 fail("sending Start()"); |
|
29 } |
|
30 |
|
31 |
|
32 bool |
|
33 TestStackHooksParent::AnswerStackFrame() |
|
34 { |
|
35 if (!mOnStack) |
|
36 fail("not on C++ stack?!"); |
|
37 |
|
38 if (!CallStackFrame()) |
|
39 fail("calling StackFrame()"); |
|
40 |
|
41 if (!mOnStack) |
|
42 fail("not on C++ stack?!"); |
|
43 |
|
44 if (1 != mIncallDepth) |
|
45 fail("missed EnteredCall or ExitedCall hook"); |
|
46 |
|
47 return true; |
|
48 } |
|
49 |
|
50 //----------------------------------------------------------------------------- |
|
51 // child |
|
52 |
|
53 TestStackHooksChild::TestStackHooksChild() : |
|
54 mOnStack(false), |
|
55 mEntered(0), |
|
56 mExited(0), |
|
57 mIncallDepth(0) |
|
58 { |
|
59 MOZ_COUNT_CTOR(TestStackHooksChild); |
|
60 } |
|
61 |
|
62 TestStackHooksChild::~TestStackHooksChild() |
|
63 { |
|
64 MOZ_COUNT_DTOR(TestStackHooksChild); |
|
65 } |
|
66 |
|
67 namespace { |
|
68 void RunTestsFn() { |
|
69 static_cast<TestStackHooksChild*>(gChildActor)->RunTests(); |
|
70 } |
|
71 } |
|
72 |
|
73 bool |
|
74 TestStackHooksChild::RecvStart() |
|
75 { |
|
76 if (!mOnStack) |
|
77 fail("missed stack notification"); |
|
78 |
|
79 if (0 != mIncallDepth) |
|
80 fail("EnteredCall/ExitedCall malfunction"); |
|
81 |
|
82 // kick off tests from a runnable so that we can start with |
|
83 // MessageChannel code on the C++ stack |
|
84 MessageLoop::current()->PostTask(FROM_HERE, |
|
85 NewRunnableFunction(RunTestsFn)); |
|
86 |
|
87 return true; |
|
88 } |
|
89 |
|
90 bool |
|
91 TestStackHooksChild::AnswerStackFrame() |
|
92 { |
|
93 if (!mOnStack) |
|
94 fail("missed stack notification"); |
|
95 |
|
96 if (1 != mIncallDepth) |
|
97 fail("missed EnteredCall or ExitedCall hook"); |
|
98 |
|
99 if (PTestStackHooks::TEST4_3 == state()) { |
|
100 if (!SendAsync()) |
|
101 fail("sending Async()"); |
|
102 } |
|
103 else if (PTestStackHooks::TEST5_3 == state()) { |
|
104 if (!SendSync()) |
|
105 fail("sending Sync()"); |
|
106 } |
|
107 else { |
|
108 fail("unexpected state"); |
|
109 } |
|
110 |
|
111 if (!mOnStack) |
|
112 fail("bad stack exit notification"); |
|
113 |
|
114 return true; |
|
115 } |
|
116 |
|
117 void |
|
118 TestStackHooksChild::RunTests() |
|
119 { |
|
120 // 1 because of RecvStart() |
|
121 if (1 != mEntered) |
|
122 fail("missed stack notification"); |
|
123 if (mOnStack) |
|
124 fail("spurious stack notification"); |
|
125 if (0 != mIncallDepth) |
|
126 fail("EnteredCall/ExitedCall malfunction"); |
|
127 |
|
128 if (!SendAsync()) |
|
129 fail("sending Async()"); |
|
130 if (mOnStack) |
|
131 fail("spurious stack notification"); |
|
132 if (0 != mIncallDepth) |
|
133 fail("EnteredCall/ExitedCall malfunction"); |
|
134 if (2 != mEntered) |
|
135 fail("missed stack notification"); |
|
136 |
|
137 if (!SendSync()) |
|
138 fail("sending Sync()"); |
|
139 if (mOnStack) |
|
140 fail("spurious stack notification"); |
|
141 if (0 != mIncallDepth) |
|
142 fail("EnteredCall/ExitedCall malfunction"); |
|
143 if (3 != mEntered) |
|
144 fail("missed stack notification"); |
|
145 |
|
146 if (!CallRpc()) |
|
147 fail("calling RPC()"); |
|
148 if (mOnStack) |
|
149 fail("spurious stack notification"); |
|
150 if (0 != mIncallDepth) |
|
151 fail("EnteredCall/ExitedCall malfunction"); |
|
152 if (4 != mEntered) |
|
153 fail("missed stack notification"); |
|
154 |
|
155 if (!CallStackFrame()) |
|
156 fail("calling StackFrame()"); |
|
157 if (mOnStack) |
|
158 fail("spurious stack notification"); |
|
159 if (0 != mIncallDepth) |
|
160 fail("EnteredCall/ExitedCall malfunction"); |
|
161 if (5 != mEntered) |
|
162 fail("missed stack notification"); |
|
163 |
|
164 Close(); |
|
165 } |
|
166 |
|
167 } // namespace _ipdltest |
|
168 } // namespace mozilla |