OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <ostream> | 8 #include <ostream> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 24 matching lines...) Expand all Loading... |
35 bool g_dump_message_as_text = false; | 35 bool g_dump_message_as_text = false; |
36 | 36 |
37 // Make a sample |Foo|. | 37 // Make a sample |Foo|. |
38 FooPtr MakeFoo() { | 38 FooPtr MakeFoo() { |
39 mojo::String name("foopy"); | 39 mojo::String name("foopy"); |
40 | 40 |
41 BarPtr bar(Bar::New()); | 41 BarPtr bar(Bar::New()); |
42 bar->alpha = 20; | 42 bar->alpha = 20; |
43 bar->beta = 40; | 43 bar->beta = 40; |
44 bar->gamma = 60; | 44 bar->gamma = 60; |
45 bar->type = Bar::TYPE_VERTICAL; | 45 bar->type = Bar::Type::VERTICAL; |
46 | 46 |
47 mojo::Array<BarPtr> extra_bars(3); | 47 mojo::Array<BarPtr> extra_bars(3); |
48 for (size_t i = 0; i < extra_bars.size(); ++i) { | 48 for (size_t i = 0; i < extra_bars.size(); ++i) { |
49 Bar::Type type = i % 2 == 0 ? Bar::TYPE_VERTICAL : Bar::TYPE_HORIZONTAL; | 49 Bar::Type type = i % 2 == 0 ? Bar::Type::VERTICAL : Bar::Type::HORIZONTAL; |
50 BarPtr bar(Bar::New()); | 50 BarPtr bar(Bar::New()); |
51 uint8_t base = static_cast<uint8_t>(i * 100); | 51 uint8_t base = static_cast<uint8_t>(i * 100); |
52 bar->alpha = base; | 52 bar->alpha = base; |
53 bar->beta = base + 20; | 53 bar->beta = base + 20; |
54 bar->gamma = base + 40; | 54 bar->gamma = base + 40; |
55 bar->type = type; | 55 bar->type = type; |
56 extra_bars[i] = std::move(bar); | 56 extra_bars[i] = std::move(bar); |
57 } | 57 } |
58 | 58 |
59 mojo::Array<uint8_t> data(10); | 59 mojo::Array<uint8_t> data(10); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 EXPECT_EQ(1, foo.x); | 117 EXPECT_EQ(1, foo.x); |
118 EXPECT_EQ(2, foo.y); | 118 EXPECT_EQ(2, foo.y); |
119 EXPECT_FALSE(foo.a); | 119 EXPECT_FALSE(foo.a); |
120 EXPECT_TRUE(foo.b); | 120 EXPECT_TRUE(foo.b); |
121 EXPECT_FALSE(foo.c); | 121 EXPECT_FALSE(foo.c); |
122 | 122 |
123 EXPECT_EQ(20, foo.bar->alpha); | 123 EXPECT_EQ(20, foo.bar->alpha); |
124 EXPECT_EQ(40, foo.bar->beta); | 124 EXPECT_EQ(40, foo.bar->beta); |
125 EXPECT_EQ(60, foo.bar->gamma); | 125 EXPECT_EQ(60, foo.bar->gamma); |
126 EXPECT_EQ(Bar::TYPE_VERTICAL, foo.bar->type); | 126 EXPECT_EQ(Bar::Type::VERTICAL, foo.bar->type); |
127 | 127 |
128 EXPECT_EQ(3u, foo.extra_bars.size()); | 128 EXPECT_EQ(3u, foo.extra_bars.size()); |
129 for (size_t i = 0; i < foo.extra_bars.size(); i++) { | 129 for (size_t i = 0; i < foo.extra_bars.size(); i++) { |
130 uint8_t base = static_cast<uint8_t>(i * 100); | 130 uint8_t base = static_cast<uint8_t>(i * 100); |
131 Bar::Type type = i % 2 == 0 ? Bar::TYPE_VERTICAL : Bar::TYPE_HORIZONTAL; | 131 Bar::Type type = i % 2 == 0 ? Bar::Type::VERTICAL : Bar::Type::HORIZONTAL; |
132 EXPECT_EQ(base, foo.extra_bars[i]->alpha) << i; | 132 EXPECT_EQ(base, foo.extra_bars[i]->alpha) << i; |
133 EXPECT_EQ(base + 20, foo.extra_bars[i]->beta) << i; | 133 EXPECT_EQ(base + 20, foo.extra_bars[i]->beta) << i; |
134 EXPECT_EQ(base + 40, foo.extra_bars[i]->gamma) << i; | 134 EXPECT_EQ(base + 40, foo.extra_bars[i]->gamma) << i; |
135 EXPECT_EQ(type, foo.extra_bars[i]->type) << i; | 135 EXPECT_EQ(type, foo.extra_bars[i]->type) << i; |
136 } | 136 } |
137 | 137 |
138 EXPECT_EQ(10u, foo.data.size()); | 138 EXPECT_EQ(10u, foo.data.size()); |
139 for (size_t i = 0; i < foo.data.size(); ++i) { | 139 for (size_t i = 0; i < foo.data.size(); ++i) { |
140 EXPECT_EQ(static_cast<uint8_t>(foo.data.size() - i), foo.data[i]) << i; | 140 EXPECT_EQ(static_cast<uint8_t>(foo.data.size() - i), foo.data[i]) << i; |
141 } | 141 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 void Frobinate(FooPtr foo, | 260 void Frobinate(FooPtr foo, |
261 BazOptions baz, | 261 BazOptions baz, |
262 PortPtr port, | 262 PortPtr port, |
263 const Service::FrobinateCallback& callback) override { | 263 const Service::FrobinateCallback& callback) override { |
264 // Users code goes here to handle the incoming Frobinate message. | 264 // Users code goes here to handle the incoming Frobinate message. |
265 | 265 |
266 // We mainly check that we're given the expected arguments. | 266 // We mainly check that we're given the expected arguments. |
267 EXPECT_FALSE(foo.is_null()); | 267 EXPECT_FALSE(foo.is_null()); |
268 if (!foo.is_null()) | 268 if (!foo.is_null()) |
269 CheckFoo(*foo); | 269 CheckFoo(*foo); |
270 EXPECT_EQ(BAZ_OPTIONS_EXTRA, baz); | 270 EXPECT_EQ(BazOptions::EXTRA, baz); |
271 | 271 |
272 if (g_dump_message_as_text) { | 272 if (g_dump_message_as_text) { |
273 // Also dump the Foo structure and all of its members. | 273 // Also dump the Foo structure and all of its members. |
274 std::cout << "Frobinate:" << std::endl; | 274 std::cout << "Frobinate:" << std::endl; |
275 int depth = 1; | 275 int depth = 1; |
276 Print(depth, "foo", foo); | 276 Print(depth, "foo", foo); |
277 Print(depth, "baz", baz); | 277 Print(depth, "baz", static_cast<int32_t>(baz)); |
278 Print(depth, "port", port.get()); | 278 Print(depth, "port", port.get()); |
279 } | 279 } |
280 callback.Run(5); | 280 callback.Run(5); |
281 } | 281 } |
282 | 282 |
283 void GetPort(mojo::InterfaceRequest<Port> port_request) override {} | 283 void GetPort(mojo::InterfaceRequest<Port> port_request) override {} |
284 }; | 284 }; |
285 | 285 |
286 class ServiceProxyImpl : public ServiceProxy { | 286 class ServiceProxyImpl : public ServiceProxy { |
287 public: | 287 public: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // User constructs a message to send. | 325 // User constructs a message to send. |
326 | 326 |
327 // Notice that it doesn't matter in what order the structs / arrays are | 327 // Notice that it doesn't matter in what order the structs / arrays are |
328 // allocated. Here, the various members of Foo are allocated before Foo is | 328 // allocated. Here, the various members of Foo are allocated before Foo is |
329 // allocated. | 329 // allocated. |
330 | 330 |
331 FooPtr foo = MakeFoo(); | 331 FooPtr foo = MakeFoo(); |
332 CheckFoo(*foo); | 332 CheckFoo(*foo); |
333 | 333 |
334 PortPtr port; | 334 PortPtr port; |
335 service->Frobinate(std::move(foo), Service::BAZ_OPTIONS_EXTRA, | 335 service->Frobinate(std::move(foo), Service::BazOptions::EXTRA, |
336 std::move(port), Service::FrobinateCallback()); | 336 std::move(port), Service::FrobinateCallback()); |
337 | 337 |
338 delete service; | 338 delete service; |
339 } | 339 } |
340 | 340 |
341 TEST_F(BindingsSampleTest, DefaultValues) { | 341 TEST_F(BindingsSampleTest, DefaultValues) { |
342 DefaultsTestPtr defaults(DefaultsTest::New()); | 342 DefaultsTestPtr defaults(DefaultsTest::New()); |
343 EXPECT_EQ(-12, defaults->a0); | 343 EXPECT_EQ(-12, defaults->a0); |
344 EXPECT_EQ(kTwelve, defaults->a1); | 344 EXPECT_EQ(kTwelve, defaults->a1); |
345 EXPECT_EQ(1234, defaults->a2); | 345 EXPECT_EQ(1234, defaults->a2); |
346 EXPECT_EQ(34567U, defaults->a3); | 346 EXPECT_EQ(34567U, defaults->a3); |
347 EXPECT_EQ(123456, defaults->a4); | 347 EXPECT_EQ(123456, defaults->a4); |
348 EXPECT_EQ(3456789012U, defaults->a5); | 348 EXPECT_EQ(3456789012U, defaults->a5); |
349 EXPECT_EQ(-111111111111LL, defaults->a6); | 349 EXPECT_EQ(-111111111111LL, defaults->a6); |
350 EXPECT_EQ(9999999999999999999ULL, defaults->a7); | 350 EXPECT_EQ(9999999999999999999ULL, defaults->a7); |
351 EXPECT_EQ(0x12345, defaults->a8); | 351 EXPECT_EQ(0x12345, defaults->a8); |
352 EXPECT_EQ(-0x12345, defaults->a9); | 352 EXPECT_EQ(-0x12345, defaults->a9); |
353 EXPECT_EQ(1234, defaults->a10); | 353 EXPECT_EQ(1234, defaults->a10); |
354 EXPECT_TRUE(defaults->a11); | 354 EXPECT_TRUE(defaults->a11); |
355 EXPECT_FALSE(defaults->a12); | 355 EXPECT_FALSE(defaults->a12); |
356 EXPECT_FLOAT_EQ(123.25f, defaults->a13); | 356 EXPECT_FLOAT_EQ(123.25f, defaults->a13); |
357 EXPECT_DOUBLE_EQ(1234567890.123, defaults->a14); | 357 EXPECT_DOUBLE_EQ(1234567890.123, defaults->a14); |
358 EXPECT_DOUBLE_EQ(1E10, defaults->a15); | 358 EXPECT_DOUBLE_EQ(1E10, defaults->a15); |
359 EXPECT_DOUBLE_EQ(-1.2E+20, defaults->a16); | 359 EXPECT_DOUBLE_EQ(-1.2E+20, defaults->a16); |
360 EXPECT_DOUBLE_EQ(1.23E-20, defaults->a17); | 360 EXPECT_DOUBLE_EQ(1.23E-20, defaults->a17); |
361 EXPECT_TRUE(defaults->a18.is_null()); | 361 EXPECT_TRUE(defaults->a18.is_null()); |
362 EXPECT_TRUE(defaults->a19.is_null()); | 362 EXPECT_TRUE(defaults->a19.is_null()); |
363 EXPECT_EQ(Bar::TYPE_BOTH, defaults->a20); | 363 EXPECT_EQ(Bar::Type::BOTH, defaults->a20); |
364 EXPECT_TRUE(defaults->a21.is_null()); | 364 EXPECT_TRUE(defaults->a21.is_null()); |
365 ASSERT_FALSE(defaults->a22.is_null()); | 365 ASSERT_FALSE(defaults->a22.is_null()); |
366 EXPECT_EQ(imported::SHAPE_RECTANGLE, defaults->a22->shape); | 366 EXPECT_EQ(imported::Shape::RECTANGLE, defaults->a22->shape); |
367 EXPECT_EQ(imported::COLOR_BLACK, defaults->a22->color); | 367 EXPECT_EQ(imported::Color::BLACK, defaults->a22->color); |
368 EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, defaults->a23); | 368 EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, defaults->a23); |
369 EXPECT_EQ(0x123456789, defaults->a24); | 369 EXPECT_EQ(0x123456789, defaults->a24); |
370 EXPECT_EQ(-0x123456789, defaults->a25); | 370 EXPECT_EQ(-0x123456789, defaults->a25); |
371 } | 371 } |
372 | 372 |
373 } // namespace | 373 } // namespace |
374 } // namespace sample | 374 } // namespace sample |
OLD | NEW |