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; | |
not at google - send to devlin
2013/05/16 17:08:20
test a list of items?
Joao da Silva
2013/05/19 13:16:29
Done.
| |
90 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( | |
91 "{" | |
92 " \"type\": [\"object\", \"array\"]," | |
93 " \"properties\": {" | |
94 " \"string\": {" | |
95 " \"type\": \"string\"," | |
96 " \"minLength\": 1," | |
97 " \"maxLength\": 100" | |
98 " }," | |
99 " \"integer\": {" | |
100 " \"type\": \"number\"," | |
101 " \"minimum\": 1000.0," | |
102 " \"maximum\": 9999.0" | |
103 " }," | |
104 " \"enum\": {" | |
105 " \"type\": \"integer\"," | |
106 " \"enum\": [0, 1, 10, 100]" | |
107 " }" | |
108 " }," | |
109 " \"additionalProperties\": {" | |
110 " \"type\": \"any\"" | |
111 " }," | |
112 " \"items\": {" | |
113 " \"type\": \"string\"" | |
114 " }," | |
115 " \"unknown_key\": \"is ignored\"" | |
not at google - send to devlin
2013/05/16 17:08:20
hmm...
Joao da Silva
2013/05/19 13:16:29
Removed :-)
| |
116 "}", &error)) << error; | |
117 } | |
OLD | NEW |