| 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 <utility> | 5 #include <utility> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "mojo/public/cpp/bindings/array.h" | 8 #include "mojo/public/cpp/bindings/array.h" |
| 9 #include "mojo/public/cpp/bindings/binding.h" | 9 #include "mojo/public/cpp/bindings/binding.h" |
| 10 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 10 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 PodUnionPtr pod_clone = pod.Clone(); | 113 PodUnionPtr pod_clone = pod.Clone(); |
| 114 EXPECT_EQ(10, pod_clone->get_f_int8()); | 114 EXPECT_EQ(10, pod_clone->get_f_int8()); |
| 115 EXPECT_TRUE(pod_clone->is_f_int8()); | 115 EXPECT_TRUE(pod_clone->is_f_int8()); |
| 116 EXPECT_EQ(pod_clone->which(), PodUnion::Tag::F_INT8); | 116 EXPECT_EQ(pod_clone->which(), PodUnion::Tag::F_INT8); |
| 117 } | 117 } |
| 118 | 118 |
| 119 TEST(UnionTest, PodSerialization) { | 119 TEST(UnionTest, PodSerialization) { |
| 120 PodUnionPtr pod1(PodUnion::New()); | 120 PodUnionPtr pod1(PodUnion::New()); |
| 121 pod1->set_f_int8(10); | 121 pod1->set_f_int8(10); |
| 122 | 122 |
| 123 size_t size = GetSerializedSize_(pod1, false); | 123 size_t size = GetSerializedSize_(pod1); |
| 124 EXPECT_EQ(16U, size); | 124 EXPECT_EQ(16U, size); |
| 125 | 125 |
| 126 mojo::internal::FixedBufferForTesting buf(size); | 126 mojo::internal::FixedBufferForTesting buf(size); |
| 127 internal::PodUnion_Data* data = nullptr; | 127 auto* data = internal::PodUnion_Data::New(&buf); |
| 128 SerializeUnion_(pod1.get(), &buf, &data, false); | 128 SerializeUnion_(pod1.get(), &buf, &data); |
| 129 | 129 |
| 130 PodUnionPtr pod2(PodUnion::New()); | 130 PodUnionPtr pod2(PodUnion::New()); |
| 131 Deserialize_(data, pod2.get()); | 131 Deserialize_(data, pod2.get()); |
| 132 | 132 |
| 133 EXPECT_EQ(10, pod2->get_f_int8()); | 133 EXPECT_EQ(10, pod2->get_f_int8()); |
| 134 EXPECT_TRUE(pod2->is_f_int8()); | 134 EXPECT_TRUE(pod2->is_f_int8()); |
| 135 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_INT8); | 135 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_INT8); |
| 136 } | 136 } |
| 137 | 137 |
| 138 TEST(UnionTest, EnumSerialization) { | 138 TEST(UnionTest, EnumSerialization) { |
| 139 PodUnionPtr pod1(PodUnion::New()); | 139 PodUnionPtr pod1(PodUnion::New()); |
| 140 pod1->set_f_enum(AnEnum::SECOND); | 140 pod1->set_f_enum(AnEnum::SECOND); |
| 141 | 141 |
| 142 size_t size = GetSerializedSize_(pod1, false); | 142 size_t size = GetSerializedSize_(pod1); |
| 143 EXPECT_EQ(16U, size); | 143 EXPECT_EQ(16U, size); |
| 144 | 144 |
| 145 mojo::internal::FixedBufferForTesting buf(size); | 145 mojo::internal::FixedBufferForTesting buf(size); |
| 146 internal::PodUnion_Data* data = nullptr; | 146 auto* data = internal::PodUnion_Data::New(&buf); |
| 147 SerializeUnion_(pod1.get(), &buf, &data, false); | 147 SerializeUnion_(pod1.get(), &buf, &data); |
| 148 | 148 |
| 149 PodUnionPtr pod2 = PodUnion::New(); | 149 PodUnionPtr pod2 = PodUnion::New(); |
| 150 Deserialize_(data, pod2.get()); | 150 Deserialize_(data, pod2.get()); |
| 151 | 151 |
| 152 EXPECT_EQ(AnEnum::SECOND, pod2->get_f_enum()); | 152 EXPECT_EQ(AnEnum::SECOND, pod2->get_f_enum()); |
| 153 EXPECT_TRUE(pod2->is_f_enum()); | 153 EXPECT_TRUE(pod2->is_f_enum()); |
| 154 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_ENUM); | 154 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_ENUM); |
| 155 } | 155 } |
| 156 | 156 |
| 157 TEST(UnionTest, PodValidation) { | 157 TEST(UnionTest, PodValidation) { |
| 158 PodUnionPtr pod(PodUnion::New()); | 158 PodUnionPtr pod(PodUnion::New()); |
| 159 pod->set_f_int8(10); | 159 pod->set_f_int8(10); |
| 160 | 160 |
| 161 size_t size = GetSerializedSize_(pod, false); | 161 size_t size = GetSerializedSize_(pod); |
| 162 EXPECT_EQ(16U, size); | 162 EXPECT_EQ(16U, size); |
| 163 | 163 |
| 164 mojo::internal::FixedBufferForTesting buf(size); | 164 mojo::internal::FixedBufferForTesting buf(size); |
| 165 internal::PodUnion_Data* data = nullptr; | 165 auto* data = internal::PodUnion_Data::New(&buf); |
| 166 SerializeUnion_(pod.get(), &buf, &data, false); | 166 SerializeUnion_(pod.get(), &buf, &data); |
| 167 std::vector<Handle> handles; | 167 std::vector<Handle> handles; |
| 168 data->EncodePointersAndHandles(&handles); | 168 data->EncodePointersAndHandles(&handles); |
| 169 EXPECT_TRUE(handles.empty()); | 169 EXPECT_TRUE(handles.empty()); |
| 170 | 170 |
| 171 void* raw_buf = buf.Leak(); | 171 void* raw_buf = buf.Leak(); |
| 172 mojo::internal::BoundsChecker bounds_checker(data, | 172 mojo::internal::BoundsChecker bounds_checker(data, |
| 173 static_cast<uint32_t>(size), 0); | 173 static_cast<uint32_t>(size), 0); |
| 174 EXPECT_EQ(mojo::internal::ValidationError::NONE, | 174 EXPECT_EQ(mojo::internal::ValidationError::NONE, |
| 175 internal::PodUnion_Data::Validate(raw_buf, &bounds_checker, false, | 175 internal::PodUnion_Data::Validate(raw_buf, &bounds_checker, false, |
| 176 nullptr)); | 176 nullptr)); |
| 177 free(raw_buf); | 177 free(raw_buf); |
| 178 } | 178 } |
| 179 | 179 |
| 180 TEST(UnionTest, SerializeNotNull) { | 180 TEST(UnionTest, SerializeNotNull) { |
| 181 PodUnionPtr pod(PodUnion::New()); | 181 PodUnionPtr pod(PodUnion::New()); |
| 182 pod->set_f_int8(0); | 182 pod->set_f_int8(0); |
| 183 size_t size = GetSerializedSize_(pod, false); | 183 size_t size = GetSerializedSize_(pod); |
| 184 mojo::internal::FixedBufferForTesting buf(size); | 184 mojo::internal::FixedBufferForTesting buf(size); |
| 185 internal::PodUnion_Data* data = nullptr; | 185 auto* data = internal::PodUnion_Data::New(&buf); |
| 186 SerializeUnion_(pod.get(), &buf, &data, false); | 186 SerializeUnion_(pod.get(), &buf, &data); |
| 187 EXPECT_FALSE(data->is_null()); | 187 EXPECT_FALSE(data->is_null()); |
| 188 } | 188 } |
| 189 | 189 |
| 190 TEST(UnionTest, SerializeIsNullInlined) { | 190 TEST(UnionTest, SerializeIsNull) { |
| 191 PodUnionPtr pod; | 191 PodUnionPtr pod; |
| 192 size_t size = GetSerializedSize_(pod, false); | 192 size_t size = GetSerializedSize_(pod); |
| 193 EXPECT_EQ(16U, size); | 193 EXPECT_EQ(16U, size); |
| 194 mojo::internal::FixedBufferForTesting buf(size); | 194 mojo::internal::FixedBufferForTesting buf(size); |
| 195 internal::PodUnion_Data* data = internal::PodUnion_Data::New(&buf); | 195 internal::PodUnion_Data* data = internal::PodUnion_Data::New(&buf); |
| 196 | 196 |
| 197 // Check that dirty output buffers are handled correctly by serialization. | 197 // Check that dirty output buffers are handled correctly by serialization. |
| 198 data->size = 16U; | 198 data->size = 16U; |
| 199 data->tag = PodUnion::Tag::F_UINT16; | 199 data->tag = PodUnion::Tag::F_UINT16; |
| 200 data->data.f_f_int16 = 20; | 200 data->data.f_f_int16 = 20; |
| 201 | 201 |
| 202 SerializeUnion_(pod.get(), &buf, &data, true); | 202 SerializeUnion_(pod.get(), &buf, &data); |
| 203 EXPECT_TRUE(data->is_null()); | 203 EXPECT_TRUE(data->is_null()); |
| 204 | 204 |
| 205 PodUnionPtr pod2 = PodUnion::New(); | 205 PodUnionPtr pod2 = PodUnion::New(); |
| 206 Deserialize_(data, pod2.get()); | 206 Deserialize_(data, pod2.get()); |
| 207 EXPECT_EQ(pod2->which(), PodUnion::Tag::__UNKNOWN__); | 207 EXPECT_EQ(pod2->which(), PodUnion::Tag::__UNKNOWN__); |
| 208 } | |
| 209 | 208 |
| 210 TEST(UnionTest, SerializeIsNullNotInlined) { | 209 { |
| 211 PodUnionPtr pod; | 210 PodUnionPtr pod; |
| 212 size_t size = GetSerializedSize_(pod, false); | 211 size_t size = GetSerializedSize_(pod); |
| 213 EXPECT_EQ(16U, size); | 212 EXPECT_EQ(16U, size); |
| 214 mojo::internal::FixedBufferForTesting buf(size); | 213 mojo::internal::FixedBufferForTesting buf(size); |
| 215 internal::PodUnion_Data* data = nullptr; | 214 auto* data = internal::PodUnion_Data::New(&buf); |
| 216 SerializeUnion_(pod.get(), &buf, &data, false); | 215 SerializeUnion_(pod.get(), &buf, &data); |
| 217 EXPECT_EQ(nullptr, data); | 216 EXPECT_EQ(static_cast<internal::PodUnion_Data::PodUnion_Tag>(0), data->tag); |
| 217 EXPECT_EQ(0u, data->size); |
| 218 EXPECT_EQ(0u, data->data.unknown); |
| 219 } |
| 218 } | 220 } |
| 219 | 221 |
| 220 TEST(UnionTest, NullValidation) { | 222 TEST(UnionTest, NullValidation) { |
| 221 void* buf = nullptr; | 223 void* buf = nullptr; |
| 222 mojo::internal::BoundsChecker bounds_checker(buf, 0, 0); | 224 mojo::internal::BoundsChecker bounds_checker(buf, 0, 0); |
| 223 EXPECT_EQ( | 225 EXPECT_EQ( |
| 224 mojo::internal::ValidationError::NONE, | 226 mojo::internal::ValidationError::NONE, |
| 225 internal::PodUnion_Data::Validate(buf, &bounds_checker, false, nullptr)); | 227 internal::PodUnion_Data::Validate(buf, &bounds_checker, false, nullptr)); |
| 226 } | 228 } |
| 227 | 229 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 EXPECT_TRUE(pod_clone->is_f_string()); | 321 EXPECT_TRUE(pod_clone->is_f_string()); |
| 320 EXPECT_EQ(pod_clone->which(), ObjectUnion::Tag::F_STRING); | 322 EXPECT_EQ(pod_clone->which(), ObjectUnion::Tag::F_STRING); |
| 321 } | 323 } |
| 322 | 324 |
| 323 TEST(UnionTest, StringSerialization) { | 325 TEST(UnionTest, StringSerialization) { |
| 324 ObjectUnionPtr pod1(ObjectUnion::New()); | 326 ObjectUnionPtr pod1(ObjectUnion::New()); |
| 325 | 327 |
| 326 String hello("hello world"); | 328 String hello("hello world"); |
| 327 pod1->set_f_string(hello); | 329 pod1->set_f_string(hello); |
| 328 | 330 |
| 329 size_t size = GetSerializedSize_(pod1, false); | 331 size_t size = GetSerializedSize_(pod1); |
| 330 mojo::internal::FixedBufferForTesting buf(size); | 332 mojo::internal::FixedBufferForTesting buf(size); |
| 331 internal::ObjectUnion_Data* data = nullptr; | 333 auto* data = internal::ObjectUnion_Data::New(&buf); |
| 332 SerializeUnion_(pod1.get(), &buf, &data, false); | 334 SerializeUnion_(pod1.get(), &buf, &data); |
| 333 | 335 |
| 334 std::vector<Handle> handles; | 336 std::vector<Handle> handles; |
| 335 data->EncodePointersAndHandles(&handles); | 337 data->EncodePointersAndHandles(&handles); |
| 336 data->DecodePointersAndHandles(&handles); | 338 data->DecodePointersAndHandles(&handles); |
| 337 | 339 |
| 338 ObjectUnionPtr pod2 = ObjectUnion::New(); | 340 ObjectUnionPtr pod2 = ObjectUnion::New(); |
| 339 Deserialize_(data, pod2.get()); | 341 Deserialize_(data, pod2.get()); |
| 340 EXPECT_EQ(hello, pod2->get_f_string()); | 342 EXPECT_EQ(hello, pod2->get_f_string()); |
| 341 EXPECT_TRUE(pod2->is_f_string()); | 343 EXPECT_TRUE(pod2->is_f_string()); |
| 342 EXPECT_EQ(pod2->which(), ObjectUnion::Tag::F_STRING); | 344 EXPECT_EQ(pod2->which(), ObjectUnion::Tag::F_STRING); |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 } | 770 } |
| 769 | 771 |
| 770 TEST(UnionTest, StructInUnionSerialization) { | 772 TEST(UnionTest, StructInUnionSerialization) { |
| 771 Environment environment; | 773 Environment environment; |
| 772 DummyStructPtr dummy(DummyStruct::New()); | 774 DummyStructPtr dummy(DummyStruct::New()); |
| 773 dummy->f_int8 = 8; | 775 dummy->f_int8 = 8; |
| 774 | 776 |
| 775 ObjectUnionPtr obj(ObjectUnion::New()); | 777 ObjectUnionPtr obj(ObjectUnion::New()); |
| 776 obj->set_f_dummy(dummy.Pass()); | 778 obj->set_f_dummy(dummy.Pass()); |
| 777 | 779 |
| 778 size_t size = GetSerializedSize_(obj, false); | 780 size_t size = GetSerializedSize_(obj); |
| 779 EXPECT_EQ(32U, size); | 781 EXPECT_EQ(32U, size); |
| 780 | 782 |
| 781 mojo::internal::FixedBufferForTesting buf(size); | 783 mojo::internal::FixedBufferForTesting buf(size); |
| 782 internal::ObjectUnion_Data* data = nullptr; | 784 auto* data = internal::ObjectUnion_Data::New(&buf); |
| 783 SerializeUnion_(obj.get(), &buf, &data, false); | 785 SerializeUnion_(obj.get(), &buf, &data); |
| 784 | 786 |
| 785 std::vector<Handle> handles; | 787 std::vector<Handle> handles; |
| 786 data->EncodePointersAndHandles(&handles); | 788 data->EncodePointersAndHandles(&handles); |
| 787 data->DecodePointersAndHandles(&handles); | 789 data->DecodePointersAndHandles(&handles); |
| 788 | 790 |
| 789 ObjectUnionPtr obj2 = ObjectUnion::New(); | 791 ObjectUnionPtr obj2 = ObjectUnion::New(); |
| 790 Deserialize_(data, obj2.get()); | 792 Deserialize_(data, obj2.get()); |
| 791 EXPECT_EQ(8, obj2->get_f_dummy()->f_int8); | 793 EXPECT_EQ(8, obj2->get_f_dummy()->f_int8); |
| 792 } | 794 } |
| 793 | 795 |
| 794 TEST(UnionTest, StructInUnionValidation) { | 796 TEST(UnionTest, StructInUnionValidation) { |
| 795 Environment environment; | 797 Environment environment; |
| 796 DummyStructPtr dummy(DummyStruct::New()); | 798 DummyStructPtr dummy(DummyStruct::New()); |
| 797 dummy->f_int8 = 8; | 799 dummy->f_int8 = 8; |
| 798 | 800 |
| 799 ObjectUnionPtr obj(ObjectUnion::New()); | 801 ObjectUnionPtr obj(ObjectUnion::New()); |
| 800 obj->set_f_dummy(dummy.Pass()); | 802 obj->set_f_dummy(dummy.Pass()); |
| 801 | 803 |
| 802 size_t size = GetSerializedSize_(obj, false); | 804 size_t size = GetSerializedSize_(obj); |
| 803 | 805 |
| 804 mojo::internal::FixedBufferForTesting buf(size); | 806 mojo::internal::FixedBufferForTesting buf(size); |
| 805 internal::ObjectUnion_Data* data = nullptr; | 807 auto* data = internal::ObjectUnion_Data::New(&buf); |
| 806 SerializeUnion_(obj.get(), &buf, &data, false); | 808 SerializeUnion_(obj.get(), &buf, &data); |
| 807 | 809 |
| 808 std::vector<Handle> handles; | 810 std::vector<Handle> handles; |
| 809 data->EncodePointersAndHandles(&handles); | 811 data->EncodePointersAndHandles(&handles); |
| 810 EXPECT_TRUE(handles.empty()); | 812 EXPECT_TRUE(handles.empty()); |
| 811 | 813 |
| 812 void* raw_buf = buf.Leak(); | 814 void* raw_buf = buf.Leak(); |
| 813 mojo::internal::BoundsChecker bounds_checker(data, | 815 mojo::internal::BoundsChecker bounds_checker(data, |
| 814 static_cast<uint32_t>(size), 0); | 816 static_cast<uint32_t>(size), 0); |
| 815 EXPECT_EQ(mojo::internal::ValidationError::NONE, | 817 EXPECT_EQ(mojo::internal::ValidationError::NONE, |
| 816 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, | 818 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, |
| 817 false, nullptr)); | 819 false, nullptr)); |
| 818 free(raw_buf); | 820 free(raw_buf); |
| 819 } | 821 } |
| 820 | 822 |
| 821 TEST(UnionTest, StructInUnionValidationNonNullable) { | 823 TEST(UnionTest, StructInUnionValidationNonNullable) { |
| 822 Environment environment; | 824 Environment environment; |
| 823 DummyStructPtr dummy(nullptr); | 825 DummyStructPtr dummy(nullptr); |
| 824 | 826 |
| 825 ObjectUnionPtr obj(ObjectUnion::New()); | 827 ObjectUnionPtr obj(ObjectUnion::New()); |
| 826 obj->set_f_dummy(dummy.Pass()); | 828 obj->set_f_dummy(dummy.Pass()); |
| 827 | 829 |
| 828 size_t size = GetSerializedSize_(obj, false); | 830 size_t size = GetSerializedSize_(obj); |
| 829 | 831 |
| 830 mojo::internal::FixedBufferForTesting buf(size); | 832 mojo::internal::FixedBufferForTesting buf(size); |
| 831 internal::ObjectUnion_Data* data = nullptr; | 833 auto* data = internal::ObjectUnion_Data::New(&buf); |
| 832 SerializeUnion_(obj.get(), &buf, &data, false); | 834 SerializeUnion_(obj.get(), &buf, &data); |
| 833 | 835 |
| 834 std::vector<Handle> handles; | 836 std::vector<Handle> handles; |
| 835 data->EncodePointersAndHandles(&handles); | 837 data->EncodePointersAndHandles(&handles); |
| 836 EXPECT_TRUE(handles.empty()); | 838 EXPECT_TRUE(handles.empty()); |
| 837 | 839 |
| 838 void* raw_buf = buf.Leak(); | 840 void* raw_buf = buf.Leak(); |
| 839 mojo::internal::BoundsChecker bounds_checker(data, | 841 mojo::internal::BoundsChecker bounds_checker(data, |
| 840 static_cast<uint32_t>(size), 0); | 842 static_cast<uint32_t>(size), 0); |
| 841 EXPECT_NE(mojo::internal::ValidationError::NONE, | 843 EXPECT_NE(mojo::internal::ValidationError::NONE, |
| 842 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, | 844 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, |
| 843 false, nullptr)); | 845 false, nullptr)); |
| 844 free(raw_buf); | 846 free(raw_buf); |
| 845 } | 847 } |
| 846 | 848 |
| 847 TEST(UnionTest, StructInUnionValidationNullable) { | 849 TEST(UnionTest, StructInUnionValidationNullable) { |
| 848 Environment environment; | 850 Environment environment; |
| 849 DummyStructPtr dummy(nullptr); | 851 DummyStructPtr dummy(nullptr); |
| 850 | 852 |
| 851 ObjectUnionPtr obj(ObjectUnion::New()); | 853 ObjectUnionPtr obj(ObjectUnion::New()); |
| 852 obj->set_f_nullable(dummy.Pass()); | 854 obj->set_f_nullable(dummy.Pass()); |
| 853 | 855 |
| 854 size_t size = GetSerializedSize_(obj, false); | 856 size_t size = GetSerializedSize_(obj); |
| 855 | 857 |
| 856 mojo::internal::FixedBufferForTesting buf(size); | 858 mojo::internal::FixedBufferForTesting buf(size); |
| 857 internal::ObjectUnion_Data* data = nullptr; | 859 auto* data = internal::ObjectUnion_Data::New(&buf); |
| 858 SerializeUnion_(obj.get(), &buf, &data, false); | 860 SerializeUnion_(obj.get(), &buf, &data); |
| 859 | 861 |
| 860 std::vector<Handle> handles; | 862 std::vector<Handle> handles; |
| 861 data->EncodePointersAndHandles(&handles); | 863 data->EncodePointersAndHandles(&handles); |
| 862 EXPECT_TRUE(handles.empty()); | 864 EXPECT_TRUE(handles.empty()); |
| 863 | 865 |
| 864 void* raw_buf = buf.Leak(); | 866 void* raw_buf = buf.Leak(); |
| 865 mojo::internal::BoundsChecker bounds_checker(data, | 867 mojo::internal::BoundsChecker bounds_checker(data, |
| 866 static_cast<uint32_t>(size), 0); | 868 static_cast<uint32_t>(size), 0); |
| 867 EXPECT_EQ(mojo::internal::ValidationError::NONE, | 869 EXPECT_EQ(mojo::internal::ValidationError::NONE, |
| 868 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, | 870 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 887 TEST(UnionTest, ArrayInUnionSerialization) { | 889 TEST(UnionTest, ArrayInUnionSerialization) { |
| 888 Environment environment; | 890 Environment environment; |
| 889 | 891 |
| 890 auto array = Array<int8_t>::New(2); | 892 auto array = Array<int8_t>::New(2); |
| 891 array[0] = 8; | 893 array[0] = 8; |
| 892 array[1] = 9; | 894 array[1] = 9; |
| 893 | 895 |
| 894 ObjectUnionPtr obj(ObjectUnion::New()); | 896 ObjectUnionPtr obj(ObjectUnion::New()); |
| 895 obj->set_f_array_int8(array.Pass()); | 897 obj->set_f_array_int8(array.Pass()); |
| 896 | 898 |
| 897 size_t size = GetSerializedSize_(obj, false); | 899 size_t size = GetSerializedSize_(obj); |
| 898 EXPECT_EQ(32U, size); | 900 EXPECT_EQ(32U, size); |
| 899 | 901 |
| 900 mojo::internal::FixedBufferForTesting buf(size); | 902 mojo::internal::FixedBufferForTesting buf(size); |
| 901 internal::ObjectUnion_Data* data = nullptr; | 903 auto* data = internal::ObjectUnion_Data::New(&buf); |
| 902 SerializeUnion_(obj.get(), &buf, &data, false); | 904 SerializeUnion_(obj.get(), &buf, &data); |
| 903 | 905 |
| 904 std::vector<Handle> handles; | 906 std::vector<Handle> handles; |
| 905 data->EncodePointersAndHandles(&handles); | 907 data->EncodePointersAndHandles(&handles); |
| 906 data->DecodePointersAndHandles(&handles); | 908 data->DecodePointersAndHandles(&handles); |
| 907 | 909 |
| 908 ObjectUnionPtr obj2 = ObjectUnion::New(); | 910 ObjectUnionPtr obj2 = ObjectUnion::New(); |
| 909 Deserialize_(data, obj2.get()); | 911 Deserialize_(data, obj2.get()); |
| 910 | 912 |
| 911 EXPECT_EQ(8, obj2->get_f_array_int8()[0]); | 913 EXPECT_EQ(8, obj2->get_f_array_int8()[0]); |
| 912 EXPECT_EQ(9, obj2->get_f_array_int8()[1]); | 914 EXPECT_EQ(9, obj2->get_f_array_int8()[1]); |
| 913 } | 915 } |
| 914 | 916 |
| 915 TEST(UnionTest, ArrayInUnionValidation) { | 917 TEST(UnionTest, ArrayInUnionValidation) { |
| 916 Environment environment; | 918 Environment environment; |
| 917 | 919 |
| 918 auto array = Array<int8_t>::New(2); | 920 auto array = Array<int8_t>::New(2); |
| 919 array[0] = 8; | 921 array[0] = 8; |
| 920 array[1] = 9; | 922 array[1] = 9; |
| 921 | 923 |
| 922 ObjectUnionPtr obj(ObjectUnion::New()); | 924 ObjectUnionPtr obj(ObjectUnion::New()); |
| 923 obj->set_f_array_int8(array.Pass()); | 925 obj->set_f_array_int8(array.Pass()); |
| 924 | 926 |
| 925 size_t size = GetSerializedSize_(obj, false); | 927 size_t size = GetSerializedSize_(obj); |
| 926 mojo::internal::FixedBufferForTesting buf(size); | 928 mojo::internal::FixedBufferForTesting buf(size); |
| 927 internal::ObjectUnion_Data* data = nullptr; | 929 auto* data = internal::ObjectUnion_Data::New(&buf); |
| 928 SerializeUnion_(obj.get(), &buf, &data, false); | 930 SerializeUnion_(obj.get(), &buf, &data); |
| 929 | 931 |
| 930 std::vector<Handle> handles; | 932 std::vector<Handle> handles; |
| 931 data->EncodePointersAndHandles(&handles); | 933 data->EncodePointersAndHandles(&handles); |
| 932 EXPECT_TRUE(handles.empty()); | 934 EXPECT_TRUE(handles.empty()); |
| 933 | 935 |
| 934 void* raw_buf = buf.Leak(); | 936 void* raw_buf = buf.Leak(); |
| 935 mojo::internal::BoundsChecker bounds_checker(data, | 937 mojo::internal::BoundsChecker bounds_checker(data, |
| 936 static_cast<uint32_t>(size), 0); | 938 static_cast<uint32_t>(size), 0); |
| 937 | 939 |
| 938 EXPECT_EQ(mojo::internal::ValidationError::NONE, | 940 EXPECT_EQ(mojo::internal::ValidationError::NONE, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 956 | 958 |
| 957 TEST(UnionTest, MapInUnionSerialization) { | 959 TEST(UnionTest, MapInUnionSerialization) { |
| 958 Environment environment; | 960 Environment environment; |
| 959 Map<String, int8_t> map; | 961 Map<String, int8_t> map; |
| 960 map.insert("one", 1); | 962 map.insert("one", 1); |
| 961 map.insert("two", 2); | 963 map.insert("two", 2); |
| 962 | 964 |
| 963 ObjectUnionPtr obj(ObjectUnion::New()); | 965 ObjectUnionPtr obj(ObjectUnion::New()); |
| 964 obj->set_f_map_int8(map.Pass()); | 966 obj->set_f_map_int8(map.Pass()); |
| 965 | 967 |
| 966 size_t size = GetSerializedSize_(obj, false); | 968 size_t size = GetSerializedSize_(obj); |
| 967 EXPECT_EQ(112U, size); | 969 EXPECT_EQ(112U, size); |
| 968 | 970 |
| 969 mojo::internal::FixedBufferForTesting buf(size); | 971 mojo::internal::FixedBufferForTesting buf(size); |
| 970 internal::ObjectUnion_Data* data = nullptr; | 972 auto* data = internal::ObjectUnion_Data::New(&buf); |
| 971 SerializeUnion_(obj.get(), &buf, &data, false); | 973 SerializeUnion_(obj.get(), &buf, &data); |
| 972 | 974 |
| 973 std::vector<Handle> handles; | 975 std::vector<Handle> handles; |
| 974 data->EncodePointersAndHandles(&handles); | 976 data->EncodePointersAndHandles(&handles); |
| 975 data->DecodePointersAndHandles(&handles); | 977 data->DecodePointersAndHandles(&handles); |
| 976 | 978 |
| 977 ObjectUnionPtr obj2 = ObjectUnion::New(); | 979 ObjectUnionPtr obj2 = ObjectUnion::New(); |
| 978 Deserialize_(data, obj2.get()); | 980 Deserialize_(data, obj2.get()); |
| 979 | 981 |
| 980 EXPECT_EQ(1, obj2->get_f_map_int8()["one"]); | 982 EXPECT_EQ(1, obj2->get_f_map_int8()["one"]); |
| 981 EXPECT_EQ(2, obj2->get_f_map_int8()["two"]); | 983 EXPECT_EQ(2, obj2->get_f_map_int8()["two"]); |
| 982 } | 984 } |
| 983 | 985 |
| 984 TEST(UnionTest, MapInUnionValidation) { | 986 TEST(UnionTest, MapInUnionValidation) { |
| 985 Environment environment; | 987 Environment environment; |
| 986 Map<String, int8_t> map; | 988 Map<String, int8_t> map; |
| 987 map.insert("one", 1); | 989 map.insert("one", 1); |
| 988 map.insert("two", 2); | 990 map.insert("two", 2); |
| 989 | 991 |
| 990 ObjectUnionPtr obj(ObjectUnion::New()); | 992 ObjectUnionPtr obj(ObjectUnion::New()); |
| 991 obj->set_f_map_int8(map.Pass()); | 993 obj->set_f_map_int8(map.Pass()); |
| 992 | 994 |
| 993 size_t size = GetSerializedSize_(obj, false); | 995 size_t size = GetSerializedSize_(obj); |
| 994 EXPECT_EQ(112U, size); | 996 EXPECT_EQ(112U, size); |
| 995 | 997 |
| 996 mojo::internal::FixedBufferForTesting buf(size); | 998 mojo::internal::FixedBufferForTesting buf(size); |
| 997 internal::ObjectUnion_Data* data = nullptr; | 999 auto* data = internal::ObjectUnion_Data::New(&buf); |
| 998 SerializeUnion_(obj.get(), &buf, &data, false); | 1000 SerializeUnion_(obj.get(), &buf, &data); |
| 999 | 1001 |
| 1000 std::vector<Handle> handles; | 1002 std::vector<Handle> handles; |
| 1001 data->EncodePointersAndHandles(&handles); | 1003 data->EncodePointersAndHandles(&handles); |
| 1002 EXPECT_TRUE(handles.empty()); | 1004 EXPECT_TRUE(handles.empty()); |
| 1003 | 1005 |
| 1004 void* raw_buf = buf.Leak(); | 1006 void* raw_buf = buf.Leak(); |
| 1005 mojo::internal::BoundsChecker bounds_checker(data, | 1007 mojo::internal::BoundsChecker bounds_checker(data, |
| 1006 static_cast<uint32_t>(size), 0); | 1008 static_cast<uint32_t>(size), 0); |
| 1007 | 1009 |
| 1008 EXPECT_EQ(mojo::internal::ValidationError::NONE, | 1010 EXPECT_EQ(mojo::internal::ValidationError::NONE, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1022 } | 1024 } |
| 1023 | 1025 |
| 1024 TEST(UnionTest, UnionInUnionSerialization) { | 1026 TEST(UnionTest, UnionInUnionSerialization) { |
| 1025 Environment environment; | 1027 Environment environment; |
| 1026 PodUnionPtr pod(PodUnion::New()); | 1028 PodUnionPtr pod(PodUnion::New()); |
| 1027 pod->set_f_int8(10); | 1029 pod->set_f_int8(10); |
| 1028 | 1030 |
| 1029 ObjectUnionPtr obj(ObjectUnion::New()); | 1031 ObjectUnionPtr obj(ObjectUnion::New()); |
| 1030 obj->set_f_pod_union(pod.Pass()); | 1032 obj->set_f_pod_union(pod.Pass()); |
| 1031 | 1033 |
| 1032 size_t size = GetSerializedSize_(obj, false); | 1034 size_t size = GetSerializedSize_(obj); |
| 1033 EXPECT_EQ(32U, size); | 1035 EXPECT_EQ(32U, size); |
| 1034 | 1036 |
| 1035 mojo::internal::FixedBufferForTesting buf(size); | 1037 mojo::internal::FixedBufferForTesting buf(size); |
| 1036 internal::ObjectUnion_Data* data = nullptr; | 1038 auto* data = internal::ObjectUnion_Data::New(&buf); |
| 1037 SerializeUnion_(obj.get(), &buf, &data, false); | 1039 SerializeUnion_(obj.get(), &buf, &data); |
| 1038 | 1040 |
| 1039 std::vector<Handle> handles; | 1041 std::vector<Handle> handles; |
| 1040 data->EncodePointersAndHandles(&handles); | 1042 data->EncodePointersAndHandles(&handles); |
| 1041 data->DecodePointersAndHandles(&handles); | 1043 data->DecodePointersAndHandles(&handles); |
| 1042 | 1044 |
| 1043 ObjectUnionPtr obj2 = ObjectUnion::New(); | 1045 ObjectUnionPtr obj2 = ObjectUnion::New(); |
| 1044 Deserialize_(data, obj2.get()); | 1046 Deserialize_(data, obj2.get()); |
| 1045 EXPECT_EQ(10, obj2->get_f_pod_union()->get_f_int8()); | 1047 EXPECT_EQ(10, obj2->get_f_pod_union()->get_f_int8()); |
| 1046 } | 1048 } |
| 1047 | 1049 |
| 1048 TEST(UnionTest, UnionInUnionValidation) { | 1050 TEST(UnionTest, UnionInUnionValidation) { |
| 1049 Environment environment; | 1051 Environment environment; |
| 1050 PodUnionPtr pod(PodUnion::New()); | 1052 PodUnionPtr pod(PodUnion::New()); |
| 1051 pod->set_f_int8(10); | 1053 pod->set_f_int8(10); |
| 1052 | 1054 |
| 1053 ObjectUnionPtr obj(ObjectUnion::New()); | 1055 ObjectUnionPtr obj(ObjectUnion::New()); |
| 1054 obj->set_f_pod_union(pod.Pass()); | 1056 obj->set_f_pod_union(pod.Pass()); |
| 1055 | 1057 |
| 1056 size_t size = GetSerializedSize_(obj, false); | 1058 size_t size = GetSerializedSize_(obj); |
| 1057 EXPECT_EQ(32U, size); | 1059 EXPECT_EQ(32U, size); |
| 1058 | 1060 |
| 1059 mojo::internal::FixedBufferForTesting buf(size); | 1061 mojo::internal::FixedBufferForTesting buf(size); |
| 1060 internal::ObjectUnion_Data* data = nullptr; | 1062 auto* data = internal::ObjectUnion_Data::New(&buf); |
| 1061 SerializeUnion_(obj.get(), &buf, &data, false); | 1063 SerializeUnion_(obj.get(), &buf, &data); |
| 1062 | 1064 |
| 1063 std::vector<Handle> handles; | 1065 std::vector<Handle> handles; |
| 1064 data->EncodePointersAndHandles(&handles); | 1066 data->EncodePointersAndHandles(&handles); |
| 1065 | 1067 |
| 1066 void* raw_buf = buf.Leak(); | 1068 void* raw_buf = buf.Leak(); |
| 1067 mojo::internal::BoundsChecker bounds_checker(data, | 1069 mojo::internal::BoundsChecker bounds_checker(data, |
| 1068 static_cast<uint32_t>(size), 0); | 1070 static_cast<uint32_t>(size), 0); |
| 1069 EXPECT_EQ(mojo::internal::ValidationError::NONE, | 1071 EXPECT_EQ(mojo::internal::ValidationError::NONE, |
| 1070 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, | 1072 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, |
| 1071 false, nullptr)); | 1073 false, nullptr)); |
| 1072 free(raw_buf); | 1074 free(raw_buf); |
| 1073 } | 1075 } |
| 1074 | 1076 |
| 1075 TEST(UnionTest, UnionInUnionValidationNonNullable) { | 1077 TEST(UnionTest, UnionInUnionValidationNonNullable) { |
| 1076 Environment environment; | 1078 Environment environment; |
| 1077 PodUnionPtr pod(nullptr); | 1079 PodUnionPtr pod(nullptr); |
| 1078 | 1080 |
| 1079 ObjectUnionPtr obj(ObjectUnion::New()); | 1081 ObjectUnionPtr obj(ObjectUnion::New()); |
| 1080 obj->set_f_pod_union(pod.Pass()); | 1082 obj->set_f_pod_union(pod.Pass()); |
| 1081 | 1083 |
| 1082 size_t size = GetSerializedSize_(obj, false); | 1084 size_t size = GetSerializedSize_(obj); |
| 1083 | 1085 |
| 1084 mojo::internal::FixedBufferForTesting buf(size); | 1086 mojo::internal::FixedBufferForTesting buf(size); |
| 1085 internal::ObjectUnion_Data* data = nullptr; | 1087 auto* data = internal::ObjectUnion_Data::New(&buf); |
| 1086 SerializeUnion_(obj.get(), &buf, &data, false); | 1088 SerializeUnion_(obj.get(), &buf, &data); |
| 1087 std::vector<Handle> handles; | 1089 std::vector<Handle> handles; |
| 1088 data->EncodePointersAndHandles(&handles); | 1090 data->EncodePointersAndHandles(&handles); |
| 1089 | 1091 |
| 1090 void* raw_buf = buf.Leak(); | 1092 void* raw_buf = buf.Leak(); |
| 1091 mojo::internal::BoundsChecker bounds_checker(data, | 1093 mojo::internal::BoundsChecker bounds_checker(data, |
| 1092 static_cast<uint32_t>(size), 0); | 1094 static_cast<uint32_t>(size), 0); |
| 1093 EXPECT_NE(mojo::internal::ValidationError::NONE, | 1095 EXPECT_NE(mojo::internal::ValidationError::NONE, |
| 1094 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, | 1096 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, |
| 1095 false, nullptr)); | 1097 false, nullptr)); |
| 1096 free(raw_buf); | 1098 free(raw_buf); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1116 | 1118 |
| 1117 TEST(UnionTest, HandleInUnionSerialization) { | 1119 TEST(UnionTest, HandleInUnionSerialization) { |
| 1118 ScopedMessagePipeHandle pipe0; | 1120 ScopedMessagePipeHandle pipe0; |
| 1119 ScopedMessagePipeHandle pipe1; | 1121 ScopedMessagePipeHandle pipe1; |
| 1120 | 1122 |
| 1121 CreateMessagePipe(nullptr, &pipe0, &pipe1); | 1123 CreateMessagePipe(nullptr, &pipe0, &pipe1); |
| 1122 | 1124 |
| 1123 HandleUnionPtr handle(HandleUnion::New()); | 1125 HandleUnionPtr handle(HandleUnion::New()); |
| 1124 handle->set_f_message_pipe(pipe1.Pass()); | 1126 handle->set_f_message_pipe(pipe1.Pass()); |
| 1125 | 1127 |
| 1126 size_t size = GetSerializedSize_(handle, false); | 1128 size_t size = GetSerializedSize_(handle); |
| 1127 EXPECT_EQ(16U, size); | 1129 EXPECT_EQ(16U, size); |
| 1128 | 1130 |
| 1129 mojo::internal::FixedBufferForTesting buf(size); | 1131 mojo::internal::FixedBufferForTesting buf(size); |
| 1130 internal::HandleUnion_Data* data = nullptr; | 1132 auto* data = internal::HandleUnion_Data::New(&buf); |
| 1131 SerializeUnion_(handle.get(), &buf, &data, false); | 1133 SerializeUnion_(handle.get(), &buf, &data); |
| 1132 | 1134 |
| 1133 std::vector<Handle> handles; | 1135 std::vector<Handle> handles; |
| 1134 data->EncodePointersAndHandles(&handles); | 1136 data->EncodePointersAndHandles(&handles); |
| 1135 EXPECT_EQ(1U, handles.size()); | 1137 EXPECT_EQ(1U, handles.size()); |
| 1136 data->DecodePointersAndHandles(&handles); | 1138 data->DecodePointersAndHandles(&handles); |
| 1137 | 1139 |
| 1138 HandleUnionPtr handle2(HandleUnion::New()); | 1140 HandleUnionPtr handle2(HandleUnion::New()); |
| 1139 Deserialize_(data, handle2.get()); | 1141 Deserialize_(data, handle2.get()); |
| 1140 | 1142 |
| 1141 std::string golden("hello world"); | 1143 std::string golden("hello world"); |
| 1142 WriteTextMessage(pipe0.get(), golden); | 1144 WriteTextMessage(pipe0.get(), golden); |
| 1143 | 1145 |
| 1144 std::string actual; | 1146 std::string actual; |
| 1145 ReadTextMessage(handle2->get_f_message_pipe().get(), &actual); | 1147 ReadTextMessage(handle2->get_f_message_pipe().get(), &actual); |
| 1146 | 1148 |
| 1147 EXPECT_EQ(golden, actual); | 1149 EXPECT_EQ(golden, actual); |
| 1148 } | 1150 } |
| 1149 | 1151 |
| 1150 TEST(UnionTest, HandleInUnionValidation) { | 1152 TEST(UnionTest, HandleInUnionValidation) { |
| 1151 Environment environment; | 1153 Environment environment; |
| 1152 ScopedMessagePipeHandle pipe0; | 1154 ScopedMessagePipeHandle pipe0; |
| 1153 ScopedMessagePipeHandle pipe1; | 1155 ScopedMessagePipeHandle pipe1; |
| 1154 | 1156 |
| 1155 CreateMessagePipe(nullptr, &pipe0, &pipe1); | 1157 CreateMessagePipe(nullptr, &pipe0, &pipe1); |
| 1156 | 1158 |
| 1157 HandleUnionPtr handle(HandleUnion::New()); | 1159 HandleUnionPtr handle(HandleUnion::New()); |
| 1158 handle->set_f_message_pipe(pipe1.Pass()); | 1160 handle->set_f_message_pipe(pipe1.Pass()); |
| 1159 | 1161 |
| 1160 size_t size = GetSerializedSize_(handle, false); | 1162 size_t size = GetSerializedSize_(handle); |
| 1161 EXPECT_EQ(16U, size); | 1163 EXPECT_EQ(16U, size); |
| 1162 | 1164 |
| 1163 mojo::internal::FixedBufferForTesting buf(size); | 1165 mojo::internal::FixedBufferForTesting buf(size); |
| 1164 internal::HandleUnion_Data* data = nullptr; | 1166 auto* data = internal::HandleUnion_Data::New(&buf); |
| 1165 SerializeUnion_(handle.get(), &buf, &data, false); | 1167 SerializeUnion_(handle.get(), &buf, &data); |
| 1166 | 1168 |
| 1167 std::vector<Handle> handles; | 1169 std::vector<Handle> handles; |
| 1168 data->EncodePointersAndHandles(&handles); | 1170 data->EncodePointersAndHandles(&handles); |
| 1169 | 1171 |
| 1170 void* raw_buf = buf.Leak(); | 1172 void* raw_buf = buf.Leak(); |
| 1171 mojo::internal::BoundsChecker bounds_checker(data, | 1173 mojo::internal::BoundsChecker bounds_checker(data, |
| 1172 static_cast<uint32_t>(size), 1); | 1174 static_cast<uint32_t>(size), 1); |
| 1173 EXPECT_EQ(mojo::internal::ValidationError::NONE, | 1175 EXPECT_EQ(mojo::internal::ValidationError::NONE, |
| 1174 internal::HandleUnion_Data::Validate(raw_buf, &bounds_checker, | 1176 internal::HandleUnion_Data::Validate(raw_buf, &bounds_checker, |
| 1175 false, nullptr)); | 1177 false, nullptr)); |
| 1176 free(raw_buf); | 1178 free(raw_buf); |
| 1177 } | 1179 } |
| 1178 | 1180 |
| 1179 TEST(UnionTest, HandleInUnionValidationNull) { | 1181 TEST(UnionTest, HandleInUnionValidationNull) { |
| 1180 Environment environment; | 1182 Environment environment; |
| 1181 ScopedMessagePipeHandle pipe; | 1183 ScopedMessagePipeHandle pipe; |
| 1182 HandleUnionPtr handle(HandleUnion::New()); | 1184 HandleUnionPtr handle(HandleUnion::New()); |
| 1183 handle->set_f_message_pipe(pipe.Pass()); | 1185 handle->set_f_message_pipe(pipe.Pass()); |
| 1184 | 1186 |
| 1185 size_t size = GetSerializedSize_(handle, false); | 1187 size_t size = GetSerializedSize_(handle); |
| 1186 EXPECT_EQ(16U, size); | 1188 EXPECT_EQ(16U, size); |
| 1187 | 1189 |
| 1188 mojo::internal::FixedBufferForTesting buf(size); | 1190 mojo::internal::FixedBufferForTesting buf(size); |
| 1189 internal::HandleUnion_Data* data = nullptr; | 1191 auto* data = internal::HandleUnion_Data::New(&buf); |
| 1190 SerializeUnion_(handle.get(), &buf, &data, false); | 1192 SerializeUnion_(handle.get(), &buf, &data); |
| 1191 | 1193 |
| 1192 std::vector<Handle> handles; | 1194 std::vector<Handle> handles; |
| 1193 data->EncodePointersAndHandles(&handles); | 1195 data->EncodePointersAndHandles(&handles); |
| 1194 | 1196 |
| 1195 void* raw_buf = buf.Leak(); | 1197 void* raw_buf = buf.Leak(); |
| 1196 mojo::internal::BoundsChecker bounds_checker(data, | 1198 mojo::internal::BoundsChecker bounds_checker(data, |
| 1197 static_cast<uint32_t>(size), 1); | 1199 static_cast<uint32_t>(size), 1); |
| 1198 EXPECT_NE(mojo::internal::ValidationError::NONE, | 1200 EXPECT_NE(mojo::internal::ValidationError::NONE, |
| 1199 internal::HandleUnion_Data::Validate(raw_buf, &bounds_checker, | 1201 internal::HandleUnion_Data::Validate(raw_buf, &bounds_checker, |
| 1200 false, nullptr)); | 1202 false, nullptr)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 | 1237 |
| 1236 TEST(UnionTest, InterfaceInUnionSerialization) { | 1238 TEST(UnionTest, InterfaceInUnionSerialization) { |
| 1237 Environment env; | 1239 Environment env; |
| 1238 RunLoop run_loop; | 1240 RunLoop run_loop; |
| 1239 SmallCacheImpl impl; | 1241 SmallCacheImpl impl; |
| 1240 SmallCachePtr ptr; | 1242 SmallCachePtr ptr; |
| 1241 Binding<SmallCache> bindings(&impl, GetProxy(&ptr)); | 1243 Binding<SmallCache> bindings(&impl, GetProxy(&ptr)); |
| 1242 | 1244 |
| 1243 HandleUnionPtr handle(HandleUnion::New()); | 1245 HandleUnionPtr handle(HandleUnion::New()); |
| 1244 handle->set_f_small_cache(ptr.Pass()); | 1246 handle->set_f_small_cache(ptr.Pass()); |
| 1245 size_t size = GetSerializedSize_(handle, false); | 1247 size_t size = GetSerializedSize_(handle); |
| 1246 EXPECT_EQ(16U, size); | 1248 EXPECT_EQ(16U, size); |
| 1247 | 1249 |
| 1248 mojo::internal::FixedBufferForTesting buf(size); | 1250 mojo::internal::FixedBufferForTesting buf(size); |
| 1249 internal::HandleUnion_Data* data = nullptr; | 1251 auto* data = internal::HandleUnion_Data::New(&buf); |
| 1250 SerializeUnion_(handle.get(), &buf, &data, false); | 1252 SerializeUnion_(handle.get(), &buf, &data); |
| 1251 | 1253 |
| 1252 std::vector<Handle> handles; | 1254 std::vector<Handle> handles; |
| 1253 data->EncodePointersAndHandles(&handles); | 1255 data->EncodePointersAndHandles(&handles); |
| 1254 EXPECT_EQ(1U, handles.size()); | 1256 EXPECT_EQ(1U, handles.size()); |
| 1255 data->DecodePointersAndHandles(&handles); | 1257 data->DecodePointersAndHandles(&handles); |
| 1256 | 1258 |
| 1257 HandleUnionPtr handle2(HandleUnion::New()); | 1259 HandleUnionPtr handle2(HandleUnion::New()); |
| 1258 Deserialize_(data, handle2.get()); | 1260 Deserialize_(data, handle2.get()); |
| 1259 | 1261 |
| 1260 auto small_cache = | 1262 auto small_cache = |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1285 PodUnionPtr pod(PodUnion::New()); | 1287 PodUnionPtr pod(PodUnion::New()); |
| 1286 pod->set_f_int16(16); | 1288 pod->set_f_int16(16); |
| 1287 | 1289 |
| 1288 ptr->Echo(pod.Pass(), | 1290 ptr->Echo(pod.Pass(), |
| 1289 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); | 1291 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); |
| 1290 run_loop.RunUntilIdle(); | 1292 run_loop.RunUntilIdle(); |
| 1291 } | 1293 } |
| 1292 | 1294 |
| 1293 } // namespace test | 1295 } // namespace test |
| 1294 } // namespace mojo | 1296 } // namespace mojo |
| OLD | NEW |