chore: checkpoint current workspace changes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <XCEngine/Core/Asset/ArtifactContainer.h>
|
||||
#include <XCEngine/Core/Asset/ArtifactFormats.h>
|
||||
#include <XCEngine/Core/Asset/AssetDatabase.h>
|
||||
#include <XCEngine/Resources/BuiltinResources.h>
|
||||
@@ -8,6 +9,7 @@
|
||||
#include <XCEngine/Core/Containers/Array.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
@@ -16,6 +18,7 @@
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
using namespace XCEngine::Containers;
|
||||
namespace Core = XCEngine::Core;
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -31,6 +34,20 @@ void WriteArtifactString(std::ofstream& output, const XCEngine::Containers::Stri
|
||||
}
|
||||
}
|
||||
|
||||
void AppendBytes(Array<Core::uint8>& payload, const void* data, size_t size) {
|
||||
const size_t oldSize = payload.Size();
|
||||
payload.Resize(oldSize + size);
|
||||
std::memcpy(payload.Data() + oldSize, data, size);
|
||||
}
|
||||
|
||||
void AppendArtifactString(Array<Core::uint8>& payload, const String& value) {
|
||||
const Core::uint32 length = static_cast<Core::uint32>(value.Length());
|
||||
AppendBytes(payload, &length, sizeof(length));
|
||||
if (length > 0) {
|
||||
AppendBytes(payload, value.CStr(), length);
|
||||
}
|
||||
}
|
||||
|
||||
bool PumpAsyncLoadsUntilIdle(ResourceManager& manager,
|
||||
std::chrono::milliseconds timeout = std::chrono::milliseconds(4000)) {
|
||||
const auto deadline = std::chrono::steady_clock::now() + timeout;
|
||||
@@ -769,6 +786,10 @@ TEST(MaterialLoader, AssetDatabaseCreatesMaterialArtifact) {
|
||||
EXPECT_TRUE(resolvedAsset.artifactReady);
|
||||
EXPECT_EQ(fs::path(resolvedAsset.artifactMainPath.CStr()).extension().string(), ".xcmat");
|
||||
EXPECT_TRUE(fs::exists(resolvedAsset.artifactMainPath.CStr()));
|
||||
const fs::path artifactPath(resolvedAsset.artifactMainPath.CStr());
|
||||
ASSERT_TRUE(artifactPath.has_parent_path());
|
||||
EXPECT_EQ(artifactPath.parent_path().filename().string(),
|
||||
artifactPath.stem().string().substr(0, 2));
|
||||
|
||||
database.Shutdown();
|
||||
fs::remove_all(projectRoot);
|
||||
@@ -1227,4 +1248,54 @@ TEST(MaterialLoader, LoadMaterialArtifactDefersTexturePayloadUntilRequested) {
|
||||
fs::remove_all(projectRoot);
|
||||
}
|
||||
|
||||
TEST(MaterialLoader, LoadMaterialArtifactFromContainerMainEntryPath) {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
const fs::path projectRoot = fs::temp_directory_path() / "xc_material_container_main_entry_test";
|
||||
fs::remove_all(projectRoot);
|
||||
fs::create_directories(projectRoot);
|
||||
|
||||
ArtifactContainerWriter writer;
|
||||
|
||||
ArtifactContainerEntry mainEntry;
|
||||
mainEntry.name = "main";
|
||||
mainEntry.resourceType = ResourceType::Material;
|
||||
mainEntry.localID = kMainAssetLocalID;
|
||||
|
||||
MaterialArtifactFileHeader fileHeader;
|
||||
AppendBytes(mainEntry.payload, &fileHeader, sizeof(fileHeader));
|
||||
AppendArtifactString(mainEntry.payload, "ContainerMaterial");
|
||||
AppendArtifactString(mainEntry.payload, "Assets/container.material");
|
||||
AppendArtifactString(mainEntry.payload, "");
|
||||
|
||||
MaterialArtifactHeader header;
|
||||
header.renderQueue = static_cast<Core::int32>(MaterialRenderQueue::Geometry);
|
||||
AppendBytes(mainEntry.payload, &header, sizeof(header));
|
||||
writer.AddEntry(std::move(mainEntry));
|
||||
|
||||
const String containerPath =
|
||||
(projectRoot / "Library" / "Artifacts" / "ab" / "container.xcmat").string().c_str();
|
||||
String errorMessage;
|
||||
ASSERT_TRUE(writer.WriteToFile(containerPath, &errorMessage))
|
||||
<< errorMessage.CStr();
|
||||
|
||||
MaterialLoader loader;
|
||||
const String virtualPath = BuildArtifactContainerEntryPath(containerPath, "main");
|
||||
EXPECT_TRUE(loader.CanLoad(virtualPath));
|
||||
|
||||
LoadResult result = loader.Load(virtualPath);
|
||||
ASSERT_TRUE(result) << result.errorMessage.CStr();
|
||||
ASSERT_NE(result.resource, nullptr);
|
||||
|
||||
auto* material = static_cast<Material*>(result.resource);
|
||||
ASSERT_NE(material, nullptr);
|
||||
EXPECT_TRUE(material->IsValid());
|
||||
EXPECT_EQ(material->GetPath(), "Assets/container.material");
|
||||
EXPECT_EQ(material->GetRenderQueue(), static_cast<Core::int32>(MaterialRenderQueue::Geometry));
|
||||
EXPECT_FALSE(material->HasRenderStateOverride());
|
||||
|
||||
delete material;
|
||||
fs::remove_all(projectRoot);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user