13 #error JSON_TEST_SRC must point to test source directory 17 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 21 string srcdir(JSON_TEST_SRC);
22 static bool test_failed =
false;
24 #define d_assert(expr) { if (!(expr)) { test_failed = true; fprintf(stderr, "%s failed\n", filename.c_str()); } } 25 #define f_assert(expr) { if (!(expr)) { test_failed = true; fprintf(stderr, "%s failed\n", __func__); } } 27 static std::string rtrim(std::string s)
29 s.erase(s.find_last_not_of(
" \n\r\t")+1);
33 static void runtest(
string filename,
const string& jdata)
35 string prefix = filename.substr(0, 4);
37 bool wantPass = (prefix ==
"pass") || (prefix ==
"roun");
38 bool wantFail = (prefix ==
"fail");
39 bool wantRoundTrip = (prefix ==
"roun");
40 assert(wantPass || wantFail);
43 bool testResult = val.
read(jdata);
52 std::string odata = val.
write(0, 0);
53 assert(odata == rtrim(jdata));
57 static void runtest_file(
const char *filename_)
59 string basename(filename_);
60 string filename =
srcdir +
"/" + basename;
61 FILE *
f =
fopen(filename.c_str(),
"r");
68 int bread = fread(buf, 1,
sizeof(buf), f);
78 runtest(basename, jdata);
81 static const char *filenames[] = {
143 testResult = val.
read(
"[\"\\u0022\"]");
147 testResult = val.
read(
"[\"\\u0191\"]");
151 testResult = val.
read(
"[\"\\u2191\"]");
155 testResult = val.
read(
"[\"\\ud834\\udd61\"]");
160 int main (
int argc,
char *argv[])
162 for (
unsigned int fidx = 0; fidx <
ARRAY_SIZE(filenames); fidx++) {
163 runtest_file(filenames[fidx]);
168 return test_failed ? 1 : 0;
FILE * fopen(const fs::path &p, const char *mode)
int main(int argc, char *argv[])
bool read(const char *raw, size_t len)
std::hash for asio::adress
assert(len-trim+(2 *lenIndices)<=WIDTH)
void unescape_unicode_test()
string srcdir(JSON_TEST_SRC)
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)