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 "mojo/public/cpp/bindings/map.h" | 5 #include "mojo/public/cpp/bindings/map.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 Array<Map<int32_t, int8_t>> array(1); | 293 Array<Map<int32_t, int8_t>> array(1); |
294 array[0].insert(1, 42); | 294 array[0].insert(1, 42); |
295 | 295 |
296 mojo::internal::SerializationContext context; | 296 mojo::internal::SerializationContext context; |
297 size_t size = | 297 size_t size = |
298 mojo::internal::PrepareToSerialize<Array<Map<int32_t, int8_t>>>( | 298 mojo::internal::PrepareToSerialize<Array<Map<int32_t, int8_t>>>( |
299 array, &context); | 299 array, &context); |
300 FixedBufferForTesting buf(size); | 300 FixedBufferForTesting buf(size); |
301 Array_Data<Map_Data<int32_t, int8_t>*>* data; | 301 Array_Data<Map_Data<int32_t, int8_t>*>* data; |
302 ArrayValidateParams validate_params( | 302 ArrayValidateParams validate_params( |
303 0, false, new ArrayValidateParams(0, false, nullptr)); | 303 0, false, new ArrayValidateParams( |
| 304 new ArrayValidateParams(0, false, nullptr), |
| 305 new ArrayValidateParams(0, false, nullptr))); |
304 mojo::internal::Serialize<Array<Map<int32_t, int8_t>>>( | 306 mojo::internal::Serialize<Array<Map<int32_t, int8_t>>>( |
305 array, &buf, &data, &validate_params, &context); | 307 array, &buf, &data, &validate_params, &context); |
306 | 308 |
307 Array<Map<int32_t, int8_t>> deserialized_array; | 309 Array<Map<int32_t, int8_t>> deserialized_array; |
308 mojo::internal::Deserialize<Array<Map<int32_t, int8_t>>>( | 310 mojo::internal::Deserialize<Array<Map<int32_t, int8_t>>>( |
309 data, &deserialized_array, &context); | 311 data, &deserialized_array, &context); |
310 | 312 |
311 ASSERT_EQ(1u, deserialized_array.size()); | 313 ASSERT_EQ(1u, deserialized_array.size()); |
312 ASSERT_EQ(1u, deserialized_array[0].size()); | 314 ASSERT_EQ(1u, deserialized_array[0].size()); |
313 ASSERT_EQ(42, deserialized_array[0].at(1)); | 315 ASSERT_EQ(42, deserialized_array[0].at(1)); |
314 } | 316 } |
315 | 317 |
316 { | 318 { |
317 Array<Map<String, Array<bool>>> array(1); | 319 Array<Map<String, Array<bool>>> array(1); |
318 Array<bool> map_value(2); | 320 Array<bool> map_value(2); |
319 map_value[0] = false; | 321 map_value[0] = false; |
320 map_value[1] = true; | 322 map_value[1] = true; |
321 array[0].insert("hello world", std::move(map_value)); | 323 array[0].insert("hello world", std::move(map_value)); |
322 | 324 |
323 mojo::internal::SerializationContext context; | 325 mojo::internal::SerializationContext context; |
324 size_t size = | 326 size_t size = |
325 mojo::internal::PrepareToSerialize<Array<Map<String, Array<bool>>>>( | 327 mojo::internal::PrepareToSerialize<Array<Map<String, Array<bool>>>>( |
326 array, &context); | 328 array, &context); |
327 FixedBufferForTesting buf(size); | 329 FixedBufferForTesting buf(size); |
328 Array_Data<Map_Data<String_Data*, Array_Data<bool>*>*>* data; | 330 Array_Data<Map_Data<String_Data*, Array_Data<bool>*>*>* data; |
329 ArrayValidateParams validate_params( | 331 ArrayValidateParams validate_params( |
330 0, false, new ArrayValidateParams( | 332 0, false, new ArrayValidateParams( |
331 0, false, new ArrayValidateParams(0, false, nullptr))); | 333 new ArrayValidateParams( |
| 334 0, false, new ArrayValidateParams(0, false, nullptr)), |
| 335 new ArrayValidateParams( |
| 336 0, false, new ArrayValidateParams(0, false, nullptr)))); |
332 mojo::internal::Serialize<Array<Map<String, Array<bool>>>>( | 337 mojo::internal::Serialize<Array<Map<String, Array<bool>>>>( |
333 array, &buf, &data, &validate_params, &context); | 338 array, &buf, &data, &validate_params, &context); |
334 | 339 |
335 Array<Map<String, Array<bool>>> deserialized_array; | 340 Array<Map<String, Array<bool>>> deserialized_array; |
336 mojo::internal::Deserialize<Array<Map<String, Array<bool>>>>( | 341 mojo::internal::Deserialize<Array<Map<String, Array<bool>>>>( |
337 data, &deserialized_array, &context); | 342 data, &deserialized_array, &context); |
338 | 343 |
339 ASSERT_EQ(1u, deserialized_array.size()); | 344 ASSERT_EQ(1u, deserialized_array.size()); |
340 ASSERT_EQ(1u, deserialized_array[0].size()); | 345 ASSERT_EQ(1u, deserialized_array[0].size()); |
341 ASSERT_FALSE(deserialized_array[0].at("hello world")[0]); | 346 ASSERT_FALSE(deserialized_array[0].at("hello world")[0]); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 ASSERT_EQ(1u, map2.size()); | 379 ASSERT_EQ(1u, map2.size()); |
375 ASSERT_NE(map2.end(), map2.find(123)); | 380 ASSERT_NE(map2.end(), map2.find(123)); |
376 | 381 |
377 ASSERT_EQ(0u, mojo_map.size()); | 382 ASSERT_EQ(0u, mojo_map.size()); |
378 ASSERT_TRUE(mojo_map.is_null()); | 383 ASSERT_TRUE(mojo_map.is_null()); |
379 } | 384 } |
380 | 385 |
381 } // namespace | 386 } // namespace |
382 } // namespace test | 387 } // namespace test |
383 } // namespace mojo | 388 } // namespace mojo |
OLD | NEW |