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

Unified Diff: mojo/public/tests/system_core_unittest.cc

Issue 23621056: Initial in-process implementation of some Mojo primitives. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 7 years, 3 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/tests/system_core_unittest.cc
diff --git a/mojo/public/tests/system_core_unittest.cc b/mojo/public/tests/system_core_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..382a800bf4c69e7c8e99009c15dc1eecdccd14de
--- /dev/null
+++ b/mojo/public/tests/system_core_unittest.cc
@@ -0,0 +1,105 @@
+// Copyright 2013 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.
+
+#include "mojo/public/system/core.h"
+
+#include <string.h>
+
+#include "mojo/public/tests/test_support.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mojo {
+namespace {
+
+class SystemTest : public test::TestBase {
+};
+
+TEST_F(SystemTest, Basic) {
+ Handle h_0;
+ MojoWaitFlags wf;
+ char buffer[10] = { 0 };
+ uint32_t buffer_size;
+
+ // The only handle that's guaranteed to be invalid is |kInvalidHandle|.
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, Close(kInvalidHandle));
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ Wait(kInvalidHandle, MOJO_WAIT_FLAG_EVERYTHING, 1000000));
+ h_0 = kInvalidHandle;
+ wf = MOJO_WAIT_FLAG_EVERYTHING;
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ WaitMany(&h_0, &wf, 1, MOJO_DEADLINE_INDEFINITE));
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ WriteMessage(h_0,
+ buffer, 3,
+ NULL, 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
+ buffer_size = static_cast<uint32_t>(sizeof(buffer));
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ ReadMessage(h_0,
+ buffer, &buffer_size,
+ NULL, NULL,
+ MOJO_READ_MESSAGE_FLAG_NONE));
+
+ Handle h_1;
+ EXPECT_EQ(MOJO_RESULT_OK, CreateMessagePipe(&h_0, &h_1));
+
+ // Shouldn't be readable.
+ EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
+ Wait(h_0, MOJO_WAIT_FLAG_READABLE, 0));
+
+ // Should be writable.
+ EXPECT_EQ(MOJO_RESULT_OK,
+ Wait(h_0, MOJO_WAIT_FLAG_WRITABLE, 0));
+
+ // Try to read.
+ EXPECT_EQ(MOJO_RESULT_NOT_FOUND,
+ ReadMessage(h_0,
+ buffer, &buffer_size,
+ NULL, NULL,
+ MOJO_READ_MESSAGE_FLAG_NONE));
+
+ // Write to |h_1|.
+ static const char hello[] = "hello";
+ memcpy(buffer, hello, sizeof(hello));
+ buffer_size = static_cast<uint32_t>(sizeof(hello));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ WriteMessage(h_1,
+ hello, buffer_size,
+ NULL, 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
+
+ // |h_0| should be readable.
+ wf = MOJO_WAIT_FLAG_READABLE;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ WaitMany(&h_0, &wf, 1, MOJO_DEADLINE_INDEFINITE));
+
+ // Read from |h_0|.
+ memset(buffer, 0, sizeof(buffer));
+ buffer_size = static_cast<uint32_t>(sizeof(buffer));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ ReadMessage(h_0,
+ buffer, &buffer_size,
+ NULL, NULL,
+ MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(static_cast<uint32_t>(sizeof(hello)), buffer_size);
+ EXPECT_EQ(0, memcmp(hello, buffer, sizeof(hello)));
+
+ // |h_0| should no longer be readable.
+ EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
+ Wait(h_0, MOJO_WAIT_FLAG_READABLE, 10));
+
+ // Close |h_0|.
+ EXPECT_EQ(MOJO_RESULT_OK, Close(h_0));
+
+ // |h_1| should no longer be readable or writable.
+ EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
+ Wait(h_1, MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE, 1000));
+
+ EXPECT_EQ(MOJO_RESULT_OK, Close(h_1));
+}
+
+// TODO(vtl): Add multi-threaded tests.
+
+} // namespace
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698