1 //  (C) Copyright Gennadiy Rozental 2001-2014.
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 /// @brief output_test_stream class definition
10 // ***************************************************************************
11 
12 #ifndef BOOST_TEST_OUTPUT_TEST_STREAM_HPP_012705GER
13 #define BOOST_TEST_OUTPUT_TEST_STREAM_HPP_012705GER
14 
15 // Boost.Test
16 #include <boost/test/detail/global_typedef.hpp>
17 #include <boost/test/utils/wrap_stringstream.hpp>
18 #include <boost/test/tools/assertion_result.hpp>
19 
20 // STL
21 #include <cstddef>          // for std::size_t
22 
23 #include <boost/test/detail/suppress_warnings.hpp>
24 
25 //____________________________________________________________________________//
26 
27 // ************************************************************************** //
28 // **************               output_test_stream             ************** //
29 // ************************************************************************** //
30 
31 
32 
33 namespace boost {
34 namespace test_tools {
35 
36 //! Class to be used to simplify testing of ostream-based output operations
37 class BOOST_TEST_DECL output_test_stream : public wrap_stringstream::wrapped_stream {
38     typedef unit_test::const_string const_string;
39 public:
40     //! Constructor
41     //!
42     //!@param[in] pattern_file_name indicates the name of the file for matching. If the
43     //!           string is empty, the standard input or output streams are used instead
44     //!           (depending on match_or_save)
45     //!@param[in] match_or_save if true, the pattern file will be read, otherwise it will be
46     //!           written
47     //!@param[in] text_or_binary if false, opens the stream in binary mode. Otherwise the stream
48     //!           is opened with default flags and the carriage returns are ignored.
49     explicit        output_test_stream( const_string    pattern_file_name = const_string(),
50                                         bool            match_or_save     = true,
51                                         bool            text_or_binary    = true );
52 
53     // Destructor
54     ~output_test_stream();
55 
56     //! Checks if the stream is empty
57     //!
58     //!@param[in] flush_stream if true, flushes the stream after the call
59     assertion_result    is_empty( bool flush_stream = true );
60 
61     //! Checks the length of the stream
62     //!
63     //!@param[in] length target length
64     //!@param[in] flush_stream if true, flushes the stream after the call. Set to false to call
65     //!           additional checks on the same content.
66     assertion_result    check_length( std::size_t length, bool flush_stream = true );
67 
68     //! Checks the content of the stream against a string
69     //!
70     //!@param[in] arg_ the target stream
71     //!@param[in] flush_stream if true, flushes the stream after the call.
72     assertion_result    is_equal( const_string arg_, bool flush_stream = true );
73 
74     //! Checks the content of the stream against a pattern file
75     //!
76     //!@param[in] flush_stream if true, flushes the stream after the call.
77     assertion_result    match_pattern( bool flush_stream = true );
78 
79     //! Flushes the stream
80     void            flush();
81 
82 private:
83     // helper functions
84     std::size_t     length();
85     void            sync();
86 
87     struct Impl;
88     Impl*           m_pimpl;
89 };
90 
91 } // namespace test_tools
92 } // namespace boost
93 
94 #include <boost/test/detail/enable_warnings.hpp>
95 
96 #endif // BOOST_TEST_OUTPUT_TEST_STREAM_HPP_012705GER
97