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

Unified Diff: mojo/public/platform/native/platform_handle_apptest.cc

Issue 1578423002: Added PlatformHandle thunks. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: effed up the build changes, didnt catch it cause gn didnt run (I think) Created 4 years, 10 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/platform/native/platform_handle_apptest.cc
diff --git a/mojo/public/platform/native/platform_handle_apptest.cc b/mojo/public/platform/native/platform_handle_apptest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a6bb40f6f17c2f9edb0bafd2e96d4d246ab365ad
--- /dev/null
+++ b/mojo/public/platform/native/platform_handle_apptest.cc
@@ -0,0 +1,69 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
viettrungluu 2016/02/18 01:10:07 Maybe call this file platform_handle_private_appte
Forrest Reiling 2016/02/23 23:48:44 Wait why? It tests the thunks and the 'api' target
viettrungluu 2016/02/24 21:59:57 All of the "platform handle" API is private.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/public/cpp/application/application_test_base.h"
+#include "mojo/public/cpp/environment/logging.h"
+#include "mojo/public/cpp/system/macros.h"
+#include "mojo/public/platform/native/platform_handle_private.h"
viettrungluu 2016/02/18 01:10:07 And include this file first....
Forrest Reiling 2016/02/23 23:48:44 Done.
Forrest Reiling 2016/02/24 20:10:42 So when I do that I dont pass the presubmit checks
viettrungluu 2016/02/24 21:59:57 That's because you didn't rename this file.
+
+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;
viettrungluu 2016/02/18 01:10:07 I think you mostly don't need this.
Forrest Reiling 2016/02/23 23:48:44 Done.
+
+ int posix_result;
viettrungluu 2016/02/18 01:10:07 "
Forrest Reiling 2016/02/23 23:48:44 Done.
+ int pipe_fds[2];
viettrungluu 2016/02/18 01:10:06 Probably initialize these (probably both to -1).
Forrest Reiling 2016/02/23 23:48:45 Done.
+
+ uint64_t write_buffer = 0xDEADBEEF;
viettrungluu 2016/02/18 01:10:06 You should include <stdint.h> for uint64_t.
Forrest Reiling 2016/02/23 23:48:44 Done.
+ uint64_t read_buffer = 0;
+
+ posix_result = pipe(pipe_fds);
+ MOJO_CHECK(posix_result >= 0) << "Failed to open pipe: " << strerror(errno);
viettrungluu 2016/02/18 01:10:07 I'd use ASSERT_GE(), probably as simply ASSERT_GE
Forrest Reiling 2016/02/23 23:48:44 Done.
+
+ /*passing second FD through wrapper*/
viettrungluu 2016/02/18 01:10:06 Please use standard C++ comments. Don't forget to
Forrest Reiling 2016/02/23 23:48:44 Done.
+ original_handle = pipe_fds[1];
+
+ mojo_result = MojoCreatePlatformHandleWrapper(original_handle, &wrapper);
+ MOJO_CHECK(mojo_result == MOJO_RESULT_OK) << "Failed to wrap platform handle";
viettrungluu 2016/02/18 01:10:07 I'd just do: EXPECT_EQ(MOJO_RESULT_OK, MojoCreate
Forrest Reiling 2016/02/23 23:48:44 Done.
+
+ mojo_result = MojoExtractPlatformHandle(wrapper, &unwrapped_handle);
viettrungluu 2016/02/18 01:10:07 "
Forrest Reiling 2016/02/23 23:48:44 Done.
+ MOJO_CHECK(mojo_result == MOJO_RESULT_OK)
+ << "Failed to extract platform handle";
+
+ /*write to wrapped/unwrapped fd*/
+ ssize_t bytes_written =
viettrungluu 2016/02/18 01:10:06 I think ssize_t is defined in <sys/types.h>.
Forrest Reiling 2016/02/23 23:48:45 Done.
+ 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);
+
viettrungluu 2016/02/18 01:10:06 You didn't MojoClose() |wrapper|, and thus you're
Forrest Reiling 2016/02/23 23:48:45 Wait so MojoExtractPlatformHandle() calls mojo::em
+ close(pipe_fds[0]);
+ close(unwrapped_handle);
+}
+
+} // namespace
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698