2015-03-05 04:37:13 +01:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include <core/Logger.hpp>
|
|
|
|
|
2016-12-28 22:15:44 +01:00
|
|
|
class CallbackReceiver : public Logger::MessageReceiver {
|
2015-03-05 04:37:13 +01:00
|
|
|
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);
|
|
|
|
}
|
2015-03-05 04:37:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
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");
|
2015-03-05 04:37:13 +01:00
|
|
|
}
|
|
|
|
|
2016-12-28 22:15:44 +01:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|