1 #include "util.h" 2 #include <jansson.h> 3 #include <string.h> 4 test_sprintf()5static void test_sprintf() { 6 json_t *s = json_sprintf("foo bar %d", 42); 7 if (!s) 8 fail("json_sprintf returned NULL"); 9 if (!json_is_string(s)) 10 fail("json_sprintf didn't return a JSON string"); 11 if (strcmp(json_string_value(s), "foo bar 42")) 12 fail("json_sprintf generated an unexpected string"); 13 14 json_decref(s); 15 16 s = json_sprintf("%s", ""); 17 if (!s) 18 fail("json_sprintf returned NULL"); 19 if (!json_is_string(s)) 20 fail("json_sprintf didn't return a JSON string"); 21 if (json_string_length(s) != 0) 22 fail("string is not empty"); 23 json_decref(s); 24 25 if (json_sprintf("%s", "\xff\xff")) 26 fail("json_sprintf unexpected success with invalid UTF"); 27 } 28 run_tests()29static void run_tests() { test_sprintf(); } 30