OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/error_generation.h" | 5 #include "tools/json_schema_compiler/test/error_generation.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "tools/json_schema_compiler/test/test_util.h" | 10 #include "tools/json_schema_compiler/test/test_util.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 const base::string16& actual) { | 26 const base::string16& actual) { |
27 if (base::ASCIIToUTF16(expected) != actual) | 27 if (base::ASCIIToUTF16(expected) != actual) |
28 return testing::AssertionFailure() << expected << " != " << actual; | 28 return testing::AssertionFailure() << expected << " != " << actual; |
29 return testing::AssertionSuccess(); | 29 return testing::AssertionSuccess(); |
30 } | 30 } |
31 | 31 |
32 // GenerateTypePopulate errors | 32 // GenerateTypePopulate errors |
33 | 33 |
34 TEST(JsonSchemaCompilerErrorTest, RequiredPropertyPopulate) { | 34 TEST(JsonSchemaCompilerErrorTest, RequiredPropertyPopulate) { |
35 { | 35 { |
36 scoped_ptr<base::DictionaryValue> value = Dictionary( | 36 std::unique_ptr<base::DictionaryValue> value = |
37 "string", new base::StringValue("bling")); | 37 Dictionary("string", new base::StringValue("bling")); |
38 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); | 38 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); |
39 } | 39 } |
40 { | 40 { |
41 scoped_ptr<base::BinaryValue> value(new base::BinaryValue()); | 41 std::unique_ptr<base::BinaryValue> value(new base::BinaryValue()); |
42 EXPECT_TRUE(EqualsUtf16("expected dictionary, got binary", | 42 EXPECT_TRUE(EqualsUtf16("expected dictionary, got binary", |
43 GetPopulateError<TestType>(*value))); | 43 GetPopulateError<TestType>(*value))); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 TEST(JsonSchemaCompilerErrorTest, UnexpectedTypePopulation) { | 47 TEST(JsonSchemaCompilerErrorTest, UnexpectedTypePopulation) { |
48 { | 48 { |
49 scoped_ptr<base::ListValue> value(new base::ListValue()); | 49 std::unique_ptr<base::ListValue> value(new base::ListValue()); |
50 EXPECT_TRUE(EqualsUtf16("", | 50 EXPECT_TRUE(EqualsUtf16("", |
51 GetPopulateError<ChoiceType::Integers>(*value))); | 51 GetPopulateError<ChoiceType::Integers>(*value))); |
52 } | 52 } |
53 { | 53 { |
54 scoped_ptr<base::BinaryValue> value(new base::BinaryValue()); | 54 std::unique_ptr<base::BinaryValue> value(new base::BinaryValue()); |
55 EXPECT_TRUE(EqualsUtf16("expected integers or integer, got binary", | 55 EXPECT_TRUE(EqualsUtf16("expected integers or integer, got binary", |
56 GetPopulateError<ChoiceType::Integers>(*value))); | 56 GetPopulateError<ChoiceType::Integers>(*value))); |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 // GenerateTypePopulateProperty errors | 60 // GenerateTypePopulateProperty errors |
61 | 61 |
62 TEST(JsonSchemaCompilerErrorTest, TypeIsRequired) { | 62 TEST(JsonSchemaCompilerErrorTest, TypeIsRequired) { |
63 { | 63 { |
64 scoped_ptr<base::DictionaryValue> value = Dictionary( | 64 std::unique_ptr<base::DictionaryValue> value = |
65 "integers", new FundamentalValue(5)); | 65 Dictionary("integers", new FundamentalValue(5)); |
66 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ChoiceType>(*value))); | 66 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ChoiceType>(*value))); |
67 } | 67 } |
68 { | 68 { |
69 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 69 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
70 EXPECT_TRUE(EqualsUtf16("'integers' is required", | 70 EXPECT_TRUE(EqualsUtf16("'integers' is required", |
71 GetPopulateError<ChoiceType>(*value))); | 71 GetPopulateError<ChoiceType>(*value))); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 // GenerateParamsCheck errors | 75 // GenerateParamsCheck errors |
76 | 76 |
77 TEST(JsonSchemaCompilerErrorTest, TooManyParameters) { | 77 TEST(JsonSchemaCompilerErrorTest, TooManyParameters) { |
78 { | 78 { |
79 scoped_ptr<base::ListValue> params_value = List( | 79 std::unique_ptr<base::ListValue> params_value = |
80 new FundamentalValue(5)); | 80 List(new FundamentalValue(5)); |
81 base::string16 error; | 81 base::string16 error; |
82 EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error)); | 82 EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error)); |
83 } | 83 } |
84 { | 84 { |
85 scoped_ptr<base::ListValue> params_value = List( | 85 std::unique_ptr<base::ListValue> params_value = |
86 new FundamentalValue(5), | 86 List(new FundamentalValue(5), new FundamentalValue(5)); |
87 new FundamentalValue(5)); | |
88 base::string16 error; | 87 base::string16 error; |
89 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); | 88 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); |
90 EXPECT_TRUE(EqualsUtf16("expected 1 arguments, got 2", error)); | 89 EXPECT_TRUE(EqualsUtf16("expected 1 arguments, got 2", error)); |
91 } | 90 } |
92 } | 91 } |
93 | 92 |
94 // GenerateFunctionParamsCreate errors | 93 // GenerateFunctionParamsCreate errors |
95 | 94 |
96 TEST(JsonSchemaCompilerErrorTest, ParamIsRequired) { | 95 TEST(JsonSchemaCompilerErrorTest, ParamIsRequired) { |
97 { | 96 { |
98 scoped_ptr<base::ListValue> params_value = List( | 97 std::unique_ptr<base::ListValue> params_value = |
99 new FundamentalValue(5)); | 98 List(new FundamentalValue(5)); |
100 base::string16 error; | 99 base::string16 error; |
101 EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error)); | 100 EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error)); |
102 } | 101 } |
103 { | 102 { |
104 scoped_ptr<base::ListValue> params_value = | 103 std::unique_ptr<base::ListValue> params_value = |
105 List(base::Value::CreateNullValue().release()); | 104 List(base::Value::CreateNullValue().release()); |
106 base::string16 error; | 105 base::string16 error; |
107 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); | 106 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); |
108 EXPECT_TRUE(EqualsUtf16("'num' is required", error)); | 107 EXPECT_TRUE(EqualsUtf16("'num' is required", error)); |
109 } | 108 } |
110 } | 109 } |
111 | 110 |
112 // GeneratePopulateVariableFromValue errors | 111 // GeneratePopulateVariableFromValue errors |
113 | 112 |
114 TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) { | 113 TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) { |
115 { | 114 { |
116 scoped_ptr<base::DictionaryValue> value = Dictionary( | 115 std::unique_ptr<base::DictionaryValue> value = |
117 "string", new base::StringValue("yes")); | 116 Dictionary("string", new base::StringValue("yes")); |
118 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); | 117 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); |
119 } | 118 } |
120 { | 119 { |
121 scoped_ptr<base::DictionaryValue> value = Dictionary( | 120 std::unique_ptr<base::DictionaryValue> value = |
122 "string", new FundamentalValue(1.1)); | 121 Dictionary("string", new FundamentalValue(1.1)); |
123 EXPECT_TRUE(EqualsUtf16("'string': expected string, got number", | 122 EXPECT_TRUE(EqualsUtf16("'string': expected string, got number", |
124 GetPopulateError<TestType>(*value))); | 123 GetPopulateError<TestType>(*value))); |
125 } | 124 } |
126 } | 125 } |
127 | 126 |
128 TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) { | 127 TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) { |
129 { | 128 { |
130 base::string16 error; | 129 base::string16 error; |
131 scoped_ptr<base::ListValue> params_value = List( | 130 std::unique_ptr<base::ListValue> params_value = |
132 new base::StringValue("Yeah!")); | 131 List(new base::StringValue("Yeah!")); |
133 EXPECT_TRUE(TestString::Params::Create(*params_value, &error)); | 132 EXPECT_TRUE(TestString::Params::Create(*params_value, &error)); |
134 } | 133 } |
135 { | 134 { |
136 scoped_ptr<base::ListValue> params_value = List( | 135 std::unique_ptr<base::ListValue> params_value = |
137 new FundamentalValue(5)); | 136 List(new FundamentalValue(5)); |
138 base::string16 error; | 137 base::string16 error; |
139 EXPECT_FALSE(TestTypeInObject::Params::Create(*params_value, &error)); | 138 EXPECT_FALSE(TestTypeInObject::Params::Create(*params_value, &error)); |
140 EXPECT_TRUE(EqualsUtf16("'paramObject': expected dictionary, got integer", | 139 EXPECT_TRUE(EqualsUtf16("'paramObject': expected dictionary, got integer", |
141 error)); | 140 error)); |
142 } | 141 } |
143 } | 142 } |
144 | 143 |
145 TEST(JsonSchemaCompilerErrorTest, WrongTypeValueType) { | 144 TEST(JsonSchemaCompilerErrorTest, WrongTypeValueType) { |
146 { | 145 { |
147 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 146 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
148 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ObjectType>(*value))); | 147 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ObjectType>(*value))); |
149 } | 148 } |
150 { | 149 { |
151 scoped_ptr<base::DictionaryValue> value = Dictionary( | 150 std::unique_ptr<base::DictionaryValue> value = |
152 "otherType", new FundamentalValue(1.1)); | 151 Dictionary("otherType", new FundamentalValue(1.1)); |
153 ObjectType out; | 152 ObjectType out; |
154 base::string16 error; | 153 base::string16 error; |
155 EXPECT_TRUE(ObjectType::Populate(*value, &out, &error)); | 154 EXPECT_TRUE(ObjectType::Populate(*value, &out, &error)); |
156 EXPECT_TRUE(EqualsUtf16("'otherType': expected dictionary, got number", | 155 EXPECT_TRUE(EqualsUtf16("'otherType': expected dictionary, got number", |
157 error)); | 156 error)); |
158 EXPECT_EQ(NULL, out.other_type.get()); | 157 EXPECT_EQ(NULL, out.other_type.get()); |
159 } | 158 } |
160 } | 159 } |
161 | 160 |
162 TEST(JsonSchemaCompilerErrorTest, UnableToPopulateArray) { | 161 TEST(JsonSchemaCompilerErrorTest, UnableToPopulateArray) { |
163 { | 162 { |
164 scoped_ptr<base::ListValue> params_value = List( | 163 std::unique_ptr<base::ListValue> params_value = |
165 new FundamentalValue(5)); | 164 List(new FundamentalValue(5)); |
166 EXPECT_TRUE(EqualsUtf16("", | 165 EXPECT_TRUE(EqualsUtf16("", |
167 GetPopulateError<ChoiceType::Integers>(*params_value))); | 166 GetPopulateError<ChoiceType::Integers>(*params_value))); |
168 } | 167 } |
169 { | 168 { |
170 scoped_ptr<base::ListValue> params_value = List( | 169 std::unique_ptr<base::ListValue> params_value = |
171 new FundamentalValue(5), | 170 List(new FundamentalValue(5), new FundamentalValue(false)); |
172 new FundamentalValue(false)); | |
173 EXPECT_TRUE(EqualsUtf16( | 171 EXPECT_TRUE(EqualsUtf16( |
174 "expected integer, got boolean; unable to populate array 'integers'", | 172 "expected integer, got boolean; unable to populate array 'integers'", |
175 GetPopulateError<ChoiceType::Integers>(*params_value))); | 173 GetPopulateError<ChoiceType::Integers>(*params_value))); |
176 } | 174 } |
177 } | 175 } |
178 | 176 |
179 TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) { | 177 TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) { |
180 { | 178 { |
181 scoped_ptr<base::DictionaryValue> value = Dictionary( | 179 std::unique_ptr<base::DictionaryValue> value = |
182 "data", new base::BinaryValue()); | 180 Dictionary("data", new base::BinaryValue()); |
183 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value))); | 181 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value))); |
184 } | 182 } |
185 { | 183 { |
186 scoped_ptr<base::DictionaryValue> value = Dictionary( | 184 std::unique_ptr<base::DictionaryValue> value = |
187 "data", new FundamentalValue(1.1)); | 185 Dictionary("data", new FundamentalValue(1.1)); |
188 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got number", | 186 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got number", |
189 GetPopulateError<BinaryData>(*value))); | 187 GetPopulateError<BinaryData>(*value))); |
190 } | 188 } |
191 } | 189 } |
192 | 190 |
193 TEST(JsonSchemaCompilerErrorTest, ListExpected) { | 191 TEST(JsonSchemaCompilerErrorTest, ListExpected) { |
194 { | 192 { |
195 scoped_ptr<base::DictionaryValue> value = Dictionary( | 193 std::unique_ptr<base::DictionaryValue> value = |
196 "TheArray", new base::ListValue()); | 194 Dictionary("TheArray", new base::ListValue()); |
197 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value))); | 195 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value))); |
198 } | 196 } |
199 { | 197 { |
200 scoped_ptr<base::DictionaryValue> value = Dictionary( | 198 std::unique_ptr<base::DictionaryValue> value = |
201 "TheArray", new FundamentalValue(5)); | 199 Dictionary("TheArray", new FundamentalValue(5)); |
202 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", | 200 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", |
203 GetPopulateError<ArrayObject>(*value))); | 201 GetPopulateError<ArrayObject>(*value))); |
204 } | 202 } |
205 } | 203 } |
206 | 204 |
207 // GenerateStringToEnumConversion errors | 205 // GenerateStringToEnumConversion errors |
208 | 206 |
209 TEST(JsonSchemaCompilerErrorTest, BadEnumValue) { | 207 TEST(JsonSchemaCompilerErrorTest, BadEnumValue) { |
210 { | 208 { |
211 scoped_ptr<base::DictionaryValue> value = Dictionary( | 209 std::unique_ptr<base::DictionaryValue> value = |
212 "enumeration", new base::StringValue("one")); | 210 Dictionary("enumeration", new base::StringValue("one")); |
213 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<HasEnumeration>(*value))); | 211 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<HasEnumeration>(*value))); |
214 } | 212 } |
215 { | 213 { |
216 scoped_ptr<base::DictionaryValue> value = Dictionary( | 214 std::unique_ptr<base::DictionaryValue> value = |
217 "enumeration", new base::StringValue("bad sauce")); | 215 Dictionary("enumeration", new base::StringValue("bad sauce")); |
218 EXPECT_TRUE(EqualsUtf16("'Enumeration': expected \"one\" or \"two\" " | 216 EXPECT_TRUE(EqualsUtf16("'Enumeration': expected \"one\" or \"two\" " |
219 "or \"three\", got \"bad sauce\"", | 217 "or \"three\", got \"bad sauce\"", |
220 GetPopulateError<HasEnumeration>(*value))); | 218 GetPopulateError<HasEnumeration>(*value))); |
221 } | 219 } |
222 } | 220 } |
223 | 221 |
224 // Warn but don't fail out errors | 222 // Warn but don't fail out errors |
225 | 223 |
226 TEST(JsonSchemaCompilerErrorTest, WarnOnOptionalFailure) { | 224 TEST(JsonSchemaCompilerErrorTest, WarnOnOptionalFailure) { |
227 { | 225 { |
228 scoped_ptr<base::DictionaryValue> value = Dictionary( | 226 std::unique_ptr<base::DictionaryValue> value = |
229 "string", new base::StringValue("bling")); | 227 Dictionary("string", new base::StringValue("bling")); |
230 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalTestType>(*value))); | 228 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalTestType>(*value))); |
231 } | 229 } |
232 { | 230 { |
233 scoped_ptr<base::DictionaryValue> value = Dictionary( | 231 std::unique_ptr<base::DictionaryValue> value = |
234 "string", new base::FundamentalValue(1)); | 232 Dictionary("string", new base::FundamentalValue(1)); |
235 | 233 |
236 OptionalTestType out; | 234 OptionalTestType out; |
237 base::string16 error; | 235 base::string16 error; |
238 EXPECT_TRUE(OptionalTestType::Populate(*value, &out, &error)); | 236 EXPECT_TRUE(OptionalTestType::Populate(*value, &out, &error)); |
239 EXPECT_TRUE(EqualsUtf16("'string': expected string, got integer", | 237 EXPECT_TRUE(EqualsUtf16("'string': expected string, got integer", |
240 error)); | 238 error)); |
241 EXPECT_EQ(NULL, out.string.get()); | 239 EXPECT_EQ(NULL, out.string.get()); |
242 } | 240 } |
243 } | 241 } |
244 | 242 |
245 TEST(JsonSchemaCompilerErrorTest, OptionalBinaryTypeFailure) { | 243 TEST(JsonSchemaCompilerErrorTest, OptionalBinaryTypeFailure) { |
246 { | 244 { |
247 scoped_ptr<base::DictionaryValue> value = Dictionary( | 245 std::unique_ptr<base::DictionaryValue> value = |
248 "data", new base::BinaryValue()); | 246 Dictionary("data", new base::BinaryValue()); |
249 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalBinaryData>(*value))); | 247 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalBinaryData>(*value))); |
250 } | 248 } |
251 { | 249 { |
252 // There's a bug with silent failures if the key doesn't exist. | 250 // There's a bug with silent failures if the key doesn't exist. |
253 scoped_ptr<base::DictionaryValue> value = Dictionary("data", | 251 std::unique_ptr<base::DictionaryValue> value = |
254 new base::FundamentalValue(1)); | 252 Dictionary("data", new base::FundamentalValue(1)); |
255 | 253 |
256 OptionalBinaryData out; | 254 OptionalBinaryData out; |
257 base::string16 error; | 255 base::string16 error; |
258 EXPECT_TRUE(OptionalBinaryData::Populate(*value, &out, &error)); | 256 EXPECT_TRUE(OptionalBinaryData::Populate(*value, &out, &error)); |
259 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got integer", | 257 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got integer", |
260 error)); | 258 error)); |
261 EXPECT_EQ(NULL, out.data.get()); | 259 EXPECT_EQ(NULL, out.data.get()); |
262 } | 260 } |
263 } | 261 } |
264 | 262 |
265 TEST(JsonSchemaCompilerErrorTest, OptionalArrayTypeFailure) { | 263 TEST(JsonSchemaCompilerErrorTest, OptionalArrayTypeFailure) { |
266 { | 264 { |
267 scoped_ptr<base::DictionaryValue> value = Dictionary( | 265 std::unique_ptr<base::DictionaryValue> value = |
268 "TheArray", new base::ListValue()); | 266 Dictionary("TheArray", new base::ListValue()); |
269 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value))); | 267 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value))); |
270 } | 268 } |
271 { | 269 { |
272 scoped_ptr<base::DictionaryValue> value = Dictionary( | 270 std::unique_ptr<base::DictionaryValue> value = |
273 "TheArray", new FundamentalValue(5)); | 271 Dictionary("TheArray", new FundamentalValue(5)); |
274 ArrayObject out; | 272 ArrayObject out; |
275 base::string16 error; | 273 base::string16 error; |
276 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); | 274 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); |
277 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", | 275 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", |
278 error)); | 276 error)); |
279 EXPECT_EQ(NULL, out.the_array.get()); | 277 EXPECT_EQ(NULL, out.the_array.get()); |
280 } | 278 } |
281 } | 279 } |
282 | 280 |
283 TEST(JsonSchemaCompilerErrorTest, OptionalUnableToPopulateArray) { | 281 TEST(JsonSchemaCompilerErrorTest, OptionalUnableToPopulateArray) { |
284 { | 282 { |
285 scoped_ptr<base::ListValue> params_value = List( | 283 std::unique_ptr<base::ListValue> params_value = |
286 new FundamentalValue(5)); | 284 List(new FundamentalValue(5)); |
287 EXPECT_TRUE(EqualsUtf16("", | 285 EXPECT_TRUE(EqualsUtf16("", |
288 GetPopulateError<OptionalChoiceType::Integers>(*params_value))); | 286 GetPopulateError<OptionalChoiceType::Integers>(*params_value))); |
289 } | 287 } |
290 { | 288 { |
291 scoped_ptr<base::ListValue> params_value = List( | 289 std::unique_ptr<base::ListValue> params_value = |
292 new FundamentalValue(5), | 290 List(new FundamentalValue(5), new FundamentalValue(false)); |
293 new FundamentalValue(false)); | |
294 OptionalChoiceType::Integers out; | 291 OptionalChoiceType::Integers out; |
295 base::string16 error; | 292 base::string16 error; |
296 EXPECT_TRUE(OptionalChoiceType::Integers::Populate(*params_value, &out, | 293 EXPECT_TRUE(OptionalChoiceType::Integers::Populate(*params_value, &out, |
297 &error)); | 294 &error)); |
298 EXPECT_TRUE(EqualsUtf16( | 295 EXPECT_TRUE(EqualsUtf16( |
299 "expected integer, got boolean; unable to populate array 'integers'", | 296 "expected integer, got boolean; unable to populate array 'integers'", |
300 error)); | 297 error)); |
301 EXPECT_EQ(NULL, out.as_integer.get()); | 298 EXPECT_EQ(NULL, out.as_integer.get()); |
302 } | 299 } |
303 } | 300 } |
304 | 301 |
305 TEST(JsonSchemaCompilerErrorTest, MultiplePopulationErrors) { | 302 TEST(JsonSchemaCompilerErrorTest, MultiplePopulationErrors) { |
306 { | 303 { |
307 | 304 std::unique_ptr<base::DictionaryValue> value = |
308 scoped_ptr<base::DictionaryValue> value = Dictionary( | 305 Dictionary("TheArray", new FundamentalValue(5)); |
309 "TheArray", new FundamentalValue(5)); | |
310 ArrayObject out; | 306 ArrayObject out; |
311 base::string16 error; | 307 base::string16 error; |
312 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); | 308 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); |
313 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", | 309 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", |
314 error)); | 310 error)); |
315 EXPECT_EQ(NULL, out.the_array.get()); | 311 EXPECT_EQ(NULL, out.the_array.get()); |
316 | 312 |
317 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); | 313 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); |
318 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer; " | 314 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer; " |
319 "'TheArray': expected list, got integer", | 315 "'TheArray': expected list, got integer", |
320 error)); | 316 error)); |
321 EXPECT_EQ(NULL, out.the_array.get()); | 317 EXPECT_EQ(NULL, out.the_array.get()); |
322 } | 318 } |
323 } | 319 } |
324 | 320 |
325 TEST(JsonSchemaCompilerErrorTest, TooManyKeys) { | 321 TEST(JsonSchemaCompilerErrorTest, TooManyKeys) { |
326 { | 322 { |
327 scoped_ptr<base::DictionaryValue> value = Dictionary( | 323 std::unique_ptr<base::DictionaryValue> value = |
328 "string", new base::StringValue("yes")); | 324 Dictionary("string", new base::StringValue("yes")); |
329 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); | 325 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); |
330 } | 326 } |
331 { | 327 { |
332 scoped_ptr<base::DictionaryValue> value = Dictionary( | 328 std::unique_ptr<base::DictionaryValue> value = |
333 "string", new base::StringValue("yes"), | 329 Dictionary("string", new base::StringValue("yes"), "ohno", |
334 "ohno", new base::StringValue("many values")); | 330 new base::StringValue("many values")); |
335 EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'", | 331 EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'", |
336 GetPopulateError<TestType>(*value))); | 332 GetPopulateError<TestType>(*value))); |
337 } | 333 } |
338 } | 334 } |
OLD | NEW |