OLD | NEW |
---|---|
(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 <string.h> | |
viettrungluu
2016/03/02 23:42:55
nit: I don't think you need this include anymore.
Forrest Reiling
2016/03/03 00:13:08
Done.
| |
9 #include <sys/types.h> | |
10 #include <unistd.h> | |
11 | |
12 #include "mojo/public/cpp/application/application_impl.h" | |
13 #include "mojo/public/cpp/application/application_test_base.h" | |
14 #include "mojo/public/cpp/environment/logging.h" | |
15 #include "mojo/public/cpp/system/macros.h" | |
16 | |
17 namespace mojo { | |
18 namespace { | |
19 | |
20 class PlatformHandlePrivateApplicationTest : public test::ApplicationTestBase { | |
21 public: | |
22 PlatformHandlePrivateApplicationTest() : ApplicationTestBase() {} | |
23 ~PlatformHandlePrivateApplicationTest() override {} | |
24 | |
25 private: | |
26 MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformHandlePrivateApplicationTest); | |
27 }; | |
28 | |
29 TEST_F(PlatformHandlePrivateApplicationTest, WrapAndUnwrapFileDescriptor) { | |
30 MojoPlatformHandle original_handle = -1; | |
31 MojoPlatformHandle unwrapped_handle = -1; | |
32 MojoHandle wrapper = MOJO_HANDLE_INVALID; | |
33 | |
34 int pipe_fds[2] = {-1, -1}; | |
35 | |
36 uint64_t write_buffer = 0xDEADBEEF; | |
37 uint64_t read_buffer = 0; | |
38 | |
39 ASSERT_EQ(pipe(pipe_fds), 0); | |
viettrungluu
2016/03/02 23:42:55
nit: ASSERT_EQ and EXPECT_EQ are both "backwards":
Forrest Reiling
2016/03/03 00:13:08
ewwww
| |
40 | |
41 // Pass second FD through wrapper. | |
42 original_handle = pipe_fds[1]; | |
43 | |
44 EXPECT_EQ(MOJO_RESULT_OK, | |
45 MojoCreatePlatformHandleWrapper(original_handle, &wrapper)); | |
46 EXPECT_EQ(MOJO_RESULT_OK, | |
47 MojoExtractPlatformHandle(wrapper, &unwrapped_handle)); | |
48 | |
49 // Write to wrapped/unwrapped FD. | |
50 ssize_t bytes_written = | |
51 write(unwrapped_handle, &write_buffer, sizeof(write_buffer)); | |
52 ASSERT_EQ(sizeof(write_buffer), static_cast<size_t>(bytes_written)); | |
53 | |
54 // Read from other end of pipe. | |
55 ssize_t bytes_read = read(pipe_fds[0], &read_buffer, sizeof(read_buffer)); | |
56 ASSERT_EQ(sizeof(read_buffer), static_cast<size_t>(bytes_read)); | |
57 | |
58 EXPECT_EQ(bytes_read, bytes_written); | |
59 EXPECT_EQ(write_buffer, read_buffer); | |
60 | |
61 EXPECT_EQ(0, close(pipe_fds[0])); | |
62 EXPECT_EQ(0, close(unwrapped_handle)); | |
63 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(wrapper)); | |
64 } | |
65 | |
66 } // namespace | |
67 } // namespace mojo | |
OLD | NEW |