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 // This file tests the C API. | 5 // This file tests the C API. |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "mojo/public/c/system/buffer.h" | 9 #include "mojo/public/c/system/buffer.h" |
10 #include "mojo/public/c/system/data_pipe.h" | 10 #include "mojo/public/c/system/data_pipe.h" |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 rights); | 730 rights); |
731 // Trying to duplicate |h2| should fail. | 731 // Trying to duplicate |h2| should fail. |
732 MojoHandle h3 = MOJO_HANDLE_INVALID; | 732 MojoHandle h3 = MOJO_HANDLE_INVALID; |
733 EXPECT_EQ(MOJO_RESULT_PERMISSION_DENIED, MojoDuplicateHandle(h2, &h3)); | 733 EXPECT_EQ(MOJO_RESULT_PERMISSION_DENIED, MojoDuplicateHandle(h2, &h3)); |
734 EXPECT_EQ(MOJO_HANDLE_INVALID, h3); | 734 EXPECT_EQ(MOJO_HANDLE_INVALID, h3); |
735 | 735 |
736 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1)); | 736 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1)); |
737 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h2)); | 737 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h2)); |
738 } | 738 } |
739 | 739 |
| 740 TEST(CoreTest, MessagePipeChecksTransferRight) { |
| 741 MojoHandle h0 = MOJO_HANDLE_INVALID; |
| 742 MojoHandle h1 = MOJO_HANDLE_INVALID; |
| 743 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &h0, &h1)); |
| 744 |
| 745 // Create a shared buffer (which is transferrable and duplicatable). |
| 746 MojoHandle h_transferrable = MOJO_HANDLE_INVALID; |
| 747 EXPECT_EQ(MOJO_RESULT_OK, |
| 748 MojoCreateSharedBuffer(nullptr, 100, &h_transferrable)); |
| 749 |
| 750 // Make a non-transferrable duplicate handle. |
| 751 MojoHandle h_not_transferrable = MOJO_HANDLE_INVALID; |
| 752 EXPECT_EQ(MOJO_RESULT_OK, MojoDuplicateHandleWithReducedRights( |
| 753 h_transferrable, MOJO_HANDLE_RIGHT_TRANSFER, |
| 754 &h_not_transferrable)); |
| 755 |
| 756 // |h_transferrable| can be transferred. |
| 757 EXPECT_EQ(MOJO_RESULT_OK, MojoWriteMessage(h0, nullptr, 0u, &h_transferrable, |
| 758 1u, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 759 |
| 760 // |h_not_transferrable| can be transferred. |
| 761 EXPECT_EQ(MOJO_RESULT_PERMISSION_DENIED, |
| 762 MojoWriteMessage(h0, nullptr, 0u, &h_not_transferrable, 1u, |
| 763 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 764 |
| 765 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0)); |
| 766 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1)); |
| 767 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h_not_transferrable)); |
| 768 } |
| 769 |
740 // This checks that things actually work in C (not C++). | 770 // This checks that things actually work in C (not C++). |
741 TEST(CoreTest, MinimalCTest) { | 771 TEST(CoreTest, MinimalCTest) { |
742 const char* failure = MinimalCTest(); | 772 const char* failure = MinimalCTest(); |
743 EXPECT_FALSE(failure) << failure; | 773 EXPECT_FALSE(failure) << failure; |
744 } | 774 } |
745 | 775 |
746 TEST(CoreTest, MinimalCppTest) { | 776 TEST(CoreTest, MinimalCppTest) { |
747 const char* failure = MinimalCppTest(); | 777 const char* failure = MinimalCppTest(); |
748 EXPECT_FALSE(failure) << failure; | 778 EXPECT_FALSE(failure) << failure; |
749 } | 779 } |
750 | 780 |
751 // TODO(vtl): Add multi-threaded tests. | 781 // TODO(vtl): Add multi-threaded tests. |
752 | 782 |
753 } // namespace | 783 } // namespace |
754 } // namespace mojo | 784 } // namespace mojo |
OLD | NEW |