mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-11 22:50:08 +00:00
tests for move_resource + fixed bugs
This commit is contained in:
@@ -11,9 +11,6 @@
|
||||
/fyrox-core/test.txt
|
||||
/fyrox-resource/test.txt
|
||||
/fyrox-core-derive/test_output
|
||||
/fyrox-resource/test_output
|
||||
/fyrox-resource/test_output1
|
||||
/fyrox-resource/test_output2
|
||||
/fyrox-impl/test_output
|
||||
history.bin
|
||||
settings.ron
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
/test_output1
|
||||
/test_output2
|
||||
/test_output3
|
||||
@@ -674,8 +674,8 @@ mod tests {
|
||||
ResourceData,
|
||||
};
|
||||
use fyrox_core::{
|
||||
futures::executor::block_on, io::FileError, parking_lot::Mutex, reflect::prelude::*,
|
||||
task::TaskPool, uuid, visitor::prelude::*, TypeUuidProvider, Uuid,
|
||||
append_extension, futures::executor::block_on, io::FileError, parking_lot::Mutex,
|
||||
reflect::prelude::*, task::TaskPool, uuid, visitor::prelude::*, TypeUuidProvider, Uuid,
|
||||
};
|
||||
use ron::ser::PrettyConfig;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -762,6 +762,7 @@ mod tests {
|
||||
|
||||
const TEST_FOLDER1: &'static str = "./test_output1";
|
||||
const TEST_FOLDER2: &'static str = "./test_output2";
|
||||
const TEST_FOLDER3: &'static str = "./test_output3";
|
||||
|
||||
fn make_file_path(root: &str, n: usize) -> PathBuf {
|
||||
Path::new(root).join(format!("test{n}.{}", MyDataLoader::EXT))
|
||||
@@ -828,4 +829,37 @@ mod tests {
|
||||
assert_eq!(block_on(res1).unwrap().data_ref().data, 2);
|
||||
assert_eq!(block_on(res2).unwrap().data_ref().data, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_move_resource() {
|
||||
write_test_resources(TEST_FOLDER3, 0..2);
|
||||
let resource_manager = ResourceManager::new(Arc::new(TaskPool::new()));
|
||||
resource_manager.add_loader(MyDataLoader {});
|
||||
resource_manager
|
||||
.update_and_load_registry(Path::new(TEST_FOLDER3).join("resources.registry"));
|
||||
let path1 = make_file_path(TEST_FOLDER3, 0);
|
||||
let path2 = make_file_path(TEST_FOLDER3, 1);
|
||||
let res1 = resource_manager.request::<MyData>(path1);
|
||||
let res2 = resource_manager.request::<MyData>(path2);
|
||||
assert_eq!(block_on(res1.clone()).unwrap().data_ref().data, 0);
|
||||
assert_eq!(block_on(res2.clone()).unwrap().data_ref().data, 1);
|
||||
let new_res1_path = ResourceRegistry::prepare_path(make_file_path(TEST_FOLDER3, 3));
|
||||
let new_res2_path = ResourceRegistry::prepare_path(make_file_path(TEST_FOLDER3, 4));
|
||||
block_on(resource_manager.move_resource(res1.as_ref(), &new_res1_path)).unwrap();
|
||||
block_on(resource_manager.move_resource(res2.as_ref(), &new_res2_path)).unwrap();
|
||||
assert_eq!(
|
||||
resource_manager.resource_path(res1.as_ref()).unwrap(),
|
||||
new_res1_path
|
||||
);
|
||||
assert!(
|
||||
std::fs::exists(append_extension(new_res1_path, ResourceMetadata::EXTENSION)).unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
resource_manager.resource_path(res2.as_ref()).unwrap(),
|
||||
new_res2_path
|
||||
);
|
||||
assert!(
|
||||
std::fs::exists(append_extension(new_res2_path, ResourceMetadata::EXTENSION)).unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ impl ResourceManager {
|
||||
/// Attempts to move a resource from its current location to the new path.
|
||||
pub async fn move_resource(
|
||||
&self,
|
||||
resource: UntypedResource,
|
||||
resource: &UntypedResource,
|
||||
new_path: impl AsRef<Path>,
|
||||
) -> Result<(), FileError> {
|
||||
let resource_uuid = resource
|
||||
@@ -437,6 +437,14 @@ impl ResourceManager {
|
||||
// Move the file with its optional import options and mandatory metadata.
|
||||
io.move_file(&existing_path, &new_path).await?;
|
||||
|
||||
assert_eq!(
|
||||
registry
|
||||
.lock()
|
||||
.register(resource_uuid, new_path.clone())
|
||||
.as_ref(),
|
||||
Some(&existing_path)
|
||||
);
|
||||
|
||||
let options_path = append_extension(&existing_path, OPTIONS_EXTENSION);
|
||||
if io.exists(&options_path).await {
|
||||
let new_options_path = append_extension(&new_path, OPTIONS_EXTENSION);
|
||||
@@ -487,9 +495,11 @@ impl ResourceManagerState {
|
||||
|
||||
let resource_io = self.resource_io.clone();
|
||||
let resource_registry = self.resource_registry.clone();
|
||||
#[allow(unused_variables)]
|
||||
let excluded_folders = resource_registry.lock().excluded_folders.clone();
|
||||
let registry_status = resource_registry.lock().status.clone();
|
||||
registry_status.mark_as_loading();
|
||||
#[allow(unused_variables)]
|
||||
let task_loaders = self.loaders.clone();
|
||||
self.task_pool.spawn_task(async move {
|
||||
// Try to update the registry first.
|
||||
|
||||
Reference in New Issue
Block a user