uri_test.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser
  2. // Copyright © 2019-2020 Badwolf Authors <https://hacktivis.me/projects/badwolf>
  3. // SPDX-License-Identifier: BSD-3-Clause
  4. #include "uri.h"
  5. #include <glib.h>
  6. #include <glib/gi18n.h>
  7. static void
  8. badwolf_ensure_uri_scheme_test(void)
  9. {
  10. const gchar *fallback = "about:blank";
  11. struct
  12. {
  13. const gchar *expect;
  14. const gchar *text;
  15. gboolean try_file;
  16. } cases[] = {
  17. //
  18. {"http://uri.c", "http://uri.c", FALSE},
  19. {"http://uri.c", "http://uri.c", TRUE},
  20. {"file:///dev/null", "file:///dev/null", FALSE},
  21. {"file:///dev/null", "file:///dev/null", TRUE},
  22. {fallback, NULL, FALSE},
  23. {fallback, NULL, TRUE},
  24. {fallback, "", FALSE},
  25. {fallback, "", TRUE},
  26. {"http:///dev/null", "/dev/null", FALSE},
  27. {"file:///dev/null", "/dev/null", TRUE},
  28. {"http://example.org", "example.org", FALSE},
  29. {"http://example.org", "example.org", TRUE},
  30. {"http://", "http://", FALSE},
  31. {"http://", "http://", TRUE} //
  32. };
  33. for(size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
  34. {
  35. g_info("badwolf_ensure_uri_scheme(\"%s\", %s)",
  36. cases[i].text,
  37. cases[i].try_file ? "TRUE" : "FALSE");
  38. const gchar *got = badwolf_ensure_uri_scheme(cases[i].text, cases[i].try_file);
  39. if(g_strcmp0(got, cases[i].expect) != 0)
  40. {
  41. g_error("expected: \"%s\", got: \"%s\"", cases[i].expect, got);
  42. }
  43. }
  44. }
  45. int
  46. main(int argc, char *argv[])
  47. {
  48. g_test_init(&argc, &argv, NULL);
  49. g_test_add_func("/badwolf_ensure_uri_scheme/test", badwolf_ensure_uri_scheme_test);
  50. return g_test_run();
  51. }