Finalize library bootstrap status and stabilize async asset regressions
This commit is contained in:
@@ -169,4 +169,58 @@ TEST(TextureLoader, ResourceManagerLoadsTextureByAssetRefFromProjectAssets) {
|
||||
fs::remove_all(projectRoot);
|
||||
}
|
||||
|
||||
TEST(TextureLoader, ResourceManagerLoadsLibraryArtifactTextureWithoutReimportingIt) {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
ResourceManager& manager = ResourceManager::Get();
|
||||
manager.Initialize();
|
||||
|
||||
const fs::path projectRoot = fs::temp_directory_path() / "xc_texture_library_artifact_direct_load_test";
|
||||
const fs::path assetsDir = projectRoot / "Assets";
|
||||
const fs::path texturePath = assetsDir / "checker.bmp";
|
||||
|
||||
fs::remove_all(projectRoot);
|
||||
fs::create_directories(assetsDir);
|
||||
fs::copy_file(GetTextureFixturePath("checker.bmp"), texturePath, fs::copy_options::overwrite_existing);
|
||||
|
||||
manager.SetResourceRoot(projectRoot.string().c_str());
|
||||
const AssetImportService::ImportStatusSnapshot bootstrapStatus = manager.GetProjectAssetImportStatus();
|
||||
EXPECT_TRUE(bootstrapStatus.HasValue());
|
||||
EXPECT_TRUE(bootstrapStatus.success);
|
||||
EXPECT_EQ(std::string(bootstrapStatus.operation.CStr()), "Bootstrap Project");
|
||||
EXPECT_GT(bootstrapStatus.startedAtMs, 0u);
|
||||
EXPECT_GE(bootstrapStatus.completedAtMs, bootstrapStatus.startedAtMs);
|
||||
EXPECT_EQ(bootstrapStatus.durationMs, bootstrapStatus.completedAtMs - bootstrapStatus.startedAtMs);
|
||||
|
||||
AssetDatabase database;
|
||||
database.Initialize(projectRoot.string().c_str());
|
||||
|
||||
AssetDatabase::ResolvedAsset resolvedAsset;
|
||||
ASSERT_TRUE(database.EnsureArtifact("Assets/checker.bmp", ResourceType::Texture, resolvedAsset));
|
||||
ASSERT_TRUE(resolvedAsset.artifactReady);
|
||||
|
||||
std::error_code ec;
|
||||
const fs::path relativeArtifactPath =
|
||||
fs::relative(fs::path(resolvedAsset.artifactMainPath.CStr()), projectRoot, ec);
|
||||
ASSERT_FALSE(ec);
|
||||
ASSERT_FALSE(relativeArtifactPath.empty());
|
||||
|
||||
const auto textureHandle = manager.Load<Texture>(relativeArtifactPath.generic_string().c_str());
|
||||
ASSERT_TRUE(textureHandle.IsValid());
|
||||
EXPECT_EQ(textureHandle->GetWidth(), 2u);
|
||||
EXPECT_EQ(textureHandle->GetHeight(), 2u);
|
||||
EXPECT_EQ(textureHandle->GetPath(), relativeArtifactPath.generic_string().c_str());
|
||||
const AssetImportService::ImportStatusSnapshot postLoadStatus = manager.GetProjectAssetImportStatus();
|
||||
EXPECT_TRUE(postLoadStatus.HasValue());
|
||||
EXPECT_EQ(std::string(postLoadStatus.operation.CStr()), "Bootstrap Project");
|
||||
EXPECT_GT(postLoadStatus.startedAtMs, 0u);
|
||||
EXPECT_GE(postLoadStatus.completedAtMs, postLoadStatus.startedAtMs);
|
||||
EXPECT_EQ(postLoadStatus.durationMs, postLoadStatus.completedAtMs - postLoadStatus.startedAtMs);
|
||||
|
||||
database.Shutdown();
|
||||
manager.SetResourceRoot("");
|
||||
manager.Shutdown();
|
||||
fs::remove_all(projectRoot);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user