]>
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 : $RCSfile$ | |
9 | // | |
10 | // Version : $Revision: 74248 $ | |
11 | // | |
12 | // Description : inidiration interfaces to support manipulators and message output | |
13 | // *************************************************************************** | |
14 | ||
15 | #ifndef BOOST_TEST_TOOLS_DETAIL_INDIRECTIONS_HPP_112812GER | |
16 | #define BOOST_TEST_TOOLS_DETAIL_INDIRECTIONS_HPP_112812GER | |
17 | ||
18 | // Boost.Test | |
19 | #include <boost/test/tools/detail/fwd.hpp> | |
20 | ||
21 | #include <boost/test/tools/assertion_result.hpp> | |
f67539c2 TL |
22 | #include <boost/test/utils/lazy_ostream.hpp> |
23 | ||
24 | #include <boost/shared_ptr.hpp> | |
25 | #include <list> | |
7c673cae FG |
26 | |
27 | #include <boost/test/detail/suppress_warnings.hpp> | |
28 | ||
29 | //____________________________________________________________________________// | |
30 | ||
31 | namespace boost { | |
32 | namespace test_tools { | |
33 | namespace tt_detail { | |
34 | ||
f67539c2 TL |
35 | struct assertion_evaluation_context |
36 | { | |
37 | assertion_evaluation_context(bool has_report = false) | |
38 | : m_has_report(has_report) | |
39 | {} | |
40 | ||
41 | bool m_has_report; | |
42 | }; | |
43 | ||
7c673cae FG |
44 | // ************************************************************************** // |
45 | // ************** assertion_evaluate indirection ************** // | |
46 | // ************************************************************************** // | |
47 | ||
48 | template<typename E> | |
49 | struct assertion_evaluate_t { | |
f67539c2 TL |
50 | |
51 | typedef shared_ptr<assertion_evaluation_context> context_holder; | |
52 | ||
53 | assertion_evaluate_t( E const& e ) : m_e( e ), m_evaluate( true ) | |
54 | {} | |
55 | ||
56 | operator assertion_result() { return m_e.evaluate( m_evaluate ); } | |
57 | ||
58 | assertion_evaluate_t<E> | |
59 | stack_context(context_holder context) const { | |
60 | assertion_evaluate_t<E> added_context(*this); | |
61 | ||
62 | added_context.m_context_holder.push_back(context); | |
63 | added_context.m_evaluate = !context->m_has_report; | |
64 | return added_context; | |
65 | } | |
7c673cae FG |
66 | |
67 | E const& m_e; | |
f67539c2 TL |
68 | std::list< context_holder > m_context_holder; |
69 | bool m_evaluate; | |
7c673cae FG |
70 | }; |
71 | ||
72 | //____________________________________________________________________________// | |
73 | ||
74 | template<typename E> | |
75 | inline assertion_evaluate_t<E> | |
76 | assertion_evaluate( E const& e ) { return assertion_evaluate_t<E>( e ); } | |
77 | ||
78 | //____________________________________________________________________________// | |
79 | ||
80 | template<typename E, typename T> | |
81 | inline assertion_evaluate_t<E> | |
82 | operator<<( assertion_evaluate_t<E> const& ae, T const& ) { return ae; } | |
83 | ||
84 | //____________________________________________________________________________// | |
85 | ||
86 | // ************************************************************************** // | |
87 | // ************** assertion_text indirection ************** // | |
88 | // ************************************************************************** // | |
89 | ||
7c673cae | 90 | inline unit_test::lazy_ostream const& |
f67539c2 TL |
91 | assertion_text( unit_test::lazy_ostream const& et, unit_test::lazy_ostream const& s) { |
92 | if(!s.empty()) | |
93 | return s; | |
94 | return et; | |
95 | } | |
7c673cae FG |
96 | |
97 | //____________________________________________________________________________// | |
98 | ||
99 | // ************************************************************************** // | |
100 | // ************** assertion_evaluate indirection ************** // | |
101 | // ************************************************************************** // | |
102 | ||
103 | struct assertion_type { | |
f67539c2 TL |
104 | assertion_type(check_type ct = CHECK_MSG) : m_check_type(ct) |
105 | {} | |
106 | ||
107 | operator check_type() { return m_check_type; } | |
108 | check_type m_check_type; | |
7c673cae FG |
109 | }; |
110 | ||
111 | //____________________________________________________________________________// | |
112 | ||
113 | template<typename T> | |
114 | inline assertion_type | |
115 | operator<<( assertion_type const& at, T const& ) { return at; } | |
116 | ||
117 | //____________________________________________________________________________// | |
118 | ||
119 | } // namespace tt_detail | |
120 | } // namespace test_tools | |
121 | } // namespace boost | |
122 | ||
123 | #include <boost/test/detail/enable_warnings.hpp> | |
124 | ||
125 | #endif // BOOST_TEST_TOOLS_DETAIL_INDIRECTIONS_HPP_112812GER |