From ca7ae883eedc5d047fdf04896a4778433299fb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sat, 28 Oct 2017 16:45:29 +0200 Subject: [PATCH] Removed Boost dependency in unit tests. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some of the unit tests depended on Boost’s null_sink to redirect the unwanted test output to /dev/null. This commit adds a simple NullOutputStream as a replacement and removes the obsolete Boost includes. --- tests/NullOutputStream.h | 44 +++++++++++++++++++++++++++++++++++ tests/TestPDDLTranslation.cpp | 11 +++++---- 2 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 tests/NullOutputStream.h diff --git a/tests/NullOutputStream.h b/tests/NullOutputStream.h new file mode 100644 index 0000000..de9f99f --- /dev/null +++ b/tests/NullOutputStream.h @@ -0,0 +1,44 @@ +#ifndef __PLASP__TESTS__NULL_OUTPUT_STREAM_H +#define __PLASP__TESTS__NULL_OUTPUT_STREAM_H + +#include + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// NullOutputStream +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +class NullStreamBuffer : public std::streambuf +{ + private: + char dummyBuffer[64]; + + protected: + virtual int overflow(int c) + { + setp(dummyBuffer, dummyBuffer + sizeof(dummyBuffer)); + return (c == traits_type::eof()) ? '\0' : c; + } +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +class NullOutputStream : public std::ostream +{ + public: + NullOutputStream() + : std::ostream(&m_nullStreamBuffer) + { + } + + NullStreamBuffer *rdbuf() const + { + return &m_nullStreamBuffer; + } + + private: + mutable NullStreamBuffer m_nullStreamBuffer; +}; + +#endif diff --git a/tests/TestPDDLTranslation.cpp b/tests/TestPDDLTranslation.cpp index 4ccb89a..4dbf459 100644 --- a/tests/TestPDDLTranslation.cpp +++ b/tests/TestPDDLTranslation.cpp @@ -1,7 +1,6 @@ #include -#include -#include +#include #include @@ -11,15 +10,17 @@ #include -boost::iostreams::stream nullStream((boost::iostreams::null_sink())); +#include "NullOutputStream.h" + const pddl::Context::WarningCallback ignoreWarnings = [](const auto &, const auto &){}; //////////////////////////////////////////////////////////////////////////////////////////////////// TEST_CASE("[PDDL translation] Former issues are fixed", "[PDDL translation]") { - // TODO: refactor - colorlog::Logger logger(nullStream, nullStream); + NullOutputStream nullOutputStream; + + colorlog::Logger logger(nullOutputStream, nullOutputStream); pddl::Tokenizer tokenizer; pddl::Context context(std::move(tokenizer), ignoreWarnings);