Skip to content

Commit c8530d0

Browse files
committed
add test case for remote ref issue
1 parent 8a6c345 commit c8530d0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/unittest/schematest.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,35 @@ TEST(SchemaValidator, Ref_remote) {
20042004
SchemaValidatorType, PointerType);
20052005
}
20062006

2007+
TEST(SchemaValidator, Ref_remote_issue1210) {
2008+
class SchemaDocumentProvider : public IRemoteSchemaDocumentProvider {
2009+
SchemaDocument** collection;
2010+
public:
2011+
SchemaDocumentProvider(SchemaDocument** collection) : collection(collection) { }
2012+
virtual const SchemaDocument* GetRemoteDocument(const char* uri, SizeType length) {
2013+
int i = 0;
2014+
while (collection[i] && typename SchemaDocument::URIType(uri, length) != collection[i]->GetURI()) ++i;
2015+
return collection[i];
2016+
}
2017+
};
2018+
SchemaDocument* collection[] { 0, 0, 0 };
2019+
SchemaDocumentProvider provider(collection);
2020+
2021+
Document x, y, z;
2022+
x.Parse("{\"properties\":{\"country\":{\"$ref\":\"y.json#/definitions/country_remote\"}},\"type\":\"object\"}");
2023+
y.Parse("{\"definitions\":{\"country_remote\":{\"$ref\":\"z.json#/definitions/country_list\"}}}");
2024+
z.Parse("{\"definitions\":{\"country_list\":{\"enum\":[\"US\"]}}}");
2025+
2026+
SchemaDocument sz(z, "z.json", 6, &provider);
2027+
collection[0] = &sz;
2028+
SchemaDocument sy(y, "y.json", 6, &provider);
2029+
collection[1] = &sy;
2030+
SchemaDocument sx(x, "x.json", 6, &provider);
2031+
2032+
VALIDATE(sx, "{\"country\":\"UK\"}", false);
2033+
VALIDATE(sx, "{\"country\":\"US\"}", true);
2034+
}
2035+
20072036
#ifdef __clang__
20082037
RAPIDJSON_DIAG_POP
20092038
#endif

0 commit comments

Comments
 (0)