diff options
author | Petri Lehtinen <petri@digip.org> | 2018-02-08 20:52:10 +0200 |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2018-02-09 07:37:33 +0200 |
commit | efe6c7b3f2b3d75f1543c3ff4e4c3ecfe914b08d (patch) | |
tree | 2eb808e44134e355355f4ce065140c47b5bb9e8e /test | |
parent | 3e81f78366b57a0b5c34d5bfab9cffe5c9605027 (diff) | |
download | jansson-efe6c7b3f2b3d75f1543c3ff4e4c3ecfe914b08d.zip jansson-efe6c7b3f2b3d75f1543c3ff4e4c3ecfe914b08d.tar.gz jansson-efe6c7b3f2b3d75f1543c3ff4e4c3ecfe914b08d.tar.bz2 |
Add json_sprintf and json_vsprintfjson_sprintf
Fixes #392
Diffstat (limited to 'test')
-rw-r--r-- | test/.gitignore | 3 | ||||
-rw-r--r-- | test/suites/api/Makefile.am | 2 | ||||
-rw-r--r-- | test/suites/api/test_sprintf.c | 22 |
3 files changed, 26 insertions, 1 deletions
diff --git a/test/.gitignore b/test/.gitignore index 58e5e31..9c638ac 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -7,14 +7,15 @@ suites/api/test_dump suites/api/test_dump_callback suites/api/test_equal suites/api/test_load +suites/api/test_load_callback suites/api/test_loadb suites/api/test_memory_funcs suites/api/test_number suites/api/test_object suites/api/test_pack suites/api/test_simple +suites/api/test_sprintf suites/api/test_unpack -suites/api/test_load_callback run-suites.log run-suites.trs test-suite.log diff --git a/test/suites/api/Makefile.am b/test/suites/api/Makefile.am index 1dbdd2b..a1bc4d3 100644 --- a/test/suites/api/Makefile.am +++ b/test/suites/api/Makefile.am @@ -14,6 +14,7 @@ check_PROGRAMS = \ test_object \ test_pack \ test_simple \ + test_sprintf \ test_unpack test_array_SOURCES = test_array.c util.h @@ -27,6 +28,7 @@ test_number_SOURCES = test_number.c util.h test_object_SOURCES = test_object.c util.h test_pack_SOURCES = test_pack.c util.h test_simple_SOURCES = test_simple.c util.h +test_sprintf_SOURCES = test_sprintf.c util.h test_unpack_SOURCES = test_unpack.c util.h AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src diff --git a/test/suites/api/test_sprintf.c b/test/suites/api/test_sprintf.c new file mode 100644 index 0000000..34908d8 --- /dev/null +++ b/test/suites/api/test_sprintf.c @@ -0,0 +1,22 @@ +#include <string.h> +#include <jansson.h> +#include "util.h" + + +static void test_sprintf() { + json_t *s = json_sprintf("foo bar %d", 42); + if (!s) + fail("json_sprintf returned NULL"); + if (!json_is_string(s)) + fail("json_sprintf didn't return a JSON string"); + if (strcmp(json_string_value(s), "foo bar 42")) + fail("json_sprintf generated an unexpected string"); + + json_decref(s); +} + + +static void run_tests() +{ + test_sprintf(); +} |