blob: 13dc668247102719779036f849b3cd03ef1771f2 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// (C) Copyright Gennadiy Rozental 2001-2008.
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$
9//
10// Version : $Revision: 54633 $
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 <ndnboost/test/utils/class_properties.hpp>
20#include <ndnboost/test/utils/wrap_stringstream.hpp>
21#include <ndnboost/test/utils/basic_cstring/basic_cstring.hpp>
22
23// Boost
24#include <ndnboost/shared_ptr.hpp>
25#include <ndnboost/detail/workaround.hpp>
26
27// STL
28#include <cstddef> // for std::size_t
29
30#include <ndnboost/test/detail/suppress_warnings.hpp>
31
32//____________________________________________________________________________//
33
34namespace ndnboost {
35
36namespace test_tools {
37
38// ************************************************************************** //
39// ************** predicate_result ************** //
40// ************************************************************************** //
41
42class BOOST_TEST_DECL predicate_result {
43 typedef unit_test::const_string const_string;
44 struct dummy { void nonnull() {}; };
45 typedef void (dummy::*safe_bool)();
46
47public:
48 // Constructor
49 predicate_result( bool pv_ )
50 : p_predicate_value( pv_ )
51 {}
52
53 template<typename BoolConvertable>
54 predicate_result( BoolConvertable const& pv_ ) : p_predicate_value( !!pv_ ) {}
55
56 // Access methods
57 bool operator!() const { return !p_predicate_value; }
58 void operator=( bool pv_ ) { p_predicate_value.value = pv_; }
59 operator safe_bool() const { return !!p_predicate_value ? &dummy::nonnull : 0; }
60
61 // Public properties
62 BOOST_READONLY_PROPERTY( bool, (predicate_result) ) p_predicate_value;
63
64 // Access methods
65 bool has_empty_message() const { return !m_message; }
66 wrap_stringstream& message()
67 {
68 if( !m_message )
69 m_message.reset( new wrap_stringstream );
70
71 return *m_message;
72 }
73 const_string message() const { return !m_message ? const_string() : const_string( m_message->str() ); }
74
75private:
76 // Data members
77 shared_ptr<wrap_stringstream> m_message;
78};
79
80} // namespace test_tools
81
82} // namespace ndnboost
83
84//____________________________________________________________________________//
85
86#include <ndnboost/test/detail/enable_warnings.hpp>
87
88#endif // BOOST_TEST_PREDICATE_RESULT_HPP_012705GER