summaryrefslogtreecommitdiff
path: root/tests/assertions.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-01-16 10:48:17 -0600
committersanine <sanine.not@pm.me>2022-01-16 10:48:17 -0600
commit70fe832f3bfcf3fdff04772e1e9a96b4422ff2b3 (patch)
tree78ba000cb87f87ff4f6412e8862ac13d3f30ce07 /tests/assertions.c
parent342f577c24439977985e2de89fe512e504489735 (diff)
add tests for lily_assert_null and lily_assert_ptr_equal
Diffstat (limited to 'tests/assertions.c')
-rw-r--r--tests/assertions.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/assertions.c b/tests/assertions.c
index d1ba141..b19e9b3 100644
--- a/tests/assertions.c
+++ b/tests/assertions.c
@@ -135,3 +135,73 @@ const char *test_assert_not_null()
return 0;
}
+
+
+const char *test_assert_null()
+{
+ int a = 5;
+ int *ptr = NULL;
+
+ int val = setjmp(_lily_globals.env);
+ if (val != 0)
+ return "true assertion failed incorrectly!";
+
+ lily_assert_null(ptr);
+
+ int passed_thru = 0;
+ _lily_globals.error_msg = NULL;
+ _lily_globals.error_location = "";
+ val = setjmp(_lily_globals.env);
+
+ if (passed_thru == 0) {
+ passed_thru = 1;
+ lily_assert_null(&a);
+ return "false assertion incorrectly succeeded!";
+ }
+ else {
+ char buf[256];
+ sprintf(buf, "&a (%p) is not NULL", &a);
+ if (strcmp(_lily_globals.error_msg, buf) != 0)
+ return "false assertion produced incorrect error message!";
+ if (strcmp(_lily_globals.error_location, "tests/assertions.c:158") != 0)
+ return "false assertion produced incorrect error location!";
+ }
+
+ return 0;
+}
+
+
+const char *test_assert_ptr_equal()
+{
+ int a = 0;
+ int b = 0;
+ int *ptr = &a;
+
+ int val = setjmp(_lily_globals.env);
+ if (val != 0)
+ return "true assertion failed incorrectly!";
+
+ lily_assert_ptr_equal(&a, ptr);
+
+ int passed_thru = 0;
+ _lily_globals.error_msg = NULL;
+ _lily_globals.error_location = "";
+ val = setjmp(_lily_globals.env);
+ ptr = &b;
+
+ if (passed_thru == 0) {
+ passed_thru = 1;
+ lily_assert_ptr_equal(&a, ptr);
+ return "false assertion incorrectly succeeded!";
+ }
+ else {
+ char buf[256];
+ sprintf(buf, "&a (%p) is not equal to ptr (%p)", &a, &b);
+ if (strcmp(_lily_globals.error_msg, buf) != 0)
+ return "false assertion produced incorrect error message!";
+ if (strcmp(_lily_globals.error_location, "tests/assertions.c:194") != 0)
+ return "false assertion produced incorrect error location!";
+ }
+
+ return 0;
+}