uri_test.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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:///usr/../dev/null", "/usr/../dev/null", FALSE},
  29. {"file:///dev/null", "/usr/../dev/null", TRUE},
  30. {"http://example.org", "example.org", FALSE},
  31. {"http://example.org", "example.org", TRUE},
  32. {"http://", "http://", FALSE},
  33. {"http://", "http://", TRUE},
  34. {"http://badwolf.c", "badwolf.c", FALSE} //
  35. };
  36. for(size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
  37. {
  38. g_info("badwolf_ensure_uri_scheme(\"%s\", %s)",
  39. cases[i].text,
  40. cases[i].try_file ? "TRUE" : "FALSE");
  41. const gchar *got = badwolf_ensure_uri_scheme(cases[i].text, cases[i].try_file);
  42. if(g_strcmp0(got, cases[i].expect) != 0)
  43. {
  44. g_error("expected: \"%s\", got: \"%s\"", cases[i].expect, got);
  45. }
  46. }
  47. }
  48. int
  49. main(int argc, char *argv[])
  50. {
  51. g_test_init(&argc, &argv, NULL);
  52. g_test_add_func("/badwolf_ensure_uri_scheme/test", badwolf_ensure_uri_scheme_test);
  53. return g_test_run();
  54. }