CppTest home page CppTest project page

cpptest-assert.h

Go to the documentation of this file.
00001 // ---
00002 //
00003 // $Id: cpptest-assert.h,v 1.3 2005/06/08 08:08:06 nilu Exp $
00004 //
00005 // CppTest - A C++ Unit Testing Framework
00006 // Copyright (c) 2003 Niklas Lundell
00007 //
00008 // ---
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2 of the License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the
00022 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023 // Boston, MA 02111-1307, USA.
00024 //
00025 // ---
00026 
00029 #ifndef CPPTEST_ASSERT_H
00030 #define CPPTEST_ASSERT_H
00031 
00056 #define TEST_FAIL(msg) \
00057     {                                                               \
00058         assertment(::Test::Source(__FILE__, __LINE__, (msg) != 0 ? #msg : "")); \
00059         if (!continue_after_failure()) return;                      \
00060     }
00061 
00084 #define TEST_ASSERT(expr)                                           \
00085     {                                                               \
00086         if (!(expr))                                                \
00087         {                                                           \
00088             assertment(::Test::Source(__FILE__, __LINE__, #expr));  \
00089             if (!continue_after_failure()) return;                  \
00090         }                                                           \
00091     }
00092 
00104 #define TEST_ASSERT_MSG(expr, msg)                                  \
00105     {                                                               \
00106         if (!(expr))                                                \
00107         {                                                           \
00108             assertment(::Test::Source(__FILE__, __LINE__, msg));    \
00109             if (!continue_after_failure()) return;                  \
00110         }                                                           \
00111     }
00112 
00126 #define TEST_ASSERT_DELTA(a, b, delta)                              \
00127     {                                                               \
00128         if (((b) < (a) - (delta)) || ((b) > (a) + (delta)))         \
00129         {                                                           \
00130             assertment(::Test::Source(__FILE__, __LINE__,           \
00131                        "delta(" #a ", " #b ", " #delta ")" ));      \
00132             if (!continue_after_failure()) return;                  \
00133         }                                                           \
00134     }
00135 
00150 #define TEST_ASSERT_DELTA_MSG(a, b, delta, msg)                     \
00151     {                                                               \
00152         if (((b) < (a) - (delta)) || ((b) > (a) + (delta)))         \
00153         {                                                           \
00154             assertment(::Test::Source(__FILE__, __LINE__, msg));    \
00155             if (!continue_after_failure()) return;                  \
00156         }                                                           \
00157     }
00158     
00171 #define TEST_THROWS(expr, x)                                        \
00172     {                                                               \
00173         bool __expected = false;                                    \
00174         try { expr; }                                               \
00175         catch (x)           { __expected = true; }                  \
00176         catch (...)         {}                                      \
00177         if (!__expected)                                            \
00178         {                                                           \
00179             assertment(::Test::Source(__FILE__, __LINE__, #expr));  \
00180             if (!continue_after_failure()) return;                  \
00181         }                                                           \
00182     }
00183 
00197 #define TEST_THROWS_MSG(expr, x, msg)                               \
00198     {                                                               \
00199         bool __expected = false;                                    \
00200         try { expr; }                                               \
00201         catch (x)           { __expected = true; }                  \
00202         catch (...)         {}                                      \
00203         if (!__expected)                                            \
00204         {                                                           \
00205             assertment(::Test::Source(__FILE__, __LINE__, msg));    \
00206             if (!continue_after_failure()) return;                  \
00207         }                                                           \
00208     }
00209 
00221 #define TEST_THROWS_ANYTHING(expr)                                  \
00222     {                                                               \
00223         bool __expected = false;                                    \
00224         try { expr; }                                               \
00225         catch (...) { __expected = true; }                          \
00226         if (!__expected)                                            \
00227         {                                                           \
00228             assertment(::Test::Source(__FILE__, __LINE__, #expr));  \
00229             if (!continue_after_failure()) return;                  \
00230         }                                                           \
00231     }
00232 
00245 #define TEST_THROWS_ANYTHING_MSG(expr, msg)                         \
00246     {                                                               \
00247         bool __expected = false;                                    \
00248         try { expr; }                                               \
00249         catch (...) { __expected = true; }                          \
00250         if (!__expected)                                            \
00251         {                                                           \
00252             assertment(::Test::Source(__FILE__, __LINE__, msg));    \
00253             if (!continue_after_failure()) return;                  \
00254         }                                                           \
00255     }
00256     
00268 #define TEST_THROWS_NOTHING(expr)                                   \
00269     {                                                               \
00270         bool __expected = true;                                     \
00271         try { expr; }                                               \
00272         catch (...) { __expected = false; }                         \
00273         if (!__expected)                                            \
00274         {                                                           \
00275             assertment(::Test::Source(__FILE__, __LINE__, #expr));  \
00276             if (!continue_after_failure()) return;                  \
00277         }                                                           \
00278     }
00279 
00292 #define TEST_THROWS_NOTHING_MSG(expr, msg)                          \
00293     {                                                               \
00294         bool __expected = true;                                     \
00295         try { expr; }                                               \
00296         catch (...) { __expected = false; }                         \
00297         if (!__expected)                                            \
00298         {                                                           \
00299             assertment(::Test::Source(__FILE__, __LINE__, msg));    \
00300             if (!continue_after_failure()) return;                  \
00301         }                                                           \
00302     }
00303 
00329 
00330 #endif // #ifndef CPPTEST_ASSERT_H
00331 

Supported by:

SourceForge Logo