source: NonGTP/Boost/boost/test/predicate_result.hpp @ 857

Revision 857, 3.6 KB checked in by igarcia, 19 years ago (diff)
Line 
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.6 $
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
34namespace boost {
35
36namespace test_tools {
37
38// ************************************************************************** //
39// **************                predicate_result              ************** //
40// ************************************************************************** //
41
42class predicate_result {
43    typedef unit_test::const_string      const_string;
44public:
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
70private:
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.6  2005/03/23 21:02:17  rogeeff
88//  Sunpro CC 5.3 fixes
89//
90//  Revision 1.5  2005/02/20 08:27:06  rogeeff
91//  This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
92//
93//  Revision 1.4  2005/02/03 20:39:12  rogeeff
94//  m_message zero init for sunpro
95//
96//  Revision 1.3  2005/02/01 06:40:06  rogeeff
97//  copyright update
98//  old log entries removed
99//  minor stilistic changes
100//  depricated tools removed
101//
102//  Revision 1.2  2005/01/31 20:07:19  rogeeff
103//  Sunpro CC 5.3 workarounds
104//
105//  Revision 1.1  2005/01/30 03:24:51  rogeeff
106//  extended_predicate_result renamed ot predicate_result and moved into separate file
107//
108// ***************************************************************************
109
110#endif // BOOST_TEST_PREDICATE_RESULT_HPP_012705GER
Note: See TracBrowser for help on using the repository browser.