aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMosder <xmosder12@gmail.com>2026-07-31 18:51:21 +0200
committerMosder <xmosder12@gmail.com>2026-07-31 18:51:21 +0200
commit08389a6d306570fc4575988e62a8397a5ff49bee (patch)
treef52e537a17f9707cdb28116b1b72f9188ef7343c /tests
parent4f4466155b6d9b5259ccd956551a675ad693e773 (diff)
feat: created tester
Diffstat (limited to 'tests')
-rw-r--r--tests/main.c3
-rw-r--r--tests/mem/alloc_tests.c37
-rw-r--r--tests/mem/alloc_tests.h3
-rw-r--r--tests/tests.c13
4 files changed, 53 insertions, 3 deletions
diff --git a/tests/main.c b/tests/main.c
deleted file mode 100644
index 9b6bdc2..0000000
--- a/tests/main.c
+++ /dev/null
@@ -1,3 +0,0 @@
-int main(void) {
- return 0;
-}
diff --git a/tests/mem/alloc_tests.c b/tests/mem/alloc_tests.c
new file mode 100644
index 0000000..6eb2e9c
--- /dev/null
+++ b/tests/mem/alloc_tests.c
@@ -0,0 +1,37 @@
+#include "alloc_tests.h"
+
+#include <limits.h>
+#include <moslib/mem/alloc.h>
+#include <stdlib.h>
+
+Test malloc_exit() {
+ safe_malloc(ULLONG_MAX);
+}
+
+Test test_safe_malloc() {
+ void *p = safe_malloc(1024);
+ test_assert(p != NULL, "Should be able to malloc 1KiB");
+ test_assert_exit(malloc_exit, EXIT_FAILURE);
+}
+
+Test realloc_exit() {
+ void *p = NULL;
+ safe_realloc(p, ULLONG_MAX);
+}
+
+Test test_safe_realloc() {
+ void *p = NULL;
+ p = safe_realloc(p, 1024);
+ test_assert(p != NULL, "Should be able to realloc NULL to 1KiB");
+
+ p = safe_realloc(p, 4096);
+ test_assert(p != NULL, "Should be able to realloc 1KiB to 4KiB");
+
+ test_assert_exit(realloc_exit, EXIT_FAILURE);
+}
+
+void mem_alloc_tests(Tester *tester) {
+ TestGroup *group = add_test_group(tester, "moslib/mem/alloc.h");
+ add_test(group, test_safe_malloc);
+ add_test(group, test_safe_realloc);
+}
diff --git a/tests/mem/alloc_tests.h b/tests/mem/alloc_tests.h
new file mode 100644
index 0000000..aaf70a4
--- /dev/null
+++ b/tests/mem/alloc_tests.h
@@ -0,0 +1,3 @@
+#include <moslib/tester.h>
+
+extern void mem_alloc_tests(Tester *tester);
diff --git a/tests/tests.c b/tests/tests.c
new file mode 100644
index 0000000..63e84ca
--- /dev/null
+++ b/tests/tests.c
@@ -0,0 +1,13 @@
+#include <moslib/tester.h>
+
+#include "mem/alloc_tests.h"
+
+int main(void) {
+ Tester *tester = new_tester();
+
+ mem_alloc_tests(tester);
+
+ run_tests(tester);
+ free_tester(tester);
+ return 0;
+}