Boost logo

Boost Test Library: output_test_stream tool

Home
Introduction
Benefits
Specification
Examples and Tests

Introduction

The class output_test_stream is a simple tool for testing output operation with standard std::ostream facilities. The class output_test_stream comply to std::ostream interface so it can be used in place of any std::ostream argument. In addition it provide several methods to validate output content. Also it allows to match/save output content versus/into specified file. Working mode of the output_test_stream could be defined by framework parameter " Save pattern"

Benefits

Simplified mechanism for checking correctness of output operations. reference to the top

Specification

class output_test_stream {
pubic:
    explicit  output_test_stream( char const* pattern_file = NULL,
                                  bool match_or_save = 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( char const* arg, bool flush_stream = true );
    bool      is_equal( std::string const& arg, bool flush_stream = true );
    bool      is_equal( char const* arg, std::size_t n,
                        bool flush_stream = true );

    bool      match_pattern( bool flush_stream = true );

    void      flush();
};

explicit output_test_stream( char const* pattern_file = NULL, bool match_or_save = true );

The class output_test_stream constructor accept pattern file name and boolean switch match_or_save that are used by match_pattern facility. If they are not present you can still use other testing mechanisms.

void flush();

The method output_test_stream::flush() is used to clean the content of the output_test_stream instance.

bool is_empty( bool flush_stream = true );

The method output_test_stream::is_empty(...) is used to check that the content of the output_test_stream instance is empty. The flush_stream argument manage automatic call of the method output_test_stream::flush() after check is done.

bool check_length( std::size_t length, bool flush_stream = true );

The method output_test_stream::check_length(...) is used to check that the length of the content of the output_test_stream instance is equal to supplied length value. The flush_stream argument manage automatic call of the method output_test_stream::flush() after check is done.

bool is_equal( char const* arg, bool flush_stream = true );
bool is_equal( std::string const& arg, bool flush_stream = true );
bool is_equal( char const* arg, std::size_t n, bool flush_stream = true );

The overloaded method output_test_stream::is_equal(...) is used to check that the content of the output_test_stream instance is equal to supplied character string. The first version compare with null-terminated string. The second compare with a reference to std::string object. And finnaly the third version compare with probably not null-terminated string defined by pointer to the string begin and the string length. The flush_stream argument manage automatic call of the method output_test_stream::flush() after check is done.

bool match_pattern( bool flush_stream = true );

The method output_test_stream::match_pattern(...) is used to match 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 the method output_test_stream::match_pattern(...) will cause the output_test_stream instance content to be stored at the end of the pattern file. The flush_stream argument manage automatic call of the method output_test_stream::flush() after check is done.

Examlpes and Tests

output_test_stream_test
result_report_test
test_tools_test
reference to the top errors_handling_test