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

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

Issue 1800753005: C++ bindings: A struct's Deserialize() now does validation before deserializing. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix char* - >char bug in unittest. FixedBuffer can accept sizes that aren't 8 byte multiples. Created 4 years, 8 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 <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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 656
657 // Serialize a null union and deserialize it back to check that we have a null 657 // Serialize a null union and deserialize it back to check that we have a null
658 // union. 658 // union.
659 TEST(UnionTest, Deserialize_NullableUnion) { 659 TEST(UnionTest, Deserialize_NullableUnion) {
660 char buf[1024]; 660 char buf[1024];
661 SmallStructPtr small_struct = SmallStruct::New(); 661 SmallStructPtr small_struct = SmallStruct::New();
662 small_struct->Serialize(buf, sizeof(buf)); 662 small_struct->Serialize(buf, sizeof(buf));
663 EXPECT_TRUE(small_struct->pod_union.is_null()); 663 EXPECT_TRUE(small_struct->pod_union.is_null());
664 664
665 SmallStructPtr deserialized_struct = SmallStruct::New(); 665 SmallStructPtr deserialized_struct = SmallStruct::New();
666 deserialized_struct->Deserialize(buf); 666 EXPECT_TRUE(deserialized_struct->Deserialize(buf, sizeof(buf)));
667
668 EXPECT_TRUE(deserialized_struct->pod_union.is_null()); 667 EXPECT_TRUE(deserialized_struct->pod_union.is_null());
669 } 668 }
670 669
671 // Validation passes with nullable null union containing non-nullable objects. 670 // Validation passes with nullable null union containing non-nullable objects.
672 TEST(UnionTest, Validation_NullableObjectUnion) { 671 TEST(UnionTest, Validation_NullableObjectUnion) {
673 Environment environment; 672 Environment environment;
674 StructNullObjectUnionPtr small_struct(StructNullObjectUnion::New()); 673 StructNullObjectUnionPtr small_struct(StructNullObjectUnion::New());
675 674
676 size_t size = GetSerializedSize_(*small_struct); 675 size_t size = GetSerializedSize_(*small_struct);
677 676
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 PodUnionPtr pod(PodUnion::New()); 1286 PodUnionPtr pod(PodUnion::New());
1288 pod->set_f_int16(16); 1287 pod->set_f_int16(16);
1289 1288
1290 ptr->Echo(pod.Pass(), 1289 ptr->Echo(pod.Pass(),
1291 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); 1290 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); });
1292 run_loop.RunUntilIdle(); 1291 run_loop.RunUntilIdle();
1293 } 1292 }
1294 1293
1295 } // namespace test 1294 } // namespace test
1296 } // namespace mojo 1295 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698