Bigfoot / Clang Format Checks (push) Successful in 10s
Bigfoot / Sonarqube (push) Skipped
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 30s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 22s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 31s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 22s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 53s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 41s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 54s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 42s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 31s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 23s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 41s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 52s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 26s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 20s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 38s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 31s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 31s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 33s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 22s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 50s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 43s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 37s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 36s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 37s
183 lines
5.8 KiB
C++
183 lines
5.8 KiB
C++
/*********************************************************************
|
|
* \file AssetContainer.cpp
|
|
*
|
|
* \author Romain BOULLARD
|
|
* \date July 2026
|
|
*********************************************************************/
|
|
#include <Engine/Asset/AssetContainer.hpp>
|
|
|
|
#include <AssetsForTesting/Asset/AssetA.hpp>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
namespace Bigfoot
|
|
{
|
|
class ContainerHandleFixture: public ::testing::Test
|
|
{
|
|
protected:
|
|
void SetUp() override
|
|
{
|
|
const auto key = m_containerA.Insert();
|
|
|
|
m_uuid = m_containerA.Get(key)->GetHeader().uuid;
|
|
|
|
m_handle = m_containerA.AcquireContainerHandle(m_uuid);
|
|
}
|
|
|
|
AssetContainer<AssetA> m_containerA;
|
|
|
|
UUID m_uuid;
|
|
|
|
ContainerHandle* m_handle;
|
|
};
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(ContainerHandleFixture, GetAsset_ShouldReturnTheAsset)
|
|
{
|
|
EXPECT_NE(m_handle->GetAsset(), nullptr);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(ContainerHandleFixture, GetAsset_ShouldReturnNullptrIfTheAssetHasBeenRemoved)
|
|
{
|
|
m_containerA.Remove(m_uuid);
|
|
EXPECT_EQ(m_handle->GetAsset(), nullptr);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(ContainerHandleFixture, IncrementHardRefCount_ShouldIncrementTheHardRefCount)
|
|
{
|
|
const std::uint32_t original = m_handle->GetHardRefCount();
|
|
m_handle->IncrementHardRefCount();
|
|
EXPECT_EQ(original + 1, m_handle->GetHardRefCount());
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(ContainerHandleFixture, IncrementSoftRefCount_ShouldIncrementTheSoftRefCount)
|
|
{
|
|
const std::uint32_t original = m_handle->GetSoftRefCount();
|
|
m_handle->IncrementSoftRefCount();
|
|
EXPECT_EQ(original + 1, m_handle->GetSoftRefCount());
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(ContainerHandleFixture, DecrementHardRefCount_ShouldDecrementTheHardRefCount)
|
|
{
|
|
m_handle->IncrementHardRefCount();
|
|
|
|
const std::uint32_t original = m_handle->GetHardRefCount();
|
|
m_handle->DecrementHardRefCount();
|
|
EXPECT_EQ(original - 1, m_handle->GetHardRefCount());
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(ContainerHandleFixture, DecrementSoftRefCount_ShouldDecrementTheSoftRefCount)
|
|
{
|
|
m_handle->IncrementSoftRefCount();
|
|
|
|
const std::uint32_t original = m_handle->GetSoftRefCount();
|
|
m_handle->DecrementSoftRefCount();
|
|
EXPECT_EQ(original - 1, m_handle->GetSoftRefCount());
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
class AssetContainerFixture: public ::testing::Test
|
|
{
|
|
protected:
|
|
AssetContainer<AssetA> m_containerA;
|
|
};
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(AssetContainerFixture, Has_ShouldReturnTrueIfTheContainerHasTheAsset)
|
|
{
|
|
const auto key = m_containerA.Insert();
|
|
EXPECT_TRUE(m_containerA.Has(m_containerA.Get(key)->GetHeader().uuid));
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(AssetContainerFixture, Has_ShouldReturnFalseIfTheContainerDoesNotHaveTheAsset)
|
|
{
|
|
EXPECT_FALSE(m_containerA.Has(UUID {}));
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(AssetContainerFixture, AcquireHandle_ShouldReturnTheAssociatedContainerHandle)
|
|
{
|
|
const auto key = m_containerA.Insert();
|
|
|
|
const ContainerHandle* handle = m_containerA.AcquireContainerHandle(m_containerA.Get(key)->GetHeader().uuid);
|
|
EXPECT_EQ(static_cast<const AssetA*>(handle->GetAsset())->GetHeader().uuid,
|
|
m_containerA.Get(key)->GetHeader().uuid);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(AssetContainerFixture, AcquireHandle_ShouldCreateTheAssociatedContainerHandleIfItDoesNotExists)
|
|
{
|
|
const ContainerHandle* handle = m_containerA.AcquireContainerHandle(UUID {});
|
|
EXPECT_EQ(handle->GetAsset(), nullptr);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(AssetContainerFixture, Insert_ShouldReturnValidAndUniqueSlotKeyOnInsert)
|
|
{
|
|
const SlotMapKey slotKey = m_containerA.Insert();
|
|
EXPECT_TRUE(slotKey.Valid());
|
|
EXPECT_NE(slotKey, m_containerA.Insert());
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(AssetContainerFixture, Insert_ShouldReturnTheSameSlotKeyInCaseOfDuplicatedUUID)
|
|
{
|
|
const SlotMapKey slotKey = m_containerA.Insert();
|
|
|
|
AssetA duplicate;
|
|
duplicate.Unpack(m_containerA.Get(slotKey)->Pack());
|
|
|
|
EXPECT_EQ(slotKey, m_containerA.Insert(std::move(duplicate)));
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(AssetContainerFixture, Get_ShouldReturnTheAssetWithTheSlotKey)
|
|
{
|
|
const SlotMapKey slotKey = m_containerA.Insert();
|
|
|
|
EXPECT_NE(m_containerA.Get(slotKey), nullptr);
|
|
EXPECT_NE(std::as_const(m_containerA).Get(slotKey), nullptr);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(AssetContainerFixture, Get_ShouldReturnNullptrIfSlotKeyNotInContainer)
|
|
{
|
|
EXPECT_EQ(m_containerA.Get(SlotMapKey<> {1, 0}), nullptr);
|
|
EXPECT_EQ(std::as_const(m_containerA).Get(SlotMapKey<> {1, 0}), nullptr);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(AssetContainerFixture, Remove_ShouldRemoveTheAsset)
|
|
{
|
|
const SlotMapKey slotKey = m_containerA.Insert();
|
|
const UUID uuid = m_containerA.Get(slotKey)->GetHeader().uuid;
|
|
|
|
m_containerA.Remove(uuid);
|
|
|
|
EXPECT_EQ(m_containerA.Get(slotKey), nullptr);
|
|
EXPECT_FALSE(m_containerA.Has(uuid));
|
|
}
|
|
} // namespace Bigfoot
|