Skip to content

Commit

Permalink
more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bertiqwerty committed Oct 23, 2024
1 parent da556d4 commit 698b1cc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
11 changes: 9 additions & 2 deletions rvimage/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,15 +831,22 @@ fn main() {
}

#[cfg(test)]
use rvlib::{defer_folder_removal, file_util::DEFAULT_TMPDIR, read_coco};
use {
rvlib::{defer_file_removal, defer_folder_removal, file_util::DEFAULT_TMPDIR, read_coco},
std::fs,
};

#[test]
fn test_coco() {
let in_prj_path = PathBuf::from("resources/test_data/rvprj_v4-0.json");
let test_file = in_prj_path.parent().unwrap().join("tmp-test.rvi");
defer_file_removal!(&test_file);
fs::copy(&in_prj_path, &test_file).unwrap();
let tmp_folder = DEFAULT_TMPDIR.join("convertcocotest");
std::fs::create_dir_all(&tmp_folder).unwrap();
defer_folder_removal!(&tmp_folder);
let (export_path, meta_data, rot90) = export_coco(in_prj_path, &tmp_folder, true).unwrap();
let (export_path, meta_data, rot90) =
export_coco(test_file.clone(), &tmp_folder, true).unwrap();
let files = tmp_folder
.read_dir()
.unwrap()
Expand Down
10 changes: 2 additions & 8 deletions rvimage/tests/ctrl_s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn test_main() {
main_loop.one_iteration(&events, &ctx).unwrap();
});
main_loop.load_prj(Some(test_file.clone())).unwrap();
thread::sleep(Duration::from_millis(1));
let file_info_before = fs::metadata(test_file.as_path())
.unwrap()
.modified()
Expand All @@ -28,23 +29,16 @@ fn test_main() {
egui::__run_test_ctx(|ctx| {
main_loop.one_iteration(&events, &ctx).unwrap();
});
thread::sleep(Duration::from_millis(10));
let file_info_before_2 = fs::metadata(test_file.as_path())
.unwrap()
.modified()
.unwrap();
thread::sleep(Duration::from_millis(1));
let events =
Events::default().events(vec![Event::Held(KeyCode::Ctrl), Event::Pressed(KeyCode::S)]);
egui::__run_test_ctx(|ctx| {
main_loop.one_iteration(&events, &ctx).unwrap();
});
thread::sleep(Duration::from_millis(10));
thread::sleep(Duration::from_millis(1));
let file_info_after = fs::metadata(test_file.as_path())
.unwrap()
.modified()
.unwrap();
assert_ne!(file_info_before, file_info_after);
// we write the last person into to the project file
assert_ne!(file_info_before, file_info_before_2);
}
10 changes: 7 additions & 3 deletions rvimage/tests/serialized_prjs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::PathBuf;
use std::{fs, path::PathBuf};

use rvlib::{control::Control, world::ToolsDataMap};
use rvlib::{control::Control, defer_file_removal, world::ToolsDataMap};

fn get_test_folder() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("resources/test_data")
Expand All @@ -15,7 +15,11 @@ fn get_ctrl() -> Control {

fn prj_load(file: &str) -> ToolsDataMap {
let mut ctrl = get_ctrl();
ctrl.load(get_test_folder().join(file)).unwrap()
let test_file_src = get_test_folder().join(get_test_folder().join(file));
let test_file = get_test_folder().join("tmp-test.rvi");
defer_file_removal!(&test_file);
fs::copy(&test_file_src, &test_file).unwrap();
ctrl.load(test_file.clone()).unwrap()
}

#[test]
Expand Down

0 comments on commit 698b1cc

Please sign in to comment.