1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-25 20:02:40 +01:00
openrw/tests/test_Logger.cpp

37 lines
904 B
C++
Raw Normal View History

#include <boost/test/unit_test.hpp>
#include <core/Logger.hpp>
2016-12-28 22:15:44 +01:00
class CallbackReceiver : public Logger::MessageReceiver {
public:
2016-09-09 22:13:22 +02:00
std::function<void(const Logger::LogMessage&)> func;
CallbackReceiver(std::function<void(const Logger::LogMessage&)> func)
: func(func) {
}
2016-12-28 22:15:44 +01:00
virtual void messageReceived(const Logger::LogMessage& message) {
2016-09-09 22:13:22 +02:00
func(message);
}
};
BOOST_AUTO_TEST_SUITE(LoggerTests)
2016-12-28 22:15:44 +01:00
BOOST_AUTO_TEST_CASE(test_receiver) {
2016-09-09 22:13:22 +02:00
Logger log;
Logger::LogMessage lastMessage("", Logger::Error, "");
2016-12-28 22:15:44 +01:00
CallbackReceiver receiver(
2016-09-09 22:13:22 +02:00
[&](const Logger::LogMessage& m) { lastMessage = m; });
2016-12-28 22:15:44 +01:00
log.addReceiver(&receiver);
2016-09-09 22:13:22 +02:00
log.info("Tests", "Test");
BOOST_CHECK_EQUAL(lastMessage.component, "Tests");
BOOST_CHECK_EQUAL(lastMessage.severity, Logger::Info);
BOOST_CHECK_EQUAL(lastMessage.message, "Test");
}
2016-12-28 22:15:44 +01:00
BOOST_AUTO_TEST_SUITE_END()