Files

93 lines
2.9 KiB
C++

/*********************************************************************
* \file SasquatchBaker.cpp
*
* \author Romain BOULLARD
* \date August 2026
*********************************************************************/
#include <SasquatchBaker/SasquatchBaker.hpp>
#include <Engine/Sasquatch/Sasquatch.hpp>
#include <System/File/File.hpp>
#include <AssetsForTesting/Asset/AssetA.hpp>
#include <AssetsForTesting/Asset/AssetB.hpp>
#include <SasquatchBakerTests/BigFileInfo_generated.hpp>
#include <gtest/gtest.h>
#include <cstring>
namespace Bigfoot
{
class SasquatchBakerFixture: public ::testing::Test
{
protected:
void SetUp() override
{
m_bigFile.Clear();
m_outputFile.Delete();
}
/*
* Packs an asset and saves it to the BigFile
*
* \param p_asset The asset to save
* \return The UUID the asset was saved under
*/
template<class ASSET>
UUID SaveAsset(ASSET& p_asset)
{
const eastl::vector<std::byte> flatbuffer = p_asset.Pack();
m_bigFile.SaveAssetFlatbuffer(p_asset.GetHeader().uuid, flatbuffer, p_asset.GetHardReferences(flatbuffer));
return p_asset.GetHeader().uuid;
}
static constexpr eastl::string_view SASQUATCH_SASQUATCHBAKERTESTS_LOCATION {"./SasquatchBakerTests.sasquatch"};
BigFile m_bigFile {File {BIGFILE_SASQUATCHBAKERTESTS_LOCATION}};
File m_outputFile {SASQUATCH_SASQUATCHBAKERTESTS_LOCATION};
};
/****************************************************************************************/
TEST_F(SasquatchBakerFixture, Bake_ShouldWriteAnEmptyFileWhenTheBigFileIsEmpty)
{
Bake(m_bigFile, m_outputFile);
Sasquatch sasquatch {m_outputFile};
const eastl::vector<std::byte> data = m_outputFile.Read(0, m_outputFile.GetSize());
ASSERT_EQ(m_outputFile.GetSize(), sizeof(SasquatchHeader));
EXPECT_EQ(sasquatch.GetHeader().m_magic, SasquatchHeader::MAGIC);
EXPECT_EQ(sasquatch.GetHeader().m_version, SasquatchHeader::VERSION);
EXPECT_EQ(sasquatch.GetHeader().m_assetCount, 0);
}
/****************************************************************************************/
TEST_F(SasquatchBakerFixture, Bake_ShouldWriteEveryAssetOfTheBigFile)
{
AssetA assetA;
assetA.SetName("hello");
SaveAsset(assetA);
AssetB assetB;
assetB.SetName("world");
assetB.GetAsset().ref_a = HardReference<AssetA> {assetA.GetHeader().uuid};
SaveAsset(assetB);
Bake(m_bigFile, m_outputFile);
Sasquatch sasquatch {m_outputFile};
EXPECT_EQ(sasquatch.GetHeader().m_magic, SasquatchHeader::MAGIC);
EXPECT_EQ(sasquatch.GetHeader().m_version, SasquatchHeader::VERSION);
EXPECT_EQ(sasquatch.GetHeader().m_assetCount, 2);
EXPECT_FALSE(sasquatch.GetAssetFlatbuffer(assetA.GetHeader().uuid).empty());
EXPECT_FALSE(sasquatch.GetAssetFlatbuffer(assetB.GetHeader().uuid).empty());
EXPECT_FALSE(sasquatch.GetAssetHardReferences(assetB.GetHeader().uuid).empty());
}
} // namespace Bigfoot