| OLD | NEW |
| 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 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 test::ScopedTestDir test_dir; | 91 test::ScopedTestDir test_dir; |
| 92 | 92 |
| 93 static const char kFooBar[] = "foo bar"; | 93 static const char kFooBar[] = "foo bar"; |
| 94 | 94 |
| 95 util::ScopedFILE fp(test_dir.CreateFile()); | 95 util::ScopedFILE fp(test_dir.CreateFile()); |
| 96 EXPECT_EQ(sizeof(kFooBar), fwrite(kFooBar, 1, sizeof(kFooBar), fp.get())); | 96 EXPECT_EQ(sizeof(kFooBar), fwrite(kFooBar, 1, sizeof(kFooBar), fp.get())); |
| 97 | 97 |
| 98 auto dispatcher = | 98 auto dispatcher = |
| 99 PlatformHandleDispatcher::Create(PlatformHandleFromFILE(std::move(fp))); | 99 PlatformHandleDispatcher::Create(PlatformHandleFromFILE(std::move(fp))); |
| 100 // TODO(vtl): Are these the correct rights for a |PlatformHandleDispatcher|? | 100 // TODO(vtl): Are these the correct rights for a |PlatformHandleDispatcher|? |
| 101 Handle handle(std::move(dispatcher), MOJO_HANDLE_RIGHT_TRANSFER | | 101 const MojoHandleRights kRights = MOJO_HANDLE_RIGHT_TRANSFER | |
| 102 MOJO_HANDLE_RIGHT_READ | | 102 MOJO_HANDLE_RIGHT_READ | |
| 103 MOJO_HANDLE_RIGHT_WRITE); | 103 MOJO_HANDLE_RIGHT_WRITE; |
| 104 Handle handle(std::move(dispatcher), kRights); |
| 104 | 105 |
| 105 HandleTransport transport(test::HandleTryStartTransport(handle)); | 106 HandleTransport transport(test::HandleTryStartTransport(handle)); |
| 106 EXPECT_TRUE(transport.is_valid()); | 107 EXPECT_TRUE(transport.is_valid()); |
| 107 EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, transport.GetType()); | 108 EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, transport.GetType()); |
| 108 EXPECT_FALSE(transport.IsBusy()); | 109 EXPECT_FALSE(transport.IsBusy()); |
| 109 | 110 |
| 110 auto generic_dispatcher = | 111 Handle equivalent_handle = |
| 111 transport.CreateEquivalentDispatcherAndClose(nullptr, 0u); | 112 transport.CreateEquivalentHandleAndClose(nullptr, 0u); |
| 112 ASSERT_TRUE(generic_dispatcher); | 113 ASSERT_TRUE(equivalent_handle.dispatcher); |
| 114 EXPECT_EQ(kRights, equivalent_handle.rights); |
| 113 | 115 |
| 114 transport.End(); | 116 transport.End(); |
| 115 EXPECT_TRUE(handle.dispatcher->HasOneRef()); | 117 EXPECT_TRUE(handle.dispatcher->HasOneRef()); |
| 116 handle.reset(); | 118 handle.reset(); |
| 117 | 119 |
| 118 ASSERT_EQ(Dispatcher::Type::PLATFORM_HANDLE, generic_dispatcher->GetType()); | 120 ASSERT_EQ(Dispatcher::Type::PLATFORM_HANDLE, |
| 119 dispatcher = RefPtr<PlatformHandleDispatcher>( | 121 equivalent_handle.dispatcher->GetType()); |
| 120 static_cast<PlatformHandleDispatcher*>(generic_dispatcher.get())); | 122 dispatcher = |
| 123 RefPtr<PlatformHandleDispatcher>(static_cast<PlatformHandleDispatcher*>( |
| 124 equivalent_handle.dispatcher.get())); |
| 121 | 125 |
| 122 fp = FILEFromPlatformHandle(dispatcher->PassPlatformHandle(), "rb"); | 126 fp = FILEFromPlatformHandle(dispatcher->PassPlatformHandle(), "rb"); |
| 123 EXPECT_TRUE(fp); | 127 EXPECT_TRUE(fp); |
| 124 | 128 |
| 125 rewind(fp.get()); | 129 rewind(fp.get()); |
| 126 char read_buffer[1000] = {}; | 130 char read_buffer[1000] = {}; |
| 127 EXPECT_EQ(sizeof(kFooBar), | 131 EXPECT_EQ(sizeof(kFooBar), |
| 128 fread(read_buffer, 1, sizeof(read_buffer), fp.get())); | 132 fread(read_buffer, 1, sizeof(read_buffer), fp.get())); |
| 129 EXPECT_STREQ(kFooBar, read_buffer); | 133 EXPECT_STREQ(kFooBar, read_buffer); |
| 130 | 134 |
| 131 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 135 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 132 } | 136 } |
| 133 | 137 |
| 134 } // namespace | 138 } // namespace |
| 135 } // namespace system | 139 } // namespace system |
| 136 } // namespace mojo | 140 } // namespace mojo |
| OLD | NEW |