]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/lightweight_test.hpp
update to boost 1.46.1. Tested on Win, Mac, Linux, GCC 4.2, 4.4, 4.5, 4.6
[lyx.git] / boost / boost / detail / lightweight_test.hpp
1 #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
2 #define BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
3
4 // MS compatible compilers support #pragma once
5
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
7 # pragma once
8 #endif
9
10 //
11 //  boost/detail/lightweight_test.hpp - lightweight test library
12 //
13 //  Copyright (c) 2002, 2009 Peter Dimov
14 //
15 //  Distributed under the Boost Software License, Version 1.0.
16 //  See accompanying file LICENSE_1_0.txt or copy at
17 //  http://www.boost.org/LICENSE_1_0.txt
18 //
19 //  BOOST_TEST(expression)
20 //  BOOST_ERROR(message)
21 //  BOOST_TEST_EQ(expr1, expr2)
22 //
23 //  int boost::report_errors()
24 //
25
26 #include <boost/current_function.hpp>
27 #include <boost/assert.hpp>
28 #include <iostream>
29
30 namespace boost
31 {
32
33 namespace detail
34 {
35
36 struct report_errors_reminder
37 {
38   bool called_report_errors_function;
39   report_errors_reminder() : called_report_errors_function(false) {}
40  ~report_errors_reminder()
41   {
42     BOOST_ASSERT(called_report_errors_function);  // verify report_errors() was called  
43   }
44 };
45
46 inline report_errors_reminder& report_errors_remind()
47 {
48   static report_errors_reminder r;
49   return r;
50 }
51
52 inline int & test_errors()
53 {
54     static int x = 0;
55     report_errors_remind();
56     return x;
57 }
58
59 inline void test_failed_impl(char const * expr, char const * file, int line, char const * function)
60 {
61     std::cerr << file << "(" << line << "): test '" << expr << "' failed in function '" << function << "'" << std::endl;
62     ++test_errors();
63 }
64
65 inline void error_impl(char const * msg, char const * file, int line, char const * function)
66 {
67     std::cerr << file << "(" << line << "): " << msg << " in function '" << function << "'" << std::endl;
68     ++test_errors();
69 }
70
71 template<class T, class U> inline void test_eq_impl( char const * expr1, char const * expr2, char const * file, int line, char const * function, T const & t, U const & u )
72 {
73     if( t == u )
74     {
75     }
76     else
77     {
78         std::cerr << file << "(" << line << "): test '" << expr1 << " == " << expr2
79             << "' failed in function '" << function << "': "
80             << "'" << t << "' != '" << u << "'" << std::endl;
81         ++test_errors();
82     }
83 }
84
85 } // namespace detail
86
87 inline int report_errors()
88 {
89     detail::report_errors_remind().called_report_errors_function = true;
90
91     int errors = detail::test_errors();
92
93     if( errors == 0 )
94     {
95         std::cerr << "No errors detected." << std::endl;
96         return 0;
97     }
98     else
99     {
100         std::cerr << errors << " error" << (errors == 1? "": "s") << " detected." << std::endl;
101         return 1;
102     }
103 }
104
105 } // namespace boost
106
107 #define BOOST_TEST(expr) ((expr)? (void)0: ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
108 #define BOOST_ERROR(msg) ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
109 #define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
110
111 #endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED