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 <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 map["two"]->set_f_int16(16); | 698 map["two"]->set_f_int16(16); |
699 | 699 |
700 mojo::internal::SerializationContext context; | 700 mojo::internal::SerializationContext context; |
701 size_t size = mojo::internal::PrepareToSerialize<Map<String, PodUnionPtr>>( | 701 size_t size = mojo::internal::PrepareToSerialize<Map<String, PodUnionPtr>>( |
702 map, &context); | 702 map, &context); |
703 EXPECT_EQ(120U, size); | 703 EXPECT_EQ(120U, size); |
704 | 704 |
705 mojo::internal::FixedBufferForTesting buf(size); | 705 mojo::internal::FixedBufferForTesting buf(size); |
706 mojo::internal::Map_Data<mojo::internal::String_Data*, | 706 mojo::internal::Map_Data<mojo::internal::String_Data*, |
707 internal::PodUnion_Data>* data; | 707 internal::PodUnion_Data>* data; |
708 mojo::internal::ArrayValidateParams validate_params(0, false, nullptr); | 708 mojo::internal::ArrayValidateParams validate_params( |
| 709 new mojo::internal::ArrayValidateParams(0, false, nullptr), |
| 710 new mojo::internal::ArrayValidateParams(0, false, nullptr)); |
709 mojo::internal::Serialize<Map<String, PodUnionPtr>>( | 711 mojo::internal::Serialize<Map<String, PodUnionPtr>>( |
710 map, &buf, &data, &validate_params, &context); | 712 map, &buf, &data, &validate_params, &context); |
711 | 713 |
712 Map<String, PodUnionPtr> map2; | 714 Map<String, PodUnionPtr> map2; |
713 mojo::internal::Deserialize<Map<String, PodUnionPtr>>(data, &map2, &context); | 715 mojo::internal::Deserialize<Map<String, PodUnionPtr>>(data, &map2, &context); |
714 | 716 |
715 EXPECT_EQ(8, map2["one"]->get_f_int8()); | 717 EXPECT_EQ(8, map2["one"]->get_f_int8()); |
716 EXPECT_EQ(16, map2["two"]->get_f_int16()); | 718 EXPECT_EQ(16, map2["two"]->get_f_int16()); |
717 } | 719 } |
718 | 720 |
719 TEST(UnionTest, PodUnionInMapSerializationWithNull) { | 721 TEST(UnionTest, PodUnionInMapSerializationWithNull) { |
720 Map<String, PodUnionPtr> map; | 722 Map<String, PodUnionPtr> map; |
721 map.insert("one", PodUnion::New()); | 723 map.insert("one", PodUnion::New()); |
722 map.insert("two", nullptr); | 724 map.insert("two", nullptr); |
723 | 725 |
724 map["one"]->set_f_int8(8); | 726 map["one"]->set_f_int8(8); |
725 | 727 |
726 mojo::internal::SerializationContext context; | 728 mojo::internal::SerializationContext context; |
727 size_t size = mojo::internal::PrepareToSerialize<Map<String, PodUnionPtr>>( | 729 size_t size = mojo::internal::PrepareToSerialize<Map<String, PodUnionPtr>>( |
728 map, &context); | 730 map, &context); |
729 EXPECT_EQ(120U, size); | 731 EXPECT_EQ(120U, size); |
730 | 732 |
731 mojo::internal::FixedBufferForTesting buf(size); | 733 mojo::internal::FixedBufferForTesting buf(size); |
732 mojo::internal::Map_Data<mojo::internal::String_Data*, | 734 mojo::internal::Map_Data<mojo::internal::String_Data*, |
733 internal::PodUnion_Data>* data; | 735 internal::PodUnion_Data>* data; |
734 mojo::internal::ArrayValidateParams validate_params(0, true, nullptr); | 736 mojo::internal::ArrayValidateParams validate_params( |
| 737 new mojo::internal::ArrayValidateParams(0, false, nullptr), |
| 738 new mojo::internal::ArrayValidateParams(0, true, nullptr)); |
735 mojo::internal::Serialize<Map<String, PodUnionPtr>>( | 739 mojo::internal::Serialize<Map<String, PodUnionPtr>>( |
736 map, &buf, &data, &validate_params, &context); | 740 map, &buf, &data, &validate_params, &context); |
737 | 741 |
738 Map<String, PodUnionPtr> map2; | 742 Map<String, PodUnionPtr> map2; |
739 mojo::internal::Deserialize<Map<String, PodUnionPtr>>(data, &map2, &context); | 743 mojo::internal::Deserialize<Map<String, PodUnionPtr>>(data, &map2, &context); |
740 | 744 |
741 EXPECT_EQ(8, map2["one"]->get_f_int8()); | 745 EXPECT_EQ(8, map2["one"]->get_f_int8()); |
742 EXPECT_TRUE(map2["two"].is_null()); | 746 EXPECT_TRUE(map2["two"].is_null()); |
743 } | 747 } |
744 | 748 |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 PodUnionPtr pod(PodUnion::New()); | 1242 PodUnionPtr pod(PodUnion::New()); |
1239 pod->set_f_int16(16); | 1243 pod->set_f_int16(16); |
1240 | 1244 |
1241 ptr->Echo(std::move(pod), | 1245 ptr->Echo(std::move(pod), |
1242 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); | 1246 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); |
1243 run_loop.RunUntilIdle(); | 1247 run_loop.RunUntilIdle(); |
1244 } | 1248 } |
1245 | 1249 |
1246 } // namespace test | 1250 } // namespace test |
1247 } // namespace mojo | 1251 } // namespace mojo |
OLD | NEW |