Test: Logging
Enabled logging in unit tests. Seperated LogManager into LogManager (singleton stuff) and LogManagerImplementation (actual logging stuff) Implemented simple FileLogger review id = 13
This commit is contained in:
@@ -2,5 +2,6 @@
|
||||
/lib/
|
||||
/bin/Debug/
|
||||
/bin/Release/
|
||||
/bin/data/log/
|
||||
|
||||
.DS_Store
|
||||
|
||||
@@ -74,11 +74,15 @@ add_files(
|
||||
|
||||
utility/logging/ConsoleLogger.cpp
|
||||
utility/logging/ConsoleLogger.h
|
||||
utility/logging/FileLogger.cpp
|
||||
utility/logging/FileLogger.h
|
||||
utility/logging/Logger.cpp
|
||||
utility/logging/Logger.h
|
||||
utility/logging/logging.h
|
||||
utility/logging/LogManager.cpp
|
||||
utility/logging/LogManager.h
|
||||
utility/logging/LogManagerImplementation.cpp
|
||||
utility/logging/LogManagerImplementation.h
|
||||
utility/logging/LogMessage.h
|
||||
|
||||
utility/math/Vector2.h
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
const std::string FileLogger::s_filePath = "data/log/";
|
||||
|
||||
FileLogger::FileLogger()
|
||||
: Logger("FileLogger")
|
||||
{
|
||||
setupFileName();
|
||||
}
|
||||
|
||||
FileLogger::~FileLogger()
|
||||
{
|
||||
}
|
||||
|
||||
void FileLogger::logInfo(const LogMessage& message)
|
||||
{
|
||||
logMessage("INFO", message);
|
||||
}
|
||||
|
||||
void FileLogger::logWarning(const LogMessage& message)
|
||||
{
|
||||
logMessage("WARNING", message);
|
||||
}
|
||||
|
||||
void FileLogger::logError(const LogMessage& message)
|
||||
{
|
||||
logMessage("ERROR", message);
|
||||
}
|
||||
|
||||
void FileLogger::setupFileName()
|
||||
{
|
||||
time_t time;
|
||||
std::time(&time);
|
||||
tm localTime = *std::localtime(&time);
|
||||
|
||||
std::stringstream filename;
|
||||
filename << "log_";
|
||||
filename << localTime.tm_mon << "-" << localTime.tm_mday << "_";
|
||||
filename << localTime.tm_hour << "-" << localTime.tm_min << "-" << localTime.tm_sec << ".txt";
|
||||
|
||||
m_fileName = filename.str();
|
||||
}
|
||||
|
||||
void FileLogger::logMessage(const std::string& type, const LogMessage& message)
|
||||
{
|
||||
std::ofstream fileStream;
|
||||
fileStream.open(s_filePath + m_fileName, std::ios::app);
|
||||
fileStream
|
||||
<< message.getTimeString("%H:%M:%S") << " | "
|
||||
<< message.getFileName() << ':' << message.line << ' ' << message.functionName << "() | "
|
||||
<< type << ": " << message.message
|
||||
<< std::endl;
|
||||
fileStream.close();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef FILE_LOGGER_H
|
||||
#define FILE_LOGGER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utility/logging/Logger.h"
|
||||
#include "utility/logging/LogMessage.h"
|
||||
|
||||
class FileLogger: public Logger
|
||||
{
|
||||
public:
|
||||
FileLogger();
|
||||
virtual ~FileLogger();
|
||||
|
||||
virtual void logInfo(const LogMessage& message);
|
||||
virtual void logWarning(const LogMessage& message);
|
||||
virtual void logError(const LogMessage& message);
|
||||
|
||||
private:
|
||||
static const std::string s_filePath;
|
||||
|
||||
void setupFileName();
|
||||
void logMessage(const std::string& type, const LogMessage& message);
|
||||
|
||||
std::string m_fileName;
|
||||
};
|
||||
|
||||
#endif // FILE_LOGGER_H
|
||||
@@ -26,37 +26,22 @@ LogManager::~LogManager()
|
||||
|
||||
void LogManager::addLogger(std::shared_ptr<Logger> logger)
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuard(m_loggerMutex);
|
||||
m_loggers.push_back(logger);
|
||||
m_logManagerImplementation.addLogger(logger);
|
||||
}
|
||||
|
||||
void LogManager::removeLogger(std::shared_ptr<Logger> logger)
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuard(m_loggerMutex);
|
||||
std::vector<std::shared_ptr<Logger>>::iterator it = std::find(m_loggers.begin(), m_loggers.end(), logger);
|
||||
if (it != m_loggers.end())
|
||||
{
|
||||
m_loggers.erase(it);
|
||||
}
|
||||
m_logManagerImplementation.removeLogger(logger);
|
||||
}
|
||||
|
||||
void LogManager::removeLoggersByType(const std::string& type)
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuard(m_loggerMutex);
|
||||
for (unsigned int i = 0; i < m_loggers.size(); i++)
|
||||
{
|
||||
if (m_loggers[i]->getType() == type)
|
||||
{
|
||||
m_loggers.erase(m_loggers.begin() + i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
m_logManagerImplementation.removeLoggersByType(type);
|
||||
}
|
||||
|
||||
int LogManager::getLoggerCount() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuard(m_loggerMutex);
|
||||
return m_loggers.size();
|
||||
return m_logManagerImplementation.getLoggerCount();
|
||||
}
|
||||
|
||||
void LogManager::logInfo(
|
||||
@@ -66,11 +51,7 @@ void LogManager::logInfo(
|
||||
const unsigned int line
|
||||
)
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuardLogger(m_loggerMutex);
|
||||
for (unsigned int i = 0; i < m_loggers.size(); i++)
|
||||
{
|
||||
m_loggers[i]->logInfo(LogMessage(message, file, function, line, getTime()));
|
||||
}
|
||||
m_logManagerImplementation.logInfo(message, file, function, line);
|
||||
}
|
||||
|
||||
void LogManager::logWarning(
|
||||
@@ -80,11 +61,7 @@ void LogManager::logWarning(
|
||||
const unsigned int line
|
||||
)
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuardLogger(m_loggerMutex);
|
||||
for (unsigned int i = 0; i < m_loggers.size(); i++)
|
||||
{
|
||||
m_loggers[i]->logWarning(LogMessage(message, file, function, line, getTime()));
|
||||
}
|
||||
m_logManagerImplementation.logWarning(message, file, function, line);
|
||||
}
|
||||
|
||||
void LogManager::logError(
|
||||
@@ -94,11 +71,7 @@ void LogManager::logError(
|
||||
const unsigned int line
|
||||
)
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuardLogger(m_loggerMutex);
|
||||
for (unsigned int i = 0; i < m_loggers.size(); i++)
|
||||
{
|
||||
m_loggers[i]->logError(LogMessage(message, file, function, line, getTime()));
|
||||
}
|
||||
m_logManagerImplementation.logError(message, file, function, line);
|
||||
}
|
||||
|
||||
std::shared_ptr<LogManager> LogManager::s_instance;
|
||||
@@ -107,12 +80,3 @@ std::mutex LogManager::s_instanceMutex;
|
||||
LogManager::LogManager()
|
||||
{
|
||||
}
|
||||
|
||||
tm LogManager::getTime()
|
||||
{
|
||||
time_t time;
|
||||
std::time(&time);
|
||||
tm result;
|
||||
result = *localtime(&time);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/logging/Logger.h"
|
||||
#include "utility/logging/LogManagerImplementation.h"
|
||||
|
||||
class LogManager
|
||||
{
|
||||
@@ -47,11 +47,7 @@ private:
|
||||
LogManager(const LogManager&);
|
||||
void operator=(const LogManager&);
|
||||
|
||||
tm getTime();
|
||||
|
||||
std::vector<std::shared_ptr<Logger> > m_loggers;
|
||||
|
||||
mutable std::mutex m_loggerMutex;
|
||||
LogManagerImplementation m_logManagerImplementation;
|
||||
};
|
||||
|
||||
#endif // LOG_MANAGER_H
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
#include "LogManagerImplementation.h"
|
||||
|
||||
LogManagerImplementation::LogManagerImplementation()
|
||||
{
|
||||
}
|
||||
|
||||
LogManagerImplementation::LogManagerImplementation(const LogManagerImplementation& other)
|
||||
{
|
||||
m_loggers = other.m_loggers;
|
||||
}
|
||||
|
||||
void LogManagerImplementation::operator=(const LogManagerImplementation& other)
|
||||
{
|
||||
m_loggers = other.m_loggers;
|
||||
}
|
||||
|
||||
LogManagerImplementation::~LogManagerImplementation()
|
||||
{
|
||||
}
|
||||
|
||||
void LogManagerImplementation::addLogger(std::shared_ptr<Logger> logger)
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuard(m_loggerMutex);
|
||||
m_loggers.push_back(logger);
|
||||
}
|
||||
|
||||
void LogManagerImplementation::removeLogger(std::shared_ptr<Logger> logger)
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuard(m_loggerMutex);
|
||||
std::vector<std::shared_ptr<Logger>>::iterator it = std::find(m_loggers.begin(), m_loggers.end(), logger);
|
||||
if (it != m_loggers.end())
|
||||
{
|
||||
m_loggers.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void LogManagerImplementation::removeLoggersByType(const std::string& type)
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuard(m_loggerMutex);
|
||||
for (unsigned int i = 0; i < m_loggers.size(); i++)
|
||||
{
|
||||
if (m_loggers[i]->getType() == type)
|
||||
{
|
||||
m_loggers.erase(m_loggers.begin() + i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int LogManagerImplementation::getLoggerCount() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuard(m_loggerMutex);
|
||||
return m_loggers.size();
|
||||
}
|
||||
|
||||
void LogManagerImplementation::logInfo(
|
||||
const std::string& message,
|
||||
const std::string& file,
|
||||
const std::string& function,
|
||||
const unsigned int line
|
||||
)
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuardLogger(m_loggerMutex);
|
||||
for (unsigned int i = 0; i < m_loggers.size(); i++)
|
||||
{
|
||||
m_loggers[i]->logInfo(LogMessage(message, file, function, line, getTime()));
|
||||
}
|
||||
}
|
||||
|
||||
void LogManagerImplementation::logWarning(
|
||||
const std::string& message,
|
||||
const std::string& file,
|
||||
const std::string& function,
|
||||
const unsigned int line
|
||||
)
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuardLogger(m_loggerMutex);
|
||||
for (unsigned int i = 0; i < m_loggers.size(); i++)
|
||||
{
|
||||
m_loggers[i]->logWarning(LogMessage(message, file, function, line, getTime()));
|
||||
}
|
||||
}
|
||||
|
||||
void LogManagerImplementation::logError(
|
||||
const std::string& message,
|
||||
const std::string& file,
|
||||
const std::string& function,
|
||||
const unsigned int line
|
||||
)
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuardLogger(m_loggerMutex);
|
||||
for (unsigned int i = 0; i < m_loggers.size(); i++)
|
||||
{
|
||||
m_loggers[i]->logError(LogMessage(message, file, function, line, getTime()));
|
||||
}
|
||||
}
|
||||
|
||||
tm LogManagerImplementation::getTime()
|
||||
{
|
||||
time_t time;
|
||||
std::time(&time);
|
||||
tm result = *std::localtime(&time); // this is done because localtime returns a pointer to a statically allocated object
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef LOG_MANAGER_IMPLEMENTATION_H
|
||||
#define LOG_MANAGER_IMPLEMENTATION_H
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/logging/Logger.h"
|
||||
|
||||
class LogManagerImplementation
|
||||
{
|
||||
public:
|
||||
LogManagerImplementation();
|
||||
|
||||
// Must be implemented because std::mutex is non-copyable, see
|
||||
// http://stackoverflow.com/questions/14263836/why-does-stdmutex-create-a-c2248-when-used-in-a-struct-with-windows-socket
|
||||
// for more details
|
||||
LogManagerImplementation(const LogManagerImplementation& other);
|
||||
void operator=(const LogManagerImplementation& other);
|
||||
|
||||
~LogManagerImplementation();
|
||||
|
||||
void addLogger(std::shared_ptr<Logger> logger);
|
||||
void removeLogger(std::shared_ptr<Logger> logger);
|
||||
void removeLoggersByType(const std::string& type);
|
||||
int getLoggerCount() const;
|
||||
|
||||
void logInfo(
|
||||
const std::string& message,
|
||||
const std::string& file,
|
||||
const std::string& function,
|
||||
const unsigned int line
|
||||
);
|
||||
void logWarning(
|
||||
const std::string& message,
|
||||
const std::string& file,
|
||||
const std::string& function,
|
||||
const unsigned int line
|
||||
);
|
||||
void logError(
|
||||
const std::string& message,
|
||||
const std::string& file,
|
||||
const std::string& function,
|
||||
const unsigned int line
|
||||
);
|
||||
|
||||
private:
|
||||
tm getTime();
|
||||
|
||||
std::vector<std::shared_ptr<Logger> > m_loggers;
|
||||
|
||||
mutable std::mutex m_loggerMutex;
|
||||
};
|
||||
|
||||
#endif // LOG_MANAGER_IMPLEMENTATION_H
|
||||
@@ -4,5 +4,7 @@ add_files(
|
||||
ConfigManagerTestSuite.h
|
||||
CxxParserTestSuite.h
|
||||
LogManagerTestSuite.h
|
||||
TestSuiteFixture.cpp
|
||||
TestSuiteFixture.h
|
||||
Vector2TestSuite.h
|
||||
)
|
||||
|
||||
@@ -2,156 +2,169 @@
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/logging/LogManagerImplementation.h"
|
||||
|
||||
class LogManagerTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_new_logger_can_be_added_to_manager()
|
||||
{
|
||||
LogManagerImplementation logManagerImplementation;
|
||||
|
||||
std::shared_ptr<Logger> logger = std::make_shared<TestLogger>();
|
||||
|
||||
int countBeforeAdd = LogManager::getInstance()->getLoggerCount();
|
||||
LogManager::getInstance()->addLogger(logger);
|
||||
int countAfterAdd = LogManager::getInstance()->getLoggerCount();
|
||||
LogManager::getInstance()->removeLogger(logger);
|
||||
int countBeforeAdd = logManagerImplementation.getLoggerCount();
|
||||
logManagerImplementation.addLogger(logger);
|
||||
int countAfterAdd = logManagerImplementation.getLoggerCount();
|
||||
logManagerImplementation.removeLogger(logger);
|
||||
|
||||
TS_ASSERT_EQUALS(1, countAfterAdd - countBeforeAdd);
|
||||
}
|
||||
|
||||
void test_logger_can_be_removed_from_manager()
|
||||
{
|
||||
LogManagerImplementation logManagerImplementation;
|
||||
|
||||
std::shared_ptr<Logger> logger = std::make_shared<TestLogger>();
|
||||
|
||||
int countBeforeAdd = LogManager::getInstance()->getLoggerCount();
|
||||
LogManager::getInstance()->addLogger(logger);
|
||||
LogManager::getInstance()->removeLogger(logger);
|
||||
int countAfterRemove = LogManager::getInstance()->getLoggerCount();
|
||||
int countBeforeAdd = logManagerImplementation.getLoggerCount();
|
||||
logManagerImplementation.addLogger(logger);
|
||||
logManagerImplementation.removeLogger(logger);
|
||||
int countAfterRemove = logManagerImplementation.getLoggerCount();
|
||||
|
||||
TS_ASSERT_EQUALS(countBeforeAdd, countAfterRemove);
|
||||
}
|
||||
|
||||
void test_logger_logs_message()
|
||||
{
|
||||
LogManagerImplementation logManagerImplementation;
|
||||
|
||||
std::string log = "test";
|
||||
std::shared_ptr<TestLogger> logger = std::make_shared<TestLogger>();
|
||||
|
||||
LogManager::getInstance()->addLogger(logger);
|
||||
|
||||
LOG_INFO(log);
|
||||
logManagerImplementation.addLogger(logger);
|
||||
logManagerImplementation.logInfo(log, __FILE__, __FUNCTION__, __LINE__);
|
||||
int logCount = logger->getMessageCount();
|
||||
std::string lastLog = logger->getLastMessage();
|
||||
|
||||
LogManager::getInstance()->removeLogger(logger);
|
||||
|
||||
TS_ASSERT_EQUALS(1, logCount);
|
||||
TS_ASSERT_EQUALS(log, lastLog);
|
||||
}
|
||||
|
||||
void test_logger_logs_warning()
|
||||
{
|
||||
LogManagerImplementation logManagerImplementation;
|
||||
|
||||
std::string log = "test";
|
||||
std::shared_ptr<TestLogger> logger = std::make_shared<TestLogger>();
|
||||
|
||||
LogManager::getInstance()->addLogger(logger);
|
||||
logManagerImplementation.addLogger(logger);
|
||||
|
||||
LOG_WARNING(log);
|
||||
logManagerImplementation.logWarning(log, __FILE__, __FUNCTION__, __LINE__);
|
||||
int logCount = logger->getWarningCount();
|
||||
std::string lastLog = logger->getLastWarning();
|
||||
|
||||
LogManager::getInstance()->removeLogger(logger);
|
||||
|
||||
TS_ASSERT_EQUALS(1, logCount);
|
||||
TS_ASSERT_EQUALS(log, lastLog);
|
||||
}
|
||||
|
||||
void test_logger_logs_error()
|
||||
{
|
||||
LogManagerImplementation logManagerImplementation;
|
||||
|
||||
std::string log = "test";
|
||||
std::shared_ptr<TestLogger> logger = std::make_shared<TestLogger>();
|
||||
|
||||
LogManager::getInstance()->addLogger(logger);
|
||||
logManagerImplementation.addLogger(logger);
|
||||
|
||||
LOG_ERROR(log);
|
||||
logManagerImplementation.logError(log, __FILE__, __FUNCTION__, __LINE__);
|
||||
int logCount = logger->getErrorCount();
|
||||
std::string lastLog = logger->getLastError();
|
||||
|
||||
LogManager::getInstance()->removeLogger(logger);
|
||||
|
||||
TS_ASSERT_EQUALS(1, logCount);
|
||||
TS_ASSERT_EQUALS(log, lastLog);
|
||||
}
|
||||
|
||||
void test_new_logger_can_be_added_to_manager_threaded()
|
||||
{
|
||||
std::thread thread0(addTestLogger);
|
||||
std::thread thread1(addTestLogger);
|
||||
LogManagerImplementation logManagerImplementation;
|
||||
unsigned int loggerCount = 100;
|
||||
|
||||
std::thread thread0(addTestLogger, &logManagerImplementation, loggerCount);
|
||||
std::thread thread1(addTestLogger, &logManagerImplementation, loggerCount);
|
||||
|
||||
thread0.join();
|
||||
thread1.join();
|
||||
|
||||
TS_ASSERT_EQUALS(200, LogManager::getInstance()->getLoggerCount());
|
||||
|
||||
removeTestLoggers();
|
||||
TS_ASSERT_EQUALS(loggerCount * 2, logManagerImplementation.getLoggerCount());
|
||||
}
|
||||
|
||||
void test_logger_can_be_removed_from_manager_threaded()
|
||||
{
|
||||
std::thread thread0(addAndRemoveTestLogger);
|
||||
std::thread thread1(addAndRemoveTestLogger);
|
||||
LogManagerImplementation logManagerImplementation;
|
||||
unsigned int loggerCount = 100;
|
||||
|
||||
std::thread thread0(addAndRemoveTestLogger, &logManagerImplementation, loggerCount);
|
||||
std::thread thread1(addAndRemoveTestLogger, &logManagerImplementation, loggerCount);
|
||||
|
||||
thread0.join();
|
||||
thread1.join();
|
||||
|
||||
TS_ASSERT_EQUALS(0, LogManager::getInstance()->getLoggerCount());
|
||||
TS_ASSERT_EQUALS(0, logManagerImplementation.getLoggerCount());
|
||||
}
|
||||
|
||||
void test_logger_logs_threaded()
|
||||
{
|
||||
std::shared_ptr<TestLogger> logger = std::make_shared<TestLogger>();
|
||||
LogManager::getInstance()->addLogger(logger);
|
||||
LogManagerImplementation logManagerImplementation;
|
||||
|
||||
std::thread thread0(loggSomeMessages);
|
||||
std::thread thread1(loggSomeMessages);
|
||||
std::string log = "foo";
|
||||
unsigned int messageCount = 100;
|
||||
std::shared_ptr<TestLogger> logger = std::make_shared<TestLogger>();
|
||||
logManagerImplementation.addLogger(logger);
|
||||
|
||||
std::thread thread0(logSomeMessages, &logManagerImplementation, log, messageCount);
|
||||
std::thread thread1(logSomeMessages, &logManagerImplementation, log, messageCount);
|
||||
|
||||
thread0.join();
|
||||
thread1.join();
|
||||
|
||||
TS_ASSERT_EQUALS(logger->getLastError(), "foo");
|
||||
TS_ASSERT_EQUALS(600, logger->getErrorCount() + logger->getWarningCount() + logger->getMessageCount());
|
||||
|
||||
removeTestLoggers();
|
||||
TS_ASSERT_EQUALS(logger->getLastError(), log);
|
||||
TS_ASSERT_EQUALS(messageCount * 6, logger->getErrorCount() + logger->getWarningCount() + logger->getMessageCount());
|
||||
}
|
||||
|
||||
private:
|
||||
static void addTestLogger()
|
||||
static void addTestLogger(LogManagerImplementation* logManagerImplementation, const unsigned int loggerCount)
|
||||
{
|
||||
for(unsigned int i = 0; i < 100; i++)
|
||||
for(unsigned int i = 0; i < loggerCount; i++)
|
||||
{
|
||||
std::shared_ptr<Logger> logger = std::make_shared<TestLogger>();
|
||||
LogManager::getInstance()->addLogger(logger);
|
||||
logManagerImplementation->addLogger(logger);
|
||||
}
|
||||
}
|
||||
|
||||
static void removeTestLoggers()
|
||||
static void removeTestLoggers(LogManagerImplementation* logManagerImplementation)
|
||||
{
|
||||
std::shared_ptr<Logger> logger = std::make_shared<TestLogger>();
|
||||
LogManager::getInstance()->removeLoggersByType(logger->getType());
|
||||
logManagerImplementation->removeLoggersByType(logger->getType());
|
||||
}
|
||||
|
||||
static void addAndRemoveTestLogger()
|
||||
static void addAndRemoveTestLogger(LogManagerImplementation* logManagerImplementation, const unsigned int loggerCount)
|
||||
{
|
||||
addTestLogger();
|
||||
removeTestLoggers();
|
||||
addTestLogger(logManagerImplementation, loggerCount);
|
||||
removeTestLoggers(logManagerImplementation);
|
||||
}
|
||||
|
||||
static void loggSomeMessages()
|
||||
static void logSomeMessages(
|
||||
LogManagerImplementation* logManagerImplementation,
|
||||
const std::string& message,
|
||||
const unsigned int messageCount
|
||||
)
|
||||
{
|
||||
for(unsigned int i = 0; i < 100; i++)
|
||||
for(unsigned int i = 0; i < messageCount; i++)
|
||||
{
|
||||
LOG_INFO("foo");
|
||||
LOG_WARNING("foo");
|
||||
LOG_ERROR("foo");
|
||||
logManagerImplementation->logInfo(message, __FILE__, __FUNCTION__, __LINE__);
|
||||
logManagerImplementation->logWarning(message, __FILE__, __FUNCTION__, __LINE__);
|
||||
logManagerImplementation->logError(message, __FILE__, __FUNCTION__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "TestSuiteFixture.h"
|
||||
|
||||
#include "utility/logging/ConsoleLogger.h"
|
||||
#include "utility/logging/FileLogger.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/logging/LogManager.h"
|
||||
|
||||
TestSuiteFixture::TestSuiteFixture()
|
||||
{
|
||||
}
|
||||
|
||||
TestSuiteFixture::~TestSuiteFixture()
|
||||
{
|
||||
}
|
||||
|
||||
bool TestSuiteFixture::setUp()
|
||||
{
|
||||
LogManager::getInstance()->addLogger(std::make_shared<ConsoleLogger>());
|
||||
LogManager::getInstance()->addLogger(std::make_shared<FileLogger>());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestSuiteFixture::tearDown()
|
||||
{
|
||||
LogManager::destroyInstance();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef TEST_SUITE_FIXTURE_H
|
||||
#define TEST_SUITE_FIXTURE_H
|
||||
|
||||
#include "cxxtest/GlobalFixture.h"
|
||||
|
||||
class TestSuiteFixture : public CxxTest::GlobalFixture
|
||||
{
|
||||
public:
|
||||
TestSuiteFixture();
|
||||
virtual ~TestSuiteFixture();
|
||||
|
||||
virtual bool setUp();
|
||||
virtual bool tearDown();
|
||||
};
|
||||
|
||||
// According to the CxxTest Documentation global fixtures are actually supposed to be implemented as global static instances
|
||||
// See http://cxxtest.com/guide.html for more details
|
||||
static TestSuiteFixture testSuiteFixture;
|
||||
|
||||
#endif // TEST_SUITE_FIXTURE_H
|
||||
Reference in New Issue
Block a user