| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | use std::path::PathBuf; |
| 11 | |
| 12 | use engine::PlaybackSession; |
| 13 | use engine::scratch::Scratch; |
| 14 | |
| 15 | fn asset(name: &str) -> PathBuf { |
| 16 | PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../assets").join(name) |
| 17 | } |
| 18 | |
| 19 | |
| 20 | fn moved_project(name: &str) -> (Scratch, PathBuf, PathBuf, PathBuf) { |
| 21 | let dir = Scratch::dir(&format!("ve_offline_{name}")); |
| 22 | let media = dir.join("film.mp4"); |
| 23 | std::fs::copy(asset("test_av.mp4"), &media).expect("copy the fixture"); |
| 24 | let session = PlaybackSession::open(&media).expect("open the fixture"); |
| 25 | session.set_gain(0.0); |
| 26 | let path = dir.join("proj.edith"); |
| 27 | session.save_project(&path).expect("save"); |
| 28 | let moved = dir.join("moved.mp4"); |
| 29 | std::fs::rename(&media, &moved).expect("move the media"); |
| 30 | (dir, path, media, moved) |
| 31 | } |
| 32 | |
| 33 | #[test] |
| 34 | fn a_moved_source_opens_offline_with_its_clips() { |
| 35 | let (_dir, path, _media, _moved) = moved_project("opens"); |
| 36 | let session = PlaybackSession::open_project(&path).expect("opens with the source offline"); |
| 37 | let offline = session.offline_sources(); |
| 38 | assert_eq!(offline.len(), 1, "{offline:?}"); |
| 39 | assert_eq!(offline[0].0, 0); |
| 40 | assert!(!session.lanes().is_empty(), "the clips stay on the timeline"); |
| 41 | } |
| 42 | |
| 43 | #[test] |
| 44 | fn relinking_by_path_brings_the_source_back() { |
| 45 | let (_dir, path, media, moved) = moved_project("relinked-open"); |
| 46 | let session = PlaybackSession::open_project_relinked(&path, &[(media, moved)]) |
| 47 | .expect("opens with the relink applied"); |
| 48 | assert!(session.offline_sources().is_empty()); |
| 49 | } |
| 50 | |
| 51 | #[test] |
| 52 | fn relink_source_checks_the_kind_and_accepts_the_same_material() { |
| 53 | let (_dir, path, _media, moved) = moved_project("relink-kind"); |
| 54 | let mut session = PlaybackSession::open_project(&path).expect("opens offline"); |
| 55 | let sound = asset("test_ac3.mka"); |
| 56 | let refused = session.relink_source(0, &sound).expect_err("a sound file is not a picture"); |
| 57 | assert!(refused.to_string().contains("is a sound file"), "{refused}"); |
| 58 | assert_eq!(session.offline_sources().len(), 1, "a refusal changes nothing"); |
| 59 | let warnings = session.relink_source(0, &moved).expect("the same film relinks"); |
| 60 | assert!(warnings.is_empty(), "{warnings:?}"); |
| 61 | assert!(session.offline_sources().is_empty()); |
| 62 | } |
| 63 | |
| 64 | #[test] |
| 65 | fn a_project_with_every_source_gone_opens_with_all_of_them_offline() { |
| 66 | let (_dir, path, _media, _moved) = moved_project("all-gone"); |
| 67 | let session = PlaybackSession::open_project(&path).expect("opens, every source offline"); |
| 68 | assert_eq!(session.offline_sources().len(), session.sources().len()); |
| 69 | assert!(!session.lanes().is_empty(), "the clips stay"); |
| 70 | } |