forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

offline.rs70 lines, 3.0 KiBHistoryRawDownload
1//! A project whose media has moved or been deleted opens with those sources
2//! offline: their clips stay, nothing reads from them, and `relink_source` or
3//! `open_project_relinked` points them back at the file. Only a project with no
4//! saved timeline is kept when every source is gone.
5//!
6//! ```text
7//! cargo test -p engine --release --test offline -- --nocapture
8//! ```
9
10use std::path::PathBuf;
11
12use engine::PlaybackSession;
13use engine::scratch::Scratch;
14
15fn asset(name: &str) -> PathBuf {
16 PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../assets").join(name)
17}
18
19/// A saved project on one copied fixture, then that fixture moved away.
20fn 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]
34fn 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]
44fn 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]
52fn 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]
65fn 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}