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

Side by Side Diff: mojo/system/core_impl_unittest.cc

Issue 66963005: Mojo: Implement local passing of MessagePipes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « mojo/system/core_impl.cc ('k') | mojo/system/core_test_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/system/core_impl.h" 5 #include "mojo/system/core_impl.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/basictypes.h"
9 #include "mojo/system/core_test_base.h" 10 #include "mojo/system/core_test_base.h"
10 11
11 namespace mojo { 12 namespace mojo {
12 namespace system { 13 namespace system {
13 namespace { 14 namespace {
14 15
15 class CoreImplTest : public test::CoreTestBase { 16 class CoreImplTest : public test::CoreTestBase {
16 }; 17 };
17 18
18 TEST_F(CoreImplTest, Basic) { 19 TEST_F(CoreImplTest, Basic) {
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 374
374 // Try writing to |h[1]|. 375 // Try writing to |h[1]|.
375 buffer[0] = 'e'; 376 buffer[0] = 'e';
376 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 377 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
377 core()->WriteMessage(h[1], buffer, 1, NULL, 0, 378 core()->WriteMessage(h[1], buffer, 1, NULL, 0,
378 MOJO_WRITE_MESSAGE_FLAG_NONE)); 379 MOJO_WRITE_MESSAGE_FLAG_NONE));
379 380
380 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h[1])); 381 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h[1]));
381 } 382 }
382 383
384 TEST_F(CoreImplTest, MessagePipeBasicLocalHandlePassing) {
385 const char kHello[] = "hello";
386 const uint32_t kHelloSize = static_cast<uint32_t>(sizeof(kHello));
387 const char kWorld[] = "world!!!";
388 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld));
389 char buffer[100];
390 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer));
391 uint32_t num_bytes;
392 MojoHandle handles[10];
393 uint32_t num_handles;
394 MojoHandle h_received;
395
396 MojoHandle h_passing[2];
397 EXPECT_EQ(MOJO_RESULT_OK,
398 core()->CreateMessagePipe(&h_passing[0], &h_passing[1]));
399
400 MojoHandle h_passed[2];
401 EXPECT_EQ(MOJO_RESULT_OK,
402 core()->CreateMessagePipe(&h_passed[0], &h_passed[1]));
403
404 // Make sure that |h_passing[]| work properly.
405 EXPECT_EQ(MOJO_RESULT_OK,
406 core()->WriteMessage(h_passing[0],
407 kHello, kHelloSize,
408 NULL, 0,
409 MOJO_WRITE_MESSAGE_FLAG_NONE));
410 EXPECT_EQ(MOJO_RESULT_OK,
411 core()->Wait(h_passing[1], MOJO_WAIT_FLAG_READABLE, 1000000000));
412 num_bytes = kBufferSize;
413 num_handles = arraysize(handles);
414 EXPECT_EQ(MOJO_RESULT_OK,
415 core()->ReadMessage(h_passing[1],
416 buffer, &num_bytes,
417 handles, &num_handles,
418 MOJO_READ_MESSAGE_FLAG_NONE));
419 EXPECT_EQ(kHelloSize, num_bytes);
420 EXPECT_STREQ(kHello, buffer);
421 EXPECT_EQ(0u, num_handles);
422
423 // Make sure that |h_passed[]| work properly.
424 EXPECT_EQ(MOJO_RESULT_OK,
425 core()->WriteMessage(h_passed[0],
426 kHello, kHelloSize,
427 NULL, 0,
428 MOJO_WRITE_MESSAGE_FLAG_NONE));
429 EXPECT_EQ(MOJO_RESULT_OK,
430 core()->Wait(h_passed[1], MOJO_WAIT_FLAG_READABLE, 1000000000));
431 num_bytes = kBufferSize;
432 num_handles = arraysize(handles);
433 EXPECT_EQ(MOJO_RESULT_OK,
434 core()->ReadMessage(h_passed[1],
435 buffer, &num_bytes,
436 handles, &num_handles,
437 MOJO_READ_MESSAGE_FLAG_NONE));
438 EXPECT_EQ(kHelloSize, num_bytes);
439 EXPECT_STREQ(kHello, buffer);
440 EXPECT_EQ(0u, num_handles);
441
442 // Send |h_passed[1]| from |h_passing[0]| to |h_passing[1]|.
443 EXPECT_EQ(MOJO_RESULT_OK,
444 core()->WriteMessage(h_passing[0],
445 kWorld, kWorldSize,
446 &h_passed[1], 1,
447 MOJO_WRITE_MESSAGE_FLAG_NONE));
448 EXPECT_EQ(MOJO_RESULT_OK,
449 core()->Wait(h_passing[1], MOJO_WAIT_FLAG_READABLE, 1000000000));
450 num_bytes = kBufferSize;
451 num_handles = arraysize(handles);
452 EXPECT_EQ(MOJO_RESULT_OK,
453 core()->ReadMessage(h_passing[1],
454 buffer, &num_bytes,
455 handles, &num_handles,
456 MOJO_READ_MESSAGE_FLAG_NONE));
457 EXPECT_EQ(kWorldSize, num_bytes);
458 EXPECT_STREQ(kWorld, buffer);
459 EXPECT_EQ(1u, num_handles);
460 h_received = handles[0];
461 EXPECT_NE(h_received, MOJO_HANDLE_INVALID);
462 EXPECT_NE(h_received, h_passing[0]);
463 EXPECT_NE(h_received, h_passing[1]);
464 EXPECT_NE(h_received, h_passed[0]);
465
466 // Note: We rely on the Mojo system not re-using handle values very often.
467 EXPECT_NE(h_received, h_passed[1]);
468
469 // |h_passed[1]| should no longer be valid; check that trying to close it
470 // fails. See above note.
471 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(h_passed[1]));
472
473 // Write to |h_passed[0]|. Should receive on |h_received|.
474 EXPECT_EQ(MOJO_RESULT_OK,
475 core()->WriteMessage(h_passed[0],
476 kHello, kHelloSize,
477 NULL, 0,
478 MOJO_WRITE_MESSAGE_FLAG_NONE));
479 EXPECT_EQ(MOJO_RESULT_OK,
480 core()->Wait(h_received, MOJO_WAIT_FLAG_READABLE, 1000000000));
481 num_bytes = kBufferSize;
482 num_handles = arraysize(handles);
483 EXPECT_EQ(MOJO_RESULT_OK,
484 core()->ReadMessage(h_received,
485 buffer, &num_bytes,
486 handles, &num_handles,
487 MOJO_READ_MESSAGE_FLAG_NONE));
488 EXPECT_EQ(kHelloSize, num_bytes);
489 EXPECT_STREQ(kHello, buffer);
490 EXPECT_EQ(0u, num_handles);
491
492 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[0]));
493 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1]));
494 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passed[0]));
495 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_received));
496 }
497
383 } // namespace 498 } // namespace
384 } // namespace system 499 } // namespace system
385 } // namespace mojo 500 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/core_impl.cc ('k') | mojo/system/core_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698