| 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 "base/values.h" | 5 #include "base/values.h" |
| 6 #include "components/json_schema/json_schema_validator.h" | 6 #include "components/json_schema/json_schema_validator.h" |
| 7 #include "components/json_schema/json_schema_validator_unittest_base.h" | 7 #include "components/json_schema/json_schema_validator_unittest_base.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 class JSONSchemaValidatorCPPTest : public JSONSchemaValidatorTestBase { | 10 class JSONSchemaValidatorCPPTest : public JSONSchemaValidatorTestBase { |
| 11 public: | 11 public: |
| 12 JSONSchemaValidatorCPPTest() : JSONSchemaValidatorTestBase() {} | 12 JSONSchemaValidatorCPPTest() : JSONSchemaValidatorTestBase() {} |
| 13 | 13 |
| 14 protected: | 14 protected: |
| 15 virtual void ExpectValid(const std::string& test_source, | 15 virtual void ExpectValid(const std::string& test_source, |
| 16 base::Value* instance, | 16 base::Value* instance, |
| 17 base::DictionaryValue* schema, | 17 base::DictionaryValue* schema, |
| 18 base::ListValue* types) OVERRIDE { | 18 base::ListValue* types) override { |
| 19 JSONSchemaValidator validator(schema, types); | 19 JSONSchemaValidator validator(schema, types); |
| 20 if (validator.Validate(instance)) | 20 if (validator.Validate(instance)) |
| 21 return; | 21 return; |
| 22 | 22 |
| 23 for (size_t i = 0; i < validator.errors().size(); ++i) { | 23 for (size_t i = 0; i < validator.errors().size(); ++i) { |
| 24 ADD_FAILURE() << test_source << ": " | 24 ADD_FAILURE() << test_source << ": " |
| 25 << validator.errors()[i].path << ": " | 25 << validator.errors()[i].path << ": " |
| 26 << validator.errors()[i].message; | 26 << validator.errors()[i].message; |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 | 29 |
| 30 virtual void ExpectNotValid( | 30 virtual void ExpectNotValid( |
| 31 const std::string& test_source, | 31 const std::string& test_source, |
| 32 base::Value* instance, base::DictionaryValue* schema, | 32 base::Value* instance, base::DictionaryValue* schema, |
| 33 base::ListValue* types, | 33 base::ListValue* types, |
| 34 const std::string& expected_error_path, | 34 const std::string& expected_error_path, |
| 35 const std::string& expected_error_message) OVERRIDE { | 35 const std::string& expected_error_message) override { |
| 36 JSONSchemaValidator validator(schema, types); | 36 JSONSchemaValidator validator(schema, types); |
| 37 if (validator.Validate(instance)) { | 37 if (validator.Validate(instance)) { |
| 38 ADD_FAILURE() << test_source; | 38 ADD_FAILURE() << test_source; |
| 39 return; | 39 return; |
| 40 } | 40 } |
| 41 | 41 |
| 42 ASSERT_EQ(1u, validator.errors().size()) << test_source; | 42 ASSERT_EQ(1u, validator.errors().size()) << test_source; |
| 43 EXPECT_EQ(expected_error_path, validator.errors()[0].path) << test_source; | 43 EXPECT_EQ(expected_error_path, validator.errors()[0].path) << test_source; |
| 44 EXPECT_EQ(expected_error_message, validator.errors()[0].message) | 44 EXPECT_EQ(expected_error_message, validator.errors()[0].message) |
| 45 << test_source; | 45 << test_source; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 " \"unknown attribute\": \"that should just be ignored\"" | 148 " \"unknown attribute\": \"that should just be ignored\"" |
| 149 "}", | 149 "}", |
| 150 JSONSchemaValidator::OPTIONS_IGNORE_UNKNOWN_ATTRIBUTES, | 150 JSONSchemaValidator::OPTIONS_IGNORE_UNKNOWN_ATTRIBUTES, |
| 151 &error)) << error; | 151 &error)) << error; |
| 152 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( | 152 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
| 153 "{" | 153 "{" |
| 154 " \"type\": \"object\"," | 154 " \"type\": \"object\"," |
| 155 " \"unknown attribute\": \"that will cause a failure\"" | 155 " \"unknown attribute\": \"that will cause a failure\"" |
| 156 "}", 0, &error)) << error; | 156 "}", 0, &error)) << error; |
| 157 } | 157 } |
| OLD | NEW |