Skip to content

Commit 839ccd7

Browse files
committed
Add test driver for JSONTestSuite
1 parent 3f03bfd commit 839ccd7

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Makefile.am

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ gen: lib/univalue_escapes.h $(GENBIN)
3333
@echo Updating $<
3434
$(AM_V_at)$(GENBIN) > lib/univalue_escapes.h
3535

36-
noinst_PROGRAMS = $(TESTS)
36+
noinst_PROGRAMS = $(TESTS) test/test_json
3737

3838
TEST_DATA_DIR=test
3939

@@ -42,6 +42,11 @@ test_unitester_LDADD = libunivalue.la
4242
test_unitester_CXXFLAGS = -I$(top_srcdir)/include -DJSON_TEST_SRC=\"$(srcdir)/$(TEST_DATA_DIR)\"
4343
test_unitester_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)
4444

45+
test_test_json_SOURCES = test/test_json.cpp
46+
test_test_json_LDADD = libunivalue.la
47+
test_test_json_CXXFLAGS = -I$(top_srcdir)/include
48+
test_test_json_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)
49+
4550
TEST_FILES = \
4651
$(TEST_DATA_DIR)/fail10.json \
4752
$(TEST_DATA_DIR)/fail11.json \

test/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
unitester
2+
test_json
23

34
*.trs
45
*.log

test/test_json.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Test program that can be called by the JSON test suite at
2+
// https://github.com/nst/JSONTestSuite.
3+
//
4+
// It reads JSON input from stdin and exits with code 0 if it can be parsed
5+
// successfully. It also pretty prints the parsed JSON value to stdout.
6+
7+
#include <iostream>
8+
#include <string>
9+
#include "univalue.h"
10+
11+
using namespace std;
12+
13+
int main (int argc, char *argv[])
14+
{
15+
UniValue val;
16+
if (val.read(string(istreambuf_iterator<char>(cin),
17+
istreambuf_iterator<char>()))) {
18+
cout << val.write(1 /* prettyIndent */, 4 /* indentLevel */) << endl;
19+
return 0;
20+
} else {
21+
cerr << "JSON Parse Error." << endl;
22+
return 1;
23+
}
24+
}

0 commit comments

Comments
 (0)