Files
Bigfoot/Bigfoot/Tests/Engine/Asset/AssetLibrary.cpp
T
rboullard 3c306dd2c7
Bigfoot / Sonarqube (push) Skipped
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m52s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m46s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 6m18s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 6m14s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 7m17s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 6m25s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 8m7s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 7m31s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 6m24s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 6m18s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 7m30s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 7m6s
Bigfoot / Clang Format Checks (push) Failing after 8s
basic testing for reference
2026-08-18 14:59:42 +02:00

145 lines
5.8 KiB
C++

/*********************************************************************
* \file AssetLibrary.cpp
*
* \author Romain BOULLARD
* \date July 2026
*********************************************************************/
#include <Engine/Asset/AssetLibrary.hpp>
#include <AssetsForTesting/Asset/AssetA.hpp>
#include <AssetsForTesting/Asset/AssetB.hpp>
#include <AssetsForTesting/Asset/AssetC.hpp>
#include <gtest/gtest.h>
namespace Bigfoot
{
class AssetLibraryFixture: public ::testing::Test
{
protected:
AssetContainer<AssetA> m_containerA;
AssetContainer<AssetB> m_containerB;
AssetContainer<AssetC> m_containerC;
AssetLibrary m_library;
};
/****************************************************************************************/
TEST_F(AssetLibraryFixture, Insert_ShouldReturnTrueOnSuccess)
{
EXPECT_TRUE(m_library.Insert(&m_containerA));
EXPECT_TRUE(m_library.Insert(&m_containerB));
EXPECT_TRUE(m_library.Insert(&m_containerC));
}
/****************************************************************************************/
TEST_F(AssetLibraryFixture, Insert_ShouldReturnFalseOnDuplicate)
{
std::ignore = m_library.Insert(&m_containerA);
EXPECT_FALSE(m_library.Insert(&m_containerA));
AssetContainer<AssetA> m_containerAA;
EXPECT_FALSE(m_library.Insert(&m_containerAA));
}
/****************************************************************************************/
TEST_F(AssetLibraryFixture, GetAssetContainer_ShouldReturnTheAssetContainerIfAvailable)
{
std::ignore = m_library.Insert(&m_containerA);
std::ignore = m_library.Insert(&m_containerB);
std::ignore = m_library.Insert(&m_containerC);
EXPECT_EQ(m_library.GetAssetContainer<AssetA>(), &m_containerA);
EXPECT_EQ(m_library.GetAssetContainer(GetAssetTypeID<AssetA>()), &m_containerA);
EXPECT_EQ(m_library.GetAssetContainer<AssetB>(), &m_containerB);
EXPECT_EQ(m_library.GetAssetContainer(GetAssetTypeID<AssetB>()), &m_containerB);
EXPECT_EQ(m_library.GetAssetContainer<AssetC>(), &m_containerC);
EXPECT_EQ(m_library.GetAssetContainer(GetAssetTypeID<AssetC>()), &m_containerC);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer<AssetA>(), &m_containerA);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer(GetAssetTypeID<AssetA>()), &m_containerA);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer<AssetB>(), &m_containerB);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer(GetAssetTypeID<AssetB>()), &m_containerB);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer<AssetC>(), &m_containerC);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer(GetAssetTypeID<AssetC>()), &m_containerC);
}
/****************************************************************************************/
TEST_F(AssetLibraryFixture, GetAssetContainer_ShouldReturnNullptrIfTheContainerDoesNotExist)
{
std::ignore = m_library.Insert(&m_containerB);
EXPECT_EQ(m_library.GetAssetContainer<AssetA>(), nullptr);
EXPECT_EQ(m_library.GetAssetContainer(GetAssetTypeID<AssetA>()), nullptr);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer<AssetA>(), nullptr);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer(GetAssetTypeID<AssetA>()), nullptr);
}
/****************************************************************************************/
TEST_F(AssetLibraryFixture, FindAssetContainerContainerForUUID_ShouldReturnTheAssetContainerIfAvailable)
{
std::ignore = m_library.Insert(&m_containerA);
std::ignore = m_library.Insert(&m_containerB);
std::ignore = m_library.Insert(&m_containerC);
const SlotMapKey keyA = m_containerA.Insert();
const SlotMapKey keyB = m_containerB.Insert();
const SlotMapKey keyC = m_containerC.Insert();
const UUID uuidA = m_containerA.Get(keyA)->GetHeader().uuid;
const UUID uuidB = m_containerB.Get(keyB)->GetHeader().uuid;
const UUID uuidC = m_containerC.Get(keyC)->GetHeader().uuid;
EXPECT_EQ(m_library.FindAssetContainerContainerForUUID(uuidA), &m_containerA);
EXPECT_EQ(m_library.FindAssetContainerContainerForUUID(uuidB), &m_containerB);
EXPECT_EQ(m_library.FindAssetContainerContainerForUUID(uuidC), &m_containerC);
EXPECT_EQ(std::as_const(m_library).FindAssetContainerContainerForUUID(uuidA), &m_containerA);
EXPECT_EQ(std::as_const(m_library).FindAssetContainerContainerForUUID(uuidB), &m_containerB);
EXPECT_EQ(std::as_const(m_library).FindAssetContainerContainerForUUID(uuidC), &m_containerC);
}
/****************************************************************************************/
TEST_F(AssetLibraryFixture, FindAssetContainerContainerForUUID_ShouldReturnNullptrIfTheContainerDoesNotExist)
{
std::ignore = m_library.Insert(&m_containerA);
std::ignore = m_library.Insert(&m_containerB);
std::ignore = m_library.Insert(&m_containerC);
std::ignore = m_containerA.Insert();
std::ignore = m_containerB.Insert();
std::ignore = m_containerC.Insert();
EXPECT_EQ(m_library.FindAssetContainerContainerForUUID(UUID {}), nullptr);
EXPECT_EQ(std::as_const(m_library).FindAssetContainerContainerForUUID(UUID {}), nullptr);
}
/****************************************************************************************/
TEST_F(AssetLibraryFixture, SetActiveAssetLibrary_ShouldSetTheActiveAssetLibraryToTheGivenLibrary)
{
SetActiveAssetLibrary(&m_library);
EXPECT_EQ(g_activeAssetLibrary, &m_library);
SetActiveAssetLibrary(&g_assetLibrary);
}
/****************************************************************************************/
TEST_F(AssetLibraryFixture, ScopedActiveAssetLibrary_ShouldChangeTheActiveAssetLibraryInAScopedWay)
{
EXPECT_EQ(g_activeAssetLibrary, &g_assetLibrary);
{
ScopedActiveAssetLibrary activeAssetLibraryScoped {&m_library};
EXPECT_EQ(g_activeAssetLibrary, &m_library);
}
EXPECT_EQ(g_activeAssetLibrary, &g_assetLibrary);
}
} // namespace Bigfoot