Atrinik Server  4.0
checkstd.h
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., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #if CHECK_MAJOR_VERSION == 0 && CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION <= 9
23 
24 #undef ck_assert
25 #define ck_assert(C) ck_assert_msg(C, NULL)
26 #undef ck_assert_msg
27 #define ck_assert_msg(expr, ...) \
28  _fail_unless(expr, __FILE__, __LINE__,\
29  "Assertion '"#expr"' failed" , ## __VA_ARGS__, NULL)
30 
31 /* Always fail */
32 #undef ck_abort
33 #define ck_abort() ck_abort_msg(NULL)
34 #undef ck_abort_msg
35 #define ck_abort_msg(...) _fail_unless(0, __FILE__, __LINE__, "Failed" , ## __VA_ARGS__, NULL)
36 
37 /* Signed and unsigned integer comparsion macros with improved output compared to ck_assert(). */
38 /* OP may be any comparion operator. */
39 #undef _ck_assert_int
40 #define _ck_assert_int(X, OP, Y) do { \
41  int64_t _ck_x = (X); \
42  int64_t _ck_y = (Y); \
43  ck_assert_msg(_ck_x OP _ck_y, "Assertion '"#X#OP#Y"' failed: "#X"==%jd, "#Y"==%jd", _ck_x, _ck_y); \
44 } while (0)
45 #undef ck_assert_int_eq
46 #define ck_assert_int_eq(X, Y) _ck_assert_int(X, ==, Y)
47 #undef ck_assert_int_ne
48 #define ck_assert_int_ne(X, Y) _ck_assert_int(X, !=, Y)
49 #undef ck_assert_int_lt
50 #define ck_assert_int_lt(X, Y) _ck_assert_int(X, <, Y)
51 #undef ck_assert_int_le
52 #define ck_assert_int_le(X, Y) _ck_assert_int(X, <=, Y)
53 #undef ck_assert_int_gt
54 #define ck_assert_int_gt(X, Y) _ck_assert_int(X, >, Y)
55 #undef ck_assert_int_ge
56 #define ck_assert_int_ge(X, Y) _ck_assert_int(X, >=, Y)
57 
58 #undef _ck_assert_uint
59 #define _ck_assert_uint(X, OP, Y) do { \
60  uint64_t _ck_x = (X); \
61  uint64_t _ck_y = (Y); \
62  ck_assert_msg(_ck_x OP _ck_y, "Assertion '"#X#OP#Y"' failed: "#X"==%ju, "#Y"==%ju", _ck_x, _ck_y); \
63 } while (0)
64 #undef ck_assert_uint_eq
65 #define ck_assert_uint_eq(X, Y) _ck_assert_uint(X, ==, Y)
66 #undef ck_assert_uint_ne
67 #define ck_assert_uint_ne(X, Y) _ck_assert_uint(X, !=, Y)
68 #undef ck_assert_uint_lt
69 #define ck_assert_uint_lt(X, Y) _ck_assert_uint(X, <, Y)
70 #undef ck_assert_uint_le
71 #define ck_assert_uint_le(X, Y) _ck_assert_uint(X, <=, Y)
72 #undef ck_assert_uint_gt
73 #define ck_assert_uint_gt(X, Y) _ck_assert_uint(X, >, Y)
74 #undef ck_assert_uint_ge
75 #define ck_assert_uint_ge(X, Y) _ck_assert_uint(X, >=, Y)
76 
77 /* String comparsion macros with improved output compared to ck_assert() */
78 /* OP might be any operator that can be used in '0 OP strcmp(X,Y)' comparison */
79 /* The x and y parameter swap in strcmp() is needed to handle >, >=, <, <= operators */
80 #undef _ck_assert_str
81 #define _ck_assert_str(X, OP, Y) do { \
82  const char* _ck_x = (X); \
83  const char* _ck_y = (Y); \
84  ck_assert_msg(0 OP strcmp(_ck_y, _ck_x), \
85  "Assertion '"#X#OP#Y"' failed: "#X"==\"%s\", "#Y"==\"%s\"", _ck_x, _ck_y); \
86 } while (0)
87 #undef ck_assert_str_eq
88 #define ck_assert_str_eq(X, Y) _ck_assert_str(X, ==, Y)
89 #undef ck_assert_str_ne
90 #define ck_assert_str_ne(X, Y) _ck_assert_str(X, !=, Y)
91 #undef ck_assert_str_lt
92 #define ck_assert_str_lt(X, Y) _ck_assert_str(X, <, Y)
93 #undef ck_assert_str_le
94 #define ck_assert_str_le(X, Y) _ck_assert_str(X, <=, Y)
95 #undef ck_assert_str_gt
96 #define ck_assert_str_gt(X, Y) _ck_assert_str(X, >, Y)
97 #undef ck_assert_str_ge
98 #define ck_assert_str_ge(X, Y) _ck_assert_str(X, >=, Y)
99 
100 /* Pointer comparsion macros with improved output compared to ck_assert(). */
101 /* OP may only be == or != */
102 #undef _ck_assert_ptr
103 #define _ck_assert_ptr(X, OP, Y) do { \
104  const void* _ck_x = (X); \
105  const void* _ck_y = (Y); \
106  ck_assert_msg(_ck_x OP _ck_y, "Assertion '"#X#OP#Y"' failed: "#X"==%p, "#Y"==%p", _ck_x, _ck_y); \
107 } while (0)
108 #undef ck_assert_ptr_eq
109 #define ck_assert_ptr_eq(X, Y) _ck_assert_ptr(X, ==, Y)
110 #undef ck_assert_ptr_ne
111 #define ck_assert_ptr_ne(X, Y) _ck_assert_ptr(X, !=, Y)
112 
113 #endif