summaryrefslogtreecommitdiffstats
path: root/contrib/ccan/json/test/run-validate.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 00:55:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 00:55:53 +0000
commit3d0386f27ca66379acf50199e1d1298386eeeeb8 (patch)
treef87bd4a126b3a843858eb447e8fd5893c3ee3882 /contrib/ccan/json/test/run-validate.c
parentInitial commit. (diff)
downloadknot-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.c49
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();
+}