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

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

Issue 2104333003: Split mojo/public/cpp/system/tests/core_unittest.cc, part 2 (of 2, apparently). (Closed) Base URL: https://github.com/domokit/mojo.git@work794_wait_many_no_handles
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
Index: mojo/public/cpp/system/tests/buffer_unittest.cc
diff --git a/mojo/public/cpp/system/tests/buffer_unittest.cc b/mojo/public/cpp/system/tests/buffer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a6feb766d663979211bf9f92c5b61fc315e1b331
--- /dev/null
+++ b/mojo/public/cpp/system/tests/buffer_unittest.cc
@@ -0,0 +1,40 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file tests the C++ wrappers in mojo/public/cpp/system/buffer.h.
+
+#include "mojo/public/cpp/system/buffer.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mojo {
+namespace {
+
+TEST(BufferTest, BasicSharedBuffer) {
+ // Cursory compilation test of |MakeScopedHandle()| with shared buffer
+ // handles.
+ EXPECT_FALSE(MakeScopedHandle(SharedBufferHandle()).is_valid());
+
+ ScopedSharedBufferHandle shared_buffer;
+ EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(nullptr, 100u, &shared_buffer));
+ EXPECT_TRUE(shared_buffer.is_valid());
+
+ void* pointer = nullptr;
+ EXPECT_EQ(MOJO_RESULT_OK, MapBuffer(shared_buffer.get(), 0, 100u, &pointer,
+ MOJO_MAP_BUFFER_FLAG_NONE));
+ EXPECT_NE(pointer, nullptr);
+
+ // Just try writing to it.
+ *static_cast<char*>(pointer) = 'x';
+
+ shared_buffer.reset();
+
+ // Can still write to it even after the handle is closed.
+ *static_cast<char*>(pointer) = 'y';
+
+ EXPECT_EQ(MOJO_RESULT_OK, UnmapBuffer(pointer));
+}
+
+} // namespace
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698