diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 00:55:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 00:55:53 +0000 |
commit | 3d0386f27ca66379acf50199e1d1298386eeeeb8 (patch) | |
tree | f87bd4a126b3a843858eb447e8fd5893c3ee3882 /contrib/ccan/json/test/run-validate.c | |
parent | Initial commit. (diff) | |
download | knot-resolver-upstream.tar.xz knot-resolver-upstream.zip |
Adding upstream version 3.2.1.upstream/3.2.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | contrib/ccan/json/test/run-validate.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/contrib/ccan/json/test/run-validate.c b/contrib/ccan/json/test/run-validate.c new file mode 100644 index 0000000..f7bb3b0 --- /dev/null +++ b/contrib/ccan/json/test/run-validate.c @@ -0,0 +1,49 @@ +#include "common.h" + +int main(void) +{ + const char *strings_file = "test/test-strings"; + FILE *f; + char buffer[1024]; + + plan_tests(224); + + f = fopen(strings_file, "rb"); + if (f == NULL) { + diag("Could not open %s: %s", strings_file, strerror(errno)); + return 1; + } + + while (fgets(buffer, sizeof(buffer), f)) { + const char *s = chomp(buffer); + bool valid; + + if (expect_literal(&s, "valid ")) { + valid = true; + } else if (expect_literal(&s, "invalid ")) { + valid = false; + } else { + fail("Invalid line in test-strings: %s", buffer); + continue; + } + + if (strcmp(s, "\"1\\u2\"") == 0) + puts("here"); + + if (json_validate(s) == valid) { + pass("%s %s", valid ? "valid" : "invalid", s); + } else { + fail("%s is %s, but json_validate returned %s", + s, + valid ? "valid" : "invalid", + valid ? "false" : "true"); + } + } + + if (ferror(f) || fclose(f) != 0) { + diag("I/O error reading test strings."); + return 1; + } + + return exit_status(); +} |