* Fix implementation of unsettenv in check's libcompat for systems that do
not provide it.
+* Improvements to the new Check API: new comparison functions for pointers:
+ ck_assert_ptr_(eq|ne).
+
Mon, Oct 22, 2012: Released Check 0.9.9
based on r637 (2012-10-22 13:54:14 +0200)
@code{ck_assert_str_lt(a, b)} will pass if the unsigned numerical value
of the character string @code{a} is less than that of @code{b}.
+@item ck_assert_ptr_eq
+@itemx ck_assert_ptr_ne
+
+Compares two pointers and displays predefined message with
+condition and values of both input parameters on failure. The operator
+used for comparison is different for each function and is indicated by
+the last two letters of the function name. The abbreviations @code{eq} and
+@code{ne} correspond to @code{==} and @code{!=} respectively.
+
@end ftable
@node Running Multiple Cases, No Fork Mode, Convenience Test Functions, Advanced Features
ck_assert_str_le
ck_assert_str_gt
ck_assert_str_ge
-
+ Check the relationship between two pointers:
+ ck_assert_ptr_eq
+ ck_assert_ptr_ne
Test cases are created with tcase_create, unit tests are added
with tcase_add_test
#define ck_assert_str_gt(X, Y) _ck_assert_str(X, >, Y)
#define ck_assert_str_ge(X, Y) _ck_assert_str(X, >=, Y)
+/* Pointer comparsion macros with improved output compared to ck_assert(). */
+/* OP may only be == or != */
+#define _ck_assert_ptr(X, OP, Y) do { \
+ void* _ck_x = (X); \
+ void* _ck_y = (Y); \
+ ck_assert_msg(_ck_x OP _ck_y, "Assertion '"#X#OP#Y"' failed: "#X"==%p, "#Y"==%p", _ck_x, _ck_y); \
+} while (0)
+#define ck_assert_ptr_eq(X, Y) _ck_assert_ptr(X, ==, Y)
+#define ck_assert_ptr_ne(X, Y) _ck_assert_ptr(X, !=, Y)
/* Mark the last point reached in a unit test
(useful for tracking down where a segfault, etc. occurs)
{ "Simple Tests", CK_FAILURE, "Assertion 't>t' failed: t==\"test2\", t==\"test2\"" },
{ "Simple Tests", CK_FAILURE, "Assertion 's>=t' failed: s==\"test1\", t==\"test2\"" },
{ "Simple Tests", CK_PASS, "Passed" },
-
+ { "Simple Tests", CK_FAILURE, "Assertion 'x==y' failed: x==0x1, y==0x2" },
+ { "Simple Tests", CK_FAILURE, "Assertion 'x!=z' failed: x==0x1, z==0x1" },
+
{ "Signal Tests", CK_ERROR, signal_11_str },
{ "Signal Tests", CK_PASS, "Passed" },
{ "Signal Tests", CK_ERROR, signal_11_8_str },
}
END_TEST
+START_TEST(test_ck_assert_ptr_eq)
+{
+ int * x = (int*)0x1;
+ int * y = (int*)0x2;
+ ck_assert_ptr_eq(NULL, NULL);
+ ck_assert_ptr_eq(x, x);
+ ck_assert_ptr_eq(x, y);
+ #define LINENO_ck_assert_ptr_eq _STR(__LINE__)
+}
+END_TEST
+
+START_TEST(test_ck_assert_ptr_ne)
+{
+ int * x = (int*)0x1;
+ int * y = (int*)0x2;
+ int * z = x;
+ ck_assert_ptr_ne(x, y);
+ ck_assert_ptr_ne(x, NULL);
+ ck_assert_ptr_ne(NULL, y);
+ ck_assert_ptr_ne(x, z);
+ #define LINENO_ck_assert_ptr_ne _STR(__LINE__)
+}
+END_TEST
+
START_TEST(test_segv)
#define LINENO_segv _STR(__LINE__)
{
LINENO_ck_assert_str_gt,
LINENO_ck_assert_str_ge,
LINENO_ck_assert_str_expr,
+ LINENO_ck_assert_ptr_eq,
+ LINENO_ck_assert_ptr_ne,
/* Signal Tests */
"-1",
tcase_add_test (tc_simple, test_ck_assert_str_gt);
tcase_add_test (tc_simple, test_ck_assert_str_ge);
tcase_add_test (tc_simple, test_ck_assert_str_expr);
+ tcase_add_test (tc_simple, test_ck_assert_ptr_eq);
+ tcase_add_test (tc_simple, test_ck_assert_ptr_ne);
tcase_add_test (tc_signal, test_segv);
tcase_add_test_raise_signal (tc_signal, test_segv, 11); /* pass */