Index: chrome/common/json_schema/json_schema_validator_unittest.cc |
diff --git a/chrome/common/json_schema/json_schema_validator_unittest.cc b/chrome/common/json_schema/json_schema_validator_unittest.cc |
index b2fdc542957a262dc5e150857510d4216334dfbd..7eda624672a078ac27b46723528165abffff02dc 100644 |
--- a/chrome/common/json_schema/json_schema_validator_unittest.cc |
+++ b/chrome/common/json_schema/json_schema_validator_unittest.cc |
@@ -50,3 +50,68 @@ class JSONSchemaValidatorCPPTest : public JSONSchemaValidatorTestBase { |
TEST_F(JSONSchemaValidatorCPPTest, Test) { |
RunTests(); |
} |
+ |
+TEST(JSONSchemaValidator, IsValidSchema) { |
+ std::string error; |
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("", &error)); |
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("\0", &error)); |
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("string", &error)); |
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("\"string\"", &error)); |
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("[]", &error)); |
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("{}", &error)); |
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
+ "{ \"type\": 123 }", &error)); |
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
+ "{ \"type\": \"invalid\" }", &error)); |
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
+ "{" |
+ " \"type\": \"object\"," |
+ " \"properties\": []" // Invalid properties type. |
+ "}", &error)); |
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
+ "{" |
+ " \"type\": \"string\"," |
+ " \"maxLength\": -1" // Must be >= 0. |
+ "}", &error)); |
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
+ "{" |
+ " \"type\": \"string\"," |
+ " \"enum\": [ {} ]," // "enum" must contain simple values. |
+ "}", &error)); |
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
+ "{" |
+ " \"type\": \"array\"," |
+ " \"items\": [ 123 ]," // "items" must contain a schema or schemas. |
+ "}", &error)); |
+ EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( |
+ "{ \"type\": \"object\" }", &error)) << error; |
+ EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( |
+ "{ \"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.
|
+ EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( |
+ "{" |
+ " \"type\": [\"object\", \"array\"]," |
+ " \"properties\": {" |
+ " \"string\": {" |
+ " \"type\": \"string\"," |
+ " \"minLength\": 1," |
+ " \"maxLength\": 100" |
+ " }," |
+ " \"integer\": {" |
+ " \"type\": \"number\"," |
+ " \"minimum\": 1000.0," |
+ " \"maximum\": 9999.0" |
+ " }," |
+ " \"enum\": {" |
+ " \"type\": \"integer\"," |
+ " \"enum\": [0, 1, 10, 100]" |
+ " }" |
+ " }," |
+ " \"additionalProperties\": {" |
+ " \"type\": \"any\"" |
+ " }," |
+ " \"items\": {" |
+ " \"type\": \"string\"" |
+ " }," |
+ " \"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 :-)
|
+ "}", &error)) << error; |
+} |