| 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 | |
| 8 #include <algorithm> | 7 #include <algorithm> |
| 9 #include <ostream> | 8 #include <ostream> |
| 10 #include <string> | 9 #include <string> |
| 10 #include <utility> |
| 11 | 11 |
| 12 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" | 12 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace mojo { | 15 namespace mojo { |
| 16 | 16 |
| 17 template <> | 17 template <> |
| 18 struct TypeConverter<int32_t, sample::BarPtr> { | 18 struct TypeConverter<int32_t, sample::BarPtr> { |
| 19 static int32_t Convert(const sample::BarPtr& bar) { | 19 static int32_t Convert(const sample::BarPtr& bar) { |
| 20 return static_cast<int32_t>(bar->alpha) << 16 | | 20 return static_cast<int32_t>(bar->alpha) << 16 | |
| (...skipping 25 matching lines...) Expand all Loading... |
| 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] = bar.Pass(); | 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); |
| 60 for (size_t i = 0; i < data.size(); ++i) | 60 for (size_t i = 0; i < data.size(); ++i) |
| 61 data[i] = static_cast<uint8_t>(data.size() - i); | 61 data[i] = static_cast<uint8_t>(data.size() - i); |
| 62 | 62 |
| 63 mojo::Array<mojo::ScopedDataPipeConsumerHandle> input_streams(2); | 63 mojo::Array<mojo::ScopedDataPipeConsumerHandle> input_streams(2); |
| 64 mojo::Array<mojo::ScopedDataPipeProducerHandle> output_streams(2); | 64 mojo::Array<mojo::ScopedDataPipeProducerHandle> output_streams(2); |
| 65 for (size_t i = 0; i < input_streams.size(); ++i) { | 65 for (size_t i = 0; i < input_streams.size(); ++i) { |
| 66 MojoCreateDataPipeOptions options; | 66 MojoCreateDataPipeOptions options; |
| 67 options.struct_size = sizeof(MojoCreateDataPipeOptions); | 67 options.struct_size = sizeof(MojoCreateDataPipeOptions); |
| 68 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | 68 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
| 69 options.element_num_bytes = 1; | 69 options.element_num_bytes = 1; |
| 70 options.capacity_num_bytes = 1024; | 70 options.capacity_num_bytes = 1024; |
| 71 mojo::ScopedDataPipeProducerHandle producer; | 71 mojo::ScopedDataPipeProducerHandle producer; |
| 72 mojo::ScopedDataPipeConsumerHandle consumer; | 72 mojo::ScopedDataPipeConsumerHandle consumer; |
| 73 mojo::CreateDataPipe(&options, &producer, &consumer); | 73 mojo::CreateDataPipe(&options, &producer, &consumer); |
| 74 input_streams[i] = consumer.Pass(); | 74 input_streams[i] = std::move(consumer); |
| 75 output_streams[i] = producer.Pass(); | 75 output_streams[i] = std::move(producer); |
| 76 } | 76 } |
| 77 | 77 |
| 78 mojo::Array<mojo::Array<bool>> array_of_array_of_bools(2); | 78 mojo::Array<mojo::Array<bool>> array_of_array_of_bools(2); |
| 79 for (size_t i = 0; i < 2; ++i) { | 79 for (size_t i = 0; i < 2; ++i) { |
| 80 mojo::Array<bool> array_of_bools(2); | 80 mojo::Array<bool> array_of_bools(2); |
| 81 for (size_t j = 0; j < 2; ++j) | 81 for (size_t j = 0; j < 2; ++j) |
| 82 array_of_bools[j] = j; | 82 array_of_bools[j] = j; |
| 83 array_of_array_of_bools[i] = array_of_bools.Pass(); | 83 array_of_array_of_bools[i] = std::move(array_of_bools); |
| 84 } | 84 } |
| 85 | 85 |
| 86 mojo::MessagePipe pipe; | 86 mojo::MessagePipe pipe; |
| 87 FooPtr foo(Foo::New()); | 87 FooPtr foo(Foo::New()); |
| 88 foo->name = name; | 88 foo->name = name; |
| 89 foo->x = 1; | 89 foo->x = 1; |
| 90 foo->y = 2; | 90 foo->y = 2; |
| 91 foo->a = false; | 91 foo->a = false; |
| 92 foo->b = true; | 92 foo->b = true; |
| 93 foo->c = false; | 93 foo->c = false; |
| 94 foo->bar = bar.Pass(); | 94 foo->bar = std::move(bar); |
| 95 foo->extra_bars = extra_bars.Pass(); | 95 foo->extra_bars = std::move(extra_bars); |
| 96 foo->data = data.Pass(); | 96 foo->data = std::move(data); |
| 97 foo->source = pipe.handle1.Pass(); | 97 foo->source = std::move(pipe.handle1); |
| 98 foo->input_streams = input_streams.Pass(); | 98 foo->input_streams = std::move(input_streams); |
| 99 foo->output_streams = output_streams.Pass(); | 99 foo->output_streams = std::move(output_streams); |
| 100 foo->array_of_array_of_bools = array_of_array_of_bools.Pass(); | 100 foo->array_of_array_of_bools = std::move(array_of_array_of_bools); |
| 101 | 101 |
| 102 return foo.Pass(); | 102 return foo; |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Check that the given |Foo| is identical to the one made by |MakeFoo()|. | 105 // Check that the given |Foo| is identical to the one made by |MakeFoo()|. |
| 106 void CheckFoo(const Foo& foo) { | 106 void CheckFoo(const Foo& foo) { |
| 107 const std::string kName("foopy"); | 107 const std::string kName("foopy"); |
| 108 ASSERT_FALSE(foo.name.is_null()); | 108 ASSERT_FALSE(foo.name.is_null()); |
| 109 EXPECT_EQ(kName.size(), foo.name.size()); | 109 EXPECT_EQ(kName.size(), foo.name.size()); |
| 110 for (size_t i = 0; i < std::min(kName.size(), foo.name.size()); i++) { | 110 for (size_t i = 0; i < std::min(kName.size(), foo.name.size()); i++) { |
| 111 // Test both |operator[]| and |at|. | 111 // Test both |operator[]| and |at|. |
| 112 EXPECT_EQ(kName[i], foo.name.at(i)) << i; | 112 EXPECT_EQ(kName[i], foo.name.at(i)) << i; |
| (...skipping 212 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(foo.Pass(), Service::BAZ_OPTIONS_EXTRA, port.Pass(), | 335 service->Frobinate(std::move(foo), Service::BAZ_OPTIONS_EXTRA, |
| 336 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); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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 |