Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: ipc/ipc_sync_message_unittest.cc

Issue 155905: Separates ipc code from common (http://crbug.com/16829) (Closed)
Patch Set: Fixes reference to 'common_message_traits' it's actually 'common_param_traits' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/ipc_sync_message_unittest.h ('k') | ipc/ipc_tests.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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.
8
9 #include <string.h>
10
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"
16
17
18 #define MESSAGES_INTERNAL_FILE "ipc/ipc_sync_message_unittest.h"
19 #include "ipc/ipc_message_macros.h"
20
21 static IPC::Message* g_reply;
22
23 class TestMessageReceiver {
24 public:
25
26 void On_0_1(bool* out1) {
27 *out1 = false;
28 }
29
30 void On_0_2(bool* out1, int* out2) {
31 *out1 = true;
32 *out2 = 2;
33 }
34
35 void On_0_3(bool* out1, int* out2, std::string* out3) {
36 *out1 = false;
37 *out2 = 3;
38 *out3 = "0_3";
39 }
40
41 void On_1_1(int in1, bool* out1) {
42 DCHECK(in1 == 1);
43 *out1 = true;
44 }
45
46 void On_1_2(bool in1, bool* out1, int* out2) {
47 DCHECK(!in1);
48 *out1 = true;
49 *out2 = 12;
50 }
51
52 void On_1_3(int in1, std::string* out1, int* out2, bool* out3) {
53 DCHECK(in1 == 3);
54 *out1 = "1_3";
55 *out2 = 13;
56 *out3 = false;
57 }
58
59 void On_2_1(int in1, bool in2, bool* out1) {
60 DCHECK(in1 == 1 && !in2);
61 *out1 = true;
62 }
63
64 void On_2_2(bool in1, int in2, bool* out1, int* out2) {
65 DCHECK(!in1 && in2 == 2);
66 *out1 = true;
67 *out2 = 22;
68 }
69
70 void On_2_3(int in1, bool in2, std::string* out1, int* out2, bool* out3) {
71 DCHECK(in1 == 3 && in2);
72 *out1 = "2_3";
73 *out2 = 23;
74 *out3 = false;
75 }
76
77 void On_3_1(int in1, bool in2, std::string in3, bool* out1) {
78 DCHECK(in1 == 1 && !in2 && in3 == "3_1");
79 *out1 = true;
80 }
81
82 void On_3_2(std::string in1, bool in2, int in3, bool* out1, int* out2) {
83 DCHECK(in1 == "3_2" && !in2 && in3 == 2);
84 *out1 = true;
85 *out2 = 32;
86 }
87
88 void On_3_3(int in1, std::string in2, bool in3, std::string* out1, int* out2,
89 bool* out3) {
90 DCHECK(in1 == 3 && in2 == "3_3" && in3);
91 *out1 = "3_3";
92 *out2 = 33;
93 *out3 = false;
94 }
95
96 bool Send(IPC::Message* message) {
97 // gets the reply message, stash in global
98 DCHECK(g_reply == NULL);
99 g_reply = message;
100 return true;
101 }
102
103 void OnMessageReceived(const IPC::Message& msg) {
104 IPC_BEGIN_MESSAGE_MAP(TestMessageReceiver, msg)
105 IPC_MESSAGE_HANDLER(Msg_C_0_1, On_0_1)
106 IPC_MESSAGE_HANDLER(Msg_C_0_2, On_0_2)
107 IPC_MESSAGE_HANDLER(Msg_C_0_3, On_0_3)
108 IPC_MESSAGE_HANDLER(Msg_C_1_1, On_1_1)
109 IPC_MESSAGE_HANDLER(Msg_C_1_2, On_1_2)
110 IPC_MESSAGE_HANDLER(Msg_C_1_3, On_1_3)
111 IPC_MESSAGE_HANDLER(Msg_C_2_1, On_2_1)
112 IPC_MESSAGE_HANDLER(Msg_C_2_2, On_2_2)
113 IPC_MESSAGE_HANDLER(Msg_C_2_3, On_2_3)
114 IPC_MESSAGE_HANDLER(Msg_C_3_1, On_3_1)
115 IPC_MESSAGE_HANDLER(Msg_C_3_2, On_3_2)
116 IPC_MESSAGE_HANDLER(Msg_C_3_3, On_3_3)
117 IPC_MESSAGE_HANDLER(Msg_R_0_1, On_0_1)
118 IPC_MESSAGE_HANDLER(Msg_R_0_2, On_0_2)
119 IPC_MESSAGE_HANDLER(Msg_R_0_3, On_0_3)
120 IPC_MESSAGE_HANDLER(Msg_R_1_1, On_1_1)
121 IPC_MESSAGE_HANDLER(Msg_R_1_2, On_1_2)
122 IPC_MESSAGE_HANDLER(Msg_R_1_3, On_1_3)
123 IPC_MESSAGE_HANDLER(Msg_R_2_1, On_2_1)
124 IPC_MESSAGE_HANDLER(Msg_R_2_2, On_2_2)
125 IPC_MESSAGE_HANDLER(Msg_R_2_3, On_2_3)
126 IPC_MESSAGE_HANDLER(Msg_R_3_1, On_3_1)
127 IPC_MESSAGE_HANDLER(Msg_R_3_2, On_3_2)
128 IPC_MESSAGE_HANDLER(Msg_R_3_3, On_3_3)
129 IPC_END_MESSAGE_MAP()
130 }
131
132 };
133
134 void Send(IPC::SyncMessage* msg) {
135 static TestMessageReceiver receiver;
136
137 IPC::MessageReplyDeserializer* reply_serializer = msg->GetReplyDeserializer();
138 DCHECK(reply_serializer != NULL);
139
140 // "send" the message
141 receiver.OnMessageReceived(*msg);
142 delete msg;
143
144 // get the reply message from the global, and deserialize the output
145 // parameters into the output pointers.
146 DCHECK(g_reply != NULL);
147 bool result = reply_serializer->SerializeOutputParameters(*g_reply);
148 DCHECK(result);
149 delete g_reply;
150 g_reply = NULL;
151 delete reply_serializer;
152 }
153
154 TEST(IPCSyncMessageTest, Main) {
155 bool bool1 = true;
156 int int1 = 0;
157 std::string string1;
158
159 Send(new Msg_C_0_1(&bool1));
160 DCHECK(!bool1);
161
162 Send(new Msg_C_0_2(&bool1, &int1));
163 DCHECK(bool1 && int1 == 2);
164
165 Send(new Msg_C_0_3(&bool1, &int1, &string1));
166 DCHECK(!bool1 && int1 == 3 && string1 == "0_3");
167
168 bool1 = false;
169 Send(new Msg_C_1_1(1, &bool1));
170 DCHECK(bool1);
171
172 bool1 = false;
173 Send(new Msg_C_1_2(false, &bool1, &int1));
174 DCHECK(bool1 && int1 == 12);
175
176 bool1 = true;
177 Send(new Msg_C_1_3(3, &string1, &int1, &bool1));
178 DCHECK(string1 == "1_3" && int1 == 13 && !bool1);
179
180 bool1 = false;
181 Send(new Msg_C_2_1(1, false, &bool1));
182 DCHECK(bool1);
183
184 bool1 = false;
185 Send(new Msg_C_2_2(false, 2, &bool1, &int1));
186 DCHECK(bool1 && int1 == 22);
187
188 bool1 = true;
189 Send(new Msg_C_2_3(3, true, &string1, &int1, &bool1));
190 DCHECK(string1 == "2_3" && int1 == 23 && !bool1);
191
192 bool1 = false;
193 Send(new Msg_C_3_1(1, false, "3_1", &bool1));
194 DCHECK(bool1);
195
196 bool1 = false;
197 Send(new Msg_C_3_2("3_2", false, 2, &bool1, &int1));
198 DCHECK(bool1 && int1 == 32);
199
200 bool1 = true;
201 Send(new Msg_C_3_3(3, "3_3", true, &string1, &int1, &bool1));
202 DCHECK(string1 == "3_3" && int1 == 33 && !bool1);
203
204 // Routed messages, just a copy of the above but with extra routing paramater
205 Send(new Msg_R_0_1(0, &bool1));
206 DCHECK(!bool1);
207
208 Send(new Msg_R_0_2(0, &bool1, &int1));
209 DCHECK(bool1 && int1 == 2);
210
211 Send(new Msg_R_0_3(0, &bool1, &int1, &string1));
212 DCHECK(!bool1 && int1 == 3 && string1 == "0_3");
213
214 bool1 = false;
215 Send(new Msg_R_1_1(0, 1, &bool1));
216 DCHECK(bool1);
217
218 bool1 = false;
219 Send(new Msg_R_1_2(0, false, &bool1, &int1));
220 DCHECK(bool1 && int1 == 12);
221
222 bool1 = true;
223 Send(new Msg_R_1_3(0, 3, &string1, &int1, &bool1));
224 DCHECK(string1 == "1_3" && int1 == 13 && !bool1);
225
226 bool1 = false;
227 Send(new Msg_R_2_1(0, 1, false, &bool1));
228 DCHECK(bool1);
229
230 bool1 = false;
231 Send(new Msg_R_2_2(0, false, 2, &bool1, &int1));
232 DCHECK(bool1 && int1 == 22);
233
234 bool1 = true;
235 Send(new Msg_R_2_3(0, 3, true, &string1, &int1, &bool1));
236 DCHECK(string1 == "2_3" && int1 == 23 && !bool1);
237
238 bool1 = false;
239 Send(new Msg_R_3_1(0, 1, false, "3_1", &bool1));
240 DCHECK(bool1);
241
242 bool1 = false;
243 Send(new Msg_R_3_2(0, "3_2", false, 2, &bool1, &int1));
244 DCHECK(bool1 && int1 == 32);
245
246 bool1 = true;
247 Send(new Msg_R_3_3(0, 3, "3_3", true, &string1, &int1, &bool1));
248 DCHECK(string1 == "3_3" && int1 == 33 && !bool1);
249 }
OLDNEW
« no previous file with comments | « ipc/ipc_sync_message_unittest.h ('k') | ipc/ipc_tests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698