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

Unified Diff: mojo/public/cpp/bindings/tests/union_unittest.cc

Issue 1618963006: Mojo C++ bindings: support enum validation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/tests/union_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/union_unittest.cc b/mojo/public/cpp/bindings/tests/union_unittest.cc
index 60bde4b1d44e9e279c96dab8d07def059b398254..c90069b0a490ca631128ed4fc75c58c73c133c7c 100644
--- a/mojo/public/cpp/bindings/tests/union_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/union_unittest.cc
@@ -264,6 +264,44 @@ TEST(UnionTest, UnknownTagValidation) {
free(raw_buf);
}
+TEST(UnionTest, UnknownEnumValueValidation) {
+ PodUnionPtr pod(PodUnion::New());
+ pod->set_f_enum(static_cast<AnEnum>(0xFFFF));
+
+ size_t size = GetSerializedSize_(pod, false);
+ EXPECT_EQ(16U, size);
+
+ mojo::internal::FixedBufferForTesting buf(size);
+ internal::PodUnion_Data* data = nullptr;
+ SerializeUnion_(std::move(pod), &buf, &data, false);
+
+ void* raw_buf = buf.Leak();
+ mojo::internal::BoundsChecker bounds_checker(data,
+ static_cast<uint32_t>(size), 0);
+ EXPECT_FALSE(
+ internal::PodUnion_Data::Validate(raw_buf, &bounds_checker, false));
+ free(raw_buf);
+}
+
+TEST(UnionTest, UnknownExtensibleEnumValueValidation) {
+ PodUnionPtr pod(PodUnion::New());
+ pod->set_f_extensible_enum(static_cast<AnExtensibleEnum>(0xFFFF));
+
+ size_t size = GetSerializedSize_(pod, false);
+ EXPECT_EQ(16U, size);
+
+ mojo::internal::FixedBufferForTesting buf(size);
+ internal::PodUnion_Data* data = nullptr;
+ SerializeUnion_(std::move(pod), &buf, &data, false);
+
+ void* raw_buf = buf.Leak();
+ mojo::internal::BoundsChecker bounds_checker(data,
+ static_cast<uint32_t>(size), 0);
+ EXPECT_TRUE(
+ internal::PodUnion_Data::Validate(raw_buf, &bounds_checker, false));
+ free(raw_buf);
+}
+
TEST(UnionTest, StringGetterSetter) {
ObjectUnionPtr pod(ObjectUnion::New());
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_util.h ('k') | mojo/public/cpp/bindings/tests/validation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698