[ CCUnit project page ] |  | [ CCUnit home page ]

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# CCUnitAssert.h

Go to the documentation of this file.

    00001 /* -*- mode: C; -*- */
    00002 /* Copyright (C) 2003, 2010 TSUTSUMI Kikuo.
    00003    This file is part of the CCUnit Library.
    00004
    00005    The CCUnit Library is free software; you can redistribute it and/or
    00006    modify it under the terms of the GNU Lesser General Public License
    00007    as published by the Free Software Foundation; either version 2.1 of
    00008    the License, or (at your option) any later version.
    00009
    00010    The CCUnit Library is distributed in the hope that it will be
    00011    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
    00012    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00013    GNU Lesser General Public License for more details.
    00014
    00015    You should have received a copy of the GNU Lesser General Public
    00016    License along with the CCUnit Library; see the file COPYING.LESSER.
    00017    If not, write to the Free Software Foundation, Inc., 59 Temple
    00018    Place - Suite 330, Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 /*
    00022  * $Id: CCUnitAssert.h,v 1.14 2010/08/16 05:07:00 tsutsumi Exp $
    00023  */
    00027 #ifndef CCUNITASSERT_H
    00028 #define CCUNITASSERT_H
    00029
    00030 #include <ccunit/CCUnitConfig.h>
    00031 #if CCUNIT_HAVE_SYS_TYPES_H
    00032 #  include <sys/types.h>
    00033 #endif
    00034
    00057 extern void ccunit_assert (const char* file, unsigned int line,
    00058                            bool condition, const char* condstr);
    00059
    00060 #ifndef CCUNIT_HAVE_U_CHAR
    00061 #define CCUNIT_HAVE_U_CHAR
    00062 typedef unsigned char u_char;
    00063 #endif
    00064 #ifndef CCUNIT_HAVE_U_INT
    00065 #define CCUNIT_HAVE_U_INT
    00066 typedef unsigned int u_int;
    00067 #endif
    00068 #ifndef CCUNIT_HAVE_U_SHORT
    00069 #define CCUNIT_HAVE_U_SHORT
    00070 typedef unsigned short u_short;
    00071 #endif
    00072 #ifndef CCUNIT_HAVE_U_LONG
    00073 #define CCUNIT_HAVE_U_LONG
    00074 typedef unsigned long u_long;
    00075 #endif
    00076 #ifndef CCUNIT_HAVE_QUAD_T
    00077 #ifdef CCUNIT_HAVE_INT64_T
    00078 #define CCUNIT_HAVE_QUAD_T 1
    00079 typedef int64_t quad_t;
    00080 #else  /* !CCUNIT_HAVE_INT64_T */
    00081 #if CCUNIT_HAVE_LONG_LONG
    00082 #define CCUNIT_HAVE_QUAD_T 1
    00083 typedef long long quad_t;
    00084 #endif  /* CCUNIT_HAVE_LONG_LONG */
    00085 #endif  /* CCUNIT_HAVE_INT64_T */
    00086 #endif  /* !CCUNIT_HAVE_QUAD_T */
    00087
    00088 #ifndef CCUNIT_HAVE_U_QUAD_T
    00089 #ifdef CCUNIT_HAVE_U_INT64_T
    00090 #define CCUNIT_HAVE_U_QUAD_T 1
    00091 typedef u_int64_t u_quad_t;
    00092 #else  /* !CCUNIT_HAVE_U_INT64_T */
    00093 #ifdef CCUNIT_HAVE_LONG_LONG
    00094 #define CCUNIT_HAVE_U_QUAD_T 1
    00095 typedef unsigned long long u_quad_t;
    00096 #endif  /* CCUNIT_HAVE_LONG_LONG */
    00097 #endif  /* CCUNIT_HAVE_U_INT64_T */
    00098 #endif  /* !CCUNIT_HAVE_U_QUAD_T */
    00099
    00100 typedef const char* _ccunit_str_t;
    00101 typedef const void* _ccunit_ptr_t;
    00102 typedef const void* _ccunit_obj_t;
    00116 #define DCL_CCUNIT_ASSERT_TEST_TYPE(TYP)                                \
    00117   extern void ccunit_assert_test_ ## TYP (const char* file, unsigned int line, \
    00118                                           bool cond, const char* condstr, \
    00119                                           TYP expect, TYP acutal)
    00120
    00121 DCL_CCUNIT_ASSERT_TEST_TYPE(char);
    00122 DCL_CCUNIT_ASSERT_TEST_TYPE(u_char);
    00123 DCL_CCUNIT_ASSERT_TEST_TYPE(int);
    00124 DCL_CCUNIT_ASSERT_TEST_TYPE(u_int);
    00125 DCL_CCUNIT_ASSERT_TEST_TYPE(short);
    00126 DCL_CCUNIT_ASSERT_TEST_TYPE(u_short);
    00127 DCL_CCUNIT_ASSERT_TEST_TYPE(long);
    00128 DCL_CCUNIT_ASSERT_TEST_TYPE(u_long);
    00129 DCL_CCUNIT_ASSERT_TEST_TYPE(float);
    00130 DCL_CCUNIT_ASSERT_TEST_TYPE(double);
    00131 DCL_CCUNIT_ASSERT_TEST_TYPE(_ccunit_str_t);
    00132 DCL_CCUNIT_ASSERT_TEST_TYPE(_ccunit_ptr_t);
    00133 #if CCUNIT_HAVE_QUAD_T
    00134 DCL_CCUNIT_ASSERT_TEST_TYPE(quad_t);
    00135 #endif
    00136 #if CCUNIT_HAVE_U_QUAD_T
    00137 DCL_CCUNIT_ASSERT_TEST_TYPE(u_quad_t);
    00138 #endif
    00139
    00140 typedef char* (*ccunit_toString_t)(_ccunit_obj_t);
    00141
    00142 extern void ccunit_assert_test__ccunit_obj_t (const char* file, unsigned int line,
    00143                                               bool cond, const char* condstr,
    00144                                               _ccunit_obj_t expect,
    00145                                               _ccunit_obj_t acutal,
    00146                                               ccunit_toString_t);
    00147
    00158 #define CCUNIT_ASSERT(COND) ccunit_assert (__FILE__, __LINE__, COND, #COND)
    00159
    00176 #define CCUNIT_ASSERT_TEST(TYP, EXPECT, OP, ACTUAL)                     \
    00177   do {                                                                  \
    00178     const TYP ex = (EXPECT);                                            \
    00179     const TYP ac = (ACTUAL);                                            \
    00180     ccunit_assert_test_ ## TYP (__FILE__, __LINE__, (ex OP ac),         \
    00181                                 (#EXPECT " " #OP " " #ACTUAL),          \
    00182                                 ex, ac);                                \
    00183   } while (0)
    00184
    00195 #define CCUNIT_ASSERT_TEST_INT(EXPECT, OP, ACTUAL)              \
    00196   CCUNIT_ASSERT_TEST (int, EXPECT, OP, ACTUAL)
    00197
    00207 #define CCUNIT_ASSERT_TEST_UINT(EXPECT, OP, ACTUAL)             \
    00208   CCUNIT_ASSERT_TEST (u_int, EXPECT, OP, ACTUAL)
    00209
    00219 #define CCUNIT_ASSERT_TEST_LONG(EXPECT, OP, ACTUAL)             \
    00220   CCUNIT_ASSERT_TEST (long, EXPECT, OP, ACTUAL)
    00221
    00231 #define CCUNIT_ASSERT_TEST_ULONG(EXPECT, OP, ACTUAL)            \
    00232   CCUNIT_ASSERT_TEST (u_long, EXPECT, OP, ACTUAL)
    00233
    00243 #define CCUNIT_ASSERT_TEST_SHORT(EXPECT, OP, ACTUAL)            \
    00244   CCUNIT_ASSERT_TEST (short, EXPECT, OP, ACTUAL)
    00245
    00255 #define CCUNIT_ASSERT_TEST_USHORT(EXPECT, OP, ACTUAL)           \
    00256   CCUNIT_ASSERT_TEST (u_short, EXPECT, OP, ACTUAL)
    00257
    00267 #define CCUNIT_ASSERT_TEST_DOUBLE(EXPECT, OP, ACTUAL)           \
    00268   CCUNIT_ASSERT_TEST (double, EXPECT, OP, ACTUAL)
    00269
    00279 #define CCUNIT_ASSERT_TEST_FLOAT(EXPECT, OP, ACTUAL)            \
    00280   CCUNIT_ASSERT_TEST (float, EXPECT, OP, ACTUAL)
    00281 #if CCUNIT_HAVE_QUAD_T
    00282
    00292 #define CCUNIT_ASSERT_TEST_QUAD(EXPECT, OP, ACTUAL)             \
    00293   CCUNIT_ASSERT_TEST (quad_t, EXPECT, OP, ACTUAL)
    00294 #endif
    00295 #if CCUNIT_HAVE_U_QUAD_T
    00296
    00306 #define CCUNIT_ASSERT_TEST_UQUAD(EXPECT, OP, ACTUAL)            \
    00307   CCUNIT_ASSERT_TEST (u_quad_t, EXPECT, OP, ACTUAL)
    00308 #endif
    00309
    00319 #define CCUNIT_ASSERT_TEST_PTR(EXPECT, OP, ACTUAL)              \
    00320   CCUNIT_ASSERT_TEST (_ccunit_ptr_t, EXPECT, OP, ACTUAL)
    00321
    00332 #define CCUNIT_ASSERT_TEST_STR(EXPECT, OP, ACTUAL)                      \
    00333   do {                                                                  \
    00334     const _ccunit_str_t ex = (EXPECT);                                  \
    00335     const _ccunit_str_t ac = (ACTUAL);                                  \
    00336     const char* condstr = "strcmp (" #EXPECT ", " #ACTUAL ") " #OP " 0"; \
    00337     ccunit_assert_test__ccunit_str_t (__FILE__, __LINE__,               \
    00338                                       strcmp(ex, ac) OP 0, condstr, ex, ac); \
    00339   } while (0)
    00340
    00352 #define CCUNIT_ASSERT_TEST_NSTR(EXPECT, OP, ACTUAL, N)                  \
    00353   do {                                                                  \
    00354     const _ccunit_str_t ex = (EXPECT);                                  \
    00355     const _ccunit_str_t ac = (ACTUAL);                                  \
    00356     const size_t n = (N);                                               \
    00357     ccunit_assert_test__ccunit_str_t (__FILE__, __LINE__,               \
    00358                                       strncmp(ex, ac, n) OP 0,          \
    00359                                       "strncmp (" #EXPECT ", " #ACTUAL  \
    00360                                       ", " #N ") " #OP " 0",            \
    00361                                       ex, ac);                          \
    00362   } while (0)
    00363
    00374 #define CCUNIT_ASSERT_TEST_CASE_STR(EXPECT, OP, ACTUAL)                 \
    00375   do {                                                                  \
    00376     const _ccunit_str_t ex = (EXPECT);                                  \
    00377     const _ccunit_str_t ac = (ACTUAL);                                  \
    00378     const size_t n = (N);                                               \
    00379     ccunit_assert_test__ccunit_str_t (__FILE__, __LINE__,               \
    00380                                       strcasecmp(ex, ac) OP 0,          \
    00381                                       "strcasecmp (" #EXPECT ", " #ACTUAL \
    00382                                       ") " #OP " 0",                    \
    00383                                       ex, ac);                          \
    00384   } while (0)
    00385
    00397 #define CCUNIT_ASSERT_TEST_CASE_NSTR(EXPECT, OP, ACTUAL, N)             \
    00398   do {                                                                  \
    00399     const _ccunit_str_t ex = (EXPECT);                                  \
    00400     const _ccunit_str_t ac = (ACTUAL);                                  \
    00401     const size_t n = (N);                                               \
    00402     ccunit_assert_test__ccunit_str_t (__FILE__, __LINE__,               \
    00403                                       strncasecmp(ex, ac, n) OP 0,      \
    00404                                       "strncasecmp (" #EXPECT ", " #ACTUAL \
    00405                                       ", " #N ") " #OP " 0",            \
    00406                                       ex, ac);                          \
    00407   } while (0)
    00408
    00420 #define CCUNIT_ASSERT_TEST_OBJ(EXPECT, OP, ACTUAL, TOSTR)               \
    00421   do {                                                                  \
    00422     const _ccunit_obj_t ex = (EXPECT);                                  \
    00423     const _ccunit_obj_t ac = (ACTUAL);                                  \
    00424     const char* condstr = #OP " (" #EXPECT ", " #ACTUAL ")";            \
    00425     ccunit_assert_test__ccunit_obj_t (__FILE__, __LINE__,               \
    00426                                       OP(ex, ac), condstr, ex, ac,      \
    00427                                       (ccunit_toString_t)TOSTR);        \
    00428   } while (0)
    00429
    00446 #define CCUNIT_ASSERT_COND(TYP, CONDITION, EXPECT, ACTUAL)              \
    00447   do {                                                                  \
    00448     const TYP ex = (EXPECT);                                            \
    00449     const TYP ac = (ACTUAL);                                            \
    00450     ccunit_assert_test_ ## TYP (__FILE__, __LINE__, (CONDITION),        \
    00451                                 (#CONDITION), ex, ac);                  \
    00452   } while (0)
    00453
    00467 #define CCUNIT_ASSERT_NULL(ACTUAL)              \
    00468   CCUNIT_ASSERT_TEST_PTR(NULL, ==, ACTUAL)
    00469
    00478 #define CCUNIT_ASSERT_NOT_NULL(ACTUAL)          \
    00479   CCUNIT_ASSERT_TEST_PTR(NULL, !=, ACTUAL)
    00480
    00490 #define CCUNIT_ASSERT_EQ_INT(EXPECT, ACTUAL)    \
    00491   CCUNIT_ASSERT_TEST_INT (EXPECT, ==, ACTUAL)
    00492
    00502 #define CCUNIT_ASSERT_NE_INT(EXPECT, ACTUAL)    \
    00503   CCUNIT_ASSERT_TEST_INT (EXPECT, !=, ACTUAL)
    00504
    00514 #define CCUNIT_ASSERT_LT_INT(EXPECT, ACTUAL)    \
    00515   CCUNIT_ASSERT_TEST_INT (EXPECT, <, ACTUAL)
    00516
    00526 #define CCUNIT_ASSERT_LE_INT(EXPECT, ACTUAL)    \
    00527   CCUNIT_ASSERT_TEST_INT (EXPECT, <=, ACTUAL)
    00528
    00538 #define CCUNIT_ASSERT_GT_INT(EXPECT, ACTUAL)    \
    00539   CCUNIT_ASSERT_TEST_INT (EXPECT, >, ACTUAL)
    00540
    00550 #define CCUNIT_ASSERT_GE_INT(EXPECT, ACTUAL)    \
    00551   CCUNIT_ASSERT_TEST_INT (EXPECT, >=, ACTUAL)
    00552
    00562 #define CCUNIT_ASSERT_EQ_UINT(EXPECT, ACTUAL)   \
    00563   CCUNIT_ASSERT_TEST_UINT (EXPECT, ==, ACTUAL)
    00564
    00574 #define CCUNIT_ASSERT_NE_UINT(EXPECT, ACTUAL)   \
    00575   CCUNIT_ASSERT_TEST_UINT (EXPECT, !=, ACTUAL)
    00576
    00586 #define CCUNIT_ASSERT_LT_UINT(EXPECT, ACTUAL)   \
    00587   CCUNIT_ASSERT_TEST_UINT (EXPECT, <, ACTUAL)
    00588
    00598 #define CCUNIT_ASSERT_LE_UINT(EXPECT, ACTUAL)   \
    00599   CCUNIT_ASSERT_TEST_UINT (EXPECT, <=, ACTUAL)
    00600
    00610 #define CCUNIT_ASSERT_GT_UINT(EXPECT, ACTUAL)   \
    00611   CCUNIT_ASSERT_TEST_UINT (EXPECT, >, ACTUAL)
    00612
    00622 #define CCUNIT_ASSERT_GE_UINT(EXPECT, ACTUAL)   \
    00623   CCUNIT_ASSERT_TEST_UINT (EXPECT, >=, ACTUAL)
    00624
    00625 #if CCUNIT_HAVE_QUAD_T
    00626
    00635 #define CCUNIT_ASSERT_EQ_QUAD(EXPECT, ACTUAL)   \
    00636   CCUNIT_ASSERT_TEST_QUAD (EXPECT, ==, ACTUAL)
    00637
    00646 #define CCUNIT_ASSERT_NE_QUAD(EXPECT, ACTUAL)   \
    00647   CCUNIT_ASSERT_TEST_QUAD (EXPECT, !=, ACTUAL)
    00648
    00657 #define CCUNIT_ASSERT_LT_QUAD(EXPECT, ACTUAL)   \
    00658   CCUNIT_ASSERT_TEST_QUAD (EXPECT, <, ACTUAL)
    00659
    00668 #define CCUNIT_ASSERT_LE_QUAD(EXPECT, ACTUAL)   \
    00669   CCUNIT_ASSERT_TEST_QUAD (EXPECT, <=, ACTUAL)
    00670
    00679 #define CCUNIT_ASSERT_GT_QUAD(EXPECT, ACTUAL)   \
    00680   CCUNIT_ASSERT_TEST_QUAD (EXPECT, >, ACTUAL)
    00681
    00690 #define CCUNIT_ASSERT_GE_QUAD(EXPECT, ACTUAL)   \
    00691   CCUNIT_ASSERT_TEST_QUAD (EXPECT, >=, ACTUAL)
    00692 #endif
    00693
    00694 #if CCUNIT_HAVE_U_QUAD_T
    00695
    00704 #define CCUNIT_ASSERT_EQ_UQUAD(EXPECT, ACTUAL)  \
    00705   CCUNIT_ASSERT_TEST_UQUAD (EXPECT, ==, ACTUAL)
    00706
    00715 #define CCUNIT_ASSERT_NE_UQUAD(EXPECT, ACTUAL)  \
    00716   CCUNIT_ASSERT_TEST_UQUAD (EXPECT, !=, ACTUAL)
    00717
    00726 #define CCUNIT_ASSERT_LT_UQUAD(EXPECT, ACTUAL)  \
    00727   CCUNIT_ASSERT_TEST_UQUAD (EXPECT, <, ACTUAL)
    00728
    00737 #define CCUNIT_ASSERT_LE_UQUAD(EXPECT, ACTUAL)  \
    00738   CCUNIT_ASSERT_TEST_UQUAD (EXPECT, <=, ACTUAL)
    00739
    00748 #define CCUNIT_ASSERT_GT_UQUAD(EXPECT, ACTUAL)  \
    00749   CCUNIT_ASSERT_TEST_UQUAD (EXPECT, >, ACTUAL)
    00750
    00759 #define CCUNIT_ASSERT_GE_UQUAD(EXPECT, ACTUAL)  \
    00760   CCUNIT_ASSERT_TEST_UQUAD (EXPECT, >=, ACTUAL)
    00761 #endif
    00762
    00772 #define CCUNIT_ASSERT_EQ_STR(EXPECT, ACTUAL)    \
    00773   CCUNIT_ASSERT_TEST_STR (EXPECT, ==, ACTUAL)
    00774
    00783 #define CCUNIT_ASSERT_NE_STR(EXPECT, ACTUAL)    \
    00784   CCUNIT_ASSERT_TEST_STR (EXPECT, !=, ACTUAL)
    00785
    00794 #define CCUNIT_ASSERT_LT_STR(EXPECT, ACTUAL)    \
    00795   CCUNIT_ASSERT_TEST_STR (EXPECT, <, ACTUAL)
    00796
    00805 #define CCUNIT_ASSERT_LE_STR(EXPECT, ACTUAL)    \
    00806   CCUNIT_ASSERT_TEST_STR (EXPECT, <=, ACTUAL)
    00807
    00816 #define CCUNIT_ASSERT_GT_STR(EXPECT, ACTUAL)    \
    00817   CCUNIT_ASSERT_TEST_STR (EXPECT, >, ACTUAL)
    00818
    00827 #define CCUNIT_ASSERT_GE_STR(EXPECT, ACTUAL)    \
    00828   CCUNIT_ASSERT_TEST_STR (EXPECT, >=, ACTUAL)
    00829
    00839 #define CCUNIT_ASSERT_EQ_PTR(EXPECT, ACTUAL)    \
    00840   CCUNIT_ASSERT_TEST_PTR (EXPECT, ==, ACTUAL)
    00841
    00850 #define CCUNIT_ASSERT_NE_PTR(EXPECT, ACTUAL)    \
    00851   CCUNIT_ASSERT_TEST_PTR (EXPECT, !=, ACTUAL)
    00852
    00861 #define CCUNIT_ASSERT_LT_PTR(EXPECT, ACTUAL)    \
    00862   CCUNIT_ASSERT_TEST_PTR (EXPECT, <, ACTUAL)
    00863
    00872 #define CCUNIT_ASSERT_LE_PTR(EXPECT, ACTUAL)    \
    00873   CCUNIT_ASSERT_TEST_PTR (EXPECT, <=, ACTUAL)
    00874
    00883 #define CCUNIT_ASSERT_GT_PTR(EXPECT, ACTUAL)    \
    00884   CCUNIT_ASSERT_TEST_PTR (EXPECT, >, ACTUAL)
    00885
    00894 #define CCUNIT_ASSERT_GE_PTR(EXPECT, ACTUAL)    \
    00895   CCUNIT_ASSERT_TEST_PTR (EXPECT, >=, ACTUAL)
    00896
    00901 #endif

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