From 839ccd71f3e547842319065d71a185eade5e4453 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Tue, 1 Nov 2016 15:15:10 -0400 Subject: [PATCH] Add test driver for JSONTestSuite --- Makefile.am | 7 ++++++- test/.gitignore | 1 + test/test_json.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/test_json.cpp diff --git a/Makefile.am b/Makefile.am index 6c1ec81e63f..caa74bf41a8 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 3d9347fe7e5..599875d26d2 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 00000000000..2943bae2b15 --- /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 +#include +#include "univalue.h" + +using namespace std; + +int main (int argc, char *argv[]) +{ + UniValue val; + if (val.read(string(istreambuf_iterator(cin), + istreambuf_iterator()))) { + cout << val.write(1 /* prettyIndent */, 4 /* indentLevel */) << endl; + return 0; + } else { + cerr << "JSON Parse Error." << endl; + return 1; + } +}