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

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

Issue 10790040: JSON Schema Compiler now supports conversion from Choice to base::Value. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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: tools/json_schema_compiler/test/choices_unittest.cc
diff --git a/tools/json_schema_compiler/test/choices_unittest.cc b/tools/json_schema_compiler/test/choices_unittest.cc
index ce5a0ee17ad3ba4adfb3458c8a48574a79827ff5..b4e76a15e7c42612671812bf79b29783a63f211a 100644
--- a/tools/json_schema_compiler/test/choices_unittest.cc
+++ b/tools/json_schema_compiler/test/choices_unittest.cc
@@ -111,6 +111,49 @@ TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) {
}
}
+TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) {
+ std::vector<std::string> strings;
+ strings.push_back("list");
+ strings.push_back("of");
+ strings.push_back("strings");
+
+ ListValue* strings_value = new ListValue();
+ for (size_t i = 0; i < strings.size(); ++i)
+ strings_value->Append(Value::CreateStringValue(strings[i]));
+
+ DictionaryValue value;
+ value.SetInteger("integers", 4);
+ value.Set("strings", strings_value);
+
+ ChoiceType out;
+ ASSERT_TRUE(ChoiceType::Populate(value, &out));
+ EXPECT_EQ(ChoiceType::INTEGERS_INTEGER, out.integers_type);
+ ASSERT_TRUE(out.integers_integer.get());
+ EXPECT_FALSE(out.integers_array.get());
+ EXPECT_EQ(4, *out.integers_integer);
+
+ EXPECT_EQ(ChoiceType::STRINGS_ARRAY, out.strings_type);
+ EXPECT_FALSE(out.strings_string.get());
+ ASSERT_TRUE(out.strings_array.get());
+ EXPECT_EQ(strings, *out.strings_array);
+}
+
+TEST(JsonSchemaCompilerChoicesTest, ChoiceTypeToValue) {
+ ListValue* strings_value = new ListValue();
+ strings_value->Append(Value::CreateStringValue("list"));
+ strings_value->Append(Value::CreateStringValue("of"));
+ strings_value->Append(Value::CreateStringValue("strings"));
+
+ DictionaryValue value;
+ value.SetInteger("integers", 5);
+ value.Set("strings", strings_value);
+
+ ChoiceType out;
+ ASSERT_TRUE(ChoiceType::Populate(value, &out));
+
+ EXPECT_TRUE(value.Equals(out.ToValue().get()));
+}
+
TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) {
{
std::vector<int> integers;
« tools/json_schema_compiler/h_generator.py ('K') | « tools/json_schema_compiler/test/choices.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698