summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler/test/choices_unittest.cc
diff options
context:
space:
mode:
authorhebert.christopherj@chromium.org <hebert.christopherj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-23 19:56:22 +0000
committerhebert.christopherj@chromium.org <hebert.christopherj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-23 19:56:22 +0000
commiteb59ebb261bd14325b13f357d67cecd97332efc9 (patch)
treecc9e7e0c7e384db9740973fa3c7673593cc990a0 /tools/json_schema_compiler/test/choices_unittest.cc
parent71221af8e1864119137c8c90f713d5a639478f06 (diff)
downloadchromium_src-eb59ebb261bd14325b13f357d67cecd97332efc9.zip
chromium_src-eb59ebb261bd14325b13f357d67cecd97332efc9.tar.gz
chromium_src-eb59ebb261bd14325b13f357d67cecd97332efc9.tar.bz2
JSON Schema Compiler now supports conversion from Choice to base::Value.
BUG=133636 TEST=choices_unittest.cc Review URL: https://chromiumcodereview.appspot.com/10790040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147904 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler/test/choices_unittest.cc')
-rw-r--r--tools/json_schema_compiler/test/choices_unittest.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/json_schema_compiler/test/choices_unittest.cc b/tools/json_schema_compiler/test/choices_unittest.cc
index ce5a0ee..b4e76a1 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;