uri_test.c 1.8 KB

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