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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "mojo/message_pump/message_pump_mojo.h" | 8 #include "mojo/message_pump/message_pump_mojo.h" |
9 #include "mojo/public/cpp/bindings/array.h" | 9 #include "mojo/public/cpp/bindings/array.h" |
10 #include "mojo/public/cpp/bindings/binding.h" | 10 #include "mojo/public/cpp/bindings/binding.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 pod1->set_f_int8(10); | 119 pod1->set_f_int8(10); |
120 | 120 |
121 size_t size = GetSerializedSize_(pod1, false); | 121 size_t size = GetSerializedSize_(pod1, false); |
122 EXPECT_EQ(16U, size); | 122 EXPECT_EQ(16U, size); |
123 | 123 |
124 mojo::internal::FixedBufferForTesting buf(size); | 124 mojo::internal::FixedBufferForTesting buf(size); |
125 internal::PodUnion_Data* data = nullptr; | 125 internal::PodUnion_Data* data = nullptr; |
126 SerializeUnion_(pod1.Pass(), &buf, &data, false); | 126 SerializeUnion_(pod1.Pass(), &buf, &data, false); |
127 | 127 |
128 PodUnionPtr pod2; | 128 PodUnionPtr pod2; |
129 Deserialize_(data, &pod2); | 129 Deserialize_(data, &pod2, nullptr); |
130 | 130 |
131 EXPECT_EQ(10, pod2->get_f_int8()); | 131 EXPECT_EQ(10, pod2->get_f_int8()); |
132 EXPECT_TRUE(pod2->is_f_int8()); | 132 EXPECT_TRUE(pod2->is_f_int8()); |
133 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_INT8); | 133 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_INT8); |
134 } | 134 } |
135 | 135 |
136 TEST(UnionTest, EnumSerialization) { | 136 TEST(UnionTest, EnumSerialization) { |
137 PodUnionPtr pod1(PodUnion::New()); | 137 PodUnionPtr pod1(PodUnion::New()); |
138 pod1->set_f_enum(AN_ENUM_SECOND); | 138 pod1->set_f_enum(AN_ENUM_SECOND); |
139 | 139 |
140 size_t size = GetSerializedSize_(pod1, false); | 140 size_t size = GetSerializedSize_(pod1, false); |
141 EXPECT_EQ(16U, size); | 141 EXPECT_EQ(16U, size); |
142 | 142 |
143 mojo::internal::FixedBufferForTesting buf(size); | 143 mojo::internal::FixedBufferForTesting buf(size); |
144 internal::PodUnion_Data* data = nullptr; | 144 internal::PodUnion_Data* data = nullptr; |
145 SerializeUnion_(pod1.Pass(), &buf, &data, false); | 145 SerializeUnion_(pod1.Pass(), &buf, &data, false); |
146 | 146 |
147 PodUnionPtr pod2; | 147 PodUnionPtr pod2; |
148 Deserialize_(data, &pod2); | 148 Deserialize_(data, &pod2, nullptr); |
149 | 149 |
150 EXPECT_EQ(AN_ENUM_SECOND, pod2->get_f_enum()); | 150 EXPECT_EQ(AN_ENUM_SECOND, pod2->get_f_enum()); |
151 EXPECT_TRUE(pod2->is_f_enum()); | 151 EXPECT_TRUE(pod2->is_f_enum()); |
152 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_ENUM); | 152 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_ENUM); |
153 } | 153 } |
154 | 154 |
155 TEST(UnionTest, PodValidation) { | 155 TEST(UnionTest, PodValidation) { |
156 PodUnionPtr pod(PodUnion::New()); | 156 PodUnionPtr pod(PodUnion::New()); |
157 pod->set_f_int8(10); | 157 pod->set_f_int8(10); |
158 | 158 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 193 |
194 // Check that dirty output buffers are handled correctly by serialization. | 194 // Check that dirty output buffers are handled correctly by serialization. |
195 data->size = 16U; | 195 data->size = 16U; |
196 data->tag = PodUnion::Tag::F_UINT16; | 196 data->tag = PodUnion::Tag::F_UINT16; |
197 data->data.f_f_int16 = 20; | 197 data->data.f_f_int16 = 20; |
198 | 198 |
199 SerializeUnion_(pod.Pass(), &buf, &data, true); | 199 SerializeUnion_(pod.Pass(), &buf, &data, true); |
200 EXPECT_TRUE(data->is_null()); | 200 EXPECT_TRUE(data->is_null()); |
201 | 201 |
202 PodUnionPtr pod2; | 202 PodUnionPtr pod2; |
203 Deserialize_(data, &pod2); | 203 Deserialize_(data, &pod2, nullptr); |
204 EXPECT_TRUE(pod2.is_null()); | 204 EXPECT_TRUE(pod2.is_null()); |
205 } | 205 } |
206 | 206 |
207 TEST(UnionTest, SerializeIsNullNotInlined) { | 207 TEST(UnionTest, SerializeIsNullNotInlined) { |
208 PodUnionPtr pod; | 208 PodUnionPtr pod; |
209 size_t size = GetSerializedSize_(pod, false); | 209 size_t size = GetSerializedSize_(pod, false); |
210 EXPECT_EQ(16U, size); | 210 EXPECT_EQ(16U, size); |
211 mojo::internal::FixedBufferForTesting buf(size); | 211 mojo::internal::FixedBufferForTesting buf(size); |
212 internal::PodUnion_Data* data = nullptr; | 212 internal::PodUnion_Data* data = nullptr; |
213 SerializeUnion_(pod.Pass(), &buf, &data, false); | 213 SerializeUnion_(pod.Pass(), &buf, &data, false); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 size_t size = GetSerializedSize_(pod1, false); | 302 size_t size = GetSerializedSize_(pod1, false); |
303 mojo::internal::FixedBufferForTesting buf(size); | 303 mojo::internal::FixedBufferForTesting buf(size); |
304 internal::ObjectUnion_Data* data = nullptr; | 304 internal::ObjectUnion_Data* data = nullptr; |
305 SerializeUnion_(pod1.Pass(), &buf, &data, false); | 305 SerializeUnion_(pod1.Pass(), &buf, &data, false); |
306 | 306 |
307 std::vector<Handle> handles; | 307 std::vector<Handle> handles; |
308 data->EncodePointersAndHandles(&handles); | 308 data->EncodePointersAndHandles(&handles); |
309 data->DecodePointersAndHandles(&handles); | 309 data->DecodePointersAndHandles(&handles); |
310 | 310 |
311 ObjectUnionPtr pod2; | 311 ObjectUnionPtr pod2; |
312 Deserialize_(data, &pod2); | 312 Deserialize_(data, &pod2, nullptr); |
313 EXPECT_EQ(hello, pod2->get_f_string()); | 313 EXPECT_EQ(hello, pod2->get_f_string()); |
314 EXPECT_TRUE(pod2->is_f_string()); | 314 EXPECT_TRUE(pod2->is_f_string()); |
315 EXPECT_EQ(pod2->which(), ObjectUnion::Tag::F_STRING); | 315 EXPECT_EQ(pod2->which(), ObjectUnion::Tag::F_STRING); |
316 } | 316 } |
317 | 317 |
318 TEST(UnionTest, NullStringValidation) { | 318 TEST(UnionTest, NullStringValidation) { |
319 size_t size = sizeof(internal::ObjectUnion_Data); | 319 size_t size = sizeof(internal::ObjectUnion_Data); |
320 mojo::internal::FixedBufferForTesting buf(size); | 320 mojo::internal::FixedBufferForTesting buf(size); |
321 internal::ObjectUnion_Data* data = internal::ObjectUnion_Data::New(&buf); | 321 internal::ObjectUnion_Data* data = internal::ObjectUnion_Data::New(&buf); |
322 data->tag = internal::ObjectUnion_Data::ObjectUnion_Tag::F_STRING; | 322 data->tag = internal::ObjectUnion_Data::ObjectUnion_Tag::F_STRING; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 388 |
389 size_t size = GetSerializedSize_(array); | 389 size_t size = GetSerializedSize_(array); |
390 EXPECT_EQ(40U, size); | 390 EXPECT_EQ(40U, size); |
391 | 391 |
392 mojo::internal::FixedBufferForTesting buf(size); | 392 mojo::internal::FixedBufferForTesting buf(size); |
393 mojo::internal::Array_Data<internal::PodUnion_Data>* data; | 393 mojo::internal::Array_Data<internal::PodUnion_Data>* data; |
394 mojo::internal::ArrayValidateParams validate_params(0, false, nullptr); | 394 mojo::internal::ArrayValidateParams validate_params(0, false, nullptr); |
395 SerializeArray_(array.Pass(), &buf, &data, &validate_params); | 395 SerializeArray_(array.Pass(), &buf, &data, &validate_params); |
396 | 396 |
397 Array<PodUnionPtr> array2; | 397 Array<PodUnionPtr> array2; |
398 Deserialize_(data, &array2); | 398 Deserialize_(data, &array2, nullptr); |
399 | 399 |
400 EXPECT_EQ(2U, array2.size()); | 400 EXPECT_EQ(2U, array2.size()); |
401 | 401 |
402 EXPECT_EQ(10, array2[0]->get_f_int8()); | 402 EXPECT_EQ(10, array2[0]->get_f_int8()); |
403 EXPECT_EQ(12, array2[1]->get_f_int16()); | 403 EXPECT_EQ(12, array2[1]->get_f_int16()); |
404 } | 404 } |
405 | 405 |
406 TEST(UnionTest, PodUnionInArraySerializationWithNull) { | 406 TEST(UnionTest, PodUnionInArraySerializationWithNull) { |
407 Array<PodUnionPtr> array(2); | 407 Array<PodUnionPtr> array(2); |
408 array[0] = PodUnion::New(); | 408 array[0] = PodUnion::New(); |
409 | 409 |
410 array[0]->set_f_int8(10); | 410 array[0]->set_f_int8(10); |
411 EXPECT_EQ(2U, array.size()); | 411 EXPECT_EQ(2U, array.size()); |
412 | 412 |
413 size_t size = GetSerializedSize_(array); | 413 size_t size = GetSerializedSize_(array); |
414 EXPECT_EQ(40U, size); | 414 EXPECT_EQ(40U, size); |
415 | 415 |
416 mojo::internal::FixedBufferForTesting buf(size); | 416 mojo::internal::FixedBufferForTesting buf(size); |
417 mojo::internal::Array_Data<internal::PodUnion_Data>* data; | 417 mojo::internal::Array_Data<internal::PodUnion_Data>* data; |
418 mojo::internal::ArrayValidateParams validate_params(0, true, nullptr); | 418 mojo::internal::ArrayValidateParams validate_params(0, true, nullptr); |
419 SerializeArray_(array.Pass(), &buf, &data, &validate_params); | 419 SerializeArray_(array.Pass(), &buf, &data, &validate_params); |
420 | 420 |
421 Array<PodUnionPtr> array2; | 421 Array<PodUnionPtr> array2; |
422 Deserialize_(data, &array2); | 422 Deserialize_(data, &array2, nullptr); |
423 | 423 |
424 EXPECT_EQ(2U, array2.size()); | 424 EXPECT_EQ(2U, array2.size()); |
425 | 425 |
426 EXPECT_EQ(10, array2[0]->get_f_int8()); | 426 EXPECT_EQ(10, array2[0]->get_f_int8()); |
427 EXPECT_TRUE(array2[1].is_null()); | 427 EXPECT_TRUE(array2[1].is_null()); |
428 } | 428 } |
429 | 429 |
430 // TODO(azani): Move back in struct_unittest.cc when possible. | 430 // TODO(azani): Move back in struct_unittest.cc when possible. |
431 // Struct tests | 431 // Struct tests |
432 TEST(UnionTest, Clone_Union) { | 432 TEST(UnionTest, Clone_Union) { |
(...skipping 11 matching lines...) Expand all Loading... |
444 small_struct->pod_union = PodUnion::New(); | 444 small_struct->pod_union = PodUnion::New(); |
445 small_struct->pod_union->set_f_int32(10); | 445 small_struct->pod_union->set_f_int32(10); |
446 | 446 |
447 size_t size = GetSerializedSize_(small_struct); | 447 size_t size = GetSerializedSize_(small_struct); |
448 | 448 |
449 mojo::internal::FixedBufferForTesting buf(size); | 449 mojo::internal::FixedBufferForTesting buf(size); |
450 internal::SmallStruct_Data* data = nullptr; | 450 internal::SmallStruct_Data* data = nullptr; |
451 Serialize_(small_struct.Pass(), &buf, &data); | 451 Serialize_(small_struct.Pass(), &buf, &data); |
452 | 452 |
453 SmallStructPtr deserialized; | 453 SmallStructPtr deserialized; |
454 Deserialize_(data, &deserialized); | 454 Deserialize_(data, &deserialized, nullptr); |
455 | 455 |
456 EXPECT_EQ(10, deserialized->pod_union->get_f_int32()); | 456 EXPECT_EQ(10, deserialized->pod_union->get_f_int32()); |
457 } | 457 } |
458 | 458 |
459 // Serialization test of a struct with a union of structs. | 459 // Serialization test of a struct with a union of structs. |
460 TEST(UnionTest, Serialization_UnionOfObjects) { | 460 TEST(UnionTest, Serialization_UnionOfObjects) { |
461 SmallObjStructPtr obj_struct(SmallObjStruct::New()); | 461 SmallObjStructPtr obj_struct(SmallObjStruct::New()); |
462 obj_struct->obj_union = ObjectUnion::New(); | 462 obj_struct->obj_union = ObjectUnion::New(); |
463 String hello("hello world"); | 463 String hello("hello world"); |
464 obj_struct->obj_union->set_f_string(hello); | 464 obj_struct->obj_union->set_f_string(hello); |
465 | 465 |
466 size_t size = GetSerializedSize_(obj_struct); | 466 size_t size = GetSerializedSize_(obj_struct); |
467 | 467 |
468 mojo::internal::FixedBufferForTesting buf(size); | 468 mojo::internal::FixedBufferForTesting buf(size); |
469 internal::SmallObjStruct_Data* data = nullptr; | 469 internal::SmallObjStruct_Data* data = nullptr; |
470 Serialize_(obj_struct.Pass(), &buf, &data); | 470 Serialize_(obj_struct.Pass(), &buf, &data); |
471 | 471 |
472 std::vector<Handle> handles; | 472 std::vector<Handle> handles; |
473 data->EncodePointersAndHandles(&handles); | 473 data->EncodePointersAndHandles(&handles); |
474 data->DecodePointersAndHandles(&handles); | 474 data->DecodePointersAndHandles(&handles); |
475 | 475 |
476 SmallObjStructPtr deserialized; | 476 SmallObjStructPtr deserialized; |
477 Deserialize_(data, &deserialized); | 477 Deserialize_(data, &deserialized, nullptr); |
478 | 478 |
479 EXPECT_EQ(hello, deserialized->obj_union->get_f_string()); | 479 EXPECT_EQ(hello, deserialized->obj_union->get_f_string()); |
480 } | 480 } |
481 | 481 |
482 // Validation test of a struct with a union. | 482 // Validation test of a struct with a union. |
483 TEST(UnionTest, Validation_UnionsInStruct) { | 483 TEST(UnionTest, Validation_UnionsInStruct) { |
484 SmallStructPtr small_struct(SmallStruct::New()); | 484 SmallStructPtr small_struct(SmallStruct::New()); |
485 small_struct->pod_union = PodUnion::New(); | 485 small_struct->pod_union = PodUnion::New(); |
486 small_struct->pod_union->set_f_int32(10); | 486 small_struct->pod_union->set_f_int32(10); |
487 | 487 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 size_t size = GetSerializedSize_(map); | 592 size_t size = GetSerializedSize_(map); |
593 EXPECT_EQ(120U, size); | 593 EXPECT_EQ(120U, size); |
594 | 594 |
595 mojo::internal::FixedBufferForTesting buf(size); | 595 mojo::internal::FixedBufferForTesting buf(size); |
596 mojo::internal::Map_Data<mojo::internal::String_Data*, | 596 mojo::internal::Map_Data<mojo::internal::String_Data*, |
597 internal::PodUnion_Data>* data; | 597 internal::PodUnion_Data>* data; |
598 mojo::internal::ArrayValidateParams validate_params(0, false, nullptr); | 598 mojo::internal::ArrayValidateParams validate_params(0, false, nullptr); |
599 SerializeMap_(map.Pass(), &buf, &data, &validate_params); | 599 SerializeMap_(map.Pass(), &buf, &data, &validate_params); |
600 | 600 |
601 Map<String, PodUnionPtr> map2; | 601 Map<String, PodUnionPtr> map2; |
602 Deserialize_(data, &map2); | 602 Deserialize_(data, &map2, nullptr); |
603 | 603 |
604 EXPECT_EQ(8, map2["one"]->get_f_int8()); | 604 EXPECT_EQ(8, map2["one"]->get_f_int8()); |
605 EXPECT_EQ(16, map2["two"]->get_f_int16()); | 605 EXPECT_EQ(16, map2["two"]->get_f_int16()); |
606 } | 606 } |
607 | 607 |
608 TEST(UnionTest, PodUnionInMapSerializationWithNull) { | 608 TEST(UnionTest, PodUnionInMapSerializationWithNull) { |
609 Map<String, PodUnionPtr> map; | 609 Map<String, PodUnionPtr> map; |
610 map.insert("one", PodUnion::New()); | 610 map.insert("one", PodUnion::New()); |
611 map.insert("two", nullptr); | 611 map.insert("two", nullptr); |
612 | 612 |
613 map["one"]->set_f_int8(8); | 613 map["one"]->set_f_int8(8); |
614 | 614 |
615 size_t size = GetSerializedSize_(map); | 615 size_t size = GetSerializedSize_(map); |
616 EXPECT_EQ(120U, size); | 616 EXPECT_EQ(120U, size); |
617 | 617 |
618 mojo::internal::FixedBufferForTesting buf(size); | 618 mojo::internal::FixedBufferForTesting buf(size); |
619 mojo::internal::Map_Data<mojo::internal::String_Data*, | 619 mojo::internal::Map_Data<mojo::internal::String_Data*, |
620 internal::PodUnion_Data>* data; | 620 internal::PodUnion_Data>* data; |
621 mojo::internal::ArrayValidateParams validate_params(0, true, nullptr); | 621 mojo::internal::ArrayValidateParams validate_params(0, true, nullptr); |
622 SerializeMap_(map.Pass(), &buf, &data, &validate_params); | 622 SerializeMap_(map.Pass(), &buf, &data, &validate_params); |
623 | 623 |
624 Map<String, PodUnionPtr> map2; | 624 Map<String, PodUnionPtr> map2; |
625 Deserialize_(data, &map2); | 625 Deserialize_(data, &map2, nullptr); |
626 | 626 |
627 EXPECT_EQ(8, map2["one"]->get_f_int8()); | 627 EXPECT_EQ(8, map2["one"]->get_f_int8()); |
628 EXPECT_TRUE(map2["two"].is_null()); | 628 EXPECT_TRUE(map2["two"].is_null()); |
629 } | 629 } |
630 | 630 |
631 TEST(UnionTest, StructInUnionGetterSetterPasser) { | 631 TEST(UnionTest, StructInUnionGetterSetterPasser) { |
632 DummyStructPtr dummy(DummyStruct::New()); | 632 DummyStructPtr dummy(DummyStruct::New()); |
633 dummy->f_int8 = 8; | 633 dummy->f_int8 = 8; |
634 | 634 |
635 ObjectUnionPtr obj(ObjectUnion::New()); | 635 ObjectUnionPtr obj(ObjectUnion::New()); |
(...skipping 14 matching lines...) Expand all Loading... |
650 | 650 |
651 mojo::internal::FixedBufferForTesting buf(size); | 651 mojo::internal::FixedBufferForTesting buf(size); |
652 internal::ObjectUnion_Data* data = nullptr; | 652 internal::ObjectUnion_Data* data = nullptr; |
653 SerializeUnion_(obj.Pass(), &buf, &data, false); | 653 SerializeUnion_(obj.Pass(), &buf, &data, false); |
654 | 654 |
655 std::vector<Handle> handles; | 655 std::vector<Handle> handles; |
656 data->EncodePointersAndHandles(&handles); | 656 data->EncodePointersAndHandles(&handles); |
657 data->DecodePointersAndHandles(&handles); | 657 data->DecodePointersAndHandles(&handles); |
658 | 658 |
659 ObjectUnionPtr obj2; | 659 ObjectUnionPtr obj2; |
660 Deserialize_(data, &obj2); | 660 Deserialize_(data, &obj2, nullptr); |
661 EXPECT_EQ(8, obj2->get_f_dummy()->f_int8); | 661 EXPECT_EQ(8, obj2->get_f_dummy()->f_int8); |
662 } | 662 } |
663 | 663 |
664 TEST(UnionTest, StructInUnionValidation) { | 664 TEST(UnionTest, StructInUnionValidation) { |
665 DummyStructPtr dummy(DummyStruct::New()); | 665 DummyStructPtr dummy(DummyStruct::New()); |
666 dummy->f_int8 = 8; | 666 dummy->f_int8 = 8; |
667 | 667 |
668 ObjectUnionPtr obj(ObjectUnion::New()); | 668 ObjectUnionPtr obj(ObjectUnion::New()); |
669 obj->set_f_dummy(dummy.Pass()); | 669 obj->set_f_dummy(dummy.Pass()); |
670 | 670 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 | 759 |
760 mojo::internal::FixedBufferForTesting buf(size); | 760 mojo::internal::FixedBufferForTesting buf(size); |
761 internal::ObjectUnion_Data* data = nullptr; | 761 internal::ObjectUnion_Data* data = nullptr; |
762 SerializeUnion_(obj.Pass(), &buf, &data, false); | 762 SerializeUnion_(obj.Pass(), &buf, &data, false); |
763 | 763 |
764 std::vector<Handle> handles; | 764 std::vector<Handle> handles; |
765 data->EncodePointersAndHandles(&handles); | 765 data->EncodePointersAndHandles(&handles); |
766 data->DecodePointersAndHandles(&handles); | 766 data->DecodePointersAndHandles(&handles); |
767 | 767 |
768 ObjectUnionPtr obj2; | 768 ObjectUnionPtr obj2; |
769 Deserialize_(data, &obj2); | 769 Deserialize_(data, &obj2, nullptr); |
770 | 770 |
771 EXPECT_EQ(8, obj2->get_f_array_int8()[0]); | 771 EXPECT_EQ(8, obj2->get_f_array_int8()[0]); |
772 EXPECT_EQ(9, obj2->get_f_array_int8()[1]); | 772 EXPECT_EQ(9, obj2->get_f_array_int8()[1]); |
773 } | 773 } |
774 | 774 |
775 TEST(UnionTest, ArrayInUnionValidation) { | 775 TEST(UnionTest, ArrayInUnionValidation) { |
776 Array<int8_t> array(2); | 776 Array<int8_t> array(2); |
777 array[0] = 8; | 777 array[0] = 8; |
778 array[1] = 9; | 778 array[1] = 9; |
779 | 779 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 | 822 |
823 mojo::internal::FixedBufferForTesting buf(size); | 823 mojo::internal::FixedBufferForTesting buf(size); |
824 internal::ObjectUnion_Data* data = nullptr; | 824 internal::ObjectUnion_Data* data = nullptr; |
825 SerializeUnion_(obj.Pass(), &buf, &data, false); | 825 SerializeUnion_(obj.Pass(), &buf, &data, false); |
826 | 826 |
827 std::vector<Handle> handles; | 827 std::vector<Handle> handles; |
828 data->EncodePointersAndHandles(&handles); | 828 data->EncodePointersAndHandles(&handles); |
829 data->DecodePointersAndHandles(&handles); | 829 data->DecodePointersAndHandles(&handles); |
830 | 830 |
831 ObjectUnionPtr obj2; | 831 ObjectUnionPtr obj2; |
832 Deserialize_(data, &obj2); | 832 Deserialize_(data, &obj2, nullptr); |
833 | 833 |
834 EXPECT_EQ(1, obj2->get_f_map_int8()["one"]); | 834 EXPECT_EQ(1, obj2->get_f_map_int8()["one"]); |
835 EXPECT_EQ(2, obj2->get_f_map_int8()["two"]); | 835 EXPECT_EQ(2, obj2->get_f_map_int8()["two"]); |
836 } | 836 } |
837 | 837 |
838 TEST(UnionTest, MapInUnionValidation) { | 838 TEST(UnionTest, MapInUnionValidation) { |
839 Map<String, int8_t> map; | 839 Map<String, int8_t> map; |
840 map.insert("one", 1); | 840 map.insert("one", 1); |
841 map.insert("two", 2); | 841 map.insert("two", 2); |
842 | 842 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 | 885 |
886 mojo::internal::FixedBufferForTesting buf(size); | 886 mojo::internal::FixedBufferForTesting buf(size); |
887 internal::ObjectUnion_Data* data = nullptr; | 887 internal::ObjectUnion_Data* data = nullptr; |
888 SerializeUnion_(obj.Pass(), &buf, &data, false); | 888 SerializeUnion_(obj.Pass(), &buf, &data, false); |
889 | 889 |
890 std::vector<Handle> handles; | 890 std::vector<Handle> handles; |
891 data->EncodePointersAndHandles(&handles); | 891 data->EncodePointersAndHandles(&handles); |
892 data->DecodePointersAndHandles(&handles); | 892 data->DecodePointersAndHandles(&handles); |
893 | 893 |
894 ObjectUnionPtr obj2; | 894 ObjectUnionPtr obj2; |
895 Deserialize_(data, &obj2); | 895 Deserialize_(data, &obj2, nullptr); |
896 EXPECT_EQ(10, obj2->get_f_pod_union()->get_f_int8()); | 896 EXPECT_EQ(10, obj2->get_f_pod_union()->get_f_int8()); |
897 } | 897 } |
898 | 898 |
899 TEST(UnionTest, UnionInUnionValidation) { | 899 TEST(UnionTest, UnionInUnionValidation) { |
900 PodUnionPtr pod(PodUnion::New()); | 900 PodUnionPtr pod(PodUnion::New()); |
901 pod->set_f_int8(10); | 901 pod->set_f_int8(10); |
902 | 902 |
903 ObjectUnionPtr obj(ObjectUnion::New()); | 903 ObjectUnionPtr obj(ObjectUnion::New()); |
904 obj->set_f_pod_union(pod.Pass()); | 904 obj->set_f_pod_union(pod.Pass()); |
905 | 905 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 mojo::internal::FixedBufferForTesting buf(size); | 977 mojo::internal::FixedBufferForTesting buf(size); |
978 internal::HandleUnion_Data* data = nullptr; | 978 internal::HandleUnion_Data* data = nullptr; |
979 SerializeUnion_(handle.Pass(), &buf, &data, false); | 979 SerializeUnion_(handle.Pass(), &buf, &data, false); |
980 | 980 |
981 std::vector<Handle> handles; | 981 std::vector<Handle> handles; |
982 data->EncodePointersAndHandles(&handles); | 982 data->EncodePointersAndHandles(&handles); |
983 EXPECT_EQ(1U, handles.size()); | 983 EXPECT_EQ(1U, handles.size()); |
984 data->DecodePointersAndHandles(&handles); | 984 data->DecodePointersAndHandles(&handles); |
985 | 985 |
986 HandleUnionPtr handle2(HandleUnion::New()); | 986 HandleUnionPtr handle2(HandleUnion::New()); |
987 Deserialize_(data, &handle2); | 987 Deserialize_(data, &handle2, nullptr); |
988 | 988 |
989 std::string golden("hello world"); | 989 std::string golden("hello world"); |
990 WriteTextMessage(pipe0.get(), golden); | 990 WriteTextMessage(pipe0.get(), golden); |
991 | 991 |
992 std::string actual; | 992 std::string actual; |
993 ReadTextMessage(handle2->get_f_message_pipe().get(), &actual); | 993 ReadTextMessage(handle2->get_f_message_pipe().get(), &actual); |
994 | 994 |
995 EXPECT_EQ(golden, actual); | 995 EXPECT_EQ(golden, actual); |
996 } | 996 } |
997 | 997 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 mojo::internal::FixedBufferForTesting buf(size); | 1088 mojo::internal::FixedBufferForTesting buf(size); |
1089 internal::HandleUnion_Data* data = nullptr; | 1089 internal::HandleUnion_Data* data = nullptr; |
1090 SerializeUnion_(handle.Pass(), &buf, &data, false); | 1090 SerializeUnion_(handle.Pass(), &buf, &data, false); |
1091 | 1091 |
1092 std::vector<Handle> handles; | 1092 std::vector<Handle> handles; |
1093 data->EncodePointersAndHandles(&handles); | 1093 data->EncodePointersAndHandles(&handles); |
1094 EXPECT_EQ(1U, handles.size()); | 1094 EXPECT_EQ(1U, handles.size()); |
1095 data->DecodePointersAndHandles(&handles); | 1095 data->DecodePointersAndHandles(&handles); |
1096 | 1096 |
1097 HandleUnionPtr handle2(HandleUnion::New()); | 1097 HandleUnionPtr handle2(HandleUnion::New()); |
1098 Deserialize_(data, &handle2); | 1098 Deserialize_(data, &handle2, nullptr); |
1099 | 1099 |
1100 handle2->get_f_small_cache()->SetIntValue(10); | 1100 handle2->get_f_small_cache()->SetIntValue(10); |
1101 run_loop.RunUntilIdle(); | 1101 run_loop.RunUntilIdle(); |
1102 EXPECT_EQ(10, impl.int_value()); | 1102 EXPECT_EQ(10, impl.int_value()); |
1103 } | 1103 } |
1104 | 1104 |
1105 class UnionInterfaceImpl : public UnionInterface { | 1105 class UnionInterfaceImpl : public UnionInterface { |
1106 public: | 1106 public: |
1107 UnionInterfaceImpl() {} | 1107 UnionInterfaceImpl() {} |
1108 ~UnionInterfaceImpl() override {} | 1108 ~UnionInterfaceImpl() override {} |
(...skipping 13 matching lines...) Expand all Loading... |
1122 PodUnionPtr pod(PodUnion::New()); | 1122 PodUnionPtr pod(PodUnion::New()); |
1123 pod->set_f_int16(16); | 1123 pod->set_f_int16(16); |
1124 | 1124 |
1125 ptr->Echo(pod.Pass(), | 1125 ptr->Echo(pod.Pass(), |
1126 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); | 1126 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); |
1127 run_loop.RunUntilIdle(); | 1127 run_loop.RunUntilIdle(); |
1128 } | 1128 } |
1129 | 1129 |
1130 } // namespace test | 1130 } // namespace test |
1131 } // namespace mojo | 1131 } // namespace mojo |
OLD | NEW |