ipc/ipdl/test/cxx/TestActorPunning.cpp

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

mercurial