Add meta schema test (failing now)
This commit is contained in:
parent
979088de60
commit
e0a8a327ea
@ -837,7 +837,7 @@ TEST(SchemaValidator, AllOf_Nested) {
|
|||||||
INVALIDATE(s, "123", "", "allOf", "");
|
INVALIDATE(s, "123", "", "allOf", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* ReadFile(const char* filename, size_t& length) {
|
static char* ReadFile(const char* filename) {
|
||||||
const char *paths[] = {
|
const char *paths[] = {
|
||||||
"%s",
|
"%s",
|
||||||
"bin/%s",
|
"bin/%s",
|
||||||
@ -858,7 +858,7 @@ static char* ReadFile(const char* filename, size_t& length) {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fseek(fp, 0, SEEK_END);
|
fseek(fp, 0, SEEK_END);
|
||||||
length = (size_t)ftell(fp);
|
size_t length = (size_t)ftell(fp);
|
||||||
fseek(fp, 0, SEEK_SET);
|
fseek(fp, 0, SEEK_SET);
|
||||||
char* json = (char*)malloc(length + 1);
|
char* json = (char*)malloc(length + 1);
|
||||||
size_t readLength = fread(json, 1, length, fp);
|
size_t readLength = fread(json, 1, length, fp);
|
||||||
@ -867,6 +867,26 @@ static char* ReadFile(const char* filename, size_t& length) {
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(SchemaValidator, ValidateMetaSchema) {
|
||||||
|
char* json = ReadFile("draft-04/schema");
|
||||||
|
Document d;
|
||||||
|
d.Parse(json);
|
||||||
|
ASSERT_FALSE(d.HasParseError());
|
||||||
|
SchemaDocument sd(d);
|
||||||
|
SchemaValidator validator(sd);
|
||||||
|
if (!d.Accept(validator)) {
|
||||||
|
StringBuffer sb;
|
||||||
|
validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
|
||||||
|
printf("Invalid schema: %s\n", sb.GetString());
|
||||||
|
printf("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());
|
||||||
|
sb.Clear();
|
||||||
|
validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
|
||||||
|
printf("Invalid document: %s\n", sb.GetString());
|
||||||
|
//ADD_FAILURE();
|
||||||
|
}
|
||||||
|
free(json);
|
||||||
|
}
|
||||||
|
|
||||||
class RemoteSchemaDocumentProvider : public IRemoteSchemaDocumentProvider {
|
class RemoteSchemaDocumentProvider : public IRemoteSchemaDocumentProvider {
|
||||||
public:
|
public:
|
||||||
RemoteSchemaDocumentProvider() : documentAllocator_(), schemaAllocator_() {
|
RemoteSchemaDocumentProvider() : documentAllocator_(), schemaAllocator_() {
|
||||||
@ -880,8 +900,7 @@ public:
|
|||||||
for (size_t i = 0; i < kCount; i++) {
|
for (size_t i = 0; i < kCount; i++) {
|
||||||
sd_[i] = 0;
|
sd_[i] = 0;
|
||||||
|
|
||||||
size_t length;
|
char* json = ReadFile(filenames[i]);
|
||||||
char* json = ReadFile(filenames[i], length);
|
|
||||||
if (!json) {
|
if (!json) {
|
||||||
printf("json remote file %s not found", filenames[i]);
|
printf("json remote file %s not found", filenames[i]);
|
||||||
ADD_FAILURE();
|
ADD_FAILURE();
|
||||||
@ -972,8 +991,7 @@ TEST(SchemaValidator, TestSuite) {
|
|||||||
for (size_t i = 0; i < sizeof(filenames) / sizeof(filenames[0]); i++) {
|
for (size_t i = 0; i < sizeof(filenames) / sizeof(filenames[0]); i++) {
|
||||||
char filename[FILENAME_MAX];
|
char filename[FILENAME_MAX];
|
||||||
sprintf(filename, "jsonschema/tests/draft4/%s", filenames[i]);
|
sprintf(filename, "jsonschema/tests/draft4/%s", filenames[i]);
|
||||||
size_t length;
|
char* json = ReadFile(filename);
|
||||||
char* json = ReadFile(filename, length);
|
|
||||||
if (!json) {
|
if (!json) {
|
||||||
printf("json test suite file %s not found", filename);
|
printf("json test suite file %s not found", filename);
|
||||||
ADD_FAILURE();
|
ADD_FAILURE();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user