Files
Bigfoot/Bigfoot/Tests/Engine/Asset/AssetLibrary.cpp
T
2026-08-30 15:40:22 +02:00

160 lines
5.5 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(GetAssetTypeID<AssetA>()), &m_containerA);
EXPECT_EQ(m_library.GetAssetContainer(GetAssetTypeID<AssetB>()), &m_containerB);
EXPECT_EQ(m_library.GetAssetContainer(GetAssetTypeID<AssetC>()), &m_containerC);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer(GetAssetTypeID<AssetA>()), &m_containerA);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer(GetAssetTypeID<AssetB>()), &m_containerB);
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(GetAssetTypeID<AssetA>()), nullptr);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer(GetAssetTypeID<AssetA>()), nullptr);
}
/****************************************************************************************/
TEST_F(AssetLibraryFixture, GetAssetContainer_ShouldReturnTheContainerThatHasTheAsset)
{
std::ignore = m_library.Insert(&m_containerA);
std::ignore = m_library.Insert(&m_containerB);
const UUID uuid = m_containerB.Insert()->GetAsset()->GetHeader().uuid;
EXPECT_EQ(m_library.GetAssetContainer(uuid), &m_containerB);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer(uuid), &m_containerB);
}
/****************************************************************************************/
TEST_F(AssetLibraryFixture, GetAssetContainer_ShouldReturnNullptrIfNoContainerHasTheAsset)
{
std::ignore = m_library.Insert(&m_containerA);
std::ignore = m_library.Insert(&m_containerB);
const UUID uuid;
EXPECT_EQ(m_library.GetAssetContainer(uuid), nullptr);
EXPECT_EQ(std::as_const(m_library).GetAssetContainer(uuid), nullptr);
}
/****************************************************************************************/
TEST_F(AssetLibraryFixture, IsLoaded_ShouldReturnTrueIfTheAssetIsLoaded)
{
std::ignore = m_library.Insert(&m_containerA);
std::ignore = m_library.Insert(&m_containerB);
const UUID uuid = m_containerB.Insert()->GetAsset()->GetHeader().uuid;
EXPECT_TRUE(m_library.IsLoaded(uuid));
}
/****************************************************************************************/
TEST_F(AssetLibraryFixture, IsLoaded_ShouldReturnFalseIfTheAssetIsNotLoaded)
{
std::ignore = m_library.Insert(&m_containerA);
std::ignore = m_library.Insert(&m_containerB);
const UUID uuid;
EXPECT_FALSE(m_library.IsLoaded(uuid));
}
/****************************************************************************************/
TEST_F(AssetLibraryFixture, IsLoaded_ShouldReturnFalseIfTheAssetWasRemovedFromItsContainer)
{
std::ignore = m_library.Insert(&m_containerA);
std::ignore = m_library.Insert(&m_containerB);
const UUID uuid = m_containerB.Insert()->GetAsset()->GetHeader().uuid;
ASSERT_TRUE(m_library.IsLoaded(uuid));
m_containerB.Remove(uuid);
EXPECT_FALSE(m_library.IsLoaded(uuid));
}
/****************************************************************************************/
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