1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/ipdl/test/cxx/TestRPC.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,214 @@ 1.4 +#include "TestRPC.h" 1.5 + 1.6 +#include "IPDLUnitTests.h" // fail etc. 1.7 +#if defined(OS_POSIX) 1.8 +#include <unistd.h> 1.9 +#else 1.10 +#include <windows.h> 1.11 +#endif 1.12 + 1.13 +namespace mozilla { 1.14 +namespace _ipdltest { 1.15 + 1.16 +//----------------------------------------------------------------------------- 1.17 +// parent 1.18 + 1.19 +TestRPCParent::TestRPCParent() 1.20 + : reentered_(false), 1.21 + resolved_first_cpow_(false) 1.22 +{ 1.23 + MOZ_COUNT_CTOR(TestRPCParent); 1.24 +} 1.25 + 1.26 +TestRPCParent::~TestRPCParent() 1.27 +{ 1.28 + MOZ_COUNT_DTOR(TestRPCParent); 1.29 +} 1.30 + 1.31 +void 1.32 +TestRPCParent::Main() 1.33 +{ 1.34 + if (!SendStart()) 1.35 + fail("sending Start"); 1.36 +} 1.37 + 1.38 +bool 1.39 +TestRPCParent::AnswerTest1_Start(uint32_t* aResult) 1.40 +{ 1.41 + uint32_t result; 1.42 + if (!CallTest1_InnerQuery(&result)) 1.43 + fail("CallTest1_InnerQuery"); 1.44 + if (result != 300) 1.45 + fail("Wrong result (expected 300)"); 1.46 + 1.47 + *aResult = 100; 1.48 + return true; 1.49 +} 1.50 + 1.51 +bool 1.52 +TestRPCParent::AnswerTest1_InnerEvent(uint32_t* aResult) 1.53 +{ 1.54 + uint32_t result; 1.55 + if (!CallTest1_NoReenter(&result)) 1.56 + fail("CallTest1_NoReenter"); 1.57 + if (result != 400) 1.58 + fail("Wrong result (expected 400)"); 1.59 + 1.60 + *aResult = 200; 1.61 + return true; 1.62 +} 1.63 + 1.64 +bool 1.65 +TestRPCParent::RecvTest2_Start() 1.66 +{ 1.67 + // Send a CPOW. During this time, we must NOT process the RPC message, as 1.68 + // we could start receiving CPOW replies out-of-order. 1.69 + if (!CallTest2_FirstUrgent()) 1.70 + fail("CallTest2_FirstUrgent"); 1.71 + 1.72 + MOZ_ASSERT(!reentered_); 1.73 + resolved_first_cpow_ = true; 1.74 + return true; 1.75 +} 1.76 + 1.77 +bool 1.78 +TestRPCParent::AnswerTest2_OutOfOrder() 1.79 +{ 1.80 + // Send a CPOW. If this RPC call was initiated while waiting for the first 1.81 + // CPOW to resolve, replies will be processed out of order, and we'll crash. 1.82 + if (!CallTest2_SecondUrgent()) 1.83 + fail("CallTest2_SecondUrgent"); 1.84 + 1.85 + reentered_ = true; 1.86 + return true; 1.87 +} 1.88 + 1.89 +bool 1.90 +TestRPCParent::RecvTest3_Start(uint32_t* aResult) 1.91 +{ 1.92 + if (!CallTest3_WakeUp(aResult)) 1.93 + fail("CallTest3_WakeUp"); 1.94 + 1.95 + return true; 1.96 +} 1.97 + 1.98 +bool 1.99 +TestRPCParent::AnswerTest3_InnerEvent(uint32_t* aResult) 1.100 +{ 1.101 + *aResult = 200; 1.102 + return true; 1.103 +} 1.104 + 1.105 +bool 1.106 +TestRPCParent::AnswerTest4_Start(uint32_t* aResult) 1.107 +{ 1.108 + if (!CallTest4_WakeUp(aResult)) 1.109 + fail("CallTest4_WakeUp"); 1.110 + 1.111 + return true; 1.112 +} 1.113 + 1.114 +bool 1.115 +TestRPCParent::AnswerTest4_Inner(uint32_t* aResult) 1.116 +{ 1.117 + *aResult = 700; 1.118 + return true; 1.119 +} 1.120 + 1.121 +//----------------------------------------------------------------------------- 1.122 +// child 1.123 + 1.124 + 1.125 +TestRPCChild::TestRPCChild() 1.126 +{ 1.127 + MOZ_COUNT_CTOR(TestRPCChild); 1.128 +} 1.129 + 1.130 +TestRPCChild::~TestRPCChild() 1.131 +{ 1.132 + MOZ_COUNT_DTOR(TestRPCChild); 1.133 +} 1.134 + 1.135 +bool 1.136 +TestRPCChild::RecvStart() 1.137 +{ 1.138 + uint32_t result; 1.139 + if (!CallTest1_Start(&result)) 1.140 + fail("CallTest1_Start"); 1.141 + if (result != 100) 1.142 + fail("Wrong result (expected 100)"); 1.143 + 1.144 + if (!SendTest2_Start()) 1.145 + fail("SendTest2_Start"); 1.146 + 1.147 + if (!CallTest2_OutOfOrder()) 1.148 + fail("CallTest2_OutOfOrder"); 1.149 + 1.150 + result = 0; 1.151 + if (!SendTest3_Start(&result)) 1.152 + fail("SendTest3_Start"); 1.153 + if (result != 200) 1.154 + fail("Wrong result (expected 200)"); 1.155 + 1.156 + // See bug 937216 (RPC calls within interrupts). 1.157 + if (!CallTest4_Start(&result)) 1.158 + fail("SendTest4_Start"); 1.159 + if (result != 700) 1.160 + fail("Wrong result (expected 700)"); 1.161 + 1.162 + Close(); 1.163 + return true; 1.164 +} 1.165 + 1.166 +bool 1.167 +TestRPCChild::AnswerTest1_InnerQuery(uint32_t* aResult) 1.168 +{ 1.169 + uint32_t result; 1.170 + if (!CallTest1_InnerEvent(&result)) 1.171 + fail("CallTest1_InnerEvent"); 1.172 + if (result != 200) 1.173 + fail("Wrong result (expected 200)"); 1.174 + 1.175 + *aResult = 300; 1.176 + return true; 1.177 +} 1.178 + 1.179 +bool 1.180 +TestRPCChild::AnswerTest1_NoReenter(uint32_t* aResult) 1.181 +{ 1.182 + *aResult = 400; 1.183 + return true; 1.184 +} 1.185 + 1.186 +bool 1.187 +TestRPCChild::AnswerTest2_FirstUrgent() 1.188 +{ 1.189 + return true; 1.190 +} 1.191 + 1.192 +bool 1.193 +TestRPCChild::AnswerTest2_SecondUrgent() 1.194 +{ 1.195 + return true; 1.196 +} 1.197 + 1.198 +bool 1.199 +TestRPCChild::AnswerTest3_WakeUp(uint32_t* aResult) 1.200 +{ 1.201 + if (!CallTest3_InnerEvent(aResult)) 1.202 + fail("CallTest3_InnerEvent"); 1.203 + 1.204 + return true; 1.205 +} 1.206 + 1.207 +bool 1.208 +TestRPCChild::AnswerTest4_WakeUp(uint32_t* aResult) 1.209 +{ 1.210 + if (!CallTest4_Inner(aResult)) 1.211 + fail("CallTest4_Inner"); 1.212 + 1.213 + return true; 1.214 +} 1.215 + 1.216 +} // namespace _ipdltest 1.217 +} // namespace mozilla