fmt_test.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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> // PRIu64
  7. #include <stdint.h> // UINT64_C
  8. static void
  9. fmt_context_id_test(void)
  10. {
  11. struct
  12. {
  13. const char *expect;
  14. uint64_t context_id;
  15. } cases[] = {
  16. //
  17. {"A: ", UINT64_C(0)},
  18. {"B: ", UINT64_C(1)},
  19. {"Y: ", UINT64_C(24)},
  20. {"Z: ", UINT64_C(25)},
  21. {"AA: ", UINT64_C(26)},
  22. {"AB: ", UINT64_C(27)},
  23. {"AZ: ", UINT64_C(51)},
  24. {"BA: ", UINT64_C(52)},
  25. {"BB: ", UINT64_C(53)},
  26. {"QKWW: ", UINT64_C(4294967296)}, // 2^32
  27. {"JFHI: ", UINT64_C(9223372036854775808)}, // 2^63
  28. {"TLPO: ", UINT64_C(18446744073709551614)}, // 2^64 -2
  29. {"TLPP: ", UINT64_C(18446744073709551615)}, // 2^64 -1 (aka UINT64_MAX)
  30. };
  31. for(size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
  32. {
  33. g_info("fmt_context_id(%" PRIu64 ")", cases[i].context_id);
  34. /* flawfinder: ignore. bound checks are done */
  35. char got[BADWOLF_CTX_SIZ] = {0, 0, 0, 0, 0, 0, 0};
  36. fmt_context_id(cases[i].context_id, got);
  37. if(strncmp(got, cases[i].expect, BADWOLF_CTX_SIZ) != 0)
  38. {
  39. g_error("expected: \"%s\", got: \"%s\"", cases[i].expect, got);
  40. }
  41. }
  42. }
  43. int
  44. main(int argc, char *argv[])
  45. {
  46. g_test_init(&argc, &argv, NULL);
  47. g_test_add_func("/fmt_context_id/test", fmt_context_id_test);
  48. return g_test_run();
  49. }