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)
6 // See http://www.boost.org/libs/test for the library home page.
9 /// @brief output_test_stream class definition
10 // ***************************************************************************
12 #ifndef BOOST_TEST_OUTPUT_TEST_STREAM_HPP_012705GER
13 #define BOOST_TEST_OUTPUT_TEST_STREAM_HPP_012705GER
16 #include <boost/test/detail/global_typedef.hpp>
17 #include <boost/test/utils/wrap_stringstream.hpp>
18 #include <boost/test/tools/assertion_result.hpp>
21 #include <cstddef> // for std::size_t
23 #include <boost/test/detail/suppress_warnings.hpp>
25 //____________________________________________________________________________//
27 // ************************************************************************** //
28 // ************** output_test_stream ************** //
29 // ************************************************************************** //
34 namespace test_tools {
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;
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
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 );
54 virtual ~output_test_stream();
56 //! Checks if the stream is empty
58 //!@param[in] flush_stream if true, flushes the stream after the call
59 virtual assertion_result is_empty( bool flush_stream = true );
61 //! Checks the length of the stream
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 virtual assertion_result check_length( std::size_t length, bool flush_stream = true );
68 //! Checks the content of the stream against a string
70 //!@param[in] arg_ the target stream
71 //!@param[in] flush_stream if true, flushes the stream after the call.
72 virtual assertion_result is_equal( const_string arg_, bool flush_stream = true );
74 //! Checks the content of the stream against a pattern file
76 //!@param[in] flush_stream if true, flushes/resets the stream after the call.
77 virtual assertion_result match_pattern( bool flush_stream = true );
79 //! Flushes the stream
84 //! Returns the string representation of the stream
86 //! May be overriden in order to mutate the string before the matching operations.
87 virtual std::string get_stream_string_representation() const;
92 //! Length of the stream
95 //! Synching the stream into an internal string representation
102 } // namespace test_tools
105 #include <boost/test/detail/enable_warnings.hpp>
107 #endif // BOOST_TEST_OUTPUT_TEST_STREAM_HPP_012705GER