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

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

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

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

# CCUnitAssert.h

説明を見る。

    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.15 2010/08/22 01:46:25 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
    00068 #define CCUNIT_ASSERT(COND) ccunit_assert (__FILE__, __LINE__, COND, #COND)
    00069
    00086 #define CCUNIT_ASSERT_TEST(TYP, EXPECT, OP, ACTUAL)                     \
    00087   do {                                                                  \
    00088     const TYP ex = (EXPECT);                                            \
    00089     const TYP ac = (ACTUAL);                                            \
    00090     ccunit_assert_test_ ## TYP (__FILE__, __LINE__, (ex OP ac),         \
    00091                                 (#EXPECT " " #OP " " #ACTUAL),          \
    00092                                 ex, ac);                                \
    00093   } while (0)
    00094
    00105 #define CCUNIT_ASSERT_TEST_INT(EXPECT, OP, ACTUAL)              \
    00106   CCUNIT_ASSERT_TEST (int, EXPECT, OP, ACTUAL)
    00107
    00117 #define CCUNIT_ASSERT_TEST_UINT(EXPECT, OP, ACTUAL)             \
    00118   CCUNIT_ASSERT_TEST (u_int, EXPECT, OP, ACTUAL)
    00119
    00129 #define CCUNIT_ASSERT_TEST_LONG(EXPECT, OP, ACTUAL)             \
    00130   CCUNIT_ASSERT_TEST (long, EXPECT, OP, ACTUAL)
    00131
    00141 #define CCUNIT_ASSERT_TEST_ULONG(EXPECT, OP, ACTUAL)            \
    00142   CCUNIT_ASSERT_TEST (u_long, EXPECT, OP, ACTUAL)
    00143
    00153 #define CCUNIT_ASSERT_TEST_SHORT(EXPECT, OP, ACTUAL)            \
    00154   CCUNIT_ASSERT_TEST (short, EXPECT, OP, ACTUAL)
    00155
    00165 #define CCUNIT_ASSERT_TEST_USHORT(EXPECT, OP, ACTUAL)           \
    00166   CCUNIT_ASSERT_TEST (u_short, EXPECT, OP, ACTUAL)
    00167
    00177 #define CCUNIT_ASSERT_TEST_DOUBLE(EXPECT, OP, ACTUAL)           \
    00178   CCUNIT_ASSERT_TEST (double, EXPECT, OP, ACTUAL)
    00179
    00189 #define CCUNIT_ASSERT_TEST_FLOAT(EXPECT, OP, ACTUAL)            \
    00190   CCUNIT_ASSERT_TEST (float, EXPECT, OP, ACTUAL)
    00191 #if CCUNIT_HAVE_QUAD_T
    00192
    00202 #define CCUNIT_ASSERT_TEST_QUAD(EXPECT, OP, ACTUAL)             \
    00203   CCUNIT_ASSERT_TEST (quad_t, EXPECT, OP, ACTUAL)
    00204 #endif
    00205 #if CCUNIT_HAVE_U_QUAD_T
    00206
    00216 #define CCUNIT_ASSERT_TEST_UQUAD(EXPECT, OP, ACTUAL)            \
    00217   CCUNIT_ASSERT_TEST (u_quad_t, EXPECT, OP, ACTUAL)
    00218 #endif
    00219
    00229 #define CCUNIT_ASSERT_TEST_PTR(EXPECT, OP, ACTUAL)              \
    00230   CCUNIT_ASSERT_TEST (_ccunit_ptr_t, EXPECT, OP, ACTUAL)
    00231
    00242 #define CCUNIT_ASSERT_TEST_STR(EXPECT, OP, ACTUAL)                      \
    00243   do {                                                                  \
    00244     const _ccunit_str_t ex = (EXPECT);                                  \
    00245     const _ccunit_str_t ac = (ACTUAL);                                  \
    00246     const char* condstr = "strcmp (" #EXPECT ", " #ACTUAL ") " #OP " 0"; \
    00247     ccunit_assert_test__ccunit_str_t (__FILE__, __LINE__,               \
    00248                                       strcmp(ex, ac) OP 0, condstr, ex, ac); \
    00249   } while (0)
    00250
    00262 #define CCUNIT_ASSERT_TEST_NSTR(EXPECT, OP, ACTUAL, N)                  \
    00263   do {                                                                  \
    00264     const _ccunit_str_t ex = (EXPECT);                                  \
    00265     const _ccunit_str_t ac = (ACTUAL);                                  \
    00266     const size_t n = (N);                                               \
    00267     ccunit_assert_test__ccunit_str_t (__FILE__, __LINE__,               \
    00268                                       strncmp(ex, ac, n) OP 0,          \
    00269                                       "strncmp (" #EXPECT ", " #ACTUAL  \
    00270                                       ", " #N ") " #OP " 0",            \
    00271                                       ex, ac);                          \
    00272   } while (0)
    00273
    00284 #define CCUNIT_ASSERT_TEST_CASE_STR(EXPECT, OP, ACTUAL)                 \
    00285   do {                                                                  \
    00286     const _ccunit_str_t ex = (EXPECT);                                  \
    00287     const _ccunit_str_t ac = (ACTUAL);                                  \
    00288     const size_t n = (N);                                               \
    00289     ccunit_assert_test__ccunit_str_t (__FILE__, __LINE__,               \
    00290                                       strcasecmp(ex, ac) OP 0,          \
    00291                                       "strcasecmp (" #EXPECT ", " #ACTUAL \
    00292                                       ") " #OP " 0",                    \
    00293                                       ex, ac);                          \
    00294   } while (0)
    00295
    00307 #define CCUNIT_ASSERT_TEST_CASE_NSTR(EXPECT, OP, ACTUAL, N)             \
    00308   do {                                                                  \
    00309     const _ccunit_str_t ex = (EXPECT);                                  \
    00310     const _ccunit_str_t ac = (ACTUAL);                                  \
    00311     const size_t n = (N);                                               \
    00312     ccunit_assert_test__ccunit_str_t (__FILE__, __LINE__,               \
    00313                                       strncasecmp(ex, ac, n) OP 0,      \
    00314                                       "strncasecmp (" #EXPECT ", " #ACTUAL \
    00315                                       ", " #N ") " #OP " 0",            \
    00316                                       ex, ac);                          \
    00317   } while (0)
    00318
    00330 #define CCUNIT_ASSERT_TEST_OBJ(EXPECT, OP, ACTUAL, TOSTR)               \
    00331   do {                                                                  \
    00332     const _ccunit_obj_t ex = (EXPECT);                                  \
    00333     const _ccunit_obj_t ac = (ACTUAL);                                  \
    00334     const char* condstr = #OP " (" #EXPECT ", " #ACTUAL ")";            \
    00335     ccunit_assert_test__ccunit_obj_t (__FILE__, __LINE__,               \
    00336                                       OP(ex, ac), condstr, ex, ac,      \
    00337                                       (ccunit_toString_t)TOSTR);        \
    00338   } while (0)
    00339
    00356 #define CCUNIT_ASSERT_COND(TYP, CONDITION, EXPECT, ACTUAL)              \
    00357   do {                                                                  \
    00358     const TYP ex = (EXPECT);                                            \
    00359     const TYP ac = (ACTUAL);                                            \
    00360     ccunit_assert_test_ ## TYP (__FILE__, __LINE__, (CONDITION),        \
    00361                                 (#CONDITION), ex, ac);                  \
    00362   } while (0)
    00363
    00377 #define CCUNIT_ASSERT_NULL(ACTUAL)              \
    00378   CCUNIT_ASSERT_TEST_PTR(NULL, ==, ACTUAL)
    00379
    00388 #define CCUNIT_ASSERT_NOT_NULL(ACTUAL)          \
    00389   CCUNIT_ASSERT_TEST_PTR(NULL, !=, ACTUAL)
    00390
    00400 #define CCUNIT_ASSERT_EQ_INT(EXPECT, ACTUAL)    \
    00401   CCUNIT_ASSERT_TEST_INT (EXPECT, ==, ACTUAL)
    00402
    00412 #define CCUNIT_ASSERT_NE_INT(EXPECT, ACTUAL)    \
    00413   CCUNIT_ASSERT_TEST_INT (EXPECT, !=, ACTUAL)
    00414
    00424 #define CCUNIT_ASSERT_LT_INT(EXPECT, ACTUAL)    \
    00425   CCUNIT_ASSERT_TEST_INT (EXPECT, <, ACTUAL)
    00426
    00436 #define CCUNIT_ASSERT_LE_INT(EXPECT, ACTUAL)    \
    00437   CCUNIT_ASSERT_TEST_INT (EXPECT, <=, ACTUAL)
    00438
    00448 #define CCUNIT_ASSERT_GT_INT(EXPECT, ACTUAL)    \
    00449   CCUNIT_ASSERT_TEST_INT (EXPECT, >, ACTUAL)
    00450
    00460 #define CCUNIT_ASSERT_GE_INT(EXPECT, ACTUAL)    \
    00461   CCUNIT_ASSERT_TEST_INT (EXPECT, >=, ACTUAL)
    00462
    00472 #define CCUNIT_ASSERT_EQ_UINT(EXPECT, ACTUAL)   \
    00473   CCUNIT_ASSERT_TEST_UINT (EXPECT, ==, ACTUAL)
    00474
    00484 #define CCUNIT_ASSERT_NE_UINT(EXPECT, ACTUAL)   \
    00485   CCUNIT_ASSERT_TEST_UINT (EXPECT, !=, ACTUAL)
    00486
    00496 #define CCUNIT_ASSERT_LT_UINT(EXPECT, ACTUAL)   \
    00497   CCUNIT_ASSERT_TEST_UINT (EXPECT, <, ACTUAL)
    00498
    00508 #define CCUNIT_ASSERT_LE_UINT(EXPECT, ACTUAL)   \
    00509   CCUNIT_ASSERT_TEST_UINT (EXPECT, <=, ACTUAL)
    00510
    00520 #define CCUNIT_ASSERT_GT_UINT(EXPECT, ACTUAL)   \
    00521   CCUNIT_ASSERT_TEST_UINT (EXPECT, >, ACTUAL)
    00522
    00532 #define CCUNIT_ASSERT_GE_UINT(EXPECT, ACTUAL)   \
    00533   CCUNIT_ASSERT_TEST_UINT (EXPECT, >=, ACTUAL)
    00534
    00535 #if CCUNIT_HAVE_QUAD_T
    00536
    00545 #define CCUNIT_ASSERT_EQ_QUAD(EXPECT, ACTUAL)   \
    00546   CCUNIT_ASSERT_TEST_QUAD (EXPECT, ==, ACTUAL)
    00547
    00556 #define CCUNIT_ASSERT_NE_QUAD(EXPECT, ACTUAL)   \
    00557   CCUNIT_ASSERT_TEST_QUAD (EXPECT, !=, ACTUAL)
    00558
    00567 #define CCUNIT_ASSERT_LT_QUAD(EXPECT, ACTUAL)   \
    00568   CCUNIT_ASSERT_TEST_QUAD (EXPECT, <, ACTUAL)
    00569
    00578 #define CCUNIT_ASSERT_LE_QUAD(EXPECT, ACTUAL)   \
    00579   CCUNIT_ASSERT_TEST_QUAD (EXPECT, <=, ACTUAL)
    00580
    00589 #define CCUNIT_ASSERT_GT_QUAD(EXPECT, ACTUAL)   \
    00590   CCUNIT_ASSERT_TEST_QUAD (EXPECT, >, ACTUAL)
    00591
    00600 #define CCUNIT_ASSERT_GE_QUAD(EXPECT, ACTUAL)   \
    00601   CCUNIT_ASSERT_TEST_QUAD (EXPECT, >=, ACTUAL)
    00602 #endif
    00603
    00604 #if CCUNIT_HAVE_U_QUAD_T
    00605
    00614 #define CCUNIT_ASSERT_EQ_UQUAD(EXPECT, ACTUAL)  \
    00615   CCUNIT_ASSERT_TEST_UQUAD (EXPECT, ==, ACTUAL)
    00616
    00625 #define CCUNIT_ASSERT_NE_UQUAD(EXPECT, ACTUAL)  \
    00626   CCUNIT_ASSERT_TEST_UQUAD (EXPECT, !=, ACTUAL)
    00627
    00636 #define CCUNIT_ASSERT_LT_UQUAD(EXPECT, ACTUAL)  \
    00637   CCUNIT_ASSERT_TEST_UQUAD (EXPECT, <, ACTUAL)
    00638
    00647 #define CCUNIT_ASSERT_LE_UQUAD(EXPECT, ACTUAL)  \
    00648   CCUNIT_ASSERT_TEST_UQUAD (EXPECT, <=, ACTUAL)
    00649
    00658 #define CCUNIT_ASSERT_GT_UQUAD(EXPECT, ACTUAL)  \
    00659   CCUNIT_ASSERT_TEST_UQUAD (EXPECT, >, ACTUAL)
    00660
    00669 #define CCUNIT_ASSERT_GE_UQUAD(EXPECT, ACTUAL)  \
    00670   CCUNIT_ASSERT_TEST_UQUAD (EXPECT, >=, ACTUAL)
    00671 #endif
    00672
    00682 #define CCUNIT_ASSERT_EQ_STR(EXPECT, ACTUAL)    \
    00683   CCUNIT_ASSERT_TEST_STR (EXPECT, ==, ACTUAL)
    00684
    00693 #define CCUNIT_ASSERT_NE_STR(EXPECT, ACTUAL)    \
    00694   CCUNIT_ASSERT_TEST_STR (EXPECT, !=, ACTUAL)
    00695
    00704 #define CCUNIT_ASSERT_LT_STR(EXPECT, ACTUAL)    \
    00705   CCUNIT_ASSERT_TEST_STR (EXPECT, <, ACTUAL)
    00706
    00715 #define CCUNIT_ASSERT_LE_STR(EXPECT, ACTUAL)    \
    00716   CCUNIT_ASSERT_TEST_STR (EXPECT, <=, ACTUAL)
    00717
    00726 #define CCUNIT_ASSERT_GT_STR(EXPECT, ACTUAL)    \
    00727   CCUNIT_ASSERT_TEST_STR (EXPECT, >, ACTUAL)
    00728
    00737 #define CCUNIT_ASSERT_GE_STR(EXPECT, ACTUAL)    \
    00738   CCUNIT_ASSERT_TEST_STR (EXPECT, >=, ACTUAL)
    00739
    00749 #define CCUNIT_ASSERT_EQ_PTR(EXPECT, ACTUAL)    \
    00750   CCUNIT_ASSERT_TEST_PTR (EXPECT, ==, ACTUAL)
    00751
    00760 #define CCUNIT_ASSERT_NE_PTR(EXPECT, ACTUAL)    \
    00761   CCUNIT_ASSERT_TEST_PTR (EXPECT, !=, ACTUAL)
    00762
    00771 #define CCUNIT_ASSERT_LT_PTR(EXPECT, ACTUAL)    \
    00772   CCUNIT_ASSERT_TEST_PTR (EXPECT, <, ACTUAL)
    00773
    00782 #define CCUNIT_ASSERT_LE_PTR(EXPECT, ACTUAL)    \
    00783   CCUNIT_ASSERT_TEST_PTR (EXPECT, <=, ACTUAL)
    00784
    00793 #define CCUNIT_ASSERT_GT_PTR(EXPECT, ACTUAL)    \
    00794   CCUNIT_ASSERT_TEST_PTR (EXPECT, >, ACTUAL)
    00795
    00804 #define CCUNIT_ASSERT_GE_PTR(EXPECT, ACTUAL)    \
    00805   CCUNIT_ASSERT_TEST_PTR (EXPECT, >=, ACTUAL)
    00806
    00809 #ifndef CCUNIT_HAVE_U_CHAR
    00810 #define CCUNIT_HAVE_U_CHAR
    00811 typedef unsigned char u_char;
    00812 #endif
    00813 #ifndef CCUNIT_HAVE_U_INT
    00814 #define CCUNIT_HAVE_U_INT
    00815 typedef unsigned int u_int;
    00816 #endif
    00817 #ifndef CCUNIT_HAVE_U_SHORT
    00818 #define CCUNIT_HAVE_U_SHORT
    00819 typedef unsigned short u_short;
    00820 #endif
    00821 #ifndef CCUNIT_HAVE_U_LONG
    00822 #define CCUNIT_HAVE_U_LONG
    00823 typedef unsigned long u_long;
    00824 #endif
    00825 #ifndef CCUNIT_HAVE_QUAD_T
    00826 #ifdef CCUNIT_HAVE_INT64_T
    00827 #define CCUNIT_HAVE_QUAD_T 1
    00828 typedef int64_t quad_t;
    00829 #else  /* !CCUNIT_HAVE_INT64_T */
    00830 #if CCUNIT_HAVE_LONG_LONG
    00831 #define CCUNIT_HAVE_QUAD_T 1
    00832 typedef long long quad_t;
    00833 #endif  /* CCUNIT_HAVE_LONG_LONG */
    00834 #endif  /* CCUNIT_HAVE_INT64_T */
    00835 #endif  /* !CCUNIT_HAVE_QUAD_T */
    00836
    00837 #ifndef CCUNIT_HAVE_U_QUAD_T
    00838 #ifdef CCUNIT_HAVE_U_INT64_T
    00839 #define CCUNIT_HAVE_U_QUAD_T 1
    00840 typedef u_int64_t u_quad_t;
    00841 #else  /* !CCUNIT_HAVE_U_INT64_T */
    00842 #ifdef CCUNIT_HAVE_LONG_LONG
    00843 #define CCUNIT_HAVE_U_QUAD_T 1
    00844 typedef unsigned long long u_quad_t;
    00845 #endif  /* CCUNIT_HAVE_LONG_LONG */
    00846 #endif  /* CCUNIT_HAVE_U_INT64_T */
    00847 #endif  /* !CCUNIT_HAVE_U_QUAD_T */
    00848
    00849 typedef const char* _ccunit_str_t;
    00850 typedef const void* _ccunit_ptr_t;
    00851 typedef const void* _ccunit_obj_t;
    00853 /*
    00854  * Asserts that a condition is true. If it isn't it longjmp with
    00855  * _ccunit_runTest_env.
    00856  *
    00857  * @param TYP test value type
    00858  * @throws _ccunit_runTest_env If condition is false.
    00859  * @ingroup Assertions
    00860  */
    00861 #define DCL_CCUNIT_ASSERT_TEST_TYPE(TYP)                                \
    00862   extern void ccunit_assert_test_ ## TYP (const char* file, unsigned int line, \
    00863                                           bool cond, const char* condstr, \
    00864                                           TYP expect, TYP acutal)
    00865
    00866 DCL_CCUNIT_ASSERT_TEST_TYPE(char);
    00867 DCL_CCUNIT_ASSERT_TEST_TYPE(u_char);
    00868 DCL_CCUNIT_ASSERT_TEST_TYPE(int);
    00869 DCL_CCUNIT_ASSERT_TEST_TYPE(u_int);
    00870 DCL_CCUNIT_ASSERT_TEST_TYPE(short);
    00871 DCL_CCUNIT_ASSERT_TEST_TYPE(u_short);
    00872 DCL_CCUNIT_ASSERT_TEST_TYPE(long);
    00873 DCL_CCUNIT_ASSERT_TEST_TYPE(u_long);
    00874 DCL_CCUNIT_ASSERT_TEST_TYPE(float);
    00875 DCL_CCUNIT_ASSERT_TEST_TYPE(double);
    00876 DCL_CCUNIT_ASSERT_TEST_TYPE(_ccunit_str_t);
    00877 DCL_CCUNIT_ASSERT_TEST_TYPE(_ccunit_ptr_t);
    00878 #if CCUNIT_HAVE_QUAD_T
    00879 DCL_CCUNIT_ASSERT_TEST_TYPE(quad_t);
    00880 #endif
    00881 #if CCUNIT_HAVE_U_QUAD_T
    00882 DCL_CCUNIT_ASSERT_TEST_TYPE(u_quad_t);
    00883 #endif
    00884
    00885 typedef char* (*ccunit_toString_t)(_ccunit_obj_t);
    00886
    00887 extern void ccunit_assert_test__ccunit_obj_t (const char* file, unsigned int line,
    00888                                               bool cond, const char* condstr,
    00889                                               _ccunit_obj_t expect,
    00890                                               _ccunit_obj_t acutal,
    00891                                               ccunit_toString_t);
    00892
    00895 #endif

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