Initial commit

This commit is contained in:
2026-01-27 17:13:49 +01:00
commit a82ec43e74
76 changed files with 4584 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/System)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Utils)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Engine)

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,7 @@
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
bigfoot_create_bigfile(${PackageName}Tests "Tests/Bigfoot")
bigfoot_create_package_tests(
${PackageName}
"")

View File

@@ -0,0 +1,19 @@
// AUTO-GENERATED DO NOT TOUCH
/*********************************************************************
* \file BigFileInfo.generated.hpp
*
*********************************************************************/
#ifndef BIGFOOT_BIGFOOT_BIGFILEINFO_GENERATED_HPP
#define BIGFOOT_BIGFOOT_BIGFILEINFO_GENERATED_HPP
#include <string_view>
namespace Bigfoot
{
/*
* BigFile location
*/
constexpr std::string_view BIGFILE_BIGFOOT_LOCATION{"D:/Development/bigfootdev/bigfoot2/build/Bigfoot/Tests/Engine/Bigfoot-bigfile.db"};
}
#endif

View File

@@ -0,0 +1,19 @@
// AUTO-GENERATED DO NOT TOUCH
/*********************************************************************
* \file BigFileInfo.generated.hpp
*
*********************************************************************/
#ifndef BIGFOOT_ENGINE_BIGFILE_BIGFILEINFO_GENERATED_HPP
#define BIGFOOT_ENGINE_BIGFILE_BIGFILEINFO_GENERATED_HPP
#include <string_view>
namespace Bigfoot
{
/*
* BigFile location
*/
constexpr std::string_view BIGFILE_ENGINETESTS_LOCATION{"D:/Development/bigfootdev/bigfoot2/build/Bigfoot/Tests/Engine/EngineTests-bigfile.db"};
}
#endif

View File

@@ -0,0 +1,19 @@
// AUTO-GENERATED DO NOT TOUCH
/*********************************************************************
* \file BigFileInfo.generated.hpp
*
*********************************************************************/
#ifndef BIGFOOT_ENGINETESTS_BIGFILEINFO_GENERATED_HPP
#define BIGFOOT_ENGINETESTS_BIGFILEINFO_GENERATED_HPP
#include <EASTL/string_view.h>
namespace Bigfoot
{
/*
* BigFile location
*/
constexpr eastl::string_view BIGFILE_ENGINETESTS_LOCATION {"./EngineTests-bigfile.db"};
} // namespace Bigfoot
#endif

View File

@@ -0,0 +1,7 @@
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
set(Dependencies)
bigfoot_create_package_tests(
${PackageName}
"")

View File

@@ -0,0 +1,182 @@
/*********************************************************************
* \file UUID.cpp
*
* \author Romain BOULLARD
* \date October 2025
*********************************************************************/
#include <System/UUID.hpp>
#include <ankerl/unordered_dense.h>
#include <gtest/gtest.h>
namespace Bigfoot
{
class UUIDFixture: public ::testing::Test
{
protected:
UUID m_a;
UUID m_b {"47183823-2574-4bfd-b411-99ed177d3e43"};
UUID m_c {"4bfd-b411-99ed177d3e43"};
std::array<std::byte, 16> m_raw {
std::byte {0},
std::byte {1},
std::byte {2},
std::byte {3},
std::byte {4},
std::byte {5},
std::byte {6},
std::byte {7},
std::byte {8},
std::byte {9},
std::byte {10},
std::byte {11},
std::byte {12},
std::byte {13},
std::byte {14},
std::byte {15},
};
UUID m_d {m_raw};
};
/****************************************************************************************/
TEST_F(UUIDFixture, DumpingRawAndConstructAnUUIDWithItShouldGiveTheSameUUID)
{
std::span<const std::byte, UUID::UUID_BYTE_SIZE> raw = m_a;
EXPECT_EQ(m_a, UUID {raw});
raw = m_b;
EXPECT_EQ(m_b, UUID {raw});
raw = m_d;
EXPECT_EQ(m_d, UUID {raw});
}
/****************************************************************************************/
TEST_F(UUIDFixture, ValidIDFromStringShouldBeEqualToString)
{
EXPECT_EQ(static_cast<std::string>(m_b), "47183823-2574-4bfd-b411-99ed177d3e43");
}
/****************************************************************************************/
TEST_F(UUIDFixture, InvalidIDFromStringShouldNotBeEqualToString)
{
EXPECT_NE(static_cast<std::string>(m_c), "4bfd-b411-99ed177d3e43");
}
/****************************************************************************************/
TEST_F(UUIDFixture, NullIDStringShouldBeEqualToNullIDString)
{
EXPECT_EQ(static_cast<std::string>(UUID::NULL_UUID), "00000000-0000-0000-0000-000000000000");
}
/****************************************************************************************/
TEST_F(UUIDFixture, DefaultConstructedIDShouldBeValid)
{
EXPECT_TRUE(m_a);
}
/****************************************************************************************/
TEST_F(UUIDFixture, StringConstructedIDFromAValidStringShouldBeValid)
{
EXPECT_TRUE(m_b);
}
/****************************************************************************************/
TEST_F(UUIDFixture, StringConstructedIDFromAnInvalidStringShouldBeInvalid)
{
EXPECT_FALSE(m_c);
}
/****************************************************************************************/
TEST_F(UUIDFixture, RawConstructedIDShouldBeValid)
{
EXPECT_TRUE(m_d);
}
/****************************************************************************************/
TEST_F(UUIDFixture, ConstructingFromRawShouldAlwaysGiveTheSameUUID)
{
EXPECT_EQ(m_d, UUID {"00010203-0405-0607-0809-0a0b0c0d0e0f"});
}
/****************************************************************************************/
TEST_F(UUIDFixture, NullIDShouldNotBeValid)
{
EXPECT_FALSE(UUID::NULL_UUID);
}
/****************************************************************************************/
TEST_F(UUIDFixture, IDShouldBeEqualToItself)
{
EXPECT_EQ(m_a, m_a);
}
/****************************************************************************************/
TEST_F(UUIDFixture, IDConstructedFromOtherIDShouldBeEqual)
{
EXPECT_EQ(m_a, UUID {m_a});
}
/****************************************************************************************/
TEST_F(UUIDFixture, IDCopiedFromOtherIDShouldBeEqual)
{
const UUID m_aDuplicate = m_a;
EXPECT_EQ(m_a, m_aDuplicate);
}
/****************************************************************************************/
TEST_F(UUIDFixture, ValidIDsShouldNotBeEqualToNullID)
{
EXPECT_NE(m_a, UUID::NULL_UUID);
EXPECT_NE(m_b, UUID::NULL_UUID);
EXPECT_NE(m_d, UUID::NULL_UUID);
}
/****************************************************************************************/
TEST_F(UUIDFixture, InvalidIDsShouldBeEqualToNullID)
{
EXPECT_EQ(m_c, UUID::NULL_UUID);
}
/****************************************************************************************/
TEST_F(UUIDFixture, GeneratingFiveMillionUniqueID)
{
ankerl::unordered_dense::set<UUID> m_ids;
for (std::uint32_t index = 0; index < 5'000'000; ++index)
{
EXPECT_TRUE(m_ids.insert(UUID {}).second);
}
}
/****************************************************************************************/
TEST_F(UUIDFixture, Raw_ShouldGiveBackTheRawDataOfTheID)
{
std::span<const std::byte, UUID::UUID_BYTE_SIZE> d = m_d;
std::span<const std::byte, UUID::UUID_BYTE_SIZE> raw = m_raw;
for (std::uint32_t i = 0; i < UUID::UUID_BYTE_SIZE; ++i)
{
EXPECT_EQ(d[i], raw[i]);
}
}
} // namespace Bigfoot

View File

@@ -0,0 +1,9 @@
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
set(Dependencies)
bigfoot_create_logger(${PackageName}Tests)
bigfoot_create_package_tests(
${PackageName}
"")

View File

@@ -0,0 +1,121 @@
/*********************************************************************
* \file Caster.cpp
*
* \author Romain BOULLARD
* \date October 2025
*********************************************************************/
#include <Utils/Caster.hpp>
#include <gtest/gtest.h>
namespace Bigfoot
{
class Parent
{
public:
Parent(const std::uint32_t p_value):
m_value(p_value)
{
}
virtual ~Parent() = default;
std::uint32_t GetParentValue() const
{
return m_value;
}
virtual std::uint32_t GetChildValue() const = 0;
private:
std::uint32_t m_value;
};
/****************************************************************************************/
class ChildA final: public Parent
{
public:
ChildA(const std::uint32_t p_value):
Parent(28),
m_value(p_value)
{
}
~ChildA() override = default;
std::uint32_t GetChildValue() const override
{
return m_value;
}
private:
std::uint32_t m_value;
};
/****************************************************************************************/
class ChildB final: public Parent
{
public:
ChildB(const std::uint32_t p_value):
Parent(34),
m_value(p_value)
{
}
~ChildB() override = default;
std::uint32_t GetChildValue() const override
{
return m_value;
}
private:
std::uint32_t m_value;
};
/****************************************************************************************/
class CasterFixture: public ::testing::Test
{
protected:
std::unique_ptr<Parent> m_a = std::make_unique<ChildA>(42);
ChildB m_b {12};
};
/****************************************************************************************/
TEST_F(CasterFixture, ObjectCast)
{
EXPECT_EQ(m_a->GetParentValue(), 28);
EXPECT_EQ(m_a->GetChildValue(), 42);
const ChildA* child = BIGFOOT_OBJECT_CAST(ChildA, m_a.get());
EXPECT_EQ(child->GetParentValue(), 28);
EXPECT_EQ(child->GetChildValue(), 42);
EXPECT_EQ(m_b.GetParentValue(), 34);
EXPECT_EQ(m_b.GetChildValue(), 12);
const Parent& parent = BIGFOOT_OBJECT_CAST(Parent, m_b);
EXPECT_EQ(parent.GetParentValue(), 34);
}
/****************************************************************************************/
TEST_F(CasterFixture, NumericCast)
{
const std::uint32_t a = 128;
const std::uint8_t b = BIGFOOT_NUMERIC_CAST(std::uint8_t, a);
EXPECT_EQ(a, b);
}
/****************************************************************************************/
#ifdef BIGFOOT_NOT_OPTIMIZED
TEST_F(CasterFixture, NumericCast_ShouldAssertIfWeLoseDataDuringTheCast)
{
const std::uint32_t a = 1000;
EXPECT_DEATH(BIGFOOT_NUMERIC_CAST(std::uint8_t, a), "");
}
#endif
} // namespace Bigfoot

View File

@@ -0,0 +1,36 @@
/*********************************************************************
* \file Concat.cpp
*
* \author Romain BOULLARD
* \date October 2025
*********************************************************************/
#include <Utils/Concat.h>
#include <gtest/gtest.h>
namespace Bigfoot
{
class ConcatFixture: public ::testing::Test
{
};
/****************************************************************************************/
TEST_F(ConcatFixture, ShouldConcatTheTwoStrings)
{
constexpr std::string_view result = CONCAT("a", "b");
EXPECT_STREQ(result.data(), "ab");
}
/****************************************************************************************/
TEST_F(ConcatFixture, UniqueName)
{
// this looks wrong, but this should expand to test_30 and test_31
constexpr std::uint32_t MAKE_UNIQUE_VARIABLE_NAME(test) = 1;
constexpr std::uint32_t MAKE_UNIQUE_VARIABLE_NAME(test) = 2;
EXPECT_EQ(test_30, 1);
EXPECT_EQ(test_31, 2);
}
} // namespace Bigfoot

View File

@@ -0,0 +1,21 @@
// AUTO-GENERATED DO NOT TOUCH
/*********************************************************************
* \file UtilsTestsLogger.generated.hpp
*
*********************************************************************/
#ifndef BIGFOOT_UTILSTESTSLOGGER_GENERATED_HPP
#define BIGFOOT_UTILSTESTSLOGGER_GENERATED_HPP
#include <Utils/Log.hpp>
#if defined BIGFOOT_NOT_OPTIMIZED
namespace Bigfoot
{
/*
* Logger
*/
inline Log::LoggerInfo UTILSTESTS_LOGGER {"UTILSTESTS_LOGGER", Log::LogLevel::Trace};
}
#endif
#endif

130
Bigfoot/Tests/Utils/Log.cpp Normal file
View File

@@ -0,0 +1,130 @@
/*********************************************************************
* \file Log.cpp
*
* \author Romain BOULLARD
* \date December 2022
*********************************************************************/
#include <Utils/Log.hpp>
#include <UtilsTests/UtilsTestsLogger.generated.hpp>
#if defined BIGFOOT_NOT_OPTIMIZED
#include <gtest/gtest.h>
namespace Bigfoot
{
class LogFixture: public ::testing::Test
{
protected:
void SetUp() override
{
UTILSTESTS_LOGGER = {"UTILSTESTS_LOGGER", Log::LogLevel::Trace};
}
constexpr Log::LogLevel QuillLogLevelToLogLevel(const quill::LogLevel p_level)
{
switch (p_level)
{
case quill::LogLevel::Debug:
return Log::LogLevel::Debug;
case quill::LogLevel::TraceL3:
return Log::LogLevel::Trace;
case quill::LogLevel::Info:
return Log::LogLevel::Info;
case quill::LogLevel::Warning:
return Log::LogLevel::Warn;
case quill::LogLevel::Error:
return Log::LogLevel::Error;
case quill::LogLevel::Critical:
return Log::LogLevel::Critical;
default:
break;
}
return Log::LogLevel::Trace;
}
Singleton<Log>::Lifetime m_log;
};
/****************************************************************************************/
TEST_F(LogFixture, RegisterLogger_ShouldRegisterTheLogger)
{
const quill::Logger* logger = Singleton<Log>::Instance().RegisterLogger(UTILSTESTS_LOGGER);
EXPECT_TRUE(logger);
EXPECT_EQ(logger, Singleton<Log>::Instance().GetLogger(UTILSTESTS_LOGGER));
EXPECT_EQ(logger->get_logger_name(), UTILSTESTS_LOGGER.m_name);
EXPECT_EQ(QuillLogLevelToLogLevel(logger->get_log_level()), UTILSTESTS_LOGGER.m_level);
}
/****************************************************************************************/
TEST_F(LogFixture, GetLogger_ShouldReturnNullptrIfTheLoggerDoesNotExist)
{
EXPECT_FALSE(Singleton<Log>::Instance().GetLogger(UTILSTESTS_LOGGER));
}
/****************************************************************************************/
TEST_F(LogFixture, GetLogger_ShouldReturnTheLoggerIfItExists)
{
[[maybe_unused]]
const quill::Logger* logger = Singleton<Log>::Instance().RegisterLogger(UTILSTESTS_LOGGER);
EXPECT_TRUE(Singleton<Log>::Instance().GetLogger(UTILSTESTS_LOGGER));
}
/****************************************************************************************/
TEST_F(LogFixture, ChangeLoggerLogLevel_ShouldChangeTheLoggerLogLevel)
{
const quill::Logger* logger = Singleton<Log>::Instance().RegisterLogger(UTILSTESTS_LOGGER);
Singleton<Log>::Instance().ChangeLoggerLogLevel(UTILSTESTS_LOGGER, Log::LogLevel::Critical);
EXPECT_EQ(QuillLogLevelToLogLevel(logger->get_log_level()), Log::LogLevel::Critical);
}
/****************************************************************************************/
TEST_F(LogFixture, LogDebug)
{
BIGFOOT_LOG_DEBUG(UTILSTESTS_LOGGER, "Hello");
}
/****************************************************************************************/
TEST_F(LogFixture, LogTrace)
{
BIGFOOT_LOG_TRACE(UTILSTESTS_LOGGER, "Hello");
}
/****************************************************************************************/
TEST_F(LogFixture, LogInfo)
{
BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "Hello");
}
/****************************************************************************************/
TEST_F(LogFixture, LogWarn)
{
BIGFOOT_LOG_WARN(UTILSTESTS_LOGGER, "Hello");
}
/****************************************************************************************/
TEST_F(LogFixture, LogError)
{
BIGFOOT_LOG_ERROR(UTILSTESTS_LOGGER, "Hello");
}
/****************************************************************************************/
TEST_F(LogFixture, LogFatal)
{
BIGFOOT_LOG_FATAL(UTILSTESTS_LOGGER, "Hello");
}
} // namespace Bigfoot
#endif

View File

@@ -0,0 +1,102 @@
/*********************************************************************
* \file Singleton.cpp
*
* \author Romain BOULLARD
* \date October 2025
*********************************************************************/
#include <Utils/Singleton.hpp>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace Bigfoot
{
class SingletonMock
{
public:
virtual ~SingletonMock() = default;
virtual void Construct() = 0;
virtual void Destruct() = 0;
};
class SingletonTest
{
public:
inline static SingletonMock* ms_mock = nullptr;
explicit SingletonTest(std::uint32_t p_data):
m_data(p_data)
{
if (ms_mock)
{
ms_mock->Construct();
}
}
~SingletonTest()
{
if (ms_mock)
{
ms_mock->Destruct();
}
}
[[nodiscard]]
std::uint32_t Data() const
{
return m_data;
}
private:
std::uint32_t m_data;
};
/****************************************************************************************/
class SingletonFixture: public ::testing::Test
{
protected:
class SingletonMockImpl: public SingletonMock
{
public:
MOCK_METHOD(void, Construct, (), (override));
MOCK_METHOD(void, Destruct, (), (override));
};
std::unique_ptr<SingletonMockImpl> m_mock;
void SetUp() override
{
m_mock = std::make_unique<::testing::NiceMock<SingletonMockImpl>>();
SingletonTest::ms_mock = m_mock.get();
}
void TearDown() override
{
SingletonTest::ms_mock = nullptr;
m_mock.reset();
}
};
/****************************************************************************************/
TEST_F(SingletonFixture, ConstructorAndDestructorShouldBeCalled)
{
::testing::InSequence seq;
EXPECT_CALL(*m_mock, Construct());
EXPECT_CALL(*m_mock, Destruct());
Singleton<SingletonTest>::Lifetime singleton {42};
}
/****************************************************************************************/
TEST_F(SingletonFixture, Instance_ShouldReturnTheInstance)
{
Singleton<SingletonTest>::Lifetime singleton {42};
EXPECT_EQ(Singleton<SingletonTest>::Instance().Data(), 42);
}
} // namespace Bigfoot

View File

@@ -0,0 +1,26 @@
/*********************************************************************
* \file TargetMacros.cpp
*
* \author Romain BOULLARD
* \date October 2025
*********************************************************************/
#include <Utils/TargetMacros.h>
#include <gtest/gtest.h>
namespace Bigfoot
{
class TargetMacrosFixture: public ::testing::Test
{
};
/****************************************************************************************/
TEST_F(TargetMacrosFixture, OptimizedOrNot)
{
constexpr std::uint32_t value = BIGFOOT_OPTIMIZED_OR_NOT(1, 2);
BIGFOOT_NOT_OPTIMIZED_ONLY(EXPECT_EQ(value, 2);)
BIGFOOT_OPTIMIZED_ONLY(EXPECT_EQ(value, 1);)
}
} // namespace Bigfoot

View File

@@ -0,0 +1,73 @@
/*********************************************************************
* \file Version.cpp
*
* \author Romain BOULLARD
* \date October 2025
*********************************************************************/
#include <Utils/Version.hpp>
#include <gtest/gtest.h>
namespace Bigfoot
{
class VersionFixture: public ::testing::Test
{
protected:
const Version m_detailed {1, 2, 3};
const Version m_combined {(1 << 16) | (2 << 8) | 3};
};
/****************************************************************************************/
TEST_F(VersionFixture, string)
{
EXPECT_STREQ(static_cast<std::string>(m_detailed).data(), "1.2.3");
EXPECT_STREQ(static_cast<std::string>(m_combined).data(), "1.2.3");
}
/****************************************************************************************/
TEST_F(VersionFixture, uint32_t)
{
EXPECT_EQ(static_cast<std::uint32_t>(m_detailed), (1 << 16) | (2 << 8) | 3);
EXPECT_EQ(static_cast<std::uint32_t>(m_combined), (1 << 16) | (2 << 8) | 3);
}
/****************************************************************************************/
TEST_F(VersionFixture, Major_ShouldBeEqualToTheMajorPartOfTheVersion)
{
EXPECT_EQ(m_detailed.Major(), 1);
EXPECT_EQ(m_combined.Major(), 1);
}
/****************************************************************************************/
TEST_F(VersionFixture, Minor_ShouldBeEqualToTheMinorPartOfTheVersion)
{
EXPECT_EQ(m_detailed.Minor(), 2);
EXPECT_EQ(m_combined.Minor(), 2);
}
/****************************************************************************************/
TEST_F(VersionFixture, Patch_ShouldBeEqualToThePatchPartOfTheVersion)
{
EXPECT_EQ(m_detailed.Patch(), 3);
EXPECT_EQ(m_combined.Patch(), 3);
}
/****************************************************************************************/
TEST_F(VersionFixture, Comparisons)
{
constexpr Version other {2, 6, 4};
EXPECT_GT(other, m_detailed);
EXPECT_GE(other, other);
EXPECT_LT(m_detailed, other);
EXPECT_LE(other, other);
EXPECT_EQ(other, other);
EXPECT_NE(other, m_detailed);
}
} // namespace Bigfoot