[Pkg-bitcoin-commits] [libunivalue] 14/38: Add test driver for JSONTestSuite
Jonas Smedegaard
dr at jones.dk
Mon Feb 27 01:13:27 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libunivalue.
commit 839ccd71f3e547842319065d71a185eade5e4453
Author: Russell Yanofsky <russ at yanofsky.org>
Date: Tue Nov 1 15:15:10 2016 -0400
Add test driver for JSONTestSuite
---
Makefile.am | 7 ++++++-
test/.gitignore | 1 +
test/test_json.cpp | 24 ++++++++++++++++++++++++
3 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am
index 6c1ec81..caa74bf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,7 +33,7 @@ gen: lib/univalue_escapes.h $(GENBIN)
@echo Updating $<
$(AM_V_at)$(GENBIN) > lib/univalue_escapes.h
-noinst_PROGRAMS = $(TESTS)
+noinst_PROGRAMS = $(TESTS) test/test_json
TEST_DATA_DIR=test
@@ -42,6 +42,11 @@ test_unitester_LDADD = libunivalue.la
test_unitester_CXXFLAGS = -I$(top_srcdir)/include -DJSON_TEST_SRC=\"$(srcdir)/$(TEST_DATA_DIR)\"
test_unitester_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)
+test_test_json_SOURCES = test/test_json.cpp
+test_test_json_LDADD = libunivalue.la
+test_test_json_CXXFLAGS = -I$(top_srcdir)/include
+test_test_json_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)
+
TEST_FILES = \
$(TEST_DATA_DIR)/fail10.json \
$(TEST_DATA_DIR)/fail11.json \
diff --git a/test/.gitignore b/test/.gitignore
index 3d9347f..599875d 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1,4 +1,5 @@
unitester
+test_json
*.trs
*.log
diff --git a/test/test_json.cpp b/test/test_json.cpp
new file mode 100644
index 0000000..2943bae
--- /dev/null
+++ b/test/test_json.cpp
@@ -0,0 +1,24 @@
+// Test program that can be called by the JSON test suite at
+// https://github.com/nst/JSONTestSuite.
+//
+// It reads JSON input from stdin and exits with code 0 if it can be parsed
+// successfully. It also pretty prints the parsed JSON value to stdout.
+
+#include <iostream>
+#include <string>
+#include "univalue.h"
+
+using namespace std;
+
+int main (int argc, char *argv[])
+{
+ UniValue val;
+ if (val.read(string(istreambuf_iterator<char>(cin),
+ istreambuf_iterator<char>()))) {
+ cout << val.write(1 /* prettyIndent */, 4 /* indentLevel */) << endl;
+ return 0;
+ } else {
+ cerr << "JSON Parse Error." << endl;
+ return 1;
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/libunivalue.git
More information about the Pkg-bitcoin-commits
mailing list