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

Side by Side Diff: mojo/public/platform/native/system_impl_private_unittest.cc

Issue 1993283002: Add thunks for MojoGetRights(), etc. (Closed) Base URL: https://github.com/domokit/mojo.git@work795_core_get_rights
Patch Set: I'm an idiot 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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, but using the explicit MojoSystemImpl parameter. 5 // This file tests the C API, but using the explicit MojoSystemImpl parameter.
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "mojo/public/platform/native/system_impl_private.h" 9 #include "mojo/public/platform/native/system_impl_private.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace mojo { 12 namespace mojo {
13 namespace { 13 namespace {
14 14
15 const MojoHandleRights kDefaultMessagePipeHandleRights =
16 MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_READ |
17 MOJO_HANDLE_RIGHT_WRITE | MOJO_HANDLE_RIGHT_GET_OPTIONS |
18 MOJO_HANDLE_RIGHT_SET_OPTIONS;
19 const MojoHandleRights kDefaultDataPipeProducerHandleRights =
20 MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_WRITE |
21 MOJO_HANDLE_RIGHT_GET_OPTIONS | MOJO_HANDLE_RIGHT_SET_OPTIONS;
22 const MojoHandleRights kDefaultDataPipeConsumerHandleRights =
23 MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_READ |
24 MOJO_HANDLE_RIGHT_GET_OPTIONS | MOJO_HANDLE_RIGHT_SET_OPTIONS;
25 const MojoHandleRights kDefaultSharedBufferHandleRights =
26 MOJO_HANDLE_RIGHT_DUPLICATE | MOJO_HANDLE_RIGHT_TRANSFER |
27 MOJO_HANDLE_RIGHT_GET_OPTIONS | MOJO_HANDLE_RIGHT_SET_OPTIONS |
28 MOJO_HANDLE_RIGHT_MAP_READABLE | MOJO_HANDLE_RIGHT_MAP_WRITABLE |
29 MOJO_HANDLE_RIGHT_MAP_EXECUTABLE;
30
15 TEST(SystemImplTest, GetTimeTicksNow) { 31 TEST(SystemImplTest, GetTimeTicksNow) {
16 MojoSystemImpl system = MojoSystemImplCreateImpl(); 32 MojoSystemImpl system = MojoSystemImplCreateImpl();
17 const MojoTimeTicks start = MojoSystemImplGetTimeTicksNow(system); 33 const MojoTimeTicks start = MojoSystemImplGetTimeTicksNow(system);
18 EXPECT_NE(static_cast<MojoTimeTicks>(0), start) 34 EXPECT_NE(static_cast<MojoTimeTicks>(0), start)
19 << "MojoGetTimeTicksNow should return nonzero value"; 35 << "MojoGetTimeTicksNow should return nonzero value";
20 36
21 // SystemImpl is leaked... 37 // SystemImpl is leaked...
22 } 38 }
23 39
24 TEST(SystemImplTest, BasicMessagePipe) { 40 TEST(SystemImplTest, BasicMessagePipe) {
25 MojoSystemImpl sys0 = MojoSystemImplCreateImpl(); 41 MojoSystemImpl sys0 = MojoSystemImplCreateImpl();
26 MojoSystemImpl sys1 = MojoSystemImplCreateImpl(); 42 MojoSystemImpl sys1 = MojoSystemImplCreateImpl();
27 EXPECT_NE(sys0, sys1); 43 EXPECT_NE(sys0, sys1);
28 44
29 MojoHandle h0, h1; 45 MojoHandle h0, h1;
30 MojoHandleSignals sig; 46 MojoHandleSignals sig;
31 char buffer[10] = {0}; 47 char buffer[10] = {0};
32 uint32_t buffer_size; 48 uint32_t buffer_size;
33 49
34 h0 = MOJO_HANDLE_INVALID; 50 h0 = MOJO_HANDLE_INVALID;
35 h1 = MOJO_HANDLE_INVALID; 51 h1 = MOJO_HANDLE_INVALID;
36 EXPECT_EQ(MOJO_RESULT_OK, 52 EXPECT_EQ(MOJO_RESULT_OK,
37 MojoSystemImplCreateMessagePipe(sys0, nullptr, &h0, &h1)); 53 MojoSystemImplCreateMessagePipe(sys0, nullptr, &h0, &h1));
38 EXPECT_NE(h0, MOJO_HANDLE_INVALID); 54 EXPECT_NE(h0, MOJO_HANDLE_INVALID);
39 EXPECT_NE(h1, MOJO_HANDLE_INVALID); 55 EXPECT_NE(h1, MOJO_HANDLE_INVALID);
56 EXPECT_NE(h0, h1);
57
58 // Both handles should have the correct rights.
59 MojoHandleRights rights = MOJO_HANDLE_RIGHT_NONE;
60 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplGetRights(sys0, h0, &rights));
61 EXPECT_EQ(kDefaultMessagePipeHandleRights, rights);
62 rights = MOJO_HANDLE_RIGHT_NONE;
63 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplGetRights(sys0, h1, &rights));
64 EXPECT_EQ(kDefaultMessagePipeHandleRights, rights);
40 65
41 // Move the other end of the pipe to a different SystemImpl. 66 // Move the other end of the pipe to a different SystemImpl.
42 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplTransferHandle(sys0, h1, sys1, &h1)); 67 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplTransferHandle(sys0, h1, sys1, &h1));
43 EXPECT_NE(h1, MOJO_HANDLE_INVALID); 68 EXPECT_NE(h1, MOJO_HANDLE_INVALID);
44 69
45 // Shouldn't be readable, we haven't written anything. 70 // Shouldn't be readable, we haven't written anything.
46 MojoHandleSignalsState state; 71 MojoHandleSignalsState state;
47 EXPECT_EQ( 72 EXPECT_EQ(
48 MOJO_RESULT_DEADLINE_EXCEEDED, 73 MOJO_RESULT_DEADLINE_EXCEEDED,
49 MojoSystemImplWait(sys0, h0, MOJO_HANDLE_SIGNAL_READABLE, 0, &state)); 74 MojoSystemImplWait(sys0, h0, MOJO_HANDLE_SIGNAL_READABLE, 0, &state));
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 uint32_t buffer_size; 165 uint32_t buffer_size;
141 void* write_pointer; 166 void* write_pointer;
142 const void* read_pointer; 167 const void* read_pointer;
143 168
144 hp = MOJO_HANDLE_INVALID; 169 hp = MOJO_HANDLE_INVALID;
145 hc = MOJO_HANDLE_INVALID; 170 hc = MOJO_HANDLE_INVALID;
146 EXPECT_EQ(MOJO_RESULT_OK, 171 EXPECT_EQ(MOJO_RESULT_OK,
147 MojoSystemImplCreateDataPipe(sys0, nullptr, &hp, &hc)); 172 MojoSystemImplCreateDataPipe(sys0, nullptr, &hp, &hc));
148 EXPECT_NE(hp, MOJO_HANDLE_INVALID); 173 EXPECT_NE(hp, MOJO_HANDLE_INVALID);
149 EXPECT_NE(hc, MOJO_HANDLE_INVALID); 174 EXPECT_NE(hc, MOJO_HANDLE_INVALID);
175 EXPECT_NE(hp, hc);
176
177 // Both handles should have the correct rights.
178 MojoHandleRights rights = MOJO_HANDLE_RIGHT_NONE;
179 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplGetRights(sys0, hp, &rights));
180 EXPECT_EQ(kDefaultDataPipeProducerHandleRights, rights);
181 rights = MOJO_HANDLE_RIGHT_NONE;
182 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplGetRights(sys0, hc, &rights));
183 EXPECT_EQ(kDefaultDataPipeConsumerHandleRights, rights);
150 184
151 // Move the other end of the pipe to a different SystemImpl. 185 // Move the other end of the pipe to a different SystemImpl.
152 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplTransferHandle(sys0, hc, sys1, &hc)); 186 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplTransferHandle(sys0, hc, sys1, &hc));
153 EXPECT_NE(hc, MOJO_HANDLE_INVALID); 187 EXPECT_NE(hc, MOJO_HANDLE_INVALID);
154 188
155 // The consumer |hc| shouldn't be readable. 189 // The consumer |hc| shouldn't be readable.
156 MojoHandleSignalsState state; 190 MojoHandleSignalsState state;
157 EXPECT_EQ( 191 EXPECT_EQ(
158 MOJO_RESULT_DEADLINE_EXCEEDED, 192 MOJO_RESULT_DEADLINE_EXCEEDED,
159 MojoSystemImplWait(sys1, hc, MOJO_HANDLE_SIGNAL_READABLE, 0, &state)); 193 MojoSystemImplWait(sys1, hc, MOJO_HANDLE_SIGNAL_READABLE, 0, &state));
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 601
568 MojoHandle h0, h1; 602 MojoHandle h0, h1;
569 void* pointer; 603 void* pointer;
570 604
571 // Create a shared buffer (|h0|). 605 // Create a shared buffer (|h0|).
572 h0 = MOJO_HANDLE_INVALID; 606 h0 = MOJO_HANDLE_INVALID;
573 EXPECT_EQ(MOJO_RESULT_OK, 607 EXPECT_EQ(MOJO_RESULT_OK,
574 MojoSystemImplCreateSharedBuffer(sys0, nullptr, kSize, &h0)); 608 MojoSystemImplCreateSharedBuffer(sys0, nullptr, kSize, &h0));
575 EXPECT_NE(h0, MOJO_HANDLE_INVALID); 609 EXPECT_NE(h0, MOJO_HANDLE_INVALID);
576 610
611 // The handle should have the correct rights.
612 MojoHandleRights rights = MOJO_HANDLE_RIGHT_NONE;
613 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplGetRights(sys0, h0, &rights));
614 EXPECT_EQ(kDefaultSharedBufferHandleRights, rights);
615
577 // Check the buffer information. 616 // Check the buffer information.
578 { 617 {
579 MojoBufferInformation info = {}; 618 MojoBufferInformation info = {};
580 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplGetBufferInformation( 619 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplGetBufferInformation(
581 sys0, h0, &info, sizeof(info))); 620 sys0, h0, &info, sizeof(info)));
582 EXPECT_EQ(sizeof(info), info.struct_size); 621 EXPECT_EQ(sizeof(info), info.struct_size);
583 EXPECT_EQ(MOJO_BUFFER_INFORMATION_FLAG_NONE, info.flags); 622 EXPECT_EQ(MOJO_BUFFER_INFORMATION_FLAG_NONE, info.flags);
584 EXPECT_EQ(kSize, info.num_bytes); 623 EXPECT_EQ(kSize, info.num_bytes);
585 } 624 }
586 625
587 // Map everything. 626 // Map everything.
588 pointer = nullptr; 627 pointer = nullptr;
589 EXPECT_EQ(MOJO_RESULT_OK, 628 EXPECT_EQ(MOJO_RESULT_OK,
590 MojoSystemImplMapBuffer(sys0, h0, 0u, kSize, &pointer, 629 MojoSystemImplMapBuffer(sys0, h0, 0u, kSize, &pointer,
591 MOJO_MAP_BUFFER_FLAG_NONE)); 630 MOJO_MAP_BUFFER_FLAG_NONE));
592 ASSERT_TRUE(pointer); 631 ASSERT_TRUE(pointer);
593 static_cast<char*>(pointer)[kSize / 2] = 'x'; 632 static_cast<char*>(pointer)[kSize / 2] = 'x';
594 633
595 // Duplicate |h0| to |h1|. 634 // Duplicate |h0| to |h1|.
596 h1 = MOJO_HANDLE_INVALID; 635 h1 = MOJO_HANDLE_INVALID;
597 EXPECT_EQ(MOJO_RESULT_OK, 636 EXPECT_EQ(MOJO_RESULT_OK,
598 MojoSystemImplDuplicateBufferHandle(sys0, h0, nullptr, &h1)); 637 MojoSystemImplDuplicateBufferHandle(sys0, h0, nullptr, &h1));
599 EXPECT_NE(h1, MOJO_HANDLE_INVALID); 638 EXPECT_NE(h1, MOJO_HANDLE_INVALID);
600 639
640 // The new handle should have the correct rights.
641 rights = MOJO_HANDLE_RIGHT_NONE;
642 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplGetRights(sys0, h1, &rights));
643 EXPECT_EQ(kDefaultSharedBufferHandleRights, rights);
644
601 // Move the other end of the pipe to a different SystemImpl. 645 // Move the other end of the pipe to a different SystemImpl.
602 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplTransferHandle(sys0, h1, sys1, &h1)); 646 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplTransferHandle(sys0, h1, sys1, &h1));
603 EXPECT_NE(h1, MOJO_HANDLE_INVALID); 647 EXPECT_NE(h1, MOJO_HANDLE_INVALID);
604 648
605 // Close |h0|. 649 // Close |h0|.
606 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys0, h0)); 650 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys0, h0));
607 651
608 // The mapping should still be good. 652 // The mapping should still be good.
609 static_cast<char*>(pointer)[kSize / 2 + 1] = 'y'; 653 static_cast<char*>(pointer)[kSize / 2 + 1] = 'y';
610 654
(...skipping 24 matching lines...) Expand all
635 // Unmap it. 679 // Unmap it.
636 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplUnmapBuffer(sys1, pointer)); 680 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplUnmapBuffer(sys1, pointer));
637 681
638 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, h1)); 682 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, h1));
639 683
640 // 2 SystemImpls are leaked... 684 // 2 SystemImpls are leaked...
641 } 685 }
642 686
643 } // namespace 687 } // namespace
644 } // namespace mojo 688 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/platform/native/system_impl_private_thunks.c ('k') | mojo/public/platform/native/system_thunks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698