fmt_test.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser
  2. // SPDX-FileCopyrightText: 2019-2022 Badwolf Authors <https://hacktivis.me/projects/badwolf>
  3. // SPDX-License-Identifier: BSD-3-Clause
  4. #include "fmt.h"
  5. #include <glib.h>
  6. #include <inttypes.h> // PRIu32
  7. #include <stdint.h> // UINT32_C
  8. static void
  9. fmt_session_id_test(void)
  10. {
  11. struct
  12. {
  13. const char *expect;
  14. uint32_t session_id;
  15. } cases[] = {
  16. //
  17. {"A: ", UINT32_C(0)},
  18. {"B: ", UINT32_C(1)},
  19. {"Y: ", UINT32_C(24)},
  20. {"Z: ", UINT32_C(25)},
  21. {"AA: ", UINT32_C(26)},
  22. {"AB: ", UINT32_C(27)},
  23. {"AZ: ", UINT32_C(51)},
  24. {"BA: ", UINT32_C(52)},
  25. {"BB: ", UINT32_C(53)},
  26. {"QKWV: ", UINT32_C(4294967295)}, // 2^32 - 1
  27. };
  28. for(size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
  29. {
  30. g_info("fmt_session_id(%" PRIu64 ")", cases[i].session_id);
  31. /* flawfinder: ignore. bound checks are done */
  32. char got[BADWOLF_CTX_SIZ] = {0, 0, 0, 0, 0, 0, 0};
  33. fmt_session_id(cases[i].session_id, got);
  34. if(strncmp(got, cases[i].expect, BADWOLF_CTX_SIZ) != 0)
  35. {
  36. g_error("expected: \"%s\", got: \"%s\"", cases[i].expect, got);
  37. }
  38. }
  39. }
  40. int
  41. main(int argc, char *argv[])
  42. {
  43. g_test_init(&argc, &argv, NULL);
  44. g_test_add_func("/fmt_session_id/test", fmt_session_id_test);
  45. return g_test_run();
  46. }