In development.
-* Documented new Check API and fixed macros to allow multiple
- evaluation.
+* Improvements to the new Check API: documentation, macros that allow
+ multiple evaluation, unit tests, and new
+ ck_assert_(str|int)_(lt|le|gt|ge) comparison functions.
* Added checkmk, a tool for reducing "boilerplate coding" when writing
unit tests with check.
@node Convenience Test Functions, Running Multiple Cases, Advanced Features, Advanced Features
@section Convenience Test Functions
-Using the @code{fail_unless} function for all tests can lead to lot of repetitive
-code that is hard to read. For your convenience Check provides a set of functions
-(actually macros) for testing often used conditions.
+Using the @code{fail_unless} function for all tests can lead to lot of
+repetitive code that is hard to read. For your convenience Check
+provides a set of functions (actually macros) for testing often used
+conditions.
-@table @code
-@vindex ck_abort
+@ftable @code
@item ck_abort
Unconditionally fails test with default message.
-@vindex ck_abort_msg
@item ck_abort_msg
Unconditionally fails test with user supplied message.
-@vindex ck_assert
@item ck_assert
-Fails test if supplied condition evaluates to true. This function is equivalent to
-@code{fail_unless} with @code{NULL} as a message.
+Fails test if supplied condition evaluates to true. This function is
+equivalent to @code{fail_unless} with @code{NULL} as a message.
-@vindex ck_assert_msg
@item ck_assert_msg
-Fails test if supplied condition evaluates to true and displays user provided
-message. This function is equivalent to @code{fail_unless}.
+Fails test if supplied condition evaluates to true and displays user
+provided message. This function is equivalent to @code{fail_unless}.
-@vindex ck_assert_int_eq
@item ck_assert_int_eq
-Takes two integer values, compares them for equality and fails test if values
-are not equal. Uses predefined message displaying failed condition and values of
-both input parameters.
-
-@vindex ck_assert_int_ne
-@item ck_assert_int_ne
-Same as @code{ck_assert_int_eq} but fails if the values are equal.
+@itemx ck_assert_int_ne
+@itemx ck_assert_int_lt
+@itemx ck_assert_int_le
+@itemx ck_assert_int_gt
+@itemx ck_assert_int_ge
+
+Compares two @code{int} values 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},
+@code{ne}, @code{lt}, @code{le}, @code{gt}, and @code{ge} correspond to
+@code{==}, @code{!=}, @code{<}, @code{<=}, @code{>}, and @code{>=}
+respectively.
-@vindex ck_assert_str_eq
@item ck_assert_str_eq
-Same as @code{ck_assert_int_eq} but takes @code{char*} values and compares
-them using the @code{strcmp()} function.
-
-@vindex ck_assert_str_eq
-@item ck_assert_str_eq
-Same as @code{ck_assert_int_ne} but takes @code{char*} values and compares
-them using the @code{strcmp()} function.
-@end table
+@itemx ck_assert_str_ne
+@itemx ck_assert_str_lt
+@itemx ck_assert_str_le
+@itemx ck_assert_str_gt
+@itemx ck_assert_str_ge
+
+Compares two null-terminated @code{char *} string values, using the
+@code{strcmp()} function internally, and displays predefined message
+with condition and input parameter values on failure. The comparison
+operator is again indicated by last two letters of the function name.
+@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}.
+
+@end ftable
@node Running Multiple Cases, No Fork Mode, Convenience Test Functions, Advanced Features
@section Running Multiple Cases
} while (0)
#define ck_assert_int_eq(X, Y) _ck_assert_int(X, ==, Y)
#define ck_assert_int_ne(X, Y) _ck_assert_int(X, !=, Y)
+#define ck_assert_int_lt(X, Y) _ck_assert_int(X, <, Y)
+#define ck_assert_int_le(X, Y) _ck_assert_int(X, <=, Y)
+#define ck_assert_int_gt(X, Y) _ck_assert_int(X, >, Y)
+#define ck_assert_int_ge(X, Y) _ck_assert_int(X, >=, Y)
/* String comparsion macros with improved output compared to fail_unless() */
/* OP might be any operator that can be used in '0 OP strcmp(X,Y)' comparison */
} while (0)
#define ck_assert_str_eq(X, Y) _ck_assert_str(X, ==, Y)
#define ck_assert_str_ne(X, Y) _ck_assert_str(X, !=, Y)
+#define ck_assert_str_lt(X, Y) _ck_assert_str(X, <, Y)
+#define ck_assert_str_le(X, Y) _ck_assert_str(X, <=, Y)
+#define ck_assert_str_gt(X, Y) _ck_assert_str(X, >, Y)
+#define ck_assert_str_ge(X, Y) _ck_assert_str(X, >=, Y)
/* Mark the last point reached in a unit test
{ "Simple Tests", CK_FAILURE, "Assertion '0' failed" },
{ "Simple Tests", CK_FAILURE, "Assertion 'x==y' failed: x==3, y==4" },
{ "Simple Tests", CK_FAILURE, "Assertion 'x!=y' failed: x==3, y==3" },
- { "Simple Tests", CK_PASS, "Passed" },
+ { "Simple Tests", CK_FAILURE, "Assertion 'x<x' failed: x==2, x==2" },
+ { "Simple Tests", CK_FAILURE, "Assertion 'y<=x' failed: y==3, x==2" },
+ { "Simple Tests", CK_FAILURE, "Assertion 'y>y' failed: y==3, y==3" },
+ { "Simple Tests", CK_FAILURE, "Assertion 'x>=y' failed: x==2, y==3" },
{ "Simple Tests", CK_PASS, "Passed" },
{ "Simple Tests", CK_FAILURE, "Assertion '\"test1\"==s' failed: \"test1\"==\"test1\", s==\"test2\"" },
{ "Simple Tests", CK_FAILURE, "Assertion 't!=s' failed: t==\"test2\", s==\"test2\"" },
+ { "Simple Tests", CK_FAILURE, "Assertion 's<s' failed: s==\"test1\", s==\"test1\"" },
+ { "Simple Tests", CK_FAILURE, "Assertion 't<=s' failed: t==\"test2\", s==\"test1\"" },
+ { "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" },
{ "Signal Tests", CK_ERROR, signal_11_str },
}
END_TEST
+/* These ck_assert tests are all designed to fail on the last
+ assertion. */
+
START_TEST(test_ck_assert)
{
int x = 3;
}
END_TEST
+START_TEST(test_ck_assert_int_lt)
+{
+ int x = 2;
+ int y = 3;
+ ck_assert_int_lt(x, y);
+ ck_assert_int_lt(x, x);
+ #define LINENO_ck_assert_int_lt _STR(__LINE__)
+}
+END_TEST
+
+START_TEST(test_ck_assert_int_le)
+{
+ int x = 2;
+ int y = 3;
+ ck_assert_int_le(x, y);
+ ck_assert_int_le(x, x);
+ ck_assert_int_le(y, x);
+ #define LINENO_ck_assert_int_le _STR(__LINE__)
+}
+END_TEST
+
+START_TEST(test_ck_assert_int_gt)
+{
+ int x = 2;
+ int y = 3;
+ ck_assert_int_gt(y, x);
+ ck_assert_int_gt(y, y);
+ #define LINENO_ck_assert_int_gt _STR(__LINE__)
+}
+END_TEST
+
+START_TEST(test_ck_assert_int_ge)
+{
+ int x = 2;
+ int y = 3;
+ ck_assert_int_ge(y, x);
+ ck_assert_int_ge(y, x);
+ ck_assert_int_ge(x, y);
+ #define LINENO_ck_assert_int_ge _STR(__LINE__)
+}
+END_TEST
+
START_TEST(test_ck_assert_int_expr)
{
int x = 1;
#define LINENO_ck_assert_int_expr _STR(__LINE__)
} END_TEST
-START_TEST(test_ck_assert_str)
-{
- _ck_assert_str("test1", < ,"test2");
- _ck_assert_str("test2", > ,"test1");
-
- _ck_assert_str("test1", <= ,"test2");
- _ck_assert_str("test2", >= ,"test1");
-
- _ck_assert_str("test1", <= ,"test1");
- _ck_assert_str("test1", >= ,"test1");
- #define LINENO_ck_assert_str _STR(__LINE__)
-}
-END_TEST
-
START_TEST(test_ck_assert_str_eq)
{
const char *s = "test2";
}
END_TEST
+START_TEST(test_ck_assert_str_lt)
+{
+ const char *s = "test1";
+ const char *t = "test2";
+ ck_assert_str_lt(s, t);
+ ck_assert_str_lt(s, s);
+ #define LINENO_ck_assert_str_lt _STR(__LINE__)
+}
+END_TEST
+
+START_TEST(test_ck_assert_str_le)
+{
+ const char *s = "test1";
+ const char *t = "test2";
+ ck_assert_str_le(s, t);
+ ck_assert_str_le(s, s);
+ ck_assert_str_le(t, s);
+ #define LINENO_ck_assert_str_le _STR(__LINE__)
+}
+END_TEST
+
+START_TEST(test_ck_assert_str_gt)
+{
+ const char *s = "test1";
+ const char *t = "test2";
+ ck_assert_str_gt(t, s);
+ ck_assert_str_gt(t, t);
+ #define LINENO_ck_assert_str_gt _STR(__LINE__)
+}
+END_TEST
+
+START_TEST(test_ck_assert_str_ge)
+{
+ const char *s = "test1";
+ const char *t = "test2";
+ ck_assert_str_ge(t, s);
+ ck_assert_str_ge(t, t);
+ ck_assert_str_ge(s, t);
+ #define LINENO_ck_assert_str_ge _STR(__LINE__)
+}
+END_TEST
+
START_TEST(test_ck_assert_str_expr)
{
const char *s = "test1";
LINENO_ck_assert_null,
LINENO_ck_assert_int_eq,
LINENO_ck_assert_int_ne,
+ LINENO_ck_assert_int_lt,
+ LINENO_ck_assert_int_le,
+ LINENO_ck_assert_int_gt,
+ LINENO_ck_assert_int_ge,
LINENO_ck_assert_int_expr,
- LINENO_ck_assert_str,
LINENO_ck_assert_str_eq,
LINENO_ck_assert_str_ne,
+ LINENO_ck_assert_str_lt,
+ LINENO_ck_assert_str_le,
+ LINENO_ck_assert_str_gt,
+ LINENO_ck_assert_str_ge,
LINENO_ck_assert_str_expr,
/* Signal Tests */
tcase_add_test (tc_simple, test_ck_assert_null);
tcase_add_test (tc_simple, test_ck_assert_int_eq);
tcase_add_test (tc_simple, test_ck_assert_int_ne);
+ tcase_add_test (tc_simple, test_ck_assert_int_lt);
+ tcase_add_test (tc_simple, test_ck_assert_int_le);
+ tcase_add_test (tc_simple, test_ck_assert_int_gt);
+ tcase_add_test (tc_simple, test_ck_assert_int_ge);
tcase_add_test (tc_simple, test_ck_assert_int_expr);
- tcase_add_test (tc_simple, test_ck_assert_str);
tcase_add_test (tc_simple, test_ck_assert_str_eq);
tcase_add_test (tc_simple, test_ck_assert_str_ne);
+ tcase_add_test (tc_simple, test_ck_assert_str_lt);
+ tcase_add_test (tc_simple, test_ck_assert_str_le);
+ 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_signal, test_segv);