chore: checkpoint current workspace changes
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <XCEngine/Core/Asset/ArtifactContainer.h>
|
||||
#include <XCEngine/Core/Asset/ArtifactFormats.h>
|
||||
#include <XCEngine/Core/Asset/AssetDatabase.h>
|
||||
#include <XCEngine/Core/Asset/AssetRef.h>
|
||||
#include <XCEngine/Core/Asset/ResourceManager.h>
|
||||
@@ -8,12 +10,14 @@
|
||||
#include <XCEngine/Core/Containers/Array.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
using namespace XCEngine::Containers;
|
||||
namespace Core = XCEngine::Core;
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -103,9 +107,14 @@ TEST(TextureLoader, AssetDatabaseCreatesTextureArtifactAndReusesItWithoutReimpor
|
||||
ASSERT_TRUE(firstResolve.exists);
|
||||
ASSERT_TRUE(firstResolve.artifactReady);
|
||||
EXPECT_TRUE(fs::exists(projectRoot / "Assets" / "checker.bmp.meta"));
|
||||
EXPECT_TRUE(fs::exists(projectRoot / "Library" / "SourceAssetDB" / "assets.db"));
|
||||
EXPECT_TRUE(fs::exists(projectRoot / "Library" / "ArtifactDB" / "artifacts.db"));
|
||||
EXPECT_TRUE(fs::exists(projectRoot / "Library" / "assets.db"));
|
||||
EXPECT_TRUE(fs::exists(projectRoot / "Library" / "artifacts.db"));
|
||||
EXPECT_TRUE(fs::exists(firstResolve.artifactMainPath.CStr()));
|
||||
const fs::path firstArtifactPath(firstResolve.artifactMainPath.CStr());
|
||||
ASSERT_TRUE(firstArtifactPath.has_filename());
|
||||
ASSERT_TRUE(firstArtifactPath.has_parent_path());
|
||||
EXPECT_EQ(firstArtifactPath.parent_path().filename().string(),
|
||||
firstArtifactPath.stem().string().substr(0, 2));
|
||||
|
||||
std::ifstream metaFile(projectRoot / "Assets" / "checker.bmp.meta");
|
||||
ASSERT_TRUE(metaFile.is_open());
|
||||
@@ -223,4 +232,64 @@ TEST(TextureLoader, ResourceManagerLoadsLibraryArtifactTextureWithoutReimporting
|
||||
fs::remove_all(projectRoot);
|
||||
}
|
||||
|
||||
TEST(TextureLoader, LoadTextureArtifactFromContainerEntryPath) {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
const fs::path projectRoot = fs::temp_directory_path() / "xc_texture_container_entry_path_test";
|
||||
fs::remove_all(projectRoot);
|
||||
fs::create_directories(projectRoot);
|
||||
|
||||
ArtifactContainerWriter writer;
|
||||
|
||||
TextureArtifactHeader header;
|
||||
header.textureType = static_cast<Core::uint32>(TextureType::Texture2D);
|
||||
header.textureFormat = static_cast<Core::uint32>(TextureFormat::RGBA8_UNORM);
|
||||
header.width = 2;
|
||||
header.height = 2;
|
||||
header.depth = 1;
|
||||
header.mipLevels = 1;
|
||||
header.arraySize = 1;
|
||||
header.pixelDataSize = 16;
|
||||
|
||||
ArtifactContainerEntry textureEntry;
|
||||
textureEntry.name = "texture_0.xctex";
|
||||
textureEntry.resourceType = ResourceType::Texture;
|
||||
textureEntry.payload.Resize(sizeof(TextureArtifactHeader) + static_cast<size_t>(header.pixelDataSize));
|
||||
std::memcpy(textureEntry.payload.Data(), &header, sizeof(TextureArtifactHeader));
|
||||
|
||||
Core::uint8* pixelBytes = textureEntry.payload.Data() + sizeof(TextureArtifactHeader);
|
||||
const Core::uint8 pixelData[16] = {
|
||||
255, 0, 0, 255,
|
||||
0, 255, 0, 255,
|
||||
0, 0, 255, 255,
|
||||
255, 255, 255, 255
|
||||
};
|
||||
std::memcpy(pixelBytes, pixelData, sizeof(pixelData));
|
||||
writer.AddEntry(std::move(textureEntry));
|
||||
|
||||
const String containerPath =
|
||||
(projectRoot / "Library" / "Artifacts" / "ab" / "artifact.xcmodel").string().c_str();
|
||||
String errorMessage;
|
||||
ASSERT_TRUE(writer.WriteToFile(containerPath, &errorMessage))
|
||||
<< errorMessage.CStr();
|
||||
|
||||
TextureLoader loader;
|
||||
const String virtualPath =
|
||||
BuildArtifactContainerEntryPath(containerPath, "texture_0.xctex");
|
||||
LoadResult result = loader.Load(virtualPath);
|
||||
ASSERT_TRUE(result) << result.errorMessage.CStr();
|
||||
ASSERT_NE(result.resource, nullptr);
|
||||
|
||||
auto* texture = static_cast<Texture*>(result.resource);
|
||||
EXPECT_EQ(texture->GetWidth(), 2u);
|
||||
EXPECT_EQ(texture->GetHeight(), 2u);
|
||||
EXPECT_EQ(texture->GetTextureType(), TextureType::Texture2D);
|
||||
EXPECT_EQ(texture->GetFormat(), TextureFormat::RGBA8_UNORM);
|
||||
EXPECT_EQ(texture->GetPixelDataSize(), 16u);
|
||||
EXPECT_EQ(texture->GetPath(), virtualPath);
|
||||
|
||||
delete texture;
|
||||
fs::remove_all(projectRoot);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user