1 #ifndef TESTUTILS_OUTPUTCHECK_H 2 #define TESTUTILS_OUTPUTCHECK_H 4 #include "../conversion/stringbuilder.h" 6 #include <cppunit/extensions/HelperMacros.h> 21 OutputCheck(
const std::string &expectedOutput, std::ostream &os = std::cout);
22 OutputCheck(std::string &&expectedOutput, std::string &&alternativeOutput, std::ostream &os = std::cout);
23 OutputCheck(std::function<
void(
const std::string &output)> &&customCheck, std::ostream &os = std::cout);
28 const std::function<void(const std::string &output)> m_customCheck;
29 const std::string m_expectedOutput;
30 const std::string m_alternativeOutput;
31 std::stringstream m_buffer;
32 std::streambuf *
const m_regularOutputBuffer;
40 , m_expectedOutput(expectedOutput)
42 , m_regularOutputBuffer(os.rdbuf(m_buffer.rdbuf()))
51 , m_expectedOutput(expectedOutput)
52 , m_alternativeOutput(alternativeOutput)
54 , m_regularOutputBuffer(os.rdbuf(m_buffer.rdbuf()))
63 , m_customCheck(customCheck)
65 , m_regularOutputBuffer(os.rdbuf(m_buffer.rdbuf()))
74 m_os.rdbuf(m_regularOutputBuffer);
76 m_customCheck(m_buffer.str());
79 if (m_alternativeOutput.empty()) {
80 CPPUNIT_ASSERT_EQUAL(m_expectedOutput, m_buffer.str());
83 const std::string actualOutput(m_buffer.str());
84 if (m_expectedOutput != actualOutput && m_alternativeOutput != actualOutput) {
86 CPPUNIT_FAIL(
"Output is not either \"" % m_expectedOutput %
"\" or \"" % m_alternativeOutput %
"\". Got instead:\n" + actualOutput);
92 #endif // TESTUTILS_OUTPUTCHECK_H Contains classes and functions utilizing creating of test applications.
Contains several functions providing conversions between different data types.
OutputCheck(const std::string &expectedOutput, std::ostream &os=std::cout)
Redirects standard output to an internal buffer.
The StandardOutputCheck class asserts whether the (standard) output written in the enclosing code blo...
~OutputCheck() noexcept(false)
Asserts the buffered standard output and restores the regular behaviour of std::cout.