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

Unified Diff: mojo/platform_handle/platform_handle_apptest.cc

Issue 1578423002: Added PlatformHandle thunks. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 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/platform_handle/platform_handle_apptest.cc
diff --git a/mojo/platform_handle/platform_handle_apptest.cc b/mojo/platform_handle/platform_handle_apptest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f04b14d0c05a3f6cb5d9b2414368955d4b474c16
--- /dev/null
+++ b/mojo/platform_handle/platform_handle_apptest.cc
@@ -0,0 +1,69 @@
+// Copyright 2014 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/platform_handle/platform_handle_functions.h"
+#include "mojo/public/cpp/application/application_impl.h"
viettrungluu 2016/02/02 00:07:36 nit: blank line above.
Forrest Reiling 2016/02/10 20:16:08 after I moved the platform handle stuff, that head
+#include "mojo/public/cpp/application/application_test_base.h"
+#include "mojo/public/cpp/environment/logging.h"
+#include "mojo/public/cpp/system/macros.h"
+
+namespace mojo {
+namespace {
+
+// Exemplifies ApplicationTestBase's application testing pattern.
+class PlatformHandleApplicationTest : public test::ApplicationTestBase {
+ public:
+ PlatformHandleApplicationTest() : ApplicationTestBase() {}
+ ~PlatformHandleApplicationTest() override {}
+
+ private:
+ MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformHandleApplicationTest);
+};
+
+TEST_F(PlatformHandleApplicationTest, WrapAndUnwrapFileDescriptor) {
+ MojoPlatformHandle original_handle;
+ MojoPlatformHandle unwrapped_handle;
+ MojoHandle wrapper;
+ MojoResult mojo_result;
+
+ int posix_result;
+ int pipe_fds[2];
+
+ uint64_t write_buffer = 0xDEADBEEF;
+ uint64_t read_buffer = 0;
+
+ posix_result = pipe(pipe_fds);
+ MOJO_CHECK(posix_result >= 0) << "Failed to open pipe: " << strerror(errno);
+
+ /*passing second FD through wrapper*/
+ original_handle = pipe_fds[1];
+
+ mojo_result = MojoCreatePlatformHandleWrapper(original_handle, &wrapper);
+ MOJO_CHECK(mojo_result == MOJO_RESULT_OK) << "Failed to wrap platform handle";
+
+ mojo_result = MojoExtractPlatformHandle(wrapper, &unwrapped_handle);
+ MOJO_CHECK(mojo_result == MOJO_RESULT_OK)
+ << "Failed to extract platform handle";
+
+ /*write to wrapped/unwrapped fd*/
+ ssize_t bytes_written =
+ write(unwrapped_handle, &write_buffer, sizeof(write_buffer));
+ MOJO_CHECK(bytes_written >= 0)
+ << "Failed to write to wrapped/unwrapped handle: " << strerror(errno);
+
+ /*read from other end of pipe*/
+ ssize_t bytes_read = read(pipe_fds[0], &read_buffer, sizeof(read_buffer));
+ MOJO_CHECK(bytes_read >= 0) << "Failed to read to read from original pipe: "
+ << strerror(errno);
+
+ MOJO_CHECK(bytes_read == bytes_written)
+ << "Read a different number of bytes from pipe than were written to pipe";
+ EXPECT_EQ(write_buffer, read_buffer);
+
+ close(pipe_fds[0]);
+ close(unwrapped_handle);
+}
+
+} // namespace
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698