Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Utils / auto_unit_test.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Boost.Test auto unit test compatibility across Boost V 1.33 and 1.34
25
26     This header file will allows to consistently use the Boost Version 1.33 syntax for defining auto
27     unit tests. If the available Boost version is 1.34, this file will automatically take care of
28     any necessary workarounds.
29
30     So, instead of <tt>\#include <boost/test/auto_unit_test.hpp></tt>, you should always write
31     <pre>
32     \#include "../Utils/auto_unit_test.hh"
33     </pre> (with possibliy adjusted path).
34  */
35
36 #ifndef HH_SENF_Utils_auto_unit_test_
37 #define HH_SENF_Utils_auto_unit_test_ 1
38
39 // Custom includes
40 #include <iostream>
41 #include <boost/version.hpp>
42
43 //#include "auto_unit_test.mpp"
44 #include "auto_unit_test.ih"
45 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46
47 #if BOOST_VERSION >= 103400
48
49 #   define BOOST_AUTO_UNIT_TEST BOOST_AUTO_TEST_CASE
50
51 #endif
52
53 #include <boost/test/auto_unit_test.hpp>
54
55 /** \defgroup unittest Boost.Test extensions
56
57     This module defines some additional extensions to Boost.Test
58  */
59
60 /** \brief Check for compile failure
61
62     \c COMPILE_FAIL() is used to check, that a certain piece of code will produce a compile
63     time failure.
64
65     \code
66     #ifdef COMPILE_CHECK
67
68     COMPILE_FAIL(foo)
69     {
70         // fails to compile ....
71         int x = "foo";
72     }
73
74     COMPILE_FAIL(bar)
75     { ... }
76
77     #endif
78     \endcode
79
80     This check is performed by the extended unit-test builder in \c senfscons.
81
82     \ingroup unittest
83  */
84 #define COMPILE_FAIL(n) void n()
85
86 /** \brief Show exception information
87
88     \c SENF_CHECK_NO_THROW() is an extension to \c BOOST_CHECK_NO_THROW() which will write out the
89     unabridged exception information when an exception is thrown in addition to signaling an error.
90
91     \ingroup unittest
92  */
93 #define SENF_CHECK_NO_THROW(expr)                                                               \
94     BOOST_CHECK_NO_THROW(                                                                       \
95         try { expr ; }                                                                          \
96         catch (std::exception & e) { std::cerr << e.what() << std::endl; throw; } )
97
98 namespace senf {
99 namespace test {
100
101     template <class Iterator>
102     typename detail::NoCharIterator<Iterator>::type nocharIterator(Iterator i);
103
104 }}
105
106 /** \brief Check ranges for equality, writing char's as int's
107
108     \c SENF_CHECK_EQUAL_COLLECTIONS() is like \c BOOST_CHECK_EQUAL_COLLECTIONS(). The only
109     difference is, that \c SENF_CHECK_EQUAL_COLLECTIONS() will write out collection values in
110     numeric form (and not as single characters) if the elements are of any char type. Other types
111     are not affected.
112
113     \hideinitializer
114     \ingroup unittest
115  */
116 #define SENF_CHECK_EQUAL_COLLECTIONS(left_begin, left_end, right_begin, right_end)              \
117     BOOST_CHECK_EQUAL_COLLECTIONS(                                                              \
118         senf::test::nocharIterator(left_begin), senf::test::nocharIterator(left_end),           \
119         senf::test::nocharIterator(right_begin), senf::test::nocharIterator(right_end))
120
121 /** \brief Define new test case
122
123     \c SENF_AUTO_UNIT_TEST() is like \c BOOST_AUTO_UNIT_TEST(). The only difference is, that
124     if an exception is thrown in the test case \c SENF_AUTO_UNIT_TEST() will write out the
125     complete what-message of the exception.
126
127     \hideinitializer
128     \ingroup unittest
129  */
130 #define SENF_AUTO_UNIT_TEST(name)                                                               \
131     void senf_test_body_##name();                                                               \
132     BOOST_AUTO_UNIT_TEST(name)                                                                  \
133     {                                                                                           \
134         try {                                                                                   \
135             senf_test_body_##name();                                                            \
136         }                                                                                       \
137         catch (std::exception & e) {                                                            \
138             std::cerr << e.what() << std::endl;                                                 \
139             throw;                                                                              \
140         }                                                                                       \
141     }                                                                                           \
142     void senf_test_body_##name()
143
144
145 #ifdef DOXYGEN
146     /** \brief Check for non-equality
147
148         \c SENF_CHECK_NOT_EQUAL() is the opposite of \c BOOST_CHECK_EQUAL.
149         \hideinitializer
150         \ingroup unittest
151      */
152     #define SENF_CHECK_NOT_EQUAL( Left, Rigth)
153 #else
154 #ifdef BOOST_CHECK_NE
155     #define SENF_CHECK_NOT_EQUAL( Left, Right) BOOST_CHECK_NE( Left, Right)
156 #else
157     #define SENF_CHECK_NOT_EQUAL( Left, Right) BOOST_CHECK( Left != Right)
158 #endif
159 #endif
160
161 //-/////////////////////////////////////////////////////////////////////////////////////////////////
162 //#include "auto_unit_test.cci"
163 //#include "auto_unit_test.ct"
164 #include "auto_unit_test.cti"
165 #endif
166
167 \f
168 // Local Variables:
169 // mode: c++
170 // fill-column: 100
171 // comment-column: 40
172 // c-file-style: "senf"
173 // indent-tabs-mode: nil
174 // ispell-local-dictionary: "american"
175 // compile-command: "scons -u test"
176 // End: