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 |