diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2023-01-10 09:49:29 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-01-10 16:10:18 +0100 |
commit | ef242750c534f91c13bac1d49b8ebcf701814dda (patch) | |
tree | bb5194c82e342728a738721667688ce3ffb60bd3 /test | |
parent | 4c7524a84a40062cf9692819577bf0ca44a15aa6 (diff) | |
download | barebox-ef242750c534f91c13bac1d49b8ebcf701814dda.tar.gz |
vsprintf: implement %pJP for printing JSONPaths
We use an array of strings to represnt a JSONPath. Add a new %pJP format
specifier that can be used to print them. This is useful for error
messages when the lookup fails.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20230110084930.3439001-4-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'test')
-rw-r--r-- | test/self/printf.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/self/printf.c b/test/self/printf.c index 7a74660868..eae40ed242 100644 --- a/test/self/printf.c +++ b/test/self/printf.c @@ -305,6 +305,22 @@ test_pointer(void) errptr(); } +static void __init +test_jsonpath(void) +{ + if (!IS_ENABLED(CONFIG_JSMN)) { + pr_info("skipping jsonpath tests: CONFIG_JSMN disabled in config\n"); + skipped_tests += 5; + return; + } + + test("<NULL>", "%pJP", NULL); + test("$", "%pJP", &(char *[]){ NULL }); + test("$.1", "%pJP", &(char *[]){ "1", NULL }); + test("$.1.23", "%pJP", &(char *[]){ "1", "23", NULL }); + test("$.1.23.456", "%pJP", &(char *[]){ "1", "23", "456", NULL }); +} + static void __init test_printf(void) { alloced_buffer = malloc(BUF_SIZE + 2*PAD_SIZE); @@ -317,6 +333,7 @@ static void __init test_printf(void) test_string(); test_pointer(); test_hexstr(); + test_jsonpath(); free(alloced_buffer); } |