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