Utils: Add SENF_CHECK_EQUAL_COLLECTIONS() unit-test for better char range support
[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     { return typename detail::NoCharIterator<Iterator>::type (i); }
104
105     template <class Value>
106     typename detail::NoCharIterator<Value *>::type nocharIterator(Value * i)
107     { return typename detail::NoCharIterator<Value *>::type (i); }
108
109     template <class Value>
110     typename detail::NoCharIterator<Value const *>::type nocharIterator(Value const * i)
111     { return typename detail::NoCharIterator<Value const *>::type (i); }
112
113 }}
114
115 /** \brief Check ranges for equality, writing char's as int's
116
117     \ref SENF_CHECK_EQUAL_COLLECTIONS() is like \c BOOST_CHECK_EQUAL_COLLECTIONS(). The only
118     difference is, that \ref SENF_CHECK_EQUAL_COLLECTIONS() will write out collection values in
119     numeric form (and not as single characters) if the elements are of any char type. Other types
120     are not affected.
121
122     \ingroup unittest
123  */
124 #define SENF_CHECK_EQUAL_COLLECTIONS(a,b,c,d)                                                    \
125     BOOST_CHECK_EQUAL_COLLECTIONS(senf::test::nocharIterator(a), senf::test::nocharIterator(b),  \
126                                   senf::test::nocharIterator(c), senf::test::nocharIterator(d))
127
128 ///////////////////////////////hh.e////////////////////////////////////////
129 //#include "auto_unit_test.cci"
130 //#include "auto_unit_test.ct"
131 //#include "auto_unit_test.cti"
132 #endif
133
134 \f
135 // Local Variables:
136 // mode: c++
137 // fill-column: 100
138 // comment-column: 40
139 // c-file-style: "senf"
140 // indent-tabs-mode: nil
141 // ispell-local-dictionary: "american"
142 // compile-command: "scons -u test"
143 // End: