1163e693ccb01eedf392d45bd9dd131f7888cdb9
[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 ///////////////////////////////hh.p////////////////////////////////////////
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     COMPILE_FAIL() is used to check, that a certain piece of code will produce a compile time
63     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     \ref 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     \ref SENF_CHECK_EQUAL_COLLECTIONS() is like \c BOOST_CHECK_EQUAL_COLLECTIONS(). The only
109     difference is, that \ref 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     \ingroup unittest
114  */
115 #define SENF_CHECK_EQUAL_COLLECTIONS(a,b,c,d)                                                    \
116     BOOST_CHECK_EQUAL_COLLECTIONS(senf::test::nocharIterator(a), senf::test::nocharIterator(b),  \
117                                   senf::test::nocharIterator(c), senf::test::nocharIterator(d))
118
119 ///////////////////////////////hh.e////////////////////////////////////////
120 //#include "auto_unit_test.cci"
121 //#include "auto_unit_test.ct"
122 #include "auto_unit_test.cti"
123 #endif
124
125 \f
126 // Local Variables:
127 // mode: c++
128 // fill-column: 100
129 // comment-column: 40
130 // c-file-style: "senf"
131 // indent-tabs-mode: nil
132 // ispell-local-dictionary: "american"
133 // compile-command: "scons -u test"
134 // End: