Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: mojo/public/cpp/bindings/tests/union_unittest.cc

Issue 2136733002: Mojo C++ bindings: add a new mode to generator to use native STL/WTF types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@67_new
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 void* raw_buf = buf.Leak(); 406 void* raw_buf = buf.Leak();
407 EXPECT_FALSE(internal::ObjectUnion_Data::Validate( 407 EXPECT_FALSE(internal::ObjectUnion_Data::Validate(
408 raw_buf, &validation_context, false)); 408 raw_buf, &validation_context, false));
409 free(raw_buf); 409 free(raw_buf);
410 } 410 }
411 411
412 // TODO(azani): Move back in array_unittest.cc when possible. 412 // TODO(azani): Move back in array_unittest.cc when possible.
413 // Array tests 413 // Array tests
414 TEST(UnionTest, PodUnionInArray) { 414 TEST(UnionTest, PodUnionInArray) {
415 SmallStructPtr small_struct(SmallStruct::New()); 415 SmallStructPtr small_struct(SmallStruct::New());
416 small_struct->pod_union_array = Array<PodUnionPtr>(2); 416 small_struct->pod_union_array.emplace(2);
417 small_struct->pod_union_array[0] = PodUnion::New(); 417 small_struct->pod_union_array.value()[0] = PodUnion::New();
418 small_struct->pod_union_array[1] = PodUnion::New(); 418 small_struct->pod_union_array.value()[1] = PodUnion::New();
419 419
420 small_struct->pod_union_array[0]->set_f_int8(10); 420 small_struct->pod_union_array.value()[0]->set_f_int8(10);
421 small_struct->pod_union_array[1]->set_f_int16(12); 421 small_struct->pod_union_array.value()[1]->set_f_int16(12);
422 422
423 EXPECT_EQ(10, small_struct->pod_union_array[0]->get_f_int8()); 423 EXPECT_EQ(10, small_struct->pod_union_array.value()[0]->get_f_int8());
424 EXPECT_EQ(12, small_struct->pod_union_array[1]->get_f_int16()); 424 EXPECT_EQ(12, small_struct->pod_union_array.value()[1]->get_f_int16());
425 } 425 }
426 426
427 TEST(UnionTest, PodUnionInArraySerialization) { 427 TEST(UnionTest, PodUnionInArraySerialization) {
428 Array<PodUnionPtr> array(2); 428 Array<PodUnionPtr> array(2);
429 array[0] = PodUnion::New(); 429 array[0] = PodUnion::New();
430 array[1] = PodUnion::New(); 430 array[1] = PodUnion::New();
431 431
432 array[0]->set_f_int8(10); 432 array[0]->set_f_int8(10);
433 array[1]->set_f_int16(12); 433 array[1]->set_f_int16(12);
434 EXPECT_EQ(2U, array.size()); 434 EXPECT_EQ(2U, array.size());
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 data, static_cast<uint32_t>(size), 0); 662 data, static_cast<uint32_t>(size), 0);
663 EXPECT_TRUE(internal::SmallStruct_Data::Validate( 663 EXPECT_TRUE(internal::SmallStruct_Data::Validate(
664 raw_buf, &validation_context)); 664 raw_buf, &validation_context));
665 free(raw_buf); 665 free(raw_buf);
666 } 666 }
667 667
668 // TODO(azani): Move back in map_unittest.cc when possible. 668 // TODO(azani): Move back in map_unittest.cc when possible.
669 // Map Tests 669 // Map Tests
670 TEST(UnionTest, PodUnionInMap) { 670 TEST(UnionTest, PodUnionInMap) {
671 SmallStructPtr small_struct(SmallStruct::New()); 671 SmallStructPtr small_struct(SmallStruct::New());
672 small_struct->pod_union_map = Map<String, PodUnionPtr>(); 672 small_struct->pod_union_map.emplace();
673 small_struct->pod_union_map.insert("one", PodUnion::New()); 673 small_struct->pod_union_map.value()["one"] = PodUnion::New();
674 small_struct->pod_union_map.insert("two", PodUnion::New()); 674 small_struct->pod_union_map.value()["two"] = PodUnion::New();
675 675
676 small_struct->pod_union_map["one"]->set_f_int8(8); 676 small_struct->pod_union_map.value()["one"]->set_f_int8(8);
677 small_struct->pod_union_map["two"]->set_f_int16(16); 677 small_struct->pod_union_map.value()["two"]->set_f_int16(16);
678 678
679 EXPECT_EQ(8, small_struct->pod_union_map["one"]->get_f_int8()); 679 EXPECT_EQ(8, small_struct->pod_union_map.value()["one"]->get_f_int8());
680 EXPECT_EQ(16, small_struct->pod_union_map["two"]->get_f_int16()); 680 EXPECT_EQ(16, small_struct->pod_union_map.value()["two"]->get_f_int16());
681 } 681 }
682 682
683 TEST(UnionTest, PodUnionInMapSerialization) { 683 TEST(UnionTest, PodUnionInMapSerialization) {
684 Map<String, PodUnionPtr> map; 684 Map<String, PodUnionPtr> map;
685 map.insert("one", PodUnion::New()); 685 map.insert("one", PodUnion::New());
686 map.insert("two", PodUnion::New()); 686 map.insert("two", PodUnion::New());
687 687
688 map["one"]->set_f_int8(8); 688 map["one"]->set_f_int8(8);
689 map["two"]->set_f_int16(16); 689 map["two"]->set_f_int16(16);
690 690
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 void* raw_buf = buf.Leak(); 885 void* raw_buf = buf.Leak();
886 mojo::internal::ValidationContext validation_context( 886 mojo::internal::ValidationContext validation_context(
887 data, static_cast<uint32_t>(size), 0); 887 data, static_cast<uint32_t>(size), 0);
888 888
889 EXPECT_TRUE(internal::ObjectUnion_Data::Validate( 889 EXPECT_TRUE(internal::ObjectUnion_Data::Validate(
890 raw_buf, &validation_context, false)); 890 raw_buf, &validation_context, false));
891 free(raw_buf); 891 free(raw_buf);
892 } 892 }
893 893
894 TEST(UnionTest, MapInUnionGetterSetter) { 894 TEST(UnionTest, MapInUnionGetterSetter) {
895 Map<String, int8_t> map; 895 std::unordered_map<std::string, int8_t> map;
896 map.insert("one", 1); 896 map.insert({"one", 1});
897 map.insert("two", 2); 897 map.insert({"two", 2});
898 898
899 ObjectUnionPtr obj(ObjectUnion::New()); 899 ObjectUnionPtr obj(ObjectUnion::New());
900 obj->set_f_map_int8(std::move(map)); 900 obj->set_f_map_int8(std::move(map));
901 901
902 EXPECT_EQ(1, obj->get_f_map_int8()["one"]); 902 EXPECT_EQ(1, obj->get_f_map_int8()["one"]);
903 EXPECT_EQ(2, obj->get_f_map_int8()["two"]); 903 EXPECT_EQ(2, obj->get_f_map_int8()["two"]);
904 } 904 }
905 905
906 TEST(UnionTest, MapInUnionSerialization) { 906 TEST(UnionTest, MapInUnionSerialization) {
907 Map<String, int8_t> map; 907 std::unordered_map<std::string, int8_t> map;
908 map.insert("one", 1); 908 map.insert({"one", 1});
909 map.insert("two", 2); 909 map.insert({"two", 2});
910 910
911 ObjectUnionPtr obj(ObjectUnion::New()); 911 ObjectUnionPtr obj(ObjectUnion::New());
912 obj->set_f_map_int8(std::move(map)); 912 obj->set_f_map_int8(std::move(map));
913 913
914 mojo::internal::SerializationContext context; 914 mojo::internal::SerializationContext context;
915 size_t size = 915 size_t size =
916 mojo::internal::PrepareToSerialize<ObjectUnionPtr>(obj, false, &context); 916 mojo::internal::PrepareToSerialize<ObjectUnionPtr>(obj, false, &context);
917 EXPECT_EQ(112U, size); 917 EXPECT_EQ(112U, size);
918 918
919 mojo::internal::FixedBufferForTesting buf(size); 919 mojo::internal::FixedBufferForTesting buf(size);
920 internal::ObjectUnion_Data* data = nullptr; 920 internal::ObjectUnion_Data* data = nullptr;
921 mojo::internal::Serialize<ObjectUnionPtr>(obj, &buf, &data, false, &context); 921 mojo::internal::Serialize<ObjectUnionPtr>(obj, &buf, &data, false, &context);
922 922
923 ObjectUnionPtr obj2; 923 ObjectUnionPtr obj2;
924 mojo::internal::Deserialize<ObjectUnionPtr>(data, &obj2, &context); 924 mojo::internal::Deserialize<ObjectUnionPtr>(data, &obj2, &context);
925 925
926 EXPECT_EQ(1, obj2->get_f_map_int8()["one"]); 926 EXPECT_EQ(1, obj2->get_f_map_int8()["one"]);
927 EXPECT_EQ(2, obj2->get_f_map_int8()["two"]); 927 EXPECT_EQ(2, obj2->get_f_map_int8()["two"]);
928 } 928 }
929 929
930 TEST(UnionTest, MapInUnionValidation) { 930 TEST(UnionTest, MapInUnionValidation) {
931 Map<String, int8_t> map; 931 std::unordered_map<std::string, int8_t> map;
932 map.insert("one", 1); 932 map.insert({"one", 1});
933 map.insert("two", 2); 933 map.insert({"two", 2});
934 934
935 ObjectUnionPtr obj(ObjectUnion::New()); 935 ObjectUnionPtr obj(ObjectUnion::New());
936 obj->set_f_map_int8(std::move(map)); 936 obj->set_f_map_int8(std::move(map));
937 937
938 mojo::internal::SerializationContext context; 938 mojo::internal::SerializationContext context;
939 size_t size = 939 size_t size =
940 mojo::internal::PrepareToSerialize<ObjectUnionPtr>(obj, false, &context); 940 mojo::internal::PrepareToSerialize<ObjectUnionPtr>(obj, false, &context);
941 EXPECT_EQ(112U, size); 941 EXPECT_EQ(112U, size);
942 942
943 mojo::internal::FixedBufferForTesting buf(size); 943 mojo::internal::FixedBufferForTesting buf(size);
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 1217
1218 PodUnionPtr pod(PodUnion::New()); 1218 PodUnionPtr pod(PodUnion::New());
1219 pod->set_f_int16(16); 1219 pod->set_f_int16(16);
1220 1220
1221 ptr->Echo(std::move(pod), base::Bind(&ExpectInt16, 16)); 1221 ptr->Echo(std::move(pod), base::Bind(&ExpectInt16, 16));
1222 base::RunLoop().RunUntilIdle(); 1222 base::RunLoop().RunUntilIdle();
1223 } 1223 }
1224 1224
1225 } // namespace test 1225 } // namespace test
1226 } // namespace mojo 1226 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/type_conversion_unittest.cc ('k') | mojo/public/cpp/bindings/tests/wtf_types_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698