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

Unified Diff: tools/json_schema_compiler/test/idl_schemas_unittest.cc

Issue 1982193002: Add enum class support to json_schema_compiler (idl files) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: I accidentally a patchset dependency Created 4 years, 7 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
« no previous file with comments | « tools/json_schema_compiler/test/idl_basics.idl ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/test/idl_schemas_unittest.cc
diff --git a/tools/json_schema_compiler/test/idl_schemas_unittest.cc b/tools/json_schema_compiler/test/idl_schemas_unittest.cc
index 2599d9e846ce36d04dfac6bed39956da875e6f6c..037983b61eb7822cc460f561270ba9298153bd0a 100644
--- a/tools/json_schema_compiler/test/idl_schemas_unittest.cc
+++ b/tools/json_schema_compiler/test/idl_schemas_unittest.cc
@@ -205,3 +205,50 @@ TEST(IdlCompiler, ObjectTypes) {
EXPECT_TRUE(params->icon.additional_properties.GetString("hello", &tmp));
EXPECT_EQ("world", tmp);
}
+
+TEST(IdlCompiler, Enums) {
+ using test::api::idl_basics::MyType3;
+ using test::api::idl_basics::EnumClass;
+ using test::api::idl_basics::EnumClassWithPrefix;
+
+ MyType3 a;
+ EXPECT_EQ(a.w, test::api::idl_basics::ENUM_TYPE_NONE);
+
+ // The type name is always used as the prefix for NONE/LAST to avoid symbol
+ // conflicts with types that share a prefix.
+ EXPECT_EQ(a.x, test::api::idl_basics::ENUM_WITH_PREFIX_NONE);
+ EXPECT_EQ(a.y, EnumClass::NONE);
+
+ // Symbol conflicts aren't possible with enum classes, so we just use NONE.
+ EXPECT_EQ(a.z, EnumClassWithPrefix::NONE);
+
+ a.w = test::api::idl_basics::ENUM_TYPE_NAME2;
+ a.x = test::api::idl_basics::PREFIX_NAME2;
+ a.y = EnumClass::NAME2;
+ a.z = EnumClassWithPrefix::PREFIX_NAME2;
+
+ std::unique_ptr<base::DictionaryValue> serialized = a.ToValue();
+ MyType3 b;
+ EXPECT_TRUE(MyType3::Populate(*serialized.get(), &b));
+ EXPECT_EQ(a.w, b.w);
+ EXPECT_EQ(a.x, b.x);
+ EXPECT_EQ(a.y, b.y);
+ EXPECT_EQ(a.z, b.z);
+
+ base::Value* v;
+ std::string w, x, y, z;
+ EXPECT_TRUE(serialized->Get("w", &v));
+ EXPECT_TRUE(v->GetAsString(&w));
+ EXPECT_TRUE(serialized->Get("x", &v));
+ EXPECT_TRUE(v->GetAsString(&x));
+ EXPECT_TRUE(serialized->Get("y", &v));
+ EXPECT_TRUE(v->GetAsString(&y));
+ EXPECT_TRUE(serialized->Get("z", &v));
+ EXPECT_TRUE(v->GetAsString(&z));
+
+ // Only the C++ syntax should be affected, so the string representations
+ // should all match.
+ EXPECT_EQ(w, x);
+ EXPECT_EQ(x, y);
+ EXPECT_EQ(y, z);
+}
« no previous file with comments | « tools/json_schema_compiler/test/idl_basics.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698