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

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

Issue 2030873002: Mojo C++ bindings: rename ArrayValidateParams for clarity (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cc-enums
Patch Set: Rebase Created 4 years, 6 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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 array[0]->set_f_int8(10); 433 array[0]->set_f_int8(10);
434 array[1]->set_f_int16(12); 434 array[1]->set_f_int16(12);
435 EXPECT_EQ(2U, array.size()); 435 EXPECT_EQ(2U, array.size());
436 436
437 size_t size = 437 size_t size =
438 mojo::internal::PrepareToSerialize<Array<PodUnionPtr>>(array, nullptr); 438 mojo::internal::PrepareToSerialize<Array<PodUnionPtr>>(array, nullptr);
439 EXPECT_EQ(40U, size); 439 EXPECT_EQ(40U, size);
440 440
441 mojo::internal::FixedBufferForTesting buf(size); 441 mojo::internal::FixedBufferForTesting buf(size);
442 mojo::internal::Array_Data<internal::PodUnion_Data>* data; 442 mojo::internal::Array_Data<internal::PodUnion_Data>* data;
443 mojo::internal::ArrayValidateParams validate_params(0, false, nullptr); 443 mojo::internal::ContainerValidateParams validate_params(0, false, nullptr);
444 mojo::internal::Serialize<Array<PodUnionPtr>>(array, &buf, &data, 444 mojo::internal::Serialize<Array<PodUnionPtr>>(array, &buf, &data,
445 &validate_params, nullptr); 445 &validate_params, nullptr);
446 446
447 Array<PodUnionPtr> array2; 447 Array<PodUnionPtr> array2;
448 mojo::internal::Deserialize<Array<PodUnionPtr>>(data, &array2, nullptr); 448 mojo::internal::Deserialize<Array<PodUnionPtr>>(data, &array2, nullptr);
449 449
450 EXPECT_EQ(2U, array2.size()); 450 EXPECT_EQ(2U, array2.size());
451 451
452 EXPECT_EQ(10, array2[0]->get_f_int8()); 452 EXPECT_EQ(10, array2[0]->get_f_int8());
453 EXPECT_EQ(12, array2[1]->get_f_int16()); 453 EXPECT_EQ(12, array2[1]->get_f_int16());
454 } 454 }
455 455
456 TEST(UnionTest, PodUnionInArraySerializationWithNull) { 456 TEST(UnionTest, PodUnionInArraySerializationWithNull) {
457 Array<PodUnionPtr> array(2); 457 Array<PodUnionPtr> array(2);
458 array[0] = PodUnion::New(); 458 array[0] = PodUnion::New();
459 459
460 array[0]->set_f_int8(10); 460 array[0]->set_f_int8(10);
461 EXPECT_EQ(2U, array.size()); 461 EXPECT_EQ(2U, array.size());
462 462
463 size_t size = 463 size_t size =
464 mojo::internal::PrepareToSerialize<Array<PodUnionPtr>>(array, nullptr); 464 mojo::internal::PrepareToSerialize<Array<PodUnionPtr>>(array, nullptr);
465 EXPECT_EQ(40U, size); 465 EXPECT_EQ(40U, size);
466 466
467 mojo::internal::FixedBufferForTesting buf(size); 467 mojo::internal::FixedBufferForTesting buf(size);
468 mojo::internal::Array_Data<internal::PodUnion_Data>* data; 468 mojo::internal::Array_Data<internal::PodUnion_Data>* data;
469 mojo::internal::ArrayValidateParams validate_params(0, true, nullptr); 469 mojo::internal::ContainerValidateParams validate_params(0, true, nullptr);
470 mojo::internal::Serialize<Array<PodUnionPtr>>(array, &buf, &data, 470 mojo::internal::Serialize<Array<PodUnionPtr>>(array, &buf, &data,
471 &validate_params, nullptr); 471 &validate_params, nullptr);
472 472
473 Array<PodUnionPtr> array2; 473 Array<PodUnionPtr> array2;
474 mojo::internal::Deserialize<Array<PodUnionPtr>>(data, &array2, nullptr); 474 mojo::internal::Deserialize<Array<PodUnionPtr>>(data, &array2, nullptr);
475 475
476 EXPECT_EQ(2U, array2.size()); 476 EXPECT_EQ(2U, array2.size());
477 477
478 EXPECT_EQ(10, array2[0]->get_f_int8()); 478 EXPECT_EQ(10, array2[0]->get_f_int8());
479 EXPECT_TRUE(array2[1].is_null()); 479 EXPECT_TRUE(array2[1].is_null());
480 } 480 }
481 481
482 TEST(UnionTest, ObjectUnionInArraySerialization) { 482 TEST(UnionTest, ObjectUnionInArraySerialization) {
483 Array<ObjectUnionPtr> array(2); 483 Array<ObjectUnionPtr> array(2);
484 array[0] = ObjectUnion::New(); 484 array[0] = ObjectUnion::New();
485 array[1] = ObjectUnion::New(); 485 array[1] = ObjectUnion::New();
486 486
487 array[0]->set_f_string("hello"); 487 array[0]->set_f_string("hello");
488 array[1]->set_f_string("world"); 488 array[1]->set_f_string("world");
489 EXPECT_EQ(2U, array.size()); 489 EXPECT_EQ(2U, array.size());
490 490
491 size_t size = 491 size_t size =
492 mojo::internal::PrepareToSerialize<Array<ObjectUnionPtr>>(array, nullptr); 492 mojo::internal::PrepareToSerialize<Array<ObjectUnionPtr>>(array, nullptr);
493 EXPECT_EQ(72U, size); 493 EXPECT_EQ(72U, size);
494 494
495 mojo::internal::FixedBufferForTesting buf(size); 495 mojo::internal::FixedBufferForTesting buf(size);
496 496
497 mojo::internal::Array_Data<internal::ObjectUnion_Data>* data; 497 mojo::internal::Array_Data<internal::ObjectUnion_Data>* data;
498 mojo::internal::ArrayValidateParams validate_params(0, false, nullptr); 498 mojo::internal::ContainerValidateParams validate_params(0, false, nullptr);
499 mojo::internal::Serialize<Array<ObjectUnionPtr>>(array, &buf, &data, 499 mojo::internal::Serialize<Array<ObjectUnionPtr>>(array, &buf, &data,
500 &validate_params, nullptr); 500 &validate_params, nullptr);
501 501
502 data->EncodePointers(); 502 data->EncodePointers();
503 503
504 std::vector<char> new_buf; 504 std::vector<char> new_buf;
505 new_buf.resize(size); 505 new_buf.resize(size);
506 506
507 void* raw_buf = buf.Leak(); 507 void* raw_buf = buf.Leak();
508 memcpy(new_buf.data(), raw_buf, size); 508 memcpy(new_buf.data(), raw_buf, size);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
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( 708 mojo::internal::ContainerValidateParams validate_params(
709 new mojo::internal::ArrayValidateParams(0, false, nullptr), 709 new mojo::internal::ContainerValidateParams(0, false, nullptr),
710 new mojo::internal::ArrayValidateParams(0, false, nullptr)); 710 new mojo::internal::ContainerValidateParams(0, false, nullptr));
711 mojo::internal::Serialize<Map<String, PodUnionPtr>>( 711 mojo::internal::Serialize<Map<String, PodUnionPtr>>(
712 map, &buf, &data, &validate_params, &context); 712 map, &buf, &data, &validate_params, &context);
713 713
714 Map<String, PodUnionPtr> map2; 714 Map<String, PodUnionPtr> map2;
715 mojo::internal::Deserialize<Map<String, PodUnionPtr>>(data, &map2, &context); 715 mojo::internal::Deserialize<Map<String, PodUnionPtr>>(data, &map2, &context);
716 716
717 EXPECT_EQ(8, map2["one"]->get_f_int8()); 717 EXPECT_EQ(8, map2["one"]->get_f_int8());
718 EXPECT_EQ(16, map2["two"]->get_f_int16()); 718 EXPECT_EQ(16, map2["two"]->get_f_int16());
719 } 719 }
720 720
721 TEST(UnionTest, PodUnionInMapSerializationWithNull) { 721 TEST(UnionTest, PodUnionInMapSerializationWithNull) {
722 Map<String, PodUnionPtr> map; 722 Map<String, PodUnionPtr> map;
723 map.insert("one", PodUnion::New()); 723 map.insert("one", PodUnion::New());
724 map.insert("two", nullptr); 724 map.insert("two", nullptr);
725 725
726 map["one"]->set_f_int8(8); 726 map["one"]->set_f_int8(8);
727 727
728 mojo::internal::SerializationContext context; 728 mojo::internal::SerializationContext context;
729 size_t size = mojo::internal::PrepareToSerialize<Map<String, PodUnionPtr>>( 729 size_t size = mojo::internal::PrepareToSerialize<Map<String, PodUnionPtr>>(
730 map, &context); 730 map, &context);
731 EXPECT_EQ(120U, size); 731 EXPECT_EQ(120U, size);
732 732
733 mojo::internal::FixedBufferForTesting buf(size); 733 mojo::internal::FixedBufferForTesting buf(size);
734 mojo::internal::Map_Data<mojo::internal::String_Data*, 734 mojo::internal::Map_Data<mojo::internal::String_Data*,
735 internal::PodUnion_Data>* data; 735 internal::PodUnion_Data>* data;
736 mojo::internal::ArrayValidateParams validate_params( 736 mojo::internal::ContainerValidateParams validate_params(
737 new mojo::internal::ArrayValidateParams(0, false, nullptr), 737 new mojo::internal::ContainerValidateParams(0, false, nullptr),
738 new mojo::internal::ArrayValidateParams(0, true, nullptr)); 738 new mojo::internal::ContainerValidateParams(0, true, nullptr));
739 mojo::internal::Serialize<Map<String, PodUnionPtr>>( 739 mojo::internal::Serialize<Map<String, PodUnionPtr>>(
740 map, &buf, &data, &validate_params, &context); 740 map, &buf, &data, &validate_params, &context);
741 741
742 Map<String, PodUnionPtr> map2; 742 Map<String, PodUnionPtr> map2;
743 mojo::internal::Deserialize<Map<String, PodUnionPtr>>(data, &map2, &context); 743 mojo::internal::Deserialize<Map<String, PodUnionPtr>>(data, &map2, &context);
744 744
745 EXPECT_EQ(8, map2["one"]->get_f_int8()); 745 EXPECT_EQ(8, map2["one"]->get_f_int8());
746 EXPECT_TRUE(map2["two"].is_null()); 746 EXPECT_TRUE(map2["two"].is_null());
747 } 747 }
748 748
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 PodUnionPtr pod(PodUnion::New()); 1242 PodUnionPtr pod(PodUnion::New());
1243 pod->set_f_int16(16); 1243 pod->set_f_int16(16);
1244 1244
1245 ptr->Echo(std::move(pod), 1245 ptr->Echo(std::move(pod),
1246 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); 1246 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); });
1247 run_loop.RunUntilIdle(); 1247 run_loop.RunUntilIdle();
1248 } 1248 }
1249 1249
1250 } // namespace test 1250 } // namespace test
1251 } // namespace mojo 1251 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/serialization_warning_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