diff --git a/Bigfoot/Tests/Utils/Log/EASTLFormatters.cpp b/Bigfoot/Tests/Utils/Log/EASTLFormatters.cpp new file mode 100644 index 0000000..66f8e34 --- /dev/null +++ b/Bigfoot/Tests/Utils/Log/EASTLFormatters.cpp @@ -0,0 +1,128 @@ +/********************************************************************* + * \file EASTLFormatters.cpp + * + * \author Romain BOULLARD + * \date August 2026 + *********************************************************************/ +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include + +namespace Bigfoot +{ +class EASTLFormattersFixture: public ::testing::Test +{ +}; + +/****************************************************************************************/ +TEST_F(EASTLFormattersFixture, FormatsEastlString) +{ + const eastl::string value = "Hello"; + EXPECT_EQ(fmt::format("{}", value), "Hello"); +} + +/****************************************************************************************/ + +TEST_F(EASTLFormattersFixture, FormatsEastlStringView) +{ + const eastl::string_view value = "Hello"; + EXPECT_EQ(fmt::format("{}", value), "Hello"); +} + +/****************************************************************************************/ + +TEST_F(EASTLFormattersFixture, FormatsEmptyVectorAsEmptyBrackets) +{ + const eastl::vector value; + EXPECT_EQ(fmt::format("{}", value), "[]"); +} + +/****************************************************************************************/ + +TEST_F(EASTLFormattersFixture, FormatsSingleElementVectorWithoutASeparator) +{ + const eastl::vector value {42}; + EXPECT_EQ(fmt::format("{}", value), "[42]"); +} + +/****************************************************************************************/ + +TEST_F(EASTLFormattersFixture, FormatsVectorOfIntsCommaSeparated) +{ + const eastl::vector value {1, 2, 3}; + EXPECT_EQ(fmt::format("{}", value), "[1, 2, 3]"); +} + +/****************************************************************************************/ + +TEST_F(EASTLFormattersFixture, FormatsVectorOfEastlStrings) +{ + const eastl::vector value {"a", "b"}; + EXPECT_EQ(fmt::format("{}", value), "[a, b]"); +} + +/****************************************************************************************/ + +TEST_F(EASTLFormattersFixture, FormatsNestedVectors) +{ + const eastl::vector> value {{1, 2}, {3}}; + EXPECT_EQ(fmt::format("{}", value), "[[1, 2], [3]]"); +} + +/****************************************************************************************/ + +#if defined BIGFOOT_NOT_OPTIMIZED +class EASTLFormattersLogFixture: public ::testing::Test +{ + protected: + eastl::string ReadFileSinkContent() + { + Singleton::GetInstance().Flush(); + + std::ifstream file {std::string {Log::FILE_SINK_PATH.data()}}; + std::stringstream buffer; + buffer << file.rdbuf(); + return eastl::string {buffer.str().c_str()}; + } +}; + +/****************************************************************************************/ + +TEST_F(EASTLFormattersLogFixture, LogsEastlStringArgument) +{ + const eastl::string value = "Hello EASTL string"; + BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "{}", value); + EXPECT_NE(ReadFileSinkContent().find("Hello EASTL string"), eastl::string::npos); +} + +/****************************************************************************************/ + +TEST_F(EASTLFormattersLogFixture, LogsEmptyVectorArgument) +{ + const eastl::vector value; + BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "{}", value); + EXPECT_NE(ReadFileSinkContent().find("[]"), eastl::string::npos); +} + +/****************************************************************************************/ + +TEST_F(EASTLFormattersLogFixture, LogsVectorArgumentWithCommaSeparators) +{ + const eastl::vector value {"a", "b", "c"}; + BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "{}", value); + EXPECT_NE(ReadFileSinkContent().find("[a, b, c]"), eastl::string::npos); +} +#endif +} // namespace Bigfoot