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

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: snapshot 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 virtual void Frobinate(const Foo& foo, BazOptions baz, PortPtr port)
270 MOJO_OVERRIDE { 270 MOJO_OVERRIDE {
271 // Users code goes here to handle the incoming Frobinate message. 271 // Users code goes here to handle the incoming Frobinate message.
272 272
273 // We mainly check that we're given the expected arguments. 273 // We mainly check that we're given the expected arguments.
274 CheckFoo(foo); 274 CheckFoo(foo);
275 EXPECT_EQ(BAZ_EXTRA, baz); 275 EXPECT_EQ(BAZ_EXTRA, baz);
276 276
277 if (g_dump_message_as_text) { 277 if (g_dump_message_as_text) {
278 // Also dump the Foo structure and all of its members. 278 // Also dump the Foo structure and all of its members.
279 std::cout << "Frobinate:" << std::endl; 279 std::cout << "Frobinate:" << std::endl;
(...skipping 12 matching lines...) Expand all
292 292
293 if (g_dump_message_as_hex) { 293 if (g_dump_message_as_hex) {
294 DumpHex(reinterpret_cast<const uint8_t*>(message->data()), 294 DumpHex(reinterpret_cast<const uint8_t*>(message->data()),
295 message->data_num_bytes()); 295 message->data_num_bytes());
296 } 296 }
297 297
298 // In the receiving process, an implementation of ServiceStub is known to 298 // In the receiving process, an implementation of ServiceStub is known to
299 // the system. It receives the incoming message. 299 // the system. It receives the incoming message.
300 ServiceImpl impl; 300 ServiceImpl impl;
301 301
302 ServiceStub stub(&impl); 302 ServiceStub stub;
303 stub.set_sink(&impl);
303 return stub.Accept(message); 304 return stub.Accept(message);
304 } 305 }
305 306
306 virtual bool AcceptWithResponder(mojo::Message* message, 307 virtual bool AcceptWithResponder(mojo::Message* message,
307 mojo::MessageReceiver* responder) 308 mojo::MessageReceiver* responder)
308 MOJO_OVERRIDE { 309 MOJO_OVERRIDE {
309 return false; 310 return false;
310 } 311 }
311 }; 312 };
312 313
313 TEST(BindingsSampleTest, Basic) { 314 TEST(BindingsSampleTest, Basic) {
314 mojo::Environment env; 315 mojo::Environment env;
315 SimpleMessageReceiver receiver; 316 SimpleMessageReceiver receiver;
316 317
317 // User has a proxy to a Service somehow. 318 // User has a proxy to a Service somehow.
318 Service* service = new ServiceProxy(&receiver); 319 Service* service = new ServiceProxy(&receiver);
319 320
320 // User constructs a message to send. 321 // User constructs a message to send.
321 322
322 // Notice that it doesn't matter in what order the structs / arrays are 323 // 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 324 // allocated. Here, the various members of Foo are allocated before Foo is
324 // allocated. 325 // allocated.
325 326
326 mojo::AllocationScope scope; 327 mojo::AllocationScope scope;
327 328
328 Foo foo = MakeFoo(); 329 Foo foo = MakeFoo();
329 CheckFoo(foo); 330 CheckFoo(foo);
330 331
331 mojo::InterfacePipe<Port, mojo::AnyInterface> pipe; 332 PortPtr port;
332 service->Frobinate(foo, Service::BAZ_EXTRA, pipe.handle_to_self.Pass()); 333 service->Frobinate(foo, Service::BAZ_EXTRA, port.Pass());
333 } 334 }
334 335
335 TEST(BindingsSampleTest, DefaultValues) { 336 TEST(BindingsSampleTest, DefaultValues) {
336 mojo::Environment env; 337 mojo::Environment env;
337 SimpleMessageReceiver receiver; 338 SimpleMessageReceiver receiver;
338 mojo::AllocationScope scope; 339 mojo::AllocationScope scope;
339 340
340 Bar bar = Bar::Builder().Finish(); 341 Bar bar = Bar::Builder().Finish();
341 EXPECT_EQ(255, bar.alpha()); 342 EXPECT_EQ(255, bar.alpha());
342 343
(...skipping 24 matching lines...) Expand all
367 368
368 EXPECT_EQ(1u, full.shape_masks().size()); 369 EXPECT_EQ(1u, full.shape_masks().size());
369 EXPECT_EQ(1 << imported::SHAPE_RECTANGLE, full.shape_masks()[0]); 370 EXPECT_EQ(1 << imported::SHAPE_RECTANGLE, full.shape_masks()[0]);
370 371
371 EXPECT_EQ(imported::SHAPE_CIRCLE, full.thing().shape()); 372 EXPECT_EQ(imported::SHAPE_CIRCLE, full.thing().shape());
372 EXPECT_EQ(imported::COLOR_BLACK, full.thing().color()); 373 EXPECT_EQ(imported::COLOR_BLACK, full.thing().color());
373 } 374 }
374 375
375 } // namespace 376 } // namespace
376 } // namespace sample 377 } // namespace sample
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698