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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 ASSERT_EQ(1u, it->second.size()); | 286 ASSERT_EQ(1u, it->second.size()); |
287 EXPECT_EQ(it->first, it->second.at(0)); | 287 EXPECT_EQ(it->first, it->second.at(0)); |
288 } | 288 } |
289 } | 289 } |
290 | 290 |
291 TEST_F(MapTest, ArrayOfMap) { | 291 TEST_F(MapTest, ArrayOfMap) { |
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 size_t size = GetSerializedSize_(array, nullptr); | 296 mojo::internal::SerializationContext context; |
| 297 size_t size = |
| 298 mojo::internal::PrepareToSerialize<Array<Map<int32_t, int8_t>>>( |
| 299 array, &context); |
297 FixedBufferForTesting buf(size); | 300 FixedBufferForTesting buf(size); |
298 Array_Data<Map_Data<int32_t, int8_t>*>* data; | 301 Array_Data<Map_Data<int32_t, int8_t>*>* data; |
299 ArrayValidateParams validate_params( | 302 ArrayValidateParams validate_params( |
300 0, false, new ArrayValidateParams(0, false, nullptr)); | 303 0, false, new ArrayValidateParams(0, false, nullptr)); |
301 SerializeArray_(std::move(array), &buf, &data, &validate_params, nullptr); | 304 mojo::internal::Serialize<Array<Map<int32_t, int8_t>>>( |
| 305 array, &buf, &data, &validate_params, &context); |
302 | 306 |
303 Array<Map<int32_t, int8_t>> deserialized_array; | 307 Array<Map<int32_t, int8_t>> deserialized_array; |
304 Deserialize_(data, &deserialized_array, nullptr); | 308 mojo::internal::Deserialize<Array<Map<int32_t, int8_t>>>( |
| 309 data, &deserialized_array, &context); |
305 | 310 |
306 ASSERT_EQ(1u, deserialized_array.size()); | 311 ASSERT_EQ(1u, deserialized_array.size()); |
307 ASSERT_EQ(1u, deserialized_array[0].size()); | 312 ASSERT_EQ(1u, deserialized_array[0].size()); |
308 ASSERT_EQ(42, deserialized_array[0].at(1)); | 313 ASSERT_EQ(42, deserialized_array[0].at(1)); |
309 } | 314 } |
310 | 315 |
311 { | 316 { |
312 Array<Map<String, Array<bool>>> array(1); | 317 Array<Map<String, Array<bool>>> array(1); |
313 Array<bool> map_value(2); | 318 Array<bool> map_value(2); |
314 map_value[0] = false; | 319 map_value[0] = false; |
315 map_value[1] = true; | 320 map_value[1] = true; |
316 array[0].insert("hello world", std::move(map_value)); | 321 array[0].insert("hello world", std::move(map_value)); |
317 | 322 |
318 size_t size = GetSerializedSize_(array, nullptr); | 323 mojo::internal::SerializationContext context; |
| 324 size_t size = |
| 325 mojo::internal::PrepareToSerialize<Array<Map<String, Array<bool>>>>( |
| 326 array, &context); |
319 FixedBufferForTesting buf(size); | 327 FixedBufferForTesting buf(size); |
320 Array_Data<Map_Data<String_Data*, Array_Data<bool>*>*>* data; | 328 Array_Data<Map_Data<String_Data*, Array_Data<bool>*>*>* data; |
321 ArrayValidateParams validate_params( | 329 ArrayValidateParams validate_params( |
322 0, false, new ArrayValidateParams( | 330 0, false, new ArrayValidateParams( |
323 0, false, new ArrayValidateParams(0, false, nullptr))); | 331 0, false, new ArrayValidateParams(0, false, nullptr))); |
324 SerializeArray_(std::move(array), &buf, &data, &validate_params, nullptr); | 332 mojo::internal::Serialize<Array<Map<String, Array<bool>>>>( |
| 333 array, &buf, &data, &validate_params, &context); |
325 | 334 |
326 Array<Map<String, Array<bool>>> deserialized_array; | 335 Array<Map<String, Array<bool>>> deserialized_array; |
327 Deserialize_(data, &deserialized_array, nullptr); | 336 mojo::internal::Deserialize<Array<Map<String, Array<bool>>>>( |
| 337 data, &deserialized_array, &context); |
328 | 338 |
329 ASSERT_EQ(1u, deserialized_array.size()); | 339 ASSERT_EQ(1u, deserialized_array.size()); |
330 ASSERT_EQ(1u, deserialized_array[0].size()); | 340 ASSERT_EQ(1u, deserialized_array[0].size()); |
331 ASSERT_FALSE(deserialized_array[0].at("hello world")[0]); | 341 ASSERT_FALSE(deserialized_array[0].at("hello world")[0]); |
332 ASSERT_TRUE(deserialized_array[0].at("hello world")[1]); | 342 ASSERT_TRUE(deserialized_array[0].at("hello world")[1]); |
333 } | 343 } |
334 } | 344 } |
335 | 345 |
336 TEST_F(MapTest, MoveFromAndToSTLMap_Copyable) { | 346 TEST_F(MapTest, MoveFromAndToSTLMap_Copyable) { |
337 std::map<int32_t, CopyableType> map1; | 347 std::map<int32_t, CopyableType> map1; |
(...skipping 26 matching lines...) Expand all Loading... |
364 ASSERT_EQ(1u, map2.size()); | 374 ASSERT_EQ(1u, map2.size()); |
365 ASSERT_NE(map2.end(), map2.find(123)); | 375 ASSERT_NE(map2.end(), map2.find(123)); |
366 | 376 |
367 ASSERT_EQ(0u, mojo_map.size()); | 377 ASSERT_EQ(0u, mojo_map.size()); |
368 ASSERT_TRUE(mojo_map.is_null()); | 378 ASSERT_TRUE(mojo_map.is_null()); |
369 } | 379 } |
370 | 380 |
371 } // namespace | 381 } // namespace |
372 } // namespace test | 382 } // namespace test |
373 } // namespace mojo | 383 } // namespace mojo |
OLD | NEW |