| 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 "chrome/common/json_schema_validator_unittest_base.h" | 5 #include "chrome/common/json_schema_validator_unittest_base.h" |
| 6 | 6 |
| 7 #include <cfloat> | 7 #include <cfloat> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/json/json_file_value_serializer.h" | 12 #include "base/json/json_file_value_serializer.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/json_schema_constants.h" |
| 19 #include "chrome/common/json_schema_validator.h" | 20 #include "chrome/common/json_schema_validator.h" |
| 20 | 21 |
| 22 namespace schema = json_schema_constants; |
| 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 #define TEST_SOURCE base::StringPrintf("%s:%i", __FILE__, __LINE__) | 26 #define TEST_SOURCE base::StringPrintf("%s:%i", __FILE__, __LINE__) |
| 24 | 27 |
| 25 Value* LoadValue(const std::string& filename) { | 28 Value* LoadValue(const std::string& filename) { |
| 26 FilePath path; | 29 FilePath path; |
| 27 PathService::Get(chrome::DIR_TEST_DATA, &path); | 30 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 28 path = path.AppendASCII("json_schema_validator").AppendASCII(filename); | 31 path = path.AppendASCII("json_schema_validator").AppendASCII(filename); |
| 29 EXPECT_TRUE(file_util::PathExists(path)); | 32 EXPECT_TRUE(file_util::PathExists(path)); |
| 30 | 33 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 TestStringPattern(); | 73 TestStringPattern(); |
| 71 TestEnum(); | 74 TestEnum(); |
| 72 TestChoices(); | 75 TestChoices(); |
| 73 TestExtends(); | 76 TestExtends(); |
| 74 TestObject(); | 77 TestObject(); |
| 75 TestTypeReference(); | 78 TestTypeReference(); |
| 76 TestArrayTuple(); | 79 TestArrayTuple(); |
| 77 TestArrayNonTuple(); | 80 TestArrayNonTuple(); |
| 78 TestString(); | 81 TestString(); |
| 79 TestNumber(); | 82 TestNumber(); |
| 80 TestTypeClassifier(); | 83 TestValueTypeClassifier(); |
| 84 TestSchemaTypeClassifier(); |
| 81 TestTypes(); | 85 TestTypes(); |
| 82 } | 86 } |
| 83 | 87 |
| 84 void JSONSchemaValidatorTestBase::TestComplex() { | 88 void JSONSchemaValidatorTestBase::TestComplex() { |
| 85 scoped_ptr<DictionaryValue> schema(LoadDictionary("complex_schema.json")); | 89 scoped_ptr<DictionaryValue> schema(LoadDictionary("complex_schema.json")); |
| 86 scoped_ptr<ListValue> instance(LoadList("complex_instance.json")); | 90 scoped_ptr<ListValue> instance(LoadList("complex_instance.json")); |
| 87 | 91 |
| 88 ASSERT_TRUE(schema.get()); | 92 ASSERT_TRUE(schema.get()); |
| 89 ASSERT_TRUE(instance.get()); | 93 ASSERT_TRUE(instance.get()); |
| 90 | 94 |
| 91 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 95 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 92 instance->Remove(instance->GetSize() - 1, NULL); | 96 instance->Remove(instance->GetSize() - 1, NULL); |
| 93 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 97 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 94 instance->Append(new DictionaryValue()); | 98 instance->Append(new DictionaryValue()); |
| 95 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", | 99 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", |
| 96 JSONSchemaValidator::FormatErrorMessage( | 100 JSONSchemaValidator::FormatErrorMessage( |
| 97 JSONSchemaValidator::kInvalidType, "number", "object")); | 101 JSONSchemaValidator::kInvalidType, |
| 102 schema::kNumber, |
| 103 schema::kObject)); |
| 98 instance->Remove(instance->GetSize() - 1, NULL); | 104 instance->Remove(instance->GetSize() - 1, NULL); |
| 99 | 105 |
| 100 DictionaryValue* item = NULL; | 106 DictionaryValue* item = NULL; |
| 101 ASSERT_TRUE(instance->GetDictionary(0, &item)); | 107 ASSERT_TRUE(instance->GetDictionary(0, &item)); |
| 102 item->SetString("url", "xxxxxxxxxxx"); | 108 item->SetString("url", "xxxxxxxxxxx"); |
| 103 | 109 |
| 104 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, | 110 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, |
| 105 "0.url", | 111 "0.url", |
| 106 JSONSchemaValidator::FormatErrorMessage( | 112 JSONSchemaValidator::FormatErrorMessage( |
| 107 JSONSchemaValidator::kStringMaxLength, "10")); | 113 JSONSchemaValidator::kStringMaxLength, "10")); |
| 108 } | 114 } |
| 109 | 115 |
| 110 void JSONSchemaValidatorTestBase::TestStringPattern() { | 116 void JSONSchemaValidatorTestBase::TestStringPattern() { |
| 111 // Regex patterns not supported in CPP validator. | 117 // Regex patterns not supported in CPP validator. |
| 112 if (type_ == CPP) | 118 if (type_ == CPP) |
| 113 return; | 119 return; |
| 114 | 120 |
| 115 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); | 121 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); |
| 116 schema->SetString("type", "string"); | 122 schema->SetString(schema::kType, schema::kString); |
| 117 schema->SetString("pattern", "foo+"); | 123 schema->SetString(schema::kPattern, "foo+"); |
| 118 | 124 |
| 119 ExpectValid(TEST_SOURCE, | 125 ExpectValid(TEST_SOURCE, |
| 120 scoped_ptr<Value>(Value::CreateStringValue("foo")).get(), | 126 scoped_ptr<Value>(Value::CreateStringValue("foo")).get(), |
| 121 schema.get(), NULL); | 127 schema.get(), NULL); |
| 122 ExpectValid(TEST_SOURCE, | 128 ExpectValid(TEST_SOURCE, |
| 123 scoped_ptr<Value>(Value::CreateStringValue("foooooo")).get(), | 129 scoped_ptr<Value>(Value::CreateStringValue("foooooo")).get(), |
| 124 schema.get(), NULL); | 130 schema.get(), NULL); |
| 125 ExpectNotValid(TEST_SOURCE, | 131 ExpectNotValid(TEST_SOURCE, |
| 126 scoped_ptr<Value>(Value::CreateStringValue("bar")).get(), | 132 scoped_ptr<Value>(Value::CreateStringValue("bar")).get(), |
| 127 schema.get(), NULL, "", | 133 schema.get(), NULL, "", |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 ExpectNotValid(TEST_SOURCE, instance.get(), | 181 ExpectNotValid(TEST_SOURCE, instance.get(), |
| 176 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice); | 182 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice); |
| 177 } | 183 } |
| 178 | 184 |
| 179 void JSONSchemaValidatorTestBase::TestExtends() { | 185 void JSONSchemaValidatorTestBase::TestExtends() { |
| 180 // TODO(aa): JS only | 186 // TODO(aa): JS only |
| 181 } | 187 } |
| 182 | 188 |
| 183 void JSONSchemaValidatorTestBase::TestObject() { | 189 void JSONSchemaValidatorTestBase::TestObject() { |
| 184 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); | 190 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); |
| 185 schema->SetString("type", "object"); | 191 schema->SetString(schema::kType, schema::kObject); |
| 186 schema->SetString("properties.foo.type", "string"); | 192 schema->SetString("properties.foo.type", schema::kString); |
| 187 schema->SetString("properties.bar.type", "integer"); | 193 schema->SetString("properties.bar.type", schema::kInteger); |
| 188 | 194 |
| 189 scoped_ptr<DictionaryValue> instance(new DictionaryValue()); | 195 scoped_ptr<DictionaryValue> instance(new DictionaryValue()); |
| 190 instance->SetString("foo", "foo"); | 196 instance->SetString("foo", "foo"); |
| 191 instance->SetInteger("bar", 42); | 197 instance->SetInteger("bar", 42); |
| 192 | 198 |
| 193 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 199 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 194 | 200 |
| 195 instance->SetBoolean("extra", true); | 201 instance->SetBoolean("extra", true); |
| 196 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, | 202 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, |
| 197 "extra", JSONSchemaValidator::kUnexpectedProperty); | 203 "extra", JSONSchemaValidator::kUnexpectedProperty); |
| 198 | 204 |
| 199 instance->Remove("extra", NULL); | 205 instance->Remove("extra", NULL); |
| 200 instance->Remove("bar", NULL); | 206 instance->Remove("bar", NULL); |
| 201 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar", | 207 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar", |
| 202 JSONSchemaValidator::kObjectPropertyIsRequired); | 208 JSONSchemaValidator::kObjectPropertyIsRequired); |
| 203 | 209 |
| 204 instance->SetString("bar", "42"); | 210 instance->SetString("bar", "42"); |
| 205 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar", | 211 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar", |
| 206 JSONSchemaValidator::FormatErrorMessage( | 212 JSONSchemaValidator::FormatErrorMessage( |
| 207 JSONSchemaValidator::kInvalidType, "integer", "string")); | 213 JSONSchemaValidator::kInvalidType, |
| 214 schema::kInteger, |
| 215 schema::kString)); |
| 208 | 216 |
| 209 DictionaryValue* additional_properties = new DictionaryValue(); | 217 DictionaryValue* additional_properties = new DictionaryValue(); |
| 210 additional_properties->SetString("type", "any"); | 218 additional_properties->SetString(schema::kType, schema::kAny); |
| 211 schema->Set("additionalProperties", additional_properties); | 219 schema->Set(schema::kAdditionalProperties, additional_properties); |
| 212 | 220 |
| 213 instance->SetInteger("bar", 42); | 221 instance->SetInteger("bar", 42); |
| 214 instance->SetBoolean("extra", true); | 222 instance->SetBoolean("extra", true); |
| 215 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 223 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 216 | 224 |
| 217 instance->SetString("extra", "foo"); | 225 instance->SetString("extra", "foo"); |
| 218 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 226 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 219 | 227 |
| 220 additional_properties->SetString("type", "boolean"); | 228 additional_properties->SetString(schema::kType, schema::kBoolean); |
| 221 instance->SetBoolean("extra", true); | 229 instance->SetBoolean("extra", true); |
| 222 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 230 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 223 | 231 |
| 224 instance->SetString("extra", "foo"); | 232 instance->SetString("extra", "foo"); |
| 225 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, | 233 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, |
| 226 "extra", JSONSchemaValidator::FormatErrorMessage( | 234 "extra", JSONSchemaValidator::FormatErrorMessage( |
| 227 JSONSchemaValidator::kInvalidType, "boolean", "string")); | 235 JSONSchemaValidator::kInvalidType, |
| 236 schema::kBoolean, |
| 237 schema::kString)); |
| 228 | 238 |
| 229 DictionaryValue* properties = NULL; | 239 DictionaryValue* properties = NULL; |
| 230 DictionaryValue* bar_property = NULL; | 240 DictionaryValue* bar_property = NULL; |
| 231 ASSERT_TRUE(schema->GetDictionary("properties", &properties)); | 241 ASSERT_TRUE(schema->GetDictionary(schema::kProperties, &properties)); |
| 232 ASSERT_TRUE(properties->GetDictionary("bar", &bar_property)); | 242 ASSERT_TRUE(properties->GetDictionary("bar", &bar_property)); |
| 233 | 243 |
| 234 bar_property->SetBoolean("optional", true); | 244 bar_property->SetBoolean(schema::kOptional, true); |
| 235 instance->Remove("extra", NULL); | 245 instance->Remove("extra", NULL); |
| 236 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 246 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 237 instance->Remove("bar", NULL); | 247 instance->Remove("bar", NULL); |
| 238 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 248 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 239 instance->Set("bar", Value::CreateNullValue()); | 249 instance->Set("bar", Value::CreateNullValue()); |
| 240 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, | 250 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, |
| 241 "bar", JSONSchemaValidator::FormatErrorMessage( | 251 "bar", JSONSchemaValidator::FormatErrorMessage( |
| 242 JSONSchemaValidator::kInvalidType, "integer", "null")); | 252 JSONSchemaValidator::kInvalidType, |
| 253 schema::kInteger, |
| 254 schema::kNull)); |
| 243 instance->SetString("bar", "42"); | 255 instance->SetString("bar", "42"); |
| 244 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, | 256 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, |
| 245 "bar", JSONSchemaValidator::FormatErrorMessage( | 257 "bar", JSONSchemaValidator::FormatErrorMessage( |
| 246 JSONSchemaValidator::kInvalidType, "integer", "string")); | 258 JSONSchemaValidator::kInvalidType, |
| 259 schema::kInteger, |
| 260 schema::kString)); |
| 247 } | 261 } |
| 248 | 262 |
| 249 void JSONSchemaValidatorTestBase::TestTypeReference() { | 263 void JSONSchemaValidatorTestBase::TestTypeReference() { |
| 250 scoped_ptr<ListValue> types(LoadList("reference_types.json")); | 264 scoped_ptr<ListValue> types(LoadList("reference_types.json")); |
| 251 ASSERT_TRUE(types.get()); | 265 ASSERT_TRUE(types.get()); |
| 252 | 266 |
| 253 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); | 267 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); |
| 254 schema->SetString("type", "object"); | 268 schema->SetString(schema::kType, schema::kObject); |
| 255 schema->SetString("properties.foo.type", "string"); | 269 schema->SetString("properties.foo.type", schema::kString); |
| 256 schema->SetString("properties.bar.$ref", "Max10Int"); | 270 schema->SetString("properties.bar.$ref", "Max10Int"); |
| 257 schema->SetString("properties.baz.$ref", "MinLengthString"); | 271 schema->SetString("properties.baz.$ref", "MinLengthString"); |
| 258 | 272 |
| 259 scoped_ptr<DictionaryValue> schema_inline(new DictionaryValue()); | 273 scoped_ptr<DictionaryValue> schema_inline(new DictionaryValue()); |
| 260 schema_inline->SetString("type", "object"); | 274 schema_inline->SetString(schema::kType, schema::kObject); |
| 261 schema_inline->SetString("properties.foo.type", "string"); | 275 schema_inline->SetString("properties.foo.type", schema::kString); |
| 262 schema_inline->SetString("properties.bar.id", "NegativeInt"); | 276 schema_inline->SetString("properties.bar.id", "NegativeInt"); |
| 263 schema_inline->SetString("properties.bar.type", "integer"); | 277 schema_inline->SetString("properties.bar.type", schema::kInteger); |
| 264 schema_inline->SetInteger("properties.bar.maximum", 0); | 278 schema_inline->SetInteger("properties.bar.maximum", 0); |
| 265 schema_inline->SetString("properties.baz.$ref", "NegativeInt"); | 279 schema_inline->SetString("properties.baz.$ref", "NegativeInt"); |
| 266 | 280 |
| 267 scoped_ptr<DictionaryValue> instance(new DictionaryValue()); | 281 scoped_ptr<DictionaryValue> instance(new DictionaryValue()); |
| 268 instance->SetString("foo", "foo"); | 282 instance->SetString("foo", "foo"); |
| 269 instance->SetInteger("bar", 4); | 283 instance->SetInteger("bar", 4); |
| 270 instance->SetString("baz", "ab"); | 284 instance->SetString("baz", "ab"); |
| 271 | 285 |
| 272 scoped_ptr<DictionaryValue> instance_inline(new DictionaryValue()); | 286 scoped_ptr<DictionaryValue> instance_inline(new DictionaryValue()); |
| 273 instance_inline->SetString("foo", "foo"); | 287 instance_inline->SetString("foo", "foo"); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 336 |
| 323 instance->Remove(1, NULL); | 337 instance->Remove(1, NULL); |
| 324 instance->Remove(1, NULL); | 338 instance->Remove(1, NULL); |
| 325 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", | 339 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", |
| 326 JSONSchemaValidator::kArrayItemRequired); | 340 JSONSchemaValidator::kArrayItemRequired); |
| 327 | 341 |
| 328 instance->Set(0, Value::CreateIntegerValue(42)); | 342 instance->Set(0, Value::CreateIntegerValue(42)); |
| 329 instance->Append(Value::CreateIntegerValue(42)); | 343 instance->Append(Value::CreateIntegerValue(42)); |
| 330 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", | 344 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", |
| 331 JSONSchemaValidator::FormatErrorMessage( | 345 JSONSchemaValidator::FormatErrorMessage( |
| 332 JSONSchemaValidator::kInvalidType, "string", "integer")); | 346 JSONSchemaValidator::kInvalidType, |
| 347 schema::kString, |
| 348 schema::kInteger)); |
| 333 | 349 |
| 334 DictionaryValue* additional_properties = new DictionaryValue(); | 350 DictionaryValue* additional_properties = new DictionaryValue(); |
| 335 additional_properties->SetString("type", "any"); | 351 additional_properties->SetString(schema::kType, schema::kAny); |
| 336 schema->Set("additionalProperties", additional_properties); | 352 schema->Set(schema::kAdditionalProperties, additional_properties); |
| 337 instance->Set(0, Value::CreateStringValue("42")); | 353 instance->Set(0, Value::CreateStringValue("42")); |
| 338 instance->Append(Value::CreateStringValue("anything")); | 354 instance->Append(Value::CreateStringValue("anything")); |
| 339 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 355 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 340 instance->Set(2, new ListValue()); | 356 instance->Set(2, new ListValue()); |
| 341 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 357 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 342 | 358 |
| 343 additional_properties->SetString("type", "boolean"); | 359 additional_properties->SetString(schema::kType, schema::kBoolean); |
| 344 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2", | 360 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2", |
| 345 JSONSchemaValidator::FormatErrorMessage( | 361 JSONSchemaValidator::FormatErrorMessage( |
| 346 JSONSchemaValidator::kInvalidType, "boolean", "array")); | 362 JSONSchemaValidator::kInvalidType, |
| 363 schema::kBoolean, |
| 364 schema::kArray)); |
| 347 instance->Set(2, Value::CreateBooleanValue(false)); | 365 instance->Set(2, Value::CreateBooleanValue(false)); |
| 348 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 366 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 349 | 367 |
| 350 ListValue* items_schema = NULL; | 368 ListValue* items_schema = NULL; |
| 351 DictionaryValue* item0_schema = NULL; | 369 DictionaryValue* item0_schema = NULL; |
| 352 ASSERT_TRUE(schema->GetList("items", &items_schema)); | 370 ASSERT_TRUE(schema->GetList(schema::kItems, &items_schema)); |
| 353 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema)); | 371 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema)); |
| 354 item0_schema->SetBoolean("optional", true); | 372 item0_schema->SetBoolean(schema::kOptional, true); |
| 355 instance->Remove(2, NULL); | 373 instance->Remove(2, NULL); |
| 356 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 374 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 357 // TODO(aa): I think this is inconsistent with the handling of NULL+optional | 375 // TODO(aa): I think this is inconsistent with the handling of NULL+optional |
| 358 // for objects. | 376 // for objects. |
| 359 instance->Set(0, Value::CreateNullValue()); | 377 instance->Set(0, Value::CreateNullValue()); |
| 360 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 378 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 361 instance->Set(0, Value::CreateIntegerValue(42)); | 379 instance->Set(0, Value::CreateIntegerValue(42)); |
| 362 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", | 380 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", |
| 363 JSONSchemaValidator::FormatErrorMessage( | 381 JSONSchemaValidator::FormatErrorMessage( |
| 364 JSONSchemaValidator::kInvalidType, "string", "integer")); | 382 JSONSchemaValidator::kInvalidType, |
| 383 schema::kString, |
| 384 schema::kInteger)); |
| 365 } | 385 } |
| 366 | 386 |
| 367 void JSONSchemaValidatorTestBase::TestArrayNonTuple() { | 387 void JSONSchemaValidatorTestBase::TestArrayNonTuple() { |
| 368 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); | 388 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); |
| 369 schema->SetString("type", "array"); | 389 schema->SetString(schema::kType, schema::kArray); |
| 370 schema->SetString("items.type", "string"); | 390 schema->SetString("items.type", schema::kString); |
| 371 schema->SetInteger("minItems", 2); | 391 schema->SetInteger(schema::kMinItems, 2); |
| 372 schema->SetInteger("maxItems", 3); | 392 schema->SetInteger(schema::kMaxItems, 3); |
| 373 | 393 |
| 374 scoped_ptr<ListValue> instance(new ListValue()); | 394 scoped_ptr<ListValue> instance(new ListValue()); |
| 375 instance->Append(Value::CreateStringValue("x")); | 395 instance->Append(Value::CreateStringValue("x")); |
| 376 instance->Append(Value::CreateStringValue("x")); | 396 instance->Append(Value::CreateStringValue("x")); |
| 377 | 397 |
| 378 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 398 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 379 instance->Append(Value::CreateStringValue("x")); | 399 instance->Append(Value::CreateStringValue("x")); |
| 380 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 400 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| 381 | 401 |
| 382 instance->Append(Value::CreateStringValue("x")); | 402 instance->Append(Value::CreateStringValue("x")); |
| 383 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "", | 403 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "", |
| 384 JSONSchemaValidator::FormatErrorMessage( | 404 JSONSchemaValidator::FormatErrorMessage( |
| 385 JSONSchemaValidator::kArrayMaxItems, "3")); | 405 JSONSchemaValidator::kArrayMaxItems, "3")); |
| 386 instance->Remove(1, NULL); | 406 instance->Remove(1, NULL); |
| 387 instance->Remove(1, NULL); | 407 instance->Remove(1, NULL); |
| 388 instance->Remove(1, NULL); | 408 instance->Remove(1, NULL); |
| 389 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "", | 409 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "", |
| 390 JSONSchemaValidator::FormatErrorMessage( | 410 JSONSchemaValidator::FormatErrorMessage( |
| 391 JSONSchemaValidator::kArrayMinItems, "2")); | 411 JSONSchemaValidator::kArrayMinItems, "2")); |
| 392 | 412 |
| 393 instance->Remove(1, NULL); | 413 instance->Remove(1, NULL); |
| 394 instance->Append(Value::CreateIntegerValue(42)); | 414 instance->Append(Value::CreateIntegerValue(42)); |
| 395 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", | 415 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", |
| 396 JSONSchemaValidator::FormatErrorMessage( | 416 JSONSchemaValidator::FormatErrorMessage( |
| 397 JSONSchemaValidator::kInvalidType, "string", "integer")); | 417 JSONSchemaValidator::kInvalidType, |
| 418 schema::kString, |
| 419 schema::kInteger)); |
| 398 } | 420 } |
| 399 | 421 |
| 400 void JSONSchemaValidatorTestBase::TestString() { | 422 void JSONSchemaValidatorTestBase::TestString() { |
| 401 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); | 423 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); |
| 402 schema->SetString("type", "string"); | 424 schema->SetString(schema::kType, schema::kString); |
| 403 schema->SetInteger("minLength", 1); | 425 schema->SetInteger(schema::kMinLength, 1); |
| 404 schema->SetInteger("maxLength", 10); | 426 schema->SetInteger(schema::kMaxLength, 10); |
| 405 | 427 |
| 406 ExpectValid(TEST_SOURCE, | 428 ExpectValid(TEST_SOURCE, |
| 407 scoped_ptr<Value>(Value::CreateStringValue("x")).get(), | 429 scoped_ptr<Value>(Value::CreateStringValue("x")).get(), |
| 408 schema.get(), NULL); | 430 schema.get(), NULL); |
| 409 ExpectValid(TEST_SOURCE, | 431 ExpectValid(TEST_SOURCE, |
| 410 scoped_ptr<Value>(Value::CreateStringValue("xxxxxxxxxx")).get(), | 432 scoped_ptr<Value>(Value::CreateStringValue("xxxxxxxxxx")).get(), |
| 411 schema.get(), NULL); | 433 schema.get(), NULL); |
| 412 | 434 |
| 413 ExpectNotValid(TEST_SOURCE, | 435 ExpectNotValid(TEST_SOURCE, |
| 414 scoped_ptr<Value>(Value::CreateStringValue("")).get(), | 436 scoped_ptr<Value>(Value::CreateStringValue("")).get(), |
| 415 schema.get(), NULL, "", | 437 schema.get(), NULL, "", |
| 416 JSONSchemaValidator::FormatErrorMessage( | 438 JSONSchemaValidator::FormatErrorMessage( |
| 417 JSONSchemaValidator::kStringMinLength, "1")); | 439 JSONSchemaValidator::kStringMinLength, "1")); |
| 418 ExpectNotValid( | 440 ExpectNotValid( |
| 419 TEST_SOURCE, | 441 TEST_SOURCE, |
| 420 scoped_ptr<Value>(Value::CreateStringValue("xxxxxxxxxxx")).get(), | 442 scoped_ptr<Value>(Value::CreateStringValue("xxxxxxxxxxx")).get(), |
| 421 schema.get(), NULL, "", | 443 schema.get(), NULL, "", |
| 422 JSONSchemaValidator::FormatErrorMessage( | 444 JSONSchemaValidator::FormatErrorMessage( |
| 423 JSONSchemaValidator::kStringMaxLength, "10")); | 445 JSONSchemaValidator::kStringMaxLength, "10")); |
| 424 | 446 |
| 425 } | 447 } |
| 426 | 448 |
| 427 void JSONSchemaValidatorTestBase::TestNumber() { | 449 void JSONSchemaValidatorTestBase::TestNumber() { |
| 428 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); | 450 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); |
| 429 schema->SetString("type", "number"); | 451 schema->SetString(schema::kType, schema::kNumber); |
| 430 schema->SetInteger("minimum", 1); | 452 schema->SetInteger(schema::kMinimum, 1); |
| 431 schema->SetInteger("maximum", 100); | 453 schema->SetInteger(schema::kMaximum, 100); |
| 432 schema->SetInteger("maxDecimal", 2); | 454 schema->SetInteger("maxDecimal", 2); |
| 433 | 455 |
| 434 ExpectValid(TEST_SOURCE, | 456 ExpectValid(TEST_SOURCE, |
| 435 scoped_ptr<Value>(Value::CreateIntegerValue(1)).get(), | 457 scoped_ptr<Value>(Value::CreateIntegerValue(1)).get(), |
| 436 schema.get(), NULL); | 458 schema.get(), NULL); |
| 437 ExpectValid(TEST_SOURCE, | 459 ExpectValid(TEST_SOURCE, |
| 438 scoped_ptr<Value>(Value::CreateIntegerValue(50)).get(), | 460 scoped_ptr<Value>(Value::CreateIntegerValue(50)).get(), |
| 439 schema.get(), NULL); | 461 schema.get(), NULL); |
| 440 ExpectValid(TEST_SOURCE, | 462 ExpectValid(TEST_SOURCE, |
| 441 scoped_ptr<Value>(Value::CreateIntegerValue(100)).get(), | 463 scoped_ptr<Value>(Value::CreateIntegerValue(100)).get(), |
| 442 schema.get(), NULL); | 464 schema.get(), NULL); |
| 443 ExpectValid(TEST_SOURCE, | 465 ExpectValid(TEST_SOURCE, |
| 444 scoped_ptr<Value>(Value::CreateDoubleValue(88.88)).get(), | 466 scoped_ptr<Value>(Value::CreateDoubleValue(88.88)).get(), |
| 445 schema.get(), NULL); | 467 schema.get(), NULL); |
| 446 | 468 |
| 447 ExpectNotValid( | 469 ExpectNotValid( |
| 448 TEST_SOURCE, | 470 TEST_SOURCE, |
| 449 scoped_ptr<Value>(Value::CreateDoubleValue(0.5)).get(), | 471 scoped_ptr<Value>(Value::CreateDoubleValue(0.5)).get(), |
| 450 schema.get(), NULL, "", | 472 schema.get(), NULL, "", |
| 451 JSONSchemaValidator::FormatErrorMessage( | 473 JSONSchemaValidator::FormatErrorMessage( |
| 452 JSONSchemaValidator::kNumberMinimum, "1")); | 474 JSONSchemaValidator::kNumberMinimum, "1")); |
| 453 ExpectNotValid( | 475 ExpectNotValid( |
| 454 TEST_SOURCE, | 476 TEST_SOURCE, |
| 455 scoped_ptr<Value>(Value::CreateDoubleValue(100.1)).get(), | 477 scoped_ptr<Value>(Value::CreateDoubleValue(100.1)).get(), |
| 456 schema.get(), NULL, "", | 478 schema.get(), NULL, "", |
| 457 JSONSchemaValidator::FormatErrorMessage( | 479 JSONSchemaValidator::FormatErrorMessage( |
| 458 JSONSchemaValidator::kNumberMaximum, "100")); | 480 JSONSchemaValidator::kNumberMaximum, "100")); |
| 459 } | 481 } |
| 460 | 482 |
| 461 void JSONSchemaValidatorTestBase::TestTypeClassifier() { | 483 void JSONSchemaValidatorTestBase::TestValueTypeClassifier() { |
| 462 EXPECT_EQ("boolean", JSONSchemaValidator::GetJSONSchemaType( | 484 EXPECT_EQ(std::string(schema::kBoolean), |
| 463 scoped_ptr<Value>(Value::CreateBooleanValue(true)).get())); | 485 JSONSchemaValidator::GetJSONSchemaType( |
| 464 EXPECT_EQ("boolean", JSONSchemaValidator::GetJSONSchemaType( | 486 scoped_ptr<Value>(Value::CreateBooleanValue(true)).get())); |
| 465 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get())); | 487 EXPECT_EQ(std::string(schema::kBoolean), |
| 488 JSONSchemaValidator::GetJSONSchemaType( |
| 489 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get())); |
| 466 | 490 |
| 467 // It doesn't matter whether the C++ type is 'integer' or 'real'. If the | 491 // It doesn't matter whether the C++ type is 'integer' or 'real'. If the |
| 468 // number is integral and within the representable range of integers in | 492 // number is integral and within the representable range of integers in |
| 469 // double, it's classified as 'integer'. | 493 // double, it's classified as 'integer'. |
| 470 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType( | 494 EXPECT_EQ(std::string(schema::kInteger), |
| 471 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get())); | 495 JSONSchemaValidator::GetJSONSchemaType( |
| 472 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType( | 496 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get())); |
| 473 scoped_ptr<Value>(Value::CreateIntegerValue(0)).get())); | 497 EXPECT_EQ(std::string(schema::kInteger), |
| 474 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType( | 498 JSONSchemaValidator::GetJSONSchemaType( |
| 475 scoped_ptr<Value>(Value::CreateDoubleValue(42)).get())); | 499 scoped_ptr<Value>(Value::CreateIntegerValue(0)).get())); |
| 476 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType( | 500 EXPECT_EQ(std::string(schema::kInteger), |
| 477 scoped_ptr<Value>( | 501 JSONSchemaValidator::GetJSONSchemaType( |
| 478 Value::CreateDoubleValue(pow(2.0, DBL_MANT_DIG))).get())); | 502 scoped_ptr<Value>(Value::CreateDoubleValue(42)).get())); |
| 479 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType( | 503 EXPECT_EQ(std::string(schema::kInteger), |
| 480 scoped_ptr<Value>( | 504 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<Value>( |
| 481 Value::CreateDoubleValue(pow(-2.0, DBL_MANT_DIG))).get())); | 505 Value::CreateDoubleValue(pow(2.0, DBL_MANT_DIG))).get())); |
| 506 EXPECT_EQ(std::string(schema::kInteger), |
| 507 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<Value>( |
| 508 Value::CreateDoubleValue(pow(-2.0, DBL_MANT_DIG))).get())); |
| 482 | 509 |
| 483 // "number" is only used for non-integral numbers, or numbers beyond what | 510 // "number" is only used for non-integral numbers, or numbers beyond what |
| 484 // double can accurately represent. | 511 // double can accurately represent. |
| 485 EXPECT_EQ("number", JSONSchemaValidator::GetJSONSchemaType( | 512 EXPECT_EQ(std::string(schema::kNumber), |
| 486 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get())); | 513 JSONSchemaValidator::GetJSONSchemaType( |
| 487 EXPECT_EQ("number", JSONSchemaValidator::GetJSONSchemaType( | 514 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get())); |
| 488 scoped_ptr<Value>(Value::CreateDoubleValue( | 515 EXPECT_EQ(std::string(schema::kNumber), |
| 489 pow(2.0, DBL_MANT_DIG) * 2)).get())); | 516 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<Value>( |
| 490 EXPECT_EQ("number", JSONSchemaValidator::GetJSONSchemaType( | 517 Value::CreateDoubleValue(pow(2.0, DBL_MANT_DIG) * 2)).get())); |
| 491 scoped_ptr<Value>(Value::CreateDoubleValue( | 518 EXPECT_EQ(std::string(schema::kNumber), |
| 492 pow(-2.0, DBL_MANT_DIG) * 2)).get())); | 519 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<Value>( |
| 520 Value::CreateDoubleValue(pow(-2.0, DBL_MANT_DIG) * 2)).get())); |
| 493 | 521 |
| 494 EXPECT_EQ("string", JSONSchemaValidator::GetJSONSchemaType( | 522 EXPECT_EQ(std::string(schema::kString), |
| 495 scoped_ptr<Value>(Value::CreateStringValue("foo")).get())); | 523 JSONSchemaValidator::GetJSONSchemaType( |
| 496 EXPECT_EQ("array", JSONSchemaValidator::GetJSONSchemaType( | 524 scoped_ptr<Value>(Value::CreateStringValue("foo")).get())); |
| 497 scoped_ptr<Value>(new ListValue()).get())); | 525 EXPECT_EQ(std::string(schema::kArray), |
| 498 EXPECT_EQ("object", JSONSchemaValidator::GetJSONSchemaType( | 526 JSONSchemaValidator::GetJSONSchemaType( |
| 499 scoped_ptr<Value>(new DictionaryValue()).get())); | 527 scoped_ptr<Value>(new ListValue()).get())); |
| 500 EXPECT_EQ("null", JSONSchemaValidator::GetJSONSchemaType( | 528 EXPECT_EQ(std::string(schema::kObject), |
| 501 scoped_ptr<Value>(Value::CreateNullValue()).get())); | 529 JSONSchemaValidator::GetJSONSchemaType( |
| 530 scoped_ptr<Value>(new DictionaryValue()).get())); |
| 531 EXPECT_EQ(std::string(schema::kNull), |
| 532 JSONSchemaValidator::GetJSONSchemaType( |
| 533 scoped_ptr<Value>(Value::CreateNullValue()).get())); |
| 534 } |
| 535 |
| 536 void JSONSchemaValidatorTestBase::TestSchemaTypeClassifier() { |
| 537 base::Value::Type value_type = base::Value::TYPE_NULL; |
| 538 EXPECT_TRUE(JSONSchemaValidator::GetValueType(schema::kArray, &value_type)); |
| 539 EXPECT_EQ(base::Value::TYPE_LIST, value_type); |
| 540 EXPECT_TRUE(JSONSchemaValidator::GetValueType(schema::kBoolean, &value_type)); |
| 541 EXPECT_EQ(base::Value::TYPE_BOOLEAN, value_type); |
| 542 EXPECT_TRUE(JSONSchemaValidator::GetValueType(schema::kInteger, &value_type)); |
| 543 EXPECT_EQ(base::Value::TYPE_INTEGER, value_type); |
| 544 EXPECT_TRUE(JSONSchemaValidator::GetValueType(schema::kNull, &value_type)); |
| 545 EXPECT_EQ(base::Value::TYPE_NULL, value_type); |
| 546 EXPECT_TRUE(JSONSchemaValidator::GetValueType(schema::kNumber, &value_type)); |
| 547 EXPECT_EQ(base::Value::TYPE_DOUBLE, value_type); |
| 548 EXPECT_TRUE(JSONSchemaValidator::GetValueType(schema::kObject, &value_type)); |
| 549 EXPECT_EQ(base::Value::TYPE_DICTIONARY, value_type); |
| 550 EXPECT_TRUE(JSONSchemaValidator::GetValueType(schema::kString, &value_type)); |
| 551 EXPECT_EQ(base::Value::TYPE_STRING, value_type); |
| 502 } | 552 } |
| 503 | 553 |
| 504 void JSONSchemaValidatorTestBase::TestTypes() { | 554 void JSONSchemaValidatorTestBase::TestTypes() { |
| 505 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); | 555 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); |
| 506 | 556 |
| 507 // valid | 557 // valid |
| 508 schema->SetString("type", "object"); | 558 schema->SetString(schema::kType, schema::kObject); |
| 509 ExpectValid(TEST_SOURCE, scoped_ptr<Value>(new DictionaryValue()).get(), | 559 ExpectValid(TEST_SOURCE, scoped_ptr<Value>(new DictionaryValue()).get(), |
| 510 schema.get(), NULL); | 560 schema.get(), NULL); |
| 511 | 561 |
| 512 schema->SetString("type", "array"); | 562 schema->SetString(schema::kType, schema::kArray); |
| 513 ExpectValid(TEST_SOURCE, scoped_ptr<Value>(new ListValue()).get(), | 563 ExpectValid(TEST_SOURCE, scoped_ptr<Value>(new ListValue()).get(), |
| 514 schema.get(), NULL); | 564 schema.get(), NULL); |
| 515 | 565 |
| 516 schema->SetString("type", "string"); | 566 schema->SetString(schema::kType, schema::kString); |
| 517 ExpectValid(TEST_SOURCE, | 567 ExpectValid(TEST_SOURCE, |
| 518 scoped_ptr<Value>(Value::CreateStringValue("foobar")).get(), | 568 scoped_ptr<Value>(Value::CreateStringValue("foobar")).get(), |
| 519 schema.get(), NULL); | 569 schema.get(), NULL); |
| 520 | 570 |
| 521 schema->SetString("type", "number"); | 571 schema->SetString(schema::kType, schema::kNumber); |
| 522 ExpectValid(TEST_SOURCE, | 572 ExpectValid(TEST_SOURCE, |
| 523 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(), | 573 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(), |
| 524 schema.get(), NULL); | 574 schema.get(), NULL); |
| 525 ExpectValid(TEST_SOURCE, | 575 ExpectValid(TEST_SOURCE, |
| 526 scoped_ptr<Value>(Value::CreateDoubleValue(42)).get(), | 576 scoped_ptr<Value>(Value::CreateDoubleValue(42)).get(), |
| 527 schema.get(), NULL); | 577 schema.get(), NULL); |
| 528 ExpectValid(TEST_SOURCE, | 578 ExpectValid(TEST_SOURCE, |
| 529 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), | 579 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), |
| 530 schema.get(), NULL); | 580 schema.get(), NULL); |
| 531 ExpectValid(TEST_SOURCE, | 581 ExpectValid(TEST_SOURCE, |
| 532 scoped_ptr<Value>(Value::CreateIntegerValue(0)).get(), | 582 scoped_ptr<Value>(Value::CreateIntegerValue(0)).get(), |
| 533 schema.get(), NULL); | 583 schema.get(), NULL); |
| 534 | 584 |
| 535 schema->SetString("type", "integer"); | 585 schema->SetString(schema::kType, schema::kInteger); |
| 536 ExpectValid(TEST_SOURCE, | 586 ExpectValid(TEST_SOURCE, |
| 537 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), | 587 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), |
| 538 schema.get(), NULL); | 588 schema.get(), NULL); |
| 539 ExpectValid(TEST_SOURCE, | 589 ExpectValid(TEST_SOURCE, |
| 540 scoped_ptr<Value>(Value::CreateDoubleValue(42)).get(), | 590 scoped_ptr<Value>(Value::CreateDoubleValue(42)).get(), |
| 541 schema.get(), NULL); | 591 schema.get(), NULL); |
| 542 ExpectValid(TEST_SOURCE, | 592 ExpectValid(TEST_SOURCE, |
| 543 scoped_ptr<Value>(Value::CreateIntegerValue(0)).get(), | 593 scoped_ptr<Value>(Value::CreateIntegerValue(0)).get(), |
| 544 schema.get(), NULL); | 594 schema.get(), NULL); |
| 545 ExpectValid(TEST_SOURCE, | 595 ExpectValid(TEST_SOURCE, |
| 546 scoped_ptr<Value>( | 596 scoped_ptr<Value>( |
| 547 Value::CreateDoubleValue(pow(2.0, DBL_MANT_DIG))).get(), | 597 Value::CreateDoubleValue(pow(2.0, DBL_MANT_DIG))).get(), |
| 548 schema.get(), NULL); | 598 schema.get(), NULL); |
| 549 ExpectValid(TEST_SOURCE, | 599 ExpectValid(TEST_SOURCE, |
| 550 scoped_ptr<Value>( | 600 scoped_ptr<Value>( |
| 551 Value::CreateDoubleValue(pow(-2.0, DBL_MANT_DIG))).get(), | 601 Value::CreateDoubleValue(pow(-2.0, DBL_MANT_DIG))).get(), |
| 552 schema.get(), NULL); | 602 schema.get(), NULL); |
| 553 | 603 |
| 554 schema->SetString("type", "boolean"); | 604 schema->SetString(schema::kType, schema::kBoolean); |
| 555 ExpectValid(TEST_SOURCE, | 605 ExpectValid(TEST_SOURCE, |
| 556 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get(), | 606 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get(), |
| 557 schema.get(), NULL); | 607 schema.get(), NULL); |
| 558 ExpectValid(TEST_SOURCE, | 608 ExpectValid(TEST_SOURCE, |
| 559 scoped_ptr<Value>(Value::CreateBooleanValue(true)).get(), | 609 scoped_ptr<Value>(Value::CreateBooleanValue(true)).get(), |
| 560 schema.get(), NULL); | 610 schema.get(), NULL); |
| 561 | 611 |
| 562 schema->SetString("type", "null"); | 612 schema->SetString(schema::kType, schema::kNull); |
| 563 ExpectValid(TEST_SOURCE, | 613 ExpectValid(TEST_SOURCE, |
| 564 scoped_ptr<Value>(Value::CreateNullValue()).get(), | 614 scoped_ptr<Value>(Value::CreateNullValue()).get(), |
| 565 schema.get(), NULL); | 615 schema.get(), NULL); |
| 566 | 616 |
| 567 // not valid | 617 // not valid |
| 568 schema->SetString("type", "object"); | 618 schema->SetString(schema::kType, schema::kObject); |
| 569 ExpectNotValid(TEST_SOURCE, scoped_ptr<Value>(new ListValue()).get(), | 619 ExpectNotValid(TEST_SOURCE, scoped_ptr<Value>(new ListValue()).get(), |
| 570 schema.get(), NULL, "", | 620 schema.get(), NULL, "", |
| 571 JSONSchemaValidator::FormatErrorMessage( | 621 JSONSchemaValidator::FormatErrorMessage( |
| 572 JSONSchemaValidator::kInvalidType, "object", "array")); | 622 JSONSchemaValidator::kInvalidType, |
| 623 schema::kObject, |
| 624 schema::kArray)); |
| 573 | 625 |
| 574 schema->SetString("type", "object"); | 626 schema->SetString(schema::kType, schema::kObject); |
| 575 ExpectNotValid(TEST_SOURCE, scoped_ptr<Value>(Value::CreateNullValue()).get(), | 627 ExpectNotValid(TEST_SOURCE, scoped_ptr<Value>(Value::CreateNullValue()).get(), |
| 576 schema.get(), NULL, "", | 628 schema.get(), NULL, "", |
| 577 JSONSchemaValidator::FormatErrorMessage( | 629 JSONSchemaValidator::FormatErrorMessage( |
| 578 JSONSchemaValidator::kInvalidType, "object", "null")); | 630 JSONSchemaValidator::kInvalidType, |
| 631 schema::kObject, |
| 632 schema::kNull)); |
| 579 | 633 |
| 580 schema->SetString("type", "array"); | 634 schema->SetString(schema::kType, schema::kArray); |
| 581 ExpectNotValid(TEST_SOURCE, | 635 ExpectNotValid(TEST_SOURCE, |
| 582 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), | 636 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), |
| 583 schema.get(), NULL, "", | 637 schema.get(), NULL, "", |
| 584 JSONSchemaValidator::FormatErrorMessage( | 638 JSONSchemaValidator::FormatErrorMessage( |
| 585 JSONSchemaValidator::kInvalidType, "array", "integer")); | 639 JSONSchemaValidator::kInvalidType, |
| 640 schema::kArray, |
| 641 schema::kInteger)); |
| 586 | 642 |
| 587 schema->SetString("type", "string"); | 643 schema->SetString(schema::kType, schema::kString); |
| 588 ExpectNotValid(TEST_SOURCE, | 644 ExpectNotValid(TEST_SOURCE, |
| 589 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), | 645 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), |
| 590 schema.get(), NULL, "", | 646 schema.get(), NULL, "", |
| 591 JSONSchemaValidator::FormatErrorMessage( | 647 JSONSchemaValidator::FormatErrorMessage( |
| 592 JSONSchemaValidator::kInvalidType, "string", "integer")); | 648 JSONSchemaValidator::kInvalidType, |
| 649 schema::kString, |
| 650 schema::kInteger)); |
| 593 | 651 |
| 594 schema->SetString("type", "number"); | 652 schema->SetString(schema::kType, schema::kNumber); |
| 595 ExpectNotValid(TEST_SOURCE, | 653 ExpectNotValid(TEST_SOURCE, |
| 596 scoped_ptr<Value>(Value::CreateStringValue("42")).get(), | 654 scoped_ptr<Value>(Value::CreateStringValue("42")).get(), |
| 597 schema.get(), NULL, "", | 655 schema.get(), NULL, "", |
| 598 JSONSchemaValidator::FormatErrorMessage( | 656 JSONSchemaValidator::FormatErrorMessage( |
| 599 JSONSchemaValidator::kInvalidType, "number", "string")); | 657 JSONSchemaValidator::kInvalidType, |
| 658 schema::kNumber, |
| 659 schema::kString)); |
| 600 | 660 |
| 601 schema->SetString("type", "integer"); | 661 schema->SetString(schema::kType, schema::kInteger); |
| 602 ExpectNotValid(TEST_SOURCE, | 662 ExpectNotValid(TEST_SOURCE, |
| 603 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(), | 663 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(), |
| 604 schema.get(), NULL, "", | 664 schema.get(), NULL, "", |
| 605 JSONSchemaValidator::FormatErrorMessage( | 665 JSONSchemaValidator::FormatErrorMessage( |
| 606 JSONSchemaValidator::kInvalidType, "integer", "number")); | 666 JSONSchemaValidator::kInvalidType, |
| 667 schema::kInteger, |
| 668 schema::kNumber)); |
| 607 | 669 |
| 608 schema->SetString("type", "integer"); | 670 schema->SetString(schema::kType, schema::kInteger); |
| 609 ExpectNotValid(TEST_SOURCE, | 671 ExpectNotValid(TEST_SOURCE, |
| 610 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(), | 672 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(), |
| 611 schema.get(), NULL, "", | 673 schema.get(), NULL, "", |
| 612 JSONSchemaValidator::FormatErrorMessage( | 674 JSONSchemaValidator::FormatErrorMessage( |
| 613 JSONSchemaValidator::kInvalidType, "integer", "number")); | 675 JSONSchemaValidator::kInvalidType, |
| 676 schema::kInteger, |
| 677 schema::kNumber)); |
| 614 | 678 |
| 615 schema->SetString("type", "boolean"); | 679 schema->SetString(schema::kType, schema::kBoolean); |
| 616 ExpectNotValid(TEST_SOURCE, | 680 ExpectNotValid(TEST_SOURCE, |
| 617 scoped_ptr<Value>(Value::CreateIntegerValue(1)).get(), | 681 scoped_ptr<Value>(Value::CreateIntegerValue(1)).get(), |
| 618 schema.get(), NULL, "", | 682 schema.get(), NULL, "", |
| 619 JSONSchemaValidator::FormatErrorMessage( | 683 JSONSchemaValidator::FormatErrorMessage( |
| 620 JSONSchemaValidator::kInvalidType, "boolean", "integer")); | 684 JSONSchemaValidator::kInvalidType, |
| 685 schema::kBoolean, |
| 686 schema::kInteger)); |
| 621 | 687 |
| 622 schema->SetString("type", "null"); | 688 schema->SetString(schema::kType, schema::kNull); |
| 623 ExpectNotValid(TEST_SOURCE, | 689 ExpectNotValid(TEST_SOURCE, |
| 624 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get(), | 690 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get(), |
| 625 schema.get(), NULL, "", | 691 schema.get(), NULL, "", |
| 626 JSONSchemaValidator::FormatErrorMessage( | 692 JSONSchemaValidator::FormatErrorMessage( |
| 627 JSONSchemaValidator::kInvalidType, "null", "boolean")); | 693 JSONSchemaValidator::kInvalidType, |
| 694 schema::kNull, |
| 695 schema::kBoolean)); |
| 628 } | 696 } |
| OLD | NEW |