OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/common/json_schema/json_schema_validator.h" | 6 #include "chrome/common/json_schema/json_schema_validator.h" |
7 #include "chrome/common/json_schema/json_schema_validator_unittest_base.h" | 7 #include "chrome/common/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 { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 ASSERT_EQ(1u, validator.errors().size()) << test_source; | 43 ASSERT_EQ(1u, validator.errors().size()) << test_source; |
44 EXPECT_EQ(expected_error_path, validator.errors()[0].path) << test_source; | 44 EXPECT_EQ(expected_error_path, validator.errors()[0].path) << test_source; |
45 EXPECT_EQ(expected_error_message, validator.errors()[0].message) | 45 EXPECT_EQ(expected_error_message, validator.errors()[0].message) |
46 << test_source; | 46 << test_source; |
47 } | 47 } |
48 }; | 48 }; |
49 | 49 |
50 TEST_F(JSONSchemaValidatorCPPTest, Test) { | 50 TEST_F(JSONSchemaValidatorCPPTest, Test) { |
51 RunTests(); | 51 RunTests(); |
52 } | 52 } |
| 53 |
| 54 TEST(JSONSchemaValidator, IsValidSchema) { |
| 55 std::string error; |
| 56 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("", &error)); |
| 57 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("\0", &error)); |
| 58 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("string", &error)); |
| 59 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("\"string\"", &error)); |
| 60 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("[]", &error)); |
| 61 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("{}", &error)); |
| 62 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
| 63 "{ \"type\": 123 }", &error)); |
| 64 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
| 65 "{ \"type\": \"invalid\" }", &error)); |
| 66 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
| 67 "{" |
| 68 " \"type\": \"object\"," |
| 69 " \"properties\": []" // Invalid properties type. |
| 70 "}", &error)); |
| 71 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
| 72 "{" |
| 73 " \"type\": \"string\"," |
| 74 " \"maxLength\": -1" // Must be >= 0. |
| 75 "}", &error)); |
| 76 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
| 77 "{" |
| 78 " \"type\": \"string\"," |
| 79 " \"enum\": [ {} ]," // "enum" must contain simple values. |
| 80 "}", &error)); |
| 81 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
| 82 "{" |
| 83 " \"type\": \"array\"," |
| 84 " \"items\": [ 123 ]," // "items" must contain a schema or schemas. |
| 85 "}", &error)); |
| 86 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( |
| 87 "{ \"type\": \"object\" }", &error)) << error; |
| 88 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( |
| 89 "{ \"type\": [\"object\", \"array\"] }", &error)) << error; |
| 90 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( |
| 91 "{" |
| 92 " \"type\": [\"object\", \"array\"]," |
| 93 " \"properties\": {" |
| 94 " \"string-property\": {" |
| 95 " \"type\": \"string\"," |
| 96 " \"minLength\": 1," |
| 97 " \"maxLength\": 100," |
| 98 " \"title\": \"The String Policy\"," |
| 99 " \"description\": \"This policy controls the String widget.\"" |
| 100 " }," |
| 101 " \"integer-property\": {" |
| 102 " \"type\": \"number\"," |
| 103 " \"minimum\": 1000.0," |
| 104 " \"maximum\": 9999.0" |
| 105 " }," |
| 106 " \"enum-property\": {" |
| 107 " \"type\": \"integer\"," |
| 108 " \"enum\": [0, 1, 10, 100]" |
| 109 " }," |
| 110 " \"items-property\": {" |
| 111 " \"type\": \"array\"," |
| 112 " \"items\": {" |
| 113 " \"type\": \"string\"" |
| 114 " }" |
| 115 " }," |
| 116 " \"items-list-property\": {" |
| 117 " \"type\": \"array\"," |
| 118 " \"items\": [" |
| 119 " { \"type\": \"string\" }," |
| 120 " { \"type\": \"integer\" }" |
| 121 " ]" |
| 122 " }" |
| 123 " }," |
| 124 " \"additionalProperties\": {" |
| 125 " \"type\": \"any\"" |
| 126 " }" |
| 127 "}", &error)) << error; |
| 128 } |
OLD | NEW |