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

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

Issue 190943003: Mojo: MultiprocessTestBase -> MultiprocessTestHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 9 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_helper.cc ('k') | mojo/mojo.gyp » ('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_helper.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/common/test/test_utils.h" 9 #include "mojo/common/test/test_utils.h"
10 #include "mojo/system/embedder/scoped_platform_handle.h" 10 #include "mojo/system/embedder/scoped_platform_handle.h"
11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 #if defined(OS_POSIX) 13 #if defined(OS_POSIX)
13 #include <fcntl.h> 14 #include <fcntl.h>
14 #endif 15 #endif
15 16
16 #if defined(OS_WIN) 17 #if defined(OS_WIN)
17 #include "base/win/windows_version.h" 18 #include "base/win/windows_version.h"
18 #endif 19 #endif
19 20
20 namespace mojo { 21 namespace mojo {
(...skipping 27 matching lines...) Expand all
48 BlockingWrite(handle, &c, 1, &bytes_written); 49 BlockingWrite(handle, &c, 1, &bytes_written);
49 return bytes_written == 1; 50 return bytes_written == 1;
50 } 51 }
51 52
52 bool ReadByte(const embedder::PlatformHandle& handle, char* c) { 53 bool ReadByte(const embedder::PlatformHandle& handle, char* c) {
53 size_t bytes_read = 0; 54 size_t bytes_read = 0;
54 BlockingRead(handle, c, 1, &bytes_read); 55 BlockingRead(handle, c, 1, &bytes_read);
55 return bytes_read == 1; 56 return bytes_read == 1;
56 } 57 }
57 58
58 typedef MultiprocessTestBase MultiprocessTestBaseTest; 59 typedef testing::Test MultiprocessTestHelperTest;
59 60
60 TEST_F(MultiprocessTestBaseTest, RunChild) { 61 TEST_F(MultiprocessTestHelperTest, RunChild) {
61 if (SkipTest()) 62 if (SkipTest())
62 return; 63 return;
63 64
64 EXPECT_TRUE(server_platform_handle.is_valid()); 65 MultiprocessTestHelper helper;
66 EXPECT_TRUE(helper.server_platform_handle.is_valid());
65 67
66 StartChild("RunChild"); 68 helper.StartChild("RunChild");
67 EXPECT_EQ(123, WaitForChildShutdown()); 69 EXPECT_EQ(123, helper.WaitForChildShutdown());
68 } 70 }
69 71
70 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(RunChild) { 72 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(RunChild) {
71 CHECK(MultiprocessTestBaseTest::client_platform_handle.is_valid()); 73 CHECK(MultiprocessTestHelper::client_platform_handle.is_valid());
72 return 123; 74 return 123;
73 } 75 }
74 76
75 TEST_F(MultiprocessTestBaseTest, TestChildMainNotFound) { 77 TEST_F(MultiprocessTestHelperTest, TestChildMainNotFound) {
76 if (SkipTest()) 78 if (SkipTest())
77 return; 79 return;
78 80
79 StartChild("NoSuchTestChildMain"); 81 MultiprocessTestHelper helper;
80 int result = WaitForChildShutdown(); 82 helper.StartChild("NoSuchTestChildMain");
83 int result = helper.WaitForChildShutdown();
81 EXPECT_FALSE(result >= 0 && result <= 127); 84 EXPECT_FALSE(result >= 0 && result <= 127);
82 } 85 }
83 86
84 TEST_F(MultiprocessTestBaseTest, PassedChannel) { 87 TEST_F(MultiprocessTestHelperTest, PassedChannel) {
85 if (SkipTest()) 88 if (SkipTest())
86 return; 89 return;
87 90
88 EXPECT_TRUE(server_platform_handle.is_valid()); 91 MultiprocessTestHelper helper;
89 StartChild("PassedChannel"); 92 EXPECT_TRUE(helper.server_platform_handle.is_valid());
93 helper.StartChild("PassedChannel");
90 94
91 // Take ownership of the handle. 95 // Take ownership of the handle.
92 embedder::ScopedPlatformHandle handle = server_platform_handle.Pass(); 96 embedder::ScopedPlatformHandle handle = helper.server_platform_handle.Pass();
93 97
94 // The handle should be non-blocking. 98 // The handle should be non-blocking.
95 EXPECT_TRUE(IsNonBlocking(handle.get())); 99 EXPECT_TRUE(IsNonBlocking(handle.get()));
96 100
97 // Write a byte. 101 // Write a byte.
98 const char c = 'X'; 102 const char c = 'X';
99 EXPECT_TRUE(WriteByte(handle.get(), c)); 103 EXPECT_TRUE(WriteByte(handle.get(), c));
100 104
101 // It'll echo it back to us, incremented. 105 // It'll echo it back to us, incremented.
102 char d = 0; 106 char d = 0;
103 EXPECT_TRUE(ReadByte(handle.get(), &d)); 107 EXPECT_TRUE(ReadByte(handle.get(), &d));
104 EXPECT_EQ(c + 1, d); 108 EXPECT_EQ(c + 1, d);
105 109
106 // And return it, incremented again. 110 // And return it, incremented again.
107 EXPECT_EQ(c + 2, WaitForChildShutdown()); 111 EXPECT_EQ(c + 2, helper.WaitForChildShutdown());
108 } 112 }
109 113
110 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PassedChannel) { 114 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PassedChannel) {
111 CHECK(MultiprocessTestBaseTest::client_platform_handle.is_valid()); 115 CHECK(MultiprocessTestHelper::client_platform_handle.is_valid());
112 116
113 // Take ownership of the handle. 117 // Take ownership of the handle.
114 embedder::ScopedPlatformHandle handle = 118 embedder::ScopedPlatformHandle handle =
115 MultiprocessTestBaseTest::client_platform_handle.Pass(); 119 MultiprocessTestHelper::client_platform_handle.Pass();
116 120
117 // The handle should be non-blocking. 121 // The handle should be non-blocking.
118 EXPECT_TRUE(IsNonBlocking(handle.get())); 122 EXPECT_TRUE(IsNonBlocking(handle.get()));
119 123
120 // Read a byte. 124 // Read a byte.
121 char c = 0; 125 char c = 0;
122 EXPECT_TRUE(ReadByte(handle.get(), &c)); 126 EXPECT_TRUE(ReadByte(handle.get(), &c));
123 127
124 // Write it back, incremented. 128 // Write it back, incremented.
125 c++; 129 c++;
126 EXPECT_TRUE(WriteByte(handle.get(), c)); 130 EXPECT_TRUE(WriteByte(handle.get(), c));
127 131
128 // And return it, incremented again. 132 // And return it, incremented again.
129 c++; 133 c++;
130 return static_cast<int>(c); 134 return static_cast<int>(c);
131 } 135 }
132 136
133 } // namespace 137 } // namespace
134 } // namespace test 138 } // namespace test
135 } // namespace mojo 139 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/common/test/multiprocess_test_helper.cc ('k') | mojo/mojo.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698