]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/test/doc/testing_tools/testing_output_streams.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / test / doc / testing_tools / testing_output_streams.qbk
CommitLineData
7c673cae
FG
1[/
2 / Copyright (c) 2003 Boost.Test contributors
3 /
4 / Distributed under the Boost Software License, Version 1.0. (See accompanying
5 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 /]
7
8[section:output_stream_testing Output streams testing tool]
9
10How would you perform correctness test for ``operator<< ( std::ostream &, ... )`` operations?
11
12You can print into the standard output stream and manually check that it is matching your expectations.
13Unfortunately, this is not really acceptable for the regression testing and doesn't serve a long term purpose of a
14unit test.
15
16You can use `std::stringstream` and compare resulting output buffer with the
17expected pattern string, but you are required to perform several additional operations with every check you do. So it
18becomes tedious very fast.
19
20The class [classref boost::test_tools::output_test_stream] is designed to automate these tasks for you. This is a simple,
21but powerful tool for testing standard `std::ostream` based output operation. The class `output_test_stream`
22complies to `std::ostream` interface so it can be used in place of any
23`std::ostream` parameter. It provides several test methods to validate output content,
24including test for match to expected output content or test for expected output length. Flushing, synchronizing,
25string comparison and error message generation is automated by the tool implementation.
26
27All `output_test_stream` validation member functions by default flush the stream once the check is performed.
28If you want to perform several checks with the same output, specify parameter `flush_stream`
29with value `false` [footnote This parameter is supported on all comparison methods, see the class
30[classref boost::test_tools::output_test_stream documentation.] ].
31
32In some cases manual generation of expected output is either too time consuming or is impossible at all because
33of sheer volume. A possible way to address that issue is to split the test in two steps:
34
35# first by checking the expected output manually
36# second to save this output to ensure that future checks produce the same output
37
38The class `output_test_stream` allows both the matching of the output content versus a /pattern file/ and generation
39of this pattern file. The command line parameter [link boost_test.utf_reference.rt_param_reference.save_pattern `save_pattern`]
40may be used to either generate a new pattern file, or to check against an existing pattern.
41
42[h3:usages Usage]
43There are two ways to employ the class `output_test_stream`:
44
45# explicit output checks and
46# pattern file matching
47
48[h4 Explicit output checks]
49
50Use the instance of class `output_test_stream` as an output stream and check output content using tool's methods.
51
52[bt_example example28..Explicit output checks with `output_test_stream`..run-fail]
53
54[note Use of `false` to prevent output flushing in first two invocation of check functions. Unless
55you want to perform several different checks for the same output you wouldn't need to use it though. Your
56test will look like a sequence of output operators followed by one check.]
57
58[tip Try to perform checks as
59frequently as possible. It not only simplifies patterns you compare with, but also allows you to more closely
60identify possible source of failure.]
61
62[h4 Pattern file matching]
63The ['pattern file] is a companion file containing the patterns that the stream should match. Your testing will look
64like a series of output operators followed by match pattern checks repeated several times.
65
66In the example below, the file `pattern_file` contains the patterns that should match.
67[pre
68i=2
69File: test.cpp Line:XXX
70]
71
72[bt_example example29..Pattern file matching with `output_test_stream`..run-fail]
73
74[tip Try to perform checks as frequently as possible, because it allows you to more closely identify possible source
75 of failure
76]
77
78
79[endsect] [/ output stream testing]