CCUnit: CCUnitAssert.h ソースファイル

CCUnit 2.1 A C Unit Testing Library

- メインページ
- 関連ページ
- モジュール
- データ構造
- ファイル

- ファイル一覧
- グローバル

全て データ構造 ファイル 関数 変数 型定義 列挙型 列挙型の値 マクロ定義 グループ ページ
CCUnitAssert.h
説明を見る。
1 /* -*- mode: C; -*- */
2 /* Copyright (C) 2003, 2010, 2013 TSUTSUMI Kikuo.
3 This file is part of the CCUnit Library.
4
5 The CCUnit Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License
7 as published by the Free Software Foundation; either version 2.1 of
8 the License, or (at your option) any later version.
9
10 The CCUnit Library is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the CCUnit Library; see the file COPYING.LESSER.
17 If not, write to the Free Software Foundation, Inc., 59 Temple
18 Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 /*
22 * $Id$
23 */
27 #ifndef CCUNITASSERT_H
28 #define CCUNITASSERT_H
29
30 #include <ccunit/CCUnitConfig.h>
31 #if CCUNIT_HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34
57 extern void ccunit_assert (const char* file, unsigned int line,
58 bool condition, const char* condstr);
59
68 #define CCUNIT_ASSERT(COND) ccunit_assert (__FILE__, __LINE__, COND, #COND)
69
86 #define CCUNIT_ASSERT_TEST(TYP, EXPECT, OP, ACTUAL) \
87 do { \
88 const TYP ex = (EXPECT); \
89 const TYP ac = (ACTUAL); \
90 ccunit_assert_test_ ## TYP (__FILE__, __LINE__, (ex OP ac), \
91 (#EXPECT " " #OP " " #ACTUAL), \
92 ex, ac); \
93 } while (0)
94
105 #define CCUNIT_ASSERT_TEST_INT(EXPECT, OP, ACTUAL) \
106 CCUNIT_ASSERT_TEST (int, EXPECT, OP, ACTUAL)
107
117 #define CCUNIT_ASSERT_TEST_UINT(EXPECT, OP, ACTUAL) \
118 CCUNIT_ASSERT_TEST (u_int, EXPECT, OP, ACTUAL)
119
129 #define CCUNIT_ASSERT_TEST_LONG(EXPECT, OP, ACTUAL) \
130 CCUNIT_ASSERT_TEST (long, EXPECT, OP, ACTUAL)
131
141 #define CCUNIT_ASSERT_TEST_ULONG(EXPECT, OP, ACTUAL) \
142 CCUNIT_ASSERT_TEST (u_long, EXPECT, OP, ACTUAL)
143
153 #define CCUNIT_ASSERT_TEST_SHORT(EXPECT, OP, ACTUAL) \
154 CCUNIT_ASSERT_TEST (short, EXPECT, OP, ACTUAL)
155
165 #define CCUNIT_ASSERT_TEST_USHORT(EXPECT, OP, ACTUAL) \
166 CCUNIT_ASSERT_TEST (u_short, EXPECT, OP, ACTUAL)
167
177 #define CCUNIT_ASSERT_TEST_DOUBLE(EXPECT, OP, ACTUAL) \
178 CCUNIT_ASSERT_TEST (double, EXPECT, OP, ACTUAL)
179
189 #define CCUNIT_ASSERT_TEST_FLOAT(EXPECT, OP, ACTUAL) \
190 CCUNIT_ASSERT_TEST (float, EXPECT, OP, ACTUAL)
191 #if CCUNIT_HAVE_QUAD_T
192
202 #define CCUNIT_ASSERT_TEST_QUAD(EXPECT, OP, ACTUAL) \
203 CCUNIT_ASSERT_TEST (quad_t, EXPECT, OP, ACTUAL)
204 #endif
205 #if CCUNIT_HAVE_U_QUAD_T
206
216 #define CCUNIT_ASSERT_TEST_UQUAD(EXPECT, OP, ACTUAL) \
217 CCUNIT_ASSERT_TEST (u_quad_t, EXPECT, OP, ACTUAL)
218 #endif
219
229 #define CCUNIT_ASSERT_TEST_PTR(EXPECT, OP, ACTUAL) \
230 CCUNIT_ASSERT_TEST (_ccunit_ptr_t, EXPECT, OP, ACTUAL)
231
242 #define CCUNIT_ASSERT_TEST_STR(EXPECT, OP, ACTUAL) \
243 do { \
244 const _ccunit_str_t ex = (EXPECT); \
245 const _ccunit_str_t ac = (ACTUAL); \
246 const char* condstr = "strcmp (" #EXPECT ", " #ACTUAL ") " #OP " 0"; \
247 ccunit_assert_test__ccunit_str_t (__FILE__, __LINE__, \
248 strcmp(ex, ac) OP 0, condstr, ex, ac); \
249 } while (0)
250
262 #define CCUNIT_ASSERT_TEST_NSTR(EXPECT, OP, ACTUAL, N) \
263 do { \
264 const _ccunit_str_t ex = (EXPECT); \
265 const _ccunit_str_t ac = (ACTUAL); \
266 const size_t n = (N); \
267 ccunit_assert_test__ccunit_str_t (__FILE__, __LINE__, \
268 strncmp(ex, ac, n) OP 0, \
269 "strncmp (" #EXPECT ", " #ACTUAL \
270 ", " #N ") " #OP " 0", \
271 ex, ac); \
272 } while (0)
273
284 #define CCUNIT_ASSERT_TEST_CASE_STR(EXPECT, OP, ACTUAL) \
285 do { \
286 const _ccunit_str_t ex = (EXPECT); \
287 const _ccunit_str_t ac = (ACTUAL); \
288 const size_t n = (N); \
289 ccunit_assert_test__ccunit_str_t (__FILE__, __LINE__, \
290 strcasecmp(ex, ac) OP 0, \
291 "strcasecmp (" #EXPECT ", " #ACTUAL \
292 ") " #OP " 0", \
293 ex, ac); \
294 } while (0)
295
307 #define CCUNIT_ASSERT_TEST_CASE_NSTR(EXPECT, OP, ACTUAL, N) \
308 do { \
309 const _ccunit_str_t ex = (EXPECT); \
310 const _ccunit_str_t ac = (ACTUAL); \
311 const size_t n = (N); \
312 ccunit_assert_test__ccunit_str_t (__FILE__, __LINE__, \
313 strncasecmp(ex, ac, n) OP 0, \
314 "strncasecmp (" #EXPECT ", " #ACTUAL \
315 ", " #N ") " #OP " 0", \
316 ex, ac); \
317 } while (0)
318
330 #define CCUNIT_ASSERT_TEST_OBJ(EXPECT, OP, ACTUAL, TOSTR) \
331 do { \
332 const _ccunit_obj_t ex = (EXPECT); \
333 const _ccunit_obj_t ac = (ACTUAL); \
334 const char* condstr = #OP " (" #EXPECT ", " #ACTUAL ")"; \
335 ccunit_assert_test__ccunit_obj_t (__FILE__, __LINE__, \
336 OP(ex, ac), condstr, ex, ac, \
337 (ccunit_toString_t)TOSTR); \
338 } while (0)
339
356 #define CCUNIT_ASSERT_COND(TYP, CONDITION, EXPECT, ACTUAL) \
357 do { \
358 const TYP ex = (EXPECT); \
359 const TYP ac = (ACTUAL); \
360 ccunit_assert_test_ ## TYP (__FILE__, __LINE__, (CONDITION), \
361 (#CONDITION), ex, ac); \
362 } while (0)
363
377 #define CCUNIT_ASSERT_NULL(ACTUAL) \
378 CCUNIT_ASSERT_TEST_PTR(NULL, ==, ACTUAL)
379
388 #define CCUNIT_ASSERT_NOT_NULL(ACTUAL) \
389 CCUNIT_ASSERT_TEST_PTR(NULL, !=, ACTUAL)
390
400 #define CCUNIT_ASSERT_EQ_INT(EXPECT, ACTUAL) \
401 CCUNIT_ASSERT_TEST_INT (EXPECT, ==, ACTUAL)
402
412 #define CCUNIT_ASSERT_NE_INT(EXPECT, ACTUAL) \
413 CCUNIT_ASSERT_TEST_INT (EXPECT, !=, ACTUAL)
414
424 #define CCUNIT_ASSERT_LT_INT(EXPECT, ACTUAL) \
425 CCUNIT_ASSERT_TEST_INT (EXPECT, <, ACTUAL)
426
436 #define CCUNIT_ASSERT_LE_INT(EXPECT, ACTUAL) \
437 CCUNIT_ASSERT_TEST_INT (EXPECT, <=, ACTUAL)
438
448 #define CCUNIT_ASSERT_GT_INT(EXPECT, ACTUAL) \
449 CCUNIT_ASSERT_TEST_INT (EXPECT, >, ACTUAL)
450
460 #define CCUNIT_ASSERT_GE_INT(EXPECT, ACTUAL) \
461 CCUNIT_ASSERT_TEST_INT (EXPECT, >=, ACTUAL)
462
472 #define CCUNIT_ASSERT_EQ_UINT(EXPECT, ACTUAL) \
473 CCUNIT_ASSERT_TEST_UINT (EXPECT, ==, ACTUAL)
474
484 #define CCUNIT_ASSERT_NE_UINT(EXPECT, ACTUAL) \
485 CCUNIT_ASSERT_TEST_UINT (EXPECT, !=, ACTUAL)
486
496 #define CCUNIT_ASSERT_LT_UINT(EXPECT, ACTUAL) \
497 CCUNIT_ASSERT_TEST_UINT (EXPECT, <, ACTUAL)
498
508 #define CCUNIT_ASSERT_LE_UINT(EXPECT, ACTUAL) \
509 CCUNIT_ASSERT_TEST_UINT (EXPECT, <=, ACTUAL)
510
520 #define CCUNIT_ASSERT_GT_UINT(EXPECT, ACTUAL) \
521 CCUNIT_ASSERT_TEST_UINT (EXPECT, >, ACTUAL)
522
532 #define CCUNIT_ASSERT_GE_UINT(EXPECT, ACTUAL) \
533 CCUNIT_ASSERT_TEST_UINT (EXPECT, >=, ACTUAL)
534
544 #define CCUNIT_ASSERT_EQ_DOUBLE(EXPECT, ACTUAL) \
545 CCUNIT_ASSERT_TEST_DOUBLE (EXPECT, ==, ACTUAL)
546
555 #define CCUNIT_ASSERT_NE_DOUBLE(EXPECT, ACTUAL) \
556 CCUNIT_ASSERT_TEST_DOUBLE (EXPECT, !=, ACTUAL)
557
566 #define CCUNIT_ASSERT_LT_DOUBLE(EXPECT, ACTUAL) \
567 CCUNIT_ASSERT_TEST_DOUBLE (EXPECT, <, ACTUAL)
568
577 #define CCUNIT_ASSERT_LE_DOUBLE(EXPECT, ACTUAL) \
578 CCUNIT_ASSERT_TEST_DOUBLE (EXPECT, <=, ACTUAL)
579
588 #define CCUNIT_ASSERT_GT_DOUBLE(EXPECT, ACTUAL) \
589 CCUNIT_ASSERT_TEST_DOUBLE (EXPECT, >, ACTUAL)
590
599 #define CCUNIT_ASSERT_GE_DOUBLE(EXPECT, ACTUAL) \
600 CCUNIT_ASSERT_TEST_DOUBLE (EXPECT, >=, ACTUAL)
601
611 #define CCUNIT_ASSERT_EQ_FLOAT(EXPECT, ACTUAL) \
612 CCUNIT_ASSERT_TEST_FLOAT (EXPECT, ==, ACTUAL)
613
622 #define CCUNIT_ASSERT_NE_FLOAT(EXPECT, ACTUAL) \
623 CCUNIT_ASSERT_TEST_FLOAT (EXPECT, !=, ACTUAL)
624
633 #define CCUNIT_ASSERT_LT_FLOAT(EXPECT, ACTUAL) \
634 CCUNIT_ASSERT_TEST_FLOAT (EXPECT, <, ACTUAL)
635
644 #define CCUNIT_ASSERT_LE_FLOAT(EXPECT, ACTUAL) \
645 CCUNIT_ASSERT_TEST_FLOAT (EXPECT, <=, ACTUAL)
646
655 #define CCUNIT_ASSERT_GT_FLOAT(EXPECT, ACTUAL) \
656 CCUNIT_ASSERT_TEST_FLOAT (EXPECT, >, ACTUAL)
657
666 #define CCUNIT_ASSERT_GE_FLOAT(EXPECT, ACTUAL) \
667 CCUNIT_ASSERT_TEST_FLOAT (EXPECT, >=, ACTUAL)
668
669 #if CCUNIT_HAVE_QUAD_T
670
679 #define CCUNIT_ASSERT_EQ_QUAD(EXPECT, ACTUAL) \
680 CCUNIT_ASSERT_TEST_QUAD (EXPECT, ==, ACTUAL)
681
690 #define CCUNIT_ASSERT_NE_QUAD(EXPECT, ACTUAL) \
691 CCUNIT_ASSERT_TEST_QUAD (EXPECT, !=, ACTUAL)
692
701 #define CCUNIT_ASSERT_LT_QUAD(EXPECT, ACTUAL) \
702 CCUNIT_ASSERT_TEST_QUAD (EXPECT, <, ACTUAL)
703
712 #define CCUNIT_ASSERT_LE_QUAD(EXPECT, ACTUAL) \
713 CCUNIT_ASSERT_TEST_QUAD (EXPECT, <=, ACTUAL)
714
723 #define CCUNIT_ASSERT_GT_QUAD(EXPECT, ACTUAL) \
724 CCUNIT_ASSERT_TEST_QUAD (EXPECT, >, ACTUAL)
725
734 #define CCUNIT_ASSERT_GE_QUAD(EXPECT, ACTUAL) \
735 CCUNIT_ASSERT_TEST_QUAD (EXPECT, >=, ACTUAL)
736 #endif
737
738 #if CCUNIT_HAVE_U_QUAD_T
739
748 #define CCUNIT_ASSERT_EQ_UQUAD(EXPECT, ACTUAL) \
749 CCUNIT_ASSERT_TEST_UQUAD (EXPECT, ==, ACTUAL)
750
759 #define CCUNIT_ASSERT_NE_UQUAD(EXPECT, ACTUAL) \
760 CCUNIT_ASSERT_TEST_UQUAD (EXPECT, !=, ACTUAL)
761
770 #define CCUNIT_ASSERT_LT_UQUAD(EXPECT, ACTUAL) \
771 CCUNIT_ASSERT_TEST_UQUAD (EXPECT, <, ACTUAL)
772
781 #define CCUNIT_ASSERT_LE_UQUAD(EXPECT, ACTUAL) \
782 CCUNIT_ASSERT_TEST_UQUAD (EXPECT, <=, ACTUAL)
783
792 #define CCUNIT_ASSERT_GT_UQUAD(EXPECT, ACTUAL) \
793 CCUNIT_ASSERT_TEST_UQUAD (EXPECT, >, ACTUAL)
794
803 #define CCUNIT_ASSERT_GE_UQUAD(EXPECT, ACTUAL) \
804 CCUNIT_ASSERT_TEST_UQUAD (EXPECT, >=, ACTUAL)
805 #endif
806
816 #define CCUNIT_ASSERT_EQ_STR(EXPECT, ACTUAL) \
817 CCUNIT_ASSERT_TEST_STR (EXPECT, ==, ACTUAL)
818
827 #define CCUNIT_ASSERT_NE_STR(EXPECT, ACTUAL) \
828 CCUNIT_ASSERT_TEST_STR (EXPECT, !=, ACTUAL)
829
838 #define CCUNIT_ASSERT_LT_STR(EXPECT, ACTUAL) \
839 CCUNIT_ASSERT_TEST_STR (EXPECT, <, ACTUAL)
840
849 #define CCUNIT_ASSERT_LE_STR(EXPECT, ACTUAL) \
850 CCUNIT_ASSERT_TEST_STR (EXPECT, <=, ACTUAL)
851
860 #define CCUNIT_ASSERT_GT_STR(EXPECT, ACTUAL) \
861 CCUNIT_ASSERT_TEST_STR (EXPECT, >, ACTUAL)
862
871 #define CCUNIT_ASSERT_GE_STR(EXPECT, ACTUAL) \
872 CCUNIT_ASSERT_TEST_STR (EXPECT, >=, ACTUAL)
873
883 #define CCUNIT_ASSERT_EQ_PTR(EXPECT, ACTUAL) \
884 CCUNIT_ASSERT_TEST_PTR (EXPECT, ==, ACTUAL)
885
894 #define CCUNIT_ASSERT_NE_PTR(EXPECT, ACTUAL) \
895 CCUNIT_ASSERT_TEST_PTR (EXPECT, !=, ACTUAL)
896
905 #define CCUNIT_ASSERT_LT_PTR(EXPECT, ACTUAL) \
906 CCUNIT_ASSERT_TEST_PTR (EXPECT, <, ACTUAL)
907
916 #define CCUNIT_ASSERT_LE_PTR(EXPECT, ACTUAL) \
917 CCUNIT_ASSERT_TEST_PTR (EXPECT, <=, ACTUAL)
918
927 #define CCUNIT_ASSERT_GT_PTR(EXPECT, ACTUAL) \
928 CCUNIT_ASSERT_TEST_PTR (EXPECT, >, ACTUAL)
929
938 #define CCUNIT_ASSERT_GE_PTR(EXPECT, ACTUAL) \
939 CCUNIT_ASSERT_TEST_PTR (EXPECT, >=, ACTUAL)
940
943 #ifndef CCUNIT_HAVE_U_CHAR
944 #define CCUNIT_HAVE_U_CHAR
945 typedef unsigned char u_char;
946 #endif
947 #ifndef CCUNIT_HAVE_U_INT
948 #define CCUNIT_HAVE_U_INT
949 typedef unsigned int u_int;
950 #endif
951 #ifndef CCUNIT_HAVE_U_SHORT
952 #define CCUNIT_HAVE_U_SHORT
953 typedef unsigned short u_short;
954 #endif
955 #ifndef CCUNIT_HAVE_U_LONG
956 #define CCUNIT_HAVE_U_LONG
957 typedef unsigned long u_long;
958 #endif
959 #ifndef CCUNIT_HAVE_QUAD_T
960 #ifdef CCUNIT_HAVE_INT64_T
961 #define CCUNIT_HAVE_QUAD_T 1
962 typedef int64_t quad_t;
963 #else /* !CCUNIT_HAVE_INT64_T */
964 #if CCUNIT_HAVE_LONG_LONG
965 #define CCUNIT_HAVE_QUAD_T 1
966 typedef long long quad_t;
967 #endif /* CCUNIT_HAVE_LONG_LONG */
968 #endif /* CCUNIT_HAVE_INT64_T */
969 #endif /* !CCUNIT_HAVE_QUAD_T */
970
971 #ifndef CCUNIT_HAVE_U_QUAD_T
972 #ifdef CCUNIT_HAVE_U_INT64_T
973 #define CCUNIT_HAVE_U_QUAD_T 1
974 typedef u_int64_t u_quad_t;
975 #else /* !CCUNIT_HAVE_U_INT64_T */
976 #ifdef CCUNIT_HAVE_LONG_LONG
977 #define CCUNIT_HAVE_U_QUAD_T 1
978 typedef unsigned long long u_quad_t;
979 #endif /* CCUNIT_HAVE_LONG_LONG */
980 #endif /* CCUNIT_HAVE_U_INT64_T */
981 #endif /* !CCUNIT_HAVE_U_QUAD_T */
982
983 typedef const char* _ccunit_str_t;
984 typedef const void* _ccunit_ptr_t;
985 typedef const void* _ccunit_obj_t;
987 /*
988 * Asserts that a condition is true. If it isn't it longjmp with
989 * _ccunit_runTest_env.
990 *
991 * @param TYP test value type
992 * @throws _ccunit_runTest_env If condition is false.
993 * @ingroup Assertions
994 */
995 #define DCL_CCUNIT_ASSERT_TEST_TYPE(TYP) \
996 extern void ccunit_assert_test_ ## TYP (const char* file, unsigned int line, \
997 bool cond, const char* condstr, \
998 TYP expect, TYP acutal)
999
1000 DCL_CCUNIT_ASSERT_TEST_TYPE(char);
1001 DCL_CCUNIT_ASSERT_TEST_TYPE(u_char);
1002 DCL_CCUNIT_ASSERT_TEST_TYPE(int);
1003 DCL_CCUNIT_ASSERT_TEST_TYPE(u_int);
1004 DCL_CCUNIT_ASSERT_TEST_TYPE(short);
1005 DCL_CCUNIT_ASSERT_TEST_TYPE(u_short);
1006 DCL_CCUNIT_ASSERT_TEST_TYPE(long);
1007 DCL_CCUNIT_ASSERT_TEST_TYPE(u_long);
1008 DCL_CCUNIT_ASSERT_TEST_TYPE(float);
1009 DCL_CCUNIT_ASSERT_TEST_TYPE(double);
1010 DCL_CCUNIT_ASSERT_TEST_TYPE(_ccunit_str_t);
1011 DCL_CCUNIT_ASSERT_TEST_TYPE(_ccunit_ptr_t);
1012 #if CCUNIT_HAVE_QUAD_T
1013 DCL_CCUNIT_ASSERT_TEST_TYPE(quad_t);
1014 #endif
1015 #if CCUNIT_HAVE_U_QUAD_T
1016 DCL_CCUNIT_ASSERT_TEST_TYPE(u_quad_t);
1017 #endif
1018
1019 typedef char* (*ccunit_toString_t)(_ccunit_obj_t);
1020
1021 extern void ccunit_assert_test__ccunit_obj_t (const char* file, unsigned int line,
1022 bool cond, const char* condstr,
1023 _ccunit_obj_t expect,
1024 _ccunit_obj_t acutal,
1025 ccunit_toString_t);
1026
1029 #endif

| hosts this site. |  | Send comments to: CCUnit Developer |