diff --git a/ipc/ipdl/test/cxx/Makefile.in b/ipc/ipdl/test/cxx/Makefile.in index c24453452db..12185328a8c 100644 --- a/ipc/ipdl/test/cxx/Makefile.in +++ b/ipc/ipdl/test/cxx/Makefile.in @@ -62,6 +62,7 @@ IPDLTESTS = \ TestCrashCleanup \ TestDataStructures \ TestDesc \ + TestFailedCtor \ TestHangs \ TestJSON \ TestLatency \ diff --git a/ipc/ipdl/test/cxx/PTestFailedCtor.ipdl b/ipc/ipdl/test/cxx/PTestFailedCtor.ipdl new file mode 100644 index 00000000000..f71de11b7b3 --- /dev/null +++ b/ipc/ipdl/test/cxx/PTestFailedCtor.ipdl @@ -0,0 +1,19 @@ +include protocol PTestFailedCtorSub; + +namespace mozilla { +namespace _ipdltest { + +rpc protocol PTestFailedCtor { + manages PTestFailedCtorSub; +child: + rpc PTestFailedCtorSub(); + __delete__(); + +state CONSTRUCT: + call PTestFailedCtorSub goto DEAD; +state DEAD: + send __delete__; +}; + +} +} diff --git a/ipc/ipdl/test/cxx/PTestFailedCtorSub.ipdl b/ipc/ipdl/test/cxx/PTestFailedCtorSub.ipdl new file mode 100644 index 00000000000..4ccc8926b5e --- /dev/null +++ b/ipc/ipdl/test/cxx/PTestFailedCtorSub.ipdl @@ -0,0 +1,18 @@ +include protocol PTestFailedCtor; +include protocol PTestFailedCtorSubsub; + +namespace mozilla { +namespace _ipdltest { + +rpc protocol PTestFailedCtorSub { + manager PTestFailedCtor; + manages PTestFailedCtorSubsub; + +parent: + async PTestFailedCtorSubsub(); + sync Sync(); + __delete__(); +}; + +} +} diff --git a/ipc/ipdl/test/cxx/PTestFailedCtorSubsub.ipdl b/ipc/ipdl/test/cxx/PTestFailedCtorSubsub.ipdl new file mode 100644 index 00000000000..101841bffd0 --- /dev/null +++ b/ipc/ipdl/test/cxx/PTestFailedCtorSubsub.ipdl @@ -0,0 +1,15 @@ + +include protocol PTestFailedCtorSub; + +namespace mozilla { +namespace _ipdltest { + +rpc protocol PTestFailedCtorSubsub { + manager PTestFailedCtorSub; + +parent: + __delete__(); +}; + +} +} diff --git a/ipc/ipdl/test/cxx/TestFailedCtor.cpp b/ipc/ipdl/test/cxx/TestFailedCtor.cpp new file mode 100644 index 00000000000..e673cd8966d --- /dev/null +++ b/ipc/ipdl/test/cxx/TestFailedCtor.cpp @@ -0,0 +1,136 @@ +#include "TestFailedCtor.h" + +#include "IPDLUnitTests.h" // fail etc. + +namespace mozilla { +namespace _ipdltest { + +//----------------------------------------------------------------------------- +// parent +void +TestFailedCtorParent::Main() +{ + PTestFailedCtorSubParent* p = CallPTestFailedCtorSubConstructor(); + if (p) + fail("expected ctor to fail"); + + Close(); +} + +PTestFailedCtorSubParent* +TestFailedCtorParent::AllocPTestFailedCtorSub() +{ + return new TestFailedCtorSubParent(); +} +bool +TestFailedCtorParent::DeallocPTestFailedCtorSub(PTestFailedCtorSubParent* actor) +{ + delete actor; + return true; +} + +PTestFailedCtorSubsubParent* +TestFailedCtorSubParent::AllocPTestFailedCtorSubsub() +{ + TestFailedCtorSubsub* a = new TestFailedCtorSubsub(); + if (!mOne) { + return mOne = a; + } else if (!mTwo) { + return mTwo = a; + } else if (!mThree) { + return mThree = a; + } else { + fail("unexpected Alloc()"); + return nsnull; + } +} +bool +TestFailedCtorSubParent::DeallocPTestFailedCtorSubsub(PTestFailedCtorSubsubParent* actor) +{ + static_cast(actor)->mDealloced = true; + return true; +} + +void +TestFailedCtorSubParent::ActorDestroy(ActorDestroyReason why) +{ + + if (mOne->mWhy != Deletion) + fail("Subsub one got wrong ActorDestroyReason"); + if (mTwo->mWhy != AncestorDeletion) + fail("Subsub two got wrong ActorDestroyReason"); + if (mThree->mWhy != AncestorDeletion) + fail("Subsub three got wrong ActorDestroyReason"); + + if (FailedConstructor != why) + fail("unexpected destruction!"); +} + +TestFailedCtorSubParent::~TestFailedCtorSubParent() +{ + if (!(mOne->mDealloced && mTwo->mDealloced && mThree->mDealloced)) + fail("Not all subsubs were Dealloc'd"); + delete mOne; + delete mTwo; + delete mThree; +} + + +//----------------------------------------------------------------------------- +// child + +PTestFailedCtorSubChild* +TestFailedCtorChild::AllocPTestFailedCtorSub() +{ + return new TestFailedCtorSubChild(); +} + +bool +TestFailedCtorChild::AnswerPTestFailedCtorSubConstructor(PTestFailedCtorSubChild* actor) +{ + PTestFailedCtorSubsubChild* c1 = actor->SendPTestFailedCtorSubsubConstructor(); + PTestFailedCtorSubsubChild::Send__delete__(c1); + + if (!actor->SendPTestFailedCtorSubsubConstructor() || + !actor->SendPTestFailedCtorSubsubConstructor() || + !actor->SendSync()) + fail("setting up test"); + + // This causes our process to die + return false; +} + +bool +TestFailedCtorChild::DeallocPTestFailedCtorSub(PTestFailedCtorSubChild* actor) +{ + delete actor; + return true; +} + +void +TestFailedCtorChild::ProcessingError(Result what) +{ + _exit(0); +} + +PTestFailedCtorSubsubChild* +TestFailedCtorSubChild::AllocPTestFailedCtorSubsub() +{ + return new TestFailedCtorSubsub(); +} + +bool +TestFailedCtorSubChild::DeallocPTestFailedCtorSubsub(PTestFailedCtorSubsubChild* actor) +{ + delete actor; + return true; +} + +void +TestFailedCtorSubChild::ActorDestroy(ActorDestroyReason why) +{ +} + + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestFailedCtor.h b/ipc/ipdl/test/cxx/TestFailedCtor.h new file mode 100644 index 00000000000..29e7bc524f4 --- /dev/null +++ b/ipc/ipdl/test/cxx/TestFailedCtor.h @@ -0,0 +1,145 @@ +#ifndef mozilla_ipdltest_TestFailedCtor_h +#define mozilla_ipdltest_TestFailedCtor_h + +#include "mozilla/_ipdltest/IPDLUnitTests.h" + +#include "mozilla/_ipdltest/PTestFailedCtorParent.h" +#include "mozilla/_ipdltest/PTestFailedCtorChild.h" + +#include "mozilla/_ipdltest/PTestFailedCtorSubParent.h" +#include "mozilla/_ipdltest/PTestFailedCtorSubChild.h" + +#include "mozilla/_ipdltest/PTestFailedCtorSubsubParent.h" +#include "mozilla/_ipdltest/PTestFailedCtorSubsubChild.h" + +namespace mozilla { +namespace _ipdltest { + +//----------------------------------------------------------------------------- +// Top-level +// +class TestFailedCtorParent : + public PTestFailedCtorParent +{ +public: + TestFailedCtorParent() { } + virtual ~TestFailedCtorParent() { } + + void Main(); + +protected: + NS_OVERRIDE + virtual PTestFailedCtorSubParent* AllocPTestFailedCtorSub(); + NS_OVERRIDE + virtual bool DeallocPTestFailedCtorSub(PTestFailedCtorSubParent* actor); + + NS_OVERRIDE + virtual void ActorDestroy(ActorDestroyReason why) + { + if (AbnormalShutdown != why) + fail("unexpected destruction!"); + passed("ok"); + QuitParent(); + } +}; + + +class TestFailedCtorChild : + public PTestFailedCtorChild +{ +public: + TestFailedCtorChild() { } + virtual ~TestFailedCtorChild() { } + +protected: + NS_OVERRIDE + virtual PTestFailedCtorSubChild* AllocPTestFailedCtorSub(); + + NS_OVERRIDE + virtual bool AnswerPTestFailedCtorSubConstructor(PTestFailedCtorSubChild* actor); + + NS_OVERRIDE + virtual bool DeallocPTestFailedCtorSub(PTestFailedCtorSubChild* actor); + + NS_OVERRIDE + virtual void ProcessingError(Result what); + + NS_OVERRIDE + virtual void ActorDestroy(ActorDestroyReason why) + { + fail("should have _exit()ed"); + } +}; + + +//----------------------------------------------------------------------------- +// First descendent +// +class TestFailedCtorSubsub; + +class TestFailedCtorSubParent : + public PTestFailedCtorSubParent +{ +public: + TestFailedCtorSubParent() : mOne(NULL), mTwo(NULL), mThree(NULL) { } + virtual ~TestFailedCtorSubParent(); + +protected: + NS_OVERRIDE + virtual PTestFailedCtorSubsubParent* AllocPTestFailedCtorSubsub(); + + NS_OVERRIDE + virtual bool DeallocPTestFailedCtorSubsub(PTestFailedCtorSubsubParent* actor); + NS_OVERRIDE + virtual bool RecvSync() { return true; } + + NS_OVERRIDE + virtual void ActorDestroy(ActorDestroyReason why); + + TestFailedCtorSubsub* mOne; + TestFailedCtorSubsub* mTwo; + TestFailedCtorSubsub* mThree; +}; + + +class TestFailedCtorSubChild : + public PTestFailedCtorSubChild +{ +public: + TestFailedCtorSubChild() { } + virtual ~TestFailedCtorSubChild() { } + +protected: + NS_OVERRIDE + virtual PTestFailedCtorSubsubChild* AllocPTestFailedCtorSubsub(); + NS_OVERRIDE + virtual bool DeallocPTestFailedCtorSubsub(PTestFailedCtorSubsubChild* actor); + + NS_OVERRIDE + virtual void ActorDestroy(ActorDestroyReason why); +}; + + +//----------------------------------------------------------------------------- +// Grand-descendent +// +class TestFailedCtorSubsub : + public PTestFailedCtorSubsubParent, + public PTestFailedCtorSubsubChild +{ +public: + TestFailedCtorSubsub() : mWhy(ActorDestroyReason(-1)), mDealloced(false) {} + virtual ~TestFailedCtorSubsub() {} + + NS_OVERRIDE + virtual void ActorDestroy(ActorDestroyReason why) { mWhy = why; } + + ActorDestroyReason mWhy; + bool mDealloced; +}; + + +} +} + +#endif // ifndef mozilla_ipdltest_TestFailedCtor_h diff --git a/ipc/ipdl/test/cxx/ipdl.mk b/ipc/ipdl/test/cxx/ipdl.mk index 35257e6c45f..7ac17d9031d 100644 --- a/ipc/ipdl/test/cxx/ipdl.mk +++ b/ipc/ipdl/test/cxx/ipdl.mk @@ -6,6 +6,9 @@ IPDLSRCS = \ PTestDesc.ipdl \ PTestDescSub.ipdl \ PTestDescSubsub.ipdl \ + PTestFailedCtor.ipdl \ + PTestFailedCtorSub.ipdl \ + PTestFailedCtorSubsub.ipdl \ PTestHandle.ipdl \ PTestHangs.ipdl \ PTestJSON.ipdl \