mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
test: add test for KeyValuePairsCompilerT6
This commit is contained in:
14
test/ObjCommonTestUtils/Utils/TestMemoryManager.h
Normal file
14
test/ObjCommonTestUtils/Utils/TestMemoryManager.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
class TestMemoryManager : public MemoryManager
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] size_t GetAllocationCount() const
|
||||
{
|
||||
return m_allocations.size() + m_destructible.size();
|
||||
}
|
||||
};
|
58
test/ObjCompilingTests.lua
Normal file
58
test/ObjCompilingTests.lua
Normal file
@ -0,0 +1,58 @@
|
||||
ObjCompilingTests = {}
|
||||
|
||||
function ObjCompilingTests:include(includes)
|
||||
if includes:handle(self:name()) then
|
||||
includedirs {
|
||||
path.join(TestFolder(), "ObjCompilingTests")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function ObjCompilingTests:link(links)
|
||||
|
||||
end
|
||||
|
||||
function ObjCompilingTests:use()
|
||||
|
||||
end
|
||||
|
||||
function ObjCompilingTests:name()
|
||||
return "ObjCompilingTests"
|
||||
end
|
||||
|
||||
function ObjCompilingTests:project()
|
||||
local folder = TestFolder()
|
||||
local includes = Includes:create()
|
||||
local links = Links:create()
|
||||
|
||||
project(self:name())
|
||||
targetdir(TargetDirectoryTest)
|
||||
location "%{wks.location}/test/%{prj.name}"
|
||||
kind "ConsoleApp"
|
||||
language "C++"
|
||||
|
||||
files {
|
||||
path.join(folder, "ObjCompilingTests/**.h"),
|
||||
path.join(folder, "ObjCompilingTests/**.cpp")
|
||||
}
|
||||
|
||||
vpaths {
|
||||
["*"] = {
|
||||
path.join(folder, "ObjCompilingTests")
|
||||
}
|
||||
}
|
||||
|
||||
self:include(includes)
|
||||
ObjCommonTestUtils:include(includes)
|
||||
ParserTestUtils:include(includes)
|
||||
ObjLoading:include(includes)
|
||||
ObjCompiling:include(includes)
|
||||
catch2:include(includes)
|
||||
|
||||
links:linkto(ObjCommonTestUtils)
|
||||
links:linkto(ParserTestUtils)
|
||||
links:linkto(ObjLoading)
|
||||
links:linkto(ObjCompiling)
|
||||
links:linkto(catch2)
|
||||
links:linkall()
|
||||
end
|
@ -0,0 +1,130 @@
|
||||
#include "Game/T6/KeyValuePairs/KeyValuePairsCompilerT6.h"
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/GameAssetPoolT6.h"
|
||||
#include "KeyValuePairs/KeyValuePairsCreator.h"
|
||||
#include "Utils/TestMemoryManager.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
||||
#include <memory>
|
||||
|
||||
using namespace T6;
|
||||
using namespace std::string_literals;
|
||||
|
||||
namespace
|
||||
{
|
||||
class TestContext
|
||||
{
|
||||
public:
|
||||
TestContext()
|
||||
: m_memory(),
|
||||
m_zone("test", 0, IGame::GetGameById(GameId::T6)),
|
||||
m_zone_definition(),
|
||||
m_zone_states(m_zone),
|
||||
m_creators(m_zone),
|
||||
m_ignored_assets(),
|
||||
m_context(m_zone, &m_creators, &m_ignored_assets),
|
||||
m_kvp_creator(m_zone_states.GetZoneAssetCreationState<KeyValuePairsCreator>())
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<IAssetCreator> CreateSut()
|
||||
{
|
||||
return CreateKeyValuePairsCompiler(m_memory, m_zone, m_zone_definition, m_zone_states);
|
||||
}
|
||||
|
||||
TestMemoryManager m_memory;
|
||||
Zone m_zone;
|
||||
ZoneDefinition m_zone_definition;
|
||||
ZoneAssetCreationStateContainer m_zone_states;
|
||||
AssetCreatorCollection m_creators;
|
||||
IgnoredAssetLookup m_ignored_assets;
|
||||
AssetCreationContext m_context;
|
||||
|
||||
KeyValuePairsCreator& m_kvp_creator;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace test::game::t6::keyvaluepairs
|
||||
{
|
||||
TEST_CASE("KeyValuePairsCompilerT6: Does not handle any asset type", "[keyvaluepairs][t6]")
|
||||
{
|
||||
TestContext testContext;
|
||||
const auto sut = testContext.CreateSut();
|
||||
|
||||
REQUIRE(!sut->GetHandlingAssetType().has_value());
|
||||
}
|
||||
|
||||
TEST_CASE("KeyValuePairsCompilerT6: Does not take any action", "[keyvaluepairs][t6]")
|
||||
{
|
||||
TestContext testContext;
|
||||
const auto sut = testContext.CreateSut();
|
||||
|
||||
REQUIRE(sut->CreateAsset("anyAsset", testContext.m_context).HasTakenAction() == false);
|
||||
}
|
||||
|
||||
TEST_CASE("KeyValuePairsCompilerT6: Does nothing without any KeyValuePairs", "[keyvaluepairs][t6]")
|
||||
{
|
||||
TestContext testContext;
|
||||
const auto sut = testContext.CreateSut();
|
||||
|
||||
sut->FinalizeZone(testContext.m_context);
|
||||
|
||||
REQUIRE(testContext.m_memory.GetAllocationCount() == 0u);
|
||||
REQUIRE(testContext.m_zone.m_pools->GetTotalAssetCount() == 0u);
|
||||
}
|
||||
|
||||
TEST_CASE("KeyValuePairsCompilerT6: Creates KeyValuePairs asset with identical name to the zone", "[keyvaluepairs][t6]")
|
||||
{
|
||||
TestContext testContext;
|
||||
const auto sut = testContext.CreateSut();
|
||||
|
||||
testContext.m_kvp_creator.AddKeyValuePair(CommonKeyValuePair("ipak_read", "test_ipak"));
|
||||
|
||||
sut->FinalizeZone(testContext.m_context);
|
||||
|
||||
REQUIRE(testContext.m_memory.GetAllocationCount() > 0u);
|
||||
REQUIRE(testContext.m_zone.m_pools->GetTotalAssetCount() == 1u);
|
||||
|
||||
XAssetInfo<KeyValuePairs>* assetInfo = *dynamic_cast<GameAssetPoolT6*>(testContext.m_zone.m_pools.get())->m_key_value_pairs->begin();
|
||||
REQUIRE(assetInfo);
|
||||
REQUIRE(assetInfo->m_name == "test");
|
||||
|
||||
auto* asset = assetInfo->Asset();
|
||||
REQUIRE(asset->name == "test"s);
|
||||
REQUIRE(asset->numVariables == 1u);
|
||||
REQUIRE(asset->keyValuePairs != nullptr);
|
||||
|
||||
REQUIRE(asset->keyValuePairs[0].keyHash == 0x0001bdc1);
|
||||
REQUIRE(asset->keyValuePairs[0].namespaceHash == 0x0000d2d3);
|
||||
REQUIRE(asset->keyValuePairs[0].value == "test_ipak"s);
|
||||
}
|
||||
|
||||
TEST_CASE("KeyValuePairsCompilerT6: Creates KeyValuePairs asset with predefined hash", "[keyvaluepairs][t6]")
|
||||
{
|
||||
TestContext testContext;
|
||||
const auto sut = testContext.CreateSut();
|
||||
|
||||
testContext.m_kvp_creator.AddKeyValuePair(CommonKeyValuePair(0xDDEEFFAA, "hello_there"));
|
||||
|
||||
sut->FinalizeZone(testContext.m_context);
|
||||
|
||||
REQUIRE(testContext.m_memory.GetAllocationCount() > 0u);
|
||||
REQUIRE(testContext.m_zone.m_pools->GetTotalAssetCount() == 1u);
|
||||
|
||||
XAssetInfo<KeyValuePairs>* assetInfo = *dynamic_cast<GameAssetPoolT6*>(testContext.m_zone.m_pools.get())->m_key_value_pairs->begin();
|
||||
REQUIRE(assetInfo);
|
||||
REQUIRE(assetInfo->m_name == "test");
|
||||
|
||||
auto* asset = assetInfo->Asset();
|
||||
REQUIRE(asset->name == "test"s);
|
||||
REQUIRE(asset->numVariables == 1u);
|
||||
REQUIRE(asset->keyValuePairs != nullptr);
|
||||
|
||||
REQUIRE(asset->keyValuePairs[0].keyHash == 0xDDEEFFAA);
|
||||
REQUIRE(asset->keyValuePairs[0].namespaceHash == 0x0000d2d3);
|
||||
REQUIRE(asset->keyValuePairs[0].value == "hello_there"s);
|
||||
}
|
||||
} // namespace test::game::t6::keyvaluepairs
|
Reference in New Issue
Block a user