ipc/ipdl/test/cxx/TestActorPunning.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/ipdl/test/cxx/TestActorPunning.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,131 @@
     1.4 +#include "TestActorPunning.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 +
    1.14 +void
    1.15 +TestActorPunningParent::Main()
    1.16 +{
    1.17 +    if (!SendStart())
    1.18 +        fail("sending Start");
    1.19 +}
    1.20 +
    1.21 +bool
    1.22 +TestActorPunningParent::RecvPun(PTestActorPunningSubParent* a, const Bad& bad)
    1.23 +{
    1.24 +    if (a->SendBad())
    1.25 +        fail("bad!");
    1.26 +    fail("shouldn't have received this message in the first place");
    1.27 +    return true;
    1.28 +}
    1.29 +
    1.30 +PTestActorPunningPunnedParent*
    1.31 +TestActorPunningParent::AllocPTestActorPunningPunnedParent()
    1.32 +{
    1.33 +    return new TestActorPunningPunnedParent();
    1.34 +}
    1.35 +
    1.36 +bool
    1.37 +TestActorPunningParent::DeallocPTestActorPunningPunnedParent(PTestActorPunningPunnedParent* a)
    1.38 +{
    1.39 +    delete a;
    1.40 +    return true;
    1.41 +}
    1.42 +
    1.43 +PTestActorPunningSubParent*
    1.44 +TestActorPunningParent::AllocPTestActorPunningSubParent()
    1.45 +{
    1.46 +    return new TestActorPunningSubParent();
    1.47 +}
    1.48 +
    1.49 +bool
    1.50 +TestActorPunningParent::DeallocPTestActorPunningSubParent(PTestActorPunningSubParent* a)
    1.51 +{
    1.52 +    delete a;
    1.53 +    return true;
    1.54 +}
    1.55 +
    1.56 +//-----------------------------------------------------------------------------
    1.57 +// child
    1.58 +
    1.59 +PTestActorPunningPunnedChild*
    1.60 +TestActorPunningChild::AllocPTestActorPunningPunnedChild()
    1.61 +{
    1.62 +    return new TestActorPunningPunnedChild();
    1.63 +}
    1.64 +
    1.65 +bool
    1.66 +TestActorPunningChild::DeallocPTestActorPunningPunnedChild(PTestActorPunningPunnedChild*)
    1.67 +{
    1.68 +    fail("should have died by now");
    1.69 +    return true;
    1.70 +}
    1.71 +
    1.72 +PTestActorPunningSubChild*
    1.73 +TestActorPunningChild::AllocPTestActorPunningSubChild()
    1.74 +{
    1.75 +    return new TestActorPunningSubChild();
    1.76 +}
    1.77 +
    1.78 +bool
    1.79 +TestActorPunningChild::DeallocPTestActorPunningSubChild(PTestActorPunningSubChild*)
    1.80 +{
    1.81 +    fail("should have died by now");
    1.82 +    return true;
    1.83 +}
    1.84 +
    1.85 +bool
    1.86 +TestActorPunningChild::RecvStart()
    1.87 +{
    1.88 +    SendPTestActorPunningSubConstructor();
    1.89 +    SendPTestActorPunningPunnedConstructor();
    1.90 +    PTestActorPunningSubChild* a = SendPTestActorPunningSubConstructor();
    1.91 +    // We can't assert whether this succeeds or fails, due to race
    1.92 +    // conditions.
    1.93 +    SendPun(a, Bad());
    1.94 +    return true;
    1.95 +}
    1.96 +
    1.97 +bool
    1.98 +TestActorPunningSubChild::RecvBad()
    1.99 +{
   1.100 +    fail("things are going really badly right now");
   1.101 +    return true;
   1.102 +}
   1.103 +
   1.104 +
   1.105 +} // namespace _ipdltest
   1.106 +} // namespace mozilla
   1.107 +
   1.108 +namespace IPC {
   1.109 +using namespace mozilla::_ipdltest;
   1.110 +using namespace mozilla::ipc;
   1.111 +
   1.112 +/*static*/ void
   1.113 +ParamTraits<Bad>::Write(Message* aMsg, const paramType& aParam)
   1.114 +{
   1.115 +    char* ptr = aMsg->BeginWriteData(4);
   1.116 +    ptr -= intptr_t(sizeof(int));
   1.117 +    ptr -= intptr_t(sizeof(ActorHandle));
   1.118 +    ActorHandle* ah = reinterpret_cast<ActorHandle*>(ptr);
   1.119 +    if (ah->mId != -3)
   1.120 +        fail("guessed wrong offset (value is %d, should be -3)", ah->mId);
   1.121 +    ah->mId = -2;
   1.122 +}
   1.123 +
   1.124 +/*static*/ bool
   1.125 +ParamTraits<Bad>::Read(const Message* aMsg, void** aIter, paramType* aResult)
   1.126 +{
   1.127 +    const char* ptr;
   1.128 +    int len;
   1.129 +    aMsg->ReadData(aIter, &ptr, &len);
   1.130 +    return true;
   1.131 +}
   1.132 +
   1.133 +} // namespace IPC
   1.134 +

mercurial