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

Side by Side Diff: mojo/edk/system/platform_handle_dispatcher_unittest.cc

Issue 1946763002: EDK: Add MojoHandleRights to DispatcherTransport. (Closed) Base URL: https://github.com/domokit/mojo.git@work788_edk_handle_10
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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/platform_handle_dispatcher.h" 5 #include "mojo/edk/system/platform_handle_dispatcher.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "mojo/edk/platform/platform_handle_utils_posix.h" 11 #include "mojo/edk/platform/platform_handle_utils_posix.h"
12 #include "mojo/edk/system/handle.h"
12 #include "mojo/edk/system/handle_transport.h" 13 #include "mojo/edk/system/handle_transport.h"
13 #include "mojo/edk/system/test/scoped_test_dir.h" 14 #include "mojo/edk/system/test/scoped_test_dir.h"
14 #include "mojo/edk/util/scoped_file.h" 15 #include "mojo/edk/util/scoped_file.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 using mojo::platform::FILEFromPlatformHandle; 18 using mojo::platform::FILEFromPlatformHandle;
18 using mojo::platform::PlatformHandleFromFILE; 19 using mojo::platform::PlatformHandleFromFILE;
19 using mojo::platform::ScopedPlatformHandle; 20 using mojo::platform::ScopedPlatformHandle;
20 using mojo::util::RefPtr; 21 using mojo::util::RefPtr;
21 22
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 TEST(PlatformHandleDispatcherTest, CreateEquivalentDispatcherAndClose) { 90 TEST(PlatformHandleDispatcherTest, CreateEquivalentDispatcherAndClose) {
90 test::ScopedTestDir test_dir; 91 test::ScopedTestDir test_dir;
91 92
92 static const char kFooBar[] = "foo bar"; 93 static const char kFooBar[] = "foo bar";
93 94
94 util::ScopedFILE fp(test_dir.CreateFile()); 95 util::ScopedFILE fp(test_dir.CreateFile());
95 EXPECT_EQ(sizeof(kFooBar), fwrite(kFooBar, 1, sizeof(kFooBar), fp.get())); 96 EXPECT_EQ(sizeof(kFooBar), fwrite(kFooBar, 1, sizeof(kFooBar), fp.get()));
96 97
97 auto dispatcher = 98 auto dispatcher =
98 PlatformHandleDispatcher::Create(PlatformHandleFromFILE(std::move(fp))); 99 PlatformHandleDispatcher::Create(PlatformHandleFromFILE(std::move(fp)));
100 // TODO(vtl): Are these the correct rights for a |PlatformHandleDispatcher|?
101 Handle handle(std::move(dispatcher), MOJO_HANDLE_RIGHT_TRANSFER |
102 MOJO_HANDLE_RIGHT_READ |
103 MOJO_HANDLE_RIGHT_WRITE);
99 104
100 DispatcherTransport transport( 105 DispatcherTransport transport(test::HandleTryStartTransport(handle));
101 test::DispatcherTryStartTransport(dispatcher.get()));
102 EXPECT_TRUE(transport.is_valid()); 106 EXPECT_TRUE(transport.is_valid());
103 EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, transport.GetType()); 107 EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, transport.GetType());
104 EXPECT_FALSE(transport.IsBusy()); 108 EXPECT_FALSE(transport.IsBusy());
105 109
106 auto generic_dispatcher = 110 auto generic_dispatcher =
107 transport.CreateEquivalentDispatcherAndClose(nullptr, 0u); 111 transport.CreateEquivalentDispatcherAndClose(nullptr, 0u);
108 ASSERT_TRUE(generic_dispatcher); 112 ASSERT_TRUE(generic_dispatcher);
109 113
110 transport.End(); 114 transport.End();
111 EXPECT_TRUE(dispatcher->HasOneRef()); 115 EXPECT_TRUE(handle.dispatcher->HasOneRef());
112 dispatcher = nullptr; 116 handle.reset();
113 117
114 ASSERT_EQ(Dispatcher::Type::PLATFORM_HANDLE, generic_dispatcher->GetType()); 118 ASSERT_EQ(Dispatcher::Type::PLATFORM_HANDLE, generic_dispatcher->GetType());
115 dispatcher = RefPtr<PlatformHandleDispatcher>( 119 dispatcher = RefPtr<PlatformHandleDispatcher>(
116 static_cast<PlatformHandleDispatcher*>(generic_dispatcher.get())); 120 static_cast<PlatformHandleDispatcher*>(generic_dispatcher.get()));
117 121
118 fp = FILEFromPlatformHandle(dispatcher->PassPlatformHandle(), "rb"); 122 fp = FILEFromPlatformHandle(dispatcher->PassPlatformHandle(), "rb");
119 EXPECT_TRUE(fp); 123 EXPECT_TRUE(fp);
120 124
121 rewind(fp.get()); 125 rewind(fp.get());
122 char read_buffer[1000] = {}; 126 char read_buffer[1000] = {};
123 EXPECT_EQ(sizeof(kFooBar), 127 EXPECT_EQ(sizeof(kFooBar),
124 fread(read_buffer, 1, sizeof(read_buffer), fp.get())); 128 fread(read_buffer, 1, sizeof(read_buffer), fp.get()));
125 EXPECT_STREQ(kFooBar, read_buffer); 129 EXPECT_STREQ(kFooBar, read_buffer);
126 130
127 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); 131 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
128 } 132 }
129 133
130 } // namespace 134 } // namespace
131 } // namespace system 135 } // namespace system
132 } // namespace mojo 136 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/multiprocess_message_pipe_unittest.cc ('k') | mojo/edk/system/remote_data_pipe_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698