OLD | NEW |
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/edk/system/core.h" | 5 #include "mojo/edk/system/core.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 num_handles = MOJO_ARRAYSIZE(handles); | 863 num_handles = MOJO_ARRAYSIZE(handles); |
864 EXPECT_EQ(MOJO_RESULT_OK, | 864 EXPECT_EQ(MOJO_RESULT_OK, |
865 core()->ReadMessage( | 865 core()->ReadMessage( |
866 h_passing[1], UserPointer<void>(buffer), | 866 h_passing[1], UserPointer<void>(buffer), |
867 MakeUserPointer(&num_bytes), MakeUserPointer(handles), | 867 MakeUserPointer(&num_bytes), MakeUserPointer(handles), |
868 MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE)); | 868 MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE)); |
869 EXPECT_EQ(kHelloSize, num_bytes); | 869 EXPECT_EQ(kHelloSize, num_bytes); |
870 EXPECT_STREQ(kHello, buffer); | 870 EXPECT_STREQ(kHello, buffer); |
871 EXPECT_EQ(0u, num_handles); | 871 EXPECT_EQ(0u, num_handles); |
872 | 872 |
873 // Make sure that you can't pass either of the message pipe's handles over | 873 // Make sure that you can't pass a message pipe handle over itself. |
874 // itself. | |
875 EXPECT_EQ(MOJO_RESULT_BUSY, | 874 EXPECT_EQ(MOJO_RESULT_BUSY, |
876 core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello), | 875 core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello), |
877 kHelloSize, MakeUserPointer(&h_passing[0]), 1, | 876 kHelloSize, MakeUserPointer(&h_passing[0]), 1, |
878 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 877 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
879 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | |
880 core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello), | |
881 kHelloSize, MakeUserPointer(&h_passing[1]), 1, | |
882 MOJO_WRITE_MESSAGE_FLAG_NONE)); | |
883 | 878 |
884 MojoHandle h_passed[2]; | 879 MojoHandle h_passed[2]; |
885 EXPECT_EQ(MOJO_RESULT_OK, | 880 EXPECT_EQ(MOJO_RESULT_OK, |
886 core()->CreateMessagePipe(NullUserPointer(), | 881 core()->CreateMessagePipe(NullUserPointer(), |
887 MakeUserPointer(&h_passed[0]), | 882 MakeUserPointer(&h_passed[0]), |
888 MakeUserPointer(&h_passed[1]))); | 883 MakeUserPointer(&h_passed[1]))); |
889 | 884 |
890 // Make sure that |h_passed[]| work properly. | 885 // Make sure that |h_passed[]| work properly. |
891 EXPECT_EQ(MOJO_RESULT_OK, | 886 EXPECT_EQ(MOJO_RESULT_OK, |
892 core()->WriteMessage(h_passed[0], UserPointer<const void>(kHello), | 887 core()->WriteMessage(h_passed[0], UserPointer<const void>(kHello), |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 // Complete the two-phase read. | 1591 // Complete the two-phase read. |
1597 EXPECT_EQ('x', static_cast<const char*>(read_ptr)[0]); | 1592 EXPECT_EQ('x', static_cast<const char*>(read_ptr)[0]); |
1598 EXPECT_EQ(MOJO_RESULT_OK, core()->EndReadData(ch, 1)); | 1593 EXPECT_EQ(MOJO_RESULT_OK, core()->EndReadData(ch, 1)); |
1599 | 1594 |
1600 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[0])); | 1595 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[0])); |
1601 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1])); | 1596 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1])); |
1602 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ph)); | 1597 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ph)); |
1603 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ch)); | 1598 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ch)); |
1604 } | 1599 } |
1605 | 1600 |
| 1601 // Tests "faux leak" message pipe handle passing situations. |
| 1602 TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing3) { |
| 1603 { |
| 1604 MojoHandle h0 = MOJO_HANDLE_INVALID; |
| 1605 MojoHandle h1 = MOJO_HANDLE_INVALID; |
| 1606 EXPECT_EQ(MOJO_RESULT_OK, |
| 1607 core()->CreateMessagePipe(NullUserPointer(), MakeUserPointer(&h0), |
| 1608 MakeUserPointer(&h1))); |
| 1609 |
| 1610 // You can send a message pipe's peer handle over itself (and nothing bad |
| 1611 // happens). |
| 1612 EXPECT_EQ( |
| 1613 MOJO_RESULT_OK, |
| 1614 core()->WriteMessage(h0, NullUserPointer(), 0, MakeUserPointer(&h1), 1, |
| 1615 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 1616 |
| 1617 // Of course, there's nothing to do afterwards except close the handle you |
| 1618 // have left. |
| 1619 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h0)); |
| 1620 } |
| 1621 |
| 1622 { |
| 1623 MojoHandle h0 = MOJO_HANDLE_INVALID; |
| 1624 MojoHandle h1 = MOJO_HANDLE_INVALID; |
| 1625 EXPECT_EQ(MOJO_RESULT_OK, |
| 1626 core()->CreateMessagePipe(NullUserPointer(), MakeUserPointer(&h0), |
| 1627 MakeUserPointer(&h1))); |
| 1628 |
| 1629 MojoHandle h_passed[2] = {MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID}; |
| 1630 EXPECT_EQ(MOJO_RESULT_OK, |
| 1631 core()->CreateMessagePipe(NullUserPointer(), |
| 1632 MakeUserPointer(&h_passed[0]), |
| 1633 MakeUserPointer(&h_passed[1]))); |
| 1634 |
| 1635 // You can also write |h1| into some other message pipe. |
| 1636 EXPECT_EQ(MOJO_RESULT_OK, |
| 1637 core()->WriteMessage(h_passed[0], NullUserPointer(), 0, |
| 1638 MakeUserPointer(&h1), 1, |
| 1639 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 1640 |
| 1641 // And then write both ends of that message pipe to |h0|. |
| 1642 EXPECT_EQ(MOJO_RESULT_OK, |
| 1643 core()->WriteMessage(h0, NullUserPointer(), 0, |
| 1644 MakeUserPointer(h_passed), 2, |
| 1645 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 1646 |
| 1647 // Again, nothing bad happens, but again you can only close |h0|. |
| 1648 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h0)); |
| 1649 } |
| 1650 } |
| 1651 |
1606 struct TestAsyncWaiter { | 1652 struct TestAsyncWaiter { |
1607 TestAsyncWaiter() : result(MOJO_RESULT_UNKNOWN) {} | 1653 TestAsyncWaiter() : result(MOJO_RESULT_UNKNOWN) {} |
1608 | 1654 |
1609 void Awake(MojoResult r) { result = r; } | 1655 void Awake(MojoResult r) { result = r; } |
1610 | 1656 |
1611 MojoResult result; | 1657 MojoResult result; |
1612 }; | 1658 }; |
1613 | 1659 |
1614 TEST_F(CoreTest, AsyncWait) { | 1660 TEST_F(CoreTest, AsyncWait) { |
1615 TestAsyncWaiter waiter; | 1661 TestAsyncWaiter waiter; |
(...skipping 17 matching lines...) Expand all Loading... |
1633 EXPECT_EQ(MOJO_RESULT_BUSY, waiter.result); | 1679 EXPECT_EQ(MOJO_RESULT_BUSY, waiter.result); |
1634 | 1680 |
1635 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); | 1681 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); |
1636 } | 1682 } |
1637 | 1683 |
1638 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|. | 1684 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|. |
1639 | 1685 |
1640 } // namespace | 1686 } // namespace |
1641 } // namespace system | 1687 } // namespace system |
1642 } // namespace mojo | 1688 } // namespace mojo |
OLD | NEW |