Commit paste-while-playing and paste-at-EOS coverage
Browse files at this commita178b73db9f4bbf855f0c35b9440072500cbe085Parent: 37f2bfe- test
- commit paste-while-playing and paste-at-EOS coverage
1 changed file +68 -0
crates/engine/tests/playback.rsmodified+68 -0
| @@ -474,6 +474,74 @@ fn paste_duplicates_a_clip_at_the_playhead() { | |||
| 474 | ); | 474 | ); |
| 475 | } | 475 | } |
| 476 | 476 | ||
| 477 | +/// Pasting at the playhead while it is running: like a delete this moves every | ||
| 478 | +/// following frame, so the session reseeks under itself -- what must not happen | ||
| 479 | +/// is a stall, and the grown timeline still plays out whole. No audio needed. | ||
| 480 | +#[test] | ||
| 481 | +fn paste_while_playing_does_not_stall() { | ||
| 482 | + let path = asset("test_baseline.mp4"); | ||
| 483 | + let mut session = PlaybackSession::open(&path).expect("open"); | ||
| 484 | + let (fps, total) = (session.meta().frame_rate, session.meta().frame_count); | ||
| 485 | + let mut last_index = None; | ||
| 486 | + | ||
| 487 | + assert!(session.cut_at(2.0), "cut at 2 s"); | ||
| 488 | + let copied = session.clip_at(0).expect("clip 0"); | ||
| 489 | + session.play(); | ||
| 490 | + run_for(&mut session, &mut last_index, Duration::from_millis(300)); | ||
| 491 | + assert!(last_index.is_some(), "no frames before the paste"); | ||
| 492 | + | ||
| 493 | + // Into the clip under the running playhead: the paste splits it in two and | ||
| 494 | + // lands between the halves. | ||
| 495 | + assert!(session.paste_at(session.now(), copied), "paste at the playhead"); | ||
| 496 | + assert!(session.is_playing(), "the paste stopped the clock"); | ||
| 497 | + assert_eq!(session.clip_spans().len(), 4); | ||
| 498 | + let grown = total + copied.len(); | ||
| 499 | + assert!( | ||
| 500 | + (session.timeline_duration() - f64::from(grown) / fps).abs() < 1e-9, | ||
| 501 | + "duration after the paste: {}", | ||
| 502 | + session.timeline_duration() | ||
| 503 | + ); | ||
| 504 | + | ||
| 505 | + // As after a mid-play import: the reseek makes the indices step backwards | ||
| 506 | + // once, so this drains without `pump`'s index-order check. | ||
| 507 | + let (count, last) = drain_to_eof(&mut session); | ||
| 508 | + eprintln!("paste while playing: {count} more frames, last {last:?}"); | ||
| 509 | + assert_eq!( | ||
| 510 | + last, | ||
| 511 | + Some(grown - 1), | ||
| 512 | + "the grown timeline did not play out" | ||
| 513 | + ); | ||
| 514 | +} | ||
| 515 | + | ||
| 516 | +/// Pasting past the end of a played-out timeline appends, and the reseek every | ||
| 517 | +/// edit does clears `eos` -- so the session plays on into the pasted clip | ||
| 518 | +/// instead of staying dead. | ||
| 519 | +#[test] | ||
| 520 | +fn paste_at_eos_revives_the_session() { | ||
| 521 | + let path = asset("test_baseline.mp4"); | ||
| 522 | + let mut session = PlaybackSession::open(&path).expect("open"); | ||
| 523 | + let total = session.meta().frame_count; | ||
| 524 | + | ||
| 525 | + assert!(session.cut_at(2.0), "cut at 2 s"); | ||
| 526 | + let copied = session.clip_at(0).expect("clip 0"); | ||
| 527 | + session.play(); | ||
| 528 | + assert_eq!(drain_to_eof(&mut session).1, Some(total - 1)); | ||
| 529 | + assert!(session.is_eos()); | ||
| 530 | + | ||
| 531 | + assert!(session.paste_at(999.0, copied), "paste past the end appends"); | ||
| 532 | + assert!(!session.is_eos(), "the paste did not revive the session"); | ||
| 533 | + assert_eq!(session.clip_spans().len(), 3, "two clips plus the pasted one"); | ||
| 534 | + // No assertion on *where* it resumes: an edit reseeks to `now()`, and at EOS | ||
| 535 | + // that is wherever the wall clock got to while draining -- a race. What is | ||
| 536 | + // fixed is that frames come again and the whole grown timeline plays out. | ||
| 537 | + next_frame(&mut session, "paste at EOS"); | ||
| 538 | + assert_eq!( | ||
| 539 | + drain_to_eof(&mut session).1, | ||
| 540 | + Some(total + copied.len() - 1), | ||
| 541 | + "the pasted clip did not play out" | ||
| 542 | + ); | ||
| 543 | +} | ||
| 544 | + | ||
| 477 | /// Editing while the device is running. A cut must not disturb playback at all | 545 | /// Editing while the device is running. A cut must not disturb playback at all |
| 478 | /// and a delete reseeks under it -- in both cases the audio keeps coming, which | 546 | /// and a delete reseeks under it -- in both cases the audio keeps coming, which |
| 479 | /// is what stops `tick` from handing the timeline back to wall time. | 547 | /// is what stops `tick` from handing the timeline back to wall time. |