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

Unified Diff: mojo/public/cpp/system/tests/core_unittest.cc

Issue 2036053002: Mojo: Add a C++-style SharedBuffer API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/public/cpp/system/handle.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/system/tests/core_unittest.cc
diff --git a/mojo/public/cpp/system/tests/core_unittest.cc b/mojo/public/cpp/system/tests/core_unittest.cc
index b500be3be763d5b46a39334285a03acb70fa5827..9a956353d50cc41faef4ed4e236c6c865c2634cd 100644
--- a/mojo/public/cpp/system/tests/core_unittest.cc
+++ b/mojo/public/cpp/system/tests/core_unittest.cc
@@ -481,6 +481,47 @@ TEST(CoreCppTest, ScopedHandleMoveCtor) {
EXPECT_FALSE(buffer2.is_valid());
}
+TEST(CoreCppTest, BasicSharedBuffer) {
+ ScopedSharedBufferHandle h0;
+
+ // Create a shared buffer (|h0|).
+ {
+ SharedBuffer buffer(100);
+ h0 = std::move(buffer.handle);
+ }
+
+ // Map everything.
+ ScopedSharedBufferMapping mapping = h0->Map(100);
+ ASSERT_TRUE(mapping);
+ static_cast<char*>(mapping.get())[50] = 'x';
+
+ // Duplicate |h0| to |h1|.
+ ScopedSharedBufferHandle h1 =
+ h0->Clone(SharedBufferHandle::AccessMode::READ_ONLY);
+ ASSERT_TRUE(h1.is_valid());
+
+ // Close |h0|.
+ h0.reset();
+
+ // The mapping should still be good.
+ static_cast<char*>(mapping.get())[51] = 'y';
+
+ // Unmap it.
+ mapping.reset();
+
+ // Map half of |h1|.
+ mapping = h1->MapAtOffset(50, 50);
+ ASSERT_TRUE(mapping);
+
+ // It should have what we wrote.
+ EXPECT_EQ('x', static_cast<char*>(mapping.get())[0]);
+ EXPECT_EQ('y', static_cast<char*>(mapping.get())[1]);
+
+ // Unmap it.
+ mapping.reset();
+ h1.reset();
+}
+
// TODO(vtl): Write data pipe tests.
} // namespace
« no previous file with comments | « mojo/public/cpp/system/handle.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698