diff options
Add tests on badwolf_ensure_uri_scheme
1 files changed, 54 insertions, 0 deletions
| -rw-r--r-- | uri_test.c | 54 |
diff --git a/uri_test.c b/uri_test.c new file mode 100644 index 0000000..c5ebe7e --- /dev/null +++ b/uri_test.c @@ -0,0 +1,54 @@ +// BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser +// Copyright © 2019 Haelwenn (lanodan) Monnier <contact@hacktivis.me> +// SPDX-License-Identifier: BSD-3-Clause + +#include "uri.h" + +#include <glib.h> +#include <glib/gi18n.h> + +static void +badwolf_ensure_uri_scheme_test(void) +{ + const gchar *fallback = "about:blank"; + + struct + { + const gchar *expect; + const gchar *text; + gboolean try_file; + } cases[] = { + // clang formatting hack + {fallback, NULL, FALSE}, + {fallback, NULL, TRUE}, + {fallback, "", FALSE}, + {fallback, "", TRUE}, + {fallback, "/dev/null", FALSE}, + //{"file://dev/null", "/dev/null", TRUE}, + //{"http://example.org", "example.org", FALSE}, + //{"http://example.org", "example.org", TRUE}, + //{fallback, "http://", FALSE}, + //{fallback, "http://", TRUE} + }; + + for(size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) + { + g_info("badwolf_ensure_uri_scheme(\"%s\", %s)", + cases[i].text, + cases[i].try_file ? "TRUE" : "FALSE"); + + const gchar *got = badwolf_ensure_uri_scheme(cases[i].text, cases[i].try_file); + + if(got != cases[i].expect) g_error("expected: \"%s\", got: \"%s\"", cases[i].expect, got); + } +} + +int +main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/badwolf_ensure_uri_scheme/test", badwolf_ensure_uri_scheme_test); + + return g_test_run(); +} |