source: XIOS/dev/dev_olga/src/extern/boost/include/boost/detail/lightweight_test.hpp @ 1022

Last change on this file since 1022 was 1022, checked in by mhnguyen, 7 years ago
File size: 2.5 KB
Line 
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 <iostream>
28
29namespace boost
30{
31
32namespace detail
33{
34
35inline int & test_errors()
36{
37    static int x = 0;
38    return x;
39}
40
41inline void test_failed_impl(char const * expr, char const * file, int line, char const * function)
42{
43    std::cerr << file << "(" << line << "): test '" << expr << "' failed in function '" << function << "'" << std::endl;
44    ++test_errors();
45}
46
47inline void error_impl(char const * msg, char const * file, int line, char const * function)
48{
49    std::cerr << file << "(" << line << "): " << msg << " in function '" << function << "'" << std::endl;
50    ++test_errors();
51}
52
53template<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 )
54{
55    if( t == u )
56    {
57    }
58    else
59    {
60        std::cerr << file << "(" << line << "): test '" << expr1 << " == " << expr2
61            << "' failed in function '" << function << "': "
62            << "'" << t << "' != '" << u << "'" << std::endl;
63        ++test_errors();
64    }
65}
66
67} // namespace detail
68
69inline int report_errors()
70{
71    int errors = detail::test_errors();
72
73    if( errors == 0 )
74    {
75        std::cerr << "No errors detected." << std::endl;
76        return 0;
77    }
78    else
79    {
80        std::cerr << errors << " error" << (errors == 1? "": "s") << " detected." << std::endl;
81        return 1;
82    }
83}
84
85} // namespace boost
86
87#define BOOST_TEST(expr) ((expr)? (void)0: ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
88#define BOOST_ERROR(msg) ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
89#define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
90
91#endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
Note: See TracBrowser for help on using the repository browser.