From f60a72b5b4fcde57736286350a7fdcf1d3698332 Mon Sep 17 00:00:00 2001 From: Dotsenko Andrey Date: Sat, 10 Dec 2016 22:31:38 +0300 Subject: [PATCH] Add tests for ck_assert_pstr_* macros --- tests/check_check_master.c | 4 +++ tests/check_check_sub.c | 52 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/tests/check_check_master.c b/tests/check_check_master.c index 3373a4b..5ac5f8c 100644 --- a/tests/check_check_master.c +++ b/tests/check_check_master.c @@ -224,6 +224,10 @@ static master_test_t master_tests[] = { { "Simple Tests", "test_ck_assert_str_ge", CK_FAILURE, "Assertion 's >= t' failed: s == \"test1\", t == \"test2\"" }, { "Simple Tests", "test_ck_assert_str_ge_with_null", CK_FAILURE, "Assertion 's >= t' failed: s == (null), t == (null)" }, { "Simple Tests", "test_ck_assert_str_expr", CK_PASS, "Passed" }, + { "Simple Tests", "test_ck_assert_pstr_eq", CK_FAILURE, "Assertion '\"test1\" == s' failed: \"test1\" == \"test1\", s == \"test\"" }, + { "Simple Tests", "test_ck_assert_pstr_eq_with_null", CK_FAILURE, "Assertion 't == s' failed: t == \"test\", s == (null)" }, + { "Simple Tests", "test_ck_assert_pstr_ne", CK_FAILURE, "Assertion 't != s' failed: t == \"test2\", s == \"test2\"" }, + { "Simple Tests", "test_ck_assert_pstr_ne_with_null", CK_FAILURE, "Assertion 't != s' failed: t == (null), s == (null)" }, { "Simple Tests", "test_ck_assert_ptr_eq", CK_FAILURE, "Assertion 'x == y' failed: x == 0x1, y == 0x2" }, { "Simple Tests", "test_ck_assert_ptr_ne", CK_FAILURE, "Assertion 'x != z' failed: x == 0x1, z == 0x1" }, { "Simple Tests", "test_ck_assert_mem_eq", CK_FAILURE, "Assertion '\"\\x00\\x00\\x00\\x00\\x01\" == s' failed: \"\\x00\\x00\\x00\\x00\\x01\" == \"0000000001\", s == \"0000000002\"" }, diff --git a/tests/check_check_sub.c b/tests/check_check_sub.c index 6c81bd7..77de05a 100644 --- a/tests/check_check_sub.c +++ b/tests/check_check_sub.c @@ -2057,6 +2057,54 @@ START_TEST(test_ck_assert_str_expr) } END_TEST +START_TEST(test_ck_assert_pstr_eq) +{ + record_test_name(tcase_name()); + + const char *s = "test"; + ck_assert_pstr_eq("test", s); + ck_assert_pstr_eq(NULL, NULL); + record_failure_line_num(__LINE__); + ck_assert_pstr_eq("test1", s); +} +END_TEST + +START_TEST(test_ck_assert_pstr_eq_with_null) +{ + record_test_name(tcase_name()); + + const char *t = "test"; + const char *s = NULL; + record_failure_line_num(__LINE__); + ck_assert_pstr_eq(t, s); +} +END_TEST + +START_TEST(test_ck_assert_pstr_ne) +{ + record_test_name(tcase_name()); + + const char *t = "test1"; + const char *s = "test2"; + ck_assert_pstr_ne(t, s); + ck_assert_pstr_ne(t, NULL); + t = "test2"; + record_failure_line_num(__LINE__); + ck_assert_pstr_ne(t, s); +} +END_TEST + +START_TEST(test_ck_assert_pstr_ne_with_null) +{ + record_test_name(tcase_name()); + + const char *s = NULL; + const char *t = NULL; + record_failure_line_num(__LINE__); + ck_assert_pstr_ne(t, s); +} +END_TEST + START_TEST(test_ck_assert_ptr_eq) { int * x = (int*)0x1; @@ -2863,6 +2911,10 @@ Suite *make_sub_suite(void) tcase_add_test (tc_simple, test_ck_assert_str_ge); tcase_add_test (tc_simple, test_ck_assert_str_ge_with_null); tcase_add_test (tc_simple, test_ck_assert_str_expr); + tcase_add_test (tc_simple, test_ck_assert_pstr_eq); + tcase_add_test (tc_simple, test_ck_assert_pstr_eq_with_null); + tcase_add_test (tc_simple, test_ck_assert_pstr_ne); + tcase_add_test (tc_simple, test_ck_assert_pstr_ne_with_null); tcase_add_test (tc_simple, test_ck_assert_ptr_eq); tcase_add_test (tc_simple, test_ck_assert_ptr_ne); tcase_add_test (tc_simple, test_ck_assert_mem_eq); -- 2.40.0