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

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

Issue 1682113003: Mojo C++ bindings: Generate InterfaceHandle<> instead of InterfacePtr<>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebase ontop of master, address trung's comments Created 4 years, 10 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
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 #include <utility>
8 9
9 #include "mojo/public/cpp/environment/environment.h" 10 #include "mojo/public/cpp/environment/environment.h"
10 #include "mojo/public/cpp/system/macros.h" 11 #include "mojo/public/cpp/system/macros.h"
11 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" 12 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace mojo { 15 namespace mojo {
15 16
16 template <> 17 template <>
17 struct TypeConverter<int32_t, sample::BarPtr> { 18 struct TypeConverter<int32_t, sample::BarPtr> {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 std::cout << " "; 252 std::cout << " ";
252 if (i % 8 == 7) 253 if (i % 8 == 7)
253 std::cout << " "; 254 std::cout << " ";
254 } 255 }
255 } 256 }
256 257
257 class ServiceImpl : public Service { 258 class ServiceImpl : public Service {
258 public: 259 public:
259 void Frobinate(FooPtr foo, 260 void Frobinate(FooPtr foo,
260 BazOptions baz, 261 BazOptions baz,
261 PortPtr port, 262 mojo::InterfaceHandle<Port> port,
262 const Service::FrobinateCallback& callback) override { 263 const Service::FrobinateCallback& callback) override {
263 // Users code goes here to handle the incoming Frobinate message. 264 // Users code goes here to handle the incoming Frobinate message.
264 265
265 // We mainly check that we're given the expected arguments. 266 // We mainly check that we're given the expected arguments.
266 EXPECT_FALSE(foo.is_null()); 267 EXPECT_FALSE(foo.is_null());
267 if (!foo.is_null()) 268 if (!foo.is_null())
268 CheckFoo(*foo); 269 CheckFoo(*foo);
269 EXPECT_EQ(Service::BazOptions::EXTRA, baz); 270 EXPECT_EQ(Service::BazOptions::EXTRA, baz);
270 271
271 if (g_dump_message_as_text) { 272 if (g_dump_message_as_text) {
272 // Also dump the Foo structure and all of its members. 273 // Also dump the Foo structure and all of its members.
273 std::cout << "Frobinate:" << std::endl; 274 std::cout << "Frobinate:" << std::endl;
274 int depth = 1; 275 int depth = 1;
275 Print(depth, "foo", foo); 276 Print(depth, "foo", foo);
276 Print(depth, "baz", static_cast<int32_t>(baz)); 277 Print(depth, "baz", static_cast<int32_t>(baz));
277 Print(depth, "port", port.get()); 278 auto portptr = PortPtr::Create(std::move(port));
279 Print(depth, "port", portptr.get());
278 } 280 }
279 callback.Run(5); 281 callback.Run(5);
280 } 282 }
281 283
282 void GetPort(mojo::InterfaceRequest<Port> port_request) override {} 284 void GetPort(mojo::InterfaceRequest<Port> port_request) override {}
283 }; 285 };
284 286
285 class ServiceProxyImpl : public ServiceProxy { 287 class ServiceProxyImpl : public ServiceProxy {
286 public: 288 public:
287 explicit ServiceProxyImpl(mojo::MessageReceiverWithResponder* receiver) 289 explicit ServiceProxyImpl(mojo::MessageReceiverWithResponder* receiver)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // User constructs a message to send. 335 // User constructs a message to send.
334 336
335 // Notice that it doesn't matter in what order the structs / arrays are 337 // Notice that it doesn't matter in what order the structs / arrays are
336 // allocated. Here, the various members of Foo are allocated before Foo is 338 // allocated. Here, the various members of Foo are allocated before Foo is
337 // allocated. 339 // allocated.
338 340
339 FooPtr foo = MakeFoo(); 341 FooPtr foo = MakeFoo();
340 CheckFoo(*foo); 342 CheckFoo(*foo);
341 343
342 PortPtr port; 344 PortPtr port;
343 service->Frobinate(foo.Pass(), Service::BazOptions::EXTRA, port.Pass(), 345 service->Frobinate(foo.Pass(), Service::BazOptions::EXTRA, std::move(port),
344 Service::FrobinateCallback()); 346 Service::FrobinateCallback());
345 347
346 delete service; 348 delete service;
347 } 349 }
348 350
349 TEST_F(BindingsSampleTest, DefaultValues) { 351 TEST_F(BindingsSampleTest, DefaultValues) {
350 DefaultsTestPtr defaults(DefaultsTest::New()); 352 DefaultsTestPtr defaults(DefaultsTest::New());
351 EXPECT_EQ(-12, defaults->a0); 353 EXPECT_EQ(-12, defaults->a0);
352 EXPECT_EQ(kTwelve, defaults->a1); 354 EXPECT_EQ(kTwelve, defaults->a1);
353 EXPECT_EQ(1234, defaults->a2); 355 EXPECT_EQ(1234, defaults->a2);
(...skipping 19 matching lines...) Expand all
373 ASSERT_FALSE(defaults->a22.is_null()); 375 ASSERT_FALSE(defaults->a22.is_null());
374 EXPECT_EQ(imported::Shape::RECTANGLE, defaults->a22->shape); 376 EXPECT_EQ(imported::Shape::RECTANGLE, defaults->a22->shape);
375 EXPECT_EQ(imported::Color::BLACK, defaults->a22->color); 377 EXPECT_EQ(imported::Color::BLACK, defaults->a22->color);
376 EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, defaults->a23); 378 EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, defaults->a23);
377 EXPECT_EQ(0x123456789, defaults->a24); 379 EXPECT_EQ(0x123456789, defaults->a24);
378 EXPECT_EQ(-0x123456789, defaults->a25); 380 EXPECT_EQ(-0x123456789, defaults->a25);
379 } 381 }
380 382
381 } // namespace 383 } // namespace
382 } // namespace sample 384 } // namespace sample
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc ('k') | mojo/public/cpp/bindings/tests/union_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698