1 // (C) Copyright Gennadiy Rozental 2001.
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.
9 /// Enhanced result for test predicate that include message explaining failure
10 // ***************************************************************************
12 #ifndef BOOST_TEST_PREDICATE_RESULT_HPP_012705GER
13 #define BOOST_TEST_PREDICATE_RESULT_HPP_012705GER
16 #include <boost/test/utils/class_properties.hpp>
17 #include <boost/test/utils/wrap_stringstream.hpp>
18 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
21 #include <boost/shared_ptr.hpp>
22 #include <boost/detail/workaround.hpp>
25 #include <cstddef> // for std::size_t
27 #include <boost/test/detail/suppress_warnings.hpp>
29 //____________________________________________________________________________//
32 namespace test_tools {
34 // ************************************************************************** //
35 // ************** assertion_result ************** //
36 // ************************************************************************** //
38 //!@brief Type used for storing the result of an assertion.
39 class BOOST_TEST_DECL assertion_result {
42 typedef unit_test::const_string const_string;
45 struct dummy { void nonnull() {} };
48 typedef void (dummy::*safe_bool)();
52 assertion_result( bool pv_ )
53 : p_predicate_value( pv_ )
56 template<typename BoolConvertable>
57 assertion_result( BoolConvertable const& pv_ ) : p_predicate_value( !!pv_ ) {}
60 bool operator!() const { return !p_predicate_value; }
61 void operator=( bool pv_ ) { p_predicate_value.value = pv_; }
62 operator safe_bool() const { return !!p_predicate_value ? &dummy::nonnull : 0; }
65 BOOST_READONLY_PROPERTY( bool, (assertion_result) ) p_predicate_value;
68 bool has_empty_message() const { return !m_message; }
69 wrap_stringstream& message()
72 m_message.reset( new wrap_stringstream );
76 const_string message() const { return !m_message ? const_string() : const_string( m_message->str() ); }
80 shared_ptr<wrap_stringstream> m_message;
83 typedef assertion_result predicate_result;
85 } // namespace test_tools
88 #include <boost/test/detail/enable_warnings.hpp>
90 #endif // BOOST_TEST_PREDICATE_RESULT_HPP_012705GER