summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib.c39
-rw-r--r--tests/lib.h8
-rw-r--r--tests/main.c2
3 files changed, 49 insertions, 0 deletions
diff --git a/tests/lib.c b/tests/lib.c
new file mode 100644
index 0000000..f194abc
--- /dev/null
+++ b/tests/lib.c
@@ -0,0 +1,39 @@
+#include <al/test.h>
+
+static bool lib_test_add_wrap(void)
+{
+ AL_TEST_START("lib_add_wrap");
+
+ u32 x = UINT32_MAX - 5;
+ x = al_u32_add_wrap(x, 15);
+ AL_TEST_EQ(x, 10, u32);
+
+ x = UINT32_MAX;
+ x = al_u32_add_wrap(x, 1);
+ AL_TEST_EQ(x, 1, u32);
+
+ x = UINT32_MAX - 25;
+ x = al_u32_add_wrap(x, 20);
+ AL_TEST_EQ(x, UINT32_MAX - 5, u32);
+ x = al_u32_add_wrap(x, 6);
+ AL_TEST_EQ(x, 1, u32);
+
+ u16 y = UINT16_MAX - 5;
+ y = al_u16_add_wrap(y, 15);
+ AL_TEST_EQ(y, 10, u16);
+
+ y = UINT16_MAX;
+ y = al_u16_add_wrap(y, 1);
+ AL_TEST_EQ(y, 1, u16);
+
+ AL_TEST_END();
+}
+
+bool lib_tests_run(void)
+{
+ AL_TEST_START_GROUP("lib");
+
+ AL_TEST_RUN(lib_test_add_wrap);
+
+ AL_TEST_END_GROUP();
+}
diff --git a/tests/lib.h b/tests/lib.h
new file mode 100644
index 0000000..bdb6efc
--- /dev/null
+++ b/tests/lib.h
@@ -0,0 +1,8 @@
+#ifndef _AL_LIB_TESTS_H
+#define _AL_LIB_TESTS_H
+
+#include <al/types.h>
+
+bool lib_tests_run(void);
+
+#endif // _AL_LIB_TESTS_H
diff --git a/tests/main.c b/tests/main.c
index 2d50d72..1c8afe2 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -1,5 +1,6 @@
#include <al/lib.h>
+#include "lib.h"
#include "array.h"
#ifdef AL_HAVE_GNU_EXTENSIONS
#include "array_typed.h"
@@ -9,6 +10,7 @@
s32 main(void)
{
+ if (!lib_tests_run()) goto fail;
if (!array_tests_run()) goto fail;
#ifdef AL_HAVE_GNU_EXTENSIONS
if (!array_typed_tests_run()) goto fail;