forge
Explore
Log in

Don't you dare go Hollow

Commit import-during-play and undo-after-import coverage

Browse files at this commit

37f2bfe0c2694f41ede282c72d71774dd87610beAhmet Kaan GümüşParent: 80f10f5
  • test
    • commit import-during-play and undo-after-import coverage
Show full message
🧪 test(playback): commit import-during-play and undo-after-import coverage
crates/engine/tests/playback.rsmodified+64 -0
@@ -735,6 +735,70 @@ fn a_vanished_source_is_skipped() {
735 assert!(session.is_eos(), "the timeline still ends");735 assert!(session.is_eos(), "the timeline still ends");
736 }736 }
737 737
738+/// Importing while the device is running: the import reseeks under the
739+/// playhead, so what must not happen is a stall -- the joined timeline still
740+/// plays out whole. No audio needed, so this runs anywhere.
741+#[test]
742+fn import_during_play_does_not_stall() {
743+ let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));
744+ let mut session = PlaybackSession::open(&av).expect("open");
745+ let first = session.meta().frame_count;
746+ let mut last_index = None;
747+
748+ session.play();
749+ run_for(&mut session, &mut last_index, Duration::from_millis(300));
750+ assert!(last_index.is_some(), "no frames before the import");
751+
752+ session.import(&av2).expect("import while playing");
753+ assert_eq!(session.clip_spans().len(), 2);
754+ assert!(session.is_playing(), "the import stopped the clock");
755+
756+ // From here on the indices go *backwards* once: `run_for` decodes far ahead
757+ // of the clock (ledger), and the import reseeks to `now()` -- which is why
758+ // this drains with `drain_to_eof` instead of the order-checking `pump`.
759+ let (count, last) = drain_to_eof(&mut session);
760+ eprintln!("import while playing: {count} more frames, last {last:?}");
761+ assert_eq!(
762+ last,
763+ Some(first + frame_count(&av2) - 1),
764+ "the joined timeline did not play out"
765+ );
766+}
767+
768+/// An import is *one* undo step: the appended clip goes, the source entry stays
769+/// behind (documented, harmless -- source indexes are forever), and the session
770+/// is still playable on the restored timeline.
771+#[test]
772+fn undo_after_import_is_one_step() {
773+ let av2 = asset("test_av2.mp4");
774+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
775+ session.import(&av2).expect("import");
776+ assert_eq!(session.clip_spans().len(), 2);
777+ assert!((session.timeline_duration() - 9.0).abs() < 1e-9);
778+
779+ assert!(session.undo(), "undo the import");
780+ assert_eq!(session.clip_spans().len(), 1, "one step, back to one clip");
781+ assert!(
782+ (session.timeline_duration() - 5.0).abs() < 1e-9,
783+ "undo did not restore the duration: {}",
784+ session.timeline_duration()
785+ );
786+
787+ // The orphan source is only observable on the project -- `PlaybackSession`
788+ // exposes sources through `clip_spans_by_source`, and the undone clip is
789+ // exactly the one that named it.
790+ let mut project = engine::Project::single(asset("test_av.mp4"), 150);
791+ let source = project.import(&av2);
792+ assert!(project.append_clip(source, 120));
793+ assert!(project.undo());
794+ assert_eq!(project.clips().len(), 1);
795+ assert_eq!(project.sources().len(), 2, "the source entry stays behind");
796+
797+ // Still playable: the undo reseeked to the (paused) playhead at zero.
798+ session.play();
799+ assert_eq!(next_index(&mut session, "undo of an import"), 0);
800+}
801+
738 /// The audio path across a source join: one worker spans both files, so the802 /// The audio path across a source join: one worker spans both files, so the
739 /// clock must keep running at real speed through the boundary. (Whether it is803 /// clock must keep running at real speed through the boundary. (Whether it is
740 /// still the *audio* clock is not observable from outside -- a device that ran804 /// still the *audio* clock is not observable from outside -- a device that ran