#include #include "g2log.h" #include #include #include "testing_helpers.h" #include "std2_make_unique.hpp" using namespace std; using namespace std2; class CoutSink { stringstream buffer; unique_ptr scope_ptr; CoutSink() : scope_ptr(std2::make_unique(&buffer)) {} void save(g2::internal::LogEntry msg) { std::cout << msg; } void clear() { buffer.str(""); } std::string string() { return buffer.str(); } public: virtual ~CoutSink() final {} static std::unique_ptr createSink() { return std::unique_ptr(new CoutSink); } }; TEST(SinkBasics, RAII_CoutSink) { std::unique_ptr ptr = nullptr; { ptr = CoutSink::createSink(); ASSERT_FALSE(nullptr == ptr); } ASSERT_TRUE(nullptr == ptr); } TEST(SinkToLogger, AddSink_Expect_return_Handle) { auto ptr = CoutSink::createSink(); RestoreLogger raii_logger; auto handler = raii_logger.callToLogger(&addSink, CoutSink::createSink()); ASSERT_FALSE(nullptr == handler); }