Skip to content

Commit 379b337

Browse files
committed
Add failing test for the case when a remote schema is violated (Tencent#1064)
1 parent 4c0f003 commit 379b337

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

test/unittest/schematest.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,20 @@ TEST(SchemaValidator, Hasher) {
124124

125125
#define INVALIDATE(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer) \
126126
{\
127-
SchemaValidator validator(schema);\
127+
INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, SchemaValidator, Pointer) \
128+
}
129+
130+
#define INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer,\
131+
SchemaValidatorType, PointerType) \
132+
{\
133+
SchemaValidatorType validator(schema);\
128134
Document d;\
129135
/*printf("\n%s\n", json);*/\
130136
d.Parse(json);\
131137
EXPECT_FALSE(d.HasParseError());\
132138
EXPECT_FALSE(d.Accept(validator));\
133139
EXPECT_FALSE(validator.IsValid());\
134-
if (validator.GetInvalidSchemaPointer() != Pointer(invalidSchemaPointer)) {\
140+
if (validator.GetInvalidSchemaPointer() != PointerType(invalidSchemaPointer)) {\
135141
StringBuffer sb;\
136142
validator.GetInvalidSchemaPointer().Stringify(sb);\
137143
printf("GetInvalidSchemaPointer() Expected: %s Actual: %s\n", invalidSchemaPointer, sb.GetString());\
@@ -142,7 +148,7 @@ TEST(SchemaValidator, Hasher) {
142148
printf("GetInvalidSchemaKeyword() Expected: %s Actual %s\n", invalidSchemaKeyword, validator.GetInvalidSchemaKeyword());\
143149
ADD_FAILURE();\
144150
}\
145-
if (validator.GetInvalidDocumentPointer() != Pointer(invalidDocumentPointer)) {\
151+
if (validator.GetInvalidDocumentPointer() != PointerType(invalidDocumentPointer)) {\
146152
StringBuffer sb;\
147153
validator.GetInvalidDocumentPointer().Stringify(sb);\
148154
printf("GetInvalidDocumentPointer() Expected: %s Actual: %s\n", invalidDocumentPointer, sb.GetString());\
@@ -1348,6 +1354,17 @@ TEST(SchemaValidator, Issue1017_allOfHandler) {
13481354
EXPECT_STREQ("{\"cyanArray2\":[],\"blackArray\":[]}", sb.GetString());
13491355
}
13501356

1357+
TEST(SchemaValidator, Ref_remote) {
1358+
typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
1359+
RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
1360+
Document sd;
1361+
sd.Parse("{\"$ref\": \"http://localhost:1234/subSchemas.json#/integer\"}");
1362+
SchemaDocumentType s(sd, &provider);
1363+
typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
1364+
typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
1365+
INVALIDATE_(s, "null", "/integer", "type", "", SchemaValidatorType, PointerType);
1366+
}
1367+
13511368
#ifdef __clang__
13521369
RAPIDJSON_DIAG_POP
13531370
#endif

0 commit comments

Comments
 (0)