summaryrefslogtreecommitdiff
path: root/tests/assertions.c
diff options
context:
space:
mode:
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;
+}