| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 ObjectWithChoices::Params::Create(*params_value)); | 105 ObjectWithChoices::Params::Create(*params_value)); |
| 106 EXPECT_FALSE(params.get()); | 106 EXPECT_FALSE(params.get()); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) { | 110 TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) { |
| 111 std::vector<std::string> strings = Vector(std::string("list"), | 111 std::vector<std::string> strings = Vector(std::string("list"), |
| 112 std::string("of"), | 112 std::string("of"), |
| 113 std::string("strings")); | 113 std::string("strings")); |
| 114 | 114 |
| 115 base::ListValue* strings_value = new base::ListValue(); | 115 auto strings_value = base::MakeUnique<base::ListValue>(); |
| 116 for (size_t i = 0; i < strings.size(); ++i) | 116 for (size_t i = 0; i < strings.size(); ++i) |
| 117 strings_value->AppendString(strings[i]); | 117 strings_value->AppendString(strings[i]); |
| 118 | 118 |
| 119 base::DictionaryValue value; | 119 base::DictionaryValue value; |
| 120 value.SetInteger("integers", 4); | 120 value.SetInteger("integers", 4); |
| 121 value.Set("strings", strings_value); | 121 value.Set("strings", std::move(strings_value)); |
| 122 | 122 |
| 123 ChoiceType out; | 123 ChoiceType out; |
| 124 ASSERT_TRUE(ChoiceType::Populate(value, &out)); | 124 ASSERT_TRUE(ChoiceType::Populate(value, &out)); |
| 125 ASSERT_TRUE(out.integers.as_integer.get()); | 125 ASSERT_TRUE(out.integers.as_integer.get()); |
| 126 EXPECT_FALSE(out.integers.as_integers.get()); | 126 EXPECT_FALSE(out.integers.as_integers.get()); |
| 127 EXPECT_EQ(4, *out.integers.as_integer); | 127 EXPECT_EQ(4, *out.integers.as_integer); |
| 128 | 128 |
| 129 EXPECT_FALSE(out.strings->as_string.get()); | 129 EXPECT_FALSE(out.strings->as_string.get()); |
| 130 ASSERT_TRUE(out.strings->as_strings.get()); | 130 ASSERT_TRUE(out.strings->as_strings.get()); |
| 131 EXPECT_EQ(strings, *out.strings->as_strings); | 131 EXPECT_EQ(strings, *out.strings->as_strings); |
| 132 } | 132 } |
| 133 | 133 |
| 134 TEST(JsonSchemaCompilerChoicesTest, ChoiceTypeToValue) { | 134 TEST(JsonSchemaCompilerChoicesTest, ChoiceTypeToValue) { |
| 135 base::ListValue* strings_value = new base::ListValue(); | 135 auto strings_value = base::MakeUnique<base::ListValue>(); |
| 136 strings_value->AppendString("list"); | 136 strings_value->AppendString("list"); |
| 137 strings_value->AppendString("of"); | 137 strings_value->AppendString("of"); |
| 138 strings_value->AppendString("strings"); | 138 strings_value->AppendString("strings"); |
| 139 | 139 |
| 140 base::DictionaryValue value; | 140 base::DictionaryValue value; |
| 141 value.SetInteger("integers", 5); | 141 value.SetInteger("integers", 5); |
| 142 value.Set("strings", strings_value); | 142 value.Set("strings", std::move(strings_value)); |
| 143 | 143 |
| 144 ChoiceType out; | 144 ChoiceType out; |
| 145 ASSERT_TRUE(ChoiceType::Populate(value, &out)); | 145 ASSERT_TRUE(ChoiceType::Populate(value, &out)); |
| 146 | 146 |
| 147 EXPECT_TRUE(value.Equals(out.ToValue().get())); | 147 EXPECT_TRUE(value.Equals(out.ToValue().get())); |
| 148 } | 148 } |
| 149 | 149 |
| 150 TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) { | 150 TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) { |
| 151 { | 151 { |
| 152 ReturnChoices::Results::Result results; | 152 ReturnChoices::Results::Result results; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 obj->as_choice2->as_choice_types.get(); | 288 obj->as_choice2->as_choice_types.get(); |
| 289 // Bleh too much effort to test everything. | 289 // Bleh too much effort to test everything. |
| 290 ASSERT_EQ(2u, choice_types->size()); | 290 ASSERT_EQ(2u, choice_types->size()); |
| 291 } | 291 } |
| 292 | 292 |
| 293 EXPECT_TRUE(base::Value::Equals(value.get(), obj->ToValue().get())); | 293 EXPECT_TRUE(base::Value::Equals(value.get(), obj->ToValue().get())); |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 | 296 |
| 297 } // namespace | 297 } // namespace |
| OLD | NEW |