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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 ExpectValid(TEST_SOURCE, | 145 ExpectValid(TEST_SOURCE, |
146 std::unique_ptr<base::Value>(new base::Value(42)).get(), | 146 std::unique_ptr<base::Value>(new base::Value(42)).get(), |
147 schema.get(), NULL); | 147 schema.get(), NULL); |
148 ExpectValid(TEST_SOURCE, | 148 ExpectValid(TEST_SOURCE, |
149 std::unique_ptr<base::Value>(new base::Value(false)).get(), | 149 std::unique_ptr<base::Value>(new base::Value(false)).get(), |
150 schema.get(), NULL); | 150 schema.get(), NULL); |
151 | 151 |
152 ExpectNotValid( | 152 ExpectNotValid( |
153 TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("42")).get(), | 153 TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("42")).get(), |
154 schema.get(), NULL, std::string(), JSONSchemaValidator::kInvalidEnum); | 154 schema.get(), NULL, std::string(), JSONSchemaValidator::kInvalidEnum); |
155 ExpectNotValid(TEST_SOURCE, base::Value::CreateNullValue().get(), | 155 ExpectNotValid(TEST_SOURCE, base::MakeUnique<base::Value>().get(), |
156 schema.get(), NULL, std::string(), | 156 schema.get(), NULL, std::string(), |
157 JSONSchemaValidator::kInvalidEnum); | 157 JSONSchemaValidator::kInvalidEnum); |
158 } | 158 } |
159 | 159 |
160 void JSONSchemaValidatorTestBase::TestChoices() { | 160 void JSONSchemaValidatorTestBase::TestChoices() { |
161 std::unique_ptr<base::DictionaryValue> schema( | 161 std::unique_ptr<base::DictionaryValue> schema( |
162 LoadDictionary("choices_schema.json")); | 162 LoadDictionary("choices_schema.json")); |
163 | 163 |
164 ExpectValid(TEST_SOURCE, base::Value::CreateNullValue().get(), schema.get(), | 164 ExpectValid(TEST_SOURCE, base::MakeUnique<base::Value>().get(), schema.get(), |
165 NULL); | 165 NULL); |
166 ExpectValid(TEST_SOURCE, | 166 ExpectValid(TEST_SOURCE, |
167 std::unique_ptr<base::Value>(new base::Value(42)).get(), | 167 std::unique_ptr<base::Value>(new base::Value(42)).get(), |
168 schema.get(), NULL); | 168 schema.get(), NULL); |
169 | 169 |
170 std::unique_ptr<base::DictionaryValue> instance(new base::DictionaryValue()); | 170 std::unique_ptr<base::DictionaryValue> instance(new base::DictionaryValue()); |
171 instance->SetString("foo", "bar"); | 171 instance->SetString("foo", "bar"); |
172 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 172 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
173 | 173 |
174 ExpectNotValid( | 174 ExpectNotValid( |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 279 |
280 base::DictionaryValue* properties = NULL; | 280 base::DictionaryValue* properties = NULL; |
281 base::DictionaryValue* bar_property = NULL; | 281 base::DictionaryValue* bar_property = NULL; |
282 ASSERT_TRUE(schema->GetDictionary(schema::kProperties, &properties)); | 282 ASSERT_TRUE(schema->GetDictionary(schema::kProperties, &properties)); |
283 ASSERT_TRUE(properties->GetDictionary("bar", &bar_property)); | 283 ASSERT_TRUE(properties->GetDictionary("bar", &bar_property)); |
284 | 284 |
285 bar_property->SetBoolean(schema::kOptional, true); | 285 bar_property->SetBoolean(schema::kOptional, true); |
286 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 286 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
287 instance->Remove("bar", NULL); | 287 instance->Remove("bar", NULL); |
288 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 288 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
289 instance->Set("bar", base::Value::CreateNullValue()); | 289 instance->Set("bar", base::MakeUnique<base::Value>()); |
290 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, | 290 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, |
291 "bar", JSONSchemaValidator::FormatErrorMessage( | 291 "bar", JSONSchemaValidator::FormatErrorMessage( |
292 JSONSchemaValidator::kInvalidType, | 292 JSONSchemaValidator::kInvalidType, |
293 schema::kInteger, | 293 schema::kInteger, |
294 schema::kNull)); | 294 schema::kNull)); |
295 instance->SetString("bar", "42"); | 295 instance->SetString("bar", "42"); |
296 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, | 296 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, |
297 "bar", JSONSchemaValidator::FormatErrorMessage( | 297 "bar", JSONSchemaValidator::FormatErrorMessage( |
298 JSONSchemaValidator::kInvalidType, | 298 JSONSchemaValidator::kInvalidType, |
299 schema::kInteger, | 299 schema::kInteger, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 426 |
427 base::ListValue* items_schema = NULL; | 427 base::ListValue* items_schema = NULL; |
428 base::DictionaryValue* item0_schema = NULL; | 428 base::DictionaryValue* item0_schema = NULL; |
429 ASSERT_TRUE(schema->GetList(schema::kItems, &items_schema)); | 429 ASSERT_TRUE(schema->GetList(schema::kItems, &items_schema)); |
430 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema)); | 430 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema)); |
431 item0_schema->SetBoolean(schema::kOptional, true); | 431 item0_schema->SetBoolean(schema::kOptional, true); |
432 instance->Remove(2, NULL); | 432 instance->Remove(2, NULL); |
433 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 433 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
434 // TODO(aa): I think this is inconsistent with the handling of NULL+optional | 434 // TODO(aa): I think this is inconsistent with the handling of NULL+optional |
435 // for objects. | 435 // for objects. |
436 instance->Set(0, base::Value::CreateNullValue()); | 436 instance->Set(0, base::MakeUnique<base::Value>()); |
437 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); | 437 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
438 instance->Set(0, new base::Value(42)); | 438 instance->Set(0, new base::Value(42)); |
439 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", | 439 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", |
440 JSONSchemaValidator::FormatErrorMessage( | 440 JSONSchemaValidator::FormatErrorMessage( |
441 JSONSchemaValidator::kInvalidType, | 441 JSONSchemaValidator::kInvalidType, |
442 schema::kString, | 442 schema::kString, |
443 schema::kInteger)); | 443 schema::kInteger)); |
444 } | 444 } |
445 | 445 |
446 void JSONSchemaValidatorTestBase::TestArrayNonTuple() { | 446 void JSONSchemaValidatorTestBase::TestArrayNonTuple() { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 std::unique_ptr<base::Value>(new base::Value("foo")).get())); | 597 std::unique_ptr<base::Value>(new base::Value("foo")).get())); |
598 EXPECT_EQ(std::string(schema::kArray), | 598 EXPECT_EQ(std::string(schema::kArray), |
599 JSONSchemaValidator::GetJSONSchemaType( | 599 JSONSchemaValidator::GetJSONSchemaType( |
600 std::unique_ptr<base::Value>(new base::ListValue()).get())); | 600 std::unique_ptr<base::Value>(new base::ListValue()).get())); |
601 EXPECT_EQ( | 601 EXPECT_EQ( |
602 std::string(schema::kObject), | 602 std::string(schema::kObject), |
603 JSONSchemaValidator::GetJSONSchemaType( | 603 JSONSchemaValidator::GetJSONSchemaType( |
604 std::unique_ptr<base::Value>(new base::DictionaryValue()).get())); | 604 std::unique_ptr<base::Value>(new base::DictionaryValue()).get())); |
605 EXPECT_EQ(std::string(schema::kNull), | 605 EXPECT_EQ(std::string(schema::kNull), |
606 JSONSchemaValidator::GetJSONSchemaType( | 606 JSONSchemaValidator::GetJSONSchemaType( |
607 base::Value::CreateNullValue().get())); | 607 base::MakeUnique<base::Value>().get())); |
608 } | 608 } |
609 | 609 |
610 void JSONSchemaValidatorTestBase::TestTypes() { | 610 void JSONSchemaValidatorTestBase::TestTypes() { |
611 std::unique_ptr<base::DictionaryValue> schema(new base::DictionaryValue()); | 611 std::unique_ptr<base::DictionaryValue> schema(new base::DictionaryValue()); |
612 | 612 |
613 // valid | 613 // valid |
614 schema->SetString(schema::kType, schema::kObject); | 614 schema->SetString(schema::kType, schema::kObject); |
615 ExpectValid(TEST_SOURCE, | 615 ExpectValid(TEST_SOURCE, |
616 std::unique_ptr<base::Value>(new base::DictionaryValue()).get(), | 616 std::unique_ptr<base::Value>(new base::DictionaryValue()).get(), |
617 schema.get(), NULL); | 617 schema.get(), NULL); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 | 663 |
664 schema->SetString(schema::kType, schema::kBoolean); | 664 schema->SetString(schema::kType, schema::kBoolean); |
665 ExpectValid(TEST_SOURCE, | 665 ExpectValid(TEST_SOURCE, |
666 std::unique_ptr<base::Value>(new base::Value(false)).get(), | 666 std::unique_ptr<base::Value>(new base::Value(false)).get(), |
667 schema.get(), NULL); | 667 schema.get(), NULL); |
668 ExpectValid(TEST_SOURCE, | 668 ExpectValid(TEST_SOURCE, |
669 std::unique_ptr<base::Value>(new base::Value(true)).get(), | 669 std::unique_ptr<base::Value>(new base::Value(true)).get(), |
670 schema.get(), NULL); | 670 schema.get(), NULL); |
671 | 671 |
672 schema->SetString(schema::kType, schema::kNull); | 672 schema->SetString(schema::kType, schema::kNull); |
673 ExpectValid(TEST_SOURCE, base::Value::CreateNullValue().get(), schema.get(), | 673 ExpectValid(TEST_SOURCE, base::MakeUnique<base::Value>().get(), schema.get(), |
674 NULL); | 674 NULL); |
675 | 675 |
676 // not valid | 676 // not valid |
677 schema->SetString(schema::kType, schema::kObject); | 677 schema->SetString(schema::kType, schema::kObject); |
678 ExpectNotValid( | 678 ExpectNotValid( |
679 TEST_SOURCE, std::unique_ptr<base::Value>(new base::ListValue()).get(), | 679 TEST_SOURCE, std::unique_ptr<base::Value>(new base::ListValue()).get(), |
680 schema.get(), NULL, std::string(), | 680 schema.get(), NULL, std::string(), |
681 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, | 681 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, |
682 schema::kObject, schema::kArray)); | 682 schema::kObject, schema::kArray)); |
683 | 683 |
684 schema->SetString(schema::kType, schema::kObject); | 684 schema->SetString(schema::kType, schema::kObject); |
685 ExpectNotValid( | 685 ExpectNotValid( |
686 TEST_SOURCE, base::Value::CreateNullValue().get(), schema.get(), NULL, | 686 TEST_SOURCE, base::MakeUnique<base::Value>().get(), schema.get(), NULL, |
687 std::string(), | 687 std::string(), |
688 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, | 688 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, |
689 schema::kObject, schema::kNull)); | 689 schema::kObject, schema::kNull)); |
690 | 690 |
691 schema->SetString(schema::kType, schema::kArray); | 691 schema->SetString(schema::kType, schema::kArray); |
692 ExpectNotValid( | 692 ExpectNotValid( |
693 TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(42)).get(), | 693 TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(42)).get(), |
694 schema.get(), NULL, std::string(), | 694 schema.get(), NULL, std::string(), |
695 JSONSchemaValidator::FormatErrorMessage( | 695 JSONSchemaValidator::FormatErrorMessage( |
696 JSONSchemaValidator::kInvalidType, schema::kArray, schema::kInteger)); | 696 JSONSchemaValidator::kInvalidType, schema::kArray, schema::kInteger)); |
(...skipping 27 matching lines...) Expand all Loading... |
724 JSONSchemaValidator::kInvalidType, schema::kBoolean, | 724 JSONSchemaValidator::kInvalidType, schema::kBoolean, |
725 schema::kInteger)); | 725 schema::kInteger)); |
726 | 726 |
727 schema->SetString(schema::kType, schema::kNull); | 727 schema->SetString(schema::kType, schema::kNull); |
728 ExpectNotValid( | 728 ExpectNotValid( |
729 TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(false)).get(), | 729 TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(false)).get(), |
730 schema.get(), NULL, std::string(), | 730 schema.get(), NULL, std::string(), |
731 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, | 731 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, |
732 schema::kNull, schema::kBoolean)); | 732 schema::kNull, schema::kBoolean)); |
733 } | 733 } |
OLD | NEW |