OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "mojo/embedder/embedder.h" | 5 #include "mojo/embedder/embedder.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 ScopedTestChannel server_channel(test_io_thread()->task_runner(), | 167 ScopedTestChannel server_channel(test_io_thread()->task_runner(), |
168 channel_pair.PassServerHandle()); | 168 channel_pair.PassServerHandle()); |
169 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); | 169 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); |
170 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); | 170 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); |
171 ScopedTestChannel client_channel(test_io_thread()->task_runner(), | 171 ScopedTestChannel client_channel(test_io_thread()->task_runner(), |
172 channel_pair.PassClientHandle()); | 172 channel_pair.PassClientHandle()); |
173 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); | 173 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); |
174 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); | 174 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); |
175 | 175 |
176 MojoHandle h0, h1; | 176 MojoHandle h0, h1; |
177 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(&h0, &h1)); | 177 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(NULL, &h0, &h1)); |
178 | 178 |
179 // Write a message to |h0| (attaching nothing). | 179 // Write a message to |h0| (attaching nothing). |
180 const char kHello[] = "hello"; | 180 const char kHello[] = "hello"; |
181 EXPECT_EQ(MOJO_RESULT_OK, | 181 EXPECT_EQ(MOJO_RESULT_OK, |
182 MojoWriteMessage(h0, kHello, | 182 MojoWriteMessage(h0, kHello, |
183 static_cast<uint32_t>(sizeof(kHello)), NULL, 0, | 183 static_cast<uint32_t>(sizeof(kHello)), NULL, 0, |
184 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 184 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
185 | 185 |
186 // Write one message to |server_mp|, attaching |h1|. | 186 // Write one message to |server_mp|, attaching |h1|. |
187 const char kWorld[] = "world!!!"; | 187 const char kWorld[] = "world!!!"; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); | 326 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); |
327 EXPECT_EQ(MOJO_RESULT_OK, | 327 EXPECT_EQ(MOJO_RESULT_OK, |
328 MojoReadMessage(server_mp, buffer, &num_bytes, NULL, NULL, | 328 MojoReadMessage(server_mp, buffer, &num_bytes, NULL, NULL, |
329 MOJO_READ_MESSAGE_FLAG_NONE)); | 329 MOJO_READ_MESSAGE_FLAG_NONE)); |
330 const char kWorld[] = "world!"; | 330 const char kWorld[] = "world!"; |
331 EXPECT_EQ(sizeof(kWorld), num_bytes); | 331 EXPECT_EQ(sizeof(kWorld), num_bytes); |
332 EXPECT_STREQ(kWorld, buffer); | 332 EXPECT_STREQ(kWorld, buffer); |
333 | 333 |
334 // Create a new message pipe (endpoints |mp0| and |mp1|). | 334 // Create a new message pipe (endpoints |mp0| and |mp1|). |
335 MojoHandle mp0, mp1; | 335 MojoHandle mp0, mp1; |
336 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(&mp0, &mp1)); | 336 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(NULL, &mp0, &mp1)); |
337 | 337 |
338 // 3. Write something to |mp0|. | 338 // 3. Write something to |mp0|. |
339 const char kFoo[] = "FOO"; | 339 const char kFoo[] = "FOO"; |
340 EXPECT_EQ(MOJO_RESULT_OK, | 340 EXPECT_EQ(MOJO_RESULT_OK, |
341 MojoWriteMessage(mp0, kFoo, | 341 MojoWriteMessage(mp0, kFoo, |
342 static_cast<uint32_t>(sizeof(kFoo)), NULL, 0, | 342 static_cast<uint32_t>(sizeof(kFoo)), NULL, 0, |
343 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 343 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
344 | 344 |
345 // 4. Write a message to |server_mp|, attaching |mp1|. | 345 // 4. Write a message to |server_mp|, attaching |mp1|. |
346 const char kBar[] = "Bar"; | 346 const char kBar[] = "Bar"; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 EXPECT_NE(mp1, MOJO_HANDLE_INVALID); | 454 EXPECT_NE(mp1, MOJO_HANDLE_INVALID); |
455 // TODO(vtl): If the scope were to end here (and the two handles closed), | 455 // TODO(vtl): If the scope were to end here (and the two handles closed), |
456 // we'd die due to |Channel::RunRemoteMessagePipeEndpoint()| not handling | 456 // we'd die due to |Channel::RunRemoteMessagePipeEndpoint()| not handling |
457 // write errors (assuming the parent had closed the pipe). | 457 // write errors (assuming the parent had closed the pipe). |
458 | 458 |
459 // 6. Close |client_mp|. | 459 // 6. Close |client_mp|. |
460 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); | 460 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); |
461 | 461 |
462 // Create a new message pipe (endpoints |mp2| and |mp3|). | 462 // Create a new message pipe (endpoints |mp2| and |mp3|). |
463 MojoHandle mp2, mp3; | 463 MojoHandle mp2, mp3; |
464 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(&mp2, &mp3)); | 464 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(NULL, &mp2, &mp3)); |
465 | 465 |
466 // 7. Write a message to |mp3|. | 466 // 7. Write a message to |mp3|. |
467 const char kBaz[] = "baz"; | 467 const char kBaz[] = "baz"; |
468 EXPECT_EQ(MOJO_RESULT_OK, | 468 EXPECT_EQ(MOJO_RESULT_OK, |
469 MojoWriteMessage(mp3, kBaz, | 469 MojoWriteMessage(mp3, kBaz, |
470 static_cast<uint32_t>(sizeof(kBaz)), NULL, 0, | 470 static_cast<uint32_t>(sizeof(kBaz)), NULL, 0, |
471 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 471 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
472 | 472 |
473 // 8. Close |mp3|. | 473 // 8. Close |mp3|. |
474 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp3)); | 474 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp3)); |
(...skipping 26 matching lines...) Expand all Loading... |
501 | 501 |
502 EXPECT_TRUE(test::Shutdown()); | 502 EXPECT_TRUE(test::Shutdown()); |
503 } | 503 } |
504 | 504 |
505 // TODO(vtl): Test immediate write & close. | 505 // TODO(vtl): Test immediate write & close. |
506 // TODO(vtl): Test broken-connection cases. | 506 // TODO(vtl): Test broken-connection cases. |
507 | 507 |
508 } // namespace | 508 } // namespace |
509 } // namespace embedder | 509 } // namespace embedder |
510 } // namespace mojo | 510 } // namespace mojo |
OLD | NEW |