| 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 |
| 11 #include "mojo/public/cpp/bindings/array.h" | 11 #include "mojo/public/cpp/bindings/array.h" |
| 12 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 12 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
| 13 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" | 13 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" |
| 14 #include "mojo/public/cpp/bindings/lib/serialization.h" | 14 #include "mojo/public/cpp/bindings/lib/serialization.h" |
| 15 #include "mojo/public/cpp/bindings/lib/validate_params.h" | 15 #include "mojo/public/cpp/bindings/lib/validate_params.h" |
| 16 #include "mojo/public/cpp/bindings/string.h" | 16 #include "mojo/public/cpp/bindings/string.h" |
| 17 #include "mojo/public/cpp/bindings/tests/container_test_util.h" | 17 #include "mojo/public/cpp/bindings/tests/container_test_util.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 namespace test { | 21 namespace test { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 using mojo::internal::Array_Data; | 25 using mojo::internal::Array_Data; |
| 26 using mojo::internal::ArrayValidateParams; | 26 using mojo::internal::ContainerValidateParams; |
| 27 using mojo::internal::FixedBufferForTesting; | 27 using mojo::internal::FixedBufferForTesting; |
| 28 using mojo::internal::Map_Data; | 28 using mojo::internal::Map_Data; |
| 29 using mojo::internal::String_Data; | 29 using mojo::internal::String_Data; |
| 30 | 30 |
| 31 struct StringIntData { | 31 struct StringIntData { |
| 32 const char* string_data; | 32 const char* string_data; |
| 33 int int_data; | 33 int int_data; |
| 34 } kStringIntData[] = { | 34 } kStringIntData[] = { |
| 35 {"one", 1}, | 35 {"one", 1}, |
| 36 {"two", 2}, | 36 {"two", 2}, |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 { | 292 { |
| 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 ContainerValidateParams validate_params( |
| 303 0, false, new ArrayValidateParams( | 303 0, false, new ContainerValidateParams( |
| 304 new ArrayValidateParams(0, false, nullptr), | 304 new ContainerValidateParams(0, false, nullptr), |
| 305 new ArrayValidateParams(0, false, nullptr))); | 305 new ContainerValidateParams(0, false, nullptr))); |
| 306 mojo::internal::Serialize<Array<Map<int32_t, int8_t>>>( | 306 mojo::internal::Serialize<Array<Map<int32_t, int8_t>>>( |
| 307 array, &buf, &data, &validate_params, &context); | 307 array, &buf, &data, &validate_params, &context); |
| 308 | 308 |
| 309 Array<Map<int32_t, int8_t>> deserialized_array; | 309 Array<Map<int32_t, int8_t>> deserialized_array; |
| 310 mojo::internal::Deserialize<Array<Map<int32_t, int8_t>>>( | 310 mojo::internal::Deserialize<Array<Map<int32_t, int8_t>>>( |
| 311 data, &deserialized_array, &context); | 311 data, &deserialized_array, &context); |
| 312 | 312 |
| 313 ASSERT_EQ(1u, deserialized_array.size()); | 313 ASSERT_EQ(1u, deserialized_array.size()); |
| 314 ASSERT_EQ(1u, deserialized_array[0].size()); | 314 ASSERT_EQ(1u, deserialized_array[0].size()); |
| 315 ASSERT_EQ(42, deserialized_array[0].at(1)); | 315 ASSERT_EQ(42, deserialized_array[0].at(1)); |
| 316 } | 316 } |
| 317 | 317 |
| 318 { | 318 { |
| 319 Array<Map<String, Array<bool>>> array(1); | 319 Array<Map<String, Array<bool>>> array(1); |
| 320 Array<bool> map_value(2); | 320 Array<bool> map_value(2); |
| 321 map_value[0] = false; | 321 map_value[0] = false; |
| 322 map_value[1] = true; | 322 map_value[1] = true; |
| 323 array[0].insert("hello world", std::move(map_value)); | 323 array[0].insert("hello world", std::move(map_value)); |
| 324 | 324 |
| 325 mojo::internal::SerializationContext context; | 325 mojo::internal::SerializationContext context; |
| 326 size_t size = | 326 size_t size = |
| 327 mojo::internal::PrepareToSerialize<Array<Map<String, Array<bool>>>>( | 327 mojo::internal::PrepareToSerialize<Array<Map<String, Array<bool>>>>( |
| 328 array, &context); | 328 array, &context); |
| 329 FixedBufferForTesting buf(size); | 329 FixedBufferForTesting buf(size); |
| 330 Array_Data<Map_Data<String_Data*, Array_Data<bool>*>*>* data; | 330 Array_Data<Map_Data<String_Data*, Array_Data<bool>*>*>* data; |
| 331 ArrayValidateParams validate_params( | 331 ContainerValidateParams validate_params( |
| 332 0, false, new ArrayValidateParams( | 332 0, false, |
| 333 new ArrayValidateParams( | 333 new ContainerValidateParams( |
| 334 0, false, new ArrayValidateParams(0, false, nullptr)), | 334 new ContainerValidateParams( |
| 335 new ArrayValidateParams( | 335 0, false, new ContainerValidateParams(0, false, nullptr)), |
| 336 0, false, new ArrayValidateParams(0, false, nullptr)))); | 336 new ContainerValidateParams( |
| 337 0, false, new ContainerValidateParams(0, false, nullptr)))); |
| 337 mojo::internal::Serialize<Array<Map<String, Array<bool>>>>( | 338 mojo::internal::Serialize<Array<Map<String, Array<bool>>>>( |
| 338 array, &buf, &data, &validate_params, &context); | 339 array, &buf, &data, &validate_params, &context); |
| 339 | 340 |
| 340 Array<Map<String, Array<bool>>> deserialized_array; | 341 Array<Map<String, Array<bool>>> deserialized_array; |
| 341 mojo::internal::Deserialize<Array<Map<String, Array<bool>>>>( | 342 mojo::internal::Deserialize<Array<Map<String, Array<bool>>>>( |
| 342 data, &deserialized_array, &context); | 343 data, &deserialized_array, &context); |
| 343 | 344 |
| 344 ASSERT_EQ(1u, deserialized_array.size()); | 345 ASSERT_EQ(1u, deserialized_array.size()); |
| 345 ASSERT_EQ(1u, deserialized_array[0].size()); | 346 ASSERT_EQ(1u, deserialized_array[0].size()); |
| 346 ASSERT_FALSE(deserialized_array[0].at("hello world")[0]); | 347 ASSERT_FALSE(deserialized_array[0].at("hello world")[0]); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 ASSERT_EQ(1u, map2.size()); | 380 ASSERT_EQ(1u, map2.size()); |
| 380 ASSERT_NE(map2.end(), map2.find(123)); | 381 ASSERT_NE(map2.end(), map2.find(123)); |
| 381 | 382 |
| 382 ASSERT_EQ(0u, mojo_map.size()); | 383 ASSERT_EQ(0u, mojo_map.size()); |
| 383 ASSERT_TRUE(mojo_map.is_null()); | 384 ASSERT_TRUE(mojo_map.is_null()); |
| 384 } | 385 } |
| 385 | 386 |
| 386 } // namespace | 387 } // namespace |
| 387 } // namespace test | 388 } // namespace test |
| 388 } // namespace mojo | 389 } // namespace mojo |
| OLD | NEW |