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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 JSONSchemaValidator::kStringPattern, "foo+")); | 137 JSONSchemaValidator::kStringPattern, "foo+")); |
138 } | 138 } |
139 | 139 |
140 void JSONSchemaValidatorTestBase::TestEnum() { | 140 void JSONSchemaValidatorTestBase::TestEnum() { |
141 std::unique_ptr<base::DictionaryValue> schema( | 141 std::unique_ptr<base::DictionaryValue> schema( |
142 LoadDictionary("enum_schema.json")); | 142 LoadDictionary("enum_schema.json")); |
143 | 143 |
144 ExpectValid(TEST_SOURCE, | 144 ExpectValid(TEST_SOURCE, |
145 std::unique_ptr<base::Value>(new base::StringValue("foo")).get(), | 145 std::unique_ptr<base::Value>(new base::StringValue("foo")).get(), |
146 schema.get(), NULL); | 146 schema.get(), NULL); |
147 ExpectValid( | 147 ExpectValid(TEST_SOURCE, |
148 TEST_SOURCE, | 148 std::unique_ptr<base::Value>(new base::Value(42)).get(), |
149 std::unique_ptr<base::Value>(new base::FundamentalValue(42)).get(), | 149 schema.get(), NULL); |
150 schema.get(), NULL); | 150 ExpectValid(TEST_SOURCE, |
151 ExpectValid( | 151 std::unique_ptr<base::Value>(new base::Value(false)).get(), |
152 TEST_SOURCE, | 152 schema.get(), NULL); |
153 std::unique_ptr<base::Value>(new base::FundamentalValue(false)).get(), | |
154 schema.get(), NULL); | |
155 | 153 |
156 ExpectNotValid( | 154 ExpectNotValid( |
157 TEST_SOURCE, | 155 TEST_SOURCE, |
158 std::unique_ptr<base::Value>(new base::StringValue("42")).get(), | 156 std::unique_ptr<base::Value>(new base::StringValue("42")).get(), |
159 schema.get(), NULL, std::string(), JSONSchemaValidator::kInvalidEnum); | 157 schema.get(), NULL, std::string(), JSONSchemaValidator::kInvalidEnum); |
160 ExpectNotValid(TEST_SOURCE, base::Value::CreateNullValue().get(), | 158 ExpectNotValid(TEST_SOURCE, base::Value::CreateNullValue().get(), |
161 schema.get(), NULL, std::string(), | 159 schema.get(), NULL, std::string(), |
162 JSONSchemaValidator::kInvalidEnum); | 160 JSONSchemaValidator::kInvalidEnum); |
163 } | 161 } |
164 | 162 |
165 void JSONSchemaValidatorTestBase::TestChoices() { | 163 void JSONSchemaValidatorTestBase::TestChoices() { |
166 std::unique_ptr<base::DictionaryValue> schema( | 164 std::unique_ptr<base::DictionaryValue> schema( |
167 LoadDictionary("choices_schema.json")); | 165 LoadDictionary("choices_schema.json")); |
168 | 166 |
169 ExpectValid(TEST_SOURCE, base::Value::CreateNullValue().get(), schema.get(), | 167 ExpectValid(TEST_SOURCE, base::Value::CreateNullValue().get(), schema.get(), |
170 NULL); | 168 NULL); |
171 ExpectValid( | 169 ExpectValid(TEST_SOURCE, |
172 TEST_SOURCE, | 170 std::unique_ptr<base::Value>(new base::Value(42)).get(), |
173 std::unique_ptr<base::Value>(new base::FundamentalValue(42)).get(), | 171 schema.get(), NULL); |
174 schema.get(), NULL); | |
175 | 172 |
176 std::unique_ptr<base::DictionaryValue> instance(new base::DictionaryValue()); | 173 std::unique_ptr<base::DictionaryValue> instance(new base::DictionaryValue()); |
177 instance->SetString("foo", "bar"); | 174 instance->SetString("foo", "bar"); |
178 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 175 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
179 | 176 |
180 ExpectNotValid( | 177 ExpectNotValid( |
181 TEST_SOURCE, | 178 TEST_SOURCE, |
182 std::unique_ptr<base::Value>(new base::StringValue("foo")).get(), | 179 std::unique_ptr<base::Value>(new base::StringValue("foo")).get(), |
183 schema.get(), NULL, std::string(), JSONSchemaValidator::kInvalidChoice); | 180 schema.get(), NULL, std::string(), JSONSchemaValidator::kInvalidChoice); |
184 ExpectNotValid( | 181 ExpectNotValid( |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 NULL, | 395 NULL, |
399 std::string(), | 396 std::string(), |
400 JSONSchemaValidator::FormatErrorMessage( | 397 JSONSchemaValidator::FormatErrorMessage( |
401 JSONSchemaValidator::kArrayMaxItems, "2")); | 398 JSONSchemaValidator::kArrayMaxItems, "2")); |
402 | 399 |
403 instance->Remove(1, NULL); | 400 instance->Remove(1, NULL); |
404 instance->Remove(1, NULL); | 401 instance->Remove(1, NULL); |
405 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", | 402 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", |
406 JSONSchemaValidator::kArrayItemRequired); | 403 JSONSchemaValidator::kArrayItemRequired); |
407 | 404 |
408 instance->Set(0, new base::FundamentalValue(42)); | 405 instance->Set(0, new base::Value(42)); |
409 instance->AppendInteger(42); | 406 instance->AppendInteger(42); |
410 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", | 407 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", |
411 JSONSchemaValidator::FormatErrorMessage( | 408 JSONSchemaValidator::FormatErrorMessage( |
412 JSONSchemaValidator::kInvalidType, | 409 JSONSchemaValidator::kInvalidType, |
413 schema::kString, | 410 schema::kString, |
414 schema::kInteger)); | 411 schema::kInteger)); |
415 | 412 |
416 base::DictionaryValue* additional_properties = new base::DictionaryValue(); | 413 base::DictionaryValue* additional_properties = new base::DictionaryValue(); |
417 additional_properties->SetString(schema::kType, schema::kAny); | 414 additional_properties->SetString(schema::kType, schema::kAny); |
418 schema->Set(schema::kAdditionalProperties, additional_properties); | 415 schema->Set(schema::kAdditionalProperties, additional_properties); |
419 instance->Set(0, new base::StringValue("42")); | 416 instance->Set(0, new base::StringValue("42")); |
420 instance->AppendString("anything"); | 417 instance->AppendString("anything"); |
421 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 418 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
422 instance->Set(2, new base::ListValue()); | 419 instance->Set(2, new base::ListValue()); |
423 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 420 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
424 | 421 |
425 additional_properties->SetString(schema::kType, schema::kBoolean); | 422 additional_properties->SetString(schema::kType, schema::kBoolean); |
426 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2", | 423 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2", |
427 JSONSchemaValidator::FormatErrorMessage( | 424 JSONSchemaValidator::FormatErrorMessage( |
428 JSONSchemaValidator::kInvalidType, | 425 JSONSchemaValidator::kInvalidType, |
429 schema::kBoolean, | 426 schema::kBoolean, |
430 schema::kArray)); | 427 schema::kArray)); |
431 instance->Set(2, new base::FundamentalValue(false)); | 428 instance->Set(2, new base::Value(false)); |
432 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 429 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
433 | 430 |
434 base::ListValue* items_schema = NULL; | 431 base::ListValue* items_schema = NULL; |
435 base::DictionaryValue* item0_schema = NULL; | 432 base::DictionaryValue* item0_schema = NULL; |
436 ASSERT_TRUE(schema->GetList(schema::kItems, &items_schema)); | 433 ASSERT_TRUE(schema->GetList(schema::kItems, &items_schema)); |
437 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema)); | 434 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema)); |
438 item0_schema->SetBoolean(schema::kOptional, true); | 435 item0_schema->SetBoolean(schema::kOptional, true); |
439 instance->Remove(2, NULL); | 436 instance->Remove(2, NULL); |
440 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 437 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
441 // TODO(aa): I think this is inconsistent with the handling of NULL+optional | 438 // TODO(aa): I think this is inconsistent with the handling of NULL+optional |
442 // for objects. | 439 // for objects. |
443 instance->Set(0, base::Value::CreateNullValue()); | 440 instance->Set(0, base::Value::CreateNullValue()); |
444 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 441 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
445 instance->Set(0, new base::FundamentalValue(42)); | 442 instance->Set(0, new base::Value(42)); |
446 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", | 443 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", |
447 JSONSchemaValidator::FormatErrorMessage( | 444 JSONSchemaValidator::FormatErrorMessage( |
448 JSONSchemaValidator::kInvalidType, | 445 JSONSchemaValidator::kInvalidType, |
449 schema::kString, | 446 schema::kString, |
450 schema::kInteger)); | 447 schema::kInteger)); |
451 } | 448 } |
452 | 449 |
453 void JSONSchemaValidatorTestBase::TestArrayNonTuple() { | 450 void JSONSchemaValidatorTestBase::TestArrayNonTuple() { |
454 std::unique_ptr<base::DictionaryValue> schema(new base::DictionaryValue()); | 451 std::unique_ptr<base::DictionaryValue> schema(new base::DictionaryValue()); |
455 schema->SetString(schema::kType, schema::kArray); | 452 schema->SetString(schema::kType, schema::kArray); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 } | 519 } |
523 | 520 |
524 void JSONSchemaValidatorTestBase::TestNumber() { | 521 void JSONSchemaValidatorTestBase::TestNumber() { |
525 std::unique_ptr<base::DictionaryValue> schema(new base::DictionaryValue()); | 522 std::unique_ptr<base::DictionaryValue> schema(new base::DictionaryValue()); |
526 schema->SetString(schema::kType, schema::kNumber); | 523 schema->SetString(schema::kType, schema::kNumber); |
527 schema->SetInteger(schema::kMinimum, 1); | 524 schema->SetInteger(schema::kMinimum, 1); |
528 schema->SetInteger(schema::kMaximum, 100); | 525 schema->SetInteger(schema::kMaximum, 100); |
529 schema->SetInteger("maxDecimal", 2); | 526 schema->SetInteger("maxDecimal", 2); |
530 | 527 |
531 ExpectValid(TEST_SOURCE, | 528 ExpectValid(TEST_SOURCE, |
532 std::unique_ptr<base::Value>(new base::FundamentalValue(1)).get(), | 529 std::unique_ptr<base::Value>(new base::Value(1)).get(), |
533 schema.get(), NULL); | 530 schema.get(), NULL); |
534 ExpectValid( | 531 ExpectValid(TEST_SOURCE, |
535 TEST_SOURCE, | 532 std::unique_ptr<base::Value>(new base::Value(50)).get(), |
536 std::unique_ptr<base::Value>(new base::FundamentalValue(50)).get(), | 533 schema.get(), NULL); |
537 schema.get(), NULL); | 534 ExpectValid(TEST_SOURCE, |
538 ExpectValid( | 535 std::unique_ptr<base::Value>(new base::Value(100)).get(), |
539 TEST_SOURCE, | 536 schema.get(), NULL); |
540 std::unique_ptr<base::Value>(new base::FundamentalValue(100)).get(), | 537 ExpectValid(TEST_SOURCE, |
541 schema.get(), NULL); | 538 std::unique_ptr<base::Value>(new base::Value(88.88)).get(), |
542 ExpectValid( | 539 schema.get(), NULL); |
543 TEST_SOURCE, | |
544 std::unique_ptr<base::Value>(new base::FundamentalValue(88.88)).get(), | |
545 schema.get(), NULL); | |
546 | 540 |
547 ExpectNotValid( | 541 ExpectNotValid(TEST_SOURCE, |
548 TEST_SOURCE, | 542 std::unique_ptr<base::Value>(new base::Value(0.5)).get(), |
549 std::unique_ptr<base::Value>(new base::FundamentalValue(0.5)).get(), | 543 schema.get(), NULL, std::string(), |
550 schema.get(), NULL, std::string(), | 544 JSONSchemaValidator::FormatErrorMessage( |
551 JSONSchemaValidator::FormatErrorMessage( | 545 JSONSchemaValidator::kNumberMinimum, "1")); |
552 JSONSchemaValidator::kNumberMinimum, "1")); | 546 ExpectNotValid(TEST_SOURCE, |
553 ExpectNotValid( | 547 std::unique_ptr<base::Value>(new base::Value(100.1)).get(), |
554 TEST_SOURCE, | 548 schema.get(), NULL, std::string(), |
555 std::unique_ptr<base::Value>(new base::FundamentalValue(100.1)).get(), | 549 JSONSchemaValidator::FormatErrorMessage( |
556 schema.get(), NULL, std::string(), | 550 JSONSchemaValidator::kNumberMaximum, "100")); |
557 JSONSchemaValidator::FormatErrorMessage( | |
558 JSONSchemaValidator::kNumberMaximum, "100")); | |
559 } | 551 } |
560 | 552 |
561 void JSONSchemaValidatorTestBase::TestTypeClassifier() { | 553 void JSONSchemaValidatorTestBase::TestTypeClassifier() { |
562 EXPECT_EQ(std::string(schema::kBoolean), | 554 EXPECT_EQ(std::string(schema::kBoolean), |
563 JSONSchemaValidator::GetJSONSchemaType( | 555 JSONSchemaValidator::GetJSONSchemaType( |
564 std::unique_ptr<base::Value>(new base::FundamentalValue(true)) | 556 std::unique_ptr<base::Value>(new base::Value(true)).get())); |
565 .get())); | |
566 EXPECT_EQ(std::string(schema::kBoolean), | 557 EXPECT_EQ(std::string(schema::kBoolean), |
567 JSONSchemaValidator::GetJSONSchemaType( | 558 JSONSchemaValidator::GetJSONSchemaType( |
568 std::unique_ptr<base::Value>(new base::FundamentalValue(false)) | 559 std::unique_ptr<base::Value>(new base::Value(false)).get())); |
569 .get())); | |
570 | 560 |
571 // It doesn't matter whether the C++ type is 'integer' or 'real'. If the | 561 // It doesn't matter whether the C++ type is 'integer' or 'real'. If the |
572 // number is integral and within the representable range of integers in | 562 // number is integral and within the representable range of integers in |
573 // double, it's classified as 'integer'. | 563 // double, it's classified as 'integer'. |
| 564 EXPECT_EQ(std::string(schema::kInteger), |
| 565 JSONSchemaValidator::GetJSONSchemaType( |
| 566 std::unique_ptr<base::Value>(new base::Value(42)).get())); |
| 567 EXPECT_EQ(std::string(schema::kInteger), |
| 568 JSONSchemaValidator::GetJSONSchemaType( |
| 569 std::unique_ptr<base::Value>(new base::Value(0)).get())); |
| 570 EXPECT_EQ(std::string(schema::kInteger), |
| 571 JSONSchemaValidator::GetJSONSchemaType( |
| 572 std::unique_ptr<base::Value>(new base::Value(42)).get())); |
574 EXPECT_EQ( | 573 EXPECT_EQ( |
575 std::string(schema::kInteger), | 574 std::string(schema::kInteger), |
576 JSONSchemaValidator::GetJSONSchemaType( | 575 JSONSchemaValidator::GetJSONSchemaType( |
577 std::unique_ptr<base::Value>(new base::FundamentalValue(42)).get())); | 576 std::unique_ptr<base::Value>(new base::Value(pow(2.0, DBL_MANT_DIG))) |
| 577 .get())); |
578 EXPECT_EQ( | 578 EXPECT_EQ( |
579 std::string(schema::kInteger), | 579 std::string(schema::kInteger), |
580 JSONSchemaValidator::GetJSONSchemaType( | 580 JSONSchemaValidator::GetJSONSchemaType( |
581 std::unique_ptr<base::Value>(new base::FundamentalValue(0)).get())); | 581 std::unique_ptr<base::Value>(new base::Value(pow(-2.0, DBL_MANT_DIG))) |
582 EXPECT_EQ( | 582 .get())); |
583 std::string(schema::kInteger), | |
584 JSONSchemaValidator::GetJSONSchemaType( | |
585 std::unique_ptr<base::Value>(new base::FundamentalValue(42)).get())); | |
586 EXPECT_EQ(std::string(schema::kInteger), | |
587 JSONSchemaValidator::GetJSONSchemaType( | |
588 std::unique_ptr<base::Value>( | |
589 new base::FundamentalValue(pow(2.0, DBL_MANT_DIG))) | |
590 .get())); | |
591 EXPECT_EQ(std::string(schema::kInteger), | |
592 JSONSchemaValidator::GetJSONSchemaType( | |
593 std::unique_ptr<base::Value>( | |
594 new base::FundamentalValue(pow(-2.0, DBL_MANT_DIG))) | |
595 .get())); | |
596 | 583 |
597 // "number" is only used for non-integral numbers, or numbers beyond what | 584 // "number" is only used for non-integral numbers, or numbers beyond what |
598 // double can accurately represent. | 585 // double can accurately represent. |
599 EXPECT_EQ(std::string(schema::kNumber), | 586 EXPECT_EQ(std::string(schema::kNumber), |
600 JSONSchemaValidator::GetJSONSchemaType( | 587 JSONSchemaValidator::GetJSONSchemaType( |
601 std::unique_ptr<base::Value>(new base::FundamentalValue(88.8)) | 588 std::unique_ptr<base::Value>(new base::Value(88.8)).get())); |
| 589 EXPECT_EQ(std::string(schema::kNumber), |
| 590 JSONSchemaValidator::GetJSONSchemaType( |
| 591 std::unique_ptr<base::Value>( |
| 592 new base::Value(pow(2.0, DBL_MANT_DIG) * 2)) |
602 .get())); | 593 .get())); |
603 EXPECT_EQ(std::string(schema::kNumber), | 594 EXPECT_EQ(std::string(schema::kNumber), |
604 JSONSchemaValidator::GetJSONSchemaType( | 595 JSONSchemaValidator::GetJSONSchemaType( |
605 std::unique_ptr<base::Value>( | 596 std::unique_ptr<base::Value>( |
606 new base::FundamentalValue(pow(2.0, DBL_MANT_DIG) * 2)) | 597 new base::Value(pow(-2.0, DBL_MANT_DIG) * 2)) |
607 .get())); | |
608 EXPECT_EQ(std::string(schema::kNumber), | |
609 JSONSchemaValidator::GetJSONSchemaType( | |
610 std::unique_ptr<base::Value>( | |
611 new base::FundamentalValue(pow(-2.0, DBL_MANT_DIG) * 2)) | |
612 .get())); | 598 .get())); |
613 | 599 |
614 EXPECT_EQ( | 600 EXPECT_EQ( |
615 std::string(schema::kString), | 601 std::string(schema::kString), |
616 JSONSchemaValidator::GetJSONSchemaType( | 602 JSONSchemaValidator::GetJSONSchemaType( |
617 std::unique_ptr<base::Value>(new base::StringValue("foo")).get())); | 603 std::unique_ptr<base::Value>(new base::StringValue("foo")).get())); |
618 EXPECT_EQ(std::string(schema::kArray), | 604 EXPECT_EQ(std::string(schema::kArray), |
619 JSONSchemaValidator::GetJSONSchemaType( | 605 JSONSchemaValidator::GetJSONSchemaType( |
620 std::unique_ptr<base::Value>(new base::ListValue()).get())); | 606 std::unique_ptr<base::Value>(new base::ListValue()).get())); |
621 EXPECT_EQ( | 607 EXPECT_EQ( |
(...skipping 19 matching lines...) Expand all Loading... |
641 std::unique_ptr<base::Value>(new base::ListValue()).get(), | 627 std::unique_ptr<base::Value>(new base::ListValue()).get(), |
642 schema.get(), NULL); | 628 schema.get(), NULL); |
643 | 629 |
644 schema->SetString(schema::kType, schema::kString); | 630 schema->SetString(schema::kType, schema::kString); |
645 ExpectValid( | 631 ExpectValid( |
646 TEST_SOURCE, | 632 TEST_SOURCE, |
647 std::unique_ptr<base::Value>(new base::StringValue("foobar")).get(), | 633 std::unique_ptr<base::Value>(new base::StringValue("foobar")).get(), |
648 schema.get(), NULL); | 634 schema.get(), NULL); |
649 | 635 |
650 schema->SetString(schema::kType, schema::kNumber); | 636 schema->SetString(schema::kType, schema::kNumber); |
| 637 ExpectValid(TEST_SOURCE, |
| 638 std::unique_ptr<base::Value>(new base::Value(88.8)).get(), |
| 639 schema.get(), NULL); |
| 640 ExpectValid(TEST_SOURCE, |
| 641 std::unique_ptr<base::Value>(new base::Value(42)).get(), |
| 642 schema.get(), NULL); |
| 643 ExpectValid(TEST_SOURCE, |
| 644 std::unique_ptr<base::Value>(new base::Value(42)).get(), |
| 645 schema.get(), NULL); |
| 646 ExpectValid(TEST_SOURCE, |
| 647 std::unique_ptr<base::Value>(new base::Value(0)).get(), |
| 648 schema.get(), NULL); |
| 649 |
| 650 schema->SetString(schema::kType, schema::kInteger); |
| 651 ExpectValid(TEST_SOURCE, |
| 652 std::unique_ptr<base::Value>(new base::Value(42)).get(), |
| 653 schema.get(), NULL); |
| 654 ExpectValid(TEST_SOURCE, |
| 655 std::unique_ptr<base::Value>(new base::Value(42)).get(), |
| 656 schema.get(), NULL); |
| 657 ExpectValid(TEST_SOURCE, |
| 658 std::unique_ptr<base::Value>(new base::Value(0)).get(), |
| 659 schema.get(), NULL); |
651 ExpectValid( | 660 ExpectValid( |
652 TEST_SOURCE, | 661 TEST_SOURCE, |
653 std::unique_ptr<base::Value>(new base::FundamentalValue(88.8)).get(), | 662 std::unique_ptr<base::Value>(new base::Value(pow(2.0, DBL_MANT_DIG))) |
| 663 .get(), |
654 schema.get(), NULL); | 664 schema.get(), NULL); |
655 ExpectValid( | 665 ExpectValid( |
656 TEST_SOURCE, | 666 TEST_SOURCE, |
657 std::unique_ptr<base::Value>(new base::FundamentalValue(42)).get(), | 667 std::unique_ptr<base::Value>(new base::Value(pow(-2.0, DBL_MANT_DIG))) |
| 668 .get(), |
658 schema.get(), NULL); | 669 schema.get(), NULL); |
659 ExpectValid( | 670 |
660 TEST_SOURCE, | 671 schema->SetString(schema::kType, schema::kBoolean); |
661 std::unique_ptr<base::Value>(new base::FundamentalValue(42)).get(), | |
662 schema.get(), NULL); | |
663 ExpectValid(TEST_SOURCE, | 672 ExpectValid(TEST_SOURCE, |
664 std::unique_ptr<base::Value>(new base::FundamentalValue(0)).get(), | 673 std::unique_ptr<base::Value>(new base::Value(false)).get(), |
665 schema.get(), NULL); | |
666 | |
667 schema->SetString(schema::kType, schema::kInteger); | |
668 ExpectValid( | |
669 TEST_SOURCE, | |
670 std::unique_ptr<base::Value>(new base::FundamentalValue(42)).get(), | |
671 schema.get(), NULL); | |
672 ExpectValid( | |
673 TEST_SOURCE, | |
674 std::unique_ptr<base::Value>(new base::FundamentalValue(42)).get(), | |
675 schema.get(), NULL); | |
676 ExpectValid(TEST_SOURCE, | |
677 std::unique_ptr<base::Value>(new base::FundamentalValue(0)).get(), | |
678 schema.get(), NULL); | 674 schema.get(), NULL); |
679 ExpectValid(TEST_SOURCE, | 675 ExpectValid(TEST_SOURCE, |
680 std::unique_ptr<base::Value>( | 676 std::unique_ptr<base::Value>(new base::Value(true)).get(), |
681 new base::FundamentalValue(pow(2.0, DBL_MANT_DIG))) | |
682 .get(), | |
683 schema.get(), NULL); | 677 schema.get(), NULL); |
684 ExpectValid(TEST_SOURCE, | |
685 std::unique_ptr<base::Value>( | |
686 new base::FundamentalValue(pow(-2.0, DBL_MANT_DIG))) | |
687 .get(), | |
688 schema.get(), NULL); | |
689 | |
690 schema->SetString(schema::kType, schema::kBoolean); | |
691 ExpectValid( | |
692 TEST_SOURCE, | |
693 std::unique_ptr<base::Value>(new base::FundamentalValue(false)).get(), | |
694 schema.get(), NULL); | |
695 ExpectValid( | |
696 TEST_SOURCE, | |
697 std::unique_ptr<base::Value>(new base::FundamentalValue(true)).get(), | |
698 schema.get(), NULL); | |
699 | 678 |
700 schema->SetString(schema::kType, schema::kNull); | 679 schema->SetString(schema::kType, schema::kNull); |
701 ExpectValid(TEST_SOURCE, base::Value::CreateNullValue().get(), schema.get(), | 680 ExpectValid(TEST_SOURCE, base::Value::CreateNullValue().get(), schema.get(), |
702 NULL); | 681 NULL); |
703 | 682 |
704 // not valid | 683 // not valid |
705 schema->SetString(schema::kType, schema::kObject); | 684 schema->SetString(schema::kType, schema::kObject); |
706 ExpectNotValid( | 685 ExpectNotValid( |
707 TEST_SOURCE, std::unique_ptr<base::Value>(new base::ListValue()).get(), | 686 TEST_SOURCE, std::unique_ptr<base::Value>(new base::ListValue()).get(), |
708 schema.get(), NULL, std::string(), | 687 schema.get(), NULL, std::string(), |
709 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, | 688 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, |
710 schema::kObject, schema::kArray)); | 689 schema::kObject, schema::kArray)); |
711 | 690 |
712 schema->SetString(schema::kType, schema::kObject); | 691 schema->SetString(schema::kType, schema::kObject); |
713 ExpectNotValid( | 692 ExpectNotValid( |
714 TEST_SOURCE, base::Value::CreateNullValue().get(), schema.get(), NULL, | 693 TEST_SOURCE, base::Value::CreateNullValue().get(), schema.get(), NULL, |
715 std::string(), | 694 std::string(), |
716 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, | 695 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, |
717 schema::kObject, schema::kNull)); | 696 schema::kObject, schema::kNull)); |
718 | 697 |
719 schema->SetString(schema::kType, schema::kArray); | 698 schema->SetString(schema::kType, schema::kArray); |
720 ExpectNotValid( | 699 ExpectNotValid( |
721 TEST_SOURCE, | 700 TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(42)).get(), |
722 std::unique_ptr<base::Value>(new base::FundamentalValue(42)).get(), | |
723 schema.get(), NULL, std::string(), | 701 schema.get(), NULL, std::string(), |
724 JSONSchemaValidator::FormatErrorMessage( | 702 JSONSchemaValidator::FormatErrorMessage( |
725 JSONSchemaValidator::kInvalidType, schema::kArray, schema::kInteger)); | 703 JSONSchemaValidator::kInvalidType, schema::kArray, schema::kInteger)); |
726 | 704 |
727 schema->SetString(schema::kType, schema::kString); | 705 schema->SetString(schema::kType, schema::kString); |
728 ExpectNotValid( | 706 ExpectNotValid(TEST_SOURCE, |
729 TEST_SOURCE, | 707 std::unique_ptr<base::Value>(new base::Value(42)).get(), |
730 std::unique_ptr<base::Value>(new base::FundamentalValue(42)).get(), | 708 schema.get(), NULL, std::string(), |
731 schema.get(), NULL, std::string(), | 709 JSONSchemaValidator::FormatErrorMessage( |
732 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, | 710 JSONSchemaValidator::kInvalidType, schema::kString, |
733 schema::kString, | 711 schema::kInteger)); |
734 schema::kInteger)); | |
735 | 712 |
736 schema->SetString(schema::kType, schema::kNumber); | 713 schema->SetString(schema::kType, schema::kNumber); |
737 ExpectNotValid( | 714 ExpectNotValid( |
738 TEST_SOURCE, | 715 TEST_SOURCE, |
739 std::unique_ptr<base::Value>(new base::StringValue("42")).get(), | 716 std::unique_ptr<base::Value>(new base::StringValue("42")).get(), |
740 schema.get(), NULL, std::string(), | 717 schema.get(), NULL, std::string(), |
741 JSONSchemaValidator::FormatErrorMessage( | 718 JSONSchemaValidator::FormatErrorMessage( |
742 JSONSchemaValidator::kInvalidType, schema::kNumber, schema::kString)); | 719 JSONSchemaValidator::kInvalidType, schema::kNumber, schema::kString)); |
743 | 720 |
744 schema->SetString(schema::kType, schema::kInteger); | 721 schema->SetString(schema::kType, schema::kInteger); |
745 ExpectNotValid( | 722 ExpectNotValid(TEST_SOURCE, |
746 TEST_SOURCE, | 723 std::unique_ptr<base::Value>(new base::Value(88.8)).get(), |
747 std::unique_ptr<base::Value>(new base::FundamentalValue(88.8)).get(), | 724 schema.get(), NULL, std::string(), |
748 schema.get(), NULL, std::string(), | 725 JSONSchemaValidator::kInvalidTypeIntegerNumber); |
749 JSONSchemaValidator::kInvalidTypeIntegerNumber); | |
750 | 726 |
751 schema->SetString(schema::kType, schema::kBoolean); | 727 schema->SetString(schema::kType, schema::kBoolean); |
752 ExpectNotValid( | 728 ExpectNotValid(TEST_SOURCE, |
753 TEST_SOURCE, | 729 std::unique_ptr<base::Value>(new base::Value(1)).get(), |
754 std::unique_ptr<base::Value>(new base::FundamentalValue(1)).get(), | 730 schema.get(), NULL, std::string(), |
755 schema.get(), NULL, std::string(), | 731 JSONSchemaValidator::FormatErrorMessage( |
756 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, | 732 JSONSchemaValidator::kInvalidType, schema::kBoolean, |
757 schema::kBoolean, | 733 schema::kInteger)); |
758 schema::kInteger)); | |
759 | 734 |
760 schema->SetString(schema::kType, schema::kNull); | 735 schema->SetString(schema::kType, schema::kNull); |
761 ExpectNotValid( | 736 ExpectNotValid( |
762 TEST_SOURCE, | 737 TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(false)).get(), |
763 std::unique_ptr<base::Value>(new base::FundamentalValue(false)).get(), | |
764 schema.get(), NULL, std::string(), | 738 schema.get(), NULL, std::string(), |
765 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, | 739 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, |
766 schema::kNull, schema::kBoolean)); | 740 schema::kNull, schema::kBoolean)); |
767 } | 741 } |
OLD | NEW |