]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) | |
5 | ||
6 | // See http://www.boost.org/libs/test for the library home page. | |
7 | // | |
8 | /// @file | |
9 | /// Enhanced result for test predicate that include message explaining failure | |
10 | // *************************************************************************** | |
11 | ||
12 | #ifndef BOOST_TEST_PREDICATE_RESULT_HPP_012705GER | |
13 | #define BOOST_TEST_PREDICATE_RESULT_HPP_012705GER | |
14 | ||
15 | // Boost.Test | |
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> | |
19 | ||
20 | // Boost | |
21 | #include <boost/shared_ptr.hpp> | |
22 | #include <boost/detail/workaround.hpp> | |
23 | ||
24 | // STL | |
25 | #include <cstddef> // for std::size_t | |
26 | ||
27 | #include <boost/test/detail/suppress_warnings.hpp> | |
28 | ||
29 | //____________________________________________________________________________// | |
30 | ||
31 | namespace boost { | |
32 | namespace test_tools { | |
33 | ||
34 | // ************************************************************************** // | |
35 | // ************** assertion_result ************** // | |
36 | // ************************************************************************** // | |
37 | ||
38 | //!@brief Type used for storing the result of an assertion. | |
39 | class BOOST_TEST_DECL assertion_result { | |
40 | ||
41 | //!@internal | |
42 | typedef unit_test::const_string const_string; | |
43 | ||
44 | //!@internal | |
45 | struct dummy { void nonnull() {} }; | |
46 | ||
47 | //!@internal | |
48 | typedef void (dummy::*safe_bool)(); | |
49 | ||
50 | public: | |
51 | // Constructor | |
52 | assertion_result( bool pv_ ) | |
53 | : p_predicate_value( pv_ ) | |
54 | {} | |
55 | ||
56 | template<typename BoolConvertable> | |
57 | assertion_result( BoolConvertable const& pv_ ) : p_predicate_value( !!pv_ ) {} | |
58 | ||
59 | // Access methods | |
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; } | |
63 | ||
64 | // Public properties | |
65 | BOOST_READONLY_PROPERTY( bool, (assertion_result) ) p_predicate_value; | |
66 | ||
67 | // Access methods | |
68 | bool has_empty_message() const { return !m_message; } | |
69 | wrap_stringstream& message() | |
70 | { | |
71 | if( !m_message ) | |
72 | m_message.reset( new wrap_stringstream ); | |
73 | ||
74 | return *m_message; | |
75 | } | |
76 | const_string message() const { return !m_message ? const_string() : const_string( m_message->str() ); } | |
77 | ||
78 | private: | |
79 | // Data members | |
80 | shared_ptr<wrap_stringstream> m_message; | |
81 | }; | |
82 | ||
83 | typedef assertion_result predicate_result; | |
84 | ||
85 | } // namespace test_tools | |
86 | } // namespace boost | |
87 | ||
88 | #include <boost/test/detail/enable_warnings.hpp> | |
89 | ||
90 | #endif // BOOST_TEST_PREDICATE_RESULT_HPP_012705GER |