From: Alexandru Ardelean Date: Wed, 16 Nov 2016 14:22:13 +0000 (+0200) Subject: test_json_pointer: update test with a few printf variants X-Git-Tag: json-c-0.13-20171207~112^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0da680f13a089a124c1c841f55288045a814243;p=thirdparty%2Fjson-c.git test_json_pointer: update test with a few printf variants Signed-off-by: Alexandru Ardelean --- diff --git a/tests/test_json_pointer.c b/tests/test_json_pointer.c index aa495ccc..f42d0104 100644 --- a/tests/test_json_pointer.c +++ b/tests/test_json_pointer.c @@ -132,6 +132,10 @@ static void test_recursion_get() assert(json_object_is_type(jo2, json_type_string)); assert(0 == strcmp("1", json_object_get_string(jo2))); + assert(0 == json_pointer_getf(jo1, &jo2, "/%s/%d/%s/%d/%s", "arr", 0, "obj", 2, "obj2")); + assert(json_object_is_type(jo2, json_type_string)); + assert(0 == strcmp("1", json_object_get_string(jo2))); + assert(jo1 != NULL); assert(0 == json_pointer_get(jo1, "/obj/obj/obj/0/obj1", &jo2)); assert(json_object_is_type(jo2, json_type_int)); @@ -180,6 +184,9 @@ static void test_wrong_inputs_get() assert(0 != json_pointer_get(jo1, "/foo/a", NULL)); assert(errno == EINVAL); errno = 0; + assert(0 != json_pointer_getf(jo1, NULL, "/%s/a", "foo")); + assert(errno == EINVAL); + errno = 0; assert(0 != json_pointer_get(jo1, "/foo/-", NULL)); assert(errno == EINVAL); errno = 0; @@ -188,7 +195,10 @@ static void test_wrong_inputs_get() assert(errno == ENOENT); errno = 0; /* Test non-optimized array path */ - assert(0 != json_pointer_get(jo1, "/foo/22", NULL)); + assert(0 != json_pointer_getf(jo1, NULL, "%s", "/foo/22")); + assert(errno == ENOENT); + errno = 0; + assert(0 != json_pointer_getf(jo1, NULL, "/%s/%d", "foo", 22)); assert(errno == ENOENT); errno = 0; assert(0 != json_pointer_get(jo1, "/foo/-1", NULL)); @@ -220,6 +230,7 @@ static void test_example_set() assert(0 == json_pointer_set(&jo1, "/fud/gaw", jo2)); /* re-using jo2 from above */ printf("PASSED - SET - /fug/gaw == [1,2,3]\n"); assert(0 == json_pointer_set(&jo1, "/fud/gaw/0", json_object_new_int(0))); + assert(0 == json_pointer_setf(&jo1, json_object_new_int(0), "%s%s/%d", "/fud", "/gaw", 0)); printf("PASSED - SET - /fug/gaw == [0,2,3]\n"); assert(0 == json_pointer_set(&jo1, "/fud/gaw/-", json_object_new_int(4))); printf("PASSED - SET - /fug/gaw == [0,2,3,4]\n");