From 2c83dcc0bc759fa92deb9dbc87a4ee84d4966232 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 16 May 2026 15:41:05 +0200 Subject: [PATCH] Move Singleton lifetime + refactor logs --- .../Include/Engine/EngineAssertHandler.hpp | 2 - .../Include/Engine/EngineLogger_generated.hpp | 2 +- .../Include/System/SystemAssertHandler.hpp | 2 - .../Include/System/SystemLogger_generated.hpp | 2 +- .../Sources/Utils/Include/Utils/Assert.hpp | 2 +- .../Sources/Utils/Include/Utils/Log/Log.hpp | 92 ---------------- .../Utils/Include/Utils/Log/LogMacros.hpp | 104 ++++++++++++++++++ .../Utils/Log/TargetLogger_generated.hpp.in | 2 +- .../Sources/Utils/Include/Utils/Singleton.hpp | 47 +++++++- .../Include/Utils/UtilsAssertHandler.hpp | 3 - .../Include/Utils/UtilsLogger_generated.hpp | 2 +- Bigfoot/Tests/Engine/Asset/Asset.cpp | 10 -- Bigfoot/Tests/Engine/BigFile/BigFile.cpp | 10 -- Bigfoot/Tests/Utils/CMakeLists.txt | 4 +- .../UtilsTests/UtilsTestsLogger_generated.hpp | 21 ---- Bigfoot/Tests/Utils/Log/Log.cpp | 76 ++----------- Bigfoot/Tests/Utils/Log/LogMacros.cpp | 64 +++++++++++ Bigfoot/Tests/Utils/Singleton.cpp | 33 +++++- 18 files changed, 258 insertions(+), 220 deletions(-) create mode 100644 Bigfoot/Sources/Utils/Include/Utils/Log/LogMacros.hpp delete mode 100644 Bigfoot/Tests/Utils/Include/UtilsTests/UtilsTestsLogger_generated.hpp create mode 100644 Bigfoot/Tests/Utils/Log/LogMacros.cpp diff --git a/Bigfoot/Sources/Engine/Include/Engine/EngineAssertHandler.hpp b/Bigfoot/Sources/Engine/Include/Engine/EngineAssertHandler.hpp index 0692912..b47f803 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/EngineAssertHandler.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/EngineAssertHandler.hpp @@ -11,11 +11,9 @@ #include #if defined BIGFOOT_NOT_OPTIMIZED -#include #include #include -#include namespace Bigfoot { diff --git a/Bigfoot/Sources/Engine/Include/Engine/EngineLogger_generated.hpp b/Bigfoot/Sources/Engine/Include/Engine/EngineLogger_generated.hpp index 49b6617..0067c8c 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/EngineLogger_generated.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/EngineLogger_generated.hpp @@ -6,7 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_ENGINELOGGER_GENERATED_HPP #define BIGFOOT_ENGINELOGGER_GENERATED_HPP -#include +#include #if defined BIGFOOT_NOT_OPTIMIZED diff --git a/Bigfoot/Sources/System/Include/System/SystemAssertHandler.hpp b/Bigfoot/Sources/System/Include/System/SystemAssertHandler.hpp index 0c61c1f..8ee1842 100644 --- a/Bigfoot/Sources/System/Include/System/SystemAssertHandler.hpp +++ b/Bigfoot/Sources/System/Include/System/SystemAssertHandler.hpp @@ -11,11 +11,9 @@ #include #if defined BIGFOOT_NOT_OPTIMIZED -#include #include #include -#include namespace Bigfoot { diff --git a/Bigfoot/Sources/System/Include/System/SystemLogger_generated.hpp b/Bigfoot/Sources/System/Include/System/SystemLogger_generated.hpp index 64b4dc3..cbafc52 100644 --- a/Bigfoot/Sources/System/Include/System/SystemLogger_generated.hpp +++ b/Bigfoot/Sources/System/Include/System/SystemLogger_generated.hpp @@ -6,7 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_SYSTEMLOGGER_GENERATED_HPP #define BIGFOOT_SYSTEMLOGGER_GENERATED_HPP -#include +#include #if defined BIGFOOT_NOT_OPTIMIZED diff --git a/Bigfoot/Sources/Utils/Include/Utils/Assert.hpp b/Bigfoot/Sources/Utils/Include/Utils/Assert.hpp index 9a51a0e..2278a0c 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Assert.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Assert.hpp @@ -6,7 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_UTILS_ASSERT_HPP #define BIGFOOT_UTILS_ASSERT_HPP -#include +#include #if defined BIGFOOT_NOT_OPTIMIZED diff --git a/Bigfoot/Sources/Utils/Include/Utils/Log/Log.hpp b/Bigfoot/Sources/Utils/Include/Utils/Log/Log.hpp index c89082e..4df77c3 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Log/Log.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Log/Log.hpp @@ -10,7 +10,6 @@ #if defined BIGFOOT_NOT_OPTIMIZED #include -#include #include @@ -92,96 +91,5 @@ class Log eastl::array, 1> m_sinks; }; } // namespace Bigfoot - -#define BIGFOOT_LOG_DEBUG(loggerName, fmt, ...) \ - do \ - { \ - if (quill::Logger* logger = Bigfoot::Singleton::Instance().GetLogger(loggerName)) \ - { \ - QUILL_LOG_DEBUG(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ - } \ - else \ - { \ - QUILL_LOG_DEBUG(Bigfoot::Singleton::Instance().RegisterLogger(loggerName), \ - fmt __VA_OPT__(, ) __VA_ARGS__); \ - } \ - } while (0) - -#define BIGFOOT_LOG_TRACE(loggerName, fmt, ...) \ - do \ - { \ - if (quill::Logger* logger = Bigfoot::Singleton::Instance().GetLogger(loggerName)) \ - { \ - QUILL_LOG_TRACE_L3(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ - } \ - else \ - { \ - QUILL_LOG_TRACE_L3(Bigfoot::Singleton::Instance().RegisterLogger(loggerName), \ - fmt __VA_OPT__(, ) __VA_ARGS__); \ - } \ - } while (0) - -#define BIGFOOT_LOG_INFO(loggerName, fmt, ...) \ - do \ - { \ - if (quill::Logger* logger = Bigfoot::Singleton::Instance().GetLogger(loggerName)) \ - { \ - QUILL_LOG_INFO(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ - } \ - else \ - { \ - QUILL_LOG_INFO(Bigfoot::Singleton::Instance().RegisterLogger(loggerName), \ - fmt __VA_OPT__(, ) __VA_ARGS__); \ - } \ - } while (0) - -#define BIGFOOT_LOG_WARN(loggerName, fmt, ...) \ - do \ - { \ - if (quill::Logger* logger = Bigfoot::Singleton::Instance().GetLogger(loggerName)) \ - { \ - QUILL_LOG_WARNING(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ - } \ - else \ - { \ - QUILL_LOG_WARNING(Bigfoot::Singleton::Instance().RegisterLogger(loggerName), \ - fmt __VA_OPT__(, ) __VA_ARGS__); \ - } \ - } while (0) - -#define BIGFOOT_LOG_ERROR(loggerName, fmt, ...) \ - do \ - { \ - if (quill::Logger* logger = Bigfoot::Singleton::Instance().GetLogger(loggerName)) \ - { \ - QUILL_LOG_ERROR(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ - } \ - else \ - { \ - QUILL_LOG_ERROR(Bigfoot::Singleton::Instance().RegisterLogger(loggerName), \ - fmt __VA_OPT__(, ) __VA_ARGS__); \ - } \ - } while (0) - -#define BIGFOOT_LOG_FATAL(loggerName, fmt, ...) \ - do \ - { \ - if (quill::Logger* logger = Bigfoot::Singleton::Instance().GetLogger(loggerName)) \ - { \ - QUILL_LOG_CRITICAL(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ - } \ - else \ - { \ - QUILL_LOG_CRITICAL(Bigfoot::Singleton::Instance().RegisterLogger(loggerName), \ - fmt __VA_OPT__(, ) __VA_ARGS__); \ - } \ - } while (0) -#else -#define BIGFOOT_LOG_DEBUG(loggerName, fmt, ...) -#define BIGFOOT_LOG_TRACE(loggerName, fmt, ...) -#define BIGFOOT_LOG_INFO(loggerName, fmt, ...) -#define BIGFOOT_LOG_WARN(loggerName, fmt, ...) -#define BIGFOOT_LOG_ERROR(loggerName, fmt, ...) -#define BIGFOOT_LOG_FATAL(loggerName, fmt, ...) #endif #endif diff --git a/Bigfoot/Sources/Utils/Include/Utils/Log/LogMacros.hpp b/Bigfoot/Sources/Utils/Include/Utils/Log/LogMacros.hpp new file mode 100644 index 0000000..5be3857 --- /dev/null +++ b/Bigfoot/Sources/Utils/Include/Utils/Log/LogMacros.hpp @@ -0,0 +1,104 @@ +/********************************************************************* + * \file LogMacros.hpp + * + * \author Romain BOULLARD + * \date May 2026 + *********************************************************************/ +#ifndef BIGFOOT_UTILS_LOG_LOGMACROS_HPP +#define BIGFOOT_UTILS_LOG_LOGMACROS_HPP +#include +#include + +#if defined BIGFOOT_NOT_OPTIMIZED +#define BIGFOOT_LOG_DEBUG(loggerName, fmt, ...) \ + do \ + { \ + if (::quill::Logger* logger = ::Bigfoot::Singleton<::Bigfoot::Log>::Instance().GetLogger(loggerName)) \ + { \ + QUILL_LOG_DEBUG(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + else \ + { \ + QUILL_LOG_DEBUG(::Bigfoot::Singleton<::Bigfoot::Log>::Instance().RegisterLogger(loggerName), \ + fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + } while (0) + +#define BIGFOOT_LOG_TRACE(loggerName, fmt, ...) \ + do \ + { \ + if (::quill::Logger* logger = ::Bigfoot::Singleton<::Bigfoot::Log>::Instance().GetLogger(loggerName)) \ + { \ + QUILL_LOG_TRACE_L3(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + else \ + { \ + QUILL_LOG_TRACE_L3(::Bigfoot::Singleton<::Bigfoot::Log>::Instance().RegisterLogger(loggerName), \ + fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + } while (0) + +#define BIGFOOT_LOG_INFO(loggerName, fmt, ...) \ + do \ + { \ + if (::quill::Logger* logger = ::Bigfoot::Singleton<::Bigfoot::Log>::Instance().GetLogger(loggerName)) \ + { \ + QUILL_LOG_INFO(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + else \ + { \ + QUILL_LOG_INFO(::Bigfoot::Singleton<::Bigfoot::Log>::Instance().RegisterLogger(loggerName), \ + fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + } while (0) + +#define BIGFOOT_LOG_WARN(loggerName, fmt, ...) \ + do \ + { \ + if (::quill::Logger* logger = ::Bigfoot::Singleton<::Bigfoot::Log>::Instance().GetLogger(loggerName)) \ + { \ + QUILL_LOG_WARNING(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + else \ + { \ + QUILL_LOG_WARNING(::Bigfoot::Singleton<::Bigfoot::Log>::Instance().RegisterLogger(loggerName), \ + fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + } while (0) + +#define BIGFOOT_LOG_ERROR(loggerName, fmt, ...) \ + do \ + { \ + if (::quill::Logger* logger = ::Bigfoot::Singleton<::Bigfoot::Log>::Instance().GetLogger(loggerName)) \ + { \ + QUILL_LOG_ERROR(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + else \ + { \ + QUILL_LOG_ERROR(::Bigfoot::Singleton<::Bigfoot::Log>::Instance().RegisterLogger(loggerName), \ + fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + } while (0) + +#define BIGFOOT_LOG_FATAL(loggerName, fmt, ...) \ + do \ + { \ + if (::quill::Logger* logger = ::Bigfoot::Singleton<::Bigfoot::Log>::Instance().GetLogger(loggerName)) \ + { \ + QUILL_LOG_CRITICAL(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + else \ + { \ + QUILL_LOG_CRITICAL(::Bigfoot::Singleton<::Bigfoot::Log>::Instance().RegisterLogger(loggerName), \ + fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + } while (0) +#else +#define BIGFOOT_LOG_DEBUG(loggerName, fmt, ...) +#define BIGFOOT_LOG_TRACE(loggerName, fmt, ...) +#define BIGFOOT_LOG_INFO(loggerName, fmt, ...) +#define BIGFOOT_LOG_WARN(loggerName, fmt, ...) +#define BIGFOOT_LOG_ERROR(loggerName, fmt, ...) +#define BIGFOOT_LOG_FATAL(loggerName, fmt, ...) +#endif +#endif diff --git a/Bigfoot/Sources/Utils/Include/Utils/Log/TargetLogger_generated.hpp.in b/Bigfoot/Sources/Utils/Include/Utils/Log/TargetLogger_generated.hpp.in index 7487db3..8977a65 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Log/TargetLogger_generated.hpp.in +++ b/Bigfoot/Sources/Utils/Include/Utils/Log/TargetLogger_generated.hpp.in @@ -6,7 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_@LOGGER_FILENAME_UPPER@_GENERATED_HPP #define BIGFOOT_@LOGGER_FILENAME_UPPER@_GENERATED_HPP -#include +#include #if defined BIGFOOT_NOT_OPTIMIZED diff --git a/Bigfoot/Sources/Utils/Include/Utils/Singleton.hpp b/Bigfoot/Sources/Utils/Include/Utils/Singleton.hpp index 8b8277d..a49c735 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Singleton.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Singleton.hpp @@ -6,7 +6,6 @@ *********************************************************************/ #ifndef BIGFOOT_UTILS_SINGLETON_HPP #define BIGFOOT_UTILS_SINGLETON_HPP - #include #include #include @@ -52,6 +51,9 @@ class Singleton /** * Constructor. * + * Initializes the singleton; this lifetime owns the instance and + * finalizes it on destruction. + * * \param p_args Arguments for the singleton */ template @@ -60,16 +62,53 @@ class Singleton Initialize(std::forward(p_args)...); } + struct EmptyLifetime + { + }; + + static inline constexpr EmptyLifetime EMPTY_LIFETIME; + + /** + * Non-owning constructor. + * + * Does not initialize the singleton and owns nothing. Such a lifetime + * only becomes an owner if it later receives ownership through move + * assignment. + */ + explicit Lifetime(EmptyLifetime) noexcept: + m_owner(false) + { + } + Lifetime(const Lifetime& p_lifetime) = delete; - Lifetime(Lifetime&& p_lifetime) = delete; + + explicit Lifetime(Lifetime&& p_lifetime) noexcept: + m_owner(eastl::exchange(p_lifetime.m_owner, false)) + { + } ~Lifetime() { - Finalize(); + if (m_owner) + { + Finalize(); + } } Lifetime& operator=(const Lifetime& p_lifetime) = delete; - Lifetime& operator=(Lifetime&& p_lifetime) = delete; + + Lifetime& operator=(Lifetime&& p_lifetime) noexcept + { + m_owner = eastl::exchange(p_lifetime.m_owner, false); + + return *this; + } + + private: + /** + * Whether this lifetime owns the singleton instance or not. + */ + bool m_owner = true; }; Singleton& operator=(const Singleton& p_singleton) = delete; diff --git a/Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp b/Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp index 88e6128..7777449 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp @@ -7,15 +7,12 @@ #ifndef BIGFOOT_UTILS_UTILSASSERTHANDLER_HPP #define BIGFOOT_UTILS_UTILSASSERTHANDLER_HPP #include -#include #include #if defined BIGFOOT_NOT_OPTIMIZED -#include #include #include -#include namespace Bigfoot { diff --git a/Bigfoot/Sources/Utils/Include/Utils/UtilsLogger_generated.hpp b/Bigfoot/Sources/Utils/Include/Utils/UtilsLogger_generated.hpp index 0db2942..e58a250 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/UtilsLogger_generated.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/UtilsLogger_generated.hpp @@ -6,7 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_UTILSLOGGER_GENERATED_HPP #define BIGFOOT_UTILSLOGGER_GENERATED_HPP -#include +#include #if defined BIGFOOT_NOT_OPTIMIZED diff --git a/Bigfoot/Tests/Engine/Asset/Asset.cpp b/Bigfoot/Tests/Engine/Asset/Asset.cpp index a6e8c01..03050b2 100644 --- a/Bigfoot/Tests/Engine/Asset/Asset.cpp +++ b/Bigfoot/Tests/Engine/Asset/Asset.cpp @@ -6,10 +6,6 @@ *********************************************************************/ #include -#include - -#include -#include #include #include @@ -23,12 +19,6 @@ namespace Bigfoot class AssetFixture: public ::testing::Test { protected: - void SetUp() override - { - BIGFOOT_NOT_OPTIMIZED_ONLY(std::ignore = Singleton::Instance().RegisterLogger(ENGINE_LOGGER);) - } - - BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton::Lifetime m_loggerLifetime;) }; /****************************************************************************************/ diff --git a/Bigfoot/Tests/Engine/BigFile/BigFile.cpp b/Bigfoot/Tests/Engine/BigFile/BigFile.cpp index 5868804..85d85cb 100644 --- a/Bigfoot/Tests/Engine/BigFile/BigFile.cpp +++ b/Bigfoot/Tests/Engine/BigFile/BigFile.cpp @@ -6,15 +6,9 @@ *********************************************************************/ #include -#include - #include #include -#include -#include -#include - #include #include @@ -35,12 +29,8 @@ class BigFileFixture: public ::testing::Test deleteHeader.Execute(); deleteAsset.Execute(); m_bigFile.CommitTransaction(); - - BIGFOOT_NOT_OPTIMIZED_ONLY(std::ignore = Singleton::Instance().RegisterLogger(ENGINE_LOGGER);) } - BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton::Lifetime m_loggerLifetime;) - BigFile m_bigFile {File {BIGFILE_ENGINETESTS_LOCATION}}; }; diff --git a/Bigfoot/Tests/Utils/CMakeLists.txt b/Bigfoot/Tests/Utils/CMakeLists.txt index eb59da7..6c98a7c 100644 --- a/Bigfoot/Tests/Utils/CMakeLists.txt +++ b/Bigfoot/Tests/Utils/CMakeLists.txt @@ -2,6 +2,4 @@ get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME) project(${PackageName}Tests) bigfoot_create_package_tests( - "") - -bigfoot_create_logger() \ No newline at end of file + "") \ No newline at end of file diff --git a/Bigfoot/Tests/Utils/Include/UtilsTests/UtilsTestsLogger_generated.hpp b/Bigfoot/Tests/Utils/Include/UtilsTests/UtilsTestsLogger_generated.hpp deleted file mode 100644 index 12c70fb..0000000 --- a/Bigfoot/Tests/Utils/Include/UtilsTests/UtilsTestsLogger_generated.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// AUTO-GENERATED DO NOT TOUCH - -/********************************************************************* - * \file UtilsTestsLogger.generated.hpp - * - *********************************************************************/ -#ifndef BIGFOOT_UTILSTESTSLOGGER_GENERATED_HPP -#define BIGFOOT_UTILSTESTSLOGGER_GENERATED_HPP -#include - -#if defined BIGFOOT_NOT_OPTIMIZED - -namespace Bigfoot -{ -/* - * Logger - */ -inline Log::LoggerInfo UTILSTESTS_LOGGER {"UTILSTESTS_LOGGER", Flat::LogLevel::Trace}; -} // namespace Bigfoot -#endif -#endif diff --git a/Bigfoot/Tests/Utils/Log/Log.cpp b/Bigfoot/Tests/Utils/Log/Log.cpp index 353de07..470c27e 100644 --- a/Bigfoot/Tests/Utils/Log/Log.cpp +++ b/Bigfoot/Tests/Utils/Log/Log.cpp @@ -6,10 +6,6 @@ *********************************************************************/ #include -#include - -#include - #if defined BIGFOOT_NOT_OPTIMIZED #include @@ -19,11 +15,6 @@ namespace Bigfoot class LogFixture: public ::testing::Test { protected: - void SetUp() override - { - UTILSTESTS_LOGGER = {"UTILSTESTS_LOGGER", Flat::LogLevel::Trace}; - } - static constexpr Flat::LogLevel QuillLogLevelToLogLevel(const quill::LogLevel p_level) { switch (p_level) @@ -48,24 +39,25 @@ class LogFixture: public ::testing::Test } Log m_log; + Log::LoggerInfo m_logger {"LOGGER", Flat::LogLevel::Trace}; }; /****************************************************************************************/ TEST_F(LogFixture, RegisterLogger_ShouldRegisterTheLogger) { - const quill::Logger* logger = m_log.RegisterLogger(UTILSTESTS_LOGGER); + const quill::Logger* logger = m_log.RegisterLogger(m_logger); EXPECT_TRUE(logger); - EXPECT_EQ(logger, m_log.GetLogger(UTILSTESTS_LOGGER)); - EXPECT_EQ(logger->get_logger_name(), UTILSTESTS_LOGGER.m_name); - EXPECT_EQ(QuillLogLevelToLogLevel(logger->get_log_level()), UTILSTESTS_LOGGER.m_level); + EXPECT_EQ(logger, m_log.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, GetLogger_ShouldReturnNullptrIfTheLoggerDoesNotExist) { - EXPECT_FALSE(m_log.GetLogger(UTILSTESTS_LOGGER)); + EXPECT_FALSE(m_log.GetLogger(m_logger)); } /****************************************************************************************/ @@ -73,66 +65,18 @@ TEST_F(LogFixture, GetLogger_ShouldReturnNullptrIfTheLoggerDoesNotExist) TEST_F(LogFixture, GetLogger_ShouldReturnTheLoggerIfItExists) { [[maybe_unused]] - const quill::Logger* logger = m_log.RegisterLogger(UTILSTESTS_LOGGER); - EXPECT_TRUE(m_log.GetLogger(UTILSTESTS_LOGGER)); + const quill::Logger* logger = m_log.RegisterLogger(m_logger); + EXPECT_TRUE(m_log.GetLogger(m_logger)); } /****************************************************************************************/ TEST_F(LogFixture, ChangeLoggerLogLevel_ShouldChangeTheLoggerLogLevel) { - const quill::Logger* logger = m_log.RegisterLogger(UTILSTESTS_LOGGER); + const quill::Logger* logger = m_log.RegisterLogger(m_logger); - m_log.ChangeLoggerLogLevel(UTILSTESTS_LOGGER, Flat::LogLevel::Critical); + m_log.ChangeLoggerLogLevel(m_logger, Flat::LogLevel::Critical); EXPECT_EQ(QuillLogLevelToLogLevel(logger->get_log_level()), Flat::LogLevel::Critical); } - -/****************************************************************************************/ - -TEST_F(LogFixture, LogDebug) -{ - Singleton::Lifetime singletonLifetime; - BIGFOOT_LOG_DEBUG(UTILSTESTS_LOGGER, "Hello"); -} - -/****************************************************************************************/ - -TEST_F(LogFixture, LogTrace) -{ - Singleton::Lifetime singletonLifetime; - BIGFOOT_LOG_TRACE(UTILSTESTS_LOGGER, "Hello"); -} - -/****************************************************************************************/ - -TEST_F(LogFixture, LogInfo) -{ - Singleton::Lifetime singletonLifetime; - BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "Hello"); -} - -/****************************************************************************************/ - -TEST_F(LogFixture, LogWarn) -{ - Singleton::Lifetime singletonLifetime; - BIGFOOT_LOG_WARN(UTILSTESTS_LOGGER, "Hello"); -} - -/****************************************************************************************/ - -TEST_F(LogFixture, LogError) -{ - Singleton::Lifetime singletonLifetime; - BIGFOOT_LOG_ERROR(UTILSTESTS_LOGGER, "Hello"); -} - -/****************************************************************************************/ - -TEST_F(LogFixture, LogFatal) -{ - Singleton::Lifetime singletonLifetime; - BIGFOOT_LOG_FATAL(UTILSTESTS_LOGGER, "Hello"); -} } // namespace Bigfoot #endif diff --git a/Bigfoot/Tests/Utils/Log/LogMacros.cpp b/Bigfoot/Tests/Utils/Log/LogMacros.cpp new file mode 100644 index 0000000..903dbf7 --- /dev/null +++ b/Bigfoot/Tests/Utils/Log/LogMacros.cpp @@ -0,0 +1,64 @@ +/********************************************************************* + * \file LogMacros.cpp + * + * \author Romain BOULLARD + * \date May 2026 + *********************************************************************/ +#include + +#if defined BIGFOOT_NOT_OPTIMIZED + +#include + +namespace Bigfoot +{ +class LogMacrosFixture: public ::testing::Test +{ + protected: + Singleton::Lifetime m_singletonLifetime; + Log::LoggerInfo m_logger {"LOGGER", Flat::LogLevel::Trace}; +}; + +/****************************************************************************************/ + +TEST_F(LogMacrosFixture, LogDebug) +{ + BIGFOOT_LOG_DEBUG(m_logger, "Hello"); +} + +/****************************************************************************************/ + +TEST_F(LogMacrosFixture, LogTrace) +{ + BIGFOOT_LOG_TRACE(m_logger, "Hello"); +} + +/****************************************************************************************/ + +TEST_F(LogMacrosFixture, LogInfo) +{ + BIGFOOT_LOG_INFO(m_logger, "Hello"); +} + +/****************************************************************************************/ + +TEST_F(LogMacrosFixture, LogWarn) +{ + BIGFOOT_LOG_WARN(m_logger, "Hello"); +} + +/****************************************************************************************/ + +TEST_F(LogMacrosFixture, LogError) +{ + BIGFOOT_LOG_ERROR(m_logger, "Hello"); +} + +/****************************************************************************************/ + +TEST_F(LogMacrosFixture, LogFatal) +{ + BIGFOOT_LOG_FATAL(m_logger, "Hello"); +} +} // namespace Bigfoot +#endif diff --git a/Bigfoot/Tests/Utils/Singleton.cpp b/Bigfoot/Tests/Utils/Singleton.cpp index 4f089b3..0570059 100644 --- a/Bigfoot/Tests/Utils/Singleton.cpp +++ b/Bigfoot/Tests/Utils/Singleton.cpp @@ -84,14 +84,43 @@ TEST_F(SingletonFixture, ConstructorAndDestructorShouldBeCalled) { ::testing::InSequence seq; - EXPECT_CALL(*m_mock, Construct()); - EXPECT_CALL(*m_mock, Destruct()); + EXPECT_CALL(*m_mock, Construct()).Times(1); + EXPECT_CALL(*m_mock, Destruct()).Times(1); Singleton::Lifetime singleton {42}; } /****************************************************************************************/ +TEST_F(SingletonFixture, ConstructorAndDestructorShouldNotBeCalledForEmptyLifetime) +{ + ::testing::InSequence seq; + + EXPECT_CALL(*m_mock, Construct()).Times(0); + EXPECT_CALL(*m_mock, Destruct()).Times(0); + + Singleton::Lifetime singleton {Singleton::Lifetime::EMPTY_LIFETIME}; +} + +/****************************************************************************************/ + +TEST_F(SingletonFixture, MovingALifetimeKeepsTheSIngletonAlive) +{ + ::testing::InSequence seq; + + EXPECT_CALL(*m_mock, Construct()).Times(1); + EXPECT_CALL(*m_mock, Destruct()).Times(1); + + Singleton::Lifetime emptyLifetime {Singleton::Lifetime::EMPTY_LIFETIME}; + { + Singleton::Lifetime singleton {42}; + emptyLifetime = std::move(singleton); + } + EXPECT_EQ(Singleton::Instance().Data(), 42); +} + +/****************************************************************************************/ + TEST_F(SingletonFixture, Instance_ShouldReturnTheInstance) { Singleton::Lifetime singleton {42};