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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 TEST(PlatformHandleDispatcherTest, CreateEquivalentDispatcherAndClose) { | 90 TEST(PlatformHandleDispatcherTest, CreateEquivalentDispatcherAndClose) { |
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 Handle handle(std::move(dispatcher), |
101 const MojoHandleRights kRights = MOJO_HANDLE_RIGHT_TRANSFER | | 101 PlatformHandleDispatcher::kDefaultHandleRights); |
102 MOJO_HANDLE_RIGHT_READ | | |
103 MOJO_HANDLE_RIGHT_WRITE; | |
104 Handle handle(std::move(dispatcher), kRights); | |
105 | 102 |
106 HandleTransport transport(test::HandleTryStartTransport(handle)); | 103 HandleTransport transport(test::HandleTryStartTransport(handle)); |
107 EXPECT_TRUE(transport.is_valid()); | 104 EXPECT_TRUE(transport.is_valid()); |
108 EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, transport.GetType()); | 105 EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, transport.GetType()); |
109 EXPECT_FALSE(transport.IsBusy()); | 106 EXPECT_FALSE(transport.IsBusy()); |
110 | 107 |
111 Handle equivalent_handle = | 108 Handle equivalent_handle = |
112 transport.CreateEquivalentHandleAndClose(nullptr, 0u); | 109 transport.CreateEquivalentHandleAndClose(nullptr, 0u); |
113 ASSERT_TRUE(equivalent_handle.dispatcher); | 110 ASSERT_TRUE(equivalent_handle.dispatcher); |
114 EXPECT_EQ(kRights, equivalent_handle.rights); | 111 EXPECT_EQ(PlatformHandleDispatcher::kDefaultHandleRights, |
| 112 equivalent_handle.rights); |
115 | 113 |
116 transport.End(); | 114 transport.End(); |
117 EXPECT_TRUE(handle.dispatcher->HasOneRef()); | 115 EXPECT_TRUE(handle.dispatcher->HasOneRef()); |
118 handle.reset(); | 116 handle.reset(); |
119 | 117 |
120 ASSERT_EQ(Dispatcher::Type::PLATFORM_HANDLE, | 118 ASSERT_EQ(Dispatcher::Type::PLATFORM_HANDLE, |
121 equivalent_handle.dispatcher->GetType()); | 119 equivalent_handle.dispatcher->GetType()); |
122 dispatcher = | 120 dispatcher = |
123 RefPtr<PlatformHandleDispatcher>(static_cast<PlatformHandleDispatcher*>( | 121 RefPtr<PlatformHandleDispatcher>(static_cast<PlatformHandleDispatcher*>( |
124 equivalent_handle.dispatcher.get())); | 122 equivalent_handle.dispatcher.get())); |
125 | 123 |
126 fp = FILEFromPlatformHandle(dispatcher->PassPlatformHandle(), "rb"); | 124 fp = FILEFromPlatformHandle(dispatcher->PassPlatformHandle(), "rb"); |
127 EXPECT_TRUE(fp); | 125 EXPECT_TRUE(fp); |
128 | 126 |
129 rewind(fp.get()); | 127 rewind(fp.get()); |
130 char read_buffer[1000] = {}; | 128 char read_buffer[1000] = {}; |
131 EXPECT_EQ(sizeof(kFooBar), | 129 EXPECT_EQ(sizeof(kFooBar), |
132 fread(read_buffer, 1, sizeof(read_buffer), fp.get())); | 130 fread(read_buffer, 1, sizeof(read_buffer), fp.get())); |
133 EXPECT_STREQ(kFooBar, read_buffer); | 131 EXPECT_STREQ(kFooBar, read_buffer); |
134 | 132 |
135 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 133 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
136 } | 134 } |
137 | 135 |
138 } // namespace | 136 } // namespace |
139 } // namespace system | 137 } // namespace system |
140 } // namespace mojo | 138 } // namespace mojo |
OLD | NEW |