Boost.Test > Components > The Test Tools > Output operations testing > boost::test_tools::ostream_test_stream
Boost Test logo

boost::test_tools::ostream_test_stream

The class boost::test_tools::ostream_test_stream encapsulates procedures needed for effective and convenient operator<<( std::ostream&, ... ) correctness checks.

Synopsis

class output_test_stream {
pubic:
    explicit  output_test_stream( const_string pattern_file   = const_string(),
                                  bool         match_or_save  = true,
                                  bool         text_or_binary = true );
              ~output_test_stream();

    bool      is_empty( bool flush_stream = true );
    bool      check_length( std::size_t length, bool flush_stream = true );
    bool      is_equal( const_string arg, bool flush_stream = true );
    bool      match_pattern( bool flush_stream = true );

    void      flush();
};

Description

The class output_test_stream models output stream. Formatted output is storred inside of output_test_stream object until check operations are performed at which time the content gets flushed (unless expletely told not to)

explicit output_test_stream( const_string pattern_file, bool match_or_save, bool text_or_binary )

Effects:

Initilize output test stream object based on arguments provided

Arguments:

pattern_file - the pattern file name. If provided file matching/saving operation is permitted. If not only explicit checks on formatted content are permitted
match_or_save - boolean switch between matching and saving to pattern file operating modes. Ignored if pattern file name is not supplied
text_or_binary - boolean switch between text and binary mode for pattern file reading/writting operations. Ignored if pattern file name is not supplied

void flush()

Effects:

Clears the content of an output_test_stream object.

bool is_empty( bool flush_stream )

Effects:

Checks that the content of the output_test_stream instance is empty.

Arguments:

flush_stream - boolean flag indicating wheather output_test_strean object content needs to be cleared at the end of the check

Returns:

true if check successful, false otherwise.

bool check_length( std::size_t length, bool flush_stream )

Effects:

Checks that the length of the output_test_stream object content is equal to supplied length value.

Arguments:

length - length value to be matched against
flush_stream - boolean flag indicating wheather output_test_strean object content needs to be cleared at the end of the check

Returns:

true if check successful, false otherwise.

bool is_equal( const_string arg, bool flush_stream )

Effects:

Checks that the content of the output_test_stream instance match the supplied string.

Arguments:

arg - character string to be matched against
flush_stream - boolean flag indicating wheather output_test_strean object content needs to be cleared at the end of the check

Returns:

true if check successful, false otherwise.

bool match_pattern( bool flush_stream )

Effects:

Matches the content of the output_test_stream instance versus the pattern file. The pattern file name is specified in the class output_test_stream constructor. If second argument of the class output_test_stream constructor is false, then every call of this method causes the output_test_stream object content to be stored at the end of the pattern file.

Arguments:

flush_stream - boolean flag indicating wheather output_test_strean object content needs to be cleared at the end of the check

Returns:

In matching mode: true if check successful, false otherwise. In saving mode always true