| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Unit test to make sure that the serialization of synchronous IPC messages | 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. | 6 // works. This ensures that the macros and templates were defined correctly. |
| 7 // Doesn't test the IPC channel mechanism. | 7 // Doesn't test the IPC channel mechanism. |
| 8 | 8 |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 31 *out2 = 2; | 31 *out2 = 2; |
| 32 } | 32 } |
| 33 | 33 |
| 34 void On_0_3(bool* out1, int* out2, std::string* out3) { | 34 void On_0_3(bool* out1, int* out2, std::string* out3) { |
| 35 *out1 = false; | 35 *out1 = false; |
| 36 *out2 = 3; | 36 *out2 = 3; |
| 37 *out3 = "0_3"; | 37 *out3 = "0_3"; |
| 38 } | 38 } |
| 39 | 39 |
| 40 void On_1_1(int in1, bool* out1) { | 40 void On_1_1(int in1, bool* out1) { |
| 41 DCHECK(in1 == 1); | 41 DCHECK_EQ(1, in1); |
| 42 *out1 = true; | 42 *out1 = true; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void On_1_2(bool in1, bool* out1, int* out2) { | 45 void On_1_2(bool in1, bool* out1, int* out2) { |
| 46 DCHECK(!in1); | 46 DCHECK(!in1); |
| 47 *out1 = true; | 47 *out1 = true; |
| 48 *out2 = 12; | 48 *out2 = 12; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void On_1_3(int in1, std::string* out1, int* out2, bool* out3) { | 51 void On_1_3(int in1, std::string* out1, int* out2, bool* out3) { |
| 52 DCHECK(in1 == 3); | 52 DCHECK_EQ(3, in1); |
| 53 *out1 = "1_3"; | 53 *out1 = "1_3"; |
| 54 *out2 = 13; | 54 *out2 = 13; |
| 55 *out3 = false; | 55 *out3 = false; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void On_2_1(int in1, bool in2, bool* out1) { | 58 void On_2_1(int in1, bool in2, bool* out1) { |
| 59 DCHECK(in1 == 1 && !in2); | 59 DCHECK_EQ(1, in1); |
| 60 DCHECK(!in2); |
| 60 *out1 = true; | 61 *out1 = true; |
| 61 } | 62 } |
| 62 | 63 |
| 63 void On_2_2(bool in1, int in2, bool* out1, int* out2) { | 64 void On_2_2(bool in1, int in2, bool* out1, int* out2) { |
| 64 DCHECK(!in1 && in2 == 2); | 65 DCHECK(!in1); |
| 66 DCHECK_EQ(2, in2); |
| 65 *out1 = true; | 67 *out1 = true; |
| 66 *out2 = 22; | 68 *out2 = 22; |
| 67 } | 69 } |
| 68 | 70 |
| 69 void On_2_3(int in1, bool in2, std::string* out1, int* out2, bool* out3) { | 71 void On_2_3(int in1, bool in2, std::string* out1, int* out2, bool* out3) { |
| 70 DCHECK(in1 == 3 && in2); | 72 DCHECK_EQ(3, in1); |
| 73 DCHECK(in2); |
| 71 *out1 = "2_3"; | 74 *out1 = "2_3"; |
| 72 *out2 = 23; | 75 *out2 = 23; |
| 73 *out3 = false; | 76 *out3 = false; |
| 74 } | 77 } |
| 75 | 78 |
| 76 void On_3_1(int in1, bool in2, std::string in3, bool* out1) { | 79 void On_3_1(int in1, bool in2, std::string in3, bool* out1) { |
| 77 DCHECK(in1 == 1 && !in2 && in3 == "3_1"); | 80 DCHECK_EQ(1, in1); |
| 81 DCHECK(!in2); |
| 82 DCHECK_EQ("3_1", in3); |
| 78 *out1 = true; | 83 *out1 = true; |
| 79 } | 84 } |
| 80 | 85 |
| 81 void On_3_2(std::string in1, bool in2, int in3, bool* out1, int* out2) { | 86 void On_3_2(std::string in1, bool in2, int in3, bool* out1, int* out2) { |
| 82 DCHECK(in1 == "3_2" && !in2 && in3 == 2); | 87 DCHECK_EQ("3_2", in1); |
| 88 DCHECK(!in2); |
| 89 DCHECK_EQ(2, in3); |
| 83 *out1 = true; | 90 *out1 = true; |
| 84 *out2 = 32; | 91 *out2 = 32; |
| 85 } | 92 } |
| 86 | 93 |
| 87 void On_3_3(int in1, std::string in2, bool in3, std::string* out1, int* out2, | 94 void On_3_3(int in1, std::string in2, bool in3, std::string* out1, int* out2, |
| 88 bool* out3) { | 95 bool* out3) { |
| 89 DCHECK(in1 == 3 && in2 == "3_3" && in3); | 96 DCHECK_EQ(3, in1); |
| 97 DCHECK_EQ("3_3", in2); |
| 98 DCHECK(in3); |
| 90 *out1 = "3_3"; | 99 *out1 = "3_3"; |
| 91 *out2 = 33; | 100 *out2 = 33; |
| 92 *out3 = false; | 101 *out3 = false; |
| 93 } | 102 } |
| 94 | 103 |
| 95 void On_3_4(bool in1, int in2, std::string in3, int* out1, bool* out2, | 104 void On_3_4(bool in1, int in2, std::string in3, int* out1, bool* out2, |
| 96 std::string* out3, bool* out4) { | 105 std::string* out3, bool* out4) { |
| 97 DCHECK(in1 && in2 == 3 && in3 == "3_4"); | 106 DCHECK(in1); |
| 107 DCHECK_EQ(3, in2); |
| 108 DCHECK_EQ("3_4", in3); |
| 98 *out1 = 34; | 109 *out1 = 34; |
| 99 *out2 = true; | 110 *out2 = true; |
| 100 *out3 = "3_4"; | 111 *out3 = "3_4"; |
| 101 *out4 = false; | 112 *out4 = false; |
| 102 } | 113 } |
| 103 | 114 |
| 104 bool Send(IPC::Message* message) { | 115 bool Send(IPC::Message* message) { |
| 105 // gets the reply message, stash in global | 116 // gets the reply message, stash in global |
| 106 DCHECK(g_reply == NULL); | 117 DCHECK(g_reply == NULL); |
| 107 g_reply = message; | 118 g_reply = message; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 175 |
| 165 TEST(IPCSyncMessageTest, Main) { | 176 TEST(IPCSyncMessageTest, Main) { |
| 166 bool bool1 = true; | 177 bool bool1 = true; |
| 167 int int1 = 0; | 178 int int1 = 0; |
| 168 std::string string1; | 179 std::string string1; |
| 169 | 180 |
| 170 Send(new Msg_C_0_1(&bool1)); | 181 Send(new Msg_C_0_1(&bool1)); |
| 171 DCHECK(!bool1); | 182 DCHECK(!bool1); |
| 172 | 183 |
| 173 Send(new Msg_C_0_2(&bool1, &int1)); | 184 Send(new Msg_C_0_2(&bool1, &int1)); |
| 174 DCHECK(bool1 && int1 == 2); | 185 DCHECK(bool1); |
| 186 DCHECK_EQ(2, int1); |
| 175 | 187 |
| 176 Send(new Msg_C_0_3(&bool1, &int1, &string1)); | 188 Send(new Msg_C_0_3(&bool1, &int1, &string1)); |
| 177 DCHECK(!bool1 && int1 == 3 && string1 == "0_3"); | 189 DCHECK(!bool1); |
| 190 DCHECK_EQ(3, int1); |
| 191 DCHECK_EQ("0_3", string1); |
| 178 | 192 |
| 179 bool1 = false; | 193 bool1 = false; |
| 180 Send(new Msg_C_1_1(1, &bool1)); | 194 Send(new Msg_C_1_1(1, &bool1)); |
| 181 DCHECK(bool1); | 195 DCHECK(bool1); |
| 182 | 196 |
| 183 bool1 = false; | 197 bool1 = false; |
| 184 Send(new Msg_C_1_2(false, &bool1, &int1)); | 198 Send(new Msg_C_1_2(false, &bool1, &int1)); |
| 185 DCHECK(bool1 && int1 == 12); | 199 DCHECK(bool1); |
| 200 DCHECK_EQ(12, int1); |
| 186 | 201 |
| 187 bool1 = true; | 202 bool1 = true; |
| 188 Send(new Msg_C_1_3(3, &string1, &int1, &bool1)); | 203 Send(new Msg_C_1_3(3, &string1, &int1, &bool1)); |
| 189 DCHECK(string1 == "1_3" && int1 == 13 && !bool1); | 204 DCHECK_EQ("1_3", string1); |
| 205 DCHECK_EQ(13, int1); |
| 206 DCHECK(!bool1); |
| 190 | 207 |
| 191 bool1 = false; | 208 bool1 = false; |
| 192 Send(new Msg_C_2_1(1, false, &bool1)); | 209 Send(new Msg_C_2_1(1, false, &bool1)); |
| 193 DCHECK(bool1); | 210 DCHECK(bool1); |
| 194 | 211 |
| 195 bool1 = false; | 212 bool1 = false; |
| 196 Send(new Msg_C_2_2(false, 2, &bool1, &int1)); | 213 Send(new Msg_C_2_2(false, 2, &bool1, &int1)); |
| 197 DCHECK(bool1 && int1 == 22); | 214 DCHECK(bool1); |
| 215 DCHECK_EQ(22, int1); |
| 198 | 216 |
| 199 bool1 = true; | 217 bool1 = true; |
| 200 Send(new Msg_C_2_3(3, true, &string1, &int1, &bool1)); | 218 Send(new Msg_C_2_3(3, true, &string1, &int1, &bool1)); |
| 201 DCHECK(string1 == "2_3" && int1 == 23 && !bool1); | 219 DCHECK_EQ("2_3", string1); |
| 220 DCHECK_EQ(23, int1); |
| 221 DCHECK(!bool1); |
| 202 | 222 |
| 203 bool1 = false; | 223 bool1 = false; |
| 204 Send(new Msg_C_3_1(1, false, "3_1", &bool1)); | 224 Send(new Msg_C_3_1(1, false, "3_1", &bool1)); |
| 205 DCHECK(bool1); | 225 DCHECK(bool1); |
| 206 | 226 |
| 207 bool1 = false; | 227 bool1 = false; |
| 208 Send(new Msg_C_3_2("3_2", false, 2, &bool1, &int1)); | 228 Send(new Msg_C_3_2("3_2", false, 2, &bool1, &int1)); |
| 209 DCHECK(bool1 && int1 == 32); | 229 DCHECK(bool1); |
| 230 DCHECK_EQ(32, int1); |
| 210 | 231 |
| 211 bool1 = true; | 232 bool1 = true; |
| 212 Send(new Msg_C_3_3(3, "3_3", true, &string1, &int1, &bool1)); | 233 Send(new Msg_C_3_3(3, "3_3", true, &string1, &int1, &bool1)); |
| 213 DCHECK(string1 == "3_3" && int1 == 33 && !bool1); | 234 DCHECK_EQ("3_3", string1); |
| 235 DCHECK_EQ(33, int1); |
| 236 DCHECK(!bool1); |
| 214 | 237 |
| 215 bool1 = false; | 238 bool1 = false; |
| 216 bool bool2 = true; | 239 bool bool2 = true; |
| 217 Send(new Msg_C_3_4(true, 3, "3_4", &int1, &bool1, &string1, &bool2)); | 240 Send(new Msg_C_3_4(true, 3, "3_4", &int1, &bool1, &string1, &bool2)); |
| 218 DCHECK(int1 == 34 && bool1 && string1 == "3_4" && !bool2); | 241 DCHECK_EQ(34, int1); |
| 242 DCHECK(bool1); |
| 243 DCHECK_EQ("3_4", string1); |
| 244 DCHECK(!bool2); |
| 219 | 245 |
| 220 // Routed messages, just a copy of the above but with extra routing paramater | 246 // Routed messages, just a copy of the above but with extra routing paramater |
| 221 Send(new Msg_R_0_1(0, &bool1)); | 247 Send(new Msg_R_0_1(0, &bool1)); |
| 222 DCHECK(!bool1); | 248 DCHECK(!bool1); |
| 223 | 249 |
| 224 Send(new Msg_R_0_2(0, &bool1, &int1)); | 250 Send(new Msg_R_0_2(0, &bool1, &int1)); |
| 225 DCHECK(bool1 && int1 == 2); | 251 DCHECK(bool1); |
| 252 DCHECK_EQ(2, int1); |
| 226 | 253 |
| 227 Send(new Msg_R_0_3(0, &bool1, &int1, &string1)); | 254 Send(new Msg_R_0_3(0, &bool1, &int1, &string1)); |
| 228 DCHECK(!bool1 && int1 == 3 && string1 == "0_3"); | 255 DCHECK(!bool1); |
| 256 DCHECK_EQ(3, int1); |
| 257 DCHECK_EQ("0_3", string1); |
| 229 | 258 |
| 230 bool1 = false; | 259 bool1 = false; |
| 231 Send(new Msg_R_1_1(0, 1, &bool1)); | 260 Send(new Msg_R_1_1(0, 1, &bool1)); |
| 232 DCHECK(bool1); | 261 DCHECK(bool1); |
| 233 | 262 |
| 234 bool1 = false; | 263 bool1 = false; |
| 235 Send(new Msg_R_1_2(0, false, &bool1, &int1)); | 264 Send(new Msg_R_1_2(0, false, &bool1, &int1)); |
| 236 DCHECK(bool1 && int1 == 12); | 265 DCHECK(bool1); |
| 266 DCHECK_EQ(12, int1); |
| 237 | 267 |
| 238 bool1 = true; | 268 bool1 = true; |
| 239 Send(new Msg_R_1_3(0, 3, &string1, &int1, &bool1)); | 269 Send(new Msg_R_1_3(0, 3, &string1, &int1, &bool1)); |
| 240 DCHECK(string1 == "1_3" && int1 == 13 && !bool1); | 270 DCHECK_EQ("1_3", string1); |
| 271 DCHECK_EQ(13, int1); |
| 272 DCHECK(!bool1); |
| 241 | 273 |
| 242 bool1 = false; | 274 bool1 = false; |
| 243 Send(new Msg_R_2_1(0, 1, false, &bool1)); | 275 Send(new Msg_R_2_1(0, 1, false, &bool1)); |
| 244 DCHECK(bool1); | 276 DCHECK(bool1); |
| 245 | 277 |
| 246 bool1 = false; | 278 bool1 = false; |
| 247 Send(new Msg_R_2_2(0, false, 2, &bool1, &int1)); | 279 Send(new Msg_R_2_2(0, false, 2, &bool1, &int1)); |
| 248 DCHECK(bool1 && int1 == 22); | 280 DCHECK(bool1); |
| 281 DCHECK_EQ(22, int1); |
| 249 | 282 |
| 250 bool1 = true; | 283 bool1 = true; |
| 251 Send(new Msg_R_2_3(0, 3, true, &string1, &int1, &bool1)); | 284 Send(new Msg_R_2_3(0, 3, true, &string1, &int1, &bool1)); |
| 252 DCHECK(string1 == "2_3" && int1 == 23 && !bool1); | 285 DCHECK(!bool1); |
| 286 DCHECK_EQ("2_3", string1); |
| 287 DCHECK_EQ(23, int1); |
| 253 | 288 |
| 254 bool1 = false; | 289 bool1 = false; |
| 255 Send(new Msg_R_3_1(0, 1, false, "3_1", &bool1)); | 290 Send(new Msg_R_3_1(0, 1, false, "3_1", &bool1)); |
| 256 DCHECK(bool1); | 291 DCHECK(bool1); |
| 257 | 292 |
| 258 bool1 = false; | 293 bool1 = false; |
| 259 Send(new Msg_R_3_2(0, "3_2", false, 2, &bool1, &int1)); | 294 Send(new Msg_R_3_2(0, "3_2", false, 2, &bool1, &int1)); |
| 260 DCHECK(bool1 && int1 == 32); | 295 DCHECK(bool1); |
| 296 DCHECK_EQ(32, int1); |
| 261 | 297 |
| 262 bool1 = true; | 298 bool1 = true; |
| 263 Send(new Msg_R_3_3(0, 3, "3_3", true, &string1, &int1, &bool1)); | 299 Send(new Msg_R_3_3(0, 3, "3_3", true, &string1, &int1, &bool1)); |
| 264 DCHECK(string1 == "3_3" && int1 == 33 && !bool1); | 300 DCHECK_EQ("3_3", string1); |
| 301 DCHECK_EQ(33, int1); |
| 302 DCHECK(!bool1); |
| 265 } | 303 } |
| OLD | NEW |