OLD | NEW |
---|---|
(Empty) | |
1 // 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.
| |
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/cpp/application/application_impl.h" | |
6 #include "mojo/public/cpp/application/application_test_base.h" | |
7 #include "mojo/public/cpp/environment/logging.h" | |
8 #include "mojo/public/cpp/system/macros.h" | |
9 #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.
| |
10 | |
11 namespace mojo { | |
12 namespace { | |
13 | |
14 // Exemplifies ApplicationTestBase's application testing pattern. | |
15 class PlatformHandleApplicationTest : public test::ApplicationTestBase { | |
16 public: | |
17 PlatformHandleApplicationTest() : ApplicationTestBase() {} | |
18 ~PlatformHandleApplicationTest() override {} | |
19 | |
20 private: | |
21 MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformHandleApplicationTest); | |
22 }; | |
23 | |
24 TEST_F(PlatformHandleApplicationTest, WrapAndUnwrapFileDescriptor) { | |
25 MojoPlatformHandle original_handle; | |
26 MojoPlatformHandle unwrapped_handle; | |
27 MojoHandle wrapper; | |
28 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.
| |
29 | |
30 int posix_result; | |
viettrungluu
2016/02/18 01:10:07
"
Forrest Reiling
2016/02/23 23:48:44
Done.
| |
31 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.
| |
32 | |
33 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.
| |
34 uint64_t read_buffer = 0; | |
35 | |
36 posix_result = pipe(pipe_fds); | |
37 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.
| |
38 | |
39 /*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.
| |
40 original_handle = pipe_fds[1]; | |
41 | |
42 mojo_result = MojoCreatePlatformHandleWrapper(original_handle, &wrapper); | |
43 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.
| |
44 | |
45 mojo_result = MojoExtractPlatformHandle(wrapper, &unwrapped_handle); | |
viettrungluu
2016/02/18 01:10:07
"
Forrest Reiling
2016/02/23 23:48:44
Done.
| |
46 MOJO_CHECK(mojo_result == MOJO_RESULT_OK) | |
47 << "Failed to extract platform handle"; | |
48 | |
49 /*write to wrapped/unwrapped fd*/ | |
50 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.
| |
51 write(unwrapped_handle, &write_buffer, sizeof(write_buffer)); | |
52 MOJO_CHECK(bytes_written >= 0) | |
53 << "Failed to write to wrapped/unwrapped handle: " << strerror(errno); | |
54 | |
55 /*read from other end of pipe*/ | |
56 ssize_t bytes_read = read(pipe_fds[0], &read_buffer, sizeof(read_buffer)); | |
57 MOJO_CHECK(bytes_read >= 0) << "Failed to read to read from original pipe: " | |
58 << strerror(errno); | |
59 | |
60 MOJO_CHECK(bytes_read == bytes_written) | |
61 << "Read a different number of bytes from pipe than were written to pipe"; | |
62 EXPECT_EQ(write_buffer, read_buffer); | |
63 | |
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
| |
64 close(pipe_fds[0]); | |
65 close(unwrapped_handle); | |
66 } | |
67 | |
68 } // namespace | |
69 } // namespace mojo | |
OLD | NEW |