From 42a3d1a62d293a85f1855846fa1a64adcc60d6a9 Mon Sep 17 00:00:00 2001 From: Dotsenko Andrey Date: Thu, 15 Dec 2016 21:47:57 +0300 Subject: [PATCH] Add tests for ck_assert_float_nonnan, ck_assert_double_nonnan and ck_assert_ldouble_nonnan macros --- tests/check_check_master.c | 15 +++++++++++++ tests/check_check_sub.c | 45 ++++++++++++++++++++++++++++++-------- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/tests/check_check_master.c b/tests/check_check_master.c index 28eac6b..42e1ff5 100644 --- a/tests/check_check_master.c +++ b/tests/check_check_master.c @@ -149,8 +149,13 @@ static master_test_t master_tests[] = { { "Simple Tests", "test_ck_assert_float_infinite_with_mod", CK_FAILURE, CK_MSG_TEXT, "Assertion '2%d is infinite' failed: 2%d == 0" }, { "Simple Tests", "test_ck_assert_float_nan", CK_FAILURE, CK_MSG_TEXT, "Assertion 'x is NaN' failed: x == inf" }, { "Simple Tests", "test_ck_assert_float_nan_with_mod", CK_FAILURE, CK_MSG_TEXT, "Assertion '2%d is NaN' failed: 2%d == 0" }, +#if ENABLE_REGEX + { "Simple Tests", "test_ck_assert_float_nonnan", CK_FAILURE, CK_MSG_REGEXP, "^Assertion 'x is not NaN' failed: x == -?nan$" }, + { "Simple Tests", "test_ck_assert_float_nonnan_with_mod", CK_FAILURE, CK_MSG_REGEXP, "^Assertion '\\(2%s\\)\\*x is not NaN' failed: \\(2%s\\)\\*x == -?nan$" }, +#else { "Simple Tests", "test_ck_assert_float_nonnan", CK_PASS, CK_MSG_TEXT, "Passed" }, { "Simple Tests", "test_ck_assert_float_nonnan_with_mod", CK_PASS, CK_MSG_TEXT, "Passed" }, +#endif { "Simple Tests", "test_ck_assert_float_nan_and_inf_with_expr", CK_PASS, CK_MSG_TEXT, "Passed" }, /* End of tests on float macros */ /* Tests on double macros */ @@ -184,8 +189,13 @@ static master_test_t master_tests[] = { { "Simple Tests", "test_ck_assert_double_infinite_with_mod", CK_FAILURE, CK_MSG_TEXT, "Assertion '2%d is infinite' failed: 2%d == 0" }, { "Simple Tests", "test_ck_assert_double_nan", CK_FAILURE, CK_MSG_TEXT, "Assertion 'x is NaN' failed: x == inf" }, { "Simple Tests", "test_ck_assert_double_nan_with_mod", CK_FAILURE, CK_MSG_TEXT, "Assertion '2%d is NaN' failed: 2%d == 0" }, +#if ENABLE_REGEX + { "Simple Tests", "test_ck_assert_double_nonnan", CK_FAILURE, CK_MSG_REGEXP, "^Assertion 'x is not NaN' failed: x == -?nan$" }, + { "Simple Tests", "test_ck_assert_double_nonnan_with_mod", CK_FAILURE, CK_MSG_REGEXP, "^Assertion '\\(2%s\\)\\*x is not NaN' failed: \\(2%s\\)\\*x == -?nan$" }, +#else { "Simple Tests", "test_ck_assert_double_nonnan", CK_PASS, CK_MSG_TEXT, "Passed" }, { "Simple Tests", "test_ck_assert_double_nonnan_with_mod", CK_PASS, CK_MSG_TEXT, "Passed" }, +#endif { "Simple Tests", "test_ck_assert_double_nan_and_inf_with_expr", CK_PASS, CK_MSG_TEXT, "Passed" }, /* End of tests on double macros */ /* Tests on long double macros */ @@ -219,8 +229,13 @@ static master_test_t master_tests[] = { { "Simple Tests", "test_ck_assert_ldouble_infinite_with_mod", CK_FAILURE, CK_MSG_TEXT, "Assertion '2%d is infinite' failed: 2%d == 0" }, { "Simple Tests", "test_ck_assert_ldouble_nan", CK_FAILURE, CK_MSG_TEXT, "Assertion 'x is NaN' failed: x == inf" }, { "Simple Tests", "test_ck_assert_ldouble_nan_with_mod", CK_FAILURE, CK_MSG_TEXT, "Assertion '2%d is NaN' failed: 2%d == 0" }, +#if ENABLE_REGEX + { "Simple Tests", "test_ck_assert_ldouble_nonnan", CK_FAILURE, CK_MSG_REGEXP, "^Assertion 'x is not NaN' failed: x == -?nan$" }, + { "Simple Tests", "test_ck_assert_ldouble_nonnan_with_mod", CK_FAILURE, CK_MSG_REGEXP, "^Assertion '\\(2%s\\)\\*x is not NaN' failed: \\(2%s\\)\\*x == -?nan$" }, +#else { "Simple Tests", "test_ck_assert_ldouble_nonnan", CK_PASS, CK_MSG_TEXT, "Passed" }, { "Simple Tests", "test_ck_assert_ldouble_nonnan_with_mod", CK_PASS, CK_MSG_TEXT, "Passed" }, +#endif { "Simple Tests", "test_ck_assert_ldouble_nan_and_inf_with_expr", CK_PASS, CK_MSG_TEXT, "Passed" }, /* End of tests on long double macros */ { "Simple Tests", "test_percent_n_escaped", CK_FAILURE, CK_MSG_TEXT, "Assertion 'returnsZero(\"%n\") == 1' failed: returnsZero(\"%n\") == 0, 1 == 1" }, diff --git a/tests/check_check_sub.c b/tests/check_check_sub.c index b5aac1d..65b87d6 100644 --- a/tests/check_check_sub.c +++ b/tests/check_check_sub.c @@ -913,10 +913,14 @@ START_TEST(test_ck_assert_float_nonnan) { record_test_name(tcase_name()); - float t = 1.0f; float x = 0.0f; ck_assert_float_nonnan(x); - // TODO: test with 0.0/0.0 and platform specific output. +#if ENABLE_REGEX + float t = 1.0f; + x = 0.0f / (1.0f - t); + record_failure_line_num(__LINE__); + ck_assert_float_nonnan(x); +#endif } END_TEST @@ -926,7 +930,12 @@ START_TEST(test_ck_assert_float_nonnan_with_mod) int s = 2; ck_assert_float_nonnan(2%s); - // TODO: test with 0.0/0.0 and platform specific output. +#if ENABLE_REGEX + float t = 1.0f; + float x = 0.0f / (1.0f - t); + record_failure_line_num(__LINE__); + ck_assert_float_nonnan((2%s)*x); +#endif } END_TEST @@ -1383,10 +1392,14 @@ START_TEST(test_ck_assert_double_nonnan) { record_test_name(tcase_name()); - double t = 1; double x = 0; ck_assert_double_nonnan(x); - // TODO: test with 0.0/0.0 and platform specific output. +#if ENABLE_REGEX + double t = 1; + x = 0.0 / (1.0 - t); + record_failure_line_num(__LINE__); + ck_assert_double_nonnan(x); +#endif } END_TEST @@ -1396,7 +1409,12 @@ START_TEST(test_ck_assert_double_nonnan_with_mod) int s = 2; ck_assert_double_nonnan(2%s); - // TODO: test with 0.0/0.0 and platform specific output. +#if ENABLE_REGEX + double t = 1.0; + double x = 0.0 / (1.0 - t); + record_failure_line_num(__LINE__); + ck_assert_double_nonnan((2%s)*x); +#endif } END_TEST @@ -1855,10 +1873,14 @@ START_TEST(test_ck_assert_ldouble_nonnan) { record_test_name(tcase_name()); - long double t = 1.0l; long double x = 0.0l; ck_assert_ldouble_nonnan(x); - // TODO: test with 0.0/0.0 and platform specific output. +#if ENABLE_REGEX + long double t = 1.0l; + x = 0.0l / (1.0l - t); + record_failure_line_num(__LINE__); + ck_assert_ldouble_nonnan(x); +#endif } END_TEST @@ -1868,7 +1890,12 @@ START_TEST(test_ck_assert_ldouble_nonnan_with_mod) int s = 2; ck_assert_ldouble_nonnan(2%s); - // TODO: test with 0.0/0.0 and platform specific output. +#if ENABLE_REGEX + long double t = 1.0l; + long double x = 0.0l / (1.0l - t); + record_failure_line_num(__LINE__); + ck_assert_ldouble_nonnan((2%s)*x); +#endif } END_TEST -- 2.40.0