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