From 87a16eb8b54002a49f12944fc09ce45d0cbadf45 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 19 Oct 2022 08:41:13 +0200 Subject: shared/json: use different return code for empty input It is useful to distinguish if json_parse_file() got no input or invalid input. Use different return codes for the two cases. --- src/test/test-json.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/test/test-json.c') diff --git a/src/test/test-json.c b/src/test/test-json.c index 3563d004c8..946c827ccf 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -344,6 +344,24 @@ TEST(build) { assert_se(json_variant_equal(a, b)); } +TEST(json_parse_file_empty) { + _cleanup_fclose_ FILE *f = NULL; + _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + + assert_se(fopen_unlocked("/dev/null", "re", &f) >= 0); + assert_se(json_parse_file(f, "waldo", 0, &v, NULL, NULL) == -ENODATA); + assert_se(v == NULL); +} + +TEST(json_parse_file_invalid) { + _cleanup_fclose_ FILE *f = NULL; + _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + + assert_se(f = fmemopen_unlocked((void*) "kookoo", 6, "r")); + assert_se(json_parse_file(f, "waldo", 0, &v, NULL, NULL) == -EINVAL); + assert_se(v == NULL); +} + TEST(source) { static const char data[] = "\n" -- cgit v1.2.3