BigFile/Sasquatch #1
@@ -0,0 +1,128 @@
|
||||
/*********************************************************************
|
||||
* \file EASTLFormatters.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date August 2026
|
||||
*********************************************************************/
|
||||
#include <Utils/Log/EASTLFormatters.hpp>
|
||||
|
||||
#include <Utils/Log/LogMacros.hpp>
|
||||
#include <Utils/Singleton.hpp>
|
||||
|
||||
#include <UtilsTests/UtilsTestsLogger_generated.hpp>
|
||||
|
||||
#include <EASTL/string.h>
|
||||
#include <EASTL/string_view.h>
|
||||
#include <EASTL/vector.h>
|
||||
#include <fmt/format.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
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<int> value;
|
||||
EXPECT_EQ(fmt::format("{}", value), "[]");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(EASTLFormattersFixture, FormatsSingleElementVectorWithoutASeparator)
|
||||
{
|
||||
const eastl::vector<int> value {42};
|
||||
EXPECT_EQ(fmt::format("{}", value), "[42]");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(EASTLFormattersFixture, FormatsVectorOfIntsCommaSeparated)
|
||||
{
|
||||
const eastl::vector<int> value {1, 2, 3};
|
||||
EXPECT_EQ(fmt::format("{}", value), "[1, 2, 3]");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(EASTLFormattersFixture, FormatsVectorOfEastlStrings)
|
||||
{
|
||||
const eastl::vector<eastl::string> value {"a", "b"};
|
||||
EXPECT_EQ(fmt::format("{}", value), "[a, b]");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(EASTLFormattersFixture, FormatsNestedVectors)
|
||||
{
|
||||
const eastl::vector<eastl::vector<int>> 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<Log>::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<int> value;
|
||||
BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "{}", value);
|
||||
EXPECT_NE(ReadFileSinkContent().find("[]"), eastl::string::npos);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(EASTLFormattersLogFixture, LogsVectorArgumentWithCommaSeparators)
|
||||
{
|
||||
const eastl::vector<eastl::string> value {"a", "b", "c"};
|
||||
BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "{}", value);
|
||||
EXPECT_NE(ReadFileSinkContent().find("[a, b, c]"), eastl::string::npos);
|
||||
}
|
||||
#endif
|
||||
} // namespace Bigfoot
|
||||
Reference in New Issue
Block a user