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

Side by Side Diff: mojo/public/platform/native/platform_handle_private_apptest.cc

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/platform/native/platform_handle_private.h"
6
7 #include <stdint.h>
8 #include <sys/types.h>
9 #include <unistd.h>
10
11 #include "mojo/public/cpp/application/application_test_base.h"
12 #include "mojo/public/cpp/environment/logging.h"
13 #include "mojo/public/cpp/system/macros.h"
14
15 namespace mojo {
16 namespace {
17
18 class PlatformHandlePrivateApplicationTest : public test::ApplicationTestBase {
19 public:
20 PlatformHandlePrivateApplicationTest() : ApplicationTestBase() {}
21 ~PlatformHandlePrivateApplicationTest() override {}
22
23 private:
24 MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformHandlePrivateApplicationTest);
25 };
26
27 TEST_F(PlatformHandlePrivateApplicationTest, WrapAndUnwrapFileDescriptor) {
28 MojoPlatformHandle original_handle = -1;
29 MojoPlatformHandle unwrapped_handle = -1;
30 MojoHandle wrapper = MOJO_HANDLE_INVALID;
31
32 int pipe_fds[2] = {-1, -1};
33
34 uint64_t write_buffer = 0xDEADBEEF;
35 uint64_t read_buffer = 0;
36
37 ASSERT_EQ(0, pipe(pipe_fds));
38
39 // Pass second FD through wrapper.
40 original_handle = pipe_fds[1];
41
42 EXPECT_EQ(MOJO_RESULT_OK,
43 MojoCreatePlatformHandleWrapper(original_handle, &wrapper));
44 EXPECT_EQ(MOJO_RESULT_OK,
45 MojoExtractPlatformHandle(wrapper, &unwrapped_handle));
46
47 // Write to wrapped/unwrapped FD.
48 ssize_t bytes_written =
49 write(unwrapped_handle, &write_buffer, sizeof(write_buffer));
50 ASSERT_EQ(sizeof(write_buffer), static_cast<size_t>(bytes_written));
51
52 // Read from other end of pipe.
53 ssize_t bytes_read = read(pipe_fds[0], &read_buffer, sizeof(read_buffer));
54 ASSERT_EQ(sizeof(read_buffer), static_cast<size_t>(bytes_read));
55
56 EXPECT_EQ(bytes_read, bytes_written);
57 EXPECT_EQ(write_buffer, read_buffer);
58
59 EXPECT_EQ(0, close(pipe_fds[0]));
60 EXPECT_EQ(0, close(unwrapped_handle));
61 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(wrapper));
62 }
63
64 } // namespace
65 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/platform/native/platform_handle_private.h ('k') | mojo/public/platform/native/platform_handle_private_thunks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698