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