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

Unified Diff: mojo/public/cpp/bindings/tests/validation_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/validation_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/validation_unittest.cc b/mojo/public/cpp/bindings/tests/validation_unittest.cc
index bb1c74505519f04fefd6610940b0c720aafe6db4..252a31a6f8ac08795a30a18bc43c14af463cb53b 100644
--- a/mojo/public/cpp/bindings/tests/validation_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/validation_unittest.cc
@@ -194,13 +194,17 @@ class DummyMessageReceiver : public MessageReceiver {
}
};
-using ValidationTest = testing::Test;
+class ValidationTest : public testing::Test {
+ public:
+ ValidationTest() : loop_(common::MessagePumpMojo::Create()) {}
+
+ protected:
+ base::MessageLoop loop_;
+};
class ValidationIntegrationTest : public ValidationTest {
public:
- ValidationIntegrationTest()
- : loop_(common::MessagePumpMojo::Create()),
- test_message_receiver_(nullptr) {}
+ ValidationIntegrationTest() : test_message_receiver_(nullptr) {}
~ValidationIntegrationTest() override {}
@@ -250,7 +254,6 @@ class ValidationIntegrationTest : public ValidationTest {
void PumpMessages() { loop_.RunUntilIdle(); }
- base::MessageLoop loop_;
TestMessageReceiver* test_message_receiver_;
ScopedMessagePipeHandle testee_endpoint_;
};
@@ -462,37 +465,31 @@ TEST_F(ValidationTest, ValidateEncodedPointer) {
EXPECT_FALSE(mojo::internal::ValidateEncodedPointer(&offset));
}
-// Tests the IsValidValue() function generated for BasicEnum.
+// Tests the IsKnownEnumValue() function generated for BasicEnum.
TEST(EnumValueValidationTest, BasicEnum) {
// BasicEnum can have -3,0,1,10 as possible integral values.
- EXPECT_FALSE(BasicEnum_IsValidValue(static_cast<BasicEnum>(-4)));
- EXPECT_TRUE(BasicEnum_IsValidValue(static_cast<BasicEnum>(-3)));
- EXPECT_FALSE(BasicEnum_IsValidValue(static_cast<BasicEnum>(-2)));
- EXPECT_FALSE(BasicEnum_IsValidValue(static_cast<BasicEnum>(-1)));
- EXPECT_TRUE(BasicEnum_IsValidValue(static_cast<BasicEnum>(0)));
- EXPECT_TRUE(BasicEnum_IsValidValue(static_cast<BasicEnum>(1)));
- EXPECT_FALSE(BasicEnum_IsValidValue(static_cast<BasicEnum>(2)));
- EXPECT_FALSE(BasicEnum_IsValidValue(static_cast<BasicEnum>(9)));
+ EXPECT_FALSE(IsKnownEnumValue(static_cast<BasicEnum>(-4)));
+ EXPECT_TRUE(IsKnownEnumValue(static_cast<BasicEnum>(-3)));
+ EXPECT_FALSE(IsKnownEnumValue(static_cast<BasicEnum>(-2)));
+ EXPECT_FALSE(IsKnownEnumValue(static_cast<BasicEnum>(-1)));
+ EXPECT_TRUE(IsKnownEnumValue(static_cast<BasicEnum>(0)));
+ EXPECT_TRUE(IsKnownEnumValue(static_cast<BasicEnum>(1)));
+ EXPECT_FALSE(IsKnownEnumValue(static_cast<BasicEnum>(2)));
+ EXPECT_FALSE(IsKnownEnumValue(static_cast<BasicEnum>(9)));
// In the mojom, we represent this value as hex (0xa).
- EXPECT_TRUE(BasicEnum_IsValidValue(static_cast<BasicEnum>(10)));
- EXPECT_FALSE(BasicEnum_IsValidValue(static_cast<BasicEnum>(11)));
+ EXPECT_TRUE(IsKnownEnumValue(static_cast<BasicEnum>(10)));
+ EXPECT_FALSE(IsKnownEnumValue(static_cast<BasicEnum>(11)));
}
-// Tests the IsValidValue() method generated for StructWithEnum.
+// Tests the IsKnownEnumValue() method generated for StructWithEnum.
TEST(EnumValueValidationTest, EnumWithin) {
// StructWithEnum::EnumWithin can have [0,4] as possible integral values.
- EXPECT_FALSE(StructWithEnum::EnumWithin_IsValidValue(
- static_cast<StructWithEnum::EnumWithin>(-1)));
- EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue(
- static_cast<StructWithEnum::EnumWithin>(0)));
- EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue(
- static_cast<StructWithEnum::EnumWithin>(1)));
- EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue(
- static_cast<StructWithEnum::EnumWithin>(2)));
- EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue(
- static_cast<StructWithEnum::EnumWithin>(3)));
- EXPECT_FALSE(StructWithEnum::EnumWithin_IsValidValue(
- static_cast<StructWithEnum::EnumWithin>(4)));
+ EXPECT_FALSE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(-1)));
+ EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(0)));
+ EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(1)));
+ EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(2)));
+ EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(3)));
+ EXPECT_FALSE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(4)));
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698