| 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 20 matching lines...) Expand all Loading... |
| 31 // Set this variable to true to print the message in hex. | 31 // Set this variable to true to print the message in hex. |
| 32 bool g_dump_message_as_hex = false; | 32 bool g_dump_message_as_hex = false; |
| 33 | 33 |
| 34 // Set this variable to true to print the message in human readable form. | 34 // Set this variable to true to print the message in human readable form. |
| 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 std::string name("foopy"); | 39 std::string name("foopy"); |
| 40 | 40 |
| 41 BarPtr bar(Bar::New()); | 41 BarPtr bar(Bar::New(20, 40, 60, Bar::Type::VERTICAL)); |
| 42 bar->alpha = 20; | |
| 43 bar->beta = 40; | |
| 44 bar->gamma = 60; | |
| 45 bar->type = Bar::Type::VERTICAL; | |
| 46 | 42 |
| 47 std::vector<BarPtr> extra_bars(3); | 43 std::vector<BarPtr> extra_bars(3); |
| 48 for (size_t i = 0; i < extra_bars.size(); ++i) { | 44 for (size_t i = 0; i < extra_bars.size(); ++i) { |
| 49 Bar::Type type = i % 2 == 0 ? Bar::Type::VERTICAL : Bar::Type::HORIZONTAL; | 45 Bar::Type type = i % 2 == 0 ? Bar::Type::VERTICAL : Bar::Type::HORIZONTAL; |
| 50 BarPtr bar(Bar::New()); | |
| 51 uint8_t base = static_cast<uint8_t>(i * 100); | 46 uint8_t base = static_cast<uint8_t>(i * 100); |
| 52 bar->alpha = base; | 47 extra_bars[i] = Bar::New(base, base + 20, base + 40, type); |
| 53 bar->beta = base + 20; | |
| 54 bar->gamma = base + 40; | |
| 55 bar->type = type; | |
| 56 extra_bars[i] = std::move(bar); | |
| 57 } | 48 } |
| 58 | 49 |
| 59 std::vector<uint8_t> data(10); | 50 std::vector<uint8_t> data(10); |
| 60 for (size_t i = 0; i < data.size(); ++i) | 51 for (size_t i = 0; i < data.size(); ++i) |
| 61 data[i] = static_cast<uint8_t>(data.size() - i); | 52 data[i] = static_cast<uint8_t>(data.size() - i); |
| 62 | 53 |
| 63 std::vector<mojo::ScopedDataPipeConsumerHandle> input_streams(2); | 54 std::vector<mojo::ScopedDataPipeConsumerHandle> input_streams(2); |
| 64 std::vector<mojo::ScopedDataPipeProducerHandle> output_streams(2); | 55 std::vector<mojo::ScopedDataPipeProducerHandle> output_streams(2); |
| 65 for (size_t i = 0; i < input_streams.size(); ++i) { | 56 for (size_t i = 0; i < input_streams.size(); ++i) { |
| 66 MojoCreateDataPipeOptions options; | 57 MojoCreateDataPipeOptions options; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 77 | 68 |
| 78 std::vector<std::vector<bool>> array_of_array_of_bools(2); | 69 std::vector<std::vector<bool>> array_of_array_of_bools(2); |
| 79 for (size_t i = 0; i < 2; ++i) { | 70 for (size_t i = 0; i < 2; ++i) { |
| 80 std::vector<bool> array_of_bools(2); | 71 std::vector<bool> array_of_bools(2); |
| 81 for (size_t j = 0; j < 2; ++j) | 72 for (size_t j = 0; j < 2; ++j) |
| 82 array_of_bools[j] = j; | 73 array_of_bools[j] = j; |
| 83 array_of_array_of_bools[i] = std::move(array_of_bools); | 74 array_of_array_of_bools[i] = std::move(array_of_bools); |
| 84 } | 75 } |
| 85 | 76 |
| 86 mojo::MessagePipe pipe; | 77 mojo::MessagePipe pipe; |
| 87 FooPtr foo(Foo::New()); | 78 return Foo::New(name, 1, 2, false, true, false, std::move(bar), |
| 88 foo->name = name; | 79 std::move(extra_bars), std::move(data), |
| 89 foo->x = 1; | 80 std::move(pipe.handle1), std::move(input_streams), |
| 90 foo->y = 2; | 81 std::move(output_streams), std::move(array_of_array_of_bools), |
| 91 foo->a = false; | 82 base::nullopt, base::nullopt); |
| 92 foo->b = true; | |
| 93 foo->c = false; | |
| 94 foo->bar = std::move(bar); | |
| 95 foo->extra_bars = std::move(extra_bars); | |
| 96 foo->data = std::move(data); | |
| 97 foo->source = std::move(pipe.handle1); | |
| 98 foo->input_streams = std::move(input_streams); | |
| 99 foo->output_streams = std::move(output_streams); | |
| 100 foo->array_of_array_of_bools = std::move(array_of_array_of_bools); | |
| 101 | |
| 102 return foo; | |
| 103 } | 83 } |
| 104 | 84 |
| 105 // Check that the given |Foo| is identical to the one made by |MakeFoo()|. | 85 // Check that the given |Foo| is identical to the one made by |MakeFoo()|. |
| 106 void CheckFoo(const Foo& foo) { | 86 void CheckFoo(const Foo& foo) { |
| 107 const std::string kName("foopy"); | 87 const std::string kName("foopy"); |
| 108 EXPECT_EQ(kName.size(), foo.name.size()); | 88 EXPECT_EQ(kName.size(), foo.name.size()); |
| 109 for (size_t i = 0; i < std::min(kName.size(), foo.name.size()); i++) { | 89 for (size_t i = 0; i < std::min(kName.size(), foo.name.size()); i++) { |
| 110 // Test both |operator[]| and |at|. | 90 // Test both |operator[]| and |at|. |
| 111 EXPECT_EQ(kName[i], foo.name.at(i)) << i; | 91 EXPECT_EQ(kName[i], foo.name.at(i)) << i; |
| 112 EXPECT_EQ(kName[i], foo.name[i]) << i; | 92 EXPECT_EQ(kName[i], foo.name[i]) << i; |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 ASSERT_FALSE(defaults->a22.is_null()); | 352 ASSERT_FALSE(defaults->a22.is_null()); |
| 373 EXPECT_EQ(imported::Shape::RECTANGLE, defaults->a22->shape); | 353 EXPECT_EQ(imported::Shape::RECTANGLE, defaults->a22->shape); |
| 374 EXPECT_EQ(imported::Color::BLACK, defaults->a22->color); | 354 EXPECT_EQ(imported::Color::BLACK, defaults->a22->color); |
| 375 EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, defaults->a23); | 355 EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, defaults->a23); |
| 376 EXPECT_EQ(0x123456789, defaults->a24); | 356 EXPECT_EQ(0x123456789, defaults->a24); |
| 377 EXPECT_EQ(-0x123456789, defaults->a25); | 357 EXPECT_EQ(-0x123456789, defaults->a25); |
| 378 } | 358 } |
| 379 | 359 |
| 380 } // namespace | 360 } // namespace |
| 381 } // namespace sample | 361 } // namespace sample |
| OLD | NEW |