ipc/ipdl/test/cxx/TestStackHooks.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:f1daec566b33
1 #ifndef mozilla__ipdltest_TestStackHooks_h
2 #define mozilla__ipdltest_TestStackHooks_h 1
3
4 #include "mozilla/_ipdltest/IPDLUnitTests.h"
5
6 #include "mozilla/_ipdltest/PTestStackHooksParent.h"
7 #include "mozilla/_ipdltest/PTestStackHooksChild.h"
8
9 namespace mozilla {
10 namespace _ipdltest {
11
12
13 class TestStackHooksParent :
14 public PTestStackHooksParent
15 {
16 public:
17 TestStackHooksParent();
18 virtual ~TestStackHooksParent();
19
20 static bool RunTestInProcesses() { return true; }
21 static bool RunTestInThreads() { return true; }
22
23 void Main();
24
25 protected:
26 virtual bool RecvAsync() MOZ_OVERRIDE {
27 if (!mOnStack)
28 fail("not on C++ stack?!");
29 return true;
30 }
31
32 virtual bool RecvSync() MOZ_OVERRIDE {
33 if (!mOnStack)
34 fail("not on C++ stack?!");
35 return true;
36 }
37
38 virtual bool AnswerRpc() MOZ_OVERRIDE {
39 if (!mOnStack)
40 fail("not on C++ stack?!");
41 return true;
42 }
43
44 virtual bool AnswerStackFrame() MOZ_OVERRIDE;
45
46 virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE
47 {
48 if (NormalShutdown != why)
49 fail("unexpected destruction!");
50 passed("ok");
51 QuitParent();
52 }
53
54 virtual void EnteredCxxStack() MOZ_OVERRIDE {
55 mOnStack = true;
56 }
57 virtual void ExitedCxxStack() MOZ_OVERRIDE {
58 mOnStack = false;
59 }
60
61 virtual void EnteredCall() MOZ_OVERRIDE {
62 ++mIncallDepth;
63 }
64 virtual void ExitedCall() MOZ_OVERRIDE {
65 --mIncallDepth;
66 }
67
68 private:
69 bool mOnStack;
70 int mIncallDepth;
71 };
72
73
74 class TestStackHooksChild :
75 public PTestStackHooksChild
76 {
77 public:
78 TestStackHooksChild();
79 virtual ~TestStackHooksChild();
80
81 void RunTests();
82
83 protected:
84 virtual bool RecvStart() MOZ_OVERRIDE;
85
86 virtual bool AnswerStackFrame() MOZ_OVERRIDE;
87
88 virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE
89 {
90 if (NormalShutdown != why)
91 fail("unexpected destruction!");
92
93 if (mEntered != mExited)
94 fail("unbalanced enter/exit notifications");
95
96 if (mOnStack)
97 fail("computing mOnStack went awry; should have failed above assertion");
98
99 QuitChild();
100 }
101
102 virtual void EnteredCxxStack() MOZ_OVERRIDE {
103 ++mEntered;
104 mOnStack = true;
105 }
106 virtual void ExitedCxxStack() MOZ_OVERRIDE {
107 ++mExited;
108 mOnStack = false;
109 }
110
111 virtual void EnteredCall() MOZ_OVERRIDE {
112 ++mIncallDepth;
113 }
114 virtual void ExitedCall() MOZ_OVERRIDE {
115 --mIncallDepth;
116 }
117
118 private:
119 bool mOnStack;
120 int mEntered;
121 int mExited;
122 int mIncallDepth;
123 };
124
125
126 } // namespace _ipdltest
127 } // namespace mozilla
128
129
130 #endif // ifndef mozilla__ipdltest_TestStackHooks_h

mercurial