Check
Unit testing framework for C
check.h
Go to the documentation of this file.
1 /*-*- mode:C; -*- */
2 /*
3  * Check: a unit test framework for C
4  * Copyright (C) 2001, 2002 Arien Malec
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef CHECK_H
23 #define CHECK_H
24 
25 #include <stddef.h>
26 #include <string.h>
27 #include <math.h>
28 #include <float.h>
29 
30 #include <check_stdint.h>
31 
32 /*
33  Macros and functions starting with _ (underscore) are internal and
34  may change without notice. You have been warned!.
35 */
36 
37 
38 #ifdef __cplusplus
39 #define CK_CPPSTART extern "C" {
40 #define CK_CPPEND }
41 CK_CPPSTART
42 #endif
43 
52 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
53 #define GCC_VERSION_AT_LEAST(major, minor, patch) \
54 ((__GNUC__ > (major)) || \
55  (__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \
56  (__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patch)) )
57 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
58 #define GCC_VERSION_AT_LEAST(major, minor, patch) \
59 ((__GNUC__ > (major)) || \
60  (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
61 #else
62 #define GCC_VERSION_AT_LEAST(major, minor, patch) 0
63 #endif
64 
65 #if GCC_VERSION_AT_LEAST(2,95,3)
66 #define CK_ATTRIBUTE_UNUSED __attribute__ ((unused))
67 #define CK_ATTRIBUTE_FORMAT(a, b, c) __attribute__ ((format (a, b, c)))
68 #else
69 #define CK_ATTRIBUTE_UNUSED
70 #define CK_ATTRIBUTE_FORMAT(a, b, c)
71 #endif /* GCC 2.95 */
72 
73 #if GCC_VERSION_AT_LEAST(2,5,0)
74 #define CK_ATTRIBUTE_NORETURN __attribute__ ((noreturn))
75 #else
76 #define CK_ATTRIBUTE_NORETURN
77 #endif /* GCC 2.5 */
78 
79 #if GCC_VERSION_AT_LEAST(4,7,4) && (__STDC_VERSION__ >= 199901L)
80 /* Operator _Pragma introduced in C99 */
81 #define CK_DIAGNOSTIC_STRINGIFY(x) #x
82 #define CK_DIAGNOSTIC_HELPER1(y) CK_DIAGNOSTIC_STRINGIFY(GCC diagnostic ignored y)
83 #define CK_DIAGNOSTIC_HELPER2(z) CK_DIAGNOSTIC_HELPER1(#z)
84 #define CK_DIAGNOSTIC_PUSH_IGNORE(w) \
85  _Pragma("GCC diagnostic push") \
86  _Pragma(CK_DIAGNOSTIC_HELPER2(w))
87 #define CK_DIAGNOSTIC_POP(w) _Pragma ("GCC diagnostic pop")
88 #else
89 #define CK_DIAGNOSTIC_PUSH_IGNORE(w)
90 #define CK_DIAGNOSTIC_POP(w)
91 #endif /* GCC 4.7.4 */
92 
93 #undef GCC_VERSION_AT_LEAST
94 
95 #include <sys/types.h>
96 
97 #if defined(_MSC_VER)
98 /* define pid_t for Windows, as it is needed later */
99 #define pid_t int
100 #endif /* _MSC_VER */
101 
102 /*
103  * Used to create the linker script for hiding lib-local symbols. Shall
104  * be put directly in front of the exported symbol.
105  */
106 #define CK_EXPORT
107 
108 /*
109  * Used for MSVC to create the export attribute
110  * CK_DLL_EXP is defined during the compilation of the library
111  * on the command line.
112  *
113  * This definition is only used when building or linking to
114  * the shared library, i.e. libcheck.so. When building the library
115  * the value must be "_declspec(dllexport)".
116  * When linking with the library, the value must be "_declspec(dllimport)"
117  *
118  * This is only used with Microsoft Visual C. In other systems
119  * the value is empty. In MSVC the value is empty when linking with
120  * a static library.
121  */
122 #ifndef CK_DLL_EXP
123 #define CK_DLL_EXP
124 #endif
125 
126 /* check version numbers */
127 
128 #define CHECK_MAJOR_VERSION (0)
129 #define CHECK_MINOR_VERSION (15)
130 #define CHECK_MICRO_VERSION (2)
131 
132 CK_DLL_EXP extern int CK_EXPORT check_major_version;
133 CK_DLL_EXP extern int CK_EXPORT check_minor_version;
134 CK_DLL_EXP extern int CK_EXPORT check_micro_version;
135 
136 #ifndef NULL
137 #define NULL ((void*)0)
138 #endif
139 
147 typedef struct TCase TCase;
148 
152 typedef void (*TFun) (int);
153 
157 typedef void (*SFun) (void);
158 
162 typedef struct Suite Suite;
163 
167 typedef struct TTest {
168  const char *name;
170  const char *file;
171  int line;
172 } TTest;
173 
188 CK_DLL_EXP Suite *CK_EXPORT suite_create(const char *name);
189 
202 CK_DLL_EXP int CK_EXPORT suite_tcase(Suite * s, const char *tcname);
203 
215 CK_DLL_EXP void CK_EXPORT suite_add_tcase(Suite * s, TCase * tc);
216 
230 CK_DLL_EXP TCase *CK_EXPORT tcase_create(const char *name);
231 
243 CK_DLL_EXP void CK_EXPORT tcase_set_tags(TCase * tc,
244  const char *tags);
253 #define tcase_add_test(tc,tf) tcase_add_test_raise_signal(tc,tf,0)
254 
267 #define tcase_add_test_raise_signal(tc,ttest,signal) \
268  _tcase_add_test((tc),(ttest),(signal), 0, 0, 1)
269 
282 #define tcase_add_exit_test(tc, ttest, expected_exit_value) \
283  _tcase_add_test((tc),(ttest),0,(expected_exit_value),0,1)
284 
299 #define tcase_add_loop_test(tc,ttest,s,e) \
300  _tcase_add_test((tc),(ttest),0,0,(s),(e))
301 
320 #define tcase_add_loop_test_raise_signal(tc,ttest,signal,s,e) \
321  _tcase_add_test((tc),(ttest),(signal),0,(s),(e))
322 
341 #define tcase_add_loop_exit_test(tc,ttest,expected_exit_value,s,e) \
342  _tcase_add_test((tc),(ttest),0,(expected_exit_value),(s),(e))
343 
344 /* Add a test function to a test case
345  (function version -- use this when the macro won't work
346 */
347 CK_DLL_EXP void CK_EXPORT _tcase_add_test(TCase * tc, const TTest * ttest,
348  int _signal, int allowed_exit_value,
349  int start, int end);
350 
376 CK_DLL_EXP void CK_EXPORT tcase_add_unchecked_fixture(TCase * tc, SFun setup,
377  SFun teardown);
378 
405 CK_DLL_EXP void CK_EXPORT tcase_add_checked_fixture(TCase * tc, SFun setup,
406  SFun teardown);
407 
428 CK_DLL_EXP void CK_EXPORT tcase_set_timeout(TCase * tc, double timeout);
429 
430 /* Internal function to mark the start of a test function */
431 CK_DLL_EXP void CK_EXPORT tcase_fn_start(const char *fname, const char *file,
432  int line);
433 
442 CK_DLL_EXP const char* CK_EXPORT tcase_name(void);
443 
451 #define START_TEST(__testname)\
452 static void __testname ## _fn (int _i CK_ATTRIBUTE_UNUSED);\
453 static const TTest __testname ## _ttest = {""# __testname, __testname ## _fn, __FILE__, __LINE__};\
454 static const TTest * __testname = & __testname ## _ttest;\
455 static void __testname ## _fn (int _i CK_ATTRIBUTE_UNUSED)
456 
462 #define END_TEST
463 
464 /*
465  * Fail the test case unless expr is false
466  *
467  * This call is deprecated.
468  */
469 #define fail_unless(expr, ...) \
470  (expr) ? \
471  _mark_point(__FILE__, __LINE__) : \
472  _ck_assert_failed(__FILE__, __LINE__, "Assertion '"#expr"' failed" , ## __VA_ARGS__, NULL)
473 
474 /*
475  * Fail the test case if expr is false
476  *
477  * This call is deprecated.
478  *
479  * NOTE: The space before the comma sign before ## is essential to be compatible
480  * with gcc 2.95.3 and earlier.
481  * FIXME: these macros may conflict with C89 if expr is
482  * FIXME: strcmp (str1, str2) due to excessive string length.
483  */
484 #define fail_if(expr, ...)\
485  (expr) ? \
486  _ck_assert_failed(__FILE__, __LINE__, "Failure '"#expr"' occurred" , ## __VA_ARGS__, NULL) \
487  : _mark_point(__FILE__, __LINE__)
488 
489 /*
490  * Fail the test
491  *
492  * This call is deprecated.
493  */
494 #define fail(...) _ck_assert_failed(__FILE__, __LINE__, "Failed" , ## __VA_ARGS__, NULL)
495 
496 /*
497  * This is called whenever an assertion fails.
498  * Note that it only has the noreturn modifier when
499  * using fork. If fork is unavailable, the function
500  * calls longjmp() when a test assertion fails. Marking
501  * the function as noreturn causes gcc to make assumptions
502  * which are not valid, as longjmp() is like a return.
503  */
504 #if 1
505 CK_DLL_EXP void CK_EXPORT _ck_assert_failed(const char *file, int line,
506  const char *expr, const char *msg,
507  ...) CK_ATTRIBUTE_NORETURN CK_ATTRIBUTE_FORMAT(printf, 4, 5);
508 #else
509 CK_DLL_EXP void CK_EXPORT _ck_assert_failed(const char *file, int line,
510  const char *expr, const char *msg,
511  ...) CK_ATTRIBUTE_FORMAT(printf, 4, 5);
512 #endif
513 
523 #define ck_assert(expr) ck_assert_msg(expr, NULL)
524 
525 /* The space before the comma sign before ## is essential to be compatible
526  with gcc 2.95.3 and earlier.
527 */
538 #define ck_assert_msg(expr, ...) \
539  (expr) ? \
540  _mark_point(__FILE__, __LINE__) : \
541  _ck_assert_failed(__FILE__, __LINE__, "Assertion '"#expr"' failed" , ## __VA_ARGS__)
542 
550 #define ck_abort() ck_abort_msg(NULL)
551 
560 #define ck_abort_msg(...) _ck_assert_failed(__FILE__, __LINE__, "Failed" , ## __VA_ARGS__)
561 
562 /* Signed and unsigned integer comparison macros with improved output compared to ck_assert(). */
563 /* OP may be any comparison operator. */
564 #define _ck_assert_int(X, OP, Y) do { \
565  intmax_t _ck_x = (X); \
566  intmax_t _ck_y = (Y); \
567  ck_assert_msg(_ck_x OP _ck_y, "Assertion '%s' failed: %s == %jd, %s == %jd", #X" "#OP" "#Y, #X, _ck_x, #Y, _ck_y); \
568 } while (0)
569 
582 #define ck_assert_int_eq(X, Y) _ck_assert_int(X, ==, Y)
583 
595 #define ck_assert_int_ne(X, Y) _ck_assert_int(X, !=, Y)
596 
608 #define ck_assert_int_lt(X, Y) _ck_assert_int(X, <, Y)
609 
621 #define ck_assert_int_le(X, Y) _ck_assert_int(X, <=, Y)
622 
634 #define ck_assert_int_gt(X, Y) _ck_assert_int(X, >, Y)
635 
647 #define ck_assert_int_ge(X, Y) _ck_assert_int(X, >=, Y)
648 
649 #define _ck_assert_uint(X, OP, Y) do { \
650  uintmax_t _ck_x = (X); \
651  uintmax_t _ck_y = (Y); \
652  ck_assert_msg(_ck_x OP _ck_y, "Assertion '%s' failed: %s == %ju, %s == %ju", #X" "#OP" "#Y, #X, _ck_x, #Y, _ck_y); \
653 } while (0)
654 
666 #define ck_assert_uint_eq(X, Y) _ck_assert_uint(X, ==, Y)
667 
679 #define ck_assert_uint_ne(X, Y) _ck_assert_uint(X, !=, Y)
680 
692 #define ck_assert_uint_lt(X, Y) _ck_assert_uint(X, <, Y)
693 
705 #define ck_assert_uint_le(X, Y) _ck_assert_uint(X, <=, Y)
706 
718 #define ck_assert_uint_gt(X, Y) _ck_assert_uint(X, >, Y)
719 
731 #define ck_assert_uint_ge(X, Y) _ck_assert_uint(X, >=, Y)
732 
733 /* Number of digits after the decimal point to output via printf */
734 #ifndef CK_FLOATING_DIG
735 # define CK_FLOATING_DIG 6
736 #endif /* CK_FLOATING_DIG */
737 
738 /* Floating point number comparison macros with improved output
739  * compared to ck_assert(). */
740 /* OP may be any comparison operator, TP is type, TM is type modifier. */
741 #define _ck_assert_floating(X, OP, Y, TP, TM) do { \
742  TP _ck_x = (X); \
743  TP _ck_y = (Y); \
744  ck_assert_msg(_ck_x OP _ck_y, \
745  "Assertion '%s' failed: %s == %.*" TM "g, %s == %.*" TM "g", \
746  #X" "#OP" "#Y, \
747  #X, (int)CK_FLOATING_DIG, _ck_x, \
748  #Y, (int)CK_FLOATING_DIG, _ck_y); \
749 } while (0)
750 
751 /* Check floating point number is finise. */
752 /* TP is type, TM is type modifier. */
753 #define _ck_assert_floating_finite(X, TP, TM) \
754 do { \
755  TP _ck_x = (X); \
756  ck_assert_msg(isfinite(_ck_x), \
757  "Assertion '%s' failed: %s == %.*" TM "g", \
758  #X" is finite", \
759  #X, (int)CK_FLOATING_DIG, _ck_x); \
760 } while (0)
761 
762 /* Check floating point number is infinise. */
763 /* TP is type, TM is type modifier. */
764 #define _ck_assert_floating_infinite(X, TP, TM) \
765 do { \
766  TP _ck_x = (X); \
767  ck_assert_msg(isinf(_ck_x), \
768  "Assertion '%s' failed: %s == %.*" TM "g", \
769  #X" is infinite", \
770  #X, (int)CK_FLOATING_DIG, _ck_x); \
771 } while (0)
772 
773 /* Check floating point number is "Not a Number". */
774 /* TP is type, TM is type modifier. */
775 #define _ck_assert_floating_nan(X, TP, TM) \
776 do { \
777  TP _ck_x = (X); \
778  ck_assert_msg(isnan(_ck_x), \
779  "Assertion '%s' failed: %s == %.*" TM "g", \
780  #X" is NaN", \
781  #X, (int)CK_FLOATING_DIG, _ck_x); \
782 } while (0)
783 
784 /* Check floating point number is not "Not a Number". */
785 /* TP is type, TM is type modifier. */
786 #define _ck_assert_floating_nonnan(X, TP, TM) \
787 do { \
788  TP _ck_x = (X); \
789  ck_assert_msg(!isnan(_ck_x), \
790  "Assertion '%s' failed: %s == %.*" TM "g", \
791  #X" is not NaN", \
792  #X, (int)CK_FLOATING_DIG, _ck_x); \
793 } while (0)
794 
795 /* Floating point tolerance comparison macros with improved output
796  * compared to ck_assert(). */
797 /* OP, D can have values: >, -1; <, 1. */
798 #define _ck_assert_floating_op_tol(X, OP, Y, T, D, TP, TM) do { \
799  TP _ck_x = (X); \
800  TP _ck_y = (Y); \
801  TP _ck_t = (T); \
802  ck_assert_msg((_ck_x - _ck_y) OP _ck_t * (D), \
803  "Assertion '%s' failed: %s == %.*" TM "g, %s == %.*" TM "g, %s == %.*" TM "g", \
804  #X" "#OP"= "#Y", error < "#T, \
805  #X, (int)CK_FLOATING_DIG, _ck_x, \
806  #Y, (int)CK_FLOATING_DIG, _ck_y, \
807  #T, (int)CK_FLOATING_DIG, _ck_t); \
808 } while (0)
809 
810 /* Floating point tolerance comparison macros with improved output
811  * compared to ck_assert(). */
812 /* OP can have values: <; >=. */
813 #define _ck_assert_floating_absdiff_op_tol(X, Y, OP, T, TP, TM) \
814 do { \
815  TP _ck_x = (X); \
816  TP _ck_y = (Y); \
817  TP _ck_t = (T); \
818  ck_assert_msg(fabsl(_ck_y - _ck_x) OP _ck_t, \
819  "Assertion '%s' failed: %s == %.*" TM "g, %s == %.*" TM "g, %s == %.*" TM "g", \
820  "fabsl("#Y" - "#X") "#OP" "#T, \
821  #X, (int)CK_FLOATING_DIG, _ck_x, \
822  #Y, (int)CK_FLOATING_DIG, _ck_y, \
823  #T, (int)CK_FLOATING_DIG, _ck_t); \
824 } while (0)
825 
842 #define ck_assert_float_eq(X, Y) _ck_assert_floating(X, ==, Y, float, "")
843 
859 #define ck_assert_float_ne(X, Y) _ck_assert_floating(X, !=, Y, float, "")
860 
872 #define ck_assert_float_lt(X, Y) _ck_assert_floating(X, <, Y, float, "")
873 
885 #define ck_assert_float_le(X, Y) _ck_assert_floating(X, <=, Y, float, "")
886 
898 #define ck_assert_float_gt(X, Y) _ck_assert_floating(X, >, Y, float, "")
899 
911 #define ck_assert_float_ge(X, Y) _ck_assert_floating(X, >=, Y, float, "")
912 
927 #define ck_assert_float_eq_tol(X, Y, T) _ck_assert_floating_absdiff_op_tol(X, Y, <, T, float, "")
928 
943 #define ck_assert_float_ne_tol(X, Y, T) _ck_assert_floating_absdiff_op_tol(X, Y, >=, T, float, "")
944 
959 #define ck_assert_float_ge_tol(X, Y, T) _ck_assert_floating_op_tol(X, >, Y, T, -1, float, "")
960 
975 #define ck_assert_float_le_tol(X, Y, T) _ck_assert_floating_op_tol(X, <, Y, T, 1, float, "")
976 
989 #define ck_assert_float_finite(X) _ck_assert_floating_finite(X, float, "")
990 
1003 #define ck_assert_float_infinite(X) _ck_assert_floating_infinite(X, float, "")
1004 
1017 #define ck_assert_float_nan(X) _ck_assert_floating_nan(X, float, "")
1018 
1031 #define ck_assert_float_nonnan(X) _ck_assert_floating_nonnan(X, float, "")
1032 
1049 #define ck_assert_double_eq(X, Y) _ck_assert_floating(X, ==, Y, double, "")
1050 
1066 #define ck_assert_double_ne(X, Y) _ck_assert_floating(X, !=, Y, double, "")
1067 
1079 #define ck_assert_double_lt(X, Y) _ck_assert_floating(X, <, Y, double, "")
1080 
1092 #define ck_assert_double_le(X, Y) _ck_assert_floating(X, <=, Y, double, "")
1093 
1105 #define ck_assert_double_gt(X, Y) _ck_assert_floating(X, >, Y, double, "")
1106 
1118 #define ck_assert_double_ge(X, Y) _ck_assert_floating(X, >=, Y, double, "")
1119 
1134 #define ck_assert_double_eq_tol(X, Y, T) _ck_assert_floating_absdiff_op_tol(X, Y, <, T, double, "")
1135 
1150 #define ck_assert_double_ne_tol(X, Y, T) _ck_assert_floating_absdiff_op_tol(X, Y, >=, T, double, "")
1151 
1166 #define ck_assert_double_ge_tol(X, Y, T) _ck_assert_floating_op_tol(X, >, Y, T, -1, double, "")
1167 
1182 #define ck_assert_double_le_tol(X, Y, T) _ck_assert_floating_op_tol(X, <, Y, T, 1, double, "")
1183 
1196 #define ck_assert_double_finite(X) _ck_assert_floating_finite(X, double, "")
1197 
1210 #define ck_assert_double_infinite(X) _ck_assert_floating_infinite(X, double, "")
1211 
1224 #define ck_assert_double_nan(X) _ck_assert_floating_nan(X, double, "")
1225 
1238 #define ck_assert_double_nonnan(X) _ck_assert_floating_nonnan(X, double, "")
1239 
1256 #define ck_assert_ldouble_eq(X, Y) _ck_assert_floating(X, ==, Y, long double, "L")
1257 
1273 #define ck_assert_ldouble_ne(X, Y) _ck_assert_floating(X, !=, Y, long double, "L")
1274 
1286 #define ck_assert_ldouble_lt(X, Y) _ck_assert_floating(X, <, Y, long double, "L")
1287 
1299 #define ck_assert_ldouble_le(X, Y) _ck_assert_floating(X, <=, Y, long double, "L")
1300 
1312 #define ck_assert_ldouble_gt(X, Y) _ck_assert_floating(X, >, Y, long double, "L")
1313 
1325 #define ck_assert_ldouble_ge(X, Y) _ck_assert_floating(X, >=, Y, long double, "L")
1326 
1341 #define ck_assert_ldouble_eq_tol(X, Y, T) _ck_assert_floating_absdiff_op_tol(X, Y, <, T, long double, "L")
1342 
1357 #define ck_assert_ldouble_ne_tol(X, Y, T) _ck_assert_floating_absdiff_op_tol(X, Y, >=, T, long double, "L")
1358 
1373 #define ck_assert_ldouble_ge_tol(X, Y, T) _ck_assert_floating_op_tol(X, >, Y, T, -1, long double, "L")
1374 
1389 #define ck_assert_ldouble_le_tol(X, Y, T) _ck_assert_floating_op_tol(X, <, Y, T, 1, long double, "L")
1390 
1403 #define ck_assert_ldouble_finite(X) _ck_assert_floating_finite(X, long double, "L")
1404 
1417 #define ck_assert_ldouble_infinite(X) _ck_assert_floating_infinite(X, long double, "L")
1418 
1431 #define ck_assert_ldouble_nan(X) _ck_assert_floating_nan(X, long double, "L")
1432 
1445 #define ck_assert_ldouble_nonnan(X) _ck_assert_floating_nonnan(X, long double, "L")
1446 
1447 /* String comparison macros with improved output compared to ck_assert() */
1448 /* OP might be any operator that can be used in '0 OP strcmp(X,Y)' comparison. */
1449 /* String pointer could be compared againts NULL with == (NULLEQ = 1) and != (NULLNE = 1) operators. */
1450 /* The x and y parameter swap in strcmp() is needed to handle >, >=, <, <= operators. */
1451 /* If the x or y parameter is NULL its value will be printed without quotes. */
1452 #define _ck_assert_str(X, OP, Y, NULLEQ, NULLNE) do { \
1453  const char* _ck_x = (X); \
1454  const char* _ck_y = (Y); \
1455  const char* _ck_x_s; \
1456  const char* _ck_y_s; \
1457  const char* _ck_x_q; \
1458  const char* _ck_y_q; \
1459  if (_ck_x != NULL) { \
1460  _ck_x_q = "\""; \
1461  _ck_x_s = _ck_x; \
1462  } else { \
1463  _ck_x_q = ""; \
1464  _ck_x_s = "(null)"; \
1465  } \
1466  if (_ck_y != NULL) { \
1467  _ck_y_q = "\""; \
1468  _ck_y_s = _ck_y; \
1469  } else { \
1470  _ck_y_q = ""; \
1471  _ck_y_s = "(null)"; \
1472  } \
1473  ck_assert_msg( \
1474  (NULLEQ && (_ck_x == NULL) && (_ck_y == NULL)) || \
1475  (NULLNE && ((_ck_x == NULL) || (_ck_y == NULL)) && (_ck_x != _ck_y)) || \
1476  ((_ck_x != NULL) && (_ck_y != NULL) && (0 OP strcmp(_ck_y, _ck_x))), \
1477  "Assertion '%s' failed: %s == %s%s%s, %s == %s%s%s", \
1478  #X" "#OP" "#Y, \
1479  #X, _ck_x_q, _ck_x_s, _ck_x_q, \
1480  #Y, _ck_y_q, _ck_y_s, _ck_y_q); \
1481 } while (0)
1482 
1496 #define ck_assert_str_eq(X, Y) _ck_assert_str(X, ==, Y, 0, 0)
1497 
1511 #define ck_assert_str_ne(X, Y) _ck_assert_str(X, !=, Y, 0, 0)
1512 
1526 #define ck_assert_str_lt(X, Y) _ck_assert_str(X, <, Y, 0, 0)
1527 
1541 #define ck_assert_str_le(X, Y) _ck_assert_str(X, <=, Y, 0, 0)
1542 
1556 #define ck_assert_str_gt(X, Y) _ck_assert_str(X, >, Y, 0, 0)
1557 
1571 #define ck_assert_str_ge(X, Y) _ck_assert_str(X, >=, Y, 0, 0)
1572 
1587 #define ck_assert_pstr_eq(X, Y) _ck_assert_str(X, ==, Y, 1, 0)
1588 
1603 #define ck_assert_pstr_ne(X, Y) _ck_assert_str(X, !=, Y, 0, 1)
1604 
1605 /* Memory location comparison macros with improved output compared to ck_assert() */
1606 /* OP might be any operator that can be used in '0 OP memcmp(X,Y,L)' comparison */
1607 /* The x and y parameter swap in memcmp() is needed to handle >, >=, <, <= operators */
1608 /* Output is limited to CK_MAX_ASSERT_MEM_PRINT_SIZE bytes */
1609 #ifndef CK_MAX_ASSERT_MEM_PRINT_SIZE
1610 #define CK_MAX_ASSERT_MEM_PRINT_SIZE 64
1611 #endif
1612 
1613 /* Memory location comparison macros with improved output compared to ck_assert() */
1614 /* OP might be any operator that can be used in '0 OP memcmp(X,Y,L)' comparison */
1615 /* The x and y parameter swap in memcmp() is needed to handle >, >=, <, <= operators */
1616 /* Output is limited to CK_MAX_ASSERT_MEM_PRINT_SIZE bytes */
1617 #ifndef CK_MAX_ASSERT_MEM_PRINT_SIZE
1618 #define CK_MAX_ASSERT_MEM_PRINT_SIZE 64
1619 #endif
1620 
1621 #define _ck_assert_mem(X, OP, Y, L) do { \
1622  const uint8_t* _ck_x = (const uint8_t*)(X); \
1623  const uint8_t* _ck_y = (const uint8_t*)(Y); \
1624  size_t _ck_l = (L); \
1625  char _ck_x_str[CK_MAX_ASSERT_MEM_PRINT_SIZE * 2 + 1]; \
1626  char _ck_y_str[CK_MAX_ASSERT_MEM_PRINT_SIZE * 2 + 1]; \
1627  static const char _ck_hexdigits[] = "0123456789abcdef"; \
1628  size_t _ck_i; \
1629  size_t _ck_maxl = (_ck_l > CK_MAX_ASSERT_MEM_PRINT_SIZE) ? CK_MAX_ASSERT_MEM_PRINT_SIZE : _ck_l; \
1630  for (_ck_i = 0; _ck_i < _ck_maxl; _ck_i++) { \
1631  _ck_x_str[_ck_i * 2 ] = _ck_hexdigits[(_ck_x[_ck_i] >> 4) & 0xF]; \
1632  _ck_y_str[_ck_i * 2 ] = _ck_hexdigits[(_ck_y[_ck_i] >> 4) & 0xF]; \
1633  _ck_x_str[_ck_i * 2 + 1] = _ck_hexdigits[_ck_x[_ck_i] & 0xF]; \
1634  _ck_y_str[_ck_i * 2 + 1] = _ck_hexdigits[_ck_y[_ck_i] & 0xF]; \
1635  } \
1636  _ck_x_str[_ck_i * 2] = 0; \
1637  _ck_y_str[_ck_i * 2] = 0; \
1638  if (_ck_maxl != _ck_l) { \
1639  _ck_x_str[_ck_i * 2 - 2] = '.'; \
1640  _ck_y_str[_ck_i * 2 - 2] = '.'; \
1641  _ck_x_str[_ck_i * 2 - 1] = '.'; \
1642  _ck_y_str[_ck_i * 2 - 1] = '.'; \
1643  } \
1644  ck_assert_msg(0 OP memcmp(_ck_y, _ck_x, _ck_l), \
1645  "Assertion '%s' failed: %s == \"%s\", %s == \"%s\"", #X" "#OP" "#Y, #X, _ck_x_str, #Y, _ck_y_str); \
1646 } while (0)
1647 
1659 #define ck_assert_mem_eq(X, Y, L) _ck_assert_mem(X, ==, Y, L)
1660 
1672 #define ck_assert_mem_ne(X, Y, L) _ck_assert_mem(X, !=, Y, L)
1673 
1685 #define ck_assert_mem_lt(X, Y, L) _ck_assert_mem(X, <, Y, L)
1686 
1698 #define ck_assert_mem_le(X, Y, L) _ck_assert_mem(X, <=, Y, L)
1699 
1711 #define ck_assert_mem_gt(X, Y, L) _ck_assert_mem(X, >, Y, L)
1712 
1724 #define ck_assert_mem_ge(X, Y, L) _ck_assert_mem(X, >=, Y, L)
1725 
1726 /* Pointer comparison macros with improved output compared to ck_assert(). */
1727 /* OP may only be == or != */
1728 #define _ck_assert_ptr(X, OP, Y) do { \
1729  const void* _ck_x = (X); \
1730  const void* _ck_y = (Y); \
1731  ck_assert_msg(_ck_x OP _ck_y, "Assertion '%s' failed: %s == %#lx, %s == %#lx", #X" "#OP" "#Y, #X, (unsigned long)(uintptr_t)_ck_x, #Y, (unsigned long)(uintptr_t)_ck_y); \
1732 } while (0)
1733 
1734 /* Pointer against NULL comparison macros with improved output
1735  * compared to ck_assert(). */
1736 /* OP may only be == or != */
1737 #define _ck_assert_ptr_null(X, OP) do { \
1738  const void* _ck_x = (X); \
1739  ck_assert_msg(_ck_x OP NULL, \
1740  "Assertion '%s' failed: %s == %#lx", \
1741  #X" "#OP" NULL", \
1742  #X, (unsigned long)(uintptr_t)_ck_x); \
1743 } while (0)
1744 
1758 #define ck_assert_ptr_eq(X, Y) _ck_assert_ptr(X, ==, Y)
1759 
1770 #define ck_assert_ptr_ne(X, Y) _ck_assert_ptr(X, !=, Y)
1771 
1783 #define ck_assert_ptr_null(X) _ck_assert_ptr_null(X, ==)
1784 
1796 #define ck_assert_ptr_nonnull(X) _ck_assert_ptr_null(X, !=)
1797 
1808 #define mark_point() _mark_point(__FILE__,__LINE__)
1809 
1810 /* Non macro version of #mark_point */
1811 CK_DLL_EXP void CK_EXPORT _mark_point(const char *file, int line);
1812 
1817 {
1823 };
1824 
1829 {
1839 #if 0
1840  CK_SUBUNIT,
1841 #endif
1843 };
1844 
1848 typedef struct SRunner SRunner;
1849 
1853 typedef struct TestResult TestResult;
1854 
1859 {
1864 };
1865 
1878 CK_DLL_EXP int CK_EXPORT tr_rtype(TestResult * tr);
1879 
1892 CK_DLL_EXP enum ck_result_ctx CK_EXPORT tr_ctx(TestResult * tr);
1893 
1901 CK_DLL_EXP const char *CK_EXPORT tr_msg(TestResult * tr);
1902 
1911 CK_DLL_EXP int CK_EXPORT tr_lno(TestResult * tr);
1912 
1922 CK_DLL_EXP const char *CK_EXPORT tr_lfile(TestResult * tr);
1923 
1933 CK_DLL_EXP const char *CK_EXPORT tr_tcname(TestResult * tr);
1934 
1949 CK_DLL_EXP SRunner *CK_EXPORT srunner_create(Suite * s);
1950 
1962 CK_DLL_EXP void CK_EXPORT srunner_add_suite(SRunner * sr, Suite * s);
1963 
1975 CK_DLL_EXP void CK_EXPORT srunner_free(SRunner * sr);
1976 
1993 CK_DLL_EXP void CK_EXPORT srunner_run_all(SRunner * sr,
1994  enum print_output print_mode);
1995 
2024 CK_DLL_EXP void CK_EXPORT srunner_run(SRunner * sr, const char *sname,
2025  const char *tcname,
2026  enum print_output print_mode);
2027 
2028 
2063 CK_DLL_EXP void CK_EXPORT srunner_run_tagged(SRunner * sr, const char *sname,
2064  const char *tcname,
2065  const char *include_tags,
2066  const char *exclude_tags,
2067  enum print_output print_mode);
2068 
2080 CK_DLL_EXP int CK_EXPORT srunner_ntests_failed(SRunner * sr);
2081 
2091 CK_DLL_EXP int CK_EXPORT srunner_ntests_run(SRunner * sr);
2092 
2110 CK_DLL_EXP TestResult **CK_EXPORT srunner_failures(SRunner * sr);
2111 
2130 CK_DLL_EXP TestResult **CK_EXPORT srunner_results(SRunner * sr);
2131 
2141 CK_DLL_EXP void CK_EXPORT srunner_print(SRunner * sr,
2142  enum print_output print_mode);
2143 
2160 CK_DLL_EXP void CK_EXPORT srunner_set_log(SRunner * sr, const char *fname);
2161 
2172 CK_DLL_EXP int CK_EXPORT srunner_has_log(SRunner * sr);
2173 
2182 CK_DLL_EXP const char *CK_EXPORT srunner_log_fname(SRunner * sr);
2183 
2200 CK_DLL_EXP void CK_EXPORT srunner_set_xml(SRunner * sr, const char *fname);
2201 
2212 CK_DLL_EXP int CK_EXPORT srunner_has_xml(SRunner * sr);
2213 
2222 CK_DLL_EXP const char *CK_EXPORT srunner_xml_fname(SRunner * sr);
2223 
2240 CK_DLL_EXP void CK_EXPORT srunner_set_tap(SRunner * sr, const char *fname);
2241 
2252 CK_DLL_EXP int CK_EXPORT srunner_has_tap(SRunner * sr);
2253 
2262 CK_DLL_EXP const char *CK_EXPORT srunner_tap_fname(SRunner * sr);
2263 
2268 {
2272 };
2273 
2281 CK_DLL_EXP enum fork_status CK_EXPORT srunner_fork_status(SRunner * sr);
2282 
2303 CK_DLL_EXP void CK_EXPORT srunner_set_fork_status(SRunner * sr,
2304  enum fork_status fstat);
2305 
2326 CK_DLL_EXP pid_t CK_EXPORT check_fork(void);
2327 
2343 CK_DLL_EXP void CK_EXPORT check_waitpid_and_exit(pid_t pid) CK_ATTRIBUTE_NORETURN;
2344 
2360 CK_DLL_EXP void CK_EXPORT check_set_max_msg_size(size_t max_msg_size);
2361 
2362 #ifdef __cplusplus
2363 CK_CPPEND
2364 #endif
2365 
2366 #endif /* CHECK_H */
CK_DLL_EXP void CK_EXPORT tcase_set_timeout(TCase *tc, double timeout)
Definition: check.h:1820
TFun fn
Definition: check.h:169
Definition: check.h:1861
Definition: check.h:1834
CK_DLL_EXP int CK_EXPORT srunner_has_xml(SRunner *sr)
CK_DLL_EXP void CK_EXPORT srunner_run_all(SRunner *sr, enum print_output print_mode)
CK_DLL_EXP int CK_EXPORT tr_rtype(TestResult *tr)
struct TestResult TestResult
Definition: check.h:1853
CK_DLL_EXP TestResult **CK_EXPORT srunner_failures(SRunner *sr)
Definition: check.h:1860
CK_DLL_EXP TestResult **CK_EXPORT srunner_results(SRunner *sr)
struct TCase TCase
Definition: check.h:147
struct Suite Suite
Definition: check.h:162
CK_DLL_EXP int CK_EXPORT suite_tcase(Suite *s, const char *tcname)
CK_DLL_EXP const char *CK_EXPORT srunner_tap_fname(SRunner *sr)
Definition: check.h:2270
CK_DLL_EXP const char *CK_EXPORT tcase_name(void)
Definition: check.h:1832
CK_DLL_EXP int CK_EXPORT tr_lno(TestResult *tr)
CK_DLL_EXP pid_t CK_EXPORT check_fork(void)
CK_DLL_EXP const char *CK_EXPORT tr_tcname(TestResult *tr)
CK_DLL_EXP Suite *CK_EXPORT suite_create(const char *name)
CK_DLL_EXP void CK_EXPORT srunner_print(SRunner *sr, enum print_output print_mode)
const char * name
Definition: check.h:168
CK_DLL_EXP void CK_EXPORT srunner_set_fork_status(SRunner *sr, enum fork_status fstat)
CK_DLL_EXP void CK_EXPORT tcase_add_unchecked_fixture(TCase *tc, SFun setup, SFun teardown)
print_output
Definition: check.h:1828
fork_status
Definition: check.h:2267
CK_DLL_EXP enum ck_result_ctx CK_EXPORT tr_ctx(TestResult *tr)
Definition: check.h:1819
CK_DLL_EXP void CK_EXPORT srunner_free(SRunner *sr)
CK_DLL_EXP int CK_EXPORT srunner_has_log(SRunner *sr)
CK_DLL_EXP SRunner *CK_EXPORT srunner_create(Suite *s)
CK_DLL_EXP enum fork_status CK_EXPORT srunner_fork_status(SRunner *sr)
void(* SFun)(void)
Definition: check.h:157
CK_DLL_EXP int CK_EXPORT srunner_ntests_run(SRunner *sr)
void(* TFun)(int)
Definition: check.h:152
test_result
Definition: check.h:1816
CK_DLL_EXP void CK_EXPORT srunner_run_tagged(SRunner *sr, const char *sname, const char *tcname, const char *include_tags, const char *exclude_tags, enum print_output print_mode)
CK_DLL_EXP TCase *CK_EXPORT tcase_create(const char *name)
Definition: check.h:1842
CK_DLL_EXP void CK_EXPORT check_set_max_msg_size(size_t max_msg_size)
CK_DLL_EXP const char *CK_EXPORT tr_msg(TestResult *tr)
CK_DLL_EXP const char *CK_EXPORT srunner_xml_fname(SRunner *sr)
Definition: check.h:1831
int line
Definition: check.h:171
Definition: check.h:1863
struct SRunner SRunner
Definition: check.h:1848
CK_DLL_EXP void CK_EXPORT tcase_set_tags(TCase *tc, const char *tags)
Definition: check.h:1830
CK_DLL_EXP void CK_EXPORT tcase_add_checked_fixture(TCase *tc, SFun setup, SFun teardown)
CK_DLL_EXP int CK_EXPORT srunner_has_tap(SRunner *sr)
CK_DLL_EXP void CK_EXPORT check_waitpid_and_exit(pid_t pid) CK_ATTRIBUTE_NORETURN
const char * file
Definition: check.h:170
CK_DLL_EXP void CK_EXPORT srunner_set_tap(SRunner *sr, const char *fname)
struct TTest TTest
CK_DLL_EXP void CK_EXPORT srunner_add_suite(SRunner *sr, Suite *s)
Definition: check.h:1818
CK_DLL_EXP const char *CK_EXPORT tr_lfile(TestResult *tr)
CK_DLL_EXP void CK_EXPORT srunner_run(SRunner *sr, const char *sname, const char *tcname, enum print_output print_mode)
Definition: check.h:1821
CK_DLL_EXP void CK_EXPORT suite_add_tcase(Suite *s, TCase *tc)
CK_DLL_EXP void CK_EXPORT srunner_set_xml(SRunner *sr, const char *fname)
CK_DLL_EXP void CK_EXPORT srunner_set_log(SRunner *sr, const char *fname)
CK_DLL_EXP void CK_EXPORT tcase_fn_start(const char *fname, const char *file, int line)
CK_DLL_EXP const char *CK_EXPORT srunner_log_fname(SRunner *sr)
CK_DLL_EXP int CK_EXPORT srunner_ntests_failed(SRunner *sr)
Definition: check.h:1862
ck_result_ctx
Definition: check.h:1858
Definition: check.h:1833
Definition: check.h:2271
Definition: check.h:167
Definition: check.h:2269