os/ossrv/ossrv_pub/boost_apis/boost/detail/lightweight_test.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
#ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
sl@0
     2
#define BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
sl@0
     3
sl@0
     4
// MS compatible compilers support #pragma once
sl@0
     5
sl@0
     6
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
sl@0
     7
# pragma once
sl@0
     8
#endif
sl@0
     9
sl@0
    10
//
sl@0
    11
//  boost/detail/lightweight_test.hpp - lightweight test library
sl@0
    12
//
sl@0
    13
//  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
sl@0
    14
//
sl@0
    15
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
    16
// accompanying file LICENSE_1_0.txt or copy at
sl@0
    17
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
    18
//
sl@0
    19
//  BOOST_TEST(expression)
sl@0
    20
//  BOOST_ERROR(message)
sl@0
    21
//
sl@0
    22
//  int boost::report_errors()
sl@0
    23
//
sl@0
    24
sl@0
    25
#include <boost/current_function.hpp>
sl@0
    26
#include <iostream>
sl@0
    27
sl@0
    28
namespace boost
sl@0
    29
{
sl@0
    30
sl@0
    31
namespace detail
sl@0
    32
{
sl@0
    33
sl@0
    34
inline int & test_errors()
sl@0
    35
{
sl@0
    36
    static int x = 0;
sl@0
    37
    return x;
sl@0
    38
}
sl@0
    39
sl@0
    40
inline void test_failed_impl(char const * expr, char const * file, int line, char const * function)
sl@0
    41
{
sl@0
    42
    std::cerr << file << "(" << line << "): test '" << expr << "' failed in function '" << function << "'" << std::endl;
sl@0
    43
    ++test_errors();
sl@0
    44
}
sl@0
    45
sl@0
    46
inline void error_impl(char const * msg, char const * file, int line, char const * function)
sl@0
    47
{
sl@0
    48
    std::cerr << file << "(" << line << "): " << msg << " in function '" << function << "'" << std::endl;
sl@0
    49
    ++test_errors();
sl@0
    50
}
sl@0
    51
sl@0
    52
} // namespace detail
sl@0
    53
sl@0
    54
inline int report_errors()
sl@0
    55
{
sl@0
    56
    int errors = detail::test_errors();
sl@0
    57
sl@0
    58
    if(errors == 0)
sl@0
    59
    {
sl@0
    60
        std::cerr << "No errors detected." << std::endl;
sl@0
    61
        return 0;
sl@0
    62
    }
sl@0
    63
    else
sl@0
    64
    {
sl@0
    65
        std::cerr << errors << " error" << (errors == 1? "": "s") << " detected." << std::endl;
sl@0
    66
        return 1;
sl@0
    67
    }
sl@0
    68
}
sl@0
    69
sl@0
    70
} // namespace boost
sl@0
    71
sl@0
    72
#define BOOST_TEST(expr) ((expr)? (void)0: ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
sl@0
    73
#define BOOST_ERROR(msg) ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
sl@0
    74
sl@0
    75
#endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED