ipc/ipdl/test/cxx/TestFailedCtor.cpp

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     1 #include "TestFailedCtor.h"
     3 #include "IPDLUnitTests.h"      // fail etc.
     5 namespace mozilla {
     6 namespace _ipdltest {
     8 //-----------------------------------------------------------------------------
     9 // parent
    10 void
    11 TestFailedCtorParent::Main()
    12 {
    13     PTestFailedCtorSubParent* p = CallPTestFailedCtorSubConstructor();
    14     if (p)
    15         fail("expected ctor to fail");
    17     Close();
    18 }
    20 PTestFailedCtorSubParent*
    21 TestFailedCtorParent::AllocPTestFailedCtorSubParent()
    22 {
    23     return new TestFailedCtorSubParent();
    24 }
    25 bool
    26 TestFailedCtorParent::DeallocPTestFailedCtorSubParent(PTestFailedCtorSubParent* actor)
    27 {
    28     delete actor;
    29     return true;
    30 }
    32 PTestFailedCtorSubsubParent*
    33 TestFailedCtorSubParent::AllocPTestFailedCtorSubsubParent()
    34 {
    35     TestFailedCtorSubsub* a = new TestFailedCtorSubsub();
    36     if (!mOne) {
    37         return mOne = a;
    38     } else if (!mTwo) {
    39         return mTwo = a;
    40     } else if (!mThree) {
    41         return mThree = a;
    42     } else {
    43         fail("unexpected Alloc()");
    44         return nullptr;
    45     }
    46 }
    47 bool
    48 TestFailedCtorSubParent::DeallocPTestFailedCtorSubsubParent(PTestFailedCtorSubsubParent* actor)
    49 {
    50     static_cast<TestFailedCtorSubsub*>(actor)->mDealloced = true;
    51     return true;
    52 }
    54 void
    55 TestFailedCtorSubParent::ActorDestroy(ActorDestroyReason why)
    56 {
    58     if (mOne->mWhy != Deletion)
    59         fail("Subsub one got wrong ActorDestroyReason");
    60     if (mTwo->mWhy != AncestorDeletion)
    61         fail("Subsub two got wrong ActorDestroyReason");
    62     if (mThree->mWhy != AncestorDeletion)
    63         fail("Subsub three got wrong ActorDestroyReason");
    65     if (FailedConstructor != why)
    66         fail("unexpected destruction!");
    67 }
    69 TestFailedCtorSubParent::~TestFailedCtorSubParent()
    70 {
    71     if (!(mOne->mDealloced && mTwo->mDealloced && mThree->mDealloced))
    72         fail("Not all subsubs were Dealloc'd");
    73     delete mOne;
    74     delete mTwo;
    75     delete mThree;
    76 }
    79 //-----------------------------------------------------------------------------
    80 // child
    82 PTestFailedCtorSubChild*
    83 TestFailedCtorChild::AllocPTestFailedCtorSubChild()
    84 {
    85     return new TestFailedCtorSubChild();
    86 }
    88 bool
    89 TestFailedCtorChild::AnswerPTestFailedCtorSubConstructor(PTestFailedCtorSubChild* actor)
    90 {
    91     PTestFailedCtorSubsubChild* c1 = actor->SendPTestFailedCtorSubsubConstructor();
    92     PTestFailedCtorSubsubChild::Send__delete__(c1);
    94     if (!actor->SendPTestFailedCtorSubsubConstructor() ||
    95         !actor->SendPTestFailedCtorSubsubConstructor() ||
    96         !actor->SendSync())
    97         fail("setting up test");
    99     // This causes our process to die
   100     return false;
   101 }
   103 bool
   104 TestFailedCtorChild::DeallocPTestFailedCtorSubChild(PTestFailedCtorSubChild* actor)
   105 {
   106     delete actor;
   107     return true;
   108 }
   110 void
   111 TestFailedCtorChild::ProcessingError(Result what)
   112 {
   113     if (OtherProcess() != 0) // thread-mode
   114         _exit(0);
   115 }
   117 PTestFailedCtorSubsubChild*
   118 TestFailedCtorSubChild::AllocPTestFailedCtorSubsubChild()
   119 {
   120     return new TestFailedCtorSubsub();
   121 }
   123 bool
   124 TestFailedCtorSubChild::DeallocPTestFailedCtorSubsubChild(PTestFailedCtorSubsubChild* actor)
   125 {
   126     delete actor;
   127     return true;
   128 }
   130 void
   131 TestFailedCtorSubChild::ActorDestroy(ActorDestroyReason why)
   132 {
   133 }
   136 } // namespace _ipdltest
   137 } // namespace mozilla

mercurial