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 #include <utility> |
8 | 9 |
9 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" | 10 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace mojo { | 13 namespace mojo { |
13 | 14 |
14 template <> | 15 template <> |
15 struct TypeConverter<int32_t, sample::BarPtr> { | 16 struct TypeConverter<int32_t, sample::BarPtr> { |
16 static int32_t Convert(const sample::BarPtr& bar) { | 17 static int32_t Convert(const sample::BarPtr& bar) { |
17 return static_cast<int32_t>(bar->alpha) << 16 | | 18 return static_cast<int32_t>(bar->alpha) << 16 | |
(...skipping 25 matching lines...) Expand all Loading... |
43 | 44 |
44 mojo::Array<BarPtr> extra_bars(3); | 45 mojo::Array<BarPtr> extra_bars(3); |
45 for (size_t i = 0; i < extra_bars.size(); ++i) { | 46 for (size_t i = 0; i < extra_bars.size(); ++i) { |
46 Bar::Type type = i % 2 == 0 ? Bar::TYPE_VERTICAL : Bar::TYPE_HORIZONTAL; | 47 Bar::Type type = i % 2 == 0 ? Bar::TYPE_VERTICAL : Bar::TYPE_HORIZONTAL; |
47 BarPtr bar(Bar::New()); | 48 BarPtr bar(Bar::New()); |
48 uint8_t base = static_cast<uint8_t>(i * 100); | 49 uint8_t base = static_cast<uint8_t>(i * 100); |
49 bar->alpha = base; | 50 bar->alpha = base; |
50 bar->beta = base + 20; | 51 bar->beta = base + 20; |
51 bar->gamma = base + 40; | 52 bar->gamma = base + 40; |
52 bar->type = type; | 53 bar->type = type; |
53 extra_bars[i] = bar.Pass(); | 54 extra_bars[i] = std::move(bar); |
54 } | 55 } |
55 | 56 |
56 mojo::Array<uint8_t> data(10); | 57 mojo::Array<uint8_t> data(10); |
57 for (size_t i = 0; i < data.size(); ++i) | 58 for (size_t i = 0; i < data.size(); ++i) |
58 data[i] = static_cast<uint8_t>(data.size() - i); | 59 data[i] = static_cast<uint8_t>(data.size() - i); |
59 | 60 |
60 mojo::Array<mojo::ScopedDataPipeConsumerHandle> input_streams(2); | 61 mojo::Array<mojo::ScopedDataPipeConsumerHandle> input_streams(2); |
61 mojo::Array<mojo::ScopedDataPipeProducerHandle> output_streams(2); | 62 mojo::Array<mojo::ScopedDataPipeProducerHandle> output_streams(2); |
62 for (size_t i = 0; i < input_streams.size(); ++i) { | 63 for (size_t i = 0; i < input_streams.size(); ++i) { |
63 MojoCreateDataPipeOptions options; | 64 MojoCreateDataPipeOptions options; |
64 options.struct_size = sizeof(MojoCreateDataPipeOptions); | 65 options.struct_size = sizeof(MojoCreateDataPipeOptions); |
65 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | 66 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
66 options.element_num_bytes = 1; | 67 options.element_num_bytes = 1; |
67 options.capacity_num_bytes = 1024; | 68 options.capacity_num_bytes = 1024; |
68 mojo::ScopedDataPipeProducerHandle producer; | 69 mojo::ScopedDataPipeProducerHandle producer; |
69 mojo::ScopedDataPipeConsumerHandle consumer; | 70 mojo::ScopedDataPipeConsumerHandle consumer; |
70 mojo::CreateDataPipe(&options, &producer, &consumer); | 71 mojo::CreateDataPipe(&options, &producer, &consumer); |
71 input_streams[i] = consumer.Pass(); | 72 input_streams[i] = std::move(consumer); |
72 output_streams[i] = producer.Pass(); | 73 output_streams[i] = std::move(producer); |
73 } | 74 } |
74 | 75 |
75 mojo::Array<mojo::Array<bool>> array_of_array_of_bools(2); | 76 mojo::Array<mojo::Array<bool>> array_of_array_of_bools(2); |
76 for (size_t i = 0; i < 2; ++i) { | 77 for (size_t i = 0; i < 2; ++i) { |
77 mojo::Array<bool> array_of_bools(2); | 78 mojo::Array<bool> array_of_bools(2); |
78 for (size_t j = 0; j < 2; ++j) | 79 for (size_t j = 0; j < 2; ++j) |
79 array_of_bools[j] = j; | 80 array_of_bools[j] = j; |
80 array_of_array_of_bools[i] = array_of_bools.Pass(); | 81 array_of_array_of_bools[i] = std::move(array_of_bools); |
81 } | 82 } |
82 | 83 |
83 mojo::MessagePipe pipe; | 84 mojo::MessagePipe pipe; |
84 FooPtr foo(Foo::New()); | 85 FooPtr foo(Foo::New()); |
85 foo->name = name; | 86 foo->name = name; |
86 foo->x = 1; | 87 foo->x = 1; |
87 foo->y = 2; | 88 foo->y = 2; |
88 foo->a = false; | 89 foo->a = false; |
89 foo->b = true; | 90 foo->b = true; |
90 foo->c = false; | 91 foo->c = false; |
91 foo->bar = bar.Pass(); | 92 foo->bar = std::move(bar); |
92 foo->extra_bars = extra_bars.Pass(); | 93 foo->extra_bars = std::move(extra_bars); |
93 foo->data = data.Pass(); | 94 foo->data = std::move(data); |
94 foo->source = pipe.handle1.Pass(); | 95 foo->source = std::move(pipe.handle1); |
95 foo->input_streams = input_streams.Pass(); | 96 foo->input_streams = std::move(input_streams); |
96 foo->output_streams = output_streams.Pass(); | 97 foo->output_streams = std::move(output_streams); |
97 foo->array_of_array_of_bools = array_of_array_of_bools.Pass(); | 98 foo->array_of_array_of_bools = std::move(array_of_array_of_bools); |
98 | 99 |
99 return foo.Pass(); | 100 return foo; |
100 } | 101 } |
101 | 102 |
102 // Check that the given |Foo| is identical to the one made by |MakeFoo()|. | 103 // Check that the given |Foo| is identical to the one made by |MakeFoo()|. |
103 void CheckFoo(const Foo& foo) { | 104 void CheckFoo(const Foo& foo) { |
104 const std::string kName("foopy"); | 105 const std::string kName("foopy"); |
105 ASSERT_FALSE(foo.name.is_null()); | 106 ASSERT_FALSE(foo.name.is_null()); |
106 EXPECT_EQ(kName.size(), foo.name.size()); | 107 EXPECT_EQ(kName.size(), foo.name.size()); |
107 for (size_t i = 0; i < std::min(kName.size(), foo.name.size()); i++) { | 108 for (size_t i = 0; i < std::min(kName.size(), foo.name.size()); i++) { |
108 // Test both |operator[]| and |at|. | 109 // Test both |operator[]| and |at|. |
109 EXPECT_EQ(kName[i], foo.name.at(i)) << i; | 110 EXPECT_EQ(kName[i], foo.name.at(i)) << i; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 // User constructs a message to send. | 323 // User constructs a message to send. |
323 | 324 |
324 // Notice that it doesn't matter in what order the structs / arrays are | 325 // Notice that it doesn't matter in what order the structs / arrays are |
325 // allocated. Here, the various members of Foo are allocated before Foo is | 326 // allocated. Here, the various members of Foo are allocated before Foo is |
326 // allocated. | 327 // allocated. |
327 | 328 |
328 FooPtr foo = MakeFoo(); | 329 FooPtr foo = MakeFoo(); |
329 CheckFoo(*foo); | 330 CheckFoo(*foo); |
330 | 331 |
331 PortPtr port; | 332 PortPtr port; |
332 service->Frobinate(foo.Pass(), Service::BAZ_OPTIONS_EXTRA, port.Pass(), | 333 service->Frobinate(std::move(foo), Service::BAZ_OPTIONS_EXTRA, |
333 Service::FrobinateCallback()); | 334 std::move(port), Service::FrobinateCallback()); |
334 | 335 |
335 delete service; | 336 delete service; |
336 } | 337 } |
337 | 338 |
338 TEST_F(BindingsSampleTest, DefaultValues) { | 339 TEST_F(BindingsSampleTest, DefaultValues) { |
339 DefaultsTestPtr defaults(DefaultsTest::New()); | 340 DefaultsTestPtr defaults(DefaultsTest::New()); |
340 EXPECT_EQ(-12, defaults->a0); | 341 EXPECT_EQ(-12, defaults->a0); |
341 EXPECT_EQ(kTwelve, defaults->a1); | 342 EXPECT_EQ(kTwelve, defaults->a1); |
342 EXPECT_EQ(1234, defaults->a2); | 343 EXPECT_EQ(1234, defaults->a2); |
343 EXPECT_EQ(34567U, defaults->a3); | 344 EXPECT_EQ(34567U, defaults->a3); |
(...skipping 18 matching lines...) Expand all Loading... |
362 ASSERT_FALSE(defaults->a22.is_null()); | 363 ASSERT_FALSE(defaults->a22.is_null()); |
363 EXPECT_EQ(imported::SHAPE_RECTANGLE, defaults->a22->shape); | 364 EXPECT_EQ(imported::SHAPE_RECTANGLE, defaults->a22->shape); |
364 EXPECT_EQ(imported::COLOR_BLACK, defaults->a22->color); | 365 EXPECT_EQ(imported::COLOR_BLACK, defaults->a22->color); |
365 EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, defaults->a23); | 366 EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, defaults->a23); |
366 EXPECT_EQ(0x123456789, defaults->a24); | 367 EXPECT_EQ(0x123456789, defaults->a24); |
367 EXPECT_EQ(-0x123456789, defaults->a25); | 368 EXPECT_EQ(-0x123456789, defaults->a25); |
368 } | 369 } |
369 | 370 |
370 } // namespace | 371 } // namespace |
371 } // namespace sample | 372 } // namespace sample |
OLD | NEW |