aboutsummaryrefslogtreecommitdiff
path: root/src/univalue/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/univalue/test')
-rw-r--r--src/univalue/test/.gitignore7
-rw-r--r--src/univalue/test/fail1.json1
-rw-r--r--src/univalue/test/fail10.json1
-rw-r--r--src/univalue/test/fail11.json1
-rw-r--r--src/univalue/test/fail12.json1
-rw-r--r--src/univalue/test/fail13.json1
-rw-r--r--src/univalue/test/fail14.json1
-rw-r--r--src/univalue/test/fail15.json1
-rw-r--r--src/univalue/test/fail16.json1
-rw-r--r--src/univalue/test/fail17.json1
-rw-r--r--src/univalue/test/fail18.json1
-rw-r--r--src/univalue/test/fail19.json1
-rw-r--r--src/univalue/test/fail2.json1
-rw-r--r--src/univalue/test/fail20.json1
-rw-r--r--src/univalue/test/fail21.json1
-rw-r--r--src/univalue/test/fail22.json1
-rw-r--r--src/univalue/test/fail23.json1
-rw-r--r--src/univalue/test/fail24.json1
-rw-r--r--src/univalue/test/fail25.json1
-rw-r--r--src/univalue/test/fail26.json1
-rw-r--r--src/univalue/test/fail27.json2
-rw-r--r--src/univalue/test/fail28.json2
-rw-r--r--src/univalue/test/fail29.json1
-rw-r--r--src/univalue/test/fail3.json1
-rw-r--r--src/univalue/test/fail30.json1
-rw-r--r--src/univalue/test/fail31.json1
-rw-r--r--src/univalue/test/fail32.json1
-rw-r--r--src/univalue/test/fail33.json1
-rw-r--r--src/univalue/test/fail34.json1
-rw-r--r--src/univalue/test/fail4.json1
-rw-r--r--src/univalue/test/fail5.json1
-rw-r--r--src/univalue/test/fail6.json1
-rw-r--r--src/univalue/test/fail7.json1
-rw-r--r--src/univalue/test/fail8.json1
-rw-r--r--src/univalue/test/fail9.json1
-rw-r--r--src/univalue/test/pass1.json58
-rw-r--r--src/univalue/test/pass2.json1
-rw-r--r--src/univalue/test/pass3.json6
-rw-r--r--src/univalue/test/unitester.cpp115
39 files changed, 223 insertions, 0 deletions
diff --git a/src/univalue/test/.gitignore b/src/univalue/test/.gitignore
new file mode 100644
index 0000000000..e4dea0df72
--- /dev/null
+++ b/src/univalue/test/.gitignore
@@ -0,0 +1,7 @@
+
+unitester
+
+*.log
+*.trs
+
+.libs
diff --git a/src/univalue/test/fail1.json b/src/univalue/test/fail1.json
new file mode 100644
index 0000000000..6216b865f1
--- /dev/null
+++ b/src/univalue/test/fail1.json
@@ -0,0 +1 @@
+"A JSON payload should be an object or array, not a string." \ No newline at end of file
diff --git a/src/univalue/test/fail10.json b/src/univalue/test/fail10.json
new file mode 100644
index 0000000000..5d8c0047bd
--- /dev/null
+++ b/src/univalue/test/fail10.json
@@ -0,0 +1 @@
+{"Extra value after close": true} "misplaced quoted value" \ No newline at end of file
diff --git a/src/univalue/test/fail11.json b/src/univalue/test/fail11.json
new file mode 100644
index 0000000000..76eb95b458
--- /dev/null
+++ b/src/univalue/test/fail11.json
@@ -0,0 +1 @@
+{"Illegal expression": 1 + 2} \ No newline at end of file
diff --git a/src/univalue/test/fail12.json b/src/univalue/test/fail12.json
new file mode 100644
index 0000000000..77580a4522
--- /dev/null
+++ b/src/univalue/test/fail12.json
@@ -0,0 +1 @@
+{"Illegal invocation": alert()} \ No newline at end of file
diff --git a/src/univalue/test/fail13.json b/src/univalue/test/fail13.json
new file mode 100644
index 0000000000..379406b59b
--- /dev/null
+++ b/src/univalue/test/fail13.json
@@ -0,0 +1 @@
+{"Numbers cannot have leading zeroes": 013} \ No newline at end of file
diff --git a/src/univalue/test/fail14.json b/src/univalue/test/fail14.json
new file mode 100644
index 0000000000..0ed366b38a
--- /dev/null
+++ b/src/univalue/test/fail14.json
@@ -0,0 +1 @@
+{"Numbers cannot be hex": 0x14} \ No newline at end of file
diff --git a/src/univalue/test/fail15.json b/src/univalue/test/fail15.json
new file mode 100644
index 0000000000..fc8376b605
--- /dev/null
+++ b/src/univalue/test/fail15.json
@@ -0,0 +1 @@
+["Illegal backslash escape: \x15"] \ No newline at end of file
diff --git a/src/univalue/test/fail16.json b/src/univalue/test/fail16.json
new file mode 100644
index 0000000000..3fe21d4b53
--- /dev/null
+++ b/src/univalue/test/fail16.json
@@ -0,0 +1 @@
+[\naked] \ No newline at end of file
diff --git a/src/univalue/test/fail17.json b/src/univalue/test/fail17.json
new file mode 100644
index 0000000000..62b9214aed
--- /dev/null
+++ b/src/univalue/test/fail17.json
@@ -0,0 +1 @@
+["Illegal backslash escape: \017"] \ No newline at end of file
diff --git a/src/univalue/test/fail18.json b/src/univalue/test/fail18.json
new file mode 100644
index 0000000000..edac92716f
--- /dev/null
+++ b/src/univalue/test/fail18.json
@@ -0,0 +1 @@
+[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]] \ No newline at end of file
diff --git a/src/univalue/test/fail19.json b/src/univalue/test/fail19.json
new file mode 100644
index 0000000000..3b9c46fa9a
--- /dev/null
+++ b/src/univalue/test/fail19.json
@@ -0,0 +1 @@
+{"Missing colon" null} \ No newline at end of file
diff --git a/src/univalue/test/fail2.json b/src/univalue/test/fail2.json
new file mode 100644
index 0000000000..6b7c11e5a5
--- /dev/null
+++ b/src/univalue/test/fail2.json
@@ -0,0 +1 @@
+["Unclosed array" \ No newline at end of file
diff --git a/src/univalue/test/fail20.json b/src/univalue/test/fail20.json
new file mode 100644
index 0000000000..27c1af3e72
--- /dev/null
+++ b/src/univalue/test/fail20.json
@@ -0,0 +1 @@
+{"Double colon":: null} \ No newline at end of file
diff --git a/src/univalue/test/fail21.json b/src/univalue/test/fail21.json
new file mode 100644
index 0000000000..62474573b2
--- /dev/null
+++ b/src/univalue/test/fail21.json
@@ -0,0 +1 @@
+{"Comma instead of colon", null} \ No newline at end of file
diff --git a/src/univalue/test/fail22.json b/src/univalue/test/fail22.json
new file mode 100644
index 0000000000..a7752581bc
--- /dev/null
+++ b/src/univalue/test/fail22.json
@@ -0,0 +1 @@
+["Colon instead of comma": false] \ No newline at end of file
diff --git a/src/univalue/test/fail23.json b/src/univalue/test/fail23.json
new file mode 100644
index 0000000000..494add1ca1
--- /dev/null
+++ b/src/univalue/test/fail23.json
@@ -0,0 +1 @@
+["Bad value", truth] \ No newline at end of file
diff --git a/src/univalue/test/fail24.json b/src/univalue/test/fail24.json
new file mode 100644
index 0000000000..caff239bfc
--- /dev/null
+++ b/src/univalue/test/fail24.json
@@ -0,0 +1 @@
+['single quote'] \ No newline at end of file
diff --git a/src/univalue/test/fail25.json b/src/univalue/test/fail25.json
new file mode 100644
index 0000000000..8b7ad23e01
--- /dev/null
+++ b/src/univalue/test/fail25.json
@@ -0,0 +1 @@
+[" tab character in string "] \ No newline at end of file
diff --git a/src/univalue/test/fail26.json b/src/univalue/test/fail26.json
new file mode 100644
index 0000000000..845d26a6a5
--- /dev/null
+++ b/src/univalue/test/fail26.json
@@ -0,0 +1 @@
+["tab\ character\ in\ string\ "] \ No newline at end of file
diff --git a/src/univalue/test/fail27.json b/src/univalue/test/fail27.json
new file mode 100644
index 0000000000..6b01a2ca4a
--- /dev/null
+++ b/src/univalue/test/fail27.json
@@ -0,0 +1,2 @@
+["line
+break"] \ No newline at end of file
diff --git a/src/univalue/test/fail28.json b/src/univalue/test/fail28.json
new file mode 100644
index 0000000000..621a0101c6
--- /dev/null
+++ b/src/univalue/test/fail28.json
@@ -0,0 +1,2 @@
+["line\
+break"] \ No newline at end of file
diff --git a/src/univalue/test/fail29.json b/src/univalue/test/fail29.json
new file mode 100644
index 0000000000..47ec421bb6
--- /dev/null
+++ b/src/univalue/test/fail29.json
@@ -0,0 +1 @@
+[0e] \ No newline at end of file
diff --git a/src/univalue/test/fail3.json b/src/univalue/test/fail3.json
new file mode 100644
index 0000000000..168c81eb78
--- /dev/null
+++ b/src/univalue/test/fail3.json
@@ -0,0 +1 @@
+{unquoted_key: "keys must be quoted"} \ No newline at end of file
diff --git a/src/univalue/test/fail30.json b/src/univalue/test/fail30.json
new file mode 100644
index 0000000000..8ab0bc4b8b
--- /dev/null
+++ b/src/univalue/test/fail30.json
@@ -0,0 +1 @@
+[0e+] \ No newline at end of file
diff --git a/src/univalue/test/fail31.json b/src/univalue/test/fail31.json
new file mode 100644
index 0000000000..1cce602b51
--- /dev/null
+++ b/src/univalue/test/fail31.json
@@ -0,0 +1 @@
+[0e+-1] \ No newline at end of file
diff --git a/src/univalue/test/fail32.json b/src/univalue/test/fail32.json
new file mode 100644
index 0000000000..45cba7396f
--- /dev/null
+++ b/src/univalue/test/fail32.json
@@ -0,0 +1 @@
+{"Comma instead if closing brace": true, \ No newline at end of file
diff --git a/src/univalue/test/fail33.json b/src/univalue/test/fail33.json
new file mode 100644
index 0000000000..ca5eb19dc9
--- /dev/null
+++ b/src/univalue/test/fail33.json
@@ -0,0 +1 @@
+["mismatch"} \ No newline at end of file
diff --git a/src/univalue/test/fail34.json b/src/univalue/test/fail34.json
new file mode 100644
index 0000000000..3f8be17286
--- /dev/null
+++ b/src/univalue/test/fail34.json
@@ -0,0 +1 @@
+{} garbage \ No newline at end of file
diff --git a/src/univalue/test/fail4.json b/src/univalue/test/fail4.json
new file mode 100644
index 0000000000..9de168bf34
--- /dev/null
+++ b/src/univalue/test/fail4.json
@@ -0,0 +1 @@
+["extra comma",] \ No newline at end of file
diff --git a/src/univalue/test/fail5.json b/src/univalue/test/fail5.json
new file mode 100644
index 0000000000..ddf3ce3d24
--- /dev/null
+++ b/src/univalue/test/fail5.json
@@ -0,0 +1 @@
+["double extra comma",,] \ No newline at end of file
diff --git a/src/univalue/test/fail6.json b/src/univalue/test/fail6.json
new file mode 100644
index 0000000000..ed91580e1b
--- /dev/null
+++ b/src/univalue/test/fail6.json
@@ -0,0 +1 @@
+[ , "<-- missing value"] \ No newline at end of file
diff --git a/src/univalue/test/fail7.json b/src/univalue/test/fail7.json
new file mode 100644
index 0000000000..8a96af3e4e
--- /dev/null
+++ b/src/univalue/test/fail7.json
@@ -0,0 +1 @@
+["Comma after the close"], \ No newline at end of file
diff --git a/src/univalue/test/fail8.json b/src/univalue/test/fail8.json
new file mode 100644
index 0000000000..b28479c6ec
--- /dev/null
+++ b/src/univalue/test/fail8.json
@@ -0,0 +1 @@
+["Extra close"]] \ No newline at end of file
diff --git a/src/univalue/test/fail9.json b/src/univalue/test/fail9.json
new file mode 100644
index 0000000000..5815574f36
--- /dev/null
+++ b/src/univalue/test/fail9.json
@@ -0,0 +1 @@
+{"Extra comma": true,} \ No newline at end of file
diff --git a/src/univalue/test/pass1.json b/src/univalue/test/pass1.json
new file mode 100644
index 0000000000..70e2685436
--- /dev/null
+++ b/src/univalue/test/pass1.json
@@ -0,0 +1,58 @@
+[
+ "JSON Test Pattern pass1",
+ {"object with 1 member":["array with 1 element"]},
+ {},
+ [],
+ -42,
+ true,
+ false,
+ null,
+ {
+ "integer": 1234567890,
+ "real": -9876.543210,
+ "e": 0.123456789e-12,
+ "E": 1.234567890E+34,
+ "": 23456789012E66,
+ "zero": 0,
+ "one": 1,
+ "space": " ",
+ "quote": "\"",
+ "backslash": "\\",
+ "controls": "\b\f\n\r\t",
+ "slash": "/ & \/",
+ "alpha": "abcdefghijklmnopqrstuvwyz",
+ "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
+ "digit": "0123456789",
+ "0123456789": "digit",
+ "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
+ "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
+ "true": true,
+ "false": false,
+ "null": null,
+ "array":[ ],
+ "object":{ },
+ "address": "50 St. James Street",
+ "url": "http://www.JSON.org/",
+ "comment": "// /* <!-- --",
+ "# -- --> */": " ",
+ " s p a c e d " :[1,2 , 3
+
+,
+
+4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
+ "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
+ "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
+ "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
+: "A key can be any string"
+ },
+ 0.5 ,98.6
+,
+99.44
+,
+
+1066,
+1e1,
+0.1e1,
+1e-1,
+1e00,2e+00,2e-00
+,"rosebud"] \ No newline at end of file
diff --git a/src/univalue/test/pass2.json b/src/univalue/test/pass2.json
new file mode 100644
index 0000000000..d3c63c7ad8
--- /dev/null
+++ b/src/univalue/test/pass2.json
@@ -0,0 +1 @@
+[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] \ No newline at end of file
diff --git a/src/univalue/test/pass3.json b/src/univalue/test/pass3.json
new file mode 100644
index 0000000000..4528d51f1a
--- /dev/null
+++ b/src/univalue/test/pass3.json
@@ -0,0 +1,6 @@
+{
+ "JSON Test Pattern pass3": {
+ "The outermost value": "must be an object or array.",
+ "In this test": "It is an object."
+ }
+}
diff --git a/src/univalue/test/unitester.cpp b/src/univalue/test/unitester.cpp
new file mode 100644
index 0000000000..835556e031
--- /dev/null
+++ b/src/univalue/test/unitester.cpp
@@ -0,0 +1,115 @@
+// Copyright 2014 BitPay Inc.
+// Distributed under the MIT/X11 software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <cassert>
+#include <string>
+#include "univalue.h"
+
+#ifndef JSON_TEST_SRC
+#error JSON_TEST_SRC must point to test source directory
+#endif
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
+using namespace std;
+string srcdir(JSON_TEST_SRC);
+
+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 wantFail = (prefix == "fail");
+ assert(wantPass || wantFail);
+
+ UniValue val;
+ bool testResult = val.read(jdata);
+
+ if (wantPass) {
+ assert(testResult == true);
+ } else {
+ assert(testResult == false);
+ }
+}
+
+static void runtest_file(const char *filename_)
+{
+ string basename(filename_);
+ string filename = srcdir + "/" + basename;
+ FILE *f = fopen(filename.c_str(), "r");
+ assert(f != NULL);
+
+ string jdata;
+
+ char buf[4096];
+ while (!feof(f)) {
+ int bread = fread(buf, 1, sizeof(buf), f);
+ assert(!ferror(f));
+
+ string s(buf, bread);
+ jdata += s;
+ }
+
+ assert(!ferror(f));
+ fclose(f);
+
+ runtest(basename, jdata);
+}
+
+static const char *filenames[] = {
+ "fail10.json",
+ "fail11.json",
+ "fail12.json",
+ "fail13.json",
+ "fail14.json",
+ "fail15.json",
+ "fail16.json",
+ "fail17.json",
+ //"fail18.json", // investigate
+ "fail19.json",
+ "fail1.json",
+ "fail20.json",
+ "fail21.json",
+ "fail22.json",
+ "fail23.json",
+ "fail24.json",
+ "fail25.json",
+ "fail26.json",
+ "fail27.json",
+ "fail28.json",
+ "fail29.json",
+ "fail2.json",
+ "fail30.json",
+ "fail31.json",
+ "fail32.json",
+ "fail33.json",
+ "fail34.json",
+ "fail3.json",
+ "fail4.json", // extra comma
+ "fail5.json",
+ "fail6.json",
+ "fail7.json",
+ "fail8.json",
+ "fail9.json", // extra comma
+ "pass1.json",
+ "pass2.json",
+ "pass3.json",
+};
+
+int main (int argc, char *argv[])
+{
+ for (unsigned int fidx = 0; fidx < ARRAY_SIZE(filenames); fidx++) {
+ runtest_file(filenames[fidx]);
+ }
+
+ return 0;
+}
+