Files
Bigfoot/Bigfoot/Tests/Engine/Asset/Asset.cpp
T
rboullard 9fd1cd0d68
Bigfoot / Sonarqube (push) Successful in 5m42s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m25s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m5s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 32s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 1m4s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m27s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m11s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 29s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 55s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m0s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m5s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 56s
Bigfoot / Clang Format Checks (push) Successful in 12s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 43s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 25s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 52s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 30s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m19s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 1m1s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 48s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 49s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 35s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m20s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 36s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 42s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 50s
Asset System (#2)
Only time I'm allowing a merge of single feature inside main (we prefer merging a version)
But I need a first Sonarqube run

Reviewed-on: #2
Co-authored-by: Romain BOULLARD <romain.boullard@protonmail.com>
2026-09-01 17:32:16 +00:00

175 lines
6.0 KiB
C++

/*********************************************************************
* \file Asset.cpp
*
* \author Romain BOULLARD
* \date August 2026
*********************************************************************/
#include <Engine/Asset/Asset.hpp>
#include <AssetsForTesting/Asset/AssetA.hpp>
#include <AssetsForTesting/Asset/AssetB.hpp>
#include <AssetsForTesting/Asset/AssetC.hpp>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace Bigfoot
{
class AssetFixture: public ::testing::Test
{
protected:
void SetUp() override
{
SetActiveAssetLibrary(&m_library);
std::ignore = m_library.Insert(&m_containerA);
std::ignore = m_library.Insert(&m_containerB);
const UUID uuidA = m_assetA.GetHeader().uuid;
const UUID uuidB = m_assetB.GetHeader().uuid;
m_assetA.GetAsset().ref_a = SoftReference<AssetA> {uuidA};
m_assetB.GetAsset().ref_a = HardReference<AssetA> {uuidA};
m_assetB.GetAsset().refs_a.push_back(SoftReference<AssetA> {uuidA});
m_assetC.GetAsset().inner_table->asset_a_ref = HardReference<AssetA> {uuidA};
m_assetC.GetAsset().inner_table->asset_a_refs.push_back(HardReference<AssetA> {uuidA});
m_assetC.GetAsset().inner_table->asset_a_refs.push_back(HardReference<AssetA> {uuidA});
m_assetC.GetAsset().asset_b_ref = HardReference<AssetB> {uuidB};
m_assetC.GetAsset().asset_b_refs.push_back(SoftReference<AssetB> {uuidB});
}
void TearDown() override
{
SetActiveAssetLibrary(&g_assetLibrary);
}
AssetLibrary m_library;
AssetContainer<AssetA> m_containerA;
AssetContainer<AssetB> m_containerB;
AssetA m_assetA;
AssetB m_assetB;
AssetC m_assetC;
};
/****************************************************************************************/
TEST_F(AssetFixture, Constructor_ShouldInitializeHeaderTypeIdAndTypeName)
{
EXPECT_EQ(m_assetA.GetHeader().type_id, AssetA::GetTypeID());
EXPECT_EQ(m_assetA.GetHeader().type_name, eastl::string {AssetA::GetTypeName()});
}
/****************************************************************************************/
TEST_F(AssetFixture, SetName_ShouldSetTheName)
{
m_assetA.SetName("MyAsset");
EXPECT_STREQ(m_assetA.GetHeader().name.c_str(), "MyAsset");
}
/****************************************************************************************/
TEST_F(AssetFixture, GetAsset_ShouldReturnAMutableReferenceToTheUnderlyingAsset)
{
m_assetA.GetAsset().health = 10;
EXPECT_EQ(m_assetA.GetAsset().health, 10);
EXPECT_EQ(std::as_const(m_assetA).GetAsset().health, 10);
}
/****************************************************************************************/
TEST_F(AssetFixture, GetTypeID_ShouldBeStableAcrossCalls)
{
EXPECT_EQ(AssetA::GetTypeID(), AssetA::GetTypeID());
}
/****************************************************************************************/
TEST_F(AssetFixture, GetTypeID_ShouldBeDifferentForDifferentAssetTypes)
{
EXPECT_NE(AssetA::GetTypeID(), AssetB::GetTypeID());
EXPECT_NE(AssetA::GetTypeID(), AssetC::GetTypeID());
EXPECT_NE(AssetB::GetTypeID(), AssetC::GetTypeID());
}
/****************************************************************************************/
TEST_F(AssetFixture, GetTypeName_ShouldReturnTheFlatbufferFullyQualifiedName)
{
EXPECT_EQ(AssetA::GetTypeName(), eastl::string_view {AssetA::FLAT_ASSET::GetFullyQualifiedName()});
}
/****************************************************************************************/
TEST_F(AssetFixture, PackThenUnpack_ShouldRoundTripTheHeaderAndTheAsset)
{
m_assetA.SetName("MyAsset");
m_assetA.GetAsset().health = 42;
m_assetA.GetAsset().mana = 7;
AssetA unpacked;
unpacked.Unpack(m_assetA.Pack());
EXPECT_EQ(unpacked.GetHeader().uuid, m_assetA.GetHeader().uuid);
EXPECT_STREQ(unpacked.GetHeader().name.c_str(), m_assetA.GetHeader().name.c_str());
EXPECT_EQ(unpacked.GetHeader().type_id, m_assetA.GetHeader().type_id);
EXPECT_STREQ(unpacked.GetHeader().type_name.c_str(), m_assetA.GetHeader().type_name.c_str());
EXPECT_EQ(unpacked.GetAsset().health, m_assetA.GetAsset().health);
EXPECT_EQ(unpacked.GetAsset().mana, m_assetA.GetAsset().mana);
}
/****************************************************************************************/
TEST_F(AssetFixture, GetHardReferences_ShouldReturnTheHardReferencesOfTheAsset)
{
const eastl::vector<UUID> hardReferences = m_assetC.GetHardReferences(m_assetC.Pack());
EXPECT_THAT(hardReferences, ::testing::UnorderedElementsAre(m_assetA.GetHeader().uuid, m_assetB.GetHeader().uuid));
}
/****************************************************************************************/
TEST_F(AssetFixture, CreateAsset_ShouldReturnTheCreatedAsset)
{
EXPECT_NE(CreateAsset<AssetA>(), nullptr);
}
/****************************************************************************************/
TEST_F(AssetFixture, CreateAsset_ShouldCreateUniqueAssets)
{
const AssetA* first = CreateAsset<AssetA>();
const AssetA* second = CreateAsset<AssetA>();
EXPECT_NE(first->GetHeader().uuid, second->GetHeader().uuid);
}
/****************************************************************************************/
TEST_F(AssetFixture, CreateAsset_ShouldReturnTheSameAssetAsItsContainerHandle)
{
const AssetA* asset = CreateAsset<AssetA>();
const ContainerHandle* handle = m_containerA.AcquireContainerHandle(asset->GetHeader().uuid);
EXPECT_EQ(handle->GetAsset(), asset);
}
/****************************************************************************************/
TEST_F(AssetFixture, CreateAsset_ShouldInsertTheAssetIntoItsCorrespondingContainer)
{
const AssetA* assetA = CreateAsset<AssetA>();
const AssetB* assetB = CreateAsset<AssetB>();
EXPECT_TRUE(m_containerA.Has(assetA->GetHeader().uuid));
EXPECT_FALSE(m_containerB.Has(assetA->GetHeader().uuid));
EXPECT_TRUE(m_containerB.Has(assetB->GetHeader().uuid));
EXPECT_FALSE(m_containerA.Has(assetB->GetHeader().uuid));
}
} // namespace Bigfoot