1#ifndef TESTUTILS_OUTPUTCHECK_H
2#define TESTUTILS_OUTPUTCHECK_H
6#include <cppunit/extensions/HelperMacros.h>
22 OutputCheck(
const std::string &expectedOutput, std::ostream &os = std::cout);
23 OutputCheck(std::string &&expectedOutput, std::string &&alternativeOutput, std::ostream &os = std::cout);
24 OutputCheck(std::function<
void(
const std::string &output)> &&customCheck, std::ostream &os = std::cout);
29 const
std::function<
void(const
std::
string &output)> m_customCheck;
30 const
std::
string m_expectedOutput;
31 const
std::
string m_alternativeOutput;
32 std::stringstream m_buffer;
33 std::streambuf *const m_regularOutputBuffer;
41 , m_expectedOutput(expectedOutput)
43 , m_regularOutputBuffer(os.rdbuf(m_buffer.rdbuf()))
52 , m_expectedOutput(expectedOutput)
53 , m_alternativeOutput(alternativeOutput)
55 , m_regularOutputBuffer(os.rdbuf(m_buffer.rdbuf()))
64 , m_customCheck(customCheck)
66 , m_regularOutputBuffer(os.rdbuf(m_buffer.rdbuf()))
75 m_os.rdbuf(m_regularOutputBuffer);
76 const std::string actualOutput(m_buffer.str());
78 m_customCheck(actualOutput);
81 if (m_alternativeOutput.empty()) {
82 CPPUNIT_ASSERT_EQUAL(m_expectedOutput, actualOutput);
85 if (m_expectedOutput != actualOutput && m_alternativeOutput != actualOutput) {
87 CPPUNIT_FAIL(
"Output is not either \"" % m_expectedOutput %
"\" or \"" % m_alternativeOutput %
"\". Got instead:\n" + actualOutput);
The StandardOutputCheck class asserts whether the (standard) output written in the enclosing code blo...
OutputCheck(std::function< void(const std::string &output)> &&customCheck, std::ostream &os=std::cout)
~OutputCheck() noexcept(false)
Asserts the buffered standard output and restores the regular behaviour of std::cout.
OutputCheck(const std::string &expectedOutput, std::ostream &os=std::cout)
Redirects standard output to an internal buffer.
Contains all utilities provides by the c++utilities library.