Skip to content

Commit

Permalink
Add test driver for JSONTestSuite
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanofsky committed Nov 7, 2016
1 parent 3f03bfd commit 839ccd7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Makefile.am
Expand Up @@ -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

Expand All @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
@@ -1,4 +1,5 @@
unitester
test_json

*.trs
*.log
24 changes: 24 additions & 0 deletions 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;
}
}

0 comments on commit 839ccd7

Please sign in to comment.