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

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

Issue 265793015: Mojo: Replace RemotePtr with InterfacePtr and InterfaceImpl (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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <algorithm> 5 #include <algorithm>
6 #include <ostream> 6 #include <ostream>
7 #include <string> 7 #include <string>
8 8
9 #include "mojo/public/cpp/bindings/allocation_scope.h" 9 #include "mojo/public/cpp/bindings/allocation_scope.h"
10 #include "mojo/public/cpp/environment/environment.h" 10 #include "mojo/public/cpp/environment/environment.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 259
260 if (i % 2 == 1) 260 if (i % 2 == 1)
261 std::cout << " "; 261 std::cout << " ";
262 if (i % 8 == 7) 262 if (i % 8 == 7)
263 std::cout << " "; 263 std::cout << " ";
264 } 264 }
265 } 265 }
266 266
267 class ServiceImpl : public Service { 267 class ServiceImpl : public Service {
268 public: 268 public:
269 virtual void Frobinate(const Foo& foo, BazOptions baz, ScopedPortHandle port) 269 ServiceImpl() : client_(NULL) {
270 }
271
272 virtual void SetClient(ServiceClient* client) MOJO_OVERRIDE {
273 client_ = client;
274 }
275
276 virtual void Frobinate(const Foo& foo, BazOptions baz, PortPtr port)
270 MOJO_OVERRIDE { 277 MOJO_OVERRIDE {
271 // Users code goes here to handle the incoming Frobinate message. 278 // Users code goes here to handle the incoming Frobinate message.
272 279
273 // We mainly check that we're given the expected arguments. 280 // We mainly check that we're given the expected arguments.
274 CheckFoo(foo); 281 CheckFoo(foo);
275 EXPECT_EQ(BAZ_EXTRA, baz); 282 EXPECT_EQ(BAZ_EXTRA, baz);
276 283
277 if (g_dump_message_as_text) { 284 if (g_dump_message_as_text) {
278 // Also dump the Foo structure and all of its members. 285 // Also dump the Foo structure and all of its members.
279 std::cout << "Frobinate:" << std::endl; 286 std::cout << "Frobinate:" << std::endl;
280 int depth = 1; 287 int depth = 1;
281 Print(depth, "foo", foo); 288 Print(depth, "foo", foo);
282 Print(depth, "baz", baz); 289 Print(depth, "baz", baz);
283 Print(depth, "port", port.get()); 290 Print(depth, "port", port.get());
284 } 291 }
285 } 292 }
293
294 private:
295 ServiceClient* client_;
296 };
297
298 class ServiceProxyImpl : public ServiceProxy {
299 public:
300 explicit ServiceProxyImpl(mojo::MessageReceiver* receiver)
301 : ServiceProxy(receiver) {
302 }
303
304 virtual void SetClient(ServiceClient* client) MOJO_OVERRIDE {
305 assert(false);
306 }
286 }; 307 };
287 308
288 class SimpleMessageReceiver : public mojo::MessageReceiver { 309 class SimpleMessageReceiver : public mojo::MessageReceiver {
289 public: 310 public:
290 virtual bool Accept(mojo::Message* message) MOJO_OVERRIDE { 311 virtual bool Accept(mojo::Message* message) MOJO_OVERRIDE {
291 // Imagine some IPC happened here. 312 // Imagine some IPC happened here.
292 313
293 if (g_dump_message_as_hex) { 314 if (g_dump_message_as_hex) {
294 DumpHex(reinterpret_cast<const uint8_t*>(message->data()), 315 DumpHex(reinterpret_cast<const uint8_t*>(message->data()),
295 message->data_num_bytes()); 316 message->data_num_bytes());
296 } 317 }
297 318
298 // In the receiving process, an implementation of ServiceStub is known to 319 // In the receiving process, an implementation of ServiceStub is known to
299 // the system. It receives the incoming message. 320 // the system. It receives the incoming message.
300 ServiceImpl impl; 321 ServiceImpl impl;
301 322
302 ServiceStub stub(&impl); 323 ServiceStub stub;
324 stub.set_sink(&impl);
303 return stub.Accept(message); 325 return stub.Accept(message);
304 } 326 }
305 327
306 virtual bool AcceptWithResponder(mojo::Message* message, 328 virtual bool AcceptWithResponder(mojo::Message* message,
307 mojo::MessageReceiver* responder) 329 mojo::MessageReceiver* responder)
308 MOJO_OVERRIDE { 330 MOJO_OVERRIDE {
309 return false; 331 return false;
310 } 332 }
311 }; 333 };
312 334
313 TEST(BindingsSampleTest, Basic) { 335 TEST(BindingsSampleTest, Basic) {
314 mojo::Environment env; 336 mojo::Environment env;
315 SimpleMessageReceiver receiver; 337 SimpleMessageReceiver receiver;
316 338
317 // User has a proxy to a Service somehow. 339 // User has a proxy to a Service somehow.
318 Service* service = new ServiceProxy(&receiver); 340 Service* service = new ServiceProxyImpl(&receiver);
319 341
320 // User constructs a message to send. 342 // User constructs a message to send.
321 343
322 // Notice that it doesn't matter in what order the structs / arrays are 344 // Notice that it doesn't matter in what order the structs / arrays are
323 // allocated. Here, the various members of Foo are allocated before Foo is 345 // allocated. Here, the various members of Foo are allocated before Foo is
324 // allocated. 346 // allocated.
325 347
326 mojo::AllocationScope scope; 348 mojo::AllocationScope scope;
327 349
328 Foo foo = MakeFoo(); 350 Foo foo = MakeFoo();
329 CheckFoo(foo); 351 CheckFoo(foo);
330 352
331 mojo::InterfacePipe<Port, mojo::AnyInterface> pipe; 353 PortPtr port;
332 service->Frobinate(foo, Service::BAZ_EXTRA, pipe.handle_to_self.Pass()); 354 service->Frobinate(foo, Service::BAZ_EXTRA, port.Pass());
333 } 355 }
334 356
335 TEST(BindingsSampleTest, DefaultValues) { 357 TEST(BindingsSampleTest, DefaultValues) {
336 mojo::Environment env; 358 mojo::Environment env;
337 SimpleMessageReceiver receiver; 359 SimpleMessageReceiver receiver;
338 mojo::AllocationScope scope; 360 mojo::AllocationScope scope;
339 361
340 Bar bar = Bar::Builder().Finish(); 362 Bar bar = Bar::Builder().Finish();
341 EXPECT_EQ(255, bar.alpha()); 363 EXPECT_EQ(255, bar.alpha());
342 364
(...skipping 24 matching lines...) Expand all
367 389
368 EXPECT_EQ(1u, full.shape_masks().size()); 390 EXPECT_EQ(1u, full.shape_masks().size());
369 EXPECT_EQ(1 << imported::SHAPE_RECTANGLE, full.shape_masks()[0]); 391 EXPECT_EQ(1 << imported::SHAPE_RECTANGLE, full.shape_masks()[0]);
370 392
371 EXPECT_EQ(imported::SHAPE_CIRCLE, full.thing().shape()); 393 EXPECT_EQ(imported::SHAPE_CIRCLE, full.thing().shape());
372 EXPECT_EQ(imported::COLOR_BLACK, full.thing().color()); 394 EXPECT_EQ(imported::COLOR_BLACK, full.thing().color());
373 } 395 }
374 396
375 } // namespace 397 } // namespace
376 } // namespace sample 398 } // namespace sample
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698