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/bindings/allocation_scope.h" | 9 #include "mojo/public/cpp/bindings/allocation_scope.h" |
10 #include "mojo/public/cpp/environment/environment.h" | 10 #include "mojo/public/cpp/environment/environment.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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] = consumer.Pass(); |
75 output_streams[i] = producer.Pass(); | 75 output_streams[i] = producer.Pass(); |
76 } | 76 } |
77 | 77 |
| 78 mojo::Array<mojo::Array<bool> >::Builder array_of_array_of_bools(2); |
| 79 for (size_t i = 0; i < 2; ++i) { |
| 80 mojo::Array<bool>::Builder array_of_bools(2); |
| 81 for (size_t j = 0; j < 2; ++j) { |
| 82 array_of_bools[j] = j; |
| 83 } |
| 84 array_of_array_of_bools[i] = array_of_bools.Finish(); |
| 85 } |
| 86 |
78 mojo::ScopedMessagePipeHandle pipe0, pipe1; | 87 mojo::ScopedMessagePipeHandle pipe0, pipe1; |
79 mojo::CreateMessagePipe(&pipe0, &pipe1); | 88 mojo::CreateMessagePipe(&pipe0, &pipe1); |
80 | 89 |
81 Foo::Builder foo; | 90 Foo::Builder foo; |
82 foo.set_name(name); | 91 foo.set_name(name); |
83 foo.set_x(1); | 92 foo.set_x(1); |
84 foo.set_y(2); | 93 foo.set_y(2); |
85 foo.set_a(false); | 94 foo.set_a(false); |
86 foo.set_b(true); | 95 foo.set_b(true); |
87 foo.set_c(false); | 96 foo.set_c(false); |
88 foo.set_bar(bar.Finish()); | 97 foo.set_bar(bar.Finish()); |
89 foo.set_extra_bars(extra_bars.Finish()); | 98 foo.set_extra_bars(extra_bars.Finish()); |
90 foo.set_data(data.Finish()); | 99 foo.set_data(data.Finish()); |
91 foo.set_source(pipe1.Pass()); | 100 foo.set_source(pipe1.Pass()); |
92 foo.set_input_streams(input_streams.Finish()); | 101 foo.set_input_streams(input_streams.Finish()); |
93 foo.set_output_streams(output_streams.Finish()); | 102 foo.set_output_streams(output_streams.Finish()); |
| 103 foo.set_array_of_array_of_bools(array_of_array_of_bools.Finish()); |
94 | 104 |
95 return foo.Finish(); | 105 return foo.Finish(); |
96 } | 106 } |
97 | 107 |
98 // Check that the given |Foo| is identical to the one made by |MakeFoo()|. | 108 // Check that the given |Foo| is identical to the one made by |MakeFoo()|. |
99 void CheckFoo(const Foo& foo) { | 109 void CheckFoo(const Foo& foo) { |
100 const std::string kName("foopy"); | 110 const std::string kName("foopy"); |
101 ASSERT_FALSE(foo.name().is_null()); | 111 ASSERT_FALSE(foo.name().is_null()); |
102 EXPECT_EQ(kName.size(), foo.name().size()); | 112 EXPECT_EQ(kName.size(), foo.name().size()); |
103 for (size_t i = 0; i < std::min(kName.size(), foo.name().size()); i++) { | 113 for (size_t i = 0; i < std::min(kName.size(), foo.name().size()); i++) { |
(...skipping 27 matching lines...) Expand all Loading... |
131 EXPECT_EQ(10u, foo.data().size()); | 141 EXPECT_EQ(10u, foo.data().size()); |
132 for (size_t i = 0; i < foo.data().size(); ++i) { | 142 for (size_t i = 0; i < foo.data().size(); ++i) { |
133 EXPECT_EQ(static_cast<uint8_t>(foo.data().size() - i), foo.data()[i]) << i; | 143 EXPECT_EQ(static_cast<uint8_t>(foo.data().size() - i), foo.data()[i]) << i; |
134 } | 144 } |
135 | 145 |
136 EXPECT_FALSE(foo.input_streams().is_null()); | 146 EXPECT_FALSE(foo.input_streams().is_null()); |
137 EXPECT_EQ(2u, foo.input_streams().size()); | 147 EXPECT_EQ(2u, foo.input_streams().size()); |
138 | 148 |
139 EXPECT_FALSE(foo.output_streams().is_null()); | 149 EXPECT_FALSE(foo.output_streams().is_null()); |
140 EXPECT_EQ(2u, foo.output_streams().size()); | 150 EXPECT_EQ(2u, foo.output_streams().size()); |
| 151 |
| 152 EXPECT_EQ(2u, foo.array_of_array_of_bools().size()); |
| 153 for (size_t i = 0; i < foo.array_of_array_of_bools().size(); ++i) { |
| 154 EXPECT_EQ(2u, foo.array_of_array_of_bools()[i].size()); |
| 155 for (size_t j = 0; j < foo.array_of_array_of_bools()[i].size(); ++j) { |
| 156 EXPECT_EQ(bool(j), foo.array_of_array_of_bools()[i][j]); |
| 157 } |
| 158 } |
141 } | 159 } |
142 | 160 |
143 void PrintSpacer(int depth) { | 161 void PrintSpacer(int depth) { |
144 for (int i = 0; i < depth; ++i) | 162 for (int i = 0; i < depth; ++i) |
145 std::cout << " "; | 163 std::cout << " "; |
146 } | 164 } |
147 | 165 |
148 void Print(int depth, const char* name, bool value) { | 166 void Print(int depth, const char* name, bool value) { |
149 PrintSpacer(depth); | 167 PrintSpacer(depth); |
150 std::cout << name << ": " << (value ? "true" : "false") << std::endl; | 168 std::cout << name << ": " << (value ? "true" : "false") << std::endl; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 Print(depth, "y", foo.y()); | 233 Print(depth, "y", foo.y()); |
216 Print(depth, "a", foo.a()); | 234 Print(depth, "a", foo.a()); |
217 Print(depth, "b", foo.b()); | 235 Print(depth, "b", foo.b()); |
218 Print(depth, "c", foo.c()); | 236 Print(depth, "c", foo.c()); |
219 Print(depth, "bar", foo.bar()); | 237 Print(depth, "bar", foo.bar()); |
220 Print(depth, "extra_bars", foo.extra_bars()); | 238 Print(depth, "extra_bars", foo.extra_bars()); |
221 Print(depth, "data", foo.data()); | 239 Print(depth, "data", foo.data()); |
222 Print(depth, "source", foo.source().get()); | 240 Print(depth, "source", foo.source().get()); |
223 Print(depth, "input_streams", foo.input_streams()); | 241 Print(depth, "input_streams", foo.input_streams()); |
224 Print(depth, "output_streams", foo.output_streams()); | 242 Print(depth, "output_streams", foo.output_streams()); |
| 243 Print(depth, "array_of_array_of_bools", foo.array_of_array_of_bools()); |
225 --depth; | 244 --depth; |
226 } | 245 } |
227 } | 246 } |
228 | 247 |
229 void DumpHex(const uint8_t* bytes, uint32_t num_bytes) { | 248 void DumpHex(const uint8_t* bytes, uint32_t num_bytes) { |
230 for (uint32_t i = 0; i < num_bytes; ++i) { | 249 for (uint32_t i = 0; i < num_bytes; ++i) { |
231 std::cout << std::setw(2) << std::setfill('0') << std::hex << | 250 std::cout << std::setw(2) << std::setfill('0') << std::hex << |
232 uint32_t(bytes[i]); | 251 uint32_t(bytes[i]); |
233 | 252 |
234 if (i % 16 == 15) { | 253 if (i % 16 == 15) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 365 |
347 EXPECT_EQ(1u, full.shape_masks().size()); | 366 EXPECT_EQ(1u, full.shape_masks().size()); |
348 EXPECT_EQ(1 << imported::SHAPE_RECTANGLE, full.shape_masks()[0]); | 367 EXPECT_EQ(1 << imported::SHAPE_RECTANGLE, full.shape_masks()[0]); |
349 | 368 |
350 EXPECT_EQ(imported::SHAPE_CIRCLE, full.thing().shape()); | 369 EXPECT_EQ(imported::SHAPE_CIRCLE, full.thing().shape()); |
351 EXPECT_EQ(imported::COLOR_BLACK, full.thing().color()); | 370 EXPECT_EQ(imported::COLOR_BLACK, full.thing().color()); |
352 } | 371 } |
353 | 372 |
354 } // namespace | 373 } // namespace |
355 } // namespace sample | 374 } // namespace sample |
OLD | NEW |