Squashed 'src/univalue/' changes from 5839ac3..2740c4f

2740c4f Merge branch '2015_11_escape_plan' into bitcoin
7482163 Add new testcase to Makefile.am
46098ee Version 1.0.1.
ccf3575 parser: Ensure multiple values cannot follow each other
eb6cd64 Omit Obj/Arr open token from jsonTokenIsValue() test
bfef9e2 Makefile.am: list recently added test data, fail{35,36}.json
3e319f3 parser: Tighten array, object syntax checks.
c74185c parser: transform C++ variables into bitmask
f2568bc Prefer C++ STL vector .at() for accessing object values.
8eafa26 travis: run parallel 'make distcheck'
fd448da test: Improve tester diagnostics.  Add failing test case from #15
2158205 Use internal, locale-independent isspace(), isdigit() implementations.
2ab9ad4 travis: Make 'make distcheck' for more comprehensive checks.
3339191 Escape all control characters

git-subtree-dir: src/univalue
git-subtree-split: 2740c4f71242086a7eb3dc32f812546ba9fad913
This commit is contained in:
MarcoFalke
2015-12-02 12:26:24 +01:00
parent 313e7f5c89
commit 982709199f
16 changed files with 205 additions and 83 deletions

View File

@@ -19,24 +19,37 @@
using namespace std;
string srcdir(JSON_TEST_SRC);
static bool test_failed = false;
#define d_assert(expr) { if (!(expr)) { test_failed = true; fprintf(stderr, "%s failed\n", filename.c_str()); } }
static std::string rtrim(std::string s)
{
s.erase(s.find_last_not_of(" \n\r\t")+1);
return s;
}
static void runtest(string filename, const string& jdata)
{
fprintf(stderr, "test %s\n", filename.c_str());
string prefix = filename.substr(0, 4);
bool wantPass = (prefix == "pass");
bool wantPass = (prefix == "pass") || (prefix == "roun");
bool wantFail = (prefix == "fail");
bool wantRoundTrip = (prefix == "roun");
assert(wantPass || wantFail);
UniValue val;
bool testResult = val.read(jdata);
if (wantPass) {
assert(testResult == true);
d_assert(testResult == true);
} else {
assert(testResult == false);
d_assert(testResult == false);
}
if (wantRoundTrip) {
std::string odata = val.write(0, 0);
assert(odata == rtrim(jdata));
}
}
@@ -92,6 +105,9 @@ static const char *filenames[] = {
"fail32.json",
"fail33.json",
"fail34.json",
"fail35.json",
"fail36.json",
"fail37.json",
"fail3.json",
"fail4.json", // extra comma
"fail5.json",
@@ -102,6 +118,7 @@ static const char *filenames[] = {
"pass1.json",
"pass2.json",
"pass3.json",
"round1.json", // round-trip test
};
int main (int argc, char *argv[])
@@ -110,6 +127,6 @@ int main (int argc, char *argv[])
runtest_file(filenames[fidx]);
}
return 0;
return test_failed ? 1 : 0;
}