Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #include "TestActorPunning.h" |
michael@0 | 2 | |
michael@0 | 3 | #include "IPDLUnitTests.h" // fail etc. |
michael@0 | 4 | |
michael@0 | 5 | namespace mozilla { |
michael@0 | 6 | namespace _ipdltest { |
michael@0 | 7 | |
michael@0 | 8 | //----------------------------------------------------------------------------- |
michael@0 | 9 | // parent |
michael@0 | 10 | |
michael@0 | 11 | void |
michael@0 | 12 | TestActorPunningParent::Main() |
michael@0 | 13 | { |
michael@0 | 14 | if (!SendStart()) |
michael@0 | 15 | fail("sending Start"); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | bool |
michael@0 | 19 | TestActorPunningParent::RecvPun(PTestActorPunningSubParent* a, const Bad& bad) |
michael@0 | 20 | { |
michael@0 | 21 | if (a->SendBad()) |
michael@0 | 22 | fail("bad!"); |
michael@0 | 23 | fail("shouldn't have received this message in the first place"); |
michael@0 | 24 | return true; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | PTestActorPunningPunnedParent* |
michael@0 | 28 | TestActorPunningParent::AllocPTestActorPunningPunnedParent() |
michael@0 | 29 | { |
michael@0 | 30 | return new TestActorPunningPunnedParent(); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | bool |
michael@0 | 34 | TestActorPunningParent::DeallocPTestActorPunningPunnedParent(PTestActorPunningPunnedParent* a) |
michael@0 | 35 | { |
michael@0 | 36 | delete a; |
michael@0 | 37 | return true; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | PTestActorPunningSubParent* |
michael@0 | 41 | TestActorPunningParent::AllocPTestActorPunningSubParent() |
michael@0 | 42 | { |
michael@0 | 43 | return new TestActorPunningSubParent(); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | bool |
michael@0 | 47 | TestActorPunningParent::DeallocPTestActorPunningSubParent(PTestActorPunningSubParent* a) |
michael@0 | 48 | { |
michael@0 | 49 | delete a; |
michael@0 | 50 | return true; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | //----------------------------------------------------------------------------- |
michael@0 | 54 | // child |
michael@0 | 55 | |
michael@0 | 56 | PTestActorPunningPunnedChild* |
michael@0 | 57 | TestActorPunningChild::AllocPTestActorPunningPunnedChild() |
michael@0 | 58 | { |
michael@0 | 59 | return new TestActorPunningPunnedChild(); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | bool |
michael@0 | 63 | TestActorPunningChild::DeallocPTestActorPunningPunnedChild(PTestActorPunningPunnedChild*) |
michael@0 | 64 | { |
michael@0 | 65 | fail("should have died by now"); |
michael@0 | 66 | return true; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | PTestActorPunningSubChild* |
michael@0 | 70 | TestActorPunningChild::AllocPTestActorPunningSubChild() |
michael@0 | 71 | { |
michael@0 | 72 | return new TestActorPunningSubChild(); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | bool |
michael@0 | 76 | TestActorPunningChild::DeallocPTestActorPunningSubChild(PTestActorPunningSubChild*) |
michael@0 | 77 | { |
michael@0 | 78 | fail("should have died by now"); |
michael@0 | 79 | return true; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | bool |
michael@0 | 83 | TestActorPunningChild::RecvStart() |
michael@0 | 84 | { |
michael@0 | 85 | SendPTestActorPunningSubConstructor(); |
michael@0 | 86 | SendPTestActorPunningPunnedConstructor(); |
michael@0 | 87 | PTestActorPunningSubChild* a = SendPTestActorPunningSubConstructor(); |
michael@0 | 88 | // We can't assert whether this succeeds or fails, due to race |
michael@0 | 89 | // conditions. |
michael@0 | 90 | SendPun(a, Bad()); |
michael@0 | 91 | return true; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | bool |
michael@0 | 95 | TestActorPunningSubChild::RecvBad() |
michael@0 | 96 | { |
michael@0 | 97 | fail("things are going really badly right now"); |
michael@0 | 98 | return true; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | |
michael@0 | 102 | } // namespace _ipdltest |
michael@0 | 103 | } // namespace mozilla |
michael@0 | 104 | |
michael@0 | 105 | namespace IPC { |
michael@0 | 106 | using namespace mozilla::_ipdltest; |
michael@0 | 107 | using namespace mozilla::ipc; |
michael@0 | 108 | |
michael@0 | 109 | /*static*/ void |
michael@0 | 110 | ParamTraits<Bad>::Write(Message* aMsg, const paramType& aParam) |
michael@0 | 111 | { |
michael@0 | 112 | char* ptr = aMsg->BeginWriteData(4); |
michael@0 | 113 | ptr -= intptr_t(sizeof(int)); |
michael@0 | 114 | ptr -= intptr_t(sizeof(ActorHandle)); |
michael@0 | 115 | ActorHandle* ah = reinterpret_cast<ActorHandle*>(ptr); |
michael@0 | 116 | if (ah->mId != -3) |
michael@0 | 117 | fail("guessed wrong offset (value is %d, should be -3)", ah->mId); |
michael@0 | 118 | ah->mId = -2; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | /*static*/ bool |
michael@0 | 122 | ParamTraits<Bad>::Read(const Message* aMsg, void** aIter, paramType* aResult) |
michael@0 | 123 | { |
michael@0 | 124 | const char* ptr; |
michael@0 | 125 | int len; |
michael@0 | 126 | aMsg->ReadData(aIter, &ptr, &len); |
michael@0 | 127 | return true; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | } // namespace IPC |
michael@0 | 131 |