1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/ipdl/test/cxx/TestFailedCtor.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,137 @@ 1.4 +#include "TestFailedCtor.h" 1.5 + 1.6 +#include "IPDLUnitTests.h" // fail etc. 1.7 + 1.8 +namespace mozilla { 1.9 +namespace _ipdltest { 1.10 + 1.11 +//----------------------------------------------------------------------------- 1.12 +// parent 1.13 +void 1.14 +TestFailedCtorParent::Main() 1.15 +{ 1.16 + PTestFailedCtorSubParent* p = CallPTestFailedCtorSubConstructor(); 1.17 + if (p) 1.18 + fail("expected ctor to fail"); 1.19 + 1.20 + Close(); 1.21 +} 1.22 + 1.23 +PTestFailedCtorSubParent* 1.24 +TestFailedCtorParent::AllocPTestFailedCtorSubParent() 1.25 +{ 1.26 + return new TestFailedCtorSubParent(); 1.27 +} 1.28 +bool 1.29 +TestFailedCtorParent::DeallocPTestFailedCtorSubParent(PTestFailedCtorSubParent* actor) 1.30 +{ 1.31 + delete actor; 1.32 + return true; 1.33 +} 1.34 + 1.35 +PTestFailedCtorSubsubParent* 1.36 +TestFailedCtorSubParent::AllocPTestFailedCtorSubsubParent() 1.37 +{ 1.38 + TestFailedCtorSubsub* a = new TestFailedCtorSubsub(); 1.39 + if (!mOne) { 1.40 + return mOne = a; 1.41 + } else if (!mTwo) { 1.42 + return mTwo = a; 1.43 + } else if (!mThree) { 1.44 + return mThree = a; 1.45 + } else { 1.46 + fail("unexpected Alloc()"); 1.47 + return nullptr; 1.48 + } 1.49 +} 1.50 +bool 1.51 +TestFailedCtorSubParent::DeallocPTestFailedCtorSubsubParent(PTestFailedCtorSubsubParent* actor) 1.52 +{ 1.53 + static_cast<TestFailedCtorSubsub*>(actor)->mDealloced = true; 1.54 + return true; 1.55 +} 1.56 + 1.57 +void 1.58 +TestFailedCtorSubParent::ActorDestroy(ActorDestroyReason why) 1.59 +{ 1.60 + 1.61 + if (mOne->mWhy != Deletion) 1.62 + fail("Subsub one got wrong ActorDestroyReason"); 1.63 + if (mTwo->mWhy != AncestorDeletion) 1.64 + fail("Subsub two got wrong ActorDestroyReason"); 1.65 + if (mThree->mWhy != AncestorDeletion) 1.66 + fail("Subsub three got wrong ActorDestroyReason"); 1.67 + 1.68 + if (FailedConstructor != why) 1.69 + fail("unexpected destruction!"); 1.70 +} 1.71 + 1.72 +TestFailedCtorSubParent::~TestFailedCtorSubParent() 1.73 +{ 1.74 + if (!(mOne->mDealloced && mTwo->mDealloced && mThree->mDealloced)) 1.75 + fail("Not all subsubs were Dealloc'd"); 1.76 + delete mOne; 1.77 + delete mTwo; 1.78 + delete mThree; 1.79 +} 1.80 + 1.81 + 1.82 +//----------------------------------------------------------------------------- 1.83 +// child 1.84 + 1.85 +PTestFailedCtorSubChild* 1.86 +TestFailedCtorChild::AllocPTestFailedCtorSubChild() 1.87 +{ 1.88 + return new TestFailedCtorSubChild(); 1.89 +} 1.90 + 1.91 +bool 1.92 +TestFailedCtorChild::AnswerPTestFailedCtorSubConstructor(PTestFailedCtorSubChild* actor) 1.93 +{ 1.94 + PTestFailedCtorSubsubChild* c1 = actor->SendPTestFailedCtorSubsubConstructor(); 1.95 + PTestFailedCtorSubsubChild::Send__delete__(c1); 1.96 + 1.97 + if (!actor->SendPTestFailedCtorSubsubConstructor() || 1.98 + !actor->SendPTestFailedCtorSubsubConstructor() || 1.99 + !actor->SendSync()) 1.100 + fail("setting up test"); 1.101 + 1.102 + // This causes our process to die 1.103 + return false; 1.104 +} 1.105 + 1.106 +bool 1.107 +TestFailedCtorChild::DeallocPTestFailedCtorSubChild(PTestFailedCtorSubChild* actor) 1.108 +{ 1.109 + delete actor; 1.110 + return true; 1.111 +} 1.112 + 1.113 +void 1.114 +TestFailedCtorChild::ProcessingError(Result what) 1.115 +{ 1.116 + if (OtherProcess() != 0) // thread-mode 1.117 + _exit(0); 1.118 +} 1.119 + 1.120 +PTestFailedCtorSubsubChild* 1.121 +TestFailedCtorSubChild::AllocPTestFailedCtorSubsubChild() 1.122 +{ 1.123 + return new TestFailedCtorSubsub(); 1.124 +} 1.125 + 1.126 +bool 1.127 +TestFailedCtorSubChild::DeallocPTestFailedCtorSubsubChild(PTestFailedCtorSubsubChild* actor) 1.128 +{ 1.129 + delete actor; 1.130 + return true; 1.131 +} 1.132 + 1.133 +void 1.134 +TestFailedCtorSubChild::ActorDestroy(ActorDestroyReason why) 1.135 +{ 1.136 +} 1.137 + 1.138 + 1.139 +} // namespace _ipdltest 1.140 +} // namespace mozilla