ipc/ipdl/test/cxx/TestStackHooks.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/ipdl/test/cxx/TestStackHooks.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,168 @@
     1.4 +#include "TestStackHooks.h"
     1.5 +
     1.6 +#include "IPDLUnitTests.h"      // fail etc.
     1.7 +
     1.8 +
     1.9 +
    1.10 +namespace mozilla {
    1.11 +namespace _ipdltest {
    1.12 +
    1.13 +//-----------------------------------------------------------------------------
    1.14 +// parent
    1.15 +
    1.16 +TestStackHooksParent::TestStackHooksParent() :
    1.17 +    mOnStack(false), mIncallDepth(0)
    1.18 +{
    1.19 +    MOZ_COUNT_CTOR(TestStackHooksParent);
    1.20 +}
    1.21 +
    1.22 +TestStackHooksParent::~TestStackHooksParent()
    1.23 +{
    1.24 +    MOZ_COUNT_DTOR(TestStackHooksParent);
    1.25 +}
    1.26 +
    1.27 +void
    1.28 +TestStackHooksParent::Main()
    1.29 +{
    1.30 +    if (!SendStart())
    1.31 +        fail("sending Start()");
    1.32 +}
    1.33 +
    1.34 +
    1.35 +bool
    1.36 +TestStackHooksParent::AnswerStackFrame()
    1.37 +{
    1.38 +    if (!mOnStack)
    1.39 +        fail("not on C++ stack?!");
    1.40 +
    1.41 +    if (!CallStackFrame())
    1.42 +        fail("calling StackFrame()");
    1.43 +
    1.44 +    if (!mOnStack)
    1.45 +        fail("not on C++ stack?!");
    1.46 +
    1.47 +    if (1 != mIncallDepth)
    1.48 +        fail("missed EnteredCall or ExitedCall hook");
    1.49 +
    1.50 +    return true;
    1.51 +}
    1.52 +
    1.53 +//-----------------------------------------------------------------------------
    1.54 +// child
    1.55 +
    1.56 +TestStackHooksChild::TestStackHooksChild() :
    1.57 +    mOnStack(false),
    1.58 +    mEntered(0),
    1.59 +    mExited(0),
    1.60 +    mIncallDepth(0)
    1.61 +{
    1.62 +    MOZ_COUNT_CTOR(TestStackHooksChild);
    1.63 +}
    1.64 +
    1.65 +TestStackHooksChild::~TestStackHooksChild()
    1.66 +{
    1.67 +    MOZ_COUNT_DTOR(TestStackHooksChild);
    1.68 +}
    1.69 +
    1.70 +namespace {
    1.71 +void RunTestsFn() {
    1.72 +    static_cast<TestStackHooksChild*>(gChildActor)->RunTests();
    1.73 +}
    1.74 +}
    1.75 +
    1.76 +bool
    1.77 +TestStackHooksChild::RecvStart()
    1.78 +{
    1.79 +    if (!mOnStack)
    1.80 +        fail("missed stack notification");
    1.81 +
    1.82 +    if (0 != mIncallDepth)
    1.83 +        fail("EnteredCall/ExitedCall malfunction");
    1.84 +
    1.85 +    // kick off tests from a runnable so that we can start with
    1.86 +    // MessageChannel code on the C++ stack
    1.87 +    MessageLoop::current()->PostTask(FROM_HERE,
    1.88 +                                     NewRunnableFunction(RunTestsFn));
    1.89 +
    1.90 +    return true;
    1.91 +}
    1.92 +
    1.93 +bool
    1.94 +TestStackHooksChild::AnswerStackFrame()
    1.95 +{
    1.96 +    if (!mOnStack)
    1.97 +        fail("missed stack notification");
    1.98 +
    1.99 +    if (1 != mIncallDepth)
   1.100 +        fail("missed EnteredCall or ExitedCall hook");
   1.101 +
   1.102 +    if (PTestStackHooks::TEST4_3 == state()) {
   1.103 +        if (!SendAsync())
   1.104 +            fail("sending Async()");
   1.105 +    }
   1.106 +    else if (PTestStackHooks::TEST5_3 == state()) {
   1.107 +        if (!SendSync())
   1.108 +            fail("sending Sync()");
   1.109 +    }
   1.110 +    else {
   1.111 +        fail("unexpected state");
   1.112 +    }
   1.113 +
   1.114 +    if (!mOnStack)
   1.115 +        fail("bad stack exit notification");
   1.116 +
   1.117 +    return true;
   1.118 +}
   1.119 +
   1.120 +void
   1.121 +TestStackHooksChild::RunTests()
   1.122 +{
   1.123 +    // 1 because of RecvStart()
   1.124 +    if (1 != mEntered)
   1.125 +        fail("missed stack notification");
   1.126 +    if (mOnStack)
   1.127 +        fail("spurious stack notification");
   1.128 +    if (0 != mIncallDepth)
   1.129 +        fail("EnteredCall/ExitedCall malfunction");
   1.130 +
   1.131 +    if (!SendAsync())
   1.132 +        fail("sending Async()");
   1.133 +    if (mOnStack)
   1.134 +        fail("spurious stack notification");
   1.135 +    if (0 != mIncallDepth)
   1.136 +        fail("EnteredCall/ExitedCall malfunction");
   1.137 +    if (2 != mEntered)
   1.138 +        fail("missed stack notification");
   1.139 +
   1.140 +    if (!SendSync())
   1.141 +        fail("sending Sync()");
   1.142 +    if (mOnStack)
   1.143 +        fail("spurious stack notification");
   1.144 +    if (0 != mIncallDepth)
   1.145 +        fail("EnteredCall/ExitedCall malfunction");
   1.146 +    if (3 != mEntered)
   1.147 +        fail("missed stack notification");
   1.148 +
   1.149 +    if (!CallRpc())
   1.150 +        fail("calling RPC()");
   1.151 +    if (mOnStack)
   1.152 +        fail("spurious stack notification");
   1.153 +    if (0 != mIncallDepth)
   1.154 +        fail("EnteredCall/ExitedCall malfunction");
   1.155 +    if (4 != mEntered)
   1.156 +        fail("missed stack notification");
   1.157 +
   1.158 +    if (!CallStackFrame())
   1.159 +        fail("calling StackFrame()");
   1.160 +    if (mOnStack)
   1.161 +        fail("spurious stack notification");
   1.162 +    if (0 != mIncallDepth)
   1.163 +        fail("EnteredCall/ExitedCall malfunction");
   1.164 +    if (5 != mEntered)
   1.165 +        fail("missed stack notification");
   1.166 +
   1.167 +    Close();
   1.168 +}
   1.169 +
   1.170 +} // namespace _ipdltest
   1.171 +} // namespace mozilla

mercurial