2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-01-07 17:31:49 +00:00

chore: add tests for templated image loader

This commit is contained in:
Jan Laupetin
2026-01-04 23:50:38 +01:00
parent 61750da759
commit fcc4d60756
21 changed files with 560 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ ObjLoadingTests = {}
function ObjLoadingTests:include(includes)
if includes:handle(self:name()) then
includedirs {
"%{wks.location}/src/ObjLoading",
path.join(TestFolder(), "ObjLoadingTests")
}
end

View File

@@ -0,0 +1,57 @@
#include "Game/IW3/Image/ImageLoaderEmbeddedIW3.h"
#include "Game/IW3/GameIW3.h"
#include "OatTestPaths.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
namespace fs = std::filesystem;
using namespace IW3;
using namespace std::literals;
namespace
{
TEST_CASE("ImageLoaderEmbeddedIW3: Can parse dds", "[iw3][image]")
{
MockSearchPath searchPath;
const auto filePath = oat::paths::GetTestDirectory() / "ObjLoadingTests/Game/IW3/Image/TestImage.dds";
const auto fileSize = fs::file_size(filePath);
std::ifstream file(filePath, std::ios::binary);
REQUIRE(file.is_open());
const auto data = std::make_unique<char[]>(fileSize);
file.read(data.get(), fileSize);
searchPath.AddFileData("images/_testimage.dds", std::string(data.get(), fileSize));
Zone zone("MockZone", 0, GameId::IW3, GamePlatform::PC);
MemoryManager memory;
AssetCreatorCollection creatorCollection(zone);
IgnoredAssetLookup ignoredAssetLookup;
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
auto loader = image::CreateLoaderEmbeddedIW3(memory, searchPath);
auto result = loader->CreateAsset("*testimage", context);
REQUIRE(result.HasBeenSuccessful());
const auto* assetInfo = reinterpret_cast<XAssetInfo<GfxImage>*>(result.GetAssetInfo());
const auto* image = assetInfo->Asset();
REQUIRE(image->name == "*testimage"s);
REQUIRE(image->width == 64);
REQUIRE(image->height == 64);
REQUIRE(image->depth == 1);
REQUIRE(image->texture.loadDef);
REQUIRE(image->texture.loadDef->resourceSize > 0);
}
} // namespace

View File

@@ -0,0 +1,54 @@
#include "Game/IW3/Image/ImageLoaderExternalIW3.h"
#include "Game/IW3/GameIW3.h"
#include "OatTestPaths.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
namespace fs = std::filesystem;
using namespace IW3;
using namespace std::literals;
namespace
{
TEST_CASE("ImageLoaderExternalIW3: Can parse iwi", "[iw3][image]")
{
MockSearchPath searchPath;
const auto filePath = oat::paths::GetTestDirectory() / "ObjLoadingTests/Game/IW3/Image/TestImage.iwi";
const auto fileSize = fs::file_size(filePath);
std::ifstream file(filePath, std::ios::binary);
REQUIRE(file.is_open());
const auto data = std::make_unique<char[]>(fileSize);
file.read(data.get(), fileSize);
searchPath.AddFileData("images/testimage.iwi", std::string(data.get(), fileSize));
Zone zone("MockZone", 0, GameId::IW3, GamePlatform::PC);
MemoryManager memory;
AssetCreatorCollection creatorCollection(zone);
IgnoredAssetLookup ignoredAssetLookup;
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
auto loader = image::CreateLoaderExternalIW3(memory, searchPath);
auto result = loader->CreateAsset("testimage", context);
REQUIRE(result.HasBeenSuccessful());
const auto* assetInfo = reinterpret_cast<XAssetInfo<GfxImage>*>(result.GetAssetInfo());
const auto* image = assetInfo->Asset();
REQUIRE(image->name == "testimage"s);
REQUIRE(image->width == 64);
REQUIRE(image->height == 64);
REQUIRE(image->depth == 1);
}
} // namespace

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,57 @@
#include "Game/IW4/Image/ImageLoaderEmbeddedIW4.h"
#include "Game/IW4/GameIW4.h"
#include "OatTestPaths.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
namespace fs = std::filesystem;
using namespace IW4;
using namespace std::literals;
namespace
{
TEST_CASE("ImageLoaderEmbeddedIW4: Can parse dds", "[iw4][image]")
{
MockSearchPath searchPath;
const auto filePath = oat::paths::GetTestDirectory() / "ObjLoadingTests/Game/IW4/Image/TestImage.dds";
const auto fileSize = fs::file_size(filePath);
std::ifstream file(filePath, std::ios::binary);
REQUIRE(file.is_open());
const auto data = std::make_unique<char[]>(fileSize);
file.read(data.get(), fileSize);
searchPath.AddFileData("images/_testimage.dds", std::string(data.get(), fileSize));
Zone zone("MockZone", 0, GameId::IW4, GamePlatform::PC);
MemoryManager memory;
AssetCreatorCollection creatorCollection(zone);
IgnoredAssetLookup ignoredAssetLookup;
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
auto loader = image::CreateLoaderEmbeddedIW4(memory, searchPath);
auto result = loader->CreateAsset("*testimage", context);
REQUIRE(result.HasBeenSuccessful());
const auto* assetInfo = reinterpret_cast<XAssetInfo<GfxImage>*>(result.GetAssetInfo());
const auto* image = assetInfo->Asset();
REQUIRE(image->name == "*testimage"s);
REQUIRE(image->width == 64);
REQUIRE(image->height == 64);
REQUIRE(image->depth == 1);
REQUIRE(image->texture.loadDef);
REQUIRE(image->texture.loadDef->resourceSize > 0);
}
} // namespace

View File

@@ -0,0 +1,54 @@
#include "Game/IW4/Image/ImageLoaderExternalIW4.h"
#include "Game/IW4/GameIW4.h"
#include "OatTestPaths.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
namespace fs = std::filesystem;
using namespace IW4;
using namespace std::literals;
namespace
{
TEST_CASE("ImageLoaderExternalIW4: Can parse iwi", "[iw4][image]")
{
MockSearchPath searchPath;
const auto filePath = oat::paths::GetTestDirectory() / "ObjLoadingTests/Game/IW4/Image/TestImage.iwi";
const auto fileSize = fs::file_size(filePath);
std::ifstream file(filePath, std::ios::binary);
REQUIRE(file.is_open());
const auto data = std::make_unique<char[]>(fileSize);
file.read(data.get(), fileSize);
searchPath.AddFileData("images/testimage.iwi", std::string(data.get(), fileSize));
Zone zone("MockZone", 0, GameId::IW4, GamePlatform::PC);
MemoryManager memory;
AssetCreatorCollection creatorCollection(zone);
IgnoredAssetLookup ignoredAssetLookup;
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
auto loader = image::CreateLoaderExternalIW4(memory, searchPath);
auto result = loader->CreateAsset("testimage", context);
REQUIRE(result.HasBeenSuccessful());
const auto* assetInfo = reinterpret_cast<XAssetInfo<GfxImage>*>(result.GetAssetInfo());
const auto* image = assetInfo->Asset();
REQUIRE(image->name == "testimage"s);
REQUIRE(image->width == 64);
REQUIRE(image->height == 64);
REQUIRE(image->depth == 1);
}
} // namespace

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,57 @@
#include "Game/IW5/Image/ImageLoaderEmbeddedIW5.h"
#include "Game/IW5/GameIW5.h"
#include "OatTestPaths.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
namespace fs = std::filesystem;
using namespace IW5;
using namespace std::literals;
namespace
{
TEST_CASE("ImageLoaderEmbeddedIW5: Can parse dds", "[iw5][image]")
{
MockSearchPath searchPath;
const auto filePath = oat::paths::GetTestDirectory() / "ObjLoadingTests/Game/IW5/Image/TestImage.dds";
const auto fileSize = fs::file_size(filePath);
std::ifstream file(filePath, std::ios::binary);
REQUIRE(file.is_open());
const auto data = std::make_unique<char[]>(fileSize);
file.read(data.get(), fileSize);
searchPath.AddFileData("images/_testimage.dds", std::string(data.get(), fileSize));
Zone zone("MockZone", 0, GameId::IW5, GamePlatform::PC);
MemoryManager memory;
AssetCreatorCollection creatorCollection(zone);
IgnoredAssetLookup ignoredAssetLookup;
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
auto loader = image::CreateLoaderEmbeddedIW5(memory, searchPath);
auto result = loader->CreateAsset("*testimage", context);
REQUIRE(result.HasBeenSuccessful());
const auto* assetInfo = reinterpret_cast<XAssetInfo<GfxImage>*>(result.GetAssetInfo());
const auto* image = assetInfo->Asset();
REQUIRE(image->name == "*testimage"s);
REQUIRE(image->width == 64);
REQUIRE(image->height == 64);
REQUIRE(image->depth == 1);
REQUIRE(image->texture.loadDef);
REQUIRE(image->texture.loadDef->resourceSize > 0);
}
} // namespace

View File

@@ -0,0 +1,54 @@
#include "Game/IW5/Image/ImageLoaderExternalIW5.h"
#include "Game/IW5/GameIW5.h"
#include "OatTestPaths.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
namespace fs = std::filesystem;
using namespace IW5;
using namespace std::literals;
namespace
{
TEST_CASE("ImageLoaderExternalIW5: Can parse iwi", "[iw5][image]")
{
MockSearchPath searchPath;
const auto filePath = oat::paths::GetTestDirectory() / "ObjLoadingTests/Game/IW5/Image/TestImage.iwi";
const auto fileSize = fs::file_size(filePath);
std::ifstream file(filePath, std::ios::binary);
REQUIRE(file.is_open());
const auto data = std::make_unique<char[]>(fileSize);
file.read(data.get(), fileSize);
searchPath.AddFileData("images/testimage.iwi", std::string(data.get(), fileSize));
Zone zone("MockZone", 0, GameId::IW5, GamePlatform::PC);
MemoryManager memory;
AssetCreatorCollection creatorCollection(zone);
IgnoredAssetLookup ignoredAssetLookup;
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
auto loader = image::CreateLoaderExternalIW5(memory, searchPath);
auto result = loader->CreateAsset("testimage", context);
REQUIRE(result.HasBeenSuccessful());
const auto* assetInfo = reinterpret_cast<XAssetInfo<GfxImage>*>(result.GetAssetInfo());
const auto* image = assetInfo->Asset();
REQUIRE(image->name == "testimage"s);
REQUIRE(image->width == 64);
REQUIRE(image->height == 64);
REQUIRE(image->depth == 1);
}
} // namespace

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,57 @@
#include "Game/T5/Image/ImageLoaderEmbeddedT5.h"
#include "Game/T5/GameT5.h"
#include "OatTestPaths.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
namespace fs = std::filesystem;
using namespace T5;
using namespace std::literals;
namespace
{
TEST_CASE("ImageLoaderEmbeddedT5: Can parse dds", "[t5][image]")
{
MockSearchPath searchPath;
const auto filePath = oat::paths::GetTestDirectory() / "ObjLoadingTests/Game/T5/Image/TestImage.dds";
const auto fileSize = fs::file_size(filePath);
std::ifstream file(filePath, std::ios::binary);
REQUIRE(file.is_open());
const auto data = std::make_unique<char[]>(fileSize);
file.read(data.get(), fileSize);
searchPath.AddFileData("images/_testimage.dds", std::string(data.get(), fileSize));
Zone zone("MockZone", 0, GameId::T5, GamePlatform::PC);
MemoryManager memory;
AssetCreatorCollection creatorCollection(zone);
IgnoredAssetLookup ignoredAssetLookup;
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
auto loader = image::CreateLoaderEmbeddedT5(memory, searchPath);
auto result = loader->CreateAsset("*testimage", context);
REQUIRE(result.HasBeenSuccessful());
const auto* assetInfo = reinterpret_cast<XAssetInfo<GfxImage>*>(result.GetAssetInfo());
const auto* image = assetInfo->Asset();
REQUIRE(image->name == "*testimage"s);
REQUIRE(image->width == 64);
REQUIRE(image->height == 64);
REQUIRE(image->depth == 1);
REQUIRE(image->texture.loadDef);
REQUIRE(image->texture.loadDef->resourceSize > 0);
}
} // namespace

View File

@@ -0,0 +1,54 @@
#include "Game/T5/Image/ImageLoaderExternalT5.h"
#include "Game/T5/GameT5.h"
#include "OatTestPaths.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
namespace fs = std::filesystem;
using namespace T5;
using namespace std::literals;
namespace
{
TEST_CASE("ImageLoaderExternalT5: Can parse iwi", "[t5][image]")
{
MockSearchPath searchPath;
const auto filePath = oat::paths::GetTestDirectory() / "ObjLoadingTests/Game/T5/Image/TestImage.iwi";
const auto fileSize = fs::file_size(filePath);
std::ifstream file(filePath, std::ios::binary);
REQUIRE(file.is_open());
const auto data = std::make_unique<char[]>(fileSize);
file.read(data.get(), fileSize);
searchPath.AddFileData("images/testimage.iwi", std::string(data.get(), fileSize));
Zone zone("MockZone", 0, GameId::T5, GamePlatform::PC);
MemoryManager memory;
AssetCreatorCollection creatorCollection(zone);
IgnoredAssetLookup ignoredAssetLookup;
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
auto loader = image::CreateLoaderExternalT5(memory, searchPath);
auto result = loader->CreateAsset("testimage", context);
REQUIRE(result.HasBeenSuccessful());
const auto* assetInfo = reinterpret_cast<XAssetInfo<GfxImage>*>(result.GetAssetInfo());
const auto* image = assetInfo->Asset();
REQUIRE(image->name == "testimage"s);
REQUIRE(image->width == 64);
REQUIRE(image->height == 64);
REQUIRE(image->depth == 1);
}
} // namespace

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,58 @@
#include "Game/T6/Image/ImageLoaderEmbeddedT6.h"
#include "Game/T6/GameT6.h"
#include "OatTestPaths.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
namespace fs = std::filesystem;
using namespace T6;
using namespace std::literals;
namespace
{
TEST_CASE("ImageLoaderEmbeddedT6: Can parse dds", "[t6][image]")
{
MockSearchPath searchPath;
const auto filePath = oat::paths::GetTestDirectory() / "ObjLoadingTests/Game/T6/Image/TestImage.dds";
const auto fileSize = fs::file_size(filePath);
std::ifstream file(filePath, std::ios::binary);
REQUIRE(file.is_open());
const auto data = std::make_unique<char[]>(fileSize);
file.read(data.get(), fileSize);
searchPath.AddFileData("images/_testimage.dds", std::string(data.get(), fileSize));
Zone zone("MockZone", 0, GameId::T6, GamePlatform::PC);
MemoryManager memory;
AssetCreatorCollection creatorCollection(zone);
IgnoredAssetLookup ignoredAssetLookup;
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
auto loader = image::CreateLoaderEmbeddedT6(memory, searchPath);
auto result = loader->CreateAsset("*testimage", context);
REQUIRE(result.HasBeenSuccessful());
const auto* assetInfo = reinterpret_cast<XAssetInfo<GfxImage>*>(result.GetAssetInfo());
const auto* image = assetInfo->Asset();
REQUIRE(image->name == "*testimage"s);
REQUIRE(image->width == 64);
REQUIRE(image->height == 64);
REQUIRE(image->depth == 1);
REQUIRE(image->streamedPartCount == 0);
REQUIRE(image->texture.loadDef);
REQUIRE(image->texture.loadDef->resourceSize > 0);
}
} // namespace

View File

@@ -0,0 +1,57 @@
#include "Game/T6/Image/ImageLoaderExternalT6.h"
#include "Game/T6/GameT6.h"
#include "OatTestPaths.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
namespace fs = std::filesystem;
using namespace T6;
using namespace std::literals;
namespace
{
TEST_CASE("ImageLoaderExternalT6: Can parse iwi", "[t6][image]")
{
MockSearchPath searchPath;
const auto filePath = oat::paths::GetTestDirectory() / "ObjLoadingTests/Game/T6/Image/TestImage.iwi";
const auto fileSize = fs::file_size(filePath);
std::ifstream file(filePath, std::ios::binary);
REQUIRE(file.is_open());
const auto data = std::make_unique<char[]>(fileSize);
file.read(data.get(), fileSize);
searchPath.AddFileData("images/testimage.iwi", std::string(data.get(), fileSize));
Zone zone("MockZone", 0, GameId::T6, GamePlatform::PC);
MemoryManager memory;
AssetCreatorCollection creatorCollection(zone);
IgnoredAssetLookup ignoredAssetLookup;
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
auto loader = image::CreateLoaderExternalT6(memory, searchPath);
auto result = loader->CreateAsset("testimage", context);
REQUIRE(result.HasBeenSuccessful());
const auto* assetInfo = reinterpret_cast<XAssetInfo<GfxImage>*>(result.GetAssetInfo());
const auto* image = assetInfo->Asset();
REQUIRE(image->name == "testimage"s);
REQUIRE(image->width == 64);
REQUIRE(image->height == 64);
REQUIRE(image->depth == 1);
REQUIRE(image->streamedPartCount == 1);
REQUIRE(image->streamedParts[0].levelSize == 2112);
REQUIRE(image->streamedParts[0].hash == (0x386422F2 & 0x1FFFFFFF));
}
} // namespace

Binary file not shown.

Binary file not shown.