Summary Files Commits Branches @commit @diff @stats
path: root / fmt_test.c
diff options
context:
space:
mode:
Commit58af594c9d9cfe7070742ff09ef8528c11d65bef (patch)
Author
 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
2022-02-26 13:41:55 +0100
Committer
 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
2022-02-26 13:54:50 +0100
Files8afad723d41000fd849a4a76fec04cbecdecbfae /fmt_test.c
goodwolf-58af594c9d9cfe7070742ff09ef8528c11d65bef.tar
goodwolf-58af594c9d9cfe7070742ff09ef8528c11d65bef.tar.gz
goodwolf-58af594c9d9cfe7070742ff09ef8528c11d65bef.zip
Parenteceb1437726a1fae5280ec57bb35a8065996e21d (diff)
fmt: Grab fmt_context_id for tests
1 files changed, 56 insertions, 0 deletions
-rw-r--r--fmt_test.c56
diff --git a/fmt_test.c b/fmt_test.c
new file mode 100644
index 0000000..7f3e0a2
--- /dev/null
+++ b/fmt_test.c
@@ -0,0 +1,56 @@
+// BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser
+// Copyright © 2019-2021 Badwolf Authors <https://hacktivis.me/projects/badwolf>
+// SPDX-License-Identifier: BSD-3-Clause
+
+#include "fmt.h"
+
+#include <glib.h>
+
+static void
+fmt_context_id_test(void)
+{
+ struct
+ {
+ const char *expect;
+ uint64_t context_id;
+ } cases[] = {
+ //
+ {"A: ", 0},
+ {"B: ", 1},
+ {"Y: ", 24},
+ {"Z: ", 25},
+ {"AA: ", 26},
+ {"AB: ", 27},
+ {"AZ: ", 51},
+ {"BA: ", 52},
+ {"BB: ", 53},
+ {"QKWW: ", 4294967296}, // 2^32
+ {"JFHI: ", 9223372036854775808}, // 2^63
+ {"TLPO: ", 18446744073709551614}, // 2^64 -2
+ {"TLPP: ", 18446744073709551615}, // 2^64 -1 (aka UINT64_MAX)
+ };
+
+ for(size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
+ {
+ g_info("fmt_context_id(%lu)", cases[i].context_id);
+ /* flawfinder: ignore. bound checks are done */
+ char got[BADWOLF_CTX_SIZ] = {0, 0, 0, 0, 0, 0, 0};
+
+ fmt_context_id(cases[i].context_id, got);
+
+ if(strncmp(got, cases[i].expect, BADWOLF_CTX_SIZ) != 0)
+ {
+ g_error("expected: \"%s\", got: \"%s\"", cases[i].expect, got);
+ }
+ }
+}
+
+int
+main(int argc, char *argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/fmt_context_id/test", fmt_context_id_test);
+
+ return g_test_run();
+}