Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 #include "TestStackHooks.h"
3 #include "IPDLUnitTests.h" // fail etc.
7 namespace mozilla {
8 namespace _ipdltest {
10 //-----------------------------------------------------------------------------
11 // parent
13 TestStackHooksParent::TestStackHooksParent() :
14 mOnStack(false), mIncallDepth(0)
15 {
16 MOZ_COUNT_CTOR(TestStackHooksParent);
17 }
19 TestStackHooksParent::~TestStackHooksParent()
20 {
21 MOZ_COUNT_DTOR(TestStackHooksParent);
22 }
24 void
25 TestStackHooksParent::Main()
26 {
27 if (!SendStart())
28 fail("sending Start()");
29 }
32 bool
33 TestStackHooksParent::AnswerStackFrame()
34 {
35 if (!mOnStack)
36 fail("not on C++ stack?!");
38 if (!CallStackFrame())
39 fail("calling StackFrame()");
41 if (!mOnStack)
42 fail("not on C++ stack?!");
44 if (1 != mIncallDepth)
45 fail("missed EnteredCall or ExitedCall hook");
47 return true;
48 }
50 //-----------------------------------------------------------------------------
51 // child
53 TestStackHooksChild::TestStackHooksChild() :
54 mOnStack(false),
55 mEntered(0),
56 mExited(0),
57 mIncallDepth(0)
58 {
59 MOZ_COUNT_CTOR(TestStackHooksChild);
60 }
62 TestStackHooksChild::~TestStackHooksChild()
63 {
64 MOZ_COUNT_DTOR(TestStackHooksChild);
65 }
67 namespace {
68 void RunTestsFn() {
69 static_cast<TestStackHooksChild*>(gChildActor)->RunTests();
70 }
71 }
73 bool
74 TestStackHooksChild::RecvStart()
75 {
76 if (!mOnStack)
77 fail("missed stack notification");
79 if (0 != mIncallDepth)
80 fail("EnteredCall/ExitedCall malfunction");
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));
87 return true;
88 }
90 bool
91 TestStackHooksChild::AnswerStackFrame()
92 {
93 if (!mOnStack)
94 fail("missed stack notification");
96 if (1 != mIncallDepth)
97 fail("missed EnteredCall or ExitedCall hook");
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 }
111 if (!mOnStack)
112 fail("bad stack exit notification");
114 return true;
115 }
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");
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");
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");
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");
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");
164 Close();
165 }
167 } // namespace _ipdltest
168 } // namespace mozilla