1 // (C) Copyright Gennadiy Rozental 2001-2008.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : enhanced result for test predicate that include message explaining failure
13 // ***************************************************************************
15 #ifndef BOOST_TEST_PREDICATE_RESULT_HPP_012705GER
16 #define BOOST_TEST_PREDICATE_RESULT_HPP_012705GER
19 #include <boost/test/utils/class_properties.hpp>
20 #include <boost/test/utils/wrap_stringstream.hpp>
21 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
24 #include <boost/shared_ptr.hpp>
25 #include <boost/detail/workaround.hpp>
28 #include <cstddef> // for std::size_t
30 #include <boost/test/detail/suppress_warnings.hpp>
32 //____________________________________________________________________________//
36 namespace test_tools
{
38 // ************************************************************************** //
39 // ************** predicate_result ************** //
40 // ************************************************************************** //
42 class BOOST_TEST_DECL predicate_result
{
43 typedef unit_test::const_string const_string
;
44 struct dummy
{ void nonnull() {}; };
45 typedef void (dummy::*safe_bool
)();
49 predicate_result( bool pv_
)
50 : p_predicate_value( pv_
)
53 template<typename BoolConvertable
>
54 predicate_result( BoolConvertable
const& pv_
) : p_predicate_value( !!pv_
) {}
57 bool operator!() const { return !p_predicate_value
; }
58 void operator=( bool pv_
) { p_predicate_value
.value
= pv_
; }
59 operator safe_bool() const { return !!p_predicate_value
? &dummy::nonnull
: 0; }
62 BOOST_READONLY_PROPERTY( bool, (predicate_result
) ) p_predicate_value
;
65 bool has_empty_message() const { return !m_message
; }
66 wrap_stringstream
& message()
69 m_message
.reset( new wrap_stringstream
);
73 const_string
message() const { return !m_message
? const_string() : const_string( m_message
->str() ); }
77 shared_ptr
<wrap_stringstream
> m_message
;
80 } // namespace test_tools
84 //____________________________________________________________________________//
86 #include <boost/test/detail/enable_warnings.hpp>
88 #endif // BOOST_TEST_PREDICATE_RESULT_HPP_012705GER