summaryrefslogtreecommitdiff
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
parent342f577c24439977985e2de89fe512e504489735 (diff)
add tests for lily_assert_null and lily_assert_ptr_equal
-rw-r--r--tests/assertions.c70
-rw-r--r--tests/main.c2
-rw-r--r--tests/tests.h2
3 files changed, 74 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;
+}
diff --git a/tests/main.c b/tests/main.c
index 32c6944..6aaf1ed 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -15,6 +15,8 @@ int main()
run_test(test_assert_true);
run_test(test_assert_false);
run_test(test_assert_not_null);
+ run_test(test_assert_null);
+ run_test(test_assert_ptr_equal);
return 0;
}
diff --git a/tests/tests.h b/tests/tests.h
index 46cfb2e..970d360 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -12,4 +12,6 @@ const char* test_assert_msg();
const char* test_assert_true();
const char* test_assert_false();
const char* test_assert_not_null();
+const char* test_assert_null();
+const char* test_assert_ptr_equal();
#endif