Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:40

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 /// @file
0009 /// Enhanced result for test predicate that include message explaining failure
0010 // ***************************************************************************
0011 
0012 #ifndef BOOST_TEST_PREDICATE_RESULT_HPP_012705GER
0013 #define BOOST_TEST_PREDICATE_RESULT_HPP_012705GER
0014 
0015 // Boost.Test
0016 #include <boost/test/utils/class_properties.hpp>
0017 #include <boost/test/utils/wrap_stringstream.hpp>
0018 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
0019 
0020 // Boost
0021 #include <boost/shared_ptr.hpp>
0022 #include <boost/detail/workaround.hpp>
0023 
0024 // STL
0025 #include <cstddef>          // for std::size_t
0026 
0027 #include <boost/test/detail/suppress_warnings.hpp>
0028 
0029 //____________________________________________________________________________//
0030 
0031 namespace boost {
0032 namespace test_tools {
0033 
0034 // ************************************************************************** //
0035 // **************                assertion_result              ************** //
0036 // ************************************************************************** //
0037 
0038 //!@brief Type used for storing the result of an assertion.
0039 class BOOST_TEST_DECL assertion_result {
0040 
0041     //!@internal
0042     typedef unit_test::const_string      const_string;
0043 
0044     //!@internal
0045     struct dummy { void nonnull() {} };
0046 
0047     //!@internal
0048     typedef void (dummy::*safe_bool)();
0049 
0050 public:
0051     // Constructor
0052     assertion_result( bool pv_ )
0053     : p_predicate_value( pv_ )
0054     {}
0055 
0056     template<typename BoolConvertable>
0057     assertion_result( BoolConvertable const& pv_ ) : p_predicate_value( !!pv_ ) {}
0058 
0059     // Access methods
0060     bool                operator!() const           { return !p_predicate_value; }
0061     void                operator=( bool pv_ )       { p_predicate_value.value = pv_; }
0062     operator            safe_bool() const           { return !!p_predicate_value ? &dummy::nonnull : 0; }
0063 
0064     // Public properties
0065     BOOST_READONLY_PROPERTY( bool, (assertion_result) ) p_predicate_value;
0066 
0067     // Access methods
0068     bool                has_empty_message() const   { return !m_message; }
0069     wrap_stringstream&  message()
0070     {
0071         if( !m_message )
0072             m_message.reset( new wrap_stringstream );
0073 
0074         return *m_message;
0075     }
0076     const_string        message() const                   { return !m_message ? const_string() : const_string( m_message->str() ); }
0077 
0078 private:
0079     // Data members
0080     shared_ptr<wrap_stringstream> m_message;
0081 };
0082 
0083 typedef assertion_result predicate_result;
0084 
0085 } // namespace test_tools
0086 } // namespace boost
0087 
0088 #include <boost/test/detail/enable_warnings.hpp>
0089 
0090 #endif // BOOST_TEST_PREDICATE_RESULT_HPP_012705GER