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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-10-19 09:46:55 +02:00
parent 7922ead507
commit 87a16eb8b5
3 changed files with 23 additions and 3 deletions
+18
View File
@@ -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"