| 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 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 small_struct->pod_union_map.value()["one"]->set_f_int8(8); | 686 small_struct->pod_union_map.value()["one"]->set_f_int8(8); |
| 687 small_struct->pod_union_map.value()["two"]->set_f_int16(16); | 687 small_struct->pod_union_map.value()["two"]->set_f_int16(16); |
| 688 | 688 |
| 689 EXPECT_EQ(8, small_struct->pod_union_map.value()["one"]->get_f_int8()); | 689 EXPECT_EQ(8, small_struct->pod_union_map.value()["one"]->get_f_int8()); |
| 690 EXPECT_EQ(16, small_struct->pod_union_map.value()["two"]->get_f_int16()); | 690 EXPECT_EQ(16, small_struct->pod_union_map.value()["two"]->get_f_int16()); |
| 691 } | 691 } |
| 692 | 692 |
| 693 TEST(UnionTest, PodUnionInMapSerialization) { | 693 TEST(UnionTest, PodUnionInMapSerialization) { |
| 694 using MojomType = MapDataView<StringDataView, PodUnionDataView>; | 694 using MojomType = MapDataView<StringDataView, PodUnionDataView>; |
| 695 | 695 |
| 696 Map<String, PodUnionPtr> map; | 696 std::unordered_map<std::string, PodUnionPtr> map; |
| 697 map.insert("one", PodUnion::New()); | 697 map.insert(std::make_pair("one", PodUnion::New())); |
| 698 map.insert("two", PodUnion::New()); | 698 map.insert(std::make_pair("two", PodUnion::New())); |
| 699 | 699 |
| 700 map["one"]->set_f_int8(8); | 700 map["one"]->set_f_int8(8); |
| 701 map["two"]->set_f_int16(16); | 701 map["two"]->set_f_int16(16); |
| 702 | 702 |
| 703 mojo::internal::SerializationContext context; | 703 mojo::internal::SerializationContext context; |
| 704 size_t size = mojo::internal::PrepareToSerialize<MojomType>(map, &context); | 704 size_t size = mojo::internal::PrepareToSerialize<MojomType>(map, &context); |
| 705 EXPECT_EQ(120U, size); | 705 EXPECT_EQ(120U, size); |
| 706 | 706 |
| 707 mojo::internal::FixedBufferForTesting buf(size); | 707 mojo::internal::FixedBufferForTesting buf(size); |
| 708 | 708 |
| 709 typename mojo::internal::MojomTypeTraits<MojomType>::Data* data; | 709 typename mojo::internal::MojomTypeTraits<MojomType>::Data* data; |
| 710 mojo::internal::ContainerValidateParams validate_params( | 710 mojo::internal::ContainerValidateParams validate_params( |
| 711 new mojo::internal::ContainerValidateParams(0, false, nullptr), | 711 new mojo::internal::ContainerValidateParams(0, false, nullptr), |
| 712 new mojo::internal::ContainerValidateParams(0, false, nullptr)); | 712 new mojo::internal::ContainerValidateParams(0, false, nullptr)); |
| 713 mojo::internal::Serialize<MojomType>(map, &buf, &data, &validate_params, | 713 mojo::internal::Serialize<MojomType>(map, &buf, &data, &validate_params, |
| 714 &context); | 714 &context); |
| 715 | 715 |
| 716 Map<String, PodUnionPtr> map2; | 716 std::unordered_map<std::string, PodUnionPtr> map2; |
| 717 mojo::internal::Deserialize<MojomType>(data, &map2, &context); | 717 mojo::internal::Deserialize<MojomType>(data, &map2, &context); |
| 718 | 718 |
| 719 EXPECT_EQ(8, map2["one"]->get_f_int8()); | 719 EXPECT_EQ(8, map2["one"]->get_f_int8()); |
| 720 EXPECT_EQ(16, map2["two"]->get_f_int16()); | 720 EXPECT_EQ(16, map2["two"]->get_f_int16()); |
| 721 } | 721 } |
| 722 | 722 |
| 723 TEST(UnionTest, PodUnionInMapSerializationWithNull) { | 723 TEST(UnionTest, PodUnionInMapSerializationWithNull) { |
| 724 using MojomType = MapDataView<StringDataView, PodUnionDataView>; | 724 using MojomType = MapDataView<StringDataView, PodUnionDataView>; |
| 725 | 725 |
| 726 Map<String, PodUnionPtr> map; | 726 std::unordered_map<std::string, PodUnionPtr> map; |
| 727 map.insert("one", PodUnion::New()); | 727 map.insert(std::make_pair("one", PodUnion::New())); |
| 728 map.insert("two", nullptr); | 728 map.insert(std::make_pair("two", nullptr)); |
| 729 | 729 |
| 730 map["one"]->set_f_int8(8); | 730 map["one"]->set_f_int8(8); |
| 731 | 731 |
| 732 mojo::internal::SerializationContext context; | 732 mojo::internal::SerializationContext context; |
| 733 size_t size = mojo::internal::PrepareToSerialize<MojomType>(map, &context); | 733 size_t size = mojo::internal::PrepareToSerialize<MojomType>(map, &context); |
| 734 EXPECT_EQ(120U, size); | 734 EXPECT_EQ(120U, size); |
| 735 | 735 |
| 736 mojo::internal::FixedBufferForTesting buf(size); | 736 mojo::internal::FixedBufferForTesting buf(size); |
| 737 typename mojo::internal::MojomTypeTraits<MojomType>::Data* data; | 737 typename mojo::internal::MojomTypeTraits<MojomType>::Data* data; |
| 738 mojo::internal::ContainerValidateParams validate_params( | 738 mojo::internal::ContainerValidateParams validate_params( |
| 739 new mojo::internal::ContainerValidateParams(0, false, nullptr), | 739 new mojo::internal::ContainerValidateParams(0, false, nullptr), |
| 740 new mojo::internal::ContainerValidateParams(0, true, nullptr)); | 740 new mojo::internal::ContainerValidateParams(0, true, nullptr)); |
| 741 mojo::internal::Serialize<MojomType>(map, &buf, &data, &validate_params, | 741 mojo::internal::Serialize<MojomType>(map, &buf, &data, &validate_params, |
| 742 &context); | 742 &context); |
| 743 | 743 |
| 744 Map<String, PodUnionPtr> map2; | 744 std::unordered_map<std::string, PodUnionPtr> map2; |
| 745 mojo::internal::Deserialize<MojomType>(data, &map2, &context); | 745 mojo::internal::Deserialize<MojomType>(data, &map2, &context); |
| 746 | 746 |
| 747 EXPECT_EQ(8, map2["one"]->get_f_int8()); | 747 EXPECT_EQ(8, map2["one"]->get_f_int8()); |
| 748 EXPECT_TRUE(map2["two"].is_null()); | 748 EXPECT_TRUE(map2["two"].is_null()); |
| 749 } | 749 } |
| 750 | 750 |
| 751 TEST(UnionTest, StructInUnionGetterSetterPasser) { | 751 TEST(UnionTest, StructInUnionGetterSetterPasser) { |
| 752 DummyStructPtr dummy(DummyStruct::New()); | 752 DummyStructPtr dummy(DummyStruct::New()); |
| 753 dummy->f_int8 = 8; | 753 dummy->f_int8 = 8; |
| 754 | 754 |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 | 1239 |
| 1240 PodUnionPtr pod(PodUnion::New()); | 1240 PodUnionPtr pod(PodUnion::New()); |
| 1241 pod->set_f_int16(16); | 1241 pod->set_f_int16(16); |
| 1242 | 1242 |
| 1243 ptr->Echo(std::move(pod), base::Bind(&ExpectInt16, 16)); | 1243 ptr->Echo(std::move(pod), base::Bind(&ExpectInt16, 16)); |
| 1244 base::RunLoop().RunUntilIdle(); | 1244 base::RunLoop().RunUntilIdle(); |
| 1245 } | 1245 } |
| 1246 | 1246 |
| 1247 } // namespace test | 1247 } // namespace test |
| 1248 } // namespace mojo | 1248 } // namespace mojo |
| OLD | NEW |