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/shared_buffer_dispatcher.h" | 5 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "mojo/edk/embedder/simple_platform_support.h" | 10 #include "mojo/edk/embedder/simple_platform_support.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 EXPECT_FALSE(d->SupportsEntrypointClass(EntrypointClass::DATA_PIPE_PRODUCER)); | 196 EXPECT_FALSE(d->SupportsEntrypointClass(EntrypointClass::DATA_PIPE_PRODUCER)); |
197 EXPECT_FALSE(d->SupportsEntrypointClass(EntrypointClass::DATA_PIPE_CONSUMER)); | 197 EXPECT_FALSE(d->SupportsEntrypointClass(EntrypointClass::DATA_PIPE_CONSUMER)); |
198 EXPECT_TRUE(d->SupportsEntrypointClass(EntrypointClass::BUFFER)); | 198 EXPECT_TRUE(d->SupportsEntrypointClass(EntrypointClass::BUFFER)); |
199 | 199 |
200 // TODO(vtl): Check that it actually returns |MOJO_RESULT_INVALID_ARGUMENT| | 200 // TODO(vtl): Check that it actually returns |MOJO_RESULT_INVALID_ARGUMENT| |
201 // for methods in unsupported entrypoint classes. | 201 // for methods in unsupported entrypoint classes. |
202 | 202 |
203 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 203 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
204 } | 204 } |
205 | 205 |
| 206 TEST_F(SharedBufferDispatcherTest, DuplicateDispatcher) { |
| 207 const uint64_t kSize = 100u; |
| 208 |
| 209 MojoResult result = MOJO_RESULT_INTERNAL; |
| 210 auto dispatcher1 = SharedBufferDispatcher::Create( |
| 211 platform_support(), SharedBufferDispatcher::kDefaultCreateOptions, kSize, |
| 212 &result); |
| 213 EXPECT_EQ(MOJO_RESULT_OK, result); |
| 214 |
| 215 // Map and write something. |
| 216 std::unique_ptr<PlatformSharedBufferMapping> mapping; |
| 217 EXPECT_EQ( |
| 218 MOJO_RESULT_OK, |
| 219 dispatcher1->MapBuffer(0u, kSize, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); |
| 220 static_cast<char*>(mapping->GetBase())[0] = 'x'; |
| 221 mapping.reset(); |
| 222 |
| 223 // Duplicate |dispatcher1| and then close it. |
| 224 RefPtr<Dispatcher> dispatcher2; |
| 225 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateDispatcher(&dispatcher2)); |
| 226 ASSERT_TRUE(dispatcher2); |
| 227 EXPECT_EQ(Dispatcher::Type::SHARED_BUFFER, dispatcher2->GetType()); |
| 228 |
| 229 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close()); |
| 230 |
| 231 // Make sure that |dispatcher2| still reports the right information. |
| 232 MojoBufferInformation info = {}; |
| 233 EXPECT_EQ(MOJO_RESULT_OK, |
| 234 dispatcher2->GetBufferInformation( |
| 235 MakeUserPointer(&info), static_cast<uint32_t>(sizeof(info)))); |
| 236 EXPECT_EQ(sizeof(MojoBufferInformation), info.struct_size); |
| 237 EXPECT_EQ(MOJO_BUFFER_INFORMATION_FLAG_NONE, info.flags); |
| 238 EXPECT_EQ(kSize, info.num_bytes); |
| 239 |
| 240 // Map |dispatcher2| and read something. |
| 241 EXPECT_EQ( |
| 242 MOJO_RESULT_OK, |
| 243 dispatcher2->MapBuffer(0u, kSize, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); |
| 244 EXPECT_EQ('x', static_cast<char*>(mapping->GetBase())[0]); |
| 245 |
| 246 EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close()); |
| 247 } |
| 248 |
206 TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandle) { | 249 TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandle) { |
207 const uint64_t kSize = 100u; | 250 const uint64_t kSize = 100u; |
208 | 251 |
209 MojoResult result = MOJO_RESULT_INTERNAL; | 252 MojoResult result = MOJO_RESULT_INTERNAL; |
210 auto dispatcher1 = SharedBufferDispatcher::Create( | 253 auto dispatcher1 = SharedBufferDispatcher::Create( |
211 platform_support(), SharedBufferDispatcher::kDefaultCreateOptions, kSize, | 254 platform_support(), SharedBufferDispatcher::kDefaultCreateOptions, kSize, |
212 &result); | 255 &result); |
213 EXPECT_EQ(MOJO_RESULT_OK, result); | 256 EXPECT_EQ(MOJO_RESULT_OK, result); |
214 | 257 |
215 // Map and write something. | 258 // Map and write something. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 382 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
340 dispatcher->MapBuffer(0, 0, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); | 383 dispatcher->MapBuffer(0, 0, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); |
341 EXPECT_FALSE(mapping); | 384 EXPECT_FALSE(mapping); |
342 | 385 |
343 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 386 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
344 } | 387 } |
345 | 388 |
346 } // namespace | 389 } // namespace |
347 } // namespace system | 390 } // namespace system |
348 } // namespace mojo | 391 } // namespace mojo |
OLD | NEW |