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

Unified Diff: mojo/edk/system/shared_buffer_dispatcher_unittest.cc

Issue 2001673003: EDK: Add Core::DuplicateHandleWithReducedRights(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/system/shared_buffer_dispatcher.cc ('k') | mojo/public/c/system/handle.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/shared_buffer_dispatcher_unittest.cc
diff --git a/mojo/edk/system/shared_buffer_dispatcher_unittest.cc b/mojo/edk/system/shared_buffer_dispatcher_unittest.cc
index fa90b239796fce39d26a78927b76c4b115ba6324..bf8a1ddbf46073e290a9b91dcca98b7bb328bf6d 100644
--- a/mojo/edk/system/shared_buffer_dispatcher_unittest.cc
+++ b/mojo/edk/system/shared_buffer_dispatcher_unittest.cc
@@ -203,6 +203,49 @@ TEST_F(SharedBufferDispatcherTest, SupportsEntrypointClass) {
EXPECT_EQ(MOJO_RESULT_OK, d->Close());
}
+TEST_F(SharedBufferDispatcherTest, DuplicateDispatcher) {
+ const uint64_t kSize = 100u;
+
+ MojoResult result = MOJO_RESULT_INTERNAL;
+ auto dispatcher1 = SharedBufferDispatcher::Create(
+ platform_support(), SharedBufferDispatcher::kDefaultCreateOptions, kSize,
+ &result);
+ EXPECT_EQ(MOJO_RESULT_OK, result);
+
+ // Map and write something.
+ std::unique_ptr<PlatformSharedBufferMapping> mapping;
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dispatcher1->MapBuffer(0u, kSize, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
+ static_cast<char*>(mapping->GetBase())[0] = 'x';
+ mapping.reset();
+
+ // Duplicate |dispatcher1| and then close it.
+ RefPtr<Dispatcher> dispatcher2;
+ EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateDispatcher(&dispatcher2));
+ ASSERT_TRUE(dispatcher2);
+ EXPECT_EQ(Dispatcher::Type::SHARED_BUFFER, dispatcher2->GetType());
+
+ EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close());
+
+ // Make sure that |dispatcher2| still reports the right information.
+ MojoBufferInformation info = {};
+ EXPECT_EQ(MOJO_RESULT_OK,
+ dispatcher2->GetBufferInformation(
+ MakeUserPointer(&info), static_cast<uint32_t>(sizeof(info))));
+ EXPECT_EQ(sizeof(MojoBufferInformation), info.struct_size);
+ EXPECT_EQ(MOJO_BUFFER_INFORMATION_FLAG_NONE, info.flags);
+ EXPECT_EQ(kSize, info.num_bytes);
+
+ // Map |dispatcher2| and read something.
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dispatcher2->MapBuffer(0u, kSize, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
+ EXPECT_EQ('x', static_cast<char*>(mapping->GetBase())[0]);
+
+ EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close());
+}
+
TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandle) {
const uint64_t kSize = 100u;
« no previous file with comments | « mojo/edk/system/shared_buffer_dispatcher.cc ('k') | mojo/public/c/system/handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698