ash: Extend launcher first button to include leading inset.
[chromium-blink-merge.git] / ipc / ipc_sync_message_unittest.cc
blob7b513f73db0e865b64404451b7524f5fa167e3a2
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // Unit test to make sure that the serialization of synchronous IPC messages
6 // works. This ensures that the macros and templates were defined correctly.
7 // Doesn't test the IPC channel mechanism.
9 #include <string.h>
11 #include "base/basictypes.h"
12 #include "ipc/ipc_message.h"
13 #include "ipc/ipc_message_utils.h"
14 #include "base/logging.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 #define IPC_MESSAGE_IMPL
18 #include "ipc/ipc_sync_message_unittest.h"
20 static IPC::Message* g_reply;
22 class TestMessageReceiver {
23 public:
25 void On_0_1(bool* out1) {
26 *out1 = false;
29 void On_0_2(bool* out1, int* out2) {
30 *out1 = true;
31 *out2 = 2;
34 void On_0_3(bool* out1, int* out2, std::string* out3) {
35 *out1 = false;
36 *out2 = 3;
37 *out3 = "0_3";
40 void On_1_1(int in1, bool* out1) {
41 DCHECK_EQ(1, in1);
42 *out1 = true;
45 void On_1_2(bool in1, bool* out1, int* out2) {
46 DCHECK(!in1);
47 *out1 = true;
48 *out2 = 12;
51 void On_1_3(int in1, std::string* out1, int* out2, bool* out3) {
52 DCHECK_EQ(3, in1);
53 *out1 = "1_3";
54 *out2 = 13;
55 *out3 = false;
58 void On_2_1(int in1, bool in2, bool* out1) {
59 DCHECK_EQ(1, in1);
60 DCHECK(!in2);
61 *out1 = true;
64 void On_2_2(bool in1, int in2, bool* out1, int* out2) {
65 DCHECK(!in1);
66 DCHECK_EQ(2, in2);
67 *out1 = true;
68 *out2 = 22;
71 void On_2_3(int in1, bool in2, std::string* out1, int* out2, bool* out3) {
72 DCHECK_EQ(3, in1);
73 DCHECK(in2);
74 *out1 = "2_3";
75 *out2 = 23;
76 *out3 = false;
79 void On_3_1(int in1, bool in2, std::string in3, bool* out1) {
80 DCHECK_EQ(1, in1);
81 DCHECK(!in2);
82 DCHECK_EQ("3_1", in3);
83 *out1 = true;
86 void On_3_2(std::string in1, bool in2, int in3, bool* out1, int* out2) {
87 DCHECK_EQ("3_2", in1);
88 DCHECK(!in2);
89 DCHECK_EQ(2, in3);
90 *out1 = true;
91 *out2 = 32;
94 void On_3_3(int in1, std::string in2, bool in3, std::string* out1, int* out2,
95 bool* out3) {
96 DCHECK_EQ(3, in1);
97 DCHECK_EQ("3_3", in2);
98 DCHECK(in3);
99 *out1 = "3_3";
100 *out2 = 33;
101 *out3 = false;
104 void On_3_4(bool in1, int in2, std::string in3, int* out1, bool* out2,
105 std::string* out3, bool* out4) {
106 DCHECK(in1);
107 DCHECK_EQ(3, in2);
108 DCHECK_EQ("3_4", in3);
109 *out1 = 34;
110 *out2 = true;
111 *out3 = "3_4";
112 *out4 = false;
115 bool Send(IPC::Message* message) {
116 // gets the reply message, stash in global
117 DCHECK(g_reply == NULL);
118 g_reply = message;
119 return true;
122 bool OnMessageReceived(const IPC::Message& msg) {
123 IPC_BEGIN_MESSAGE_MAP(TestMessageReceiver, msg)
124 IPC_MESSAGE_HANDLER(Msg_C_0_1, On_0_1)
125 IPC_MESSAGE_HANDLER(Msg_C_0_2, On_0_2)
126 IPC_MESSAGE_HANDLER(Msg_C_0_3, On_0_3)
127 IPC_MESSAGE_HANDLER(Msg_C_1_1, On_1_1)
128 IPC_MESSAGE_HANDLER(Msg_C_1_2, On_1_2)
129 IPC_MESSAGE_HANDLER(Msg_C_1_3, On_1_3)
130 IPC_MESSAGE_HANDLER(Msg_C_2_1, On_2_1)
131 IPC_MESSAGE_HANDLER(Msg_C_2_2, On_2_2)
132 IPC_MESSAGE_HANDLER(Msg_C_2_3, On_2_3)
133 IPC_MESSAGE_HANDLER(Msg_C_3_1, On_3_1)
134 IPC_MESSAGE_HANDLER(Msg_C_3_2, On_3_2)
135 IPC_MESSAGE_HANDLER(Msg_C_3_3, On_3_3)
136 IPC_MESSAGE_HANDLER(Msg_C_3_4, On_3_4)
137 IPC_MESSAGE_HANDLER(Msg_R_0_1, On_0_1)
138 IPC_MESSAGE_HANDLER(Msg_R_0_2, On_0_2)
139 IPC_MESSAGE_HANDLER(Msg_R_0_3, On_0_3)
140 IPC_MESSAGE_HANDLER(Msg_R_1_1, On_1_1)
141 IPC_MESSAGE_HANDLER(Msg_R_1_2, On_1_2)
142 IPC_MESSAGE_HANDLER(Msg_R_1_3, On_1_3)
143 IPC_MESSAGE_HANDLER(Msg_R_2_1, On_2_1)
144 IPC_MESSAGE_HANDLER(Msg_R_2_2, On_2_2)
145 IPC_MESSAGE_HANDLER(Msg_R_2_3, On_2_3)
146 IPC_MESSAGE_HANDLER(Msg_R_3_1, On_3_1)
147 IPC_MESSAGE_HANDLER(Msg_R_3_2, On_3_2)
148 IPC_MESSAGE_HANDLER(Msg_R_3_3, On_3_3)
149 IPC_MESSAGE_HANDLER(Msg_R_3_4, On_3_4)
150 IPC_END_MESSAGE_MAP()
151 return true;
156 void Send(IPC::SyncMessage* msg) {
157 static TestMessageReceiver receiver;
159 IPC::MessageReplyDeserializer* reply_serializer = msg->GetReplyDeserializer();
160 DCHECK(reply_serializer != NULL);
162 // "send" the message
163 receiver.OnMessageReceived(*msg);
164 delete msg;
166 // get the reply message from the global, and deserialize the output
167 // parameters into the output pointers.
168 DCHECK(g_reply != NULL);
169 bool result = reply_serializer->SerializeOutputParameters(*g_reply);
170 DCHECK(result);
171 delete g_reply;
172 g_reply = NULL;
173 delete reply_serializer;
176 TEST(IPCSyncMessageTest, Main) {
177 bool bool1 = true;
178 int int1 = 0;
179 std::string string1;
181 Send(new Msg_C_0_1(&bool1));
182 DCHECK(!bool1);
184 Send(new Msg_C_0_2(&bool1, &int1));
185 DCHECK(bool1);
186 DCHECK_EQ(2, int1);
188 Send(new Msg_C_0_3(&bool1, &int1, &string1));
189 DCHECK(!bool1);
190 DCHECK_EQ(3, int1);
191 DCHECK_EQ("0_3", string1);
193 bool1 = false;
194 Send(new Msg_C_1_1(1, &bool1));
195 DCHECK(bool1);
197 bool1 = false;
198 Send(new Msg_C_1_2(false, &bool1, &int1));
199 DCHECK(bool1);
200 DCHECK_EQ(12, int1);
202 bool1 = true;
203 Send(new Msg_C_1_3(3, &string1, &int1, &bool1));
204 DCHECK_EQ("1_3", string1);
205 DCHECK_EQ(13, int1);
206 DCHECK(!bool1);
208 bool1 = false;
209 Send(new Msg_C_2_1(1, false, &bool1));
210 DCHECK(bool1);
212 bool1 = false;
213 Send(new Msg_C_2_2(false, 2, &bool1, &int1));
214 DCHECK(bool1);
215 DCHECK_EQ(22, int1);
217 bool1 = true;
218 Send(new Msg_C_2_3(3, true, &string1, &int1, &bool1));
219 DCHECK_EQ("2_3", string1);
220 DCHECK_EQ(23, int1);
221 DCHECK(!bool1);
223 bool1 = false;
224 Send(new Msg_C_3_1(1, false, "3_1", &bool1));
225 DCHECK(bool1);
227 bool1 = false;
228 Send(new Msg_C_3_2("3_2", false, 2, &bool1, &int1));
229 DCHECK(bool1);
230 DCHECK_EQ(32, int1);
232 bool1 = true;
233 Send(new Msg_C_3_3(3, "3_3", true, &string1, &int1, &bool1));
234 DCHECK_EQ("3_3", string1);
235 DCHECK_EQ(33, int1);
236 DCHECK(!bool1);
238 bool1 = false;
239 bool bool2 = true;
240 Send(new Msg_C_3_4(true, 3, "3_4", &int1, &bool1, &string1, &bool2));
241 DCHECK_EQ(34, int1);
242 DCHECK(bool1);
243 DCHECK_EQ("3_4", string1);
244 DCHECK(!bool2);
246 // Routed messages, just a copy of the above but with extra routing paramater
247 Send(new Msg_R_0_1(0, &bool1));
248 DCHECK(!bool1);
250 Send(new Msg_R_0_2(0, &bool1, &int1));
251 DCHECK(bool1);
252 DCHECK_EQ(2, int1);
254 Send(new Msg_R_0_3(0, &bool1, &int1, &string1));
255 DCHECK(!bool1);
256 DCHECK_EQ(3, int1);
257 DCHECK_EQ("0_3", string1);
259 bool1 = false;
260 Send(new Msg_R_1_1(0, 1, &bool1));
261 DCHECK(bool1);
263 bool1 = false;
264 Send(new Msg_R_1_2(0, false, &bool1, &int1));
265 DCHECK(bool1);
266 DCHECK_EQ(12, int1);
268 bool1 = true;
269 Send(new Msg_R_1_3(0, 3, &string1, &int1, &bool1));
270 DCHECK_EQ("1_3", string1);
271 DCHECK_EQ(13, int1);
272 DCHECK(!bool1);
274 bool1 = false;
275 Send(new Msg_R_2_1(0, 1, false, &bool1));
276 DCHECK(bool1);
278 bool1 = false;
279 Send(new Msg_R_2_2(0, false, 2, &bool1, &int1));
280 DCHECK(bool1);
281 DCHECK_EQ(22, int1);
283 bool1 = true;
284 Send(new Msg_R_2_3(0, 3, true, &string1, &int1, &bool1));
285 DCHECK(!bool1);
286 DCHECK_EQ("2_3", string1);
287 DCHECK_EQ(23, int1);
289 bool1 = false;
290 Send(new Msg_R_3_1(0, 1, false, "3_1", &bool1));
291 DCHECK(bool1);
293 bool1 = false;
294 Send(new Msg_R_3_2(0, "3_2", false, 2, &bool1, &int1));
295 DCHECK(bool1);
296 DCHECK_EQ(32, int1);
298 bool1 = true;
299 Send(new Msg_R_3_3(0, 3, "3_3", true, &string1, &int1, &bool1));
300 DCHECK_EQ("3_3", string1);
301 DCHECK_EQ(33, int1);
302 DCHECK(!bool1);