Environment for tests
Some checks failed
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m47s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled
Bigfoot / Clang Format Checks (push) Has been cancelled
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Some checks failed
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m47s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled
Bigfoot / Clang Format Checks (push) Has been cancelled
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
This commit is contained in:
@@ -41,6 +41,18 @@ class Log
|
||||
Log(const Log& p_logger) = delete;
|
||||
Log(Log&& p_logger) = delete;
|
||||
|
||||
/**
|
||||
* Starts the logger backend
|
||||
*
|
||||
*/
|
||||
void Start();
|
||||
|
||||
/**
|
||||
* Stops the logger backend
|
||||
*
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
/**
|
||||
* Register a logger.
|
||||
*
|
||||
@@ -49,6 +61,13 @@ class Log
|
||||
[[nodiscard]]
|
||||
quill::Logger* RegisterLogger(const LoggerInfo& p_loggerInfo);
|
||||
|
||||
/**
|
||||
* Unregister a logger.
|
||||
*
|
||||
* \param p_loggerInfo The logger to unregister
|
||||
*/
|
||||
void UnregisterLogger(const LoggerInfo& p_loggerInfo);
|
||||
|
||||
/**
|
||||
* Register a logger.
|
||||
*
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace Bigfoot
|
||||
{
|
||||
Log::Log()
|
||||
{
|
||||
quill::Backend::start();
|
||||
|
||||
m_sinks[static_cast<std::size_t>(Flat::LogSinkType::Console)] =
|
||||
quill::Frontend::create_or_get_sink<quill::ConsoleSink>(
|
||||
std::string {Flat::EnumNameLogSinkType(Flat::LogSinkType::Console)});
|
||||
@@ -21,6 +19,21 @@ Log::Log()
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
void Log::Start()
|
||||
{
|
||||
quill::Backend::start();
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
void Log::Stop()
|
||||
{
|
||||
Flush();
|
||||
quill::Backend::stop();
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
quill::Logger* Log::RegisterLogger(const LoggerInfo& p_loggerInfo)
|
||||
{
|
||||
quill::Logger* logger = quill::Frontend::create_or_get_logger(
|
||||
@@ -33,6 +46,16 @@ quill::Logger* Log::RegisterLogger(const LoggerInfo& p_loggerInfo)
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
void Log::UnregisterLogger(const LoggerInfo& p_loggerInfo)
|
||||
{
|
||||
if (quill::Logger* logger = quill::Frontend::get_logger(p_loggerInfo.m_name))
|
||||
{
|
||||
quill::Frontend::remove_logger_blocking(logger);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
quill::Logger* Log::GetLogger(const LoggerInfo& p_loggerInfo)
|
||||
{
|
||||
return quill::Frontend::get_logger(p_loggerInfo.m_name);
|
||||
@@ -91,14 +114,10 @@ void Log::Flush()
|
||||
|
||||
Log::~Log()
|
||||
{
|
||||
Flush();
|
||||
|
||||
for (quill::Logger* logger: quill::Frontend::get_all_loggers())
|
||||
{
|
||||
quill::Frontend::remove_logger(logger);
|
||||
}
|
||||
|
||||
quill::Backend::stop();
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
|
||||
32
Bigfoot/Tests/Engine/EngineTests/Environment.cpp
Normal file
32
Bigfoot/Tests/Engine/EngineTests/Environment.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*********************************************************************
|
||||
* \file Environment.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date May 2026
|
||||
*********************************************************************/
|
||||
#include <Utils/Log/LogMacros.hpp>
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class TestingEnvironment: public ::testing::Environment
|
||||
{
|
||||
public:
|
||||
void SetUp() override
|
||||
{
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton<Log>::GetInstance().Start());
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton<Log>::GetInstance().Stop());
|
||||
}
|
||||
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton<Log>::Lifetime m_lifetime);
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
// This runs before main() and registers the environment
|
||||
const ::testing::Environment* const kEnv = ::testing::AddGlobalTestEnvironment(new Bigfoot::TestingEnvironment());
|
||||
32
Bigfoot/Tests/System/SystemTests/Environment.cpp
Normal file
32
Bigfoot/Tests/System/SystemTests/Environment.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*********************************************************************
|
||||
* \file Environment.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date May 2026
|
||||
*********************************************************************/
|
||||
#include <Utils/Log/LogMacros.hpp>
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class TestingEnvironment: public ::testing::Environment
|
||||
{
|
||||
public:
|
||||
void SetUp() override
|
||||
{
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton<Log>::GetInstance().Start());
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton<Log>::GetInstance().Stop());
|
||||
}
|
||||
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton<Log>::Lifetime m_lifetime);
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
// This runs before main() and registers the environment
|
||||
const ::testing::Environment* const kEnv = ::testing::AddGlobalTestEnvironment(new Bigfoot::TestingEnvironment());
|
||||
@@ -6,6 +6,8 @@
|
||||
*********************************************************************/
|
||||
#include <Utils/Log/Log.hpp>
|
||||
|
||||
#include <Utils/Singleton.hpp>
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
@@ -38,7 +40,11 @@ class LogFixture: public ::testing::Test
|
||||
return Flat::LogLevel::Trace;
|
||||
}
|
||||
|
||||
Log m_log;
|
||||
void TearDown() override
|
||||
{
|
||||
Singleton<Log>::GetInstance().UnregisterLogger(m_logger);
|
||||
}
|
||||
|
||||
Log::LoggerInfo m_logger {"LOGGER", Flat::LogLevel::Trace};
|
||||
};
|
||||
|
||||
@@ -46,18 +52,28 @@ class LogFixture: public ::testing::Test
|
||||
|
||||
TEST_F(LogFixture, RegisterLogger_ShouldRegisterTheLogger)
|
||||
{
|
||||
const quill::Logger* logger = m_log.RegisterLogger(m_logger);
|
||||
const quill::Logger* logger = Singleton<Log>::GetInstance().RegisterLogger(m_logger);
|
||||
EXPECT_TRUE(logger);
|
||||
EXPECT_EQ(logger, m_log.GetLogger(m_logger));
|
||||
EXPECT_EQ(logger, Singleton<Log>::GetInstance().GetLogger(m_logger));
|
||||
EXPECT_EQ(logger->get_logger_name(), m_logger.m_name);
|
||||
EXPECT_EQ(QuillLogLevelToLogLevel(logger->get_log_level()), m_logger.m_level);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, UnregisterLogger_ShouldUnregisterTheLogger)
|
||||
{
|
||||
std::ignore = Singleton<Log>::GetInstance().RegisterLogger(m_logger);
|
||||
Singleton<Log>::GetInstance().UnregisterLogger(m_logger);
|
||||
|
||||
EXPECT_EQ(Singleton<Log>::GetInstance().GetLogger(m_logger), nullptr);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, GetLogger_ShouldReturnNullptrIfTheLoggerDoesNotExist)
|
||||
{
|
||||
EXPECT_FALSE(m_log.GetLogger(m_logger));
|
||||
EXPECT_FALSE(Singleton<Log>::GetInstance().GetLogger(m_logger));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
@@ -65,17 +81,17 @@ TEST_F(LogFixture, GetLogger_ShouldReturnNullptrIfTheLoggerDoesNotExist)
|
||||
TEST_F(LogFixture, GetLogger_ShouldReturnTheLoggerIfItExists)
|
||||
{
|
||||
[[maybe_unused]]
|
||||
const quill::Logger* logger = m_log.RegisterLogger(m_logger);
|
||||
EXPECT_TRUE(m_log.GetLogger(m_logger));
|
||||
const quill::Logger* logger = Singleton<Log>::GetInstance().RegisterLogger(m_logger);
|
||||
EXPECT_TRUE(Singleton<Log>::GetInstance().GetLogger(m_logger));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, ChangeLoggerLogLevel_ShouldChangeTheLoggerLogLevel)
|
||||
{
|
||||
const quill::Logger* logger = m_log.RegisterLogger(m_logger);
|
||||
const quill::Logger* logger = Singleton<Log>::GetInstance().RegisterLogger(m_logger);
|
||||
|
||||
m_log.ChangeLoggerLogLevel(m_logger, Flat::LogLevel::Critical);
|
||||
Singleton<Log>::GetInstance().ChangeLoggerLogLevel(m_logger, Flat::LogLevel::Critical);
|
||||
EXPECT_EQ(QuillLogLevelToLogLevel(logger->get_log_level()), Flat::LogLevel::Critical);
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
|
||||
@@ -15,7 +15,11 @@ namespace Bigfoot
|
||||
class LogMacrosFixture: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
Singleton<Log>::Lifetime m_singletonLifetime;
|
||||
void TearDown() override
|
||||
{
|
||||
Singleton<Log>::GetInstance().UnregisterLogger(m_logger);
|
||||
}
|
||||
|
||||
Log::LoggerInfo m_logger {"LOGGER", Flat::LogLevel::Trace};
|
||||
};
|
||||
|
||||
|
||||
32
Bigfoot/Tests/Utils/UtilsTests/Environment.cpp
Normal file
32
Bigfoot/Tests/Utils/UtilsTests/Environment.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*********************************************************************
|
||||
* \file Environment.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date May 2026
|
||||
*********************************************************************/
|
||||
#include <Utils/Log/LogMacros.hpp>
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class TestingEnvironment: public ::testing::Environment
|
||||
{
|
||||
public:
|
||||
void SetUp() override
|
||||
{
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton<Log>::GetInstance().Start());
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton<Log>::GetInstance().Stop());
|
||||
}
|
||||
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton<Log>::Lifetime m_lifetime);
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
// This runs before main() and registers the environment
|
||||
const ::testing::Environment* const kEnv = ::testing::AddGlobalTestEnvironment(new Bigfoot::TestingEnvironment());
|
||||
Reference in New Issue
Block a user