aboutsummaryrefslogtreecommitdiff
path: root/src/univalue/test
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2015-12-02 12:28:14 +0100
committerMarcoFalke <falke.marco@gmail.com>2015-12-02 12:28:48 +0100
commitfad4ea836dc7cd1bb13c7394a6fadff419e4b026 (patch)
treeff7f84f4820a67a433c25e42b7914f3fced26193 /src/univalue/test
parent1b0241fcec3e00d13658090e26cfa1f05133116e (diff)
parent982709199f1b4e9e35211c419a81938f9f1dd4ed (diff)
Merge commit '982709199f1b4e9e35211c419a81938f9f1dd4ed' into bitcoin
Diffstat (limited to 'src/univalue/test')
-rw-r--r--src/univalue/test/.gitignore3
-rw-r--r--src/univalue/test/fail35.json1
-rw-r--r--src/univalue/test/fail36.json1
-rw-r--r--src/univalue/test/fail37.json1
-rw-r--r--src/univalue/test/round1.json1
-rw-r--r--src/univalue/test/unitester.cpp29
6 files changed, 30 insertions, 6 deletions
diff --git a/src/univalue/test/.gitignore b/src/univalue/test/.gitignore
index 4afa094b10..3d9347fe7e 100644
--- a/src/univalue/test/.gitignore
+++ b/src/univalue/test/.gitignore
@@ -1 +1,4 @@
unitester
+
+*.trs
+*.log
diff --git a/src/univalue/test/fail35.json b/src/univalue/test/fail35.json
new file mode 100644
index 0000000000..de30ca5c47
--- /dev/null
+++ b/src/univalue/test/fail35.json
@@ -0,0 +1 @@
+[ true true true [] [] [] ]
diff --git a/src/univalue/test/fail36.json b/src/univalue/test/fail36.json
new file mode 100644
index 0000000000..f82eb8e1f0
--- /dev/null
+++ b/src/univalue/test/fail36.json
@@ -0,0 +1 @@
+{"a":}
diff --git a/src/univalue/test/fail37.json b/src/univalue/test/fail37.json
new file mode 100644
index 0000000000..3294dc3a42
--- /dev/null
+++ b/src/univalue/test/fail37.json
@@ -0,0 +1 @@
+{"a":1 "b":2}
diff --git a/src/univalue/test/round1.json b/src/univalue/test/round1.json
new file mode 100644
index 0000000000..a711e7308b
--- /dev/null
+++ b/src/univalue/test/round1.json
@@ -0,0 +1 @@
+["\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007f"]
diff --git a/src/univalue/test/unitester.cpp b/src/univalue/test/unitester.cpp
index 835556e031..5a052fe92c 100644
--- a/src/univalue/test/unitester.cpp
+++ b/src/univalue/test/unitester.cpp
@@ -19,24 +19,37 @@
using namespace std;
string srcdir(JSON_TEST_SRC);
+static bool test_failed = false;
-static void runtest(string filename, const string& jdata)
+#define d_assert(expr) { if (!(expr)) { test_failed = true; fprintf(stderr, "%s failed\n", filename.c_str()); } }
+
+static std::string rtrim(std::string s)
{
- fprintf(stderr, "test %s\n", filename.c_str());
+ s.erase(s.find_last_not_of(" \n\r\t")+1);
+ return s;
+}
+static void runtest(string filename, const string& jdata)
+{
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;
}