Search more paths for different build situations
This commit is contained in:
parent
3f7a3bcc04
commit
3675b33a2a
@ -101,14 +101,21 @@ TEST(Document, Parse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static FILE* OpenEncodedFile(const char* filename) {
|
static FILE* OpenEncodedFile(const char* filename) {
|
||||||
|
const char *paths[] = {
|
||||||
|
"encodings/%s",
|
||||||
|
"bin/encodings/%s",
|
||||||
|
"../bin/encodings/%s",
|
||||||
|
"../../bin/encodings/%s",
|
||||||
|
"../../../bin/encodings/%s"
|
||||||
|
};
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
sprintf(buffer, "encodings/%s", filename);
|
for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) {
|
||||||
FILE *fp = fopen(buffer, "rb");
|
sprintf(buffer, paths[i], filename);
|
||||||
if (!fp) {
|
FILE *fp = fopen(buffer, "rb");
|
||||||
sprintf(buffer, "../../bin/encodings/%s", filename);
|
if (fp)
|
||||||
fp = fopen(buffer, "rb");
|
return fp;
|
||||||
}
|
}
|
||||||
return fp;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Document, ParseStream_EncodedInputStream) {
|
TEST(Document, ParseStream_EncodedInputStream) {
|
||||||
|
@ -47,14 +47,21 @@ private:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static FILE* Open(const char* filename) {
|
static FILE* Open(const char* filename) {
|
||||||
|
const char *paths[] = {
|
||||||
|
"encodings/%s",
|
||||||
|
"bin/encodings/%s",
|
||||||
|
"../bin/encodings/%s",
|
||||||
|
"../../bin/encodings/%s",
|
||||||
|
"../../../bin/encodings/%s"
|
||||||
|
};
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
sprintf(buffer, "encodings/%s", filename);
|
for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) {
|
||||||
FILE *fp = fopen(buffer, "rb");
|
sprintf(buffer, paths[i], filename);
|
||||||
if (!fp) {
|
FILE *fp = fopen(buffer, "rb");
|
||||||
sprintf(buffer, "../../bin/encodings/%s", filename);
|
if (fp)
|
||||||
fp = fopen(buffer, "rb");
|
return fp;
|
||||||
}
|
}
|
||||||
return fp;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *ReadFile(const char* filename, bool appendPath, size_t* outLength) {
|
static char *ReadFile(const char* filename, bool appendPath, size_t* outLength) {
|
||||||
|
@ -31,9 +31,21 @@ public:
|
|||||||
FileStreamTest() : filename_(), json_(), length_() {}
|
FileStreamTest() : filename_(), json_(), length_() {}
|
||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
FILE *fp = fopen(filename_ = "data/sample.json", "rb");
|
const char *paths[] = {
|
||||||
if (!fp)
|
"data/sample.json",
|
||||||
fp = fopen(filename_ = "../../bin/data/sample.json", "rb");
|
"bin/data/sample.json",
|
||||||
|
"../bin/data/sample.json",
|
||||||
|
"../../bin/data/sample.json",
|
||||||
|
"../../../bin/data/sample.json"
|
||||||
|
};
|
||||||
|
FILE* fp = 0;
|
||||||
|
for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) {
|
||||||
|
fp = fopen(paths[i], "rb");
|
||||||
|
if (fp) {
|
||||||
|
filename_ = paths[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
ASSERT_TRUE(fp != 0);
|
ASSERT_TRUE(fp != 0);
|
||||||
|
|
||||||
fseek(fp, 0, SEEK_END);
|
fseek(fp, 0, SEEK_END);
|
||||||
|
@ -25,9 +25,22 @@
|
|||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
|
|
||||||
static char* ReadFile(const char* filename, size_t& length) {
|
static char* ReadFile(const char* filename, size_t& length) {
|
||||||
FILE *fp = fopen(filename, "rb");
|
const char *paths[] = {
|
||||||
if (!fp)
|
"jsonchecker/%s",
|
||||||
fp = fopen(filename, "rb");
|
"bin/jsonchecker/%s",
|
||||||
|
"../bin/jsonchecker/%s",
|
||||||
|
"../../bin/jsonchecker/%s",
|
||||||
|
"../../../bin/jsonchecker/%s"
|
||||||
|
};
|
||||||
|
char buffer[1024];
|
||||||
|
FILE *fp = 0;
|
||||||
|
for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) {
|
||||||
|
sprintf(buffer, paths[i], filename);
|
||||||
|
fp = fopen(buffer, "rb");
|
||||||
|
if (fp)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -51,17 +64,13 @@ TEST(JsonChecker, Reader) {
|
|||||||
if (i == 18) // fail18.json is valid in rapidjson, which has no limitation on depth of nesting.
|
if (i == 18) // fail18.json is valid in rapidjson, which has no limitation on depth of nesting.
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sprintf(filename, "jsonchecker/fail%d.json", i);
|
sprintf(filename, "fail%d.json", i);
|
||||||
size_t length;
|
size_t length;
|
||||||
char* json = ReadFile(filename, length);
|
char* json = ReadFile(filename, length);
|
||||||
if (!json) {
|
if (!json) {
|
||||||
sprintf(filename, "../../bin/jsonchecker/fail%d.json", i);
|
printf("jsonchecker file %s not found", filename);
|
||||||
json = ReadFile(filename, length);
|
ADD_FAILURE();
|
||||||
if (!json) {
|
continue;
|
||||||
printf("jsonchecker file %s not found", filename);
|
|
||||||
ADD_FAILURE();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak)
|
GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak)
|
||||||
@ -76,16 +85,12 @@ TEST(JsonChecker, Reader) {
|
|||||||
|
|
||||||
// passX.json
|
// passX.json
|
||||||
for (int i = 1; i <= 3; i++) {
|
for (int i = 1; i <= 3; i++) {
|
||||||
sprintf(filename, "jsonchecker/pass%d.json", i);
|
sprintf(filename, "pass%d.json", i);
|
||||||
size_t length;
|
size_t length;
|
||||||
char* json = ReadFile(filename, length);
|
char* json = ReadFile(filename, length);
|
||||||
if (!json) {
|
if (!json) {
|
||||||
sprintf(filename, "../../bin/jsonchecker/pass%d.json", i);
|
printf("jsonchecker file %s not found", filename);
|
||||||
json = ReadFile(filename, length);
|
continue;
|
||||||
if (!json) {
|
|
||||||
printf("jsonchecker file %s not found", filename);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak)
|
GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user