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

Side by Side Diff: mojo/system/remote_message_pipe_posix_unittest.cc

Issue 137273003: Mojo: Rename PlatformChannelHandle to PlatformHandle, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased 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/system/raw_channel_win.cc ('k') | mojo/system/scoped_platform_handle.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 // TODO(vtl): The POSIX-specific bits have been factored out. Apply this test to 5 // TODO(vtl): The POSIX-specific bits have been factored out. Apply this test to
6 // non-POSIX once we have a non-POSIX implementation. 6 // non-POSIX once we have a non-POSIX implementation.
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "mojo/system/channel.h" 18 #include "mojo/system/channel.h"
19 #include "mojo/system/local_message_pipe_endpoint.h" 19 #include "mojo/system/local_message_pipe_endpoint.h"
20 #include "mojo/system/message_pipe.h" 20 #include "mojo/system/message_pipe.h"
21 #include "mojo/system/platform_channel.h"
22 #include "mojo/system/platform_channel_pair.h" 21 #include "mojo/system/platform_channel_pair.h"
23 #include "mojo/system/proxy_message_pipe_endpoint.h" 22 #include "mojo/system/proxy_message_pipe_endpoint.h"
23 #include "mojo/system/scoped_platform_handle.h"
24 #include "mojo/system/test_utils.h" 24 #include "mojo/system/test_utils.h"
25 #include "mojo/system/waiter.h" 25 #include "mojo/system/waiter.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 namespace mojo { 28 namespace mojo {
29 namespace system { 29 namespace system {
30 namespace { 30 namespace {
31 31
32 class RemoteMessagePipeTest : public testing::Test { 32 class RemoteMessagePipeTest : public testing::Test {
33 public: 33 public:
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 scoped_refptr<base::TaskRunner> io_thread_task_runner() { 87 scoped_refptr<base::TaskRunner> io_thread_task_runner() {
88 return io_thread_message_loop()->message_loop_proxy(); 88 return io_thread_message_loop()->message_loop_proxy();
89 } 89 }
90 90
91 private: 91 private:
92 void SetUpOnIOThread() { 92 void SetUpOnIOThread() {
93 CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop()); 93 CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop());
94 94
95 PlatformChannelPair channel_pair; 95 PlatformChannelPair channel_pair;
96 platform_channels_[0] = channel_pair.CreateServerChannel(); 96 platform_handles_[0] = channel_pair.PassServerHandle();
97 CHECK(platform_channels_[0].get()); 97 platform_handles_[1] = channel_pair.PassClientHandle();
98 CHECK(platform_channels_[0]->is_valid());
99 platform_channels_[1] = channel_pair.CreateClientChannel();
100 CHECK(platform_channels_[1].get());
101 CHECK(platform_channels_[1]->is_valid());
102 } 98 }
103 99
104 void CreateAndInitChannel(unsigned channel_index) { 100 void CreateAndInitChannel(unsigned channel_index) {
105 CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop()); 101 CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop());
106 CHECK(channel_index == 0 || channel_index == 1); 102 CHECK(channel_index == 0 || channel_index == 1);
107 CHECK(!channels_[channel_index].get()); 103 CHECK(!channels_[channel_index].get());
108 104
109 channels_[channel_index] = new Channel(); 105 channels_[channel_index] = new Channel();
110 CHECK(channels_[channel_index]->Init( 106 CHECK(channels_[channel_index]->Init(
111 platform_channels_[channel_index]->PassHandle())); 107 platform_handles_[channel_index].Pass()));
112 } 108 }
113 109
114 void ConnectMessagePipesOnIOThread(scoped_refptr<MessagePipe> mp_0, 110 void ConnectMessagePipesOnIOThread(scoped_refptr<MessagePipe> mp_0,
115 scoped_refptr<MessagePipe> mp_1) { 111 scoped_refptr<MessagePipe> mp_1) {
116 CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop()); 112 CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop());
117 113
118 if (!channels_[0].get()) 114 if (!channels_[0].get())
119 CreateAndInitChannel(0); 115 CreateAndInitChannel(0);
120 if (!channels_[1].get()) 116 if (!channels_[1].get())
121 CreateAndInitChannel(1); 117 CreateAndInitChannel(1);
(...skipping 27 matching lines...) Expand all
149 channels_[0]->Shutdown(); 145 channels_[0]->Shutdown();
150 channels_[0] = NULL; 146 channels_[0] = NULL;
151 } 147 }
152 if (channels_[1].get()) { 148 if (channels_[1].get()) {
153 channels_[1]->Shutdown(); 149 channels_[1]->Shutdown();
154 channels_[1] = NULL; 150 channels_[1] = NULL;
155 } 151 }
156 } 152 }
157 153
158 base::Thread io_thread_; 154 base::Thread io_thread_;
159 scoped_ptr<PlatformChannel> platform_channels_[2]; 155 ScopedPlatformHandle platform_handles_[2];
160 scoped_refptr<Channel> channels_[2]; 156 scoped_refptr<Channel> channels_[2];
161 157
162 DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeTest); 158 DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeTest);
163 }; 159 };
164 160
165 TEST_F(RemoteMessagePipeTest, Basic) { 161 TEST_F(RemoteMessagePipeTest, Basic) {
166 const char hello[] = "hello"; 162 const char hello[] = "hello";
167 const char world[] = "world!!!1!!!1!"; 163 const char world[] = "world!!!1!!!1!";
168 char buffer[100] = { 0 }; 164 char buffer[100] = { 0 };
169 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); 165 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 MOJO_READ_MESSAGE_FLAG_NONE)); 417 MOJO_READ_MESSAGE_FLAG_NONE));
422 EXPECT_EQ(sizeof(hello), static_cast<size_t>(buffer_size)); 418 EXPECT_EQ(sizeof(hello), static_cast<size_t>(buffer_size));
423 EXPECT_EQ(0, strcmp(buffer, hello)); 419 EXPECT_EQ(0, strcmp(buffer, hello));
424 420
425 // And MP 1, port 1. 421 // And MP 1, port 1.
426 mp_1->Close(1); 422 mp_1->Close(1);
427 } 423 }
428 } // namespace 424 } // namespace
429 } // namespace system 425 } // namespace system
430 } // namespace mojo 426 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/raw_channel_win.cc ('k') | mojo/system/scoped_platform_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698