Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: tools/json_schema_compiler/test/error_generation_unittest.cc

Issue 2476493003: Remove FundamentalValue
Patch Set: Fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 11
12 using namespace test::api::error_generation; 12 using namespace test::api::error_generation;
13 using base::FundamentalValue; 13 using base::Value;
14 using json_schema_compiler::test_util::Dictionary; 14 using json_schema_compiler::test_util::Dictionary;
15 using json_schema_compiler::test_util::List; 15 using json_schema_compiler::test_util::List;
16 16
17 template <typename T> 17 template <typename T>
18 base::string16 GetPopulateError(const base::Value& value) { 18 base::string16 GetPopulateError(const base::Value& value) {
19 base::string16 error; 19 base::string16 error;
20 T test_type; 20 T test_type;
21 T::Populate(value, &test_type, &error); 21 T::Populate(value, &test_type, &error);
22 return error; 22 return error;
23 } 23 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 EXPECT_TRUE(EqualsUtf16("expected integers or integer, got binary", 56 EXPECT_TRUE(EqualsUtf16("expected integers or integer, got binary",
57 GetPopulateError<ChoiceType::Integers>(*value))); 57 GetPopulateError<ChoiceType::Integers>(*value)));
58 } 58 }
59 } 59 }
60 60
61 // GenerateTypePopulateProperty errors 61 // GenerateTypePopulateProperty errors
62 62
63 TEST(JsonSchemaCompilerErrorTest, TypeIsRequired) { 63 TEST(JsonSchemaCompilerErrorTest, TypeIsRequired) {
64 { 64 {
65 std::unique_ptr<base::DictionaryValue> value = 65 std::unique_ptr<base::DictionaryValue> value =
66 Dictionary("integers", new FundamentalValue(5)); 66 Dictionary("integers", new Value(5));
67 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ChoiceType>(*value))); 67 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ChoiceType>(*value)));
68 } 68 }
69 { 69 {
70 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 70 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
71 EXPECT_TRUE(EqualsUtf16("'integers' is required", 71 EXPECT_TRUE(EqualsUtf16("'integers' is required",
72 GetPopulateError<ChoiceType>(*value))); 72 GetPopulateError<ChoiceType>(*value)));
73 } 73 }
74 } 74 }
75 75
76 // GenerateParamsCheck errors 76 // GenerateParamsCheck errors
77 77
78 TEST(JsonSchemaCompilerErrorTest, TooManyParameters) { 78 TEST(JsonSchemaCompilerErrorTest, TooManyParameters) {
79 { 79 {
80 std::unique_ptr<base::ListValue> params_value = 80 std::unique_ptr<base::ListValue> params_value =
81 List(new FundamentalValue(5)); 81 List(new Value(5));
82 base::string16 error; 82 base::string16 error;
83 EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error)); 83 EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error));
84 } 84 }
85 { 85 {
86 std::unique_ptr<base::ListValue> params_value = 86 std::unique_ptr<base::ListValue> params_value =
87 List(new FundamentalValue(5), new FundamentalValue(5)); 87 List(new Value(5), new Value(5));
88 base::string16 error; 88 base::string16 error;
89 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); 89 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error));
90 EXPECT_TRUE(EqualsUtf16("expected 1 arguments, got 2", error)); 90 EXPECT_TRUE(EqualsUtf16("expected 1 arguments, got 2", error));
91 } 91 }
92 } 92 }
93 93
94 // GenerateFunctionParamsCreate errors 94 // GenerateFunctionParamsCreate errors
95 95
96 TEST(JsonSchemaCompilerErrorTest, ParamIsRequired) { 96 TEST(JsonSchemaCompilerErrorTest, ParamIsRequired) {
97 { 97 {
98 std::unique_ptr<base::ListValue> params_value = 98 std::unique_ptr<base::ListValue> params_value =
99 List(new FundamentalValue(5)); 99 List(new Value(5));
100 base::string16 error; 100 base::string16 error;
101 EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error)); 101 EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error));
102 } 102 }
103 { 103 {
104 std::unique_ptr<base::ListValue> params_value = 104 std::unique_ptr<base::ListValue> params_value =
105 List(base::Value::CreateNullValue().release()); 105 List(base::Value::CreateNullValue().release());
106 base::string16 error; 106 base::string16 error;
107 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); 107 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error));
108 EXPECT_TRUE(EqualsUtf16("'num' is required", error)); 108 EXPECT_TRUE(EqualsUtf16("'num' is required", error));
109 } 109 }
110 } 110 }
111 111
112 // GeneratePopulateVariableFromValue errors 112 // GeneratePopulateVariableFromValue errors
113 113
114 TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) { 114 TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) {
115 { 115 {
116 std::unique_ptr<base::DictionaryValue> value = 116 std::unique_ptr<base::DictionaryValue> value =
117 Dictionary("string", new base::StringValue("yes")); 117 Dictionary("string", new base::StringValue("yes"));
118 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); 118 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value)));
119 } 119 }
120 { 120 {
121 std::unique_ptr<base::DictionaryValue> value = 121 std::unique_ptr<base::DictionaryValue> value =
122 Dictionary("string", new FundamentalValue(1.1)); 122 Dictionary("string", new Value(1.1));
123 EXPECT_TRUE(EqualsUtf16("'string': expected string, got double", 123 EXPECT_TRUE(EqualsUtf16("'string': expected string, got double",
124 GetPopulateError<TestType>(*value))); 124 GetPopulateError<TestType>(*value)));
125 } 125 }
126 } 126 }
127 127
128 TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) { 128 TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) {
129 { 129 {
130 base::string16 error; 130 base::string16 error;
131 std::unique_ptr<base::ListValue> params_value = 131 std::unique_ptr<base::ListValue> params_value =
132 List(new base::StringValue("Yeah!")); 132 List(new base::StringValue("Yeah!"));
133 EXPECT_TRUE(TestString::Params::Create(*params_value, &error)); 133 EXPECT_TRUE(TestString::Params::Create(*params_value, &error));
134 } 134 }
135 { 135 {
136 std::unique_ptr<base::ListValue> params_value = 136 std::unique_ptr<base::ListValue> params_value =
137 List(new FundamentalValue(5)); 137 List(new Value(5));
138 base::string16 error; 138 base::string16 error;
139 EXPECT_FALSE(TestTypeInObject::Params::Create(*params_value, &error)); 139 EXPECT_FALSE(TestTypeInObject::Params::Create(*params_value, &error));
140 EXPECT_TRUE(EqualsUtf16("'paramObject': expected dictionary, got integer", 140 EXPECT_TRUE(EqualsUtf16("'paramObject': expected dictionary, got integer",
141 error)); 141 error));
142 } 142 }
143 } 143 }
144 144
145 TEST(JsonSchemaCompilerErrorTest, WrongTypeValueType) { 145 TEST(JsonSchemaCompilerErrorTest, WrongTypeValueType) {
146 { 146 {
147 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 147 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
148 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ObjectType>(*value))); 148 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ObjectType>(*value)));
149 } 149 }
150 { 150 {
151 std::unique_ptr<base::DictionaryValue> value = 151 std::unique_ptr<base::DictionaryValue> value =
152 Dictionary("otherType", new FundamentalValue(1.1)); 152 Dictionary("otherType", new Value(1.1));
153 ObjectType out; 153 ObjectType out;
154 base::string16 error; 154 base::string16 error;
155 EXPECT_TRUE(ObjectType::Populate(*value, &out, &error)); 155 EXPECT_TRUE(ObjectType::Populate(*value, &out, &error));
156 EXPECT_TRUE(EqualsUtf16("'otherType': expected dictionary, got double", 156 EXPECT_TRUE(EqualsUtf16("'otherType': expected dictionary, got double",
157 error)); 157 error));
158 EXPECT_EQ(NULL, out.other_type.get()); 158 EXPECT_EQ(NULL, out.other_type.get());
159 } 159 }
160 } 160 }
161 161
162 TEST(JsonSchemaCompilerErrorTest, UnableToPopulateArray) { 162 TEST(JsonSchemaCompilerErrorTest, UnableToPopulateArray) {
163 { 163 {
164 std::unique_ptr<base::ListValue> params_value = 164 std::unique_ptr<base::ListValue> params_value =
165 List(new FundamentalValue(5)); 165 List(new Value(5));
166 EXPECT_TRUE(EqualsUtf16("", 166 EXPECT_TRUE(EqualsUtf16("",
167 GetPopulateError<ChoiceType::Integers>(*params_value))); 167 GetPopulateError<ChoiceType::Integers>(*params_value)));
168 } 168 }
169 { 169 {
170 std::unique_ptr<base::ListValue> params_value = 170 std::unique_ptr<base::ListValue> params_value =
171 List(new FundamentalValue(5), new FundamentalValue(false)); 171 List(new Value(5), new Value(false));
172 EXPECT_TRUE(EqualsUtf16( 172 EXPECT_TRUE(EqualsUtf16(
173 "expected integer, got boolean; unable to populate array 'integers'", 173 "expected integer, got boolean; unable to populate array 'integers'",
174 GetPopulateError<ChoiceType::Integers>(*params_value))); 174 GetPopulateError<ChoiceType::Integers>(*params_value)));
175 } 175 }
176 } 176 }
177 177
178 TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) { 178 TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) {
179 { 179 {
180 std::unique_ptr<base::DictionaryValue> value = 180 std::unique_ptr<base::DictionaryValue> value =
181 Dictionary("data", new base::BinaryValue()); 181 Dictionary("data", new base::BinaryValue());
182 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value))); 182 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value)));
183 } 183 }
184 { 184 {
185 std::unique_ptr<base::DictionaryValue> value = 185 std::unique_ptr<base::DictionaryValue> value =
186 Dictionary("data", new FundamentalValue(1.1)); 186 Dictionary("data", new Value(1.1));
187 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got double", 187 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got double",
188 GetPopulateError<BinaryData>(*value))); 188 GetPopulateError<BinaryData>(*value)));
189 } 189 }
190 } 190 }
191 191
192 TEST(JsonSchemaCompilerErrorTest, ListExpected) { 192 TEST(JsonSchemaCompilerErrorTest, ListExpected) {
193 { 193 {
194 std::unique_ptr<base::DictionaryValue> value = 194 std::unique_ptr<base::DictionaryValue> value =
195 Dictionary("TheArray", new base::ListValue()); 195 Dictionary("TheArray", new base::ListValue());
196 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value))); 196 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value)));
197 } 197 }
198 { 198 {
199 std::unique_ptr<base::DictionaryValue> value = 199 std::unique_ptr<base::DictionaryValue> value =
200 Dictionary("TheArray", new FundamentalValue(5)); 200 Dictionary("TheArray", new Value(5));
201 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", 201 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer",
202 GetPopulateError<ArrayObject>(*value))); 202 GetPopulateError<ArrayObject>(*value)));
203 } 203 }
204 } 204 }
205 205
206 // GenerateStringToEnumConversion errors 206 // GenerateStringToEnumConversion errors
207 207
208 TEST(JsonSchemaCompilerErrorTest, BadEnumValue) { 208 TEST(JsonSchemaCompilerErrorTest, BadEnumValue) {
209 { 209 {
210 std::unique_ptr<base::DictionaryValue> value = 210 std::unique_ptr<base::DictionaryValue> value =
(...skipping 12 matching lines...) Expand all
223 // Warn but don't fail out errors 223 // Warn but don't fail out errors
224 224
225 TEST(JsonSchemaCompilerErrorTest, WarnOnOptionalFailure) { 225 TEST(JsonSchemaCompilerErrorTest, WarnOnOptionalFailure) {
226 { 226 {
227 std::unique_ptr<base::DictionaryValue> value = 227 std::unique_ptr<base::DictionaryValue> value =
228 Dictionary("string", new base::StringValue("bling")); 228 Dictionary("string", new base::StringValue("bling"));
229 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalTestType>(*value))); 229 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalTestType>(*value)));
230 } 230 }
231 { 231 {
232 std::unique_ptr<base::DictionaryValue> value = 232 std::unique_ptr<base::DictionaryValue> value =
233 Dictionary("string", new base::FundamentalValue(1)); 233 Dictionary("string", new base::Value(1));
234 234
235 OptionalTestType out; 235 OptionalTestType out;
236 base::string16 error; 236 base::string16 error;
237 EXPECT_TRUE(OptionalTestType::Populate(*value, &out, &error)); 237 EXPECT_TRUE(OptionalTestType::Populate(*value, &out, &error));
238 EXPECT_TRUE(EqualsUtf16("'string': expected string, got integer", 238 EXPECT_TRUE(EqualsUtf16("'string': expected string, got integer",
239 error)); 239 error));
240 EXPECT_EQ(NULL, out.string.get()); 240 EXPECT_EQ(NULL, out.string.get());
241 } 241 }
242 } 242 }
243 243
244 TEST(JsonSchemaCompilerErrorTest, OptionalBinaryTypeFailure) { 244 TEST(JsonSchemaCompilerErrorTest, OptionalBinaryTypeFailure) {
245 { 245 {
246 std::unique_ptr<base::DictionaryValue> value = 246 std::unique_ptr<base::DictionaryValue> value =
247 Dictionary("data", new base::BinaryValue()); 247 Dictionary("data", new base::BinaryValue());
248 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalBinaryData>(*value))); 248 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalBinaryData>(*value)));
249 } 249 }
250 { 250 {
251 // There's a bug with silent failures if the key doesn't exist. 251 // There's a bug with silent failures if the key doesn't exist.
252 std::unique_ptr<base::DictionaryValue> value = 252 std::unique_ptr<base::DictionaryValue> value =
253 Dictionary("data", new base::FundamentalValue(1)); 253 Dictionary("data", new base::Value(1));
254 254
255 OptionalBinaryData out; 255 OptionalBinaryData out;
256 base::string16 error; 256 base::string16 error;
257 EXPECT_TRUE(OptionalBinaryData::Populate(*value, &out, &error)); 257 EXPECT_TRUE(OptionalBinaryData::Populate(*value, &out, &error));
258 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got integer", 258 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got integer",
259 error)); 259 error));
260 EXPECT_EQ(NULL, out.data.get()); 260 EXPECT_EQ(NULL, out.data.get());
261 } 261 }
262 } 262 }
263 263
264 TEST(JsonSchemaCompilerErrorTest, OptionalArrayTypeFailure) { 264 TEST(JsonSchemaCompilerErrorTest, OptionalArrayTypeFailure) {
265 { 265 {
266 std::unique_ptr<base::DictionaryValue> value = 266 std::unique_ptr<base::DictionaryValue> value =
267 Dictionary("TheArray", new base::ListValue()); 267 Dictionary("TheArray", new base::ListValue());
268 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value))); 268 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value)));
269 } 269 }
270 { 270 {
271 std::unique_ptr<base::DictionaryValue> value = 271 std::unique_ptr<base::DictionaryValue> value =
272 Dictionary("TheArray", new FundamentalValue(5)); 272 Dictionary("TheArray", new Value(5));
273 ArrayObject out; 273 ArrayObject out;
274 base::string16 error; 274 base::string16 error;
275 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); 275 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error));
276 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", 276 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer",
277 error)); 277 error));
278 EXPECT_EQ(NULL, out.the_array.get()); 278 EXPECT_EQ(NULL, out.the_array.get());
279 } 279 }
280 } 280 }
281 281
282 TEST(JsonSchemaCompilerErrorTest, OptionalUnableToPopulateArray) { 282 TEST(JsonSchemaCompilerErrorTest, OptionalUnableToPopulateArray) {
283 { 283 {
284 std::unique_ptr<base::ListValue> params_value = 284 std::unique_ptr<base::ListValue> params_value =
285 List(new FundamentalValue(5)); 285 List(new Value(5));
286 EXPECT_TRUE(EqualsUtf16("", 286 EXPECT_TRUE(EqualsUtf16("",
287 GetPopulateError<OptionalChoiceType::Integers>(*params_value))); 287 GetPopulateError<OptionalChoiceType::Integers>(*params_value)));
288 } 288 }
289 { 289 {
290 std::unique_ptr<base::ListValue> params_value = 290 std::unique_ptr<base::ListValue> params_value =
291 List(new FundamentalValue(5), new FundamentalValue(false)); 291 List(new Value(5), new Value(false));
292 OptionalChoiceType::Integers out; 292 OptionalChoiceType::Integers out;
293 base::string16 error; 293 base::string16 error;
294 EXPECT_TRUE(OptionalChoiceType::Integers::Populate(*params_value, &out, 294 EXPECT_TRUE(OptionalChoiceType::Integers::Populate(*params_value, &out,
295 &error)); 295 &error));
296 EXPECT_TRUE(EqualsUtf16( 296 EXPECT_TRUE(EqualsUtf16(
297 "expected integer, got boolean; unable to populate array 'integers'", 297 "expected integer, got boolean; unable to populate array 'integers'",
298 error)); 298 error));
299 EXPECT_EQ(NULL, out.as_integer.get()); 299 EXPECT_EQ(NULL, out.as_integer.get());
300 } 300 }
301 } 301 }
302 302
303 TEST(JsonSchemaCompilerErrorTest, MultiplePopulationErrors) { 303 TEST(JsonSchemaCompilerErrorTest, MultiplePopulationErrors) {
304 { 304 {
305 std::unique_ptr<base::DictionaryValue> value = 305 std::unique_ptr<base::DictionaryValue> value =
306 Dictionary("TheArray", new FundamentalValue(5)); 306 Dictionary("TheArray", new Value(5));
307 ArrayObject out; 307 ArrayObject out;
308 base::string16 error; 308 base::string16 error;
309 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); 309 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error));
310 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", 310 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer",
311 error)); 311 error));
312 EXPECT_EQ(NULL, out.the_array.get()); 312 EXPECT_EQ(NULL, out.the_array.get());
313 313
314 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); 314 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error));
315 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer; " 315 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer; "
316 "'TheArray': expected list, got integer", 316 "'TheArray': expected list, got integer",
317 error)); 317 error));
318 EXPECT_EQ(NULL, out.the_array.get()); 318 EXPECT_EQ(NULL, out.the_array.get());
319 } 319 }
320 } 320 }
321 321
322 TEST(JsonSchemaCompilerErrorTest, TooManyKeys) { 322 TEST(JsonSchemaCompilerErrorTest, TooManyKeys) {
323 { 323 {
324 std::unique_ptr<base::DictionaryValue> value = 324 std::unique_ptr<base::DictionaryValue> value =
325 Dictionary("string", new base::StringValue("yes")); 325 Dictionary("string", new base::StringValue("yes"));
326 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); 326 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value)));
327 } 327 }
328 { 328 {
329 std::unique_ptr<base::DictionaryValue> value = 329 std::unique_ptr<base::DictionaryValue> value =
330 Dictionary("string", new base::StringValue("yes"), "ohno", 330 Dictionary("string", new base::StringValue("yes"), "ohno",
331 new base::StringValue("many values")); 331 new base::StringValue("many values"));
332 EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'", 332 EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'",
333 GetPopulateError<TestType>(*value))); 333 GetPopulateError<TestType>(*value)));
334 } 334 }
335 } 335 }
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/crossref_unittest.cc ('k') | tools/json_schema_compiler/test/idl_schemas_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698