|
1 // (C) Copyright Gennadiy Rozental 2001-2005. |
|
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 : $RCSfile: predicate_result.hpp,v $ |
|
9 // |
|
10 // Version : $Revision: 1.7 $ |
|
11 // |
|
12 // Description : enhanced result for test predicate that include message explaining failure |
|
13 // *************************************************************************** |
|
14 |
|
15 #ifndef BOOST_TEST_PREDICATE_RESULT_HPP_012705GER |
|
16 #define BOOST_TEST_PREDICATE_RESULT_HPP_012705GER |
|
17 |
|
18 // Boost.Test |
|
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> |
|
22 |
|
23 // Boost |
|
24 #include <boost/shared_ptr.hpp> |
|
25 #include <boost/detail/workaround.hpp> |
|
26 |
|
27 // STL |
|
28 #include <cstddef> // for std::size_t |
|
29 |
|
30 #include <boost/test/detail/suppress_warnings.hpp> |
|
31 |
|
32 //____________________________________________________________________________// |
|
33 |
|
34 namespace boost { |
|
35 |
|
36 namespace test_tools { |
|
37 |
|
38 // ************************************************************************** // |
|
39 // ************** predicate_result ************** // |
|
40 // ************************************************************************** // |
|
41 |
|
42 class BOOST_TEST_DECL predicate_result { |
|
43 typedef unit_test::const_string const_string; |
|
44 public: |
|
45 // Constructor |
|
46 predicate_result( bool pv_ ) |
|
47 : p_predicate_value( pv_ ) |
|
48 {} |
|
49 |
|
50 template<typename BoolConvertable> |
|
51 predicate_result( BoolConvertable const& pv_ ) : p_predicate_value( !!pv_ ) {} |
|
52 |
|
53 bool operator!() const { return !p_predicate_value; } |
|
54 void operator=( bool pv_ ) { p_predicate_value.value = pv_; } |
|
55 |
|
56 // Public properties |
|
57 BOOST_READONLY_PROPERTY( bool, (predicate_result) ) p_predicate_value; |
|
58 |
|
59 // Access methods |
|
60 bool has_empty_message() const { return !m_message; } |
|
61 wrap_stringstream& message() |
|
62 { |
|
63 if( !m_message ) |
|
64 m_message.reset( new wrap_stringstream ); |
|
65 |
|
66 return *m_message; |
|
67 } |
|
68 const_string message() const { return !m_message ? const_string() : const_string( m_message->str() ); } |
|
69 |
|
70 private: |
|
71 // Data members |
|
72 shared_ptr<wrap_stringstream> m_message; |
|
73 }; |
|
74 |
|
75 } // namespace test_tools |
|
76 |
|
77 } // namespace boost |
|
78 |
|
79 //____________________________________________________________________________// |
|
80 |
|
81 #include <boost/test/detail/enable_warnings.hpp> |
|
82 |
|
83 // *************************************************************************** |
|
84 // Revision History : |
|
85 // |
|
86 // $Log: predicate_result.hpp,v $ |
|
87 // Revision 1.7 2005/12/14 05:16:49 rogeeff |
|
88 // dll support introduced |
|
89 // |
|
90 // Revision 1.6 2005/03/23 21:02:17 rogeeff |
|
91 // Sunpro CC 5.3 fixes |
|
92 // |
|
93 // Revision 1.5 2005/02/20 08:27:06 rogeeff |
|
94 // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates |
|
95 // |
|
96 // Revision 1.4 2005/02/03 20:39:12 rogeeff |
|
97 // m_message zero init for sunpro |
|
98 // |
|
99 // Revision 1.3 2005/02/01 06:40:06 rogeeff |
|
100 // copyright update |
|
101 // old log entries removed |
|
102 // minor stilistic changes |
|
103 // depricated tools removed |
|
104 // |
|
105 // Revision 1.2 2005/01/31 20:07:19 rogeeff |
|
106 // Sunpro CC 5.3 workarounds |
|
107 // |
|
108 // Revision 1.1 2005/01/30 03:24:51 rogeeff |
|
109 // extended_predicate_result renamed ot predicate_result and moved into separate file |
|
110 // |
|
111 // *************************************************************************** |
|
112 |
|
113 #endif // BOOST_TEST_PREDICATE_RESULT_HPP_012705GER |