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

Side by Side Diff: mojo/public/c/system/tests/core_unittest.cc

Issue 2012613002: Enforce/require MOJO_HANDLE_RIGHT_TRANSFER in sending handles via MojoWriteMessage(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 months 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
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 // 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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698