| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "tools/json_schema_compiler/test/choices.h" | 5 #include "tools/json_schema_compiler/test/choices.h" |
| 6 | 6 |
| 7 #include "base/strings/string_piece.h" | 7 #include "base/strings/string_piece.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "tools/json_schema_compiler/test/test_util.h" | 9 #include "tools/json_schema_compiler/test/test_util.h" |
| 10 | 10 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 new base::FundamentalValue(5)); | 74 new base::FundamentalValue(5)); |
| 75 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 75 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 76 params_value->Append(object_param.release()); | 76 params_value->Append(object_param.release()); |
| 77 scoped_ptr<ObjectWithChoices::Params> params( | 77 scoped_ptr<ObjectWithChoices::Params> params( |
| 78 ObjectWithChoices::Params::Create(*params_value)); | 78 ObjectWithChoices::Params::Create(*params_value)); |
| 79 EXPECT_FALSE(params.get()); | 79 EXPECT_FALSE(params.get()); |
| 80 } | 80 } |
| 81 { | 81 { |
| 82 scoped_ptr<base::DictionaryValue> object_param(new base::DictionaryValue()); | 82 scoped_ptr<base::DictionaryValue> object_param(new base::DictionaryValue()); |
| 83 object_param->SetWithoutPathExpansion("strings", | 83 object_param->SetWithoutPathExpansion("strings", |
| 84 base::Value::CreateStringValue("asdf")); | 84 new base::StringValue("asdf")); |
| 85 object_param->SetWithoutPathExpansion("integers", | 85 object_param->SetWithoutPathExpansion("integers", |
| 86 base::Value::CreateStringValue("asdf")); | 86 new base::StringValue("asdf")); |
| 87 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 87 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 88 params_value->Append(object_param.release()); | 88 params_value->Append(object_param.release()); |
| 89 scoped_ptr<ObjectWithChoices::Params> params( | 89 scoped_ptr<ObjectWithChoices::Params> params( |
| 90 ObjectWithChoices::Params::Create(*params_value)); | 90 ObjectWithChoices::Params::Create(*params_value)); |
| 91 EXPECT_FALSE(params.get()); | 91 EXPECT_FALSE(params.get()); |
| 92 } | 92 } |
| 93 { | 93 { |
| 94 scoped_ptr<base::DictionaryValue> object_param(new base::DictionaryValue()); | 94 scoped_ptr<base::DictionaryValue> object_param(new base::DictionaryValue()); |
| 95 object_param->SetWithoutPathExpansion("integers", | 95 object_param->SetWithoutPathExpansion("integers", |
| 96 new base::FundamentalValue(6)); | 96 new base::FundamentalValue(6)); |
| 97 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 97 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 98 params_value->Append(object_param.release()); | 98 params_value->Append(object_param.release()); |
| 99 scoped_ptr<ObjectWithChoices::Params> params( | 99 scoped_ptr<ObjectWithChoices::Params> params( |
| 100 ObjectWithChoices::Params::Create(*params_value)); | 100 ObjectWithChoices::Params::Create(*params_value)); |
| 101 EXPECT_FALSE(params.get()); | 101 EXPECT_FALSE(params.get()); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) { | 105 TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) { |
| 106 std::vector<std::string> strings = Vector(std::string("list"), | 106 std::vector<std::string> strings = Vector(std::string("list"), |
| 107 std::string("of"), | 107 std::string("of"), |
| 108 std::string("strings")); | 108 std::string("strings")); |
| 109 | 109 |
| 110 base::ListValue* strings_value = new base::ListValue(); | 110 base::ListValue* strings_value = new base::ListValue(); |
| 111 for (size_t i = 0; i < strings.size(); ++i) | 111 for (size_t i = 0; i < strings.size(); ++i) |
| 112 strings_value->Append(base::Value::CreateStringValue(strings[i])); | 112 strings_value->Append(new base::StringValue(strings[i])); |
| 113 | 113 |
| 114 base::DictionaryValue value; | 114 base::DictionaryValue value; |
| 115 value.SetInteger("integers", 4); | 115 value.SetInteger("integers", 4); |
| 116 value.Set("strings", strings_value); | 116 value.Set("strings", strings_value); |
| 117 | 117 |
| 118 ChoiceType out; | 118 ChoiceType out; |
| 119 ASSERT_TRUE(ChoiceType::Populate(value, &out)); | 119 ASSERT_TRUE(ChoiceType::Populate(value, &out)); |
| 120 ASSERT_TRUE(out.integers.as_integer.get()); | 120 ASSERT_TRUE(out.integers.as_integer.get()); |
| 121 EXPECT_FALSE(out.integers.as_integers.get()); | 121 EXPECT_FALSE(out.integers.as_integers.get()); |
| 122 EXPECT_EQ(4, *out.integers.as_integer); | 122 EXPECT_EQ(4, *out.integers.as_integer); |
| 123 | 123 |
| 124 EXPECT_FALSE(out.strings->as_string.get()); | 124 EXPECT_FALSE(out.strings->as_string.get()); |
| 125 ASSERT_TRUE(out.strings->as_strings.get()); | 125 ASSERT_TRUE(out.strings->as_strings.get()); |
| 126 EXPECT_EQ(strings, *out.strings->as_strings); | 126 EXPECT_EQ(strings, *out.strings->as_strings); |
| 127 } | 127 } |
| 128 | 128 |
| 129 TEST(JsonSchemaCompilerChoicesTest, ChoiceTypeToValue) { | 129 TEST(JsonSchemaCompilerChoicesTest, ChoiceTypeToValue) { |
| 130 base::ListValue* strings_value = new base::ListValue(); | 130 base::ListValue* strings_value = new base::ListValue(); |
| 131 strings_value->Append(base::Value::CreateStringValue("list")); | 131 strings_value->Append(new base::StringValue("list")); |
| 132 strings_value->Append(base::Value::CreateStringValue("of")); | 132 strings_value->Append(new base::StringValue("of")); |
| 133 strings_value->Append(base::Value::CreateStringValue("strings")); | 133 strings_value->Append(new base::StringValue("strings")); |
| 134 | 134 |
| 135 base::DictionaryValue value; | 135 base::DictionaryValue value; |
| 136 value.SetInteger("integers", 5); | 136 value.SetInteger("integers", 5); |
| 137 value.Set("strings", strings_value); | 137 value.Set("strings", strings_value); |
| 138 | 138 |
| 139 ChoiceType out; | 139 ChoiceType out; |
| 140 ASSERT_TRUE(ChoiceType::Populate(value, &out)); | 140 ASSERT_TRUE(ChoiceType::Populate(value, &out)); |
| 141 | 141 |
| 142 EXPECT_TRUE(value.Equals(out.ToValue().get())); | 142 EXPECT_TRUE(value.Equals(out.ToValue().get())); |
| 143 } | 143 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 obj->as_choice2->as_choice_types.get(); | 283 obj->as_choice2->as_choice_types.get(); |
| 284 // Bleh too much effort to test everything. | 284 // Bleh too much effort to test everything. |
| 285 ASSERT_EQ(2u, choice_types->size()); | 285 ASSERT_EQ(2u, choice_types->size()); |
| 286 } | 286 } |
| 287 | 287 |
| 288 EXPECT_TRUE(base::Value::Equals(value.get(), obj->ToValue().get())); | 288 EXPECT_TRUE(base::Value::Equals(value.get(), obj->ToValue().get())); |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 | 291 |
| 292 } // namespace | 292 } // namespace |
| OLD | NEW |