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

Side by Side Diff: mojo/common/test/multiprocess_test_base_unittest.cc

Issue 137063010: Mojo: Move platform handle/channel stuff in system to embedder namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/common/test/multiprocess_test_base.cc ('k') | mojo/system/channel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/common/test/multiprocess_test_base.h" 5 #include "mojo/common/test/multiprocess_test_base.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "mojo/system/scoped_platform_handle.h" 9 #include "mojo/system/scoped_platform_handle.h"
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 // POSIX-specific test of passed handle ---------------------------------------- 46 // POSIX-specific test of passed handle ----------------------------------------
47 47
48 #if defined(OS_POSIX) 48 #if defined(OS_POSIX)
49 TEST_F(MultiprocessTestBaseTest, PassedChannelPosix) { 49 TEST_F(MultiprocessTestBaseTest, PassedChannelPosix) {
50 EXPECT_TRUE(server_platform_handle.is_valid()); 50 EXPECT_TRUE(server_platform_handle.is_valid());
51 StartChild("PassedChannelPosix"); 51 StartChild("PassedChannelPosix");
52 52
53 // Take ownership of the FD. 53 // Take ownership of the FD.
54 system::ScopedPlatformHandle handle = server_platform_handle.Pass(); 54 embedder::ScopedPlatformHandle handle = server_platform_handle.Pass();
55 int fd = handle.get().fd; 55 int fd = handle.get().fd;
56 56
57 // The FD should be non-blocking. Check this. 57 // The FD should be non-blocking. Check this.
58 CHECK((fcntl(fd, F_GETFL) & O_NONBLOCK)); 58 CHECK((fcntl(fd, F_GETFL) & O_NONBLOCK));
59 // We're lazy. Set it to block. 59 // We're lazy. Set it to block.
60 PCHECK(fcntl(fd, F_SETFL, 0) == 0); 60 PCHECK(fcntl(fd, F_SETFL, 0) == 0);
61 61
62 // Write a byte. 62 // Write a byte.
63 const char c = 'X'; 63 const char c = 'X';
64 ssize_t write_size = HANDLE_EINTR(write(fd, &c, 1)); 64 ssize_t write_size = HANDLE_EINTR(write(fd, &c, 1));
65 EXPECT_EQ(1, write_size); 65 EXPECT_EQ(1, write_size);
66 66
67 // It'll echo it back to us, incremented. 67 // It'll echo it back to us, incremented.
68 char d = 0; 68 char d = 0;
69 ssize_t read_size = HANDLE_EINTR(read(fd, &d, 1)); 69 ssize_t read_size = HANDLE_EINTR(read(fd, &d, 1));
70 EXPECT_EQ(1, read_size); 70 EXPECT_EQ(1, read_size);
71 EXPECT_EQ(c + 1, d); 71 EXPECT_EQ(c + 1, d);
72 72
73 // And return it, incremented again. 73 // And return it, incremented again.
74 EXPECT_EQ(c + 2, WaitForChildShutdown()); 74 EXPECT_EQ(c + 2, WaitForChildShutdown());
75 } 75 }
76 76
77 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PassedChannelPosix) { 77 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PassedChannelPosix) {
78 CHECK(MultiprocessTestBaseTest::client_platform_handle.is_valid()); 78 CHECK(MultiprocessTestBaseTest::client_platform_handle.is_valid());
79 79
80 // Take ownership of the FD. 80 // Take ownership of the FD.
81 system::ScopedPlatformHandle handle = 81 embedder::ScopedPlatformHandle handle =
82 MultiprocessTestBaseTest::client_platform_handle.Pass(); 82 MultiprocessTestBaseTest::client_platform_handle.Pass();
83 int fd = handle.get().fd; 83 int fd = handle.get().fd;
84 84
85 // The FD should still be non-blocking. Check this. 85 // The FD should still be non-blocking. Check this.
86 CHECK((fcntl(fd, F_GETFL) & O_NONBLOCK)); 86 CHECK((fcntl(fd, F_GETFL) & O_NONBLOCK));
87 // We're lazy. Set it to block. 87 // We're lazy. Set it to block.
88 PCHECK(fcntl(fd, F_SETFL, 0) == 0); 88 PCHECK(fcntl(fd, F_SETFL, 0) == 0);
89 89
90 // Read a byte. 90 // Read a byte.
91 char c = 0; 91 char c = 0;
92 ssize_t read_size = HANDLE_EINTR(read(fd, &c, 1)); 92 ssize_t read_size = HANDLE_EINTR(read(fd, &c, 1));
93 CHECK_EQ(read_size, 1); 93 CHECK_EQ(read_size, 1);
94 94
95 // Write it back, incremented. 95 // Write it back, incremented.
96 c++; 96 c++;
97 ssize_t write_size = HANDLE_EINTR(write(fd, &c, 1)); 97 ssize_t write_size = HANDLE_EINTR(write(fd, &c, 1));
98 CHECK_EQ(write_size, 1); 98 CHECK_EQ(write_size, 1);
99 99
100 // And return it, incremented again. 100 // And return it, incremented again.
101 c++; 101 c++;
102 return static_cast<int>(c); 102 return static_cast<int>(c);
103 } 103 }
104 #endif // defined(OS_POSIX) 104 #endif // defined(OS_POSIX)
105 105
106 } // namespace 106 } // namespace
107 } // namespace mojo 107 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/common/test/multiprocess_test_base.cc ('k') | mojo/system/channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698