Sanitizers

This commit is contained in:
2026-02-20 21:01:49 +01:00
committed by Romain BOULLARD
parent 934b44c1f8
commit f780e6f59a
3 changed files with 88 additions and 16 deletions

View File

@@ -1,39 +1,73 @@
/********************************************************************* /*********************************************************************
* \file Singleton.cpp * \file Log.cpp
* *
* \author Romain BOULLARD * \author Romain BOULLARD
* \date February 2026 * \date February 2026
*********************************************************************/ *********************************************************************/
#include <Singleton.hpp> #include <Log.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>
namespace Bin2CPP namespace Bin2CPP
{ {
class SingletonFixture: public ::testing::Test class LogFixture: public ::testing::Test
{ {
protected: protected:
Singleton<std::uint8_t>::Lifetime m_lifetime{8}; Log m_log;
}; };
/****************************************************************************************/ /****************************************************************************************/
TEST_F(SingletonFixture, HasInstance_ShouldReturnTrueIfSingletonIsInitialized) TEST_F(LogFixture, GetLogger_ShouldReturnTheLogger)
{ {
EXPECT_TRUE(Singleton<std::uint8_t>::HasInstance()); EXPECT_TRUE(m_log.GetLogger());
} }
/****************************************************************************************/ /****************************************************************************************/
TEST_F(SingletonFixture, HasInstance_ShouldReturnFaleIfSingletonIsNotInitialized) TEST_F(LogFixture, LogDebug)
{ {
EXPECT_FALSE(Singleton<std::uint32_t>::HasInstance()); Singleton<Log>::Lifetime singletonLifetime;
BIN2CPP_LOG_DEBUG("Hello");
} }
/****************************************************************************************/ /****************************************************************************************/
TEST_F(SingletonFixture, Instance_ShouldReturnTheInstance) TEST_F(LogFixture, LogTrace)
{ {
EXPECT_EQ(Singleton<std::uint8_t>::Instance(), 8); Singleton<Log>::Lifetime singletonLifetime;
BIN2CPP_LOG_TRACE("Hello");
}
/****************************************************************************************/
TEST_F(LogFixture, LogInfo)
{
Singleton<Log>::Lifetime singletonLifetime;
BIN2CPP_LOG_INFO("Hello");
}
/****************************************************************************************/
TEST_F(LogFixture, LogWarn)
{
Singleton<Log>::Lifetime singletonLifetime;
BIN2CPP_LOG_WARN("Hello");
}
/****************************************************************************************/
TEST_F(LogFixture, LogError)
{
Singleton<Log>::Lifetime singletonLifetime;
BIN2CPP_LOG_ERROR("Hello");
}
/****************************************************************************************/
TEST_F(LogFixture, LogFatal)
{
Singleton<Log>::Lifetime singletonLifetime;
BIN2CPP_LOG_FATAL("Hello");
} }
} // namespace Bin2CPP } // namespace Bin2CPP

View File

@@ -1,3 +1,39 @@
// /*********************************************************************
// Created by romain on 16/02/2026. * \file Singleton.cpp
// *
* \author Romain BOULLARD
* \date February 2026
*********************************************************************/
#include <Singleton.hpp>
#include <gtest/gtest.h>
namespace Bin2CPP
{
class SingletonFixture: public ::testing::Test
{
protected:
Singleton<std::uint8_t>::Lifetime m_lifetime{8};
};
/****************************************************************************************/
TEST_F(SingletonFixture, HasInstance_ShouldReturnTrueIfSingletonIsInitialized)
{
EXPECT_TRUE(Singleton<std::uint8_t>::HasInstance());
}
/****************************************************************************************/
TEST_F(SingletonFixture, HasInstance_ShouldReturnFaleIfSingletonIsNotInitialized)
{
EXPECT_FALSE(Singleton<std::uint32_t>::HasInstance());
}
/****************************************************************************************/
TEST_F(SingletonFixture, Instance_ShouldReturnTheInstance)
{
EXPECT_EQ(Singleton<std::uint8_t>::Instance(), 8);
}
} // namespace Bin2CPP

View File

@@ -9,8 +9,10 @@ compiler.cstd=17
build_type=Debug build_type=Debug
[conf] [conf]
tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'}
tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}}
tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}}
tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_SHARED_LINK_FLAGS': {'value': '-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'SHARED link flags for Bigfoot', 'force': True}}
tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bigfoot', 'force': True}}
tools.cmake.cmaketoolchain:generator=Ninja tools.cmake.cmaketoolchain:generator=Ninja
tools.system.package_manager:mode=install tools.system.package_manager:mode=install
tools.system.package_manager:sudo=True tools.system.package_manager:sudo=True