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

Side by Side Diff: mojo/public/cpp/bindings/tests/handle_passing_unittest.cc

Issue 289063015: Mojo: Remove SetClient from generated interfaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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
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/public/cpp/bindings/allocation_scope.h" 5 #include "mojo/public/cpp/bindings/allocation_scope.h"
6 #include "mojo/public/cpp/environment/environment.h" 6 #include "mojo/public/cpp/environment/environment.h"
7 #include "mojo/public/cpp/test_support/test_utils.h" 7 #include "mojo/public/cpp/test_support/test_utils.h"
8 #include "mojo/public/cpp/utility/run_loop.h" 8 #include "mojo/public/cpp/utility/run_loop.h"
9 #include "mojo/public/interfaces/bindings/tests/sample_factory.mojom.h" 9 #include "mojo/public/interfaces/bindings/tests/sample_factory.mojom.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 RunLoop loop_; 134 RunLoop loop_;
135 }; 135 };
136 136
137 TEST_F(HandlePassingTest, Basic) { 137 TEST_F(HandlePassingTest, Basic) {
138 sample::FactoryPtr factory; 138 sample::FactoryPtr factory;
139 BindToProxy(new SampleFactoryImpl(), &factory); 139 BindToProxy(new SampleFactoryImpl(), &factory);
140 140
141 SampleFactoryClientImpl factory_client; 141 SampleFactoryClientImpl factory_client;
142 factory_client.set_expected_text_reply(kText1); 142 factory_client.set_expected_text_reply(kText1);
143 143
144 factory->SetClient(&factory_client); 144 factory.set_client(&factory_client);
145 145
146 ScopedMessagePipeHandle pipe0, pipe1; 146 ScopedMessagePipeHandle pipe0, pipe1;
147 CreateMessagePipe(&pipe0, &pipe1); 147 CreateMessagePipe(&pipe0, &pipe1);
148 148
149 EXPECT_TRUE(WriteTextMessage(pipe1.get(), kText1)); 149 EXPECT_TRUE(WriteTextMessage(pipe1.get(), kText1));
150 150
151 ScopedMessagePipeHandle pipe2, pipe3; 151 ScopedMessagePipeHandle pipe2, pipe3;
152 CreateMessagePipe(&pipe2, &pipe3); 152 CreateMessagePipe(&pipe2, &pipe3);
153 153
154 EXPECT_TRUE(WriteTextMessage(pipe3.get(), kText2)); 154 EXPECT_TRUE(WriteTextMessage(pipe3.get(), kText2));
(...skipping 11 matching lines...) Expand all
166 PumpMessages(); 166 PumpMessages();
167 167
168 EXPECT_TRUE(factory_client.got_response()); 168 EXPECT_TRUE(factory_client.got_response());
169 } 169 }
170 170
171 TEST_F(HandlePassingTest, PassInvalid) { 171 TEST_F(HandlePassingTest, PassInvalid) {
172 sample::FactoryPtr factory; 172 sample::FactoryPtr factory;
173 BindToProxy(new SampleFactoryImpl(), &factory); 173 BindToProxy(new SampleFactoryImpl(), &factory);
174 174
175 SampleFactoryClientImpl factory_client; 175 SampleFactoryClientImpl factory_client;
176 factory->SetClient(&factory_client); 176 factory.set_client(&factory_client);
177 177
178 { 178 {
179 AllocationScope scope; 179 AllocationScope scope;
180 sample::Request::Builder request; 180 sample::Request::Builder request;
181 request.set_x(1); 181 request.set_x(1);
182 factory->DoStuff(request.Finish(), ScopedMessagePipeHandle().Pass()); 182 factory->DoStuff(request.Finish(), ScopedMessagePipeHandle().Pass());
183 } 183 }
184 184
185 EXPECT_FALSE(factory_client.got_response()); 185 EXPECT_FALSE(factory_client.got_response());
186 186
187 PumpMessages(); 187 PumpMessages();
188 188
189 EXPECT_TRUE(factory_client.got_response()); 189 EXPECT_TRUE(factory_client.got_response());
190 } 190 }
191 191
192 // Verifies DataPipeConsumer can be passed and read from. 192 // Verifies DataPipeConsumer can be passed and read from.
193 TEST_F(HandlePassingTest, DataPipe) { 193 TEST_F(HandlePassingTest, DataPipe) {
194 sample::FactoryPtr factory; 194 sample::FactoryPtr factory;
195 BindToProxy(new SampleFactoryImpl(), &factory); 195 BindToProxy(new SampleFactoryImpl(), &factory);
196 196
197 SampleFactoryClientImpl factory_client; 197 SampleFactoryClientImpl factory_client;
198 factory->SetClient(&factory_client); 198 factory.set_client(&factory_client);
199 199
200 // Writes a string to a data pipe and passes the data pipe (consumer) to the 200 // Writes a string to a data pipe and passes the data pipe (consumer) to the
201 // factory. 201 // factory.
202 ScopedDataPipeProducerHandle producer_handle; 202 ScopedDataPipeProducerHandle producer_handle;
203 ScopedDataPipeConsumerHandle consumer_handle; 203 ScopedDataPipeConsumerHandle consumer_handle;
204 MojoCreateDataPipeOptions options = { 204 MojoCreateDataPipeOptions options = {
205 sizeof(MojoCreateDataPipeOptions), 205 sizeof(MojoCreateDataPipeOptions),
206 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, 206 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
207 1, 207 1,
208 1024}; 208 1024};
(...skipping 17 matching lines...) Expand all
226 PumpMessages(); 226 PumpMessages();
227 227
228 EXPECT_TRUE(factory_client.got_response()); 228 EXPECT_TRUE(factory_client.got_response());
229 } 229 }
230 230
231 TEST_F(HandlePassingTest, PipesAreClosed) { 231 TEST_F(HandlePassingTest, PipesAreClosed) {
232 sample::FactoryPtr factory; 232 sample::FactoryPtr factory;
233 BindToProxy(new SampleFactoryImpl(), &factory); 233 BindToProxy(new SampleFactoryImpl(), &factory);
234 234
235 SampleFactoryClientImpl factory_client; 235 SampleFactoryClientImpl factory_client;
236 factory->SetClient(&factory_client); 236 factory.set_client(&factory_client);
237 237
238 MessagePipe extra_pipe; 238 MessagePipe extra_pipe;
239 239
240 MojoHandle handle0_value = extra_pipe.handle0.get().value(); 240 MojoHandle handle0_value = extra_pipe.handle0.get().value();
241 MojoHandle handle1_value = extra_pipe.handle1.get().value(); 241 MojoHandle handle1_value = extra_pipe.handle1.get().value();
242 242
243 { 243 {
244 AllocationScope scope; 244 AllocationScope scope;
245 245
246 Array<MessagePipeHandle>::Builder pipes(2); 246 Array<MessagePipeHandle>::Builder pipes(2);
(...skipping 13 matching lines...) Expand all
260 } 260 }
261 261
262 // We expect the pipes to have been closed. 262 // We expect the pipes to have been closed.
263 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(handle0_value)); 263 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(handle0_value));
264 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(handle1_value)); 264 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(handle1_value));
265 } 265 }
266 266
267 } // namespace 267 } // namespace
268 } // namespace test 268 } // namespace test
269 } // namespace mojo 269 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/no_interface.h ('k') | mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698