Add json_sprintf and json_vsprintf

Fixes #392
This commit is contained in:
Petri Lehtinen
2018-02-08 20:52:10 +02:00
parent 3e81f78366
commit efe6c7b3f2
8 changed files with 78 additions and 1 deletions

View File

@@ -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

View File

@@ -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();
}