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 "components/json_schema/json_schema_validator_unittest_base.h" | 5 #include "components/json_schema/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 #include <memory> | 10 #include <memory> |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 JSONSchemaValidator::kUnknownTypeReference, | 378 JSONSchemaValidator::kUnknownTypeReference, |
379 "NegativeInt")); | 379 "NegativeInt")); |
380 } | 380 } |
381 | 381 |
382 void JSONSchemaValidatorTestBase::TestArrayTuple() { | 382 void JSONSchemaValidatorTestBase::TestArrayTuple() { |
383 std::unique_ptr<base::DictionaryValue> schema( | 383 std::unique_ptr<base::DictionaryValue> schema( |
384 LoadDictionary("array_tuple_schema.json")); | 384 LoadDictionary("array_tuple_schema.json")); |
385 ASSERT_TRUE(schema.get()); | 385 ASSERT_TRUE(schema.get()); |
386 | 386 |
387 std::unique_ptr<base::ListValue> instance(new base::ListValue()); | 387 std::unique_ptr<base::ListValue> instance(new base::ListValue()); |
388 instance->Append(new base::StringValue("42")); | 388 instance->AppendString("42"); |
389 instance->Append(new base::FundamentalValue(42)); | 389 instance->AppendInteger(42); |
390 | 390 |
391 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 391 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
392 | 392 |
393 instance->Append(new base::StringValue("anything")); | 393 instance->AppendString("anything"); |
394 ExpectNotValid(TEST_SOURCE, | 394 ExpectNotValid(TEST_SOURCE, |
395 instance.get(), | 395 instance.get(), |
396 schema.get(), | 396 schema.get(), |
397 NULL, | 397 NULL, |
398 std::string(), | 398 std::string(), |
399 JSONSchemaValidator::FormatErrorMessage( | 399 JSONSchemaValidator::FormatErrorMessage( |
400 JSONSchemaValidator::kArrayMaxItems, "2")); | 400 JSONSchemaValidator::kArrayMaxItems, "2")); |
401 | 401 |
402 instance->Remove(1, NULL); | 402 instance->Remove(1, NULL); |
403 instance->Remove(1, NULL); | 403 instance->Remove(1, NULL); |
404 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", | 404 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", |
405 JSONSchemaValidator::kArrayItemRequired); | 405 JSONSchemaValidator::kArrayItemRequired); |
406 | 406 |
407 instance->Set(0, new base::FundamentalValue(42)); | 407 instance->Set(0, new base::FundamentalValue(42)); |
408 instance->Append(new base::FundamentalValue(42)); | 408 instance->AppendInteger(42); |
409 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", | 409 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", |
410 JSONSchemaValidator::FormatErrorMessage( | 410 JSONSchemaValidator::FormatErrorMessage( |
411 JSONSchemaValidator::kInvalidType, | 411 JSONSchemaValidator::kInvalidType, |
412 schema::kString, | 412 schema::kString, |
413 schema::kInteger)); | 413 schema::kInteger)); |
414 | 414 |
415 base::DictionaryValue* additional_properties = new base::DictionaryValue(); | 415 base::DictionaryValue* additional_properties = new base::DictionaryValue(); |
416 additional_properties->SetString(schema::kType, schema::kAny); | 416 additional_properties->SetString(schema::kType, schema::kAny); |
417 schema->Set(schema::kAdditionalProperties, additional_properties); | 417 schema->Set(schema::kAdditionalProperties, additional_properties); |
418 instance->Set(0, new base::StringValue("42")); | 418 instance->Set(0, new base::StringValue("42")); |
419 instance->Append(new base::StringValue("anything")); | 419 instance->AppendString("anything"); |
420 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 420 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
421 instance->Set(2, new base::ListValue()); | 421 instance->Set(2, new base::ListValue()); |
422 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 422 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
423 | 423 |
424 additional_properties->SetString(schema::kType, schema::kBoolean); | 424 additional_properties->SetString(schema::kType, schema::kBoolean); |
425 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2", | 425 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2", |
426 JSONSchemaValidator::FormatErrorMessage( | 426 JSONSchemaValidator::FormatErrorMessage( |
427 JSONSchemaValidator::kInvalidType, | 427 JSONSchemaValidator::kInvalidType, |
428 schema::kBoolean, | 428 schema::kBoolean, |
429 schema::kArray)); | 429 schema::kArray)); |
(...skipping 20 matching lines...) Expand all Loading... |
450 } | 450 } |
451 | 451 |
452 void JSONSchemaValidatorTestBase::TestArrayNonTuple() { | 452 void JSONSchemaValidatorTestBase::TestArrayNonTuple() { |
453 std::unique_ptr<base::DictionaryValue> schema(new base::DictionaryValue()); | 453 std::unique_ptr<base::DictionaryValue> schema(new base::DictionaryValue()); |
454 schema->SetString(schema::kType, schema::kArray); | 454 schema->SetString(schema::kType, schema::kArray); |
455 schema->SetString("items.type", schema::kString); | 455 schema->SetString("items.type", schema::kString); |
456 schema->SetInteger(schema::kMinItems, 2); | 456 schema->SetInteger(schema::kMinItems, 2); |
457 schema->SetInteger(schema::kMaxItems, 3); | 457 schema->SetInteger(schema::kMaxItems, 3); |
458 | 458 |
459 std::unique_ptr<base::ListValue> instance(new base::ListValue()); | 459 std::unique_ptr<base::ListValue> instance(new base::ListValue()); |
460 instance->Append(new base::StringValue("x")); | 460 instance->AppendString("x"); |
461 instance->Append(new base::StringValue("x")); | 461 instance->AppendString("x"); |
462 | 462 |
463 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 463 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
464 instance->Append(new base::StringValue("x")); | 464 instance->AppendString("x"); |
465 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 465 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
466 | 466 |
467 instance->Append(new base::StringValue("x")); | 467 instance->AppendString("x"); |
468 ExpectNotValid(TEST_SOURCE, | 468 ExpectNotValid(TEST_SOURCE, |
469 instance.get(), | 469 instance.get(), |
470 schema.get(), | 470 schema.get(), |
471 NULL, | 471 NULL, |
472 std::string(), | 472 std::string(), |
473 JSONSchemaValidator::FormatErrorMessage( | 473 JSONSchemaValidator::FormatErrorMessage( |
474 JSONSchemaValidator::kArrayMaxItems, "3")); | 474 JSONSchemaValidator::kArrayMaxItems, "3")); |
475 instance->Remove(1, NULL); | 475 instance->Remove(1, NULL); |
476 instance->Remove(1, NULL); | 476 instance->Remove(1, NULL); |
477 instance->Remove(1, NULL); | 477 instance->Remove(1, NULL); |
478 ExpectNotValid(TEST_SOURCE, | 478 ExpectNotValid(TEST_SOURCE, |
479 instance.get(), | 479 instance.get(), |
480 schema.get(), | 480 schema.get(), |
481 NULL, | 481 NULL, |
482 std::string(), | 482 std::string(), |
483 JSONSchemaValidator::FormatErrorMessage( | 483 JSONSchemaValidator::FormatErrorMessage( |
484 JSONSchemaValidator::kArrayMinItems, "2")); | 484 JSONSchemaValidator::kArrayMinItems, "2")); |
485 | 485 |
486 instance->Remove(1, NULL); | 486 instance->Remove(1, NULL); |
487 instance->Append(new base::FundamentalValue(42)); | 487 instance->AppendInteger(42); |
488 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", | 488 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", |
489 JSONSchemaValidator::FormatErrorMessage( | 489 JSONSchemaValidator::FormatErrorMessage( |
490 JSONSchemaValidator::kInvalidType, | 490 JSONSchemaValidator::kInvalidType, |
491 schema::kString, | 491 schema::kString, |
492 schema::kInteger)); | 492 schema::kInteger)); |
493 } | 493 } |
494 | 494 |
495 void JSONSchemaValidatorTestBase::TestString() { | 495 void JSONSchemaValidatorTestBase::TestString() { |
496 std::unique_ptr<base::DictionaryValue> schema(new base::DictionaryValue()); | 496 std::unique_ptr<base::DictionaryValue> schema(new base::DictionaryValue()); |
497 schema->SetString(schema::kType, schema::kString); | 497 schema->SetString(schema::kType, schema::kString); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 schema::kInteger)); | 757 schema::kInteger)); |
758 | 758 |
759 schema->SetString(schema::kType, schema::kNull); | 759 schema->SetString(schema::kType, schema::kNull); |
760 ExpectNotValid( | 760 ExpectNotValid( |
761 TEST_SOURCE, | 761 TEST_SOURCE, |
762 std::unique_ptr<base::Value>(new base::FundamentalValue(false)).get(), | 762 std::unique_ptr<base::Value>(new base::FundamentalValue(false)).get(), |
763 schema.get(), NULL, std::string(), | 763 schema.get(), NULL, std::string(), |
764 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, | 764 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, |
765 schema::kNull, schema::kBoolean)); | 765 schema::kNull, schema::kBoolean)); |
766 } | 766 } |
OLD | NEW |