gecko/ipc/ipdl/test/cxx/TestStackHooks.h
2010-02-16 12:44:23 -06:00

124 lines
2.3 KiB
C++

#ifndef mozilla__ipdltest_TestStackHooks_h
#define mozilla__ipdltest_TestStackHooks_h 1
#include "mozilla/_ipdltest/IPDLUnitTests.h"
#include "mozilla/_ipdltest/PTestStackHooksParent.h"
#include "mozilla/_ipdltest/PTestStackHooksChild.h"
namespace mozilla {
namespace _ipdltest {
class TestStackHooksParent :
public PTestStackHooksParent
{
public:
TestStackHooksParent();
virtual ~TestStackHooksParent();
void Main();
protected:
NS_OVERRIDE
virtual bool RecvAsync() {
if (!mOnStack)
fail("not on C++ stack?!");
return true;
}
NS_OVERRIDE
virtual bool RecvSync() {
if (!mOnStack)
fail("not on C++ stack?!");
return true;
}
NS_OVERRIDE
virtual bool AnswerRpc() {
if (!mOnStack)
fail("not on C++ stack?!");
return true;
}
NS_OVERRIDE
virtual bool AnswerStackFrame();
NS_OVERRIDE
virtual void ActorDestroy(ActorDestroyReason why)
{
if (NormalShutdown != why)
fail("unexpected destruction!");
passed("ok");
QuitParent();
}
NS_OVERRIDE
virtual void EnteredCxxStack() {
mOnStack = true;
}
NS_OVERRIDE
virtual void ExitedCxxStack() {
mOnStack = false;
}
private:
bool mOnStack;
};
class TestStackHooksChild :
public PTestStackHooksChild
{
public:
TestStackHooksChild();
virtual ~TestStackHooksChild();
void RunTests();
protected:
NS_OVERRIDE
virtual bool RecvStart();
NS_OVERRIDE
virtual bool AnswerStackFrame();
NS_OVERRIDE
virtual void ActorDestroy(ActorDestroyReason why)
{
if (NormalShutdown != why)
fail("unexpected destruction!");
if (mEntered != mExited)
fail("unbalanced enter/exit notifications");
if (mOnStack)
fail("computing mOnStack went awry; should have failed above assertion");
QuitChild();
}
NS_OVERRIDE
virtual void EnteredCxxStack() {
++mEntered;
mOnStack = true;
}
NS_OVERRIDE
virtual void ExitedCxxStack() {
++mExited;
mOnStack = false;
}
private:
bool mOnStack;
int mEntered;
int mExited;
};
} // namespace _ipdltest
} // namespace mozilla
#endif // ifndef mozilla__ipdltest_TestStackHooks_h