ipc/ipdl/test/cxx/TestStackHooks.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/ipdl/test/cxx/TestStackHooks.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,130 @@
     1.4 +#ifndef mozilla__ipdltest_TestStackHooks_h
     1.5 +#define mozilla__ipdltest_TestStackHooks_h 1
     1.6 +
     1.7 +#include "mozilla/_ipdltest/IPDLUnitTests.h"
     1.8 +
     1.9 +#include "mozilla/_ipdltest/PTestStackHooksParent.h"
    1.10 +#include "mozilla/_ipdltest/PTestStackHooksChild.h"
    1.11 +
    1.12 +namespace mozilla {
    1.13 +namespace _ipdltest {
    1.14 +
    1.15 +
    1.16 +class TestStackHooksParent :
    1.17 +    public PTestStackHooksParent
    1.18 +{
    1.19 +public:
    1.20 +    TestStackHooksParent();
    1.21 +    virtual ~TestStackHooksParent();
    1.22 +
    1.23 +    static bool RunTestInProcesses() { return true; }
    1.24 +    static bool RunTestInThreads() { return true; }
    1.25 +
    1.26 +    void Main();
    1.27 +
    1.28 +protected:    
    1.29 +    virtual bool RecvAsync() MOZ_OVERRIDE {
    1.30 +        if (!mOnStack)
    1.31 +            fail("not on C++ stack?!");
    1.32 +        return true;
    1.33 +    }
    1.34 +
    1.35 +    virtual bool RecvSync() MOZ_OVERRIDE {
    1.36 +        if (!mOnStack)
    1.37 +            fail("not on C++ stack?!");
    1.38 +        return true;
    1.39 +    }
    1.40 +
    1.41 +    virtual bool AnswerRpc() MOZ_OVERRIDE {
    1.42 +        if (!mOnStack)
    1.43 +            fail("not on C++ stack?!");
    1.44 +        return true;
    1.45 +    }
    1.46 +
    1.47 +    virtual bool AnswerStackFrame() MOZ_OVERRIDE;
    1.48 +
    1.49 +    virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE
    1.50 +    {
    1.51 +        if (NormalShutdown != why)
    1.52 +            fail("unexpected destruction!");  
    1.53 +        passed("ok");
    1.54 +        QuitParent();
    1.55 +    }
    1.56 +
    1.57 +    virtual void EnteredCxxStack() MOZ_OVERRIDE {
    1.58 +        mOnStack = true;
    1.59 +    }
    1.60 +    virtual void ExitedCxxStack() MOZ_OVERRIDE {
    1.61 +        mOnStack = false;
    1.62 +    }
    1.63 +
    1.64 +    virtual void EnteredCall() MOZ_OVERRIDE {
    1.65 +        ++mIncallDepth;
    1.66 +    }
    1.67 +    virtual void ExitedCall() MOZ_OVERRIDE {
    1.68 +        --mIncallDepth;
    1.69 +    }
    1.70 +
    1.71 +private:
    1.72 +    bool mOnStack;
    1.73 +    int mIncallDepth;
    1.74 +};
    1.75 +
    1.76 +
    1.77 +class TestStackHooksChild :
    1.78 +    public PTestStackHooksChild
    1.79 +{
    1.80 +public:
    1.81 +    TestStackHooksChild();
    1.82 +    virtual ~TestStackHooksChild();
    1.83 +
    1.84 +    void RunTests();
    1.85 +
    1.86 +protected:
    1.87 +    virtual bool RecvStart() MOZ_OVERRIDE;
    1.88 +
    1.89 +    virtual bool AnswerStackFrame() MOZ_OVERRIDE;
    1.90 +
    1.91 +    virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE
    1.92 +    {
    1.93 +        if (NormalShutdown != why)
    1.94 +            fail("unexpected destruction!");
    1.95 +
    1.96 +        if (mEntered != mExited)
    1.97 +            fail("unbalanced enter/exit notifications");
    1.98 +
    1.99 +        if (mOnStack)
   1.100 +            fail("computing mOnStack went awry; should have failed above assertion");
   1.101 +
   1.102 +        QuitChild();
   1.103 +    }
   1.104 +
   1.105 +    virtual void EnteredCxxStack() MOZ_OVERRIDE {
   1.106 +        ++mEntered;
   1.107 +        mOnStack = true;
   1.108 +    }
   1.109 +    virtual void ExitedCxxStack() MOZ_OVERRIDE {
   1.110 +        ++mExited;
   1.111 +        mOnStack = false;
   1.112 +    }
   1.113 +
   1.114 +    virtual void EnteredCall() MOZ_OVERRIDE {
   1.115 +        ++mIncallDepth;
   1.116 +    }
   1.117 +    virtual void ExitedCall() MOZ_OVERRIDE {
   1.118 +        --mIncallDepth;
   1.119 +    }
   1.120 +
   1.121 +private:
   1.122 +    bool mOnStack;
   1.123 +    int mEntered;
   1.124 +    int mExited;
   1.125 +    int mIncallDepth;
   1.126 +};
   1.127 +
   1.128 +
   1.129 +} // namespace _ipdltest
   1.130 +} // namespace mozilla
   1.131 +
   1.132 +
   1.133 +#endif // ifndef mozilla__ipdltest_TestStackHooks_h

mercurial