refactor: drop internal bridge/ffi layers; exporter family lands
Single-lib cleanup: the per-crate src/bridge/ and src/ffi.rs layers are gone (oakundo/oakcommon/oaknode/oaktimeline/oakcodec/oakaudio/ oakrender/oaktask/oakplugin/oakstorage); cross-crate calls are plain Rust, CHandle marshalling shrinks to the oakengine boundary, and tests call the Rust APIs directly (pure C-ABI wrapper tests removed where the domain layer already covers the behavior). exporter.h family implemented: oakengine_export_render (CLI contract), oakengine_export_render_with_params (was a stub), last_error and progress callback; synchronous path reuses task_create_export + start_sync. Fixes on the way: oaktask video ticket self-deadlock, audio params dropped on the export path, codec encoder AAC slicing and H.264 time base. Real-mp4 tests cover both entry points, progress and the illegal-argument matrix. Also: oakstorage session maps null project handles to None (version- info path), configstore test double literal 3.14 -> 3.15 (clippy PI lint), oakaudio output callback scratch buffer + env-aware P1 test, cli media round-trip test uses a generated 16-frame clip (no more minute-long debug runs).
This commit is contained in:
@@ -1,305 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Contract tests for the C ABI bridge layer (`src/bridge/`). The bridge
|
||||
//! declares the oaknode / oakundo / oakcommon foreign functions this crate
|
||||
//! calls for cross-module work (blocks, tracks, undo handles, XML). The
|
||||
//! exhaustive cross-module behaviour is owned by the C++ gtest suites of
|
||||
//! those modules; here we pin that the symbols the crate depends on are
|
||||
//! declared with the documented C ABI signature and that the bridge's own
|
||||
//! helpers are wired to the right functions.
|
||||
//!
|
||||
//! Rational ↔ num/den and Rational ↔ string conversion are NOT bridge C ABI
|
||||
//! functions (the bridge only carries XML + config): num/den conversion is
|
||||
//! `util::rat_nd` and the string format lives on `oakcore_rs::Rational`, so
|
||||
//! those tests pin the in-crate helpers directly.
|
||||
//!
|
||||
//! These tests call the `extern "C"` symbols, which are only defined under
|
||||
//! `--features test-stubs` (the in-crate mocks in `src/bridge/teststubs.rs`);
|
||||
//! run with that feature. The parts that build mock XML readers through
|
||||
//! `teststubs::xml_reader_handle` are additionally gated `#[cfg(feature =
|
||||
//! "test-stubs")]`.
|
||||
|
||||
use oakcore_rs::Rational;
|
||||
use oaktimeline::handle::CHandle;
|
||||
use oaktimeline::util;
|
||||
|
||||
/// The undo bridge declares a `make_command_handle`-style constructor that
|
||||
/// boxes a command into the C ABI handle shape, and a `free` that runs the
|
||||
/// caller's `free_fn` before clearing the handle.
|
||||
#[test]
|
||||
fn undo_bridge_constructs_handle() {
|
||||
use oaktimeline::bridge::undo::{
|
||||
oakundo_command_free, oakundo_command_init, OakUndoCommandVtable,
|
||||
};
|
||||
use oaktimeline::error::OAKTIMELINE_ABI_VERSION;
|
||||
use std::ffi::c_void;
|
||||
|
||||
unsafe extern "C" fn free_u32(ud: *mut c_void) {
|
||||
drop(Box::from_raw(ud as *mut u32));
|
||||
}
|
||||
|
||||
let vtable = OakUndoCommandVtable {
|
||||
redo: None,
|
||||
undo: None,
|
||||
free_fn: Some(free_u32),
|
||||
};
|
||||
let userdata = Box::into_raw(Box::new(7u32)) as *mut c_void;
|
||||
let mut h = unsafe { oakundo_command_init(&vtable, userdata) };
|
||||
assert!(!h.is_null(), "init must return a non-null command handle");
|
||||
assert_eq!(h.abi_version, OAKTIMELINE_ABI_VERSION);
|
||||
// Freeing runs `free_fn` (dropping the boxed u32) and clears the handle.
|
||||
unsafe { oakundo_command_free(&mut h) };
|
||||
assert!(h.is_null(), "free must clear the handle");
|
||||
}
|
||||
|
||||
/// The undo bridge frees a command handle and tolerates a null handle
|
||||
/// (free(NULL) no-op), matching `oakundo_capi::free_command_handle`.
|
||||
#[test]
|
||||
fn undo_bridge_free_handle_is_null_safe() {
|
||||
use oaktimeline::bridge::undo::oakundo_command_free;
|
||||
|
||||
// NULL pointer: no-op, no panic.
|
||||
unsafe { oakundo_command_free(std::ptr::null_mut()) };
|
||||
// Empty handle: no-op, no panic, stays empty.
|
||||
let mut h = CHandle::null();
|
||||
unsafe { oakundo_command_free(&mut h) };
|
||||
assert!(h.is_null());
|
||||
}
|
||||
|
||||
/// The node bridge exposes the block/track accessors this crate calls for
|
||||
/// edit commands (in/out/length, previous/next, track, track length).
|
||||
#[cfg(feature = "test-stubs")]
|
||||
#[test]
|
||||
fn node_bridge_exposes_block_geometry() {
|
||||
use oaktimeline::bridge::node::{
|
||||
oaknode_block_clip_create, oaknode_track_create, oaknode_track_prepend_block,
|
||||
};
|
||||
|
||||
let b = unsafe { oaknode_block_clip_create() };
|
||||
assert!(!b.is_null());
|
||||
// Default in/out/length are 0/1.
|
||||
assert_eq!(util::block_in(b.clone()), Rational::new(0, 1));
|
||||
assert_eq!(util::block_out(b.clone()), Rational::new(0, 1));
|
||||
assert_eq!(util::block_length(b.clone()), Rational::new(0, 1));
|
||||
// Detached block: no previous / next / owning track.
|
||||
assert!(util::block_previous(b.clone()).is_null());
|
||||
assert!(util::block_next(b.clone()).is_null());
|
||||
assert!(util::block_track(b.clone()).is_null());
|
||||
|
||||
// Attach two blocks to a track; prepend puts each at the front.
|
||||
let t = unsafe { oaknode_track_create(0) };
|
||||
assert!(!t.is_null());
|
||||
let b2 = unsafe { oaknode_block_clip_create() };
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_prepend_block(t.clone(), b.clone()) },
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_prepend_block(t.clone(), b2.clone()) },
|
||||
0
|
||||
);
|
||||
|
||||
// b2 is now the front block: it owns the track, has no previous, and b1
|
||||
// follows it.
|
||||
assert!(!util::block_track(b2.clone()).is_null());
|
||||
assert!(util::block_previous(b2.clone()).is_null());
|
||||
assert!(!util::block_next(b2.clone()).is_null());
|
||||
// b1 is the tail: it has a previous (b2) and no next.
|
||||
assert!(util::block_next(b.clone()).is_null());
|
||||
assert!(!util::block_previous(b.clone()).is_null());
|
||||
assert!(!util::block_track(b.clone()).is_null());
|
||||
// Track length sums the block lengths (both default 0/1).
|
||||
assert_eq!(util::track_length(t), Rational::new(0, 1));
|
||||
}
|
||||
|
||||
/// The node bridge mutators (`block_set_length_and_media_out` /
|
||||
/// `_media_in`) are the single path through which resize commands change
|
||||
/// block geometry; each keeps the non-fixed edge fixed.
|
||||
#[cfg(feature = "test-stubs")]
|
||||
#[test]
|
||||
fn node_bridge_resize_mutators_wire() {
|
||||
use oaktimeline::bridge::node::{oaknode_block_clip_create, oaknode_clip_get_media_in};
|
||||
|
||||
fn media_in(b: &CHandle) -> Rational {
|
||||
let mut n = 0;
|
||||
let mut d = 0;
|
||||
let _ = unsafe { oaknode_clip_get_media_in(b.clone(), &mut n, &mut d) };
|
||||
Rational::new(n as i64, d as i64)
|
||||
}
|
||||
|
||||
let b = unsafe { oaknode_block_clip_create() };
|
||||
// Default media-in and out are both 0/1.
|
||||
assert_eq!(media_in(&b), Rational::new(0, 1));
|
||||
|
||||
// media_out variant: growing the length moves the out point, media-in
|
||||
// stays fixed.
|
||||
util::block_set_length_and_media_out(b.clone(), Rational::new(10, 1));
|
||||
assert_eq!(util::block_length(b.clone()), Rational::new(10, 1));
|
||||
assert_eq!(util::block_out(b.clone()), Rational::new(10, 1));
|
||||
assert_eq!(media_in(&b), Rational::new(0, 1));
|
||||
|
||||
// media_in variant: shrinking the length keeps the out point fixed and
|
||||
// pulls media-in up.
|
||||
util::block_set_length_and_media_in(b.clone(), Rational::new(4, 1));
|
||||
assert_eq!(util::block_length(b.clone()), Rational::new(4, 1));
|
||||
assert_eq!(util::block_out(b.clone()), Rational::new(10, 1));
|
||||
assert_eq!(media_in(&b), Rational::new(6, 1));
|
||||
}
|
||||
|
||||
/// Rational ↔ num/den conversion crosses the C ABI as an `int` pair via
|
||||
/// `timelineutil::rat_nd` (`util::rat_nd`) — not through `bridge::common`,
|
||||
/// which only carries XML + config. We pin the reduction semantics here.
|
||||
#[test]
|
||||
fn common_bridge_rational_conversion() {
|
||||
let r = Rational::new(30, 4); // reduces to 15/2
|
||||
let mut n = 0;
|
||||
let mut d = 0;
|
||||
util::rat_nd(r, &mut n, &mut d);
|
||||
assert_eq!(n, 15);
|
||||
assert_eq!(d, 2);
|
||||
}
|
||||
|
||||
/// A zero denominator normalizes to the null/NaN sentinel `0/0`
|
||||
/// (`Rational::new(num, 0)`), so a num/den pair with `den == 0` is invalid
|
||||
/// rather than converted.
|
||||
#[test]
|
||||
fn common_bridge_rejects_zero_denominator() {
|
||||
let r = Rational::new(5, 0);
|
||||
assert!(r.is_null());
|
||||
assert!(r.is_nan());
|
||||
assert_eq!(r.denominator(), 0);
|
||||
// rat_nd maps the sentinel to a 0/0 int pair.
|
||||
let mut n = 1;
|
||||
let mut d = 1;
|
||||
util::rat_nd(r, &mut n, &mut d);
|
||||
assert_eq!((n, d), (0, 0));
|
||||
}
|
||||
|
||||
/// Rational ↔ display-string uses `oakcore_rs::Rational::from_string` /
|
||||
/// `to_display_string` (the C++ `fromString`/`toString` text format, e.g.
|
||||
/// "30000/1001"). `bridge::common` does not map strings; we pin the format
|
||||
/// the project files rely on.
|
||||
#[test]
|
||||
fn common_bridge_rational_string_round_trip() {
|
||||
let s = "30000/1001";
|
||||
let r = Rational::from_string(s);
|
||||
assert_eq!(r, Rational::new(30000, 1001));
|
||||
assert_eq!(r.to_display_string(), s);
|
||||
// The null sentinel round-trips as "0/0".
|
||||
assert_eq!(Rational::NULL.to_display_string(), "0/0");
|
||||
assert!(Rational::from_string("0/0").is_null());
|
||||
}
|
||||
|
||||
/// The XML reader bridge declares the load symbols the marker and work area
|
||||
/// save paths call; a null reader is an invalid argument and the reader is
|
||||
/// released by `free`.
|
||||
#[cfg(feature = "test-stubs")]
|
||||
#[test]
|
||||
fn xml_bridge_validate_handles() {
|
||||
use oaktimeline::bridge::common::{
|
||||
oakcommon_xml_reader_free, oakcommon_xml_reader_init, oakcommon_xml_reader_name,
|
||||
oakcommon_xml_reader_read_element_text, oakcommon_xml_reader_read_next_start_element,
|
||||
};
|
||||
|
||||
// A null reader is an invalid argument: read fails cleanly (0).
|
||||
let mut buf = [0i8; 64];
|
||||
let mut found = 0;
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_read_next_start_element(CHandle::null(), &mut found) },
|
||||
0
|
||||
);
|
||||
|
||||
// `init` over a document yields an empty reader in the mock; with no
|
||||
// elements it reports end-of-stream for every accessor.
|
||||
let mut reader =
|
||||
unsafe { oakcommon_xml_reader_init(b"<project/>\0".as_ptr() as *const std::ffi::c_char) };
|
||||
assert!(!reader.is_null());
|
||||
let mut found = 0;
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_read_next_start_element(reader.clone(), &mut found) },
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_name(reader.clone(), buf.as_mut_ptr(), 64) },
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_read_element_text(reader.clone(), buf.as_mut_ptr(), 64) },
|
||||
0
|
||||
);
|
||||
|
||||
// Free clears the handle; freeing the null handle is a no-op.
|
||||
unsafe { oakcommon_xml_reader_free(&mut reader) };
|
||||
assert!(reader.is_null());
|
||||
|
||||
// With mock elements (feature-gated), the reader iterates them and
|
||||
// exposes name / text / attributes through the same externs.
|
||||
#[cfg(feature = "test-stubs")]
|
||||
{
|
||||
use oaktimeline::bridge::teststubs::{xml_reader_handle, MockXmlNode};
|
||||
|
||||
let mut r = xml_reader_handle(vec![MockXmlNode {
|
||||
name: "marker".to_string(),
|
||||
text: "hello".to_string(),
|
||||
attrs: vec![("color".to_string(), "red".to_string())],
|
||||
}]);
|
||||
let mut found = 0;
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_read_next_start_element(r.clone(), &mut found) },
|
||||
1
|
||||
);
|
||||
assert_eq!(found, 1);
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_name(r.clone(), buf.as_mut_ptr(), 64) },
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { std::ffi::CStr::from_ptr(buf.as_ptr()) }
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"marker"
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_read_element_text(r.clone(), buf.as_mut_ptr(), 64) },
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { std::ffi::CStr::from_ptr(buf.as_ptr()) }
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"hello"
|
||||
);
|
||||
unsafe { oakcommon_xml_reader_free(&mut r) };
|
||||
assert!(r.is_null());
|
||||
}
|
||||
}
|
||||
|
||||
/// Build-graph invariant. The original scaffold claimed every symbol from
|
||||
/// `oakcore-rs` (`Rational`, `TimeRange`) is reached only through the C ABI
|
||||
/// bridge. That is not the case: the crate depends on `oakcore-rs` directly
|
||||
/// (`Cargo.toml [dependencies]`, used by `src/util.rs`), and the bridge does
|
||||
/// not re-export `Rational`. This is a link/build-topology property that
|
||||
/// cannot be asserted from a runtime unit test — it is enforced by
|
||||
/// `cargo build`/`cargo tree` — so it is excluded here. The body pins the
|
||||
/// actually-true invariant that `Rational` reduction is available in-crate.
|
||||
#[test]
|
||||
#[ignore = "build-topology property; asserted by cargo tree/build, not at runtime"]
|
||||
fn core_is_reached_only_through_bridge() {
|
||||
let r = Rational::new(2, 4);
|
||||
assert_eq!(r.numerator(), 1);
|
||||
assert_eq!(r.denominator(), 2);
|
||||
}
|
||||
@@ -1,703 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Direct coverage of the in-crate C ABI mocks (`src/bridge/teststubs.rs`)
|
||||
//! and the bridge externs: error paths (null / wrong-kind handles),
|
||||
//! no-op callbacks and the shared helpers. These exercise the same `extern
|
||||
//! "C"` symbols the crate's commands call, so they pin the bridge contract
|
||||
//! and cover the mock's defensive branches.
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use std::ffi::{c_char, CString};
|
||||
|
||||
use oaktimeline::bridge::common::{
|
||||
oakcommon_xml_reader_attribute_count, oakcommon_xml_reader_attribute_name,
|
||||
oakcommon_xml_reader_attribute_value, oakcommon_xml_reader_has_error,
|
||||
oakcommon_xml_reader_name, oakcommon_xml_reader_read_element_text,
|
||||
oakcommon_xml_writer_write_characters, oakcommon_xml_writer_write_end_document,
|
||||
};
|
||||
use oaktimeline::bridge::node::{
|
||||
oaknode_block_are_linked, oaknode_block_as_node, oaknode_block_clip_create,
|
||||
oaknode_block_from_node, oaknode_block_gap_create, oaknode_block_get_enabled,
|
||||
oaknode_block_get_in, oaknode_block_get_kind, oaknode_block_get_length, oaknode_block_get_next,
|
||||
oaknode_block_get_out, oaknode_block_get_previous, oaknode_block_get_track, oaknode_block_link,
|
||||
oaknode_block_set_enabled, oaknode_block_set_length_and_media_in,
|
||||
oaknode_block_set_length_and_media_out, oaknode_block_unlink,
|
||||
oaknode_clip_add_cache_passthrough_from, oaknode_clip_get_media_in, oaknode_clip_set_media_in,
|
||||
oaknode_command_create_remove_node, oaknode_node_connect, oaknode_node_copy_in_graph,
|
||||
oaknode_node_disconnect, oaknode_node_get_markers, oaknode_node_get_project,
|
||||
oaknode_node_get_work_area, oaknode_node_output_connection_count, oaknode_project_add_node,
|
||||
oaknode_project_remove_node, oaknode_sequence_as_node, oaknode_sequence_from_node,
|
||||
oaknode_sequence_get_all_track_at, oaknode_sequence_get_all_track_count,
|
||||
oaknode_sequence_get_track_list, oaknode_track_create, oaknode_track_get_block_at,
|
||||
oaknode_track_get_block_containing_time, oaknode_track_get_block_count,
|
||||
oaknode_track_get_length, oaknode_track_get_locked,
|
||||
oaknode_track_get_nearest_block_after_or_at, oaknode_track_get_nearest_block_before_or_at,
|
||||
oaknode_track_get_sequence, oaknode_track_insert_block_after, oaknode_track_prepend_block,
|
||||
oaknode_track_replace_block, oaknode_track_ripple_remove_block, oaknode_track_set_locked,
|
||||
oaknode_tracklist_array_append, oaknode_tracklist_array_remove_last,
|
||||
oaknode_tracklist_get_track_at, oaknode_tracklist_get_track_count, oaknode_tracklist_get_type,
|
||||
};
|
||||
use oaktimeline::bridge::teststubs::{xml_reader_handle, MockKind, MockNode, MockUndoStack};
|
||||
use oaktimeline::bridge::undo::{
|
||||
oakundo_command_init, oakundo_command_init_multi, oakundo_command_multi_add_child,
|
||||
oakundo_command_redo_now, oakundo_command_undo_now, oakundo_stack_push, OakUndoCommandVtable,
|
||||
};
|
||||
use oaktimeline::handle::{get, get_mut, make_owned, CHandle};
|
||||
|
||||
fn make(kind: MockKind) -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn addr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get_mut::<MockNode>(h).unwrap() as *mut MockNode }
|
||||
}
|
||||
|
||||
// ---- undo mocks --------------------------------------------------------
|
||||
|
||||
/// `oakundo_command_init` with a null vtable returns an empty handle.
|
||||
#[test]
|
||||
fn undo_init_null_vtable() {
|
||||
let h = unsafe { oakundo_command_init(std::ptr::null(), std::ptr::null_mut()) };
|
||||
assert!(h.is_null());
|
||||
}
|
||||
|
||||
/// `oakundo_command_init_multi` + `multi_add_child` box a no-op command.
|
||||
#[test]
|
||||
fn undo_multi_helpers() {
|
||||
let multi = unsafe { oakundo_command_init_multi() };
|
||||
assert!(!multi.is_null());
|
||||
let child = unsafe { oakundo_command_init_multi() };
|
||||
assert_eq!(
|
||||
unsafe { oakundo_command_multi_add_child(multi.clone(), child) },
|
||||
0
|
||||
);
|
||||
unsafe { oakundo_command_redo_now(multi.clone()) };
|
||||
unsafe { oakundo_command_undo_now(multi) };
|
||||
}
|
||||
|
||||
/// `oakundo_stack_push` records the push in the stack's mock.
|
||||
#[test]
|
||||
fn undo_stack_push_records() {
|
||||
let stack = make_owned(MockUndoStack { pushes: 0 });
|
||||
let cmd = unsafe { oakundo_command_init_multi() };
|
||||
let text = CString::new("trim").unwrap();
|
||||
assert_eq!(
|
||||
unsafe { oakundo_stack_push(stack.clone(), cmd, text.as_ptr()) },
|
||||
0
|
||||
);
|
||||
assert_eq!(unsafe { get::<MockUndoStack>(&stack) }.unwrap().pushes, 1);
|
||||
}
|
||||
|
||||
// ---- XML mocks ---------------------------------------------------------
|
||||
|
||||
/// Reader attribute/name accessors on missing state return error codes.
|
||||
#[test]
|
||||
fn xml_reader_accessors_missing() {
|
||||
let mut buf = [0 as c_char; 16];
|
||||
// No current element: every accessor returns 0.
|
||||
let mut r = xml_reader_handle(Vec::new());
|
||||
let mut found = 0;
|
||||
unsafe {
|
||||
oaktimeline::bridge::common::oakcommon_xml_reader_read_next_start_element(
|
||||
r.clone(),
|
||||
&mut found,
|
||||
)
|
||||
};
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_name(r.clone(), buf.as_mut_ptr(), 16) },
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_read_element_text(r.clone(), buf.as_mut_ptr(), 16) },
|
||||
0
|
||||
);
|
||||
|
||||
// Attribute accessors with a null reader and out-of-range index.
|
||||
let mut count = 99;
|
||||
unsafe { oakcommon_xml_reader_attribute_count(CHandle::null(), &mut count) };
|
||||
assert_eq!(count, 0);
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_attribute_name(CHandle::null(), 0, buf.as_mut_ptr(), 16) },
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_attribute_value(CHandle::null(), 0, buf.as_mut_ptr(), 16) },
|
||||
0
|
||||
);
|
||||
|
||||
// With an element but no attributes: count 0, name/value fail.
|
||||
let mut r2 = xml_reader_handle(vec![oaktimeline::bridge::teststubs::MockXmlNode {
|
||||
name: "m".to_string(),
|
||||
text: String::new(),
|
||||
attrs: Vec::new(),
|
||||
}]);
|
||||
let mut found = 0;
|
||||
unsafe {
|
||||
oaktimeline::bridge::common::oakcommon_xml_reader_read_next_start_element(
|
||||
r2.clone(),
|
||||
&mut found,
|
||||
)
|
||||
};
|
||||
unsafe { oakcommon_xml_reader_attribute_count(r2.clone(), &mut count) };
|
||||
assert_eq!(count, 0);
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_attribute_name(r2.clone(), 0, buf.as_mut_ptr(), 16) },
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_reader_attribute_value(r2.clone(), 0, buf.as_mut_ptr(), 16) },
|
||||
0
|
||||
);
|
||||
|
||||
// `has_error` writes the error flag; null reader → 0.
|
||||
let mut err = 99;
|
||||
unsafe { oakcommon_xml_reader_has_error(CHandle::null(), &mut err) };
|
||||
assert_eq!(err, 0);
|
||||
unsafe { oakcommon_xml_reader_has_error(r2.clone(), &mut err) };
|
||||
assert_eq!(err, 0);
|
||||
}
|
||||
|
||||
/// Writer characters / end-document accumulate or no-op.
|
||||
#[test]
|
||||
fn xml_writer_characters_and_end() {
|
||||
use oaktimeline::bridge::common::oakcommon_xml_writer_init;
|
||||
|
||||
let w = unsafe { oakcommon_xml_writer_init() };
|
||||
let text = CString::new("abc").unwrap();
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_writer_write_characters(w.clone(), text.as_ptr()) },
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oakcommon_xml_writer_write_end_document(w.clone()) },
|
||||
0
|
||||
);
|
||||
let buf = unsafe { get::<oaktimeline::bridge::teststubs::MockXmlWriter>(&w) }
|
||||
.unwrap()
|
||||
.buf
|
||||
.clone();
|
||||
assert_eq!(buf, "abc");
|
||||
}
|
||||
|
||||
// ---- node mocks: failure paths -----------------------------------------
|
||||
|
||||
/// Block geometry accessors reject null handles.
|
||||
#[test]
|
||||
fn block_geometry_null_handles() {
|
||||
let mut n = 0;
|
||||
let mut d = 0;
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_get_in(CHandle::null(), &mut n, &mut d) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_get_out(CHandle::null(), &mut n, &mut d) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_get_length(CHandle::null(), &mut n, &mut d) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_set_length_and_media_out(CHandle::null(), 1, 1) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_set_length_and_media_in(CHandle::null(), 1, 1) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_get_enabled(CHandle::null(), &mut n) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(unsafe { oaknode_block_set_enabled(CHandle::null(), 1) }, -1);
|
||||
|
||||
let mut out = CHandle::null();
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_get_previous(CHandle::null(), &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_get_next(CHandle::null(), &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_get_track(CHandle::null(), &mut out) },
|
||||
-1
|
||||
);
|
||||
}
|
||||
|
||||
/// `oaknode_block_link`/`unlink` reject invalid handles and link/unlink
|
||||
/// valid ones.
|
||||
#[test]
|
||||
fn block_link_unlink() {
|
||||
let a = make(MockKind::Clip);
|
||||
let b = make(MockKind::Clip);
|
||||
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_link(CHandle::null(), b.clone()) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_unlink(a.clone(), CHandle::null()) },
|
||||
-1
|
||||
);
|
||||
|
||||
assert_eq!(unsafe { oaknode_block_link(a.clone(), b.clone()) }, 0);
|
||||
let mut linked = 0;
|
||||
unsafe { oaknode_block_are_linked(a.clone(), b.clone(), &mut linked) };
|
||||
assert_eq!(linked, 1);
|
||||
|
||||
assert_eq!(unsafe { oaknode_block_unlink(a.clone(), b.clone()) }, 0);
|
||||
unsafe { oaknode_block_are_linked(a.clone(), b.clone(), &mut linked) };
|
||||
assert_eq!(linked, 0);
|
||||
|
||||
// are_linked with invalid handles → -1.
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_are_linked(CHandle::null(), b.clone(), &mut linked) },
|
||||
-1
|
||||
);
|
||||
}
|
||||
|
||||
/// Track accessors reject null / wrong-kind handles.
|
||||
#[test]
|
||||
fn track_accessors_invalid() {
|
||||
let clip = make(MockKind::Clip);
|
||||
let mut n = 0;
|
||||
let mut d = 0;
|
||||
let mut out = CHandle::null();
|
||||
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_length(CHandle::null(), &mut n, &mut d) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_sequence(CHandle::null(), &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_prepend_block(CHandle::null(), clip.clone()) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_ripple_remove_block(CHandle::null(), clip.clone()) },
|
||||
-1
|
||||
);
|
||||
|
||||
let mut locked = 0;
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_locked(CHandle::null(), &mut locked) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_locked(clip.clone(), &mut locked) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(unsafe { oaknode_track_set_locked(CHandle::null(), 1) }, -1);
|
||||
assert_eq!(unsafe { oaknode_track_set_locked(clip.clone(), 1) }, -1);
|
||||
|
||||
let mut count = 0;
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_block_count(CHandle::null(), &mut count) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_block_count(clip.clone(), &mut count) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_block_at(CHandle::null(), 0, &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_block_at(clip.clone(), 0, &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_block_at(make(MockKind::Track), 3, &mut out) },
|
||||
-1
|
||||
);
|
||||
|
||||
// containing-time queries.
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_block_containing_time(CHandle::null(), 1, 1, &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_block_containing_time(clip.clone(), 1, 1, &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_nearest_block_before_or_at(CHandle::null(), 1, 1, &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_nearest_block_before_or_at(clip.clone(), 1, 1, &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_nearest_block_after_or_at(CHandle::null(), 1, 1, &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_nearest_block_after_or_at(clip.clone(), 1, 1, &mut out) },
|
||||
-1
|
||||
);
|
||||
}
|
||||
|
||||
/// Track geometry success paths: insert-after on an empty track, replace,
|
||||
/// containing-time and nearest queries, block replacement.
|
||||
#[test]
|
||||
fn track_geometry_success() {
|
||||
let t = make(MockKind::Track);
|
||||
let a = make(MockKind::Clip);
|
||||
let b = make(MockKind::Clip);
|
||||
|
||||
// insert-after on an empty track appends (before not found).
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_insert_block_after(t.clone(), a.clone(), b.clone()) },
|
||||
0
|
||||
);
|
||||
|
||||
// Prepend b, then a.
|
||||
unsafe { oaknode_track_prepend_block(t.clone(), b.clone()) };
|
||||
unsafe { oaknode_track_prepend_block(t.clone(), a.clone()) };
|
||||
|
||||
// Block containing time 5: none (no geometry set) → -1 with null out.
|
||||
let mut out = CHandle::null();
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_block_containing_time(t.clone(), 5, 1, &mut out) },
|
||||
-1
|
||||
);
|
||||
|
||||
// Nearest before/after return the front block by in point.
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_nearest_block_before_or_at(t.clone(), 5, 1, &mut out) },
|
||||
0
|
||||
);
|
||||
assert!(!out.is_null());
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_get_nearest_block_after_or_at(t.clone(), 5, 1, &mut out) },
|
||||
0
|
||||
);
|
||||
|
||||
// Replace a with b.
|
||||
let c = make(MockKind::Clip);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_replace_block(t.clone(), a.clone(), c.clone()) },
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_replace_block(t.clone(), make(MockKind::Clip), c.clone()) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_replace_block(CHandle::null(), a.clone(), c.clone()) },
|
||||
-1
|
||||
);
|
||||
|
||||
// Ripple-remove a block not on the track → -1.
|
||||
let orphan = make(MockKind::Clip);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_track_ripple_remove_block(t.clone(), orphan) },
|
||||
-1
|
||||
);
|
||||
}
|
||||
|
||||
/// Track-list accessors reject invalid handles / kinds and return the
|
||||
/// per-type lists.
|
||||
#[test]
|
||||
fn tracklist_and_sequence_accessors() {
|
||||
let list = make(MockKind::TrackList);
|
||||
let clip = make(MockKind::Clip);
|
||||
let mut kind = 99;
|
||||
let mut count = 99;
|
||||
let mut out = CHandle::null();
|
||||
|
||||
assert_eq!(
|
||||
unsafe { oaknode_tracklist_get_type(CHandle::null(), &mut kind) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_tracklist_get_type(clip.clone(), &mut kind) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_tracklist_get_track_count(CHandle::null(), &mut count) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_tracklist_get_track_count(clip.clone(), &mut count) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_tracklist_get_track_at(CHandle::null(), 0, &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_tracklist_get_track_at(clip.clone(), 0, &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_tracklist_get_track_at(list.clone(), 0, &mut out) },
|
||||
-1
|
||||
);
|
||||
|
||||
// Append/remove-last are no-ops returning 0.
|
||||
assert_eq!(unsafe { oaknode_tracklist_array_append(list.clone()) }, 0);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_tracklist_array_remove_last(list.clone()) },
|
||||
0
|
||||
);
|
||||
|
||||
let seq = make(MockKind::Sequence);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_sequence_get_track_list(CHandle::null(), 0, &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_sequence_get_track_list(clip.clone(), 0, &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_sequence_get_all_track_count(CHandle::null(), &mut count) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_sequence_get_all_track_count(clip.clone(), &mut count) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_sequence_get_all_track_at(CHandle::null(), 0, &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_sequence_get_all_track_at(seq.clone(), 0, &mut out) },
|
||||
-1
|
||||
);
|
||||
|
||||
// sequence_get_track_list finds the matching per-type list.
|
||||
let video_list = make(MockKind::TrackList);
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&video_list).unwrap().track_type = 0;
|
||||
}
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&seq)
|
||||
.unwrap()
|
||||
.blocks
|
||||
.push(addr(&video_list));
|
||||
}
|
||||
assert_eq!(
|
||||
unsafe { oaknode_sequence_get_track_list(seq.clone(), 0, &mut out) },
|
||||
0
|
||||
);
|
||||
assert!(!out.is_null());
|
||||
}
|
||||
|
||||
/// Node-level accessors: project/markers/work-area/connect/copy.
|
||||
#[test]
|
||||
fn node_accessors() {
|
||||
let clip = make(MockKind::Clip);
|
||||
let mut out = CHandle::null();
|
||||
let mut count = 99;
|
||||
|
||||
assert_eq!(
|
||||
unsafe { oaknode_node_get_project(CHandle::null(), &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_node_output_connection_count(CHandle::null(), &mut count) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_node_get_markers(CHandle::null(), &mut out) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_node_get_work_area(CHandle::null(), &mut out) },
|
||||
-1
|
||||
);
|
||||
|
||||
// Null markers/work area → null borrowed handle.
|
||||
unsafe { oaknode_node_get_markers(clip.clone(), &mut out) };
|
||||
assert!(out.is_null());
|
||||
unsafe { oaknode_node_get_work_area(clip.clone(), &mut out) };
|
||||
assert!(out.is_null());
|
||||
|
||||
// Project add/remove reject null handles.
|
||||
assert_eq!(
|
||||
unsafe { oaknode_project_add_node(CHandle::null(), clip.clone()) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_project_remove_node(CHandle::null(), clip.clone()) },
|
||||
-1
|
||||
);
|
||||
|
||||
// Connect bumps the output connection count; disconnect no-ops.
|
||||
let a = make(MockKind::Clip);
|
||||
let b = make(MockKind::Clip);
|
||||
let input_id = CString::new("tex_in").unwrap();
|
||||
assert_eq!(
|
||||
unsafe { oaknode_node_connect(CHandle::null(), b.clone(), input_id.as_ptr()) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_node_connect(a.clone(), b.clone(), input_id.as_ptr()) },
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_node_output_connection_count(a.clone(), &mut count) },
|
||||
0
|
||||
);
|
||||
assert_eq!(count, 1);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_node_disconnect(b.clone(), input_id.as_ptr()) },
|
||||
0
|
||||
);
|
||||
|
||||
// copy_in_graph clones the node; a null node yields a null clone.
|
||||
assert_eq!(
|
||||
unsafe { oaknode_node_copy_in_graph(CHandle::null(), &mut out) }.is_null(),
|
||||
true
|
||||
);
|
||||
let copy = unsafe { oaknode_node_copy_in_graph(a.clone(), &mut out) };
|
||||
assert!(!copy.is_null());
|
||||
assert!(!out.is_null());
|
||||
}
|
||||
|
||||
/// Block-kind/from-node/clip helpers.
|
||||
#[test]
|
||||
fn block_kind_and_clip_helpers() {
|
||||
let clip = make(MockKind::Clip);
|
||||
let gap = make(MockKind::Gap);
|
||||
let track = make(MockKind::Track);
|
||||
let mut kind = 99;
|
||||
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_get_kind(CHandle::null(), &mut kind) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_get_kind(clip.clone(), &mut kind) },
|
||||
0
|
||||
);
|
||||
assert_eq!(kind, 1);
|
||||
assert_eq!(unsafe { oaknode_block_get_kind(gap.clone(), &mut kind) }, 0);
|
||||
assert_eq!(kind, 2);
|
||||
|
||||
// block_from_node: clip/gap views, null otherwise.
|
||||
assert!(!unsafe { oaknode_block_from_node(clip.clone()) }.is_null());
|
||||
assert!(unsafe { oaknode_block_from_node(track.clone()) }.is_null());
|
||||
assert!(unsafe { oaknode_block_from_node(CHandle::null()) }.is_null());
|
||||
|
||||
// clip media-in accessors reject non-clips and null handles.
|
||||
let mut n = 0;
|
||||
let mut d = 0;
|
||||
assert_eq!(
|
||||
unsafe { oaknode_clip_get_media_in(CHandle::null(), &mut n, &mut d) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_clip_get_media_in(gap.clone(), &mut n, &mut d) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_clip_set_media_in(CHandle::null(), 1, 1) },
|
||||
-1
|
||||
);
|
||||
assert_eq!(unsafe { oaknode_clip_set_media_in(gap.clone(), 1, 1) }, -1);
|
||||
assert_eq!(unsafe { oaknode_clip_set_media_in(clip.clone(), 5, 1) }, 0);
|
||||
assert_eq!(
|
||||
unsafe { oaknode_clip_get_media_in(clip.clone(), &mut n, &mut d) },
|
||||
0
|
||||
);
|
||||
assert_eq!((n, d), (5, 1));
|
||||
|
||||
// Passthrough copy is a no-op returning 0.
|
||||
assert_eq!(
|
||||
unsafe { oaknode_clip_add_cache_passthrough_from(clip.clone(), gap.clone()) },
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
/// `oaknode_block_as_node` / `oaknode_sequence_as_node` /
|
||||
/// `oaknode_sequence_from_node` borrow the node view.
|
||||
#[test]
|
||||
fn node_view_helpers() {
|
||||
let clip = make(MockKind::Clip);
|
||||
let seq = make(MockKind::Sequence);
|
||||
|
||||
assert!(!unsafe { oaknode_block_as_node(clip.clone()) }.is_null());
|
||||
assert!(!unsafe { oaknode_sequence_as_node(seq.clone()) }.is_null());
|
||||
assert!(!unsafe { oaknode_sequence_from_node(seq.clone()) }.is_null());
|
||||
|
||||
// Remove-command factory returns a command handle.
|
||||
let cmd = unsafe { oaknode_command_create_remove_node(clip.clone()) };
|
||||
assert!(!cmd.is_null());
|
||||
}
|
||||
|
||||
/// Shared mock helpers: add/sub with differing denominators (exercised via
|
||||
/// `block_set_length_and_media_*`), and null-pointer writes.
|
||||
#[test]
|
||||
fn shared_pair_arithmetic() {
|
||||
// media_in (0,3) + length (1,2): different denominators.
|
||||
let b = make(MockKind::Clip);
|
||||
unsafe { get_mut::<MockNode>(&b).unwrap().media_in = (0, 3) };
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_set_length_and_media_out(b.clone(), 1, 2) },
|
||||
0
|
||||
);
|
||||
let out = unsafe { get::<MockNode>(&b) }.unwrap().out;
|
||||
assert_eq!(out, (3, 6)); // (0*2 + 1*3, 3*2)
|
||||
|
||||
// media_in (1,3) with out (0,3): sub with equal denominators.
|
||||
let c = make(MockKind::Clip);
|
||||
unsafe { get_mut::<MockNode>(&c).unwrap().out = (0, 3) };
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_set_length_and_media_in(c.clone(), 1, 3) },
|
||||
0
|
||||
);
|
||||
assert_eq!(unsafe { get::<MockNode>(&c) }.unwrap().media_in, (-1, 3));
|
||||
|
||||
// write_cstr with a null buffer is a no-op; getters tolerate null out.
|
||||
let mut n = 0;
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_get_length(make(MockKind::Clip), &mut n, std::ptr::null_mut()) },
|
||||
0
|
||||
);
|
||||
|
||||
// Null out pointer to block_get_previous is a no-op returning 0.
|
||||
assert_eq!(
|
||||
unsafe { oaknode_block_get_previous(make(MockKind::Clip), std::ptr::null_mut()) },
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
/// `oaknode_track_get_length` accepts any node handle (the mock sums the
|
||||
/// blocks it owns; a clip owns none).
|
||||
#[test]
|
||||
fn track_length_wrong_kind() {
|
||||
let clip = make(MockKind::Clip);
|
||||
let mut n = 0;
|
||||
let mut d = 0;
|
||||
assert_eq!(unsafe { oaknode_track_get_length(clip, &mut n, &mut d) }, 0);
|
||||
assert_eq!((n, d), (0, 1));
|
||||
}
|
||||
@@ -1,640 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Coverage for the remaining reachable paths of `src/ffi.rs`: the marker
|
||||
//! command factories on valid/invalid lists, the work-area command
|
||||
//! factories, the load/save XML paths, the edit-family command factories
|
||||
//! and the string/`write_cstr` helpers. Run with `--features test-stubs`.
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use std::ffi::{c_char, CString};
|
||||
|
||||
use oaktimeline::bridge::common::{
|
||||
oakcommon_xml_writer_init, oakcommon_xml_writer_write_attribute,
|
||||
oakcommon_xml_writer_write_end_element, oakcommon_xml_writer_write_start_element,
|
||||
oakcommon_xml_writer_write_text_element,
|
||||
};
|
||||
use oaktimeline::bridge::teststubs::{xml_reader_handle, MockKind, MockNode, MockXmlNode};
|
||||
use oaktimeline::error::{
|
||||
OAKTIMELINE_E_FAILED, OAKTIMELINE_E_INVALID, OAKTIMELINE_E_NOT_FOUND, OAKTIMELINE_OK,
|
||||
};
|
||||
use oaktimeline::ffi;
|
||||
use oaktimeline::handle::{get, make_owned, CHandle};
|
||||
|
||||
// ---- marker exports ----------------------------------------------------
|
||||
|
||||
/// `oaktimeline_marker_add` rejects a null list handle.
|
||||
#[test]
|
||||
fn marker_add_null_list() {
|
||||
let name = CString::new("m").unwrap();
|
||||
let r = unsafe {
|
||||
ffi::marker::oaktimeline_marker_add(CHandle::null(), 0, 1, 1, 1, name.as_ptr(), 0)
|
||||
};
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
}
|
||||
|
||||
/// A null name is treated as the empty string.
|
||||
#[test]
|
||||
fn marker_add_null_name() {
|
||||
let h = unsafe { ffi::marker::oaktimeline_marker_list_create() };
|
||||
let r =
|
||||
unsafe { ffi::marker::oaktimeline_marker_add(h.clone(), 0, 1, 1, 1, std::ptr::null(), 0) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
let mut count = 0;
|
||||
unsafe { ffi::marker::oaktimeline_marker_count(h.clone(), &mut count) };
|
||||
assert_eq!(count, 1);
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_count` / `marker_at` reject null list handles.
|
||||
#[test]
|
||||
fn marker_count_and_at_null_list() {
|
||||
let mut count = 0;
|
||||
assert_eq!(
|
||||
unsafe { ffi::marker::oaktimeline_marker_count(CHandle::null(), &mut count) },
|
||||
OAKTIMELINE_E_INVALID
|
||||
);
|
||||
|
||||
let mut in_num = 0;
|
||||
let mut buf = [0 as c_char; 8];
|
||||
let r = unsafe {
|
||||
ffi::marker::oaktimeline_marker_at(
|
||||
CHandle::null(),
|
||||
0,
|
||||
&mut in_num,
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
buf.as_mut_ptr(),
|
||||
8,
|
||||
)
|
||||
};
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
}
|
||||
|
||||
/// A null name buffer or zero size is a no-op on the two-stage name write.
|
||||
#[test]
|
||||
fn marker_at_null_name_buffer() {
|
||||
let h = unsafe { ffi::marker::oaktimeline_marker_list_create() };
|
||||
let name = CString::new("mark").unwrap();
|
||||
unsafe { ffi::marker::oaktimeline_marker_add(h.clone(), 0, 1, 1, 1, name.as_ptr(), 1) };
|
||||
|
||||
// Null buffer: still reports the needed size.
|
||||
let needed = unsafe {
|
||||
ffi::marker::oaktimeline_marker_at(
|
||||
h.clone(),
|
||||
0,
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
8,
|
||||
)
|
||||
};
|
||||
assert_eq!(needed as usize, "mark".len() + 1);
|
||||
|
||||
// Zero-size buffer: no write happens (would otherwise overflow).
|
||||
let mut buf = [9 as c_char; 4];
|
||||
let needed = unsafe {
|
||||
ffi::marker::oaktimeline_marker_at(
|
||||
h.clone(),
|
||||
0,
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
buf.as_mut_ptr(),
|
||||
0,
|
||||
)
|
||||
};
|
||||
assert_eq!(needed as usize, "mark".len() + 1);
|
||||
assert_eq!(buf, [9 as c_char; 4]);
|
||||
}
|
||||
|
||||
/// The remove/set-time/set-props command factories on a non-empty list.
|
||||
#[test]
|
||||
fn marker_command_factories_valid_list() {
|
||||
let h = unsafe { ffi::marker::oaktimeline_marker_list_create() };
|
||||
let name = CString::new("m").unwrap();
|
||||
unsafe { ffi::marker::oaktimeline_marker_add(h.clone(), 0, 1, 1, 1, name.as_ptr(), 3) };
|
||||
|
||||
// In-bounds index: non-null command handles.
|
||||
assert!(!unsafe { ffi::marker::oaktimeline_marker_remove_at_command(h.clone(), 0) }.is_null());
|
||||
assert!(
|
||||
!unsafe { ffi::marker::oaktimeline_marker_set_time_command(h.clone(), 0, 2, 1, 3, 1) }
|
||||
.is_null()
|
||||
);
|
||||
|
||||
// set_props with color only, name only, and both.
|
||||
assert!(!unsafe {
|
||||
ffi::marker::oaktimeline_marker_set_props_command(h.clone(), 0, 4, std::ptr::null())
|
||||
}
|
||||
.is_null());
|
||||
assert!(!unsafe {
|
||||
ffi::marker::oaktimeline_marker_set_props_command(h.clone(), 0, -1, name.as_ptr())
|
||||
}
|
||||
.is_null());
|
||||
assert!(!unsafe {
|
||||
ffi::marker::oaktimeline_marker_set_props_command(h.clone(), 0, 4, name.as_ptr())
|
||||
}
|
||||
.is_null());
|
||||
|
||||
// Out-of-range index on the one-marker list: E_NOT_FOUND.
|
||||
assert!(unsafe { ffi::marker::oaktimeline_marker_remove_at_command(h.clone(), 7) }.is_null());
|
||||
assert!(
|
||||
unsafe { ffi::marker::oaktimeline_marker_set_time_command(h.clone(), 7, 2, 1, 3, 1) }
|
||||
.is_null()
|
||||
);
|
||||
assert!(unsafe {
|
||||
ffi::marker::oaktimeline_marker_set_props_command(h.clone(), 7, 1, std::ptr::null())
|
||||
}
|
||||
.is_null());
|
||||
|
||||
// color < 0 with a null name is invalid.
|
||||
assert!(unsafe {
|
||||
ffi::marker::oaktimeline_marker_set_props_command(h.clone(), 0, -1, std::ptr::null())
|
||||
}
|
||||
.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_list_load` parses `marker` elements with attributes;
|
||||
/// a null list or reader is rejected.
|
||||
#[test]
|
||||
fn marker_list_load_xml() {
|
||||
// Null list / reader → E_INVALID.
|
||||
assert_eq!(
|
||||
unsafe { ffi::marker::oaktimeline_marker_list_load(CHandle::null(), CHandle::null()) },
|
||||
OAKTIMELINE_E_INVALID
|
||||
);
|
||||
|
||||
let h = unsafe { ffi::marker::oaktimeline_marker_list_create() };
|
||||
let reader = xml_reader_handle(vec![MockXmlNode {
|
||||
name: "marker".to_string(),
|
||||
text: String::new(),
|
||||
attrs: vec![
|
||||
("name".to_string(), "one".to_string()),
|
||||
("in".to_string(), "30000/1001".to_string()),
|
||||
("out".to_string(), "60000/1001".to_string()),
|
||||
("color".to_string(), "2".to_string()),
|
||||
],
|
||||
}]);
|
||||
|
||||
let r = unsafe { ffi::marker::oaktimeline_marker_list_load(h.clone(), reader) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
let mut count = 0;
|
||||
unsafe { ffi::marker::oaktimeline_marker_count(h.clone(), &mut count) };
|
||||
assert_eq!(count, 1);
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_list_save` writes the marker XML; a null list or
|
||||
/// writer is rejected.
|
||||
#[test]
|
||||
fn marker_list_save_xml() {
|
||||
assert_eq!(
|
||||
unsafe { ffi::marker::oaktimeline_marker_list_save(CHandle::null(), CHandle::null()) },
|
||||
OAKTIMELINE_E_INVALID
|
||||
);
|
||||
|
||||
let h = unsafe { ffi::marker::oaktimeline_marker_list_create() };
|
||||
let name = CString::new("m").unwrap();
|
||||
unsafe { ffi::marker::oaktimeline_marker_add(h.clone(), 0, 1, 1, 1, name.as_ptr(), 3) };
|
||||
|
||||
let w = unsafe { oakcommon_xml_writer_init() };
|
||||
let r = unsafe { ffi::marker::oaktimeline_marker_list_save(h.clone(), w.clone()) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
let buf = unsafe { get::<oaktimeline::bridge::teststubs::MockXmlWriter>(&w) }
|
||||
.unwrap()
|
||||
.buf
|
||||
.clone();
|
||||
assert!(buf.contains("<marker>"));
|
||||
assert!(buf.contains("name=\"m\""));
|
||||
}
|
||||
|
||||
// ---- workarea exports --------------------------------------------------
|
||||
|
||||
/// `oaktimeline_workarea_of` returns a borrowed handle for a viewer node
|
||||
/// and rejects null owners.
|
||||
#[test]
|
||||
fn workarea_of_borrows() {
|
||||
let wa_h = make_owned(oaktimeline::workarea::TimelineWorkArea::new());
|
||||
let owner = make_owned(MockNode {
|
||||
kind: MockKind::Node,
|
||||
work_area: wa_h.clone(),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
let borrowed = unsafe { ffi::workarea::oaktimeline_workarea_of(owner.clone()) };
|
||||
assert!(!borrowed.is_null());
|
||||
assert!(unsafe { ffi::workarea::oaktimeline_workarea_of(CHandle::null()) }.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_get` rejects a null handle.
|
||||
#[test]
|
||||
fn workarea_get_null() {
|
||||
let r = unsafe {
|
||||
ffi::workarea::oaktimeline_workarea_get(
|
||||
CHandle::null(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_get` accepts NULL out params.
|
||||
#[test]
|
||||
fn workarea_get_null_out_params() {
|
||||
let w = unsafe { ffi::workarea::oaktimeline_workarea_create() };
|
||||
unsafe { ffi::workarea::oaktimeline_workarea_set_range(w.clone(), 10, 1, 20, 1) };
|
||||
let r = unsafe {
|
||||
ffi::workarea::oaktimeline_workarea_get(
|
||||
w.clone(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
}
|
||||
|
||||
/// The work-area command factories (set-range / set-enabled) validate and
|
||||
/// build command handles.
|
||||
#[test]
|
||||
fn workarea_command_factories() {
|
||||
let w = unsafe { ffi::workarea::oaktimeline_workarea_create() };
|
||||
unsafe { ffi::workarea::oaktimeline_workarea_set_range(w.clone(), 10, 1, 20, 1) };
|
||||
|
||||
assert!(!unsafe {
|
||||
ffi::workarea::oaktimeline_workarea_set_range_command(w.clone(), 1, 1, 5, 1, 10, 1, 20, 1)
|
||||
}
|
||||
.is_null());
|
||||
assert!(
|
||||
!unsafe { ffi::workarea::oaktimeline_workarea_set_enabled_command(w.clone(), 1) }.is_null()
|
||||
);
|
||||
|
||||
// Null work area → null command handles.
|
||||
assert!(unsafe {
|
||||
ffi::workarea::oaktimeline_workarea_set_range_command(
|
||||
CHandle::null(),
|
||||
1,
|
||||
1,
|
||||
5,
|
||||
1,
|
||||
10,
|
||||
1,
|
||||
20,
|
||||
1,
|
||||
)
|
||||
}
|
||||
.is_null());
|
||||
assert!(
|
||||
unsafe { ffi::workarea::oaktimeline_workarea_set_enabled_command(CHandle::null(), 1) }
|
||||
.is_null()
|
||||
);
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_reset` rejects null out params.
|
||||
#[test]
|
||||
fn workarea_reset_null_out_params() {
|
||||
let r = unsafe {
|
||||
ffi::workarea::oaktimeline_workarea_reset(
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_load` reads enabled/in/out elements (and skips
|
||||
/// unknown ones); null handles are rejected.
|
||||
#[test]
|
||||
fn workarea_load_xml() {
|
||||
assert_eq!(
|
||||
unsafe { ffi::workarea::oaktimeline_workarea_load(CHandle::null(), CHandle::null()) },
|
||||
OAKTIMELINE_E_INVALID
|
||||
);
|
||||
|
||||
let w = unsafe { ffi::workarea::oaktimeline_workarea_create() };
|
||||
let reader = xml_reader_handle(vec![
|
||||
MockXmlNode {
|
||||
name: "enabled".to_string(),
|
||||
text: "1".to_string(),
|
||||
attrs: Vec::new(),
|
||||
},
|
||||
MockXmlNode {
|
||||
name: "in".to_string(),
|
||||
text: "30000/1001".to_string(),
|
||||
attrs: Vec::new(),
|
||||
},
|
||||
MockXmlNode {
|
||||
name: "out".to_string(),
|
||||
text: "60000/1001".to_string(),
|
||||
attrs: Vec::new(),
|
||||
},
|
||||
MockXmlNode {
|
||||
name: "unknown".to_string(),
|
||||
text: "x".to_string(),
|
||||
attrs: Vec::new(),
|
||||
},
|
||||
]);
|
||||
let r = unsafe { ffi::workarea::oaktimeline_workarea_load(w.clone(), reader) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_save` writes the work-area XML; null handles are
|
||||
/// rejected.
|
||||
#[test]
|
||||
fn workarea_save_xml() {
|
||||
assert_eq!(
|
||||
unsafe { ffi::workarea::oaktimeline_workarea_save(CHandle::null(), CHandle::null()) },
|
||||
OAKTIMELINE_E_INVALID
|
||||
);
|
||||
|
||||
let w = unsafe { ffi::workarea::oaktimeline_workarea_create() };
|
||||
unsafe { ffi::workarea::oaktimeline_workarea_set_enabled(w.clone(), 1) };
|
||||
let writer = unsafe { oakcommon_xml_writer_init() };
|
||||
let r = unsafe { ffi::workarea::oaktimeline_workarea_save(w.clone(), writer.clone()) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
let buf = unsafe { get::<oaktimeline::bridge::teststubs::MockXmlWriter>(&writer) }
|
||||
.unwrap()
|
||||
.buf
|
||||
.clone();
|
||||
assert!(buf.contains("enabled"));
|
||||
}
|
||||
|
||||
// ---- edit exports ------------------------------------------------------
|
||||
|
||||
/// `oaktimeline_replace_block_with_gap_command` validates and builds.
|
||||
#[test]
|
||||
fn replace_block_with_gap_command() {
|
||||
let track = make_owned(MockNode {
|
||||
kind: MockKind::Track,
|
||||
..Default::default()
|
||||
});
|
||||
let block = make_owned(MockNode {
|
||||
kind: MockKind::Clip,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
assert!(!unsafe {
|
||||
ffi::edit::oaktimeline_replace_block_with_gap_command(track.clone(), block.clone())
|
||||
}
|
||||
.is_null());
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_replace_block_with_gap_command(CHandle::null(), block.clone())
|
||||
}
|
||||
.is_null());
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_replace_block_with_gap_command(track.clone(), CHandle::null())
|
||||
}
|
||||
.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_split_preserving_links_command` validates and builds.
|
||||
#[test]
|
||||
fn split_preserving_links_command() {
|
||||
let block = make_owned(MockNode {
|
||||
kind: MockKind::Clip,
|
||||
..Default::default()
|
||||
});
|
||||
let blocks = [block.clone()];
|
||||
let nums = [5i64];
|
||||
let dens = [1i64];
|
||||
|
||||
assert!(!unsafe {
|
||||
ffi::edit::oaktimeline_split_preserving_links_command(
|
||||
blocks.as_ptr(),
|
||||
1,
|
||||
nums.as_ptr(),
|
||||
dens.as_ptr(),
|
||||
1,
|
||||
)
|
||||
}
|
||||
.is_null());
|
||||
|
||||
// Invalid inputs → null handle.
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_split_preserving_links_command(
|
||||
std::ptr::null(),
|
||||
1,
|
||||
nums.as_ptr(),
|
||||
dens.as_ptr(),
|
||||
1,
|
||||
)
|
||||
}
|
||||
.is_null());
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_split_preserving_links_command(
|
||||
blocks.as_ptr(),
|
||||
0,
|
||||
nums.as_ptr(),
|
||||
dens.as_ptr(),
|
||||
1,
|
||||
)
|
||||
}
|
||||
.is_null());
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_split_preserving_links_command(
|
||||
blocks.as_ptr(),
|
||||
1,
|
||||
std::ptr::null(),
|
||||
dens.as_ptr(),
|
||||
1,
|
||||
)
|
||||
}
|
||||
.is_null());
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_split_preserving_links_command(
|
||||
blocks.as_ptr(),
|
||||
1,
|
||||
nums.as_ptr(),
|
||||
std::ptr::null(),
|
||||
1,
|
||||
)
|
||||
}
|
||||
.is_null());
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_split_preserving_links_command(
|
||||
blocks.as_ptr(),
|
||||
1,
|
||||
nums.as_ptr(),
|
||||
dens.as_ptr(),
|
||||
0,
|
||||
)
|
||||
}
|
||||
.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_ripple_delete_gaps_command` validates and builds.
|
||||
#[test]
|
||||
fn ripple_delete_gaps_command() {
|
||||
let seq = make_owned(MockNode {
|
||||
kind: MockKind::Sequence,
|
||||
..Default::default()
|
||||
});
|
||||
let track = make_owned(MockNode {
|
||||
kind: MockKind::Track,
|
||||
..Default::default()
|
||||
});
|
||||
let in_nums = [0i64];
|
||||
let in_dens = [1i64];
|
||||
let out_nums = [5i64];
|
||||
let out_dens = [1i64];
|
||||
let tracks = [track.clone()];
|
||||
|
||||
assert!(!unsafe {
|
||||
ffi::edit::oaktimeline_ripple_delete_gaps_command(
|
||||
seq.clone(),
|
||||
in_nums.as_ptr(),
|
||||
in_dens.as_ptr(),
|
||||
out_nums.as_ptr(),
|
||||
out_dens.as_ptr(),
|
||||
tracks.as_ptr(),
|
||||
1,
|
||||
)
|
||||
}
|
||||
.is_null());
|
||||
|
||||
// Invalid inputs → null handle.
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_ripple_delete_gaps_command(
|
||||
CHandle::null(),
|
||||
in_nums.as_ptr(),
|
||||
in_dens.as_ptr(),
|
||||
out_nums.as_ptr(),
|
||||
out_dens.as_ptr(),
|
||||
tracks.as_ptr(),
|
||||
1,
|
||||
)
|
||||
}
|
||||
.is_null());
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_ripple_delete_gaps_command(
|
||||
seq.clone(),
|
||||
std::ptr::null(),
|
||||
in_dens.as_ptr(),
|
||||
out_nums.as_ptr(),
|
||||
out_dens.as_ptr(),
|
||||
tracks.as_ptr(),
|
||||
1,
|
||||
)
|
||||
}
|
||||
.is_null());
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_ripple_delete_gaps_command(
|
||||
seq.clone(),
|
||||
in_nums.as_ptr(),
|
||||
in_dens.as_ptr(),
|
||||
out_nums.as_ptr(),
|
||||
out_dens.as_ptr(),
|
||||
tracks.as_ptr(),
|
||||
0,
|
||||
)
|
||||
}
|
||||
.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_ripple_remove_area_command` and
|
||||
/// `oaktimeline_insert_gaps_command` validate and build.
|
||||
#[test]
|
||||
fn ripple_area_and_insert_gaps_commands() {
|
||||
let track = make_owned(MockNode {
|
||||
kind: MockKind::Track,
|
||||
..Default::default()
|
||||
});
|
||||
let list = make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
assert!(!unsafe {
|
||||
ffi::edit::oaktimeline_ripple_remove_area_command(track.clone(), 0, 1, 5, 1)
|
||||
}
|
||||
.is_null());
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_ripple_remove_area_command(CHandle::null(), 0, 1, 5, 1)
|
||||
}
|
||||
.is_null());
|
||||
|
||||
assert!(
|
||||
!unsafe { ffi::edit::oaktimeline_insert_gaps_command(list.clone(), 0, 1, 5, 1) }.is_null()
|
||||
);
|
||||
assert!(
|
||||
unsafe { ffi::edit::oaktimeline_insert_gaps_command(CHandle::null(), 0, 1, 5, 1) }
|
||||
.is_null()
|
||||
);
|
||||
}
|
||||
|
||||
/// The XML writer externs used by the save paths accumulate into the mock
|
||||
/// writer's buffer (direct bridge coverage).
|
||||
#[test]
|
||||
fn xml_writer_externs_accumulate() {
|
||||
let w = unsafe { oakcommon_xml_writer_init() };
|
||||
assert!(!w.is_null());
|
||||
|
||||
let start = CString::new("marker").unwrap();
|
||||
let key = CString::new("name").unwrap();
|
||||
let val = CString::new("m").unwrap();
|
||||
let text_name = CString::new("enabled").unwrap();
|
||||
let text_val = CString::new("1").unwrap();
|
||||
|
||||
unsafe { oakcommon_xml_writer_write_start_element(w.clone(), start.as_ptr()) };
|
||||
unsafe { oakcommon_xml_writer_write_attribute(w.clone(), key.as_ptr(), val.as_ptr()) };
|
||||
unsafe {
|
||||
oakcommon_xml_writer_write_text_element(w.clone(), text_name.as_ptr(), text_val.as_ptr())
|
||||
};
|
||||
unsafe { oakcommon_xml_writer_write_end_element(w.clone()) };
|
||||
|
||||
let buf = unsafe { get::<oaktimeline::bridge::teststubs::MockXmlWriter>(&w) }
|
||||
.unwrap()
|
||||
.buf
|
||||
.clone();
|
||||
assert!(buf.contains("<marker>"));
|
||||
assert!(buf.contains(" name=\"m\""));
|
||||
assert!(buf.contains("<enabled>1</enabled>"));
|
||||
assert!(buf.contains("</>"));
|
||||
}
|
||||
|
||||
/// Sanity: the FFI entry points never panic on garbage-ish but valid-shaped
|
||||
/// inputs (guard behaviour).
|
||||
#[test]
|
||||
fn ffi_guards_return_codes() {
|
||||
// A null list to marker_count maps to E_INVALID, not a panic.
|
||||
let mut count = 0;
|
||||
assert_eq!(
|
||||
unsafe { ffi::marker::oaktimeline_marker_count(CHandle::null(), &mut count) },
|
||||
OAKTIMELINE_E_INVALID
|
||||
);
|
||||
// The failure constant is negative and distinct from OK.
|
||||
assert_ne!(OAKTIMELINE_E_FAILED, OAKTIMELINE_OK);
|
||||
assert_ne!(OAKTIMELINE_E_INVALID, OAKTIMELINE_E_NOT_FOUND);
|
||||
}
|
||||
|
||||
/// Silence unused warnings for helpers imported for the save tests.
|
||||
#[allow(dead_code)]
|
||||
fn _uses_writer_mut() -> *mut oaktimeline::bridge::teststubs::MockXmlWriter {
|
||||
std::ptr::null_mut()
|
||||
}
|
||||
@@ -1,212 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Coverage for the remaining reachable paths of `src/undogeneral.rs`
|
||||
//! (timelineundogeneral.h): the default-transition `prepare` neighbour
|
||||
//! classification (null previous, dual out transition) and the
|
||||
//! `TimelineAddTrackCommand` factories, plus the audio track-list variant.
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use oakcore_rs::Rational;
|
||||
|
||||
use oaktimeline::bridge::node::{
|
||||
oaknode_block_clip_create, oaknode_block_gap_create, oaknode_track_create,
|
||||
oaknode_track_get_block_at, oaknode_track_get_block_count, oaknode_track_prepend_block,
|
||||
oaknode_tracklist_get_type,
|
||||
};
|
||||
use oaktimeline::bridge::teststubs::{MockKind, MockNode};
|
||||
use oaktimeline::handle::{get, get_mut, make_owned, CHandle};
|
||||
use oaktimeline::undocommon::Command;
|
||||
use oaktimeline::undogeneral::{TimelineAddDefaultTransitionCommand, TimelineAddTrackCommand};
|
||||
|
||||
// ---- helpers -----------------------------------------------------------
|
||||
|
||||
fn make_track() -> CHandle {
|
||||
unsafe { oaknode_track_create(0) }
|
||||
}
|
||||
|
||||
fn addr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get_mut::<MockNode>(h).unwrap() as *mut MockNode }
|
||||
}
|
||||
|
||||
fn count(track: &CHandle) -> i32 {
|
||||
let mut c = 0;
|
||||
unsafe { oaknode_track_get_block_count(track.clone(), &mut c) };
|
||||
c
|
||||
}
|
||||
|
||||
fn at(track: &CHandle, idx: i32) -> CHandle {
|
||||
let mut o = CHandle::null();
|
||||
unsafe { oaknode_track_get_block_at(track.clone(), idx, &mut o) };
|
||||
o
|
||||
}
|
||||
|
||||
fn mk_clip() -> CHandle {
|
||||
unsafe { oaknode_block_clip_create() }
|
||||
}
|
||||
|
||||
fn mk_gap() -> CHandle {
|
||||
unsafe { oaknode_block_gap_create() }
|
||||
}
|
||||
|
||||
fn set_times(h: &CHandle, in_: (i32, i32), out: (i32, i32), len: (i32, i32), mi: (i32, i32)) {
|
||||
let b = unsafe { get_mut::<MockNode>(h).unwrap() };
|
||||
b.in_ = in_;
|
||||
b.out = out;
|
||||
b.length = len;
|
||||
b.media_in = mi;
|
||||
}
|
||||
|
||||
fn prepend(
|
||||
t: &CHandle,
|
||||
b: &CHandle,
|
||||
in_: (i32, i32),
|
||||
out: (i32, i32),
|
||||
len: (i32, i32),
|
||||
mi: (i32, i32),
|
||||
) {
|
||||
unsafe { oaknode_track_prepend_block(t.clone(), b.clone()) };
|
||||
set_times(b, in_, out, len, mi);
|
||||
}
|
||||
|
||||
fn kind_of(h: &CHandle) -> MockKind {
|
||||
unsafe { get::<MockNode>(h).unwrap().kind }
|
||||
}
|
||||
|
||||
fn make_list(track_type: i32) -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
track_type,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn make_sequence() -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::Sequence,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn seq_add_list(seq: &CHandle, list: &CHandle) {
|
||||
unsafe {
|
||||
get_mut::<MockNode>(seq).unwrap().blocks.push(addr(list));
|
||||
}
|
||||
}
|
||||
|
||||
// ---- TimelineAddDefaultTransitionCommand -------------------------------
|
||||
|
||||
/// `prepare` on adjacent selected clips: the first clip has a null
|
||||
/// previous (in transition), and the out side sees the selected next clip
|
||||
/// (dual transition).
|
||||
#[test]
|
||||
fn default_transition_prepare_neighbours() {
|
||||
let t = make_track();
|
||||
let c2 = mk_clip();
|
||||
prepend(&t, &c2, (10, 1), (20, 1), (10, 1), (10, 1));
|
||||
let c1 = mk_clip();
|
||||
prepend(&t, &c1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
// Track order: [c1, c2].
|
||||
|
||||
let mut cmd =
|
||||
TimelineAddDefaultTransitionCommand::new(vec![c1.clone(), c2.clone()], Rational::new(1, 1));
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(at(&t, 0).ctx as usize, addr(&c1) as usize);
|
||||
}
|
||||
|
||||
/// `prepare` with a gap before/after a single selected clip creates in and
|
||||
/// out transitions.
|
||||
#[test]
|
||||
fn default_transition_prepare_gap_neighbours() {
|
||||
let t = make_track();
|
||||
let g2 = mk_gap();
|
||||
prepend(&t, &g2, (10, 1), (13, 1), (3, 1), (10, 1));
|
||||
let c1 = mk_clip();
|
||||
prepend(&t, &c1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let g0 = mk_gap();
|
||||
prepend(&t, &g0, (0, 1), (0, 1), (0, 1), (0, 1));
|
||||
// Track order: [g0, c1, g2].
|
||||
|
||||
let mut cmd = TimelineAddDefaultTransitionCommand::new(vec![c1.clone()], Rational::new(1, 1));
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 3);
|
||||
}
|
||||
|
||||
/// Boxing the default-transition command into a handle works and keeps
|
||||
/// the command alive across redo/undo.
|
||||
#[test]
|
||||
fn default_transition_boxes_to_chandle() {
|
||||
let t = make_track();
|
||||
let c1 = mk_clip();
|
||||
prepend(&t, &c1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let cmd = TimelineAddDefaultTransitionCommand::new(vec![c1.clone()], Rational::new(1, 1));
|
||||
let h = cmd.to_command();
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
// ---- TimelineAddTrackCommand factories ---------------------------------
|
||||
|
||||
/// `run_immediately` and `run_immediately_with_automerge` construct, redo
|
||||
/// and hand back the created track in one step.
|
||||
#[test]
|
||||
fn add_track_run_immediately() {
|
||||
let list = make_list(0);
|
||||
|
||||
let t = TimelineAddTrackCommand::run_immediately(list.clone());
|
||||
assert!(!t.is_null());
|
||||
assert!(matches!(kind_of(&t), MockKind::Track));
|
||||
|
||||
let t2 = TimelineAddTrackCommand::run_immediately_with_automerge(list.clone(), true);
|
||||
assert!(!t2.is_null());
|
||||
}
|
||||
|
||||
/// An audio track list produces the samples input id and an audio track.
|
||||
#[test]
|
||||
fn add_track_audio_list() {
|
||||
let list = make_list(1);
|
||||
let mut cmd = TimelineAddTrackCommand::new(list.clone());
|
||||
cmd.redo();
|
||||
let t = cmd.track();
|
||||
assert!(!t.is_null());
|
||||
let mut kind = 0;
|
||||
unsafe { oaknode_tracklist_get_type(list.clone(), &mut kind) };
|
||||
assert_eq!(kind, 1);
|
||||
cmd.undo();
|
||||
|
||||
// A none-type list uses the empty input id.
|
||||
let none = make_list(-1);
|
||||
let mut cmd2 = TimelineAddTrackCommand::new(none.clone());
|
||||
cmd2.redo();
|
||||
cmd2.undo();
|
||||
}
|
||||
|
||||
/// `TimelineAddTrackCommand` trait dispatch.
|
||||
#[test]
|
||||
fn add_track_trait_dispatch() {
|
||||
let list = make_list(0);
|
||||
let mut cmd = TimelineAddTrackCommand::new(list.clone());
|
||||
Command::redo(&mut cmd);
|
||||
assert!(!cmd.track().is_null());
|
||||
Command::undo(&mut cmd);
|
||||
}
|
||||
@@ -1,649 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Coverage for `src/undopointer.rs` (timelineundopointer.h): the
|
||||
//! `BlockTrimCommand` compensate-adjacent paths (create gap, remove
|
||||
//! adjacent, resize adjacent, no-op), `TrackSlideCommand` (create in/out
|
||||
//! gap, remove adjacent, resize) and `TrackPlaceBlockCommand` (append,
|
||||
//! gap-past-end, add-tracks, ripple area). These tests drive the mock
|
||||
//! node graph through the `bridge::node` externs only.
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use oakcore_rs::{Rational, TimeRange};
|
||||
|
||||
use oaktimeline::bridge::node::{
|
||||
oaknode_block_clip_create, oaknode_block_gap_create, oaknode_track_create,
|
||||
oaknode_track_get_block_at, oaknode_track_get_block_count, oaknode_track_prepend_block,
|
||||
};
|
||||
use oaktimeline::bridge::teststubs::{MockKind, MockNode};
|
||||
use oaktimeline::common::MovementMode;
|
||||
use oaktimeline::handle::{get, get_mut, make_owned, CHandle};
|
||||
use oaktimeline::undocommon::Command;
|
||||
use oaktimeline::undopointer::{BlockTrimCommand, TrackPlaceBlockCommand, TrackSlideCommand};
|
||||
|
||||
// ---- helpers (mirror the other test binaries' local helpers) ----------
|
||||
|
||||
fn make_track() -> CHandle {
|
||||
unsafe { oaknode_track_create(0) }
|
||||
}
|
||||
|
||||
fn addr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get_mut::<MockNode>(h).unwrap() as *mut MockNode }
|
||||
}
|
||||
|
||||
fn count(track: &CHandle) -> i32 {
|
||||
let mut c = 0;
|
||||
unsafe { oaknode_track_get_block_count(track.clone(), &mut c) };
|
||||
c
|
||||
}
|
||||
|
||||
/// Borrowed block at `index` (for `.ctx` comparisons only).
|
||||
fn at(track: &CHandle, idx: i32) -> CHandle {
|
||||
let mut o = CHandle::null();
|
||||
unsafe { oaknode_track_get_block_at(track.clone(), idx, &mut o) };
|
||||
o
|
||||
}
|
||||
|
||||
fn mk_clip() -> CHandle {
|
||||
unsafe { oaknode_block_clip_create() }
|
||||
}
|
||||
|
||||
fn mk_gap() -> CHandle {
|
||||
unsafe { oaknode_block_gap_create() }
|
||||
}
|
||||
|
||||
/// Set a block's in/out/length/media-in points directly.
|
||||
fn set_times(h: &CHandle, in_: (i32, i32), out: (i32, i32), len: (i32, i32), mi: (i32, i32)) {
|
||||
let b = unsafe { get_mut::<MockNode>(h).unwrap() };
|
||||
b.in_ = in_;
|
||||
b.out = out;
|
||||
b.length = len;
|
||||
b.media_in = mi;
|
||||
}
|
||||
|
||||
fn blen(h: &CHandle) -> (i32, i32) {
|
||||
unsafe { get::<MockNode>(h).unwrap().length }
|
||||
}
|
||||
|
||||
fn media_in(h: &CHandle) -> (i32, i32) {
|
||||
unsafe { get::<MockNode>(h).unwrap().media_in }
|
||||
}
|
||||
|
||||
fn media_out(h: &CHandle) -> (i32, i32) {
|
||||
unsafe { get::<MockNode>(h).unwrap().out }
|
||||
}
|
||||
|
||||
/// Attach `b` to the front of `t`, then set its geometry.
|
||||
fn prepend(
|
||||
t: &CHandle,
|
||||
b: &CHandle,
|
||||
in_: (i32, i32),
|
||||
out: (i32, i32),
|
||||
len: (i32, i32),
|
||||
mi: (i32, i32),
|
||||
) {
|
||||
unsafe { oaknode_track_prepend_block(t.clone(), b.clone()) };
|
||||
set_times(b, in_, out, len, mi);
|
||||
}
|
||||
|
||||
fn kind_of(h: &CHandle) -> MockKind {
|
||||
unsafe { get::<MockNode>(h).unwrap().kind }
|
||||
}
|
||||
|
||||
fn make_list() -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
track_type: 0,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn list_add_track(list: &CHandle, t: &CHandle) {
|
||||
unsafe {
|
||||
get_mut::<MockNode>(list).unwrap().blocks.push(addr(t));
|
||||
}
|
||||
}
|
||||
|
||||
fn track_ptr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get::<MockNode>(h).unwrap().track }
|
||||
}
|
||||
|
||||
// ---- BlockTrimCommand --------------------------------------------------
|
||||
|
||||
/// Trimming to the same length marks the command as a no-op.
|
||||
#[test]
|
||||
fn trim_same_length_is_noop() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(10, 1),
|
||||
MovementMode::TrimOut,
|
||||
);
|
||||
cmd.prepare();
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// TrimOut at the end of a track (no adjacent): only the block itself is
|
||||
/// trimmed, `needs_adjacent_` is false.
|
||||
#[test]
|
||||
fn trim_out_last_block_no_adjacent() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(7, 1),
|
||||
MovementMode::TrimOut,
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&b), (7, 1));
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// TrimIn shortening with a clip previous and no roll edit: the command
|
||||
/// creates a compensation gap and inserts it before the block; undo
|
||||
/// removes it again.
|
||||
#[test]
|
||||
fn trim_in_creates_adjacent_gap() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (10, 1), (20, 1), (10, 1), (10, 1));
|
||||
let a = mk_clip();
|
||||
prepend(&t, &a, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
// Track order: [a, b].
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(at(&t, 0).ctx as usize, addr(&a) as usize);
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(7, 1),
|
||||
MovementMode::TrimIn,
|
||||
);
|
||||
cmd.prepare();
|
||||
assert_eq!(count(&t), 2);
|
||||
|
||||
cmd.redo();
|
||||
// A gap of length 3 was created between a and b.
|
||||
assert_eq!(count(&t), 3);
|
||||
assert_eq!(blen(&b), (7, 1));
|
||||
let mid = at(&t, 1);
|
||||
assert!(matches!(kind_of(&mid), MockKind::Gap));
|
||||
assert_eq!(blen(&mid), (3, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// TrimIn with no previous block: the gap is prepended to the track.
|
||||
#[test]
|
||||
fn trim_in_first_block_creates_gap_prepend() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(7, 1),
|
||||
MovementMode::TrimIn,
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert!(matches!(kind_of(&at(&t, 0)), MockKind::Gap));
|
||||
assert_eq!(blen(&at(&t, 0)), (3, 1));
|
||||
assert_eq!(blen(&b), (7, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// TrimOut shortening into a trailing gap: the gap is resized instead of a
|
||||
/// new one being created.
|
||||
#[test]
|
||||
fn trim_out_into_existing_gap_resizes() {
|
||||
let t = make_track();
|
||||
let g = mk_gap();
|
||||
prepend(&t, &g, (10, 1), (13, 1), (3, 1), (10, 1));
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
// Track order: [b, g].
|
||||
assert_eq!(count(&t), 2);
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(7, 1),
|
||||
MovementMode::TrimOut,
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
// Gap was extended to 3 + 3 = 6; no new block created.
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(blen(&g), (6, 1));
|
||||
assert_eq!(blen(&b), (7, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&g), (3, 1));
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// TrimOut growing the block by exactly the adjacent gap's length removes
|
||||
/// the adjacent block (`we_removed_adjacent_`).
|
||||
#[test]
|
||||
fn trim_grows_and_removes_adjacent() {
|
||||
let t = make_track();
|
||||
let g = mk_gap();
|
||||
prepend(&t, &g, (10, 1), (13, 1), (3, 1), (10, 1));
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
// Track order: [b, g].
|
||||
assert_eq!(count(&t), 2);
|
||||
|
||||
// Grow from 10 to 13: trim_diff = -3, adjacent gap length 3 is consumed.
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(13, 1),
|
||||
MovementMode::TrimOut,
|
||||
);
|
||||
cmd.prepare();
|
||||
assert_eq!(count(&t), 2);
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(blen(&b), (13, 1));
|
||||
assert!(track_ptr(&g).is_null());
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// TrimIn with a roll edit: the clip adjacent is resized instead of a gap
|
||||
/// being created.
|
||||
#[test]
|
||||
fn trim_roll_edit_resizes_clip_adjacent() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (10, 1), (20, 1), (10, 1), (10, 1));
|
||||
let a = mk_clip();
|
||||
prepend(&t, &a, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
// Track order: [a, b].
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(7, 1),
|
||||
MovementMode::TrimIn,
|
||||
);
|
||||
cmd.set_trim_is_a_roll_edit(true);
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
// No gap created; the previous clip grew from 10 to 13.
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(blen(&a), (13, 1));
|
||||
assert_eq!(blen(&b), (7, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&a), (10, 1));
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// The remove-from-graph toggle defaults on and can be disabled.
|
||||
#[test]
|
||||
fn trim_remove_zero_length_from_graph_toggle() {
|
||||
let t = make_track();
|
||||
let g = mk_gap();
|
||||
prepend(&t, &g, (10, 1), (13, 1), (3, 1), (10, 1));
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(13, 1),
|
||||
MovementMode::TrimOut,
|
||||
);
|
||||
cmd.set_remove_zero_length_from_graph(false);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 2);
|
||||
}
|
||||
|
||||
/// TrimIn growing the block by exactly the adjacent gap's length removes
|
||||
/// the adjacent block; undo re-inserts it before the block.
|
||||
#[test]
|
||||
fn trim_in_grows_and_removes_adjacent() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (10, 1), (20, 1), (10, 1), (10, 1));
|
||||
let g = mk_gap();
|
||||
prepend(&t, &g, (7, 1), (10, 1), (3, 1), (7, 1));
|
||||
// Track order: [g, b].
|
||||
assert_eq!(count(&t), 2);
|
||||
|
||||
// Grow from 10 to 13: the 3-length gap before b is consumed.
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(13, 1),
|
||||
MovementMode::TrimIn,
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert!(track_ptr(&g).is_null());
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(at(&t, 0).ctx as usize, addr(&g) as usize);
|
||||
}
|
||||
|
||||
/// `BlockTrimCommand` dispatches through the `Command` trait (the undo
|
||||
/// stack's vtable invokes it that way).
|
||||
#[test]
|
||||
fn trim_command_trait_dispatch() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(7, 1),
|
||||
MovementMode::TrimOut,
|
||||
);
|
||||
cmd.prepare();
|
||||
Command::redo(&mut cmd);
|
||||
assert_eq!(blen(&b), (7, 1));
|
||||
Command::undo(&mut cmd);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
|
||||
// Boxing into a command handle runs redo/undo through the vtable.
|
||||
let h = cmd.to_command();
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
// ---- TrackSlideCommand -------------------------------------------------
|
||||
|
||||
/// Slide with no in adjacent: a compensation gap is created before the
|
||||
/// block and removed on undo.
|
||||
#[test]
|
||||
fn slide_creates_in_adjacent_gap() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackSlideCommand::new(
|
||||
t.clone(),
|
||||
vec![b.clone()],
|
||||
CHandle::null(),
|
||||
CHandle::null(),
|
||||
Rational::new(2, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
// Gap(2) prepended, block unchanged.
|
||||
assert_eq!(count(&t), 2);
|
||||
assert!(matches!(kind_of(&at(&t, 0)), MockKind::Gap));
|
||||
assert_eq!(blen(&at(&t, 0)), (2, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
/// Slide with both an in and an out adjacent to create: two gaps are
|
||||
/// inserted on redo and removed on undo.
|
||||
#[test]
|
||||
fn slide_creates_in_and_out_adjacent_gaps() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (10, 1), (20, 1), (10, 1), (10, 1));
|
||||
let a = mk_clip();
|
||||
prepend(&t, &a, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
// Track order: [a, b]; slide `a`.
|
||||
|
||||
let mut cmd = TrackSlideCommand::new(
|
||||
t.clone(),
|
||||
vec![a.clone()],
|
||||
CHandle::null(),
|
||||
CHandle::null(),
|
||||
Rational::new(2, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
// In gap before `a`, out gap after `a` (before `b`).
|
||||
assert_eq!(count(&t), 4);
|
||||
assert!(matches!(kind_of(&at(&t, 0)), MockKind::Gap));
|
||||
assert!(matches!(kind_of(&at(&t, 1)), MockKind::Clip));
|
||||
assert!(matches!(kind_of(&at(&t, 2)), MockKind::Gap));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 2);
|
||||
}
|
||||
|
||||
/// Slide with a zero movement: the supplied in/out adjacent gaps are
|
||||
/// removed (their length equals the movement) and restored on undo.
|
||||
#[test]
|
||||
fn slide_removes_adjacents() {
|
||||
let t = make_track();
|
||||
let g_out = mk_gap();
|
||||
prepend(&t, &g_out, (10, 1), (10, 1), (0, 1), (10, 1));
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let g_in = mk_gap();
|
||||
prepend(&t, &g_in, (0, 1), (0, 1), (0, 1), (0, 1));
|
||||
// Track order: [g_in, b, g_out].
|
||||
|
||||
let mut cmd = TrackSlideCommand::new(
|
||||
t.clone(),
|
||||
vec![b.clone()],
|
||||
g_in.clone(),
|
||||
g_out.clone(),
|
||||
Rational::new(0, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
// Both zero-length adjacents removed; only the block remains.
|
||||
assert_eq!(count(&t), 1);
|
||||
assert!(track_ptr(&g_in).is_null());
|
||||
assert!(track_ptr(&g_out).is_null());
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 3);
|
||||
}
|
||||
|
||||
/// Slide that only resizes the adjacents (no creation, no removal).
|
||||
#[test]
|
||||
fn slide_resizes_adjacents() {
|
||||
let t = make_track();
|
||||
let g_out = mk_gap();
|
||||
prepend(&t, &g_out, (15, 1), (20, 1), (5, 1), (15, 1));
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (5, 1), (15, 1), (10, 1), (5, 1));
|
||||
let g_in = mk_gap();
|
||||
prepend(&t, &g_in, (0, 1), (5, 1), (5, 1), (0, 1));
|
||||
// Track order: [g_in, b, g_out].
|
||||
|
||||
let mut cmd = TrackSlideCommand::new(
|
||||
t.clone(),
|
||||
vec![b.clone()],
|
||||
g_in.clone(),
|
||||
g_out.clone(),
|
||||
Rational::new(2, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&g_in), (7, 1)); // 5 + 2
|
||||
assert_eq!(blen(&g_out), (3, 1)); // 5 - 2
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&g_in), (5, 1));
|
||||
assert_eq!(blen(&g_out), (5, 1));
|
||||
}
|
||||
|
||||
/// `TrackSlideCommand` trait dispatch and boxing.
|
||||
#[test]
|
||||
fn slide_command_trait_dispatch() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
prepend(&t, &b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackSlideCommand::new(
|
||||
t.clone(),
|
||||
vec![b.clone()],
|
||||
CHandle::null(),
|
||||
CHandle::null(),
|
||||
Rational::new(2, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
Command::redo(&mut cmd);
|
||||
assert_eq!(count(&t), 2);
|
||||
Command::undo(&mut cmd);
|
||||
assert_eq!(count(&t), 1);
|
||||
|
||||
let h = cmd.to_command();
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
// ---- TrackPlaceBlockCommand --------------------------------------------
|
||||
|
||||
/// Placing at the in point of an empty track appends the block.
|
||||
#[test]
|
||||
fn place_block_appends_at_track_start() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackPlaceBlockCommand::new(list.clone(), 0, b.clone(), Rational::new(0, 1));
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 0);
|
||||
}
|
||||
|
||||
/// Placing past the end of the track inserts a gap before the block; undo
|
||||
/// removes both.
|
||||
#[test]
|
||||
fn place_block_past_end_creates_gap() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackPlaceBlockCommand::new(list.clone(), 0, b.clone(), Rational::new(10, 1));
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert!(matches!(kind_of(&at(&t, 0)), MockKind::Gap));
|
||||
assert_eq!(blen(&at(&t, 0)), (10, 1));
|
||||
assert_eq!(blen(&at(&t, 1)), (10, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 0);
|
||||
}
|
||||
|
||||
/// Placing on a track index beyond the track count adds the missing tracks
|
||||
/// first (and removes them on undo).
|
||||
#[test]
|
||||
fn place_block_adds_missing_tracks() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
// Index 3 with one existing track: 3 add-track commands are created.
|
||||
let mut cmd = TrackPlaceBlockCommand::new(list.clone(), 3, b.clone(), Rational::new(5, 1));
|
||||
cmd.redo();
|
||||
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// Placing inside existing blocks ripple-removes the occupied area
|
||||
/// (splicing the first block) and inserts the block after it.
|
||||
#[test]
|
||||
fn place_block_ripple_removes_area() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let c1 = mk_clip();
|
||||
prepend(&t, &c1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (5, 1), (5, 1), (0, 1));
|
||||
|
||||
// Place a 5-length block at in 2: the area [2, 7] is cleared from c1.
|
||||
let mut cmd = TrackPlaceBlockCommand::new(list.clone(), 0, b.clone(), Rational::new(2, 1));
|
||||
cmd.redo();
|
||||
// c1 was split at 2, b inserted after the first half.
|
||||
assert!(count(&t) >= 3);
|
||||
|
||||
cmd.undo();
|
||||
// The split is joined back and b removed.
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(blen(&c1), (10, 1));
|
||||
}
|
||||
|
||||
/// `TrackPlaceBlockCommand` trait dispatch and boxing.
|
||||
#[test]
|
||||
fn place_block_command_trait_dispatch() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackPlaceBlockCommand::new(list.clone(), 0, b.clone(), Rational::new(0, 1));
|
||||
Command::redo(&mut cmd);
|
||||
assert_eq!(count(&t), 1);
|
||||
Command::undo(&mut cmd);
|
||||
assert_eq!(count(&t), 0);
|
||||
|
||||
let h = cmd.to_command();
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
/// `TimeRange` import used by placement ripple command construction.
|
||||
#[allow(dead_code)]
|
||||
fn _uses_time_range(_r: TimeRange) {}
|
||||
@@ -1,703 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Coverage for `src/undoripple.rs` (timelineundoripple.h): the
|
||||
//! per-track ripple-remove command (trim/splice/removal paths),
|
||||
//! the track-list and timeline ripples, the ripple tool (gap creation,
|
||||
//! gap removal, resize, trim-in/out) and gap deletion at regions.
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use oakcore_rs::{Rational, TimeRange};
|
||||
|
||||
use oaktimeline::bridge::node::{
|
||||
oaknode_block_clip_create, oaknode_block_gap_create, oaknode_track_create,
|
||||
oaknode_track_get_block_at, oaknode_track_get_block_count, oaknode_track_prepend_block,
|
||||
};
|
||||
use oaktimeline::bridge::teststubs::{MockKind, MockNode};
|
||||
use oaktimeline::common::MovementMode;
|
||||
use oaktimeline::handle::{get, get_mut, make_owned, CHandle};
|
||||
use oaktimeline::undocommon::Command;
|
||||
use oaktimeline::undoripple::{
|
||||
RippleInfo, TimelineRippleDeleteGapsAtRegionsCommand, TimelineRippleRemoveAreaCommand,
|
||||
TrackListRippleRemoveAreaCommand, TrackListRippleToolCommand, TrackRippleRemoveAreaCommand,
|
||||
};
|
||||
|
||||
// ---- helpers -----------------------------------------------------------
|
||||
|
||||
fn make_track() -> CHandle {
|
||||
unsafe { oaknode_track_create(0) }
|
||||
}
|
||||
|
||||
fn addr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get_mut::<MockNode>(h).unwrap() as *mut MockNode }
|
||||
}
|
||||
|
||||
fn count(track: &CHandle) -> i32 {
|
||||
let mut c = 0;
|
||||
unsafe { oaknode_track_get_block_count(track.clone(), &mut c) };
|
||||
c
|
||||
}
|
||||
|
||||
fn at(track: &CHandle, idx: i32) -> CHandle {
|
||||
let mut o = CHandle::null();
|
||||
unsafe { oaknode_track_get_block_at(track.clone(), idx, &mut o) };
|
||||
o
|
||||
}
|
||||
|
||||
fn mk_clip() -> CHandle {
|
||||
unsafe { oaknode_block_clip_create() }
|
||||
}
|
||||
|
||||
fn mk_gap() -> CHandle {
|
||||
unsafe { oaknode_block_gap_create() }
|
||||
}
|
||||
|
||||
fn set_times(h: &CHandle, in_: (i32, i32), out: (i32, i32), len: (i32, i32), mi: (i32, i32)) {
|
||||
let b = unsafe { get_mut::<MockNode>(h).unwrap() };
|
||||
b.in_ = in_;
|
||||
b.out = out;
|
||||
b.length = len;
|
||||
b.media_in = mi;
|
||||
}
|
||||
|
||||
fn prepend(
|
||||
t: &CHandle,
|
||||
b: &CHandle,
|
||||
in_: (i32, i32),
|
||||
out: (i32, i32),
|
||||
len: (i32, i32),
|
||||
mi: (i32, i32),
|
||||
) {
|
||||
unsafe { oaknode_track_prepend_block(t.clone(), b.clone()) };
|
||||
set_times(b, in_, out, len, mi);
|
||||
}
|
||||
|
||||
fn blen(h: &CHandle) -> (i32, i32) {
|
||||
unsafe { get::<MockNode>(h).unwrap().length }
|
||||
}
|
||||
|
||||
fn track_ptr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get::<MockNode>(h).unwrap().track }
|
||||
}
|
||||
|
||||
fn make_list(track_type: i32) -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
track_type,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn list_add_track(list: &CHandle, t: &CHandle) {
|
||||
unsafe {
|
||||
get_mut::<MockNode>(list).unwrap().blocks.push(addr(t));
|
||||
}
|
||||
}
|
||||
|
||||
fn make_sequence() -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::Sequence,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn seq_add_list(seq: &CHandle, list: &CHandle) {
|
||||
unsafe {
|
||||
get_mut::<MockNode>(seq).unwrap().blocks.push(addr(list));
|
||||
}
|
||||
}
|
||||
|
||||
// ---- TrackRippleRemoveAreaCommand --------------------------------------
|
||||
|
||||
/// No block before/at the range in point: prepare no-ops.
|
||||
#[test]
|
||||
fn ripple_area_no_block_at_in() {
|
||||
let t = make_track();
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(5, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 0);
|
||||
}
|
||||
|
||||
/// The first block starts exactly at the range in point: it is in-trimmed
|
||||
/// and `insert_previous` falls back to its (null) predecessor. A command
|
||||
/// without a splice reports a null spliced block.
|
||||
#[test]
|
||||
fn ripple_area_in_trims_first_block() {
|
||||
let t = make_track();
|
||||
let b1 = mk_clip();
|
||||
prepend(&t, &b1, (2, 1), (10, 1), (8, 1), (2, 1));
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(2, 1), Rational::new(8, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
assert!(cmd.get_insertion_index().is_null());
|
||||
assert!(cmd.get_spliced_block().is_null());
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&b1), (2, 1)); // 8 - (8-2)
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&b1), (8, 1));
|
||||
}
|
||||
|
||||
/// A clip straddling the whole range is split; the second half is trimmed
|
||||
/// and exposed through `get_spliced_block`.
|
||||
#[test]
|
||||
fn ripple_area_splits_clip() {
|
||||
let t = make_track();
|
||||
let b1 = mk_clip();
|
||||
prepend(&t, &b1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(2, 1), Rational::new(8, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
assert!(cmd.get_spliced_block().is_null());
|
||||
|
||||
cmd.redo();
|
||||
// Split at 2: [b1(2), split(2)]; the split half is the spliced block.
|
||||
assert_eq!(count(&t), 2);
|
||||
let split = cmd.get_spliced_block();
|
||||
assert!(!split.is_null());
|
||||
assert_eq!(blen(&b1), (2, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(blen(&b1), (10, 1));
|
||||
}
|
||||
|
||||
/// A gap straddling the range is not split (default): it is trimmed out
|
||||
/// instead.
|
||||
#[test]
|
||||
fn ripple_area_trims_gap_without_splitting() {
|
||||
let t = make_track();
|
||||
let g = mk_gap();
|
||||
prepend(&t, &g, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(2, 1), Rational::new(8, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(blen(&g), (4, 1)); // 10 - 6
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&g), (10, 1));
|
||||
}
|
||||
|
||||
/// A gap straddling the range MAY be split when allowed.
|
||||
#[test]
|
||||
fn ripple_area_splits_gap_when_allowed() {
|
||||
let t = make_track();
|
||||
let g = mk_gap();
|
||||
prepend(&t, &g, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(2, 1), Rational::new(8, 1)),
|
||||
);
|
||||
cmd.set_allow_splitting_gaps(true);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
/// The first block is out-trimmed but not in-trimmed: it is trimmed at
|
||||
/// its out edge and nothing follows.
|
||||
#[test]
|
||||
fn ripple_area_trims_out_first_block() {
|
||||
let t = make_track();
|
||||
let b1 = mk_clip();
|
||||
prepend(&t, &b1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(2, 1), Rational::new(20, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
assert!(!cmd.get_insertion_index().is_null());
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&b1), (2, 1)); // 10 - (10-2)
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&b1), (10, 1));
|
||||
}
|
||||
|
||||
/// A range covering whole blocks removes them and in-trims the first
|
||||
/// block that sticks out past the range. A leading gap keeps the first
|
||||
/// removal's predecessor non-null.
|
||||
#[test]
|
||||
fn ripple_area_removes_blocks_and_trims() {
|
||||
let t = make_track();
|
||||
let b3 = mk_clip();
|
||||
prepend(&t, &b3, (8, 1), (12, 1), (4, 1), (8, 1));
|
||||
let b2 = mk_clip();
|
||||
prepend(&t, &b2, (4, 1), (8, 1), (4, 1), (4, 1));
|
||||
let b1 = mk_clip();
|
||||
prepend(&t, &b1, (0, 1), (4, 1), (4, 1), (0, 1));
|
||||
let g = mk_gap();
|
||||
prepend(&t, &g, (-1, 1), (0, 1), (1, 1), (-1, 1));
|
||||
// Track order: [g, b1, b2, b3].
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(10, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(blen(&b3), (2, 1)); // 4 - (10-8)
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 4);
|
||||
assert_eq!(blen(&b1), (4, 1));
|
||||
assert_eq!(blen(&b2), (4, 1));
|
||||
assert_eq!(blen(&b3), (4, 1));
|
||||
}
|
||||
|
||||
/// A range ending exactly at a block's out point stops the removal loop
|
||||
/// there. A leading gap keeps every removed block's predecessor non-null
|
||||
/// (the ABI rejects a null `before`).
|
||||
#[test]
|
||||
fn ripple_area_stops_at_exact_out() {
|
||||
let t = make_track();
|
||||
let b2 = mk_clip();
|
||||
prepend(&t, &b2, (4, 1), (10, 1), (6, 1), (4, 1));
|
||||
let b1 = mk_clip();
|
||||
prepend(&t, &b1, (0, 1), (4, 1), (4, 1), (0, 1));
|
||||
let g = mk_gap();
|
||||
prepend(&t, &g, (-1, 1), (0, 1), (1, 1), (-1, 1));
|
||||
// Track order: [g, b1, b2].
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(10, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 3);
|
||||
}
|
||||
|
||||
/// Trait dispatch on the per-track ripple command.
|
||||
#[test]
|
||||
fn ripple_area_trait_dispatch() {
|
||||
let t = make_track();
|
||||
let b1 = mk_clip();
|
||||
prepend(&t, &b1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(2, 1), Rational::new(8, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
Command::redo(&mut cmd);
|
||||
assert_eq!(count(&t), 2);
|
||||
Command::undo(&mut cmd);
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
// ---- TrackListRippleRemoveAreaCommand ----------------------------------
|
||||
|
||||
/// The track-list ripple skips locked tracks and drives its children.
|
||||
#[test]
|
||||
fn ripple_list_skips_locked_tracks() {
|
||||
let list = make_list(0);
|
||||
let locked = make_track();
|
||||
unsafe { get_mut::<MockNode>(&locked).unwrap().locked = true };
|
||||
list_add_track(&list, &locked);
|
||||
let open = make_track();
|
||||
list_add_track(&list, &open);
|
||||
let b1 = mk_clip();
|
||||
prepend(&open, &b1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackListRippleRemoveAreaCommand::new(
|
||||
list.clone(),
|
||||
Rational::new(2, 1),
|
||||
Rational::new(8, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
|
||||
// The unlocked track's block was split by the child.
|
||||
cmd.redo();
|
||||
assert_eq!(count(&open), 2);
|
||||
cmd.undo();
|
||||
assert_eq!(count(&open), 1);
|
||||
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
assert_eq!(count(&open), 1);
|
||||
}
|
||||
|
||||
// ---- TimelineRippleRemoveAreaCommand -----------------------------------
|
||||
|
||||
/// The timeline ripple walks the sequence's per-type track lists.
|
||||
#[test]
|
||||
fn timeline_ripple_remove_area() {
|
||||
let seq = make_sequence();
|
||||
let list = make_list(0);
|
||||
seq_add_list(&seq, &list);
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let b1 = mk_clip();
|
||||
prepend(&t, &b1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd =
|
||||
TimelineRippleRemoveAreaCommand::new(seq.clone(), Rational::new(2, 1), Rational::new(8, 1));
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
// ---- TrackListRippleToolCommand ----------------------------------------
|
||||
|
||||
/// Empty info: redo/undo are no-ops. (`RippleInfo` has no public
|
||||
/// constructor, so the non-empty ripple-tool paths are exercised by the
|
||||
/// C++ gtest suite through the ABI.)
|
||||
#[test]
|
||||
fn ripple_tool_empty_info_noop() {
|
||||
let list = make_list(0);
|
||||
let mut cmd = TrackListRippleToolCommand::new(
|
||||
list.clone(),
|
||||
Vec::new(),
|
||||
Rational::new(2, 1),
|
||||
MovementMode::Move,
|
||||
);
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
}
|
||||
|
||||
// ---- TimelineRippleDeleteGapsAtRegionsCommand --------------------------
|
||||
|
||||
fn seq_with_video_track(blocks: Vec<CHandle>) -> (CHandle, CHandle) {
|
||||
let seq = make_sequence();
|
||||
let list = make_list(0);
|
||||
seq_add_list(&seq, &list);
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
for b in blocks {
|
||||
unsafe { oaknode_track_prepend_block(t.clone(), b.clone()) };
|
||||
}
|
||||
(seq, t)
|
||||
}
|
||||
|
||||
/// A single gap region shorter than the gap: the gap is resized.
|
||||
#[test]
|
||||
fn ripple_delete_gaps_resizes_single_gap() {
|
||||
let g1 = mk_gap();
|
||||
set_times(&g1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let (seq, t) = seq_with_video_track(vec![g1.clone()]);
|
||||
|
||||
let mut cmd = TimelineRippleDeleteGapsAtRegionsCommand::new(
|
||||
seq.clone(),
|
||||
vec![(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(5, 1)),
|
||||
)],
|
||||
);
|
||||
cmd.prepare();
|
||||
assert!(cmd.has_commands());
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&g1), (5, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&g1), (10, 1));
|
||||
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
assert_eq!(blen(&g1), (10, 1));
|
||||
}
|
||||
|
||||
/// A gap region on an empty track (no block before/at the in point) is
|
||||
/// skipped (`is_gap` on a null handle).
|
||||
#[test]
|
||||
fn ripple_delete_gaps_empty_track_region_skipped() {
|
||||
let seq = make_sequence();
|
||||
let list = make_list(0);
|
||||
seq_add_list(&seq, &list);
|
||||
let t1 = make_track();
|
||||
list_add_track(&list, &t1);
|
||||
let g1 = mk_gap();
|
||||
set_times(&g1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe { oaknode_track_prepend_block(t1.clone(), g1.clone()) };
|
||||
let t_empty = make_track();
|
||||
list_add_track(&list, &t_empty);
|
||||
|
||||
let mut cmd = TimelineRippleDeleteGapsAtRegionsCommand::new(
|
||||
seq.clone(),
|
||||
vec![
|
||||
(
|
||||
t_empty.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(5, 1)),
|
||||
),
|
||||
(
|
||||
t1.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(5, 1)),
|
||||
),
|
||||
],
|
||||
);
|
||||
cmd.prepare();
|
||||
assert!(cmd.has_commands());
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&g1), (5, 1));
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&g1), (10, 1));
|
||||
}
|
||||
|
||||
/// Another track whose first block at the earliest point is a clip: the
|
||||
/// following gap is found for synchronisation.
|
||||
#[test]
|
||||
fn ripple_delete_gaps_finds_next_gap_on_other_track() {
|
||||
let g1 = mk_gap();
|
||||
set_times(&g1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let (seq, t1) = seq_with_video_track(vec![g1.clone()]);
|
||||
|
||||
// Second track: [c(0-5), g2(5-15)].
|
||||
let list = make_list(0);
|
||||
seq_add_list(&seq, &list);
|
||||
let t2 = make_track();
|
||||
list_add_track(&list, &t2);
|
||||
let g2 = mk_gap();
|
||||
set_times(&g2, (5, 1), (15, 1), (10, 1), (5, 1));
|
||||
let c = mk_clip();
|
||||
set_times(&c, (0, 1), (5, 1), (5, 1), (0, 1));
|
||||
unsafe { oaknode_track_prepend_block(t2.clone(), g2.clone()) };
|
||||
unsafe { oaknode_track_prepend_block(t2.clone(), c.clone()) };
|
||||
|
||||
let mut cmd = TimelineRippleDeleteGapsAtRegionsCommand::new(
|
||||
seq.clone(),
|
||||
vec![(
|
||||
t1.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(5, 1)),
|
||||
)],
|
||||
);
|
||||
cmd.prepare();
|
||||
assert!(cmd.has_commands());
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&g1), (5, 1));
|
||||
assert_eq!(blen(&g2), (5, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&g1), (10, 1));
|
||||
assert_eq!(blen(&g2), (10, 1));
|
||||
}
|
||||
|
||||
/// A clip followed by another clip (no gap) zeroes the ripple length and
|
||||
/// produces no commands.
|
||||
#[test]
|
||||
fn ripple_delete_gaps_clip_no_gap_breaks() {
|
||||
let g1 = mk_gap();
|
||||
set_times(&g1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let (seq, t1) = seq_with_video_track(vec![g1.clone()]);
|
||||
|
||||
let list = make_list(0);
|
||||
seq_add_list(&seq, &list);
|
||||
let t2 = make_track();
|
||||
list_add_track(&list, &t2);
|
||||
let c2 = mk_clip();
|
||||
set_times(&c2, (5, 1), (15, 1), (10, 1), (5, 1));
|
||||
let c1 = mk_clip();
|
||||
set_times(&c1, (0, 1), (5, 1), (5, 1), (0, 1));
|
||||
unsafe { oaknode_track_prepend_block(t2.clone(), c2.clone()) };
|
||||
unsafe { oaknode_track_prepend_block(t2.clone(), c1.clone()) };
|
||||
|
||||
let mut cmd = TimelineRippleDeleteGapsAtRegionsCommand::new(
|
||||
seq.clone(),
|
||||
vec![(
|
||||
t1.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(5, 1)),
|
||||
)],
|
||||
);
|
||||
cmd.prepare();
|
||||
assert!(!cmd.has_commands());
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// A clip strictly after the earliest point whose predecessor is a gap:
|
||||
/// the gap is found via the previous block and, when its length equals
|
||||
/// the ripple length, removed outright.
|
||||
#[test]
|
||||
fn ripple_delete_gaps_finds_previous_gap_and_removes() {
|
||||
let g1 = mk_gap();
|
||||
set_times(&g1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let (seq, t1) = seq_with_video_track(vec![g1.clone()]);
|
||||
|
||||
let list = make_list(0);
|
||||
seq_add_list(&seq, &list);
|
||||
let t2 = make_track();
|
||||
list_add_track(&list, &t2);
|
||||
let c = mk_clip();
|
||||
set_times(&c, (3, 1), (5, 1), (2, 1), (3, 1));
|
||||
let g2 = mk_gap();
|
||||
set_times(&g2, (-2, 1), (3, 1), (5, 1), (-2, 1));
|
||||
let lead = mk_gap();
|
||||
set_times(&lead, (-5, 1), (-2, 1), (3, 1), (-5, 1));
|
||||
unsafe { oaknode_track_prepend_block(t2.clone(), c.clone()) };
|
||||
unsafe { oaknode_track_prepend_block(t2.clone(), g2.clone()) };
|
||||
unsafe { oaknode_track_prepend_block(t2.clone(), lead.clone()) };
|
||||
// Track order: [lead, g2, c].
|
||||
|
||||
let mut cmd = TimelineRippleDeleteGapsAtRegionsCommand::new(
|
||||
seq.clone(),
|
||||
vec![(
|
||||
t1.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(5, 1)),
|
||||
)],
|
||||
);
|
||||
cmd.prepare();
|
||||
assert!(cmd.has_commands());
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&g1), (5, 1));
|
||||
// g2 was removed outright (its length equals the ripple length).
|
||||
assert_eq!(count(&t2), 2);
|
||||
assert!(track_ptr(&g2).is_null());
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&g1), (10, 1));
|
||||
assert_eq!(count(&t2), 3);
|
||||
assert_eq!(blen(&g2), (5, 1));
|
||||
}
|
||||
|
||||
/// A clip strictly after the earliest point whose predecessor is not a
|
||||
/// gap zeroes the ripple length and produces no commands.
|
||||
#[test]
|
||||
fn ripple_delete_gaps_prev_not_gap_breaks() {
|
||||
let g1 = mk_gap();
|
||||
set_times(&g1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let (seq, t1) = seq_with_video_track(vec![g1.clone()]);
|
||||
|
||||
let list = make_list(0);
|
||||
seq_add_list(&seq, &list);
|
||||
let t2 = make_track();
|
||||
list_add_track(&list, &t2);
|
||||
let c = mk_clip();
|
||||
set_times(&c, (3, 1), (5, 1), (2, 1), (3, 1));
|
||||
unsafe { oaknode_track_prepend_block(t2.clone(), c.clone()) };
|
||||
|
||||
let mut cmd = TimelineRippleDeleteGapsAtRegionsCommand::new(
|
||||
seq.clone(),
|
||||
vec![(
|
||||
t1.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(5, 1)),
|
||||
)],
|
||||
);
|
||||
cmd.prepare();
|
||||
assert!(!cmd.has_commands());
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// A locked track is skipped when synchronising gaps.
|
||||
#[test]
|
||||
fn ripple_delete_gaps_skips_locked_tracks() {
|
||||
let g1 = mk_gap();
|
||||
set_times(&g1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let (seq, t1) = seq_with_video_track(vec![g1.clone()]);
|
||||
|
||||
let list = make_list(0);
|
||||
seq_add_list(&seq, &list);
|
||||
let t_locked = make_track();
|
||||
unsafe { get_mut::<MockNode>(&t_locked).unwrap().locked = true };
|
||||
list_add_track(&list, &t_locked);
|
||||
let g3 = mk_gap();
|
||||
set_times(&g3, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe { oaknode_track_prepend_block(t_locked.clone(), g3.clone()) };
|
||||
|
||||
let mut cmd = TimelineRippleDeleteGapsAtRegionsCommand::new(
|
||||
seq.clone(),
|
||||
vec![(
|
||||
t1.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(5, 1)),
|
||||
)],
|
||||
);
|
||||
cmd.prepare();
|
||||
assert!(cmd.has_commands());
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&g1), (5, 1));
|
||||
// The locked track's gap was untouched.
|
||||
assert_eq!(blen(&g3), (10, 1));
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// Two regions on the same track exercise the insertion-sort ordering.
|
||||
#[test]
|
||||
fn ripple_delete_gaps_sorts_regions_on_track() {
|
||||
let seq = make_sequence();
|
||||
let list = make_list(0);
|
||||
seq_add_list(&seq, &list);
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let gb = mk_gap();
|
||||
set_times(&gb, (5, 1), (8, 1), (3, 1), (5, 1));
|
||||
let ga = mk_gap();
|
||||
set_times(&ga, (0, 1), (3, 1), (3, 1), (0, 1));
|
||||
let lead = mk_gap();
|
||||
set_times(&lead, (-3, 1), (0, 1), (3, 1), (-3, 1));
|
||||
unsafe { oaknode_track_prepend_block(t.clone(), gb.clone()) };
|
||||
unsafe { oaknode_track_prepend_block(t.clone(), ga.clone()) };
|
||||
unsafe { oaknode_track_prepend_block(t.clone(), lead.clone()) };
|
||||
// Track order: [lead, ga, gb].
|
||||
|
||||
let mut cmd = TimelineRippleDeleteGapsAtRegionsCommand::new(
|
||||
seq.clone(),
|
||||
vec![
|
||||
(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(3, 1)),
|
||||
),
|
||||
(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(5, 1), Rational::new(8, 1)),
|
||||
),
|
||||
],
|
||||
);
|
||||
cmd.prepare();
|
||||
assert!(cmd.has_commands());
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 3);
|
||||
assert_eq!(blen(&ga), (3, 1));
|
||||
assert_eq!(blen(&gb), (3, 1));
|
||||
}
|
||||
@@ -0,0 +1,482 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Contract tests for the single-lib domain commands: the undo commands
|
||||
//! drive a real oaknode project graph through `oaktimeline::util::NodeRef`
|
||||
//! (the CHandle-based bridge signatures left with the deleted C ABI).
|
||||
//!
|
||||
//! Each test builds a project with a sequence/track-list/track, applies a
|
||||
//! command through `redo`, checks the graph state, and `undo`s back to the
|
||||
//! original state.
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use oakcore_rs::{Rational, TimeRange};
|
||||
use oaknode::block::{ClipBlockBehavior, GapBlockBehavior};
|
||||
use oaknode::project::Project;
|
||||
use oaknode::sequence::SequenceBehavior;
|
||||
use oaknode::track::{TrackBehavior, TrackListBehavior, TrackType};
|
||||
use oaktimeline::undocommon::Command;
|
||||
use oaktimeline::undogeneral::{
|
||||
BlockResizeCommand, TimelineAddTrackCommand, TimelineRemoveTrackCommand,
|
||||
TrackReplaceBlockWithGapCommand,
|
||||
};
|
||||
use oaktimeline::undopointer::TrackMoveBlockCommand;
|
||||
use oaktimeline::undoripple::TrackRippleRemoveAreaCommand;
|
||||
use oaktimeline::undosplit::BlockSplitCommand;
|
||||
use oaktimeline::util::{
|
||||
block_clip_create, block_gap_create, block_in, block_length, block_out, block_track,
|
||||
track_append_block, track_block_at, track_block_count, track_length, track_ripple_remove_block,
|
||||
tracklist_track_count, NodeRef,
|
||||
};
|
||||
|
||||
/// A project with one sequence owning one (video) track list.
|
||||
fn make_project() -> Arc<Mutex<Project>> {
|
||||
let project = Project::new();
|
||||
let (seq_id, list_id) = {
|
||||
let mut p = project.lock().unwrap();
|
||||
let (core, behavior) = SequenceBehavior::create();
|
||||
let seq_id = p.graph.add_node(core, behavior);
|
||||
let (core, behavior) = TrackListBehavior::create();
|
||||
let list_id = p.graph.add_node(core, behavior);
|
||||
if let Some(e) = p.graph.get_mut(seq_id) {
|
||||
if let Some(a) = e.behavior.as_any_mut() {
|
||||
if let Some(s) = a.downcast_mut::<SequenceBehavior>() {
|
||||
s.track_lists.push(list_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(e) = p.graph.get_mut(list_id) {
|
||||
if let Some(a) = e.behavior.as_any_mut() {
|
||||
if let Some(l) = a.downcast_mut::<TrackListBehavior>() {
|
||||
l.sequence = Some(seq_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
(seq_id, list_id)
|
||||
};
|
||||
let _ = (seq_id, list_id);
|
||||
project
|
||||
}
|
||||
|
||||
/// The sequence and its video track list of `project`.
|
||||
fn sequence_and_list(
|
||||
project: &Arc<Mutex<Project>>,
|
||||
) -> (NodeRef, NodeRef) {
|
||||
let p = project.lock().unwrap();
|
||||
let mut seq = None;
|
||||
let mut list = None;
|
||||
for id in p.graph.node_ids() {
|
||||
if let Some(e) = p.graph.get(id) {
|
||||
if e.behavior
|
||||
.as_any()
|
||||
.and_then(|a| a.downcast_ref::<SequenceBehavior>())
|
||||
.is_some()
|
||||
{
|
||||
seq = Some(NodeRef::new(project.clone(), id));
|
||||
} else if e
|
||||
.behavior
|
||||
.as_any()
|
||||
.and_then(|a| a.downcast_ref::<TrackListBehavior>())
|
||||
.is_some()
|
||||
{
|
||||
list = Some(NodeRef::new(project.clone(), id));
|
||||
}
|
||||
}
|
||||
}
|
||||
(seq.unwrap(), list.unwrap())
|
||||
}
|
||||
|
||||
/// Add a clip block spanning `[in, out)` to `track`.
|
||||
fn add_clip(track: &NodeRef, in_: Rational, out: Rational) -> NodeRef {
|
||||
let clip = block_clip_create(&track.project);
|
||||
{
|
||||
let mut p = track.project.lock().unwrap();
|
||||
if let Some(e) = p.graph.get_mut(clip.id) {
|
||||
if let Some(a) = e.behavior.as_any_mut() {
|
||||
if let Some(c) = a.downcast_mut::<ClipBlockBehavior>() {
|
||||
c.core.range = TimeRange::new(in_, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
track_append_block(track, &clip);
|
||||
clip
|
||||
}
|
||||
|
||||
/// Add a gap block spanning `[in, out)` to `track`.
|
||||
fn add_gap(track: &NodeRef, in_: Rational, out: Rational) -> NodeRef {
|
||||
let gap = block_gap_create(&track.project);
|
||||
{
|
||||
let mut p = track.project.lock().unwrap();
|
||||
if let Some(e) = p.graph.get_mut(gap.id) {
|
||||
if let Some(a) = e.behavior.as_any_mut() {
|
||||
if let Some(g) = a.downcast_mut::<GapBlockBehavior>() {
|
||||
g.core.range = TimeRange::new(in_, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
track_append_block(track, &gap);
|
||||
gap
|
||||
}
|
||||
|
||||
/// The block span of `block` (`None` for a stale node).
|
||||
fn span_of(block: &NodeRef) -> Option<(Rational, Rational)> {
|
||||
let p = block.project.lock().unwrap();
|
||||
p.graph.get(block.id).and_then(|e| e.behavior.as_any()).and_then(|a| {
|
||||
[
|
||||
a.downcast_ref::<ClipBlockBehavior>().map(|b| &b.core),
|
||||
a.downcast_ref::<GapBlockBehavior>().map(|b| &b.core),
|
||||
]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.next()
|
||||
.map(|core| (core.in_(), core.out()))
|
||||
})
|
||||
}
|
||||
|
||||
/// `TimelineAddTrackCommand` redo appends a track to the list; undo removes
|
||||
/// it again, and a second redo restores the same track node.
|
||||
#[test]
|
||||
fn add_track_command_redo_undo_cycle() {
|
||||
let project = make_project();
|
||||
let (_seq, list) = sequence_and_list(&project);
|
||||
|
||||
assert_eq!(tracklist_track_count(&list), 0);
|
||||
let track = TimelineAddTrackCommand::run_immediately(list.clone());
|
||||
assert_eq!(tracklist_track_count(&list), 1);
|
||||
assert_eq!(track_length(&track), Rational::new(0, 1));
|
||||
|
||||
let mut cmd = TimelineRemoveTrackCommand::new(track.clone());
|
||||
cmd.redo();
|
||||
assert_eq!(tracklist_track_count(&list), 0);
|
||||
cmd.undo();
|
||||
assert_eq!(tracklist_track_count(&list), 1);
|
||||
cmd.redo();
|
||||
assert_eq!(tracklist_track_count(&list), 0);
|
||||
}
|
||||
|
||||
/// `TimelineAddTrackCommand` creates the track with the list's media type.
|
||||
#[test]
|
||||
fn add_track_command_track_type() {
|
||||
let project = make_project();
|
||||
let (_seq, list) = sequence_and_list(&project);
|
||||
|
||||
let track = TimelineAddTrackCommand::run_immediately(list);
|
||||
{
|
||||
let p = project.lock().unwrap();
|
||||
let entry = p.graph.get(track.id).unwrap();
|
||||
let behavior = entry
|
||||
.behavior
|
||||
.as_any()
|
||||
.and_then(|a| a.downcast_ref::<TrackBehavior>())
|
||||
.unwrap();
|
||||
assert_eq!(behavior.kind, TrackType::Video);
|
||||
}
|
||||
}
|
||||
|
||||
/// `BlockSplitCommand` splits a clip at a point: the original becomes the
|
||||
/// first half `[in, point)` and the clone the second half `[point, out)`;
|
||||
/// undo restores the single original block.
|
||||
#[test]
|
||||
fn split_command_redo_undo() {
|
||||
let project = make_project();
|
||||
let (_seq, list) = sequence_and_list(&project);
|
||||
let track = TimelineAddTrackCommand::run_immediately(list.clone());
|
||||
let clip = add_clip(&track, Rational::new(0, 1), Rational::new(100, 1));
|
||||
|
||||
let mut split = BlockSplitCommand::new(clip.clone(), Rational::new(40, 1));
|
||||
split.prepare();
|
||||
split.redo();
|
||||
|
||||
assert_eq!(block_length(&clip), Rational::new(40, 1));
|
||||
assert_eq!(block_in(&clip), Rational::new(0, 1));
|
||||
let second = split.new_block().unwrap();
|
||||
assert_eq!(block_in(&second), Rational::new(40, 1));
|
||||
assert_eq!(block_out(&second), Rational::new(100, 1));
|
||||
assert_eq!(track_block_count(&track), 2);
|
||||
|
||||
split.undo();
|
||||
assert_eq!(block_length(&clip), Rational::new(100, 1));
|
||||
assert_eq!(block_out(&clip), Rational::new(100, 1));
|
||||
assert_eq!(track_block_count(&track), 1);
|
||||
|
||||
// The undo detached the second half from the graph; the next redo
|
||||
// re-attaches it with the same identity.
|
||||
split.redo();
|
||||
assert_eq!(block_length(&clip), Rational::new(40, 1));
|
||||
assert_eq!(split.new_block().unwrap().id, second.id);
|
||||
assert_eq!(track_block_count(&track), 2);
|
||||
}
|
||||
|
||||
/// `TrackReplaceBlockWithGapCommand` merges a clip into a following gap on
|
||||
/// redo and restores both blocks on undo.
|
||||
#[test]
|
||||
fn replace_block_with_gap_round_trip() {
|
||||
let project = make_project();
|
||||
let (_seq, list) = sequence_and_list(&project);
|
||||
let track = TimelineAddTrackCommand::run_immediately(list);
|
||||
let clip = add_clip(&track, Rational::new(0, 1), Rational::new(50, 1));
|
||||
let gap = add_gap(&track, Rational::new(50, 1), Rational::new(100, 1));
|
||||
|
||||
let mut cmd = TrackReplaceBlockWithGapCommand::new(track.clone(), clip.clone(), false);
|
||||
cmd.redo();
|
||||
// The clip is gone; the gap absorbed its length (in-anchored at 50).
|
||||
assert_eq!(track_block_count(&track), 1);
|
||||
let remaining = track_block_at(&track, 0).unwrap();
|
||||
assert_eq!(remaining.id, gap.id);
|
||||
assert_eq!(block_in(&remaining), Rational::new(50, 1));
|
||||
assert_eq!(block_length(&remaining), Rational::new(100, 1));
|
||||
assert!(block_track(&clip).is_none());
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(track_block_count(&track), 2);
|
||||
let first = track_block_at(&track, 0).unwrap();
|
||||
assert_eq!(first.id, clip.id);
|
||||
assert_eq!(block_in(&first), Rational::new(0, 1));
|
||||
assert_eq!(block_length(&first), Rational::new(50, 1));
|
||||
let second = track_block_at(&track, 1).unwrap();
|
||||
assert_eq!(second.id, gap.id);
|
||||
assert_eq!(block_in(&second), Rational::new(50, 1));
|
||||
assert_eq!(block_length(&second), Rational::new(50, 1));
|
||||
}
|
||||
|
||||
/// `TrackReplaceBlockWithGapCommand` creates its own gap when no
|
||||
/// neighbouring gap exists, and swaps it back out on undo.
|
||||
#[test]
|
||||
fn replace_block_with_gap_creates_gap() {
|
||||
let project = make_project();
|
||||
let (_seq, list) = sequence_and_list(&project);
|
||||
let track = TimelineAddTrackCommand::run_immediately(list);
|
||||
let clip = add_clip(&track, Rational::new(0, 1), Rational::new(50, 1));
|
||||
let tail = add_clip(&track, Rational::new(50, 1), Rational::new(100, 1));
|
||||
|
||||
let mut cmd = TrackReplaceBlockWithGapCommand::new(track.clone(), clip.clone(), false);
|
||||
cmd.redo();
|
||||
// clip replaced by a fresh gap of the same length.
|
||||
assert_eq!(track_block_count(&track), 2);
|
||||
let first = track_block_at(&track, 0).unwrap();
|
||||
assert_ne!(first.id, clip.id);
|
||||
assert_eq!(block_in(&first), Rational::new(0, 1));
|
||||
assert_eq!(block_length(&first), Rational::new(50, 1));
|
||||
assert_eq!(track_block_at(&track, 1).unwrap().id, tail.id);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(track_block_count(&track), 2);
|
||||
let restored = track_block_at(&track, 0).unwrap();
|
||||
assert_eq!(restored.id, clip.id);
|
||||
assert_eq!(block_length(&restored), Rational::new(50, 1));
|
||||
}
|
||||
|
||||
/// `TrackRippleRemoveAreaCommand` trims the boundary blocks and removes
|
||||
/// the blocks fully inside the range; undo restores everything.
|
||||
#[test]
|
||||
fn ripple_remove_area_round_trip() {
|
||||
let project = make_project();
|
||||
let (_seq, list) = sequence_and_list(&project);
|
||||
let track = TimelineAddTrackCommand::run_immediately(list);
|
||||
let c1 = add_clip(&track, Rational::new(0, 1), Rational::new(50, 1));
|
||||
let c2 = add_clip(&track, Rational::new(50, 1), Rational::new(100, 1));
|
||||
let c3 = add_clip(&track, Rational::new(100, 1), Rational::new(150, 1));
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
track.clone(),
|
||||
TimeRange::new(Rational::new(25, 1), Rational::new(125, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
|
||||
// c2 removed; c1 trimmed to [0,25); c3 out-anchored to [125,150).
|
||||
assert_eq!(track_block_count(&track), 2);
|
||||
let first = track_block_at(&track, 0).unwrap();
|
||||
assert_eq!(first.id, c1.id);
|
||||
assert_eq!(span_of(&first), Some((Rational::new(0, 1), Rational::new(25, 1))));
|
||||
let second = track_block_at(&track, 1).unwrap();
|
||||
assert_eq!(second.id, c3.id);
|
||||
assert_eq!(
|
||||
span_of(&second),
|
||||
Some((Rational::new(125, 1), Rational::new(150, 1)))
|
||||
);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(track_block_count(&track), 3);
|
||||
assert_eq!(track_block_at(&track, 0).unwrap().id, c1.id);
|
||||
assert_eq!(track_block_at(&track, 1).unwrap().id, c2.id);
|
||||
assert_eq!(track_block_at(&track, 2).unwrap().id, c3.id);
|
||||
assert_eq!(span_of(&c1), Some((Rational::new(0, 1), Rational::new(50, 1))));
|
||||
assert_eq!(
|
||||
span_of(&c2),
|
||||
Some((Rational::new(50, 1), Rational::new(100, 1)))
|
||||
);
|
||||
assert_eq!(
|
||||
span_of(&c3),
|
||||
Some((Rational::new(100, 1), Rational::new(150, 1)))
|
||||
);
|
||||
}
|
||||
|
||||
/// `BlockResizeCommand` changes a block's length out-anchored and restores
|
||||
/// it on undo.
|
||||
#[test]
|
||||
fn block_resize_round_trip() {
|
||||
let project = make_project();
|
||||
let (_seq, list) = sequence_and_list(&project);
|
||||
let track = TimelineAddTrackCommand::run_immediately(list);
|
||||
let clip = add_clip(&track, Rational::new(0, 1), Rational::new(50, 1));
|
||||
|
||||
let mut cmd = BlockResizeCommand::new(clip.clone(), Rational::new(30, 1));
|
||||
cmd.redo();
|
||||
assert_eq!(block_length(&clip), Rational::new(30, 1));
|
||||
// Out-anchored: the in point shifts so the out stays at 50.
|
||||
assert_eq!(block_out(&clip), Rational::new(50, 1));
|
||||
cmd.undo();
|
||||
assert_eq!(block_length(&clip), Rational::new(50, 1));
|
||||
assert_eq!(block_in(&clip), Rational::new(0, 1));
|
||||
}
|
||||
|
||||
/// `TrackMoveBlockCommand` replaces the source spot with a gap and places
|
||||
/// the block at the destination; undo restores the original layout.
|
||||
#[test]
|
||||
fn move_block_round_trip() {
|
||||
let project = make_project();
|
||||
let (_seq, list) = sequence_and_list(&project);
|
||||
let track = TimelineAddTrackCommand::run_immediately(list.clone());
|
||||
let clip = add_clip(&track, Rational::new(0, 1), Rational::new(50, 1));
|
||||
let tail = add_clip(&track, Rational::new(50, 1), Rational::new(100, 1));
|
||||
|
||||
let mut cmd = TrackMoveBlockCommand::new(
|
||||
list,
|
||||
0,
|
||||
clip.clone(),
|
||||
Rational::new(150, 1),
|
||||
);
|
||||
cmd.redo();
|
||||
// Layout: a gap fills the clip's old spot [0,50), the tail stays at
|
||||
// [50,100), a bridging gap covers [100,150) and the moved clip is
|
||||
// appended at [150,200).
|
||||
assert_eq!(track_block_count(&track), 4);
|
||||
assert_eq!(block_in(&clip), Rational::new(150, 1));
|
||||
assert_eq!(block_length(&clip), Rational::new(50, 1));
|
||||
let first = track_block_at(&track, 0).unwrap();
|
||||
assert_eq!(span_of(&first), Some((Rational::new(0, 1), Rational::new(50, 1))));
|
||||
assert_eq!(track_block_at(&track, 1).unwrap().id, tail.id);
|
||||
let third = track_block_at(&track, 2).unwrap();
|
||||
assert_eq!(
|
||||
span_of(&third),
|
||||
Some((Rational::new(100, 1), Rational::new(150, 1)))
|
||||
);
|
||||
assert_eq!(track_block_at(&track, 3).unwrap().id, clip.id);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(track_block_count(&track), 2);
|
||||
assert_eq!(track_block_at(&track, 0).unwrap().id, clip.id);
|
||||
assert_eq!(track_block_at(&track, 1).unwrap().id, tail.id);
|
||||
assert_eq!(span_of(&clip), Some((Rational::new(0, 1), Rational::new(50, 1))));
|
||||
assert_eq!(span_of(&tail), Some((Rational::new(50, 1), Rational::new(100, 1))));
|
||||
}
|
||||
|
||||
/// The `Command` trait dispatch (used by the oakundo vtable wrappers)
|
||||
/// routes through the same redo/undo bodies as the inherent methods.
|
||||
#[test]
|
||||
fn commands_trait_dispatch() {
|
||||
let project = make_project();
|
||||
let (_seq, list) = sequence_and_list(&project);
|
||||
let track = TimelineAddTrackCommand::run_immediately(list);
|
||||
let clip = add_clip(&track, Rational::new(0, 1), Rational::new(50, 1));
|
||||
|
||||
let mut resize = BlockResizeCommand::new(clip.clone(), Rational::new(10, 1));
|
||||
Command::redo(&mut resize);
|
||||
assert_eq!(block_length(&clip), Rational::new(10, 1));
|
||||
Command::undo(&mut resize);
|
||||
assert_eq!(block_length(&clip), Rational::new(50, 1));
|
||||
}
|
||||
|
||||
/// `TrackPlaceBlockCommand` splices a clip into the middle of another:
|
||||
/// the host block is split at the range in, the remainder is trimmed to
|
||||
/// the range out, and the placed block lands in between; undo restores
|
||||
/// the single host block.
|
||||
#[test]
|
||||
fn place_block_splice_round_trip() {
|
||||
let project = make_project();
|
||||
let (_seq, list) = sequence_and_list(&project);
|
||||
let track = TimelineAddTrackCommand::run_immediately(list.clone());
|
||||
let host = add_clip(&track, Rational::new(0, 1), Rational::new(100, 1));
|
||||
let placed = add_clip(&track, Rational::new(25, 1), Rational::new(35, 1));
|
||||
track_ripple_remove_block(&track, &placed);
|
||||
|
||||
let mut cmd = oaktimeline::undopointer::TrackPlaceBlockCommand::new(
|
||||
list.clone(),
|
||||
0,
|
||||
placed.clone(),
|
||||
Rational::new(25, 1),
|
||||
);
|
||||
cmd.redo();
|
||||
// host split to [0,25), remainder trimmed to [25,90), placed at [25,35).
|
||||
assert_eq!(track_block_count(&track), 3);
|
||||
assert_eq!(track_block_at(&track, 0).unwrap().id, host.id);
|
||||
assert_eq!(track_block_at(&track, 1).unwrap().id, placed.id);
|
||||
assert_eq!(
|
||||
span_of(&host),
|
||||
Some((Rational::new(0, 1), Rational::new(25, 1)))
|
||||
);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(track_block_count(&track), 1);
|
||||
assert_eq!(track_block_at(&track, 0).unwrap().id, host.id);
|
||||
assert_eq!(
|
||||
span_of(&host),
|
||||
Some((Rational::new(0, 1), Rational::new(100, 1)))
|
||||
);
|
||||
}
|
||||
|
||||
/// `TrackListInsertGaps` splits a block at the insertion point and
|
||||
/// inserts a gap of the requested length after it; undo removes the gap
|
||||
/// and re-joins the block.
|
||||
#[test]
|
||||
fn insert_gaps_round_trip() {
|
||||
let project = make_project();
|
||||
let (_seq, list) = sequence_and_list(&project);
|
||||
let track = TimelineAddTrackCommand::run_immediately(list.clone());
|
||||
let clip = add_clip(&track, Rational::new(0, 1), Rational::new(100, 1));
|
||||
|
||||
let mut cmd =
|
||||
oaktimeline::undogeneral::TrackListInsertGaps::new(
|
||||
list.clone(),
|
||||
Rational::new(40, 1),
|
||||
Rational::new(20, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
// clip split to [0,40) + [40,100), gap [40,60) inserted after the
|
||||
// first half.
|
||||
assert_eq!(track_block_count(&track), 3);
|
||||
let first = track_block_at(&track, 0).unwrap();
|
||||
assert_eq!(first.id, clip.id);
|
||||
assert_eq!(span_of(&first), Some((Rational::new(0, 1), Rational::new(40, 1))));
|
||||
let gap = track_block_at(&track, 1).unwrap();
|
||||
assert_eq!(
|
||||
span_of(&gap),
|
||||
Some((Rational::new(40, 1), Rational::new(60, 1)))
|
||||
);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(track_block_count(&track), 1);
|
||||
assert_eq!(track_block_at(&track, 0).unwrap().id, clip.id);
|
||||
assert_eq!(
|
||||
span_of(&clip),
|
||||
Some((Rational::new(0, 1), Rational::new(100, 1)))
|
||||
);
|
||||
}
|
||||
@@ -1,982 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Contract tests for the edit-family undo commands
|
||||
//! (`src/undogeneral.rs`, `src/undopointer.rs`, `src/undoripple.rs`,
|
||||
//! `src/undosplit.rs`, `src/undotrack.rs`). These mirror
|
||||
//! `include/timeline/edit.h`; each command boxes into a CHandle via
|
||||
//! the bridge undo vtable instead of the C++ `UndoCommand` hierarchy.
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use oakcore_rs::{Rational, TimeRange};
|
||||
use oaktimeline::bridge::node::{
|
||||
oaknode_block_clip_create, oaknode_block_gap_create, oaknode_track_create,
|
||||
oaknode_track_get_block_at, oaknode_track_get_block_count, oaknode_track_prepend_block,
|
||||
};
|
||||
use oaktimeline::bridge::teststubs::{MockKind, MockNode};
|
||||
use oaktimeline::common::MovementMode;
|
||||
use oaktimeline::handle::{get, get_mut, make_owned, CHandle, OAKTIMELINE_ABI_VERSION};
|
||||
use oaktimeline::undocommon::Command;
|
||||
use oaktimeline::undogeneral::{
|
||||
BlockEnableDisableCommand, BlockResizeCommand, BlockResizeWithMediaInCommand,
|
||||
BlockSetMediaInCommand, TimelineAddDefaultTransitionCommand, TimelineAddTrackCommand,
|
||||
TimelineRemoveTrackCommand, TrackListInsertGaps, TrackReplaceBlockWithGapCommand,
|
||||
TransitionRemoveCommand,
|
||||
};
|
||||
use oaktimeline::undopointer::{
|
||||
BlockTrimCommand, TrackMoveBlockCommand, TrackPlaceBlockCommand, TrackSlideCommand,
|
||||
};
|
||||
use oaktimeline::undoripple::{
|
||||
TimelineRippleDeleteGapsAtRegionsCommand, TimelineRippleRemoveAreaCommand,
|
||||
TrackListRippleRemoveAreaCommand, TrackRippleRemoveAreaCommand,
|
||||
};
|
||||
use oaktimeline::undosplit::{
|
||||
BlockSplitCommand, BlockSplitPreservingLinksCommand, TrackSplitAtTimeCommand,
|
||||
};
|
||||
use oaktimeline::undotrack::{
|
||||
TrackInsertBlockAfterCommand, TrackPrependBlockCommand, TrackReplaceBlockCommand,
|
||||
};
|
||||
|
||||
/// `TimelineAddTrackCommand` redo adds a track; undo removes it. The
|
||||
/// newly-created track is exposed via `track()`.
|
||||
#[test]
|
||||
fn add_track_command_redo_undo() {
|
||||
let list = make_list();
|
||||
let mut cmd = TimelineAddTrackCommand::new(list.clone());
|
||||
|
||||
cmd.redo();
|
||||
let t = cmd.track();
|
||||
assert!(!t.is_null());
|
||||
assert!(matches!(kind_of(&t), MockKind::Track));
|
||||
assert_eq!(track_type_of(&t), 0);
|
||||
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// `TimelineAddTrackCommand` with `automerge` uses the same add/remove
|
||||
/// path but performs an automerge on redo.
|
||||
#[test]
|
||||
fn add_track_command_with_automerge() {
|
||||
let list = make_list();
|
||||
let mut cmd = TimelineAddTrackCommand::with_automerge(list.clone(), true);
|
||||
|
||||
cmd.redo();
|
||||
let t = cmd.track();
|
||||
assert!(!t.is_null());
|
||||
assert!(matches!(kind_of(&t), MockKind::Track));
|
||||
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// `TimelineRemoveTrackCommand` redo removes the track; undo restores
|
||||
/// it.
|
||||
#[test]
|
||||
fn remove_track_command_redo_undo() {
|
||||
let t = make_track();
|
||||
let mut cmd = TimelineRemoveTrackCommand::new(t.clone());
|
||||
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
|
||||
assert_eq!(count(&t), 0);
|
||||
}
|
||||
|
||||
/// `TrackPlaceBlockCommand` redo places the block at a track index and
|
||||
/// in-point; undo returns the track to its prior state.
|
||||
#[test]
|
||||
fn place_block_command_redo_undo() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let mut cmd = TrackPlaceBlockCommand::new(list.clone(), 0, b.clone(), Rational::new(0, 1));
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 0);
|
||||
}
|
||||
|
||||
/// `TrackMoveBlockCommand` redo gaps the block's old spot and places it at
|
||||
/// the new in point (keeping the length); undo restores the original
|
||||
/// position.
|
||||
#[test]
|
||||
fn track_move_block_redo_undo() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackMoveBlockCommand::new(list.clone(), 0, b.clone(), Rational::new(20, 1));
|
||||
cmd.redo();
|
||||
// The old spot is a gap; the block sits at the new in point, length kept.
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(b_in(&b), (20, 1));
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(b_in(&b), (0, 1));
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(b_in(&b), (20, 1));
|
||||
}
|
||||
|
||||
/// `TrackMoveBlockCommand` moves the block onto another track (the
|
||||
/// destination track index need not match the source); undo moves it back.
|
||||
#[test]
|
||||
fn track_move_block_cross_track_redo_undo() {
|
||||
let list = make_list();
|
||||
let t0 = make_track();
|
||||
let t1 = make_track();
|
||||
list_add_track(&list, &t0);
|
||||
list_add_track(&list, &t1);
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t0.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackMoveBlockCommand::new(list.clone(), 1, b.clone(), Rational::new(20, 1));
|
||||
cmd.redo();
|
||||
// t0's only block moved away (at-end gap: nothing left behind); t1 holds
|
||||
// a lead-in gap plus the block.
|
||||
assert_eq!(count(&t0), 0);
|
||||
assert_eq!(count(&t1), 2);
|
||||
assert_eq!(b_in(&b), (20, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t0), 1);
|
||||
assert_eq!(count(&t1), 0);
|
||||
assert_eq!(b_in(&b), (0, 1));
|
||||
}
|
||||
|
||||
/// `BlockResizeCommand` redo resizes the block; undo restores its
|
||||
/// original length (media out follows the resize).
|
||||
#[test]
|
||||
fn block_resize_command_redo_undo() {
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let mut cmd = BlockResizeCommand::new(b.clone(), Rational::new(6, 1));
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&b), (6, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// `BlockResizeWithMediaInCommand` resizes while keeping media out
|
||||
/// fixed, shifting media in instead.
|
||||
#[test]
|
||||
fn block_resize_with_media_in_redo_undo() {
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let mut cmd = BlockResizeWithMediaInCommand::new(b.clone(), Rational::new(6, 1));
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&b), (6, 1));
|
||||
assert_eq!(media_in(&b), (4, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
assert_eq!(media_in(&b), (0, 1));
|
||||
}
|
||||
|
||||
/// `BlockSetMediaInCommand` redo sets the media-in point; undo
|
||||
/// restores the original.
|
||||
#[test]
|
||||
fn block_set_media_in_redo_undo() {
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let mut cmd = BlockSetMediaInCommand::new(b.clone(), Rational::new(4, 1));
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(media_in(&b), (4, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(media_in(&b), (0, 1));
|
||||
}
|
||||
|
||||
/// `BlockTrimCommand` trims to a new length under a given movement
|
||||
/// mode; undo restores the original length. Trim flags are settable
|
||||
/// before execution.
|
||||
#[test]
|
||||
fn block_trim_command_redo_undo() {
|
||||
let t = make_track();
|
||||
let g1 = mk_gap();
|
||||
let b = mk_clip();
|
||||
let c = mk_clip();
|
||||
set_times(&g1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&b, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
set_times(&c, (20, 1), (30, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), c.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g1.clone());
|
||||
}
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(6, 1),
|
||||
MovementMode::TrimOut,
|
||||
);
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 4);
|
||||
assert_eq!(blen(&b), (6, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 3);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// `TrackReplaceBlockWithGapCommand` redo swaps the block for a gap;
|
||||
/// undo restores the block.
|
||||
#[test]
|
||||
fn replace_block_with_gap_redo_undo() {
|
||||
let t = make_track();
|
||||
let g = mk_gap();
|
||||
let blk = mk_clip();
|
||||
let nxt = mk_clip();
|
||||
set_times(&g, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&blk, (10, 1), (15, 1), (5, 1), (0, 1));
|
||||
set_times(&nxt, (15, 1), (25, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), nxt.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), blk.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackReplaceBlockWithGapCommand::new(t.clone(), blk.clone(), false);
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(blen(&g), (15, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 3);
|
||||
assert_eq!(blen(&g), (10, 1));
|
||||
}
|
||||
|
||||
/// `BlockEnableDisableCommand` redo toggles enabled; undo restores.
|
||||
#[test]
|
||||
fn block_enable_disable_redo_undo() {
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let mut cmd = BlockEnableDisableCommand::new(b.clone(), false);
|
||||
|
||||
cmd.redo();
|
||||
assert!(!enabled(&b));
|
||||
|
||||
cmd.undo();
|
||||
assert!(enabled(&b));
|
||||
}
|
||||
|
||||
/// `TrackPrependBlockCommand` redo inserts at the front; undo removes.
|
||||
#[test]
|
||||
fn track_prepend_block_redo_undo() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let b2 = mk_clip();
|
||||
set_times(&b2, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let mut cmd = TrackPrependBlockCommand::new(t.clone(), b2.clone());
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
/// `TrackInsertBlockAfterCommand` redo inserts after a sibling; undo
|
||||
/// removes.
|
||||
#[test]
|
||||
fn track_insert_block_after_redo_undo() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let b2 = mk_clip();
|
||||
set_times(&b2, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let mut cmd = TrackInsertBlockAfterCommand::new(t.clone(), b2.clone(), b.clone());
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
/// `TrackReplaceBlockCommand` redo swaps the block; undo restores the
|
||||
/// original.
|
||||
#[test]
|
||||
fn track_replace_block_redo_undo() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let b2 = mk_clip();
|
||||
set_times(&b2, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let mut cmd = TrackReplaceBlockCommand::new(t.clone(), b.clone(), b2.clone());
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
// `at()` returns a borrowed handle (raw value pointer), while `b2.ctx`
|
||||
// is the owned `RefBox` pointer — compare the underlying value address.
|
||||
assert_eq!(at(&t, 0).ctx as usize, addr(&b2) as usize);
|
||||
assert!(track_ptr(&b).is_null());
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(at(&t, 0).ctx as usize, addr(&b) as usize);
|
||||
assert!(track_ptr(&b2).is_null());
|
||||
}
|
||||
|
||||
/// The track commands dispatch through the `Command` trait, as the undo
|
||||
/// stack's vtable invokes them.
|
||||
#[test]
|
||||
fn track_commands_trait_dispatch() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut prepend = TrackPrependBlockCommand::new(t.clone(), b.clone());
|
||||
Command::redo(&mut prepend);
|
||||
assert_eq!(count(&t), 1);
|
||||
Command::undo(&mut prepend);
|
||||
assert_eq!(count(&t), 0);
|
||||
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
let b2 = mk_clip();
|
||||
set_times(&b2, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let mut ins = TrackInsertBlockAfterCommand::new(t.clone(), b2.clone(), b.clone());
|
||||
Command::redo(&mut ins);
|
||||
assert_eq!(count(&t), 2);
|
||||
Command::undo(&mut ins);
|
||||
assert_eq!(count(&t), 1);
|
||||
|
||||
let b3 = mk_clip();
|
||||
set_times(&b3, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let mut rep = TrackReplaceBlockCommand::new(t.clone(), b.clone(), b3.clone());
|
||||
Command::redo(&mut rep);
|
||||
assert_eq!(at(&t, 0).ctx as usize, addr(&b3) as usize);
|
||||
Command::undo(&mut rep);
|
||||
assert_eq!(at(&t, 0).ctx as usize, addr(&b) as usize);
|
||||
}
|
||||
|
||||
/// `BlockSplitCommand` redo splits at a point; undo joins the pieces
|
||||
/// back. `new_block` exposes the created half after redo.
|
||||
#[test]
|
||||
fn block_split_command_redo_undo() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = BlockSplitCommand::new(b.clone(), Rational::new(5, 1));
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(blen(&b), (5, 1));
|
||||
assert!(!cmd.new_block().is_null());
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// `BlockSplitPreservingLinksCommand` splits many blocks at matching
|
||||
/// times and keeps linked-media relations; undo rejoins them.
|
||||
#[test]
|
||||
fn block_split_preserving_links_redo_undo() {
|
||||
let t = make_track();
|
||||
let clip = mk_clip();
|
||||
set_times(&clip, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), clip.clone());
|
||||
}
|
||||
|
||||
let mut cmd =
|
||||
BlockSplitPreservingLinksCommand::new(vec![clip.clone()], vec![Rational::new(5, 1)]);
|
||||
cmd.prepare();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert!(cmd.get_split(clip.clone(), 0).is_some());
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(blen(&clip), (10, 1));
|
||||
}
|
||||
|
||||
/// `TrackSplitAtTimeCommand` redo splits the block under the point;
|
||||
/// undo rejoins.
|
||||
#[test]
|
||||
fn track_split_at_time_redo_undo() {
|
||||
let t = make_track();
|
||||
let mut cmd = TrackSplitAtTimeCommand::new(t.clone(), Rational::new(5, 1));
|
||||
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
|
||||
assert_eq!(count(&t), 0);
|
||||
}
|
||||
|
||||
/// `BlockSplitCommand::redo` without a prior `prepare` still creates the
|
||||
/// second half (the C ABI command path may call redo directly).
|
||||
#[test]
|
||||
fn block_split_redo_without_prepare() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = BlockSplitCommand::new(b.clone(), Rational::new(4, 1));
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(blen(&b), (4, 1));
|
||||
assert!(!cmd.new_block().is_null());
|
||||
}
|
||||
|
||||
/// Split commands dispatch through the `Command` trait, and
|
||||
/// `get_split` reports `None` for unknown blocks / out-of-range indices.
|
||||
#[test]
|
||||
fn split_commands_trait_dispatch_and_get_split() {
|
||||
let t = make_track();
|
||||
let clip = mk_clip();
|
||||
set_times(&clip, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), clip.clone());
|
||||
}
|
||||
|
||||
// `BlockSplitCommand` via the trait.
|
||||
let mut s = BlockSplitCommand::new(clip.clone(), Rational::new(5, 1));
|
||||
s.prepare();
|
||||
assert_eq!(count(&t), 1);
|
||||
Command::redo(&mut s);
|
||||
assert_eq!(count(&t), 2);
|
||||
Command::undo(&mut s);
|
||||
assert_eq!(count(&t), 1);
|
||||
|
||||
// `BlockSplitPreservingLinksCommand`: prepare applies, undo unsplits,
|
||||
// redo re-applies; `get_split` None paths.
|
||||
let other = mk_clip();
|
||||
let mut p =
|
||||
BlockSplitPreservingLinksCommand::new(vec![clip.clone()], vec![Rational::new(5, 1)]);
|
||||
p.prepare();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert!(p.get_split(clip.clone(), 0).is_some());
|
||||
assert!(p.get_split(clip.clone(), 5).is_none());
|
||||
assert!(p.get_split(other, 0).is_none());
|
||||
|
||||
Command::undo(&mut p);
|
||||
assert_eq!(count(&t), 1);
|
||||
Command::redo(&mut p);
|
||||
assert_eq!(count(&t), 2);
|
||||
|
||||
// `TrackSplitAtTimeCommand` via the trait (no inner command built).
|
||||
let mut ts = TrackSplitAtTimeCommand::new(t.clone(), Rational::new(5, 1));
|
||||
Command::redo(&mut ts);
|
||||
Command::undo(&mut ts);
|
||||
}
|
||||
|
||||
/// `TrackRippleRemoveAreaCommand` redo ripples out a range (splicing
|
||||
/// surrounding blocks); undo re-inserts the removed material. The
|
||||
/// spliced block and insertion index are queryable afterwards.
|
||||
#[test]
|
||||
fn track_ripple_remove_area_redo_undo() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(10, 1), Rational::new(15, 1)),
|
||||
);
|
||||
cmd.set_allow_splitting_gaps(true);
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&b), (5, 1));
|
||||
assert_eq!(count(&t), 1);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
/// `TrackListRippleRemoveAreaCommand` removes the same area across
|
||||
/// every track in a list.
|
||||
#[test]
|
||||
fn track_list_ripple_remove_area_redo_undo() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let b = mk_clip();
|
||||
set_times(&b, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackListRippleRemoveAreaCommand::new(
|
||||
list.clone(),
|
||||
Rational::new(10, 1),
|
||||
Rational::new(15, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&b), (5, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// `TimelineRippleRemoveAreaCommand` removes an area across all
|
||||
/// tracks in a timeline.
|
||||
#[test]
|
||||
fn timeline_ripple_remove_area_redo_undo() {
|
||||
let seq = make_sequence();
|
||||
let list = make_list();
|
||||
seq_add_list(&seq, &list);
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let b = mk_clip();
|
||||
set_times(&b, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TimelineRippleRemoveAreaCommand::new(
|
||||
seq.clone(),
|
||||
Rational::new(10, 1),
|
||||
Rational::new(15, 1),
|
||||
);
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&b), (5, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// `TrackListInsertGaps` redo inserts a gap at a point of a given
|
||||
/// length across a track list; undo removes it.
|
||||
#[test]
|
||||
fn track_list_insert_gaps_redo_undo() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let clip = mk_clip();
|
||||
set_times(&clip, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), clip.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackListInsertGaps::new(list.clone(), Rational::new(5, 1), Rational::new(3, 1));
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
/// `TimelineRippleDeleteGapsAtRegionsCommand` redo deletes gaps at the
|
||||
/// given regions; undo re-inserts them. `has_commands` reports whether
|
||||
/// any deletion was planned during `prepare`.
|
||||
#[test]
|
||||
fn ripple_delete_gaps_redo_undo() {
|
||||
let seq = make_sequence();
|
||||
let list = make_list();
|
||||
seq_add_list(&seq, &list);
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let gap = mk_gap();
|
||||
set_times(&gap, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), gap.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TimelineRippleDeleteGapsAtRegionsCommand::new(
|
||||
seq.clone(),
|
||||
vec![(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(10, 1)),
|
||||
)],
|
||||
);
|
||||
cmd.prepare();
|
||||
assert!(cmd.has_commands());
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 0);
|
||||
|
||||
// `oaknode_track_insert_block_after` prepends on a null predecessor, so
|
||||
// the gap removed on redo is restored by undo.
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
/// `TrackSlideCommand` redo slides a block range by a movement;
|
||||
/// undo restores the original positions.
|
||||
#[test]
|
||||
fn track_slide_command_redo_undo() {
|
||||
let t = make_track();
|
||||
let g1 = mk_gap();
|
||||
let b = mk_clip();
|
||||
let g2 = mk_gap();
|
||||
set_times(&g1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&b, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
set_times(&g2, (20, 1), (30, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g2.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g1.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackSlideCommand::new(
|
||||
t.clone(),
|
||||
vec![b.clone()],
|
||||
g1.clone(),
|
||||
g2.clone(),
|
||||
Rational::new(5, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&g1), (15, 1));
|
||||
assert_eq!(blen(&g2), (5, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&g1), (10, 1));
|
||||
assert_eq!(blen(&g2), (10, 1));
|
||||
}
|
||||
|
||||
/// `TimelineAddDefaultTransitionCommand` redo inserts default
|
||||
/// transitions between clips at a timebase; undo removes them.
|
||||
#[test]
|
||||
fn add_default_transition_redo_undo() {
|
||||
let mut cmd = TimelineAddDefaultTransitionCommand::new(vec![], Rational::new(30, 1));
|
||||
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// `TransitionRemoveCommand` redo removes a transition; undo restores
|
||||
/// it (optionally keeping it in the graph).
|
||||
#[test]
|
||||
fn transition_remove_redo_undo() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
let c = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&c, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), c.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TransitionRemoveCommand::new(b.clone(), false);
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert!(track_ptr(&b).is_null());
|
||||
|
||||
// The stub's undo is a no-op and does not re-insert the removed
|
||||
// block; the block count therefore stays unchanged.
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
/// Every edit command `to_command` produces a CHandle suitable for the
|
||||
/// undo stack, and every `prepare` is idempotent for repeated redo.
|
||||
#[test]
|
||||
fn all_edit_commands_box_to_chandle() {
|
||||
let seq = make_sequence();
|
||||
let list = make_list();
|
||||
seq_add_list(&seq, &list);
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
let b2 = mk_clip();
|
||||
|
||||
let mut handles: Vec<CHandle> = Vec::new();
|
||||
handles.push(BlockResizeCommand::new(b.clone(), Rational::new(6, 1)).to_command());
|
||||
handles.push(BlockResizeWithMediaInCommand::new(b.clone(), Rational::new(6, 1)).to_command());
|
||||
handles.push(BlockSetMediaInCommand::new(b.clone(), Rational::new(4, 1)).to_command());
|
||||
handles.push(TimelineAddTrackCommand::new(list.clone()).to_command());
|
||||
handles.push(TimelineAddTrackCommand::with_automerge(list.clone(), true).to_command());
|
||||
handles.push(TimelineRemoveTrackCommand::new(t.clone()).to_command());
|
||||
handles.push(TransitionRemoveCommand::new(b.clone(), false).to_command());
|
||||
handles.push(TrackReplaceBlockWithGapCommand::new(t.clone(), b.clone(), false).to_command());
|
||||
handles.push(BlockEnableDisableCommand::new(b.clone(), false).to_command());
|
||||
handles.push(
|
||||
TrackListInsertGaps::new(list.clone(), Rational::new(5, 1), Rational::new(3, 1))
|
||||
.to_command(),
|
||||
);
|
||||
handles
|
||||
.push(TimelineAddDefaultTransitionCommand::new(vec![], Rational::new(30, 1)).to_command());
|
||||
handles.push(
|
||||
BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(6, 1),
|
||||
MovementMode::TrimOut,
|
||||
)
|
||||
.to_command(),
|
||||
);
|
||||
handles.push(
|
||||
TrackSlideCommand::new(
|
||||
t.clone(),
|
||||
vec![b.clone()],
|
||||
b.clone(),
|
||||
b2.clone(),
|
||||
Rational::new(5, 1),
|
||||
)
|
||||
.to_command(),
|
||||
);
|
||||
handles.push(
|
||||
TrackPlaceBlockCommand::new(list.clone(), 0, b.clone(), Rational::new(0, 1)).to_command(),
|
||||
);
|
||||
handles.push(
|
||||
TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(10, 1), Rational::new(15, 1)),
|
||||
)
|
||||
.to_command(),
|
||||
);
|
||||
handles.push(
|
||||
TrackListRippleRemoveAreaCommand::new(
|
||||
list.clone(),
|
||||
Rational::new(10, 1),
|
||||
Rational::new(15, 1),
|
||||
)
|
||||
.to_command(),
|
||||
);
|
||||
handles.push(
|
||||
TimelineRippleRemoveAreaCommand::new(
|
||||
seq.clone(),
|
||||
Rational::new(10, 1),
|
||||
Rational::new(15, 1),
|
||||
)
|
||||
.to_command(),
|
||||
);
|
||||
handles.push(
|
||||
TimelineRippleDeleteGapsAtRegionsCommand::new(
|
||||
seq.clone(),
|
||||
vec![(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(10, 1)),
|
||||
)],
|
||||
)
|
||||
.to_command(),
|
||||
);
|
||||
handles.push(BlockSplitCommand::new(b.clone(), Rational::new(5, 1)).to_command());
|
||||
handles.push(
|
||||
BlockSplitPreservingLinksCommand::new(vec![b.clone()], vec![Rational::new(5, 1)])
|
||||
.to_command(),
|
||||
);
|
||||
handles.push(TrackSplitAtTimeCommand::new(t.clone(), Rational::new(5, 1)).to_command());
|
||||
handles.push(TrackPrependBlockCommand::new(t.clone(), b2.clone()).to_command());
|
||||
handles.push(TrackInsertBlockAfterCommand::new(t.clone(), b2.clone(), b.clone()).to_command());
|
||||
handles.push(TrackReplaceBlockCommand::new(t.clone(), b.clone(), b2.clone()).to_command());
|
||||
|
||||
for h in handles {
|
||||
assert!(!h.is_null());
|
||||
assert_eq!(h.abi_version, OAKTIMELINE_ABI_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
/// `MovementMode` round-trips through its C integer and
|
||||
/// `is_a_trim_mode` distinguishes trim modes.
|
||||
#[test]
|
||||
fn movement_mode_c_round_trip() {
|
||||
assert_eq!(MovementMode::None.to_c_int(), 0);
|
||||
assert_eq!(MovementMode::Move.to_c_int(), 1);
|
||||
assert_eq!(MovementMode::TrimIn.to_c_int(), 2);
|
||||
assert_eq!(MovementMode::TrimOut.to_c_int(), 3);
|
||||
|
||||
assert!(!MovementMode::None.is_a_trim_mode());
|
||||
assert!(!MovementMode::Move.is_a_trim_mode());
|
||||
assert!(MovementMode::TrimIn.is_a_trim_mode());
|
||||
assert!(MovementMode::TrimOut.is_a_trim_mode());
|
||||
|
||||
for v in 0..=3 {
|
||||
assert_eq!(MovementMode::from_c_int(v).map(|m| m.to_c_int()), Some(v));
|
||||
}
|
||||
assert!(MovementMode::from_c_int(9).is_none());
|
||||
}
|
||||
|
||||
// ---- helpers ---------------------------------------------------------
|
||||
|
||||
/// A new detached track of video type (0).
|
||||
fn make_track() -> CHandle {
|
||||
unsafe { oaknode_track_create(0) }
|
||||
}
|
||||
|
||||
/// Raw pointer to the node boxed behind a handle.
|
||||
fn addr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get_mut::<MockNode>(h).unwrap() as *mut MockNode }
|
||||
}
|
||||
|
||||
/// Number of blocks on a track.
|
||||
fn count(track: &CHandle) -> i32 {
|
||||
let mut c = 0;
|
||||
unsafe { oaknode_track_get_block_count(track.clone(), &mut c) };
|
||||
c
|
||||
}
|
||||
|
||||
/// Borrowed block at `index` on a track (for `.ctx` comparison only).
|
||||
fn at(track: &CHandle, idx: i32) -> CHandle {
|
||||
let mut o = CHandle::null();
|
||||
unsafe { oaknode_track_get_block_at(track.clone(), idx, &mut o) };
|
||||
o
|
||||
}
|
||||
|
||||
/// A new clip block.
|
||||
fn mk_clip() -> CHandle {
|
||||
unsafe { oaknode_block_clip_create() }
|
||||
}
|
||||
|
||||
/// A new gap block.
|
||||
fn mk_gap() -> CHandle {
|
||||
unsafe { oaknode_block_gap_create() }
|
||||
}
|
||||
|
||||
/// Set a block's in/out/length/media-in points directly.
|
||||
fn set_times(h: &CHandle, in_: (i32, i32), out: (i32, i32), len: (i32, i32), mi: (i32, i32)) {
|
||||
let b = unsafe { get_mut::<MockNode>(h).unwrap() };
|
||||
b.in_ = in_;
|
||||
b.out = out;
|
||||
b.length = len;
|
||||
b.media_in = mi;
|
||||
}
|
||||
|
||||
/// A block's length as `(num, den)`.
|
||||
fn blen(h: &CHandle) -> (i32, i32) {
|
||||
unsafe { get::<MockNode>(h).unwrap().length }
|
||||
}
|
||||
|
||||
/// A block's in point as `(num, den)`.
|
||||
fn b_in(h: &CHandle) -> (i32, i32) {
|
||||
unsafe { get::<MockNode>(h).unwrap().in_ }
|
||||
}
|
||||
|
||||
/// A block's media-in as `(num, den)`.
|
||||
fn media_in(h: &CHandle) -> (i32, i32) {
|
||||
unsafe { get::<MockNode>(h).unwrap().media_in }
|
||||
}
|
||||
|
||||
/// A block's enabled flag.
|
||||
fn enabled(h: &CHandle) -> bool {
|
||||
unsafe { get::<MockNode>(h).unwrap().enabled }
|
||||
}
|
||||
|
||||
/// A block's owning-track raw pointer.
|
||||
fn track_ptr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get::<MockNode>(h).unwrap().track }
|
||||
}
|
||||
|
||||
/// A node's kind.
|
||||
fn kind_of(h: &CHandle) -> MockKind {
|
||||
unsafe { get::<MockNode>(h).unwrap().kind }
|
||||
}
|
||||
|
||||
/// A node's track type.
|
||||
fn track_type_of(h: &CHandle) -> i32 {
|
||||
unsafe { get::<MockNode>(h).unwrap().track_type }
|
||||
}
|
||||
|
||||
/// A new empty track list of video type (0).
|
||||
fn make_list() -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
track_type: 0,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
/// Add a track to a track list (mock: push onto `blocks`).
|
||||
fn list_add_track(list: &CHandle, t: &CHandle) {
|
||||
unsafe {
|
||||
get_mut::<MockNode>(list).unwrap().blocks.push(addr(t));
|
||||
}
|
||||
}
|
||||
|
||||
/// A new empty sequence.
|
||||
fn make_sequence() -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::Sequence,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
/// Add a track list to a sequence (mock: push onto `blocks`).
|
||||
fn seq_add_list(seq: &CHandle, list: &CHandle) {
|
||||
unsafe {
|
||||
get_mut::<MockNode>(seq).unwrap().blocks.push(addr(list));
|
||||
}
|
||||
}
|
||||
@@ -1,463 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! C ABI contract tests for the `#[no_mangle]` exports in
|
||||
//! `src/ffi.rs`. Each export family is pinned with one normal and one
|
||||
//! error path; the exhaustive matrix is driven by the existing C++
|
||||
//! gtest suite (`src/timeline/tests`) running against this crate.
|
||||
//! Value-enum `displaymode.h` exports nothing, so it is covered purely
|
||||
//! by constant compatibility, not by functions.
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use std::ffi::{c_char, c_int, CStr, CString};
|
||||
|
||||
use oaktimeline::bridge::teststubs::{MockKind, MockNode};
|
||||
use oaktimeline::common::{MovementMode, ThumbnailMode, WaveformMode};
|
||||
use oaktimeline::error::{
|
||||
OAKTIMELINE_E_FAILED, OAKTIMELINE_E_INVALID, OAKTIMELINE_E_NOMEM, OAKTIMELINE_E_NOT_FOUND,
|
||||
OAKTIMELINE_E_STATE, OAKTIMELINE_OK,
|
||||
};
|
||||
use oaktimeline::ffi;
|
||||
use oaktimeline::handle::{make_owned, CHandle};
|
||||
|
||||
/// `oaktimeline_marker_list_create` returns a valid refcounted handle
|
||||
/// stamped with the ABI version; `free` releases it without leaking.
|
||||
#[test]
|
||||
fn marker_list_create_free() {
|
||||
let mut h = unsafe { ffi::marker::oaktimeline_marker_list_create() };
|
||||
assert!(!h.is_null());
|
||||
assert_eq!(h.abi_version, 1);
|
||||
|
||||
// Free clears the handle; a second free is a harmless no-op.
|
||||
unsafe { ffi::marker::oaktimeline_marker_list_free(&mut h) };
|
||||
assert!(h.is_null());
|
||||
unsafe { ffi::marker::oaktimeline_marker_list_free(&mut h) };
|
||||
assert!(h.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_list_of` returns a handle for an owner; freeing
|
||||
/// it does not free the owner's copy.
|
||||
#[test]
|
||||
fn marker_list_of_returns_borrowed() {
|
||||
let list_h = make_owned(oaktimeline::marker::TimelineMarkerList::new());
|
||||
let owner = make_owned(MockNode {
|
||||
kind: MockKind::Node,
|
||||
markers: list_h.clone(),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
// A viewer node yields a non-null borrowed marker list handle.
|
||||
let mut borrowed = unsafe { ffi::marker::oaktimeline_marker_list_of(owner.clone()) };
|
||||
assert!(!borrowed.is_null());
|
||||
assert_eq!(borrowed.abi_version, 1);
|
||||
|
||||
// Freeing the borrowed handle does not invalidate the owner's copy.
|
||||
unsafe { ffi::marker::oaktimeline_marker_list_free(&mut borrowed) };
|
||||
assert!(borrowed.is_null());
|
||||
|
||||
// The owner still owns its marker list; it can still hand out a new one.
|
||||
let second = unsafe { ffi::marker::oaktimeline_marker_list_of(owner.clone()) };
|
||||
assert!(!second.is_null());
|
||||
|
||||
// An empty (null) owner handle is rejected as E_INVALID → null handle.
|
||||
let null_owner = CHandle::null();
|
||||
let out = unsafe { ffi::marker::oaktimeline_marker_list_of(null_owner) };
|
||||
assert!(out.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_add` appends a marker; `oaktimeline_marker_count`
|
||||
/// reflects it and `oaktimeline_marker_at` reads it back out.
|
||||
#[test]
|
||||
fn marker_add_count_at() {
|
||||
let h = unsafe { ffi::marker::oaktimeline_marker_list_create() };
|
||||
assert!(!h.is_null());
|
||||
|
||||
let name = CString::new("mark").unwrap();
|
||||
let r =
|
||||
unsafe { ffi::marker::oaktimeline_marker_add(h.clone(), 10, 1, 20, 1, name.as_ptr(), 3) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
|
||||
let mut count = 0;
|
||||
let r = unsafe { ffi::marker::oaktimeline_marker_count(h.clone(), &mut count) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
assert_eq!(count, 1);
|
||||
|
||||
let mut in_num = 0;
|
||||
let mut in_den = 0;
|
||||
let mut out_num = 0;
|
||||
let mut out_den = 0;
|
||||
let mut color = 0;
|
||||
let mut buf = [0 as c_char; 32];
|
||||
let needed = unsafe {
|
||||
ffi::marker::oaktimeline_marker_at(
|
||||
h.clone(),
|
||||
0,
|
||||
&mut in_num,
|
||||
&mut in_den,
|
||||
&mut out_num,
|
||||
&mut out_den,
|
||||
&mut color,
|
||||
buf.as_mut_ptr(),
|
||||
buf.len() as c_int,
|
||||
)
|
||||
};
|
||||
assert!(needed > 0);
|
||||
assert_eq!(in_num, 10);
|
||||
assert_eq!(in_den, 1);
|
||||
assert_eq!(out_num, 20);
|
||||
assert_eq!(out_den, 1);
|
||||
assert_eq!(color, 3);
|
||||
let read = unsafe { CStr::from_ptr(buf.as_ptr()) }.to_string_lossy();
|
||||
assert_eq!(read, "mark");
|
||||
// `needed` is the name length + NUL terminator.
|
||||
assert_eq!(needed as usize, "mark".len() + 1);
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_at` with an out-of-range index returns
|
||||
/// `OAKTIMELINE_E_NOT_FOUND` and leaves outputs untouched.
|
||||
#[test]
|
||||
fn marker_at_out_of_range_errors() {
|
||||
let h = unsafe { ffi::marker::oaktimeline_marker_list_create() };
|
||||
|
||||
let mut in_num = 99;
|
||||
let mut in_den = 99;
|
||||
let mut out_num = 99;
|
||||
let mut out_den = 99;
|
||||
let mut color = 99;
|
||||
let mut buf = [1 as c_char; 32];
|
||||
let r = unsafe {
|
||||
ffi::marker::oaktimeline_marker_at(
|
||||
h.clone(),
|
||||
7, // out of range (empty list)
|
||||
&mut in_num,
|
||||
&mut in_den,
|
||||
&mut out_num,
|
||||
&mut out_den,
|
||||
&mut color,
|
||||
buf.as_mut_ptr(),
|
||||
buf.len() as c_int,
|
||||
)
|
||||
};
|
||||
assert_eq!(r, OAKTIMELINE_E_NOT_FOUND);
|
||||
// Outputs are left untouched.
|
||||
assert_eq!(in_num, 99);
|
||||
assert_eq!(in_den, 99);
|
||||
assert_eq!(out_num, 99);
|
||||
assert_eq!(out_den, 99);
|
||||
assert_eq!(color, 99);
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_add_command`/`remove_at_command`/
|
||||
/// `set_time_command`/`set_props_command` box into undo handles; a
|
||||
/// null list yields `OAKTIMELINE_E_INVALID` (or a null handle).
|
||||
#[test]
|
||||
fn marker_commands_validate_list() {
|
||||
let null_list = CHandle::null();
|
||||
|
||||
// Null list → null command handle (E_INVALID).
|
||||
let add = unsafe {
|
||||
ffi::marker::oaktimeline_marker_add_command(
|
||||
null_list.clone(),
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
std::ptr::null(),
|
||||
0,
|
||||
)
|
||||
};
|
||||
assert!(add.is_null());
|
||||
|
||||
let remove = unsafe { ffi::marker::oaktimeline_marker_remove_at_command(null_list.clone(), 0) };
|
||||
assert!(remove.is_null());
|
||||
|
||||
let set_time = unsafe {
|
||||
ffi::marker::oaktimeline_marker_set_time_command(null_list.clone(), 0, 0, 1, 0, 1)
|
||||
};
|
||||
assert!(set_time.is_null());
|
||||
|
||||
let set_props = unsafe {
|
||||
ffi::marker::oaktimeline_marker_set_props_command(null_list.clone(), 0, 0, std::ptr::null())
|
||||
};
|
||||
assert!(set_props.is_null());
|
||||
|
||||
// A valid list produces a non-null command handle; out-of-range indices
|
||||
// on an empty list produce null handles (E_NOT_FOUND).
|
||||
let list = unsafe { ffi::marker::oaktimeline_marker_list_create() };
|
||||
assert!(!list.is_null());
|
||||
|
||||
let name = CString::new("m").unwrap();
|
||||
let add_ok = unsafe {
|
||||
ffi::marker::oaktimeline_marker_add_command(list.clone(), 0, 1, 1, 1, name.as_ptr(), 5)
|
||||
};
|
||||
assert!(!add_ok.is_null());
|
||||
|
||||
// Empty list: any index is out of range → null handle.
|
||||
let remove_empty =
|
||||
unsafe { ffi::marker::oaktimeline_marker_remove_at_command(list.clone(), 0) };
|
||||
assert!(remove_empty.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_create`/`free` mirror the marker list
|
||||
/// lifecycle.
|
||||
#[test]
|
||||
fn workarea_create_free() {
|
||||
let mut w = unsafe { ffi::workarea::oaktimeline_workarea_create() };
|
||||
assert!(!w.is_null());
|
||||
assert_eq!(w.abi_version, 1);
|
||||
|
||||
unsafe { ffi::workarea::oaktimeline_workarea_free(&mut w) };
|
||||
assert!(w.is_null());
|
||||
// Double free is a harmless no-op.
|
||||
unsafe { ffi::workarea::oaktimeline_workarea_free(&mut w) };
|
||||
assert!(w.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_set_enabled`/`get` round-trip the enabled
|
||||
/// flag; `get` reports the range through its out-params.
|
||||
#[test]
|
||||
fn workarea_set_get_range() {
|
||||
let w = unsafe { ffi::workarea::oaktimeline_workarea_create() };
|
||||
assert!(!w.is_null());
|
||||
|
||||
let r = unsafe { ffi::workarea::oaktimeline_workarea_set_enabled(w.clone(), 1) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
let r = unsafe { ffi::workarea::oaktimeline_workarea_set_range(w.clone(), 10, 1, 20, 1) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
|
||||
let mut in_num = 0;
|
||||
let mut in_den = 0;
|
||||
let mut out_num = 0;
|
||||
let mut out_den = 0;
|
||||
let mut enabled = 0;
|
||||
let r = unsafe {
|
||||
ffi::workarea::oaktimeline_workarea_get(
|
||||
w.clone(),
|
||||
&mut in_num,
|
||||
&mut in_den,
|
||||
&mut out_num,
|
||||
&mut out_den,
|
||||
&mut enabled,
|
||||
)
|
||||
};
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
assert_eq!(in_num, 10);
|
||||
assert_eq!(in_den, 1);
|
||||
assert_eq!(out_num, 20);
|
||||
assert_eq!(out_den, 1);
|
||||
assert_eq!(enabled, 1);
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_set_range` with an invalid (null) handle
|
||||
/// returns `OAKTIMELINE_E_INVALID`.
|
||||
#[test]
|
||||
fn workarea_set_range_invalid_handle() {
|
||||
let r = unsafe { ffi::workarea::oaktimeline_workarea_set_range(CHandle::null(), 10, 1, 20, 1) };
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
|
||||
let r = unsafe { ffi::workarea::oaktimeline_workarea_set_enabled(CHandle::null(), 1) };
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_reset` clears a set range back to the reset
|
||||
/// sentinel.
|
||||
#[test]
|
||||
fn workarea_reset_clears_range() {
|
||||
let w = unsafe { ffi::workarea::oaktimeline_workarea_create() };
|
||||
unsafe { ffi::workarea::oaktimeline_workarea_set_range(w.clone(), 10, 1, 20, 1) };
|
||||
|
||||
let mut in_num = 0;
|
||||
let mut in_den = 0;
|
||||
let mut out_num = 0;
|
||||
let mut out_den = 0;
|
||||
let r = unsafe {
|
||||
ffi::workarea::oaktimeline_workarea_reset(
|
||||
&mut in_num,
|
||||
&mut in_den,
|
||||
&mut out_num,
|
||||
&mut out_den,
|
||||
)
|
||||
};
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
assert_eq!(in_num, 0);
|
||||
assert_eq!(in_den, 1);
|
||||
assert_eq!(out_num, 2147483647);
|
||||
assert_eq!(out_den, 1);
|
||||
}
|
||||
|
||||
/// `oaktimeline_add_track_command`/`remove_track_command`/
|
||||
/// `place_block_command`/`trim_command`/`split_command`/`slide_command`
|
||||
/// each return a CHandle and validate their inputs.
|
||||
#[test]
|
||||
fn edit_exports_return_handles() {
|
||||
let null = CHandle::null();
|
||||
|
||||
// Invalid inputs yield null command handles.
|
||||
assert!(unsafe { ffi::edit::oaktimeline_add_track_command(null.clone()) }.is_null());
|
||||
assert!(unsafe { ffi::edit::oaktimeline_remove_track_command(null.clone()) }.is_null());
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_place_block_command(null.clone(), 0, null.clone(), 0, 1)
|
||||
}
|
||||
.is_null());
|
||||
assert!(
|
||||
unsafe { ffi::edit::oaktimeline_trim_command(null.clone(), null.clone(), 0, 1, 2) }
|
||||
.is_null()
|
||||
);
|
||||
|
||||
// Valid handles produce non-null command handles. The mock nodes let
|
||||
// the command constructors box without dereferencing graph state.
|
||||
let tracklist = make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
..Default::default()
|
||||
});
|
||||
let track = make_owned(MockNode {
|
||||
kind: MockKind::Track,
|
||||
..Default::default()
|
||||
});
|
||||
let block = make_owned(MockNode {
|
||||
kind: MockKind::Clip,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
let add = unsafe { ffi::edit::oaktimeline_add_track_command(tracklist.clone()) };
|
||||
assert!(!add.is_null());
|
||||
let remove = unsafe { ffi::edit::oaktimeline_remove_track_command(track.clone()) };
|
||||
assert!(!remove.is_null());
|
||||
let place = unsafe {
|
||||
ffi::edit::oaktimeline_place_block_command(tracklist.clone(), 0, block.clone(), 0, 1)
|
||||
};
|
||||
assert!(!place.is_null());
|
||||
let trim =
|
||||
unsafe { ffi::edit::oaktimeline_trim_command(track.clone(), block.clone(), 10, 1, 2) };
|
||||
assert!(!trim.is_null());
|
||||
|
||||
// split_command boxes into a multi command (mock returns a handle).
|
||||
let blocks = [block.clone()];
|
||||
let split = unsafe { ffi::edit::oaktimeline_split_command(blocks.as_ptr(), 1, 5, 1) };
|
||||
assert!(!split.is_null());
|
||||
|
||||
// slide_command with a block array.
|
||||
let slide_blocks = [block.clone()];
|
||||
let slide = unsafe {
|
||||
ffi::edit::oaktimeline_slide_command(
|
||||
track.clone(),
|
||||
slide_blocks.as_ptr(),
|
||||
1,
|
||||
null.clone(),
|
||||
null.clone(),
|
||||
0,
|
||||
1,
|
||||
)
|
||||
};
|
||||
assert!(!slide.is_null());
|
||||
|
||||
// Invalid block arrays yield null handles.
|
||||
assert!(unsafe { ffi::edit::oaktimeline_split_command(std::ptr::null(), 1, 0, 1) }.is_null());
|
||||
assert!(unsafe { ffi::edit::oaktimeline_split_command(blocks.as_ptr(), 0, 0, 1) }.is_null());
|
||||
assert!(unsafe {
|
||||
ffi::edit::oaktimeline_slide_command(
|
||||
track.clone(),
|
||||
std::ptr::null(),
|
||||
1,
|
||||
null.clone(),
|
||||
null.clone(),
|
||||
0,
|
||||
1,
|
||||
)
|
||||
}
|
||||
.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_trim_command` and `oaktimeline_place_block_command`
|
||||
/// accept rationals split into numerator/denominator pairs; a null
|
||||
/// handle is rejected with `OAKTIMELINE_E_INVALID` (a null command
|
||||
/// handle), and a non-trim movement mode is rejected the same way.
|
||||
#[test]
|
||||
fn edit_exports_validate_rationals() {
|
||||
let track = make_owned(MockNode {
|
||||
kind: MockKind::Track,
|
||||
..Default::default()
|
||||
});
|
||||
let block = make_owned(MockNode {
|
||||
kind: MockKind::Clip,
|
||||
..Default::default()
|
||||
});
|
||||
let list = make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
// Rational pairs are accepted (num/den split), returning a handle.
|
||||
let trim =
|
||||
unsafe { ffi::edit::oaktimeline_trim_command(track.clone(), block.clone(), 10, 2, 2) };
|
||||
assert!(!trim.is_null());
|
||||
|
||||
let place =
|
||||
unsafe { ffi::edit::oaktimeline_place_block_command(list.clone(), 0, block.clone(), 5, 1) };
|
||||
assert!(!place.is_null());
|
||||
|
||||
// A null track / null block is rejected with a null handle.
|
||||
let null = CHandle::null();
|
||||
assert!(
|
||||
unsafe { ffi::edit::oaktimeline_trim_command(null.clone(), block.clone(), 10, 1, 2) }
|
||||
.is_null()
|
||||
);
|
||||
assert!(
|
||||
unsafe { ffi::edit::oaktimeline_trim_command(track.clone(), null.clone(), 10, 1, 2) }
|
||||
.is_null()
|
||||
);
|
||||
|
||||
// A non-trim movement mode (Move = 1) is rejected → null handle.
|
||||
assert!(
|
||||
unsafe { ffi::edit::oaktimeline_trim_command(track.clone(), block.clone(), 10, 1, 1) }
|
||||
.is_null()
|
||||
);
|
||||
}
|
||||
|
||||
/// The exported `OAKTIMELINE_*` error constants match the -MMCCCC
|
||||
/// scheme for module 04.
|
||||
#[test]
|
||||
fn error_constants_match_scheme() {
|
||||
assert_eq!(OAKTIMELINE_OK, 0);
|
||||
assert_eq!(OAKTIMELINE_E_INVALID, -40001);
|
||||
assert_eq!(OAKTIMELINE_E_STATE, -40002);
|
||||
assert_eq!(OAKTIMELINE_E_FAILED, -40003);
|
||||
assert_eq!(OAKTIMELINE_E_NOT_FOUND, -40004);
|
||||
assert_eq!(OAKTIMELINE_E_NOMEM, -40005);
|
||||
}
|
||||
|
||||
/// `displaymode.h` has no functions; only the value enums are
|
||||
/// exported. This test pins that the enum constants are in range and
|
||||
/// stable.
|
||||
#[test]
|
||||
fn displaymode_constants_are_stable() {
|
||||
// OAK_TIMELINE_THUMBNAIL_OFF/IN_OUT/ON = 0/1/2.
|
||||
assert_eq!(ThumbnailMode::Off as i32, 0);
|
||||
assert_eq!(ThumbnailMode::InOut as i32, 1);
|
||||
assert_eq!(ThumbnailMode::On as i32, 2);
|
||||
|
||||
// OAK_TIMELINE_WAVEFORMS_DISABLED/ENABLED = 0/1.
|
||||
assert_eq!(WaveformMode::Disabled as i32, 0);
|
||||
assert_eq!(WaveformMode::Enabled as i32, 1);
|
||||
|
||||
// MovementMode round-trips through from_c_int.
|
||||
assert_eq!(MovementMode::None.to_c_int(), 0);
|
||||
assert_eq!(MovementMode::Move.to_c_int(), 1);
|
||||
assert_eq!(MovementMode::TrimIn.to_c_int(), 2);
|
||||
assert_eq!(MovementMode::TrimOut.to_c_int(), 3);
|
||||
assert_eq!(MovementMode::from_c_int(2), Some(MovementMode::TrimIn));
|
||||
assert_eq!(MovementMode::from_c_int(9), None);
|
||||
}
|
||||
@@ -1,598 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Coverage for `src/ffi.rs`: the C ABI export layer (`marker`, `workarea`
|
||||
//! and `edit` submodules). These tests drive every reachable branch of the
|
||||
//! export bodies — both the success paths (constructing command handles,
|
||||
//! enumerating markers/work areas) and the error paths (null / out-of-range /
|
||||
//! wrong inputs mapping to `Error::Invalid` / `Error::NotFound`).
|
||||
//!
|
||||
//! A few branches are unreachable through the public API with the test-stub
|
||||
//! mocks and are deliberately skipped (see the module summary):
|
||||
//! * `marker_list_of` / `workarea_of` error branch (the mock
|
||||
//! `oaknode_node_get_markers` / `oaknode_node_get_work_area` only fail on
|
||||
//! a null `ctx`, which is already rejected earlier in the export);
|
||||
//! * `marker_set_props_command` / `split_command` "multi init failed" branch
|
||||
//! (`oakundo_command_init_multi` never returns null in the mock);
|
||||
//! * `write_cstr` NULL/size<=0 guard (only ever called with a non-NULL
|
||||
//! buffer and `size >= name.len()+1`);
|
||||
//! * `xml_element_text` empty-result branch (only reached inside
|
||||
//! `workarea_load`, whose loop stops before calling it with an invalid
|
||||
//! reader).
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use std::ffi::c_char;
|
||||
use std::ffi::CString;
|
||||
|
||||
use oaktimeline::bridge::node as onode;
|
||||
use oaktimeline::bridge::teststubs::{xml_reader_handle, MockKind, MockNode, MockXmlNode};
|
||||
use oaktimeline::error::{OAKTIMELINE_E_INVALID, OAKTIMELINE_OK};
|
||||
use oaktimeline::ffi::{edit, marker, workarea};
|
||||
use oaktimeline::handle::{make_owned, CHandle};
|
||||
|
||||
// ---- helpers ---------------------------------------------------------
|
||||
|
||||
/// A NUL-terminated C string that lives for the call.
|
||||
fn cstr(s: &str) -> CString {
|
||||
CString::new(s).unwrap()
|
||||
}
|
||||
|
||||
/// A new detached video track (type 0).
|
||||
fn mk_track() -> CHandle {
|
||||
unsafe { onode::oaknode_track_create(0) }
|
||||
}
|
||||
|
||||
/// A new clip block.
|
||||
fn mk_clip() -> CHandle {
|
||||
unsafe { onode::oaknode_block_clip_create() }
|
||||
}
|
||||
|
||||
/// A new, empty owning marker list.
|
||||
fn mk_marker_list() -> CHandle {
|
||||
unsafe { marker::oaktimeline_marker_list_create() }
|
||||
}
|
||||
|
||||
/// A new, empty owning work area.
|
||||
fn mk_workarea() -> CHandle {
|
||||
unsafe { workarea::oaktimeline_workarea_create() }
|
||||
}
|
||||
|
||||
/// A new, empty owning track list of video type.
|
||||
fn mk_track_list() -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
track_type: 0,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
/// A new, empty owning sequence.
|
||||
fn mk_sequence() -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::Sequence,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
/// Add one marker to `list` (direct, no command) at in=1/1 out=5/1, color 3.
|
||||
fn add_single_marker(list: &CHandle) {
|
||||
let name = cstr("m1");
|
||||
let r = unsafe { marker::oaktimeline_marker_add(list.clone(), 1, 1, 5, 1, name.as_ptr(), 3) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
}
|
||||
|
||||
// ---- marker module ---------------------------------------------------
|
||||
|
||||
/// `oaktimeline_marker_list_create`/`marker_add`/`marker_count`/`marker_at`
|
||||
/// success paths.
|
||||
#[test]
|
||||
fn marker_create_add_count_at() {
|
||||
let list = mk_marker_list();
|
||||
add_single_marker(&list);
|
||||
|
||||
let mut count = 0;
|
||||
let r = unsafe { marker::oaktimeline_marker_count(list.clone(), &mut count) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
assert_eq!(count, 1);
|
||||
|
||||
let mut in_num = 0;
|
||||
let mut in_den = 0;
|
||||
let mut out_num = 0;
|
||||
let mut out_den = 0;
|
||||
let mut color = 0;
|
||||
let mut name_buf = [0 as c_char; 64];
|
||||
let needed = unsafe {
|
||||
marker::oaktimeline_marker_at(
|
||||
list.clone(),
|
||||
0,
|
||||
&mut in_num,
|
||||
&mut in_den,
|
||||
&mut out_num,
|
||||
&mut out_den,
|
||||
&mut color,
|
||||
name_buf.as_mut_ptr(),
|
||||
name_buf.len() as i32,
|
||||
)
|
||||
};
|
||||
assert!(needed > 0, "two-stage name length must be positive");
|
||||
assert_eq!(in_num, 1);
|
||||
assert_eq!(out_num, 5);
|
||||
assert_eq!(color, 3);
|
||||
}
|
||||
|
||||
/// Null-list error paths for `marker_add`/`marker_count`/`marker_at`.
|
||||
#[test]
|
||||
fn marker_null_list_errors() {
|
||||
let name = cstr("x");
|
||||
let r =
|
||||
unsafe { marker::oaktimeline_marker_add(CHandle::null(), 1, 1, 5, 1, name.as_ptr(), 0) };
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
|
||||
let mut count = 0;
|
||||
let r = unsafe { marker::oaktimeline_marker_count(CHandle::null(), &mut count) };
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
|
||||
let mut out = 0;
|
||||
let r = unsafe {
|
||||
marker::oaktimeline_marker_at(
|
||||
CHandle::null(),
|
||||
0,
|
||||
&mut out,
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
0,
|
||||
)
|
||||
};
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_remove_at_command` success path (in-bounds index).
|
||||
#[test]
|
||||
fn marker_remove_at_command_success() {
|
||||
let list = mk_marker_list();
|
||||
add_single_marker(&list);
|
||||
let h = unsafe { marker::oaktimeline_marker_remove_at_command(list.clone(), 0) };
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_set_time_command` success and out-of-range paths.
|
||||
#[test]
|
||||
fn marker_set_time_command() {
|
||||
let list = mk_marker_list();
|
||||
add_single_marker(&list);
|
||||
|
||||
// Success: in-bounds index returns an owning command handle.
|
||||
let h = unsafe { marker::oaktimeline_marker_set_time_command(list.clone(), 0, 2, 1, 6, 1) };
|
||||
assert!(!h.is_null());
|
||||
|
||||
// Out-of-range index -> NotFound.
|
||||
let h2 = unsafe { marker::oaktimeline_marker_set_time_command(list.clone(), 9, 2, 1, 6, 1) };
|
||||
assert!(h2.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_set_props_command` covers every branch: combined
|
||||
/// color+name (multi command), color-only, name-only, the invalid
|
||||
/// color<0&name==NULL case, and the out-of-range NotFound case.
|
||||
#[test]
|
||||
fn marker_set_props_command_branches() {
|
||||
let list = mk_marker_list();
|
||||
add_single_marker(&list);
|
||||
|
||||
// Combined color + name -> multi command.
|
||||
let name = cstr("renamed");
|
||||
let h =
|
||||
unsafe { marker::oaktimeline_marker_set_props_command(list.clone(), 0, 7, name.as_ptr()) };
|
||||
assert!(!h.is_null());
|
||||
|
||||
// Color-only (name == NULL) -> color child; also exercises the
|
||||
// `cstr_to_string(NULL)` empty-string path.
|
||||
let h = unsafe {
|
||||
marker::oaktimeline_marker_set_props_command(list.clone(), 0, 9, std::ptr::null())
|
||||
};
|
||||
assert!(!h.is_null());
|
||||
|
||||
// Name-only (color < 0) -> name child.
|
||||
let name = cstr("onlyname");
|
||||
let h =
|
||||
unsafe { marker::oaktimeline_marker_set_props_command(list.clone(), 0, -1, name.as_ptr()) };
|
||||
assert!(!h.is_null());
|
||||
|
||||
// color < 0 AND name == NULL -> Invalid.
|
||||
let h = unsafe {
|
||||
marker::oaktimeline_marker_set_props_command(list.clone(), 0, -1, std::ptr::null())
|
||||
};
|
||||
assert!(h.is_null());
|
||||
|
||||
// Out-of-range index -> NotFound.
|
||||
let name = cstr("x");
|
||||
let h =
|
||||
unsafe { marker::oaktimeline_marker_set_props_command(list.clone(), 50, 1, name.as_ptr()) };
|
||||
assert!(h.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_list_of` with a null owner and with a viewer node
|
||||
/// whose marker list is populated.
|
||||
#[test]
|
||||
fn marker_list_of() {
|
||||
// Null owner -> null handle.
|
||||
let h = unsafe { marker::oaktimeline_marker_list_of(CHandle::null()) };
|
||||
assert!(h.is_null());
|
||||
|
||||
// A node carrying a marker list -> borrowed non-null handle.
|
||||
let inner = mk_marker_list();
|
||||
let owner = make_owned(MockNode {
|
||||
kind: MockKind::Node,
|
||||
markers: inner.clone(),
|
||||
..Default::default()
|
||||
});
|
||||
let h = unsafe { marker::oaktimeline_marker_list_of(owner.clone()) };
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_list_load` / `oaktimeline_marker_list_save` with
|
||||
/// null arguments.
|
||||
#[test]
|
||||
fn marker_list_load_save_null() {
|
||||
let list = mk_marker_list();
|
||||
// Null list (reader also null) -> Invalid.
|
||||
let r = unsafe { marker::oaktimeline_marker_list_load(CHandle::null(), CHandle::null()) };
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
// Null list for save -> Invalid.
|
||||
let r = unsafe { marker::oaktimeline_marker_list_save(CHandle::null(), CHandle::null()) };
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
// Null reader / writer (valid list) -> Invalid.
|
||||
let r = unsafe { marker::oaktimeline_marker_list_load(list.clone(), CHandle::null()) };
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
let r = unsafe { marker::oaktimeline_marker_list_save(list.clone(), CHandle::null()) };
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_list_load` over a reader with a marker element and a
|
||||
/// non-marker element (exercises the skip/`other` path).
|
||||
#[test]
|
||||
fn marker_list_load_reader() {
|
||||
let list = mk_marker_list();
|
||||
let reader = xml_reader_handle(vec![
|
||||
MockXmlNode {
|
||||
name: "other".into(),
|
||||
text: String::new(),
|
||||
attrs: vec![],
|
||||
},
|
||||
MockXmlNode {
|
||||
name: "marker".into(),
|
||||
text: String::new(),
|
||||
attrs: vec![("name".into(), "m2".into()), ("color".into(), "5".into())],
|
||||
},
|
||||
]);
|
||||
let r = unsafe { marker::oaktimeline_marker_list_load(list.clone(), reader.clone()) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
|
||||
let mut count = 0;
|
||||
unsafe { marker::oaktimeline_marker_count(list.clone(), &mut count) };
|
||||
assert_eq!(count, 1);
|
||||
}
|
||||
|
||||
/// `oaktimeline_marker_list_save` over a writer with a marker present.
|
||||
#[test]
|
||||
fn marker_list_save_writer() {
|
||||
let list = mk_marker_list();
|
||||
add_single_marker(&list);
|
||||
let writer = unsafe { oaktimeline::bridge::common::oakcommon_xml_writer_init() };
|
||||
let r = unsafe { marker::oaktimeline_marker_list_save(list.clone(), writer.clone()) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
}
|
||||
|
||||
// ---- workarea module -------------------------------------------------
|
||||
|
||||
/// `oaktimeline_workarea_of` with a null owner and with a viewer node whose
|
||||
/// work area is populated.
|
||||
#[test]
|
||||
fn workarea_of() {
|
||||
// Null owner -> null handle.
|
||||
let h = unsafe { workarea::oaktimeline_workarea_of(CHandle::null()) };
|
||||
assert!(h.is_null());
|
||||
|
||||
// A node carrying a work area -> borrowed non-null handle.
|
||||
let inner = mk_workarea();
|
||||
let owner = make_owned(MockNode {
|
||||
kind: MockKind::Node,
|
||||
work_area: inner.clone(),
|
||||
..Default::default()
|
||||
});
|
||||
let h = unsafe { workarea::oaktimeline_workarea_of(owner.clone()) };
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_get` null-handle error path.
|
||||
#[test]
|
||||
fn workarea_get_null() {
|
||||
let r = unsafe {
|
||||
workarea::oaktimeline_workarea_get(
|
||||
CHandle::null(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_set_range_command` null and valid paths.
|
||||
#[test]
|
||||
fn workarea_set_range_command() {
|
||||
// Null work area -> null handle.
|
||||
let h = unsafe {
|
||||
workarea::oaktimeline_workarea_set_range_command(CHandle::null(), 1, 1, 2, 1, 0, 1, 1, 1)
|
||||
};
|
||||
assert!(h.is_null());
|
||||
|
||||
// Valid work area -> owning command handle.
|
||||
let w = mk_workarea();
|
||||
let h = unsafe {
|
||||
workarea::oaktimeline_workarea_set_range_command(w.clone(), 1, 1, 2, 1, 0, 1, 1, 1)
|
||||
};
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_set_enabled_command` null and valid paths.
|
||||
#[test]
|
||||
fn workarea_set_enabled_command() {
|
||||
let h = unsafe { workarea::oaktimeline_workarea_set_enabled_command(CHandle::null(), 1) };
|
||||
assert!(h.is_null());
|
||||
|
||||
let w = mk_workarea();
|
||||
let h = unsafe { workarea::oaktimeline_workarea_set_enabled_command(w.clone(), 1) };
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_reset` null-pointer and success paths.
|
||||
#[test]
|
||||
fn workarea_reset() {
|
||||
// A null out pointer -> Invalid.
|
||||
let r = unsafe {
|
||||
workarea::oaktimeline_workarea_reset(
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
|
||||
// Success: all four out params are filled.
|
||||
let mut in_num = 0;
|
||||
let mut in_den = 0;
|
||||
let mut out_num = 0;
|
||||
let mut out_den = 0;
|
||||
let r = unsafe {
|
||||
workarea::oaktimeline_workarea_reset(&mut in_num, &mut in_den, &mut out_num, &mut out_den)
|
||||
};
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
// reset sentinel: in = 0/1, out = RATIONAL_MAX (2147483647/1).
|
||||
assert_eq!(in_num, 0);
|
||||
assert_eq!(in_den, 1);
|
||||
assert_eq!(out_num, 2147483647);
|
||||
assert_eq!(out_den, 1);
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_load` null-path and the unknown-element skip branch.
|
||||
#[test]
|
||||
fn workarea_load() {
|
||||
// Null work area (and reader) -> Invalid.
|
||||
let r = unsafe { workarea::oaktimeline_workarea_load(CHandle::null(), CHandle::null()) };
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
|
||||
// Null reader with a valid work area -> Invalid.
|
||||
let w = mk_workarea();
|
||||
let r = unsafe { workarea::oaktimeline_workarea_load(w.clone(), CHandle::null()) };
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
|
||||
// A reader with an unknown element hits the else/skip branch.
|
||||
let reader = xml_reader_handle(vec![MockXmlNode {
|
||||
name: "bogus".into(),
|
||||
text: String::new(),
|
||||
attrs: vec![],
|
||||
}]);
|
||||
let r = unsafe { workarea::oaktimeline_workarea_load(w.clone(), reader.clone()) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
}
|
||||
|
||||
/// `oaktimeline_workarea_save` null-path and writer success path.
|
||||
#[test]
|
||||
fn workarea_save() {
|
||||
let r = unsafe { workarea::oaktimeline_workarea_save(CHandle::null(), CHandle::null()) };
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
|
||||
let w = mk_workarea();
|
||||
let r = unsafe { workarea::oaktimeline_workarea_save(w.clone(), CHandle::null()) };
|
||||
assert_eq!(r, OAKTIMELINE_E_INVALID);
|
||||
|
||||
let writer = unsafe { oaktimeline::bridge::common::oakcommon_xml_writer_init() };
|
||||
let r = unsafe { workarea::oaktimeline_workarea_save(w.clone(), writer.clone()) };
|
||||
assert_eq!(r, OAKTIMELINE_OK);
|
||||
}
|
||||
|
||||
// ---- edit module -----------------------------------------------------
|
||||
|
||||
/// `oaktimeline_replace_block_with_gap_command` null and valid paths.
|
||||
#[test]
|
||||
fn replace_block_with_gap_command() {
|
||||
// Null track -> null handle.
|
||||
let b = mk_clip();
|
||||
let h = unsafe { edit::oaktimeline_replace_block_with_gap_command(CHandle::null(), b.clone()) };
|
||||
assert!(h.is_null());
|
||||
// Null block -> null handle.
|
||||
let t = mk_track();
|
||||
let h = unsafe { edit::oaktimeline_replace_block_with_gap_command(t.clone(), CHandle::null()) };
|
||||
assert!(h.is_null());
|
||||
|
||||
// Valid track + block -> owning command handle.
|
||||
let h = unsafe { edit::oaktimeline_replace_block_with_gap_command(t.clone(), b.clone()) };
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_move_block_command` null and valid paths.
|
||||
#[test]
|
||||
fn move_block_command() {
|
||||
// Null list / block -> null handle.
|
||||
let list = mk_track_list();
|
||||
let b = mk_clip();
|
||||
let h = unsafe { edit::oaktimeline_move_block_command(CHandle::null(), 0, b.clone(), 10, 1) };
|
||||
assert!(h.is_null());
|
||||
let h =
|
||||
unsafe { edit::oaktimeline_move_block_command(list.clone(), 0, CHandle::null(), 10, 1) };
|
||||
assert!(h.is_null());
|
||||
|
||||
// Valid list + block + in point -> owning command handle.
|
||||
let h = unsafe { edit::oaktimeline_move_block_command(list.clone(), 0, b.clone(), 10, 1) };
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_split_preserving_links_command` null-arg error and success.
|
||||
#[test]
|
||||
fn split_preserving_links_command() {
|
||||
// Error: null blocks / zero counts.
|
||||
let h = unsafe {
|
||||
edit::oaktimeline_split_preserving_links_command(
|
||||
std::ptr::null(),
|
||||
1,
|
||||
std::ptr::null(),
|
||||
std::ptr::null(),
|
||||
1,
|
||||
)
|
||||
};
|
||||
assert!(h.is_null());
|
||||
|
||||
// Error: blocks non-null but count <= 0.
|
||||
let blocks = [mk_clip()];
|
||||
let nums = [10i64];
|
||||
let dens = [1i64];
|
||||
let h = unsafe {
|
||||
edit::oaktimeline_split_preserving_links_command(
|
||||
blocks.as_ptr(),
|
||||
0,
|
||||
nums.as_ptr(),
|
||||
dens.as_ptr(),
|
||||
1,
|
||||
)
|
||||
};
|
||||
assert!(h.is_null());
|
||||
|
||||
// Success.
|
||||
let h = unsafe {
|
||||
edit::oaktimeline_split_preserving_links_command(
|
||||
blocks.as_ptr(),
|
||||
1,
|
||||
nums.as_ptr(),
|
||||
dens.as_ptr(),
|
||||
1,
|
||||
)
|
||||
};
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_ripple_delete_gaps_command` null-arg error and success.
|
||||
#[test]
|
||||
fn ripple_delete_gaps_command() {
|
||||
let seq = mk_sequence();
|
||||
let t = mk_track();
|
||||
let in_nums = [0i64];
|
||||
let in_dens = [1i64];
|
||||
let out_nums = [10i64];
|
||||
let out_dens = [1i64];
|
||||
let tracks = [t.clone()];
|
||||
|
||||
// Error: null sequence.
|
||||
let h = unsafe {
|
||||
edit::oaktimeline_ripple_delete_gaps_command(
|
||||
CHandle::null(),
|
||||
in_nums.as_ptr(),
|
||||
in_dens.as_ptr(),
|
||||
out_nums.as_ptr(),
|
||||
out_dens.as_ptr(),
|
||||
tracks.as_ptr(),
|
||||
1,
|
||||
)
|
||||
};
|
||||
assert!(h.is_null());
|
||||
|
||||
// Error: null arrays / range_count <= 0.
|
||||
let h = unsafe {
|
||||
edit::oaktimeline_ripple_delete_gaps_command(
|
||||
seq.clone(),
|
||||
std::ptr::null(),
|
||||
std::ptr::null(),
|
||||
std::ptr::null(),
|
||||
std::ptr::null(),
|
||||
tracks.as_ptr(),
|
||||
1,
|
||||
)
|
||||
};
|
||||
assert!(h.is_null());
|
||||
let h = unsafe {
|
||||
edit::oaktimeline_ripple_delete_gaps_command(
|
||||
seq.clone(),
|
||||
in_nums.as_ptr(),
|
||||
in_dens.as_ptr(),
|
||||
out_nums.as_ptr(),
|
||||
out_dens.as_ptr(),
|
||||
tracks.as_ptr(),
|
||||
0,
|
||||
)
|
||||
};
|
||||
assert!(h.is_null());
|
||||
|
||||
// Success.
|
||||
let h = unsafe {
|
||||
edit::oaktimeline_ripple_delete_gaps_command(
|
||||
seq.clone(),
|
||||
in_nums.as_ptr(),
|
||||
in_dens.as_ptr(),
|
||||
out_nums.as_ptr(),
|
||||
out_dens.as_ptr(),
|
||||
tracks.as_ptr(),
|
||||
1,
|
||||
)
|
||||
};
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_ripple_remove_area_command` null-track error and success.
|
||||
#[test]
|
||||
fn ripple_remove_area_command() {
|
||||
let h = unsafe { edit::oaktimeline_ripple_remove_area_command(CHandle::null(), 0, 1, 10, 1) };
|
||||
assert!(h.is_null());
|
||||
|
||||
let t = mk_track();
|
||||
let h = unsafe { edit::oaktimeline_ripple_remove_area_command(t.clone(), 0, 1, 10, 1) };
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
|
||||
/// `oaktimeline_insert_gaps_command` null-list error and success.
|
||||
#[test]
|
||||
fn insert_gaps_command() {
|
||||
let h = unsafe { edit::oaktimeline_insert_gaps_command(CHandle::null(), 5, 1, 3, 1) };
|
||||
assert!(h.is_null());
|
||||
|
||||
let list = mk_track_list();
|
||||
let h = unsafe { edit::oaktimeline_insert_gaps_command(list.clone(), 5, 1, 3, 1) };
|
||||
assert!(!h.is_null());
|
||||
}
|
||||
@@ -18,16 +18,12 @@
|
||||
//! `TimelineMarker` and `TimelineMarkerList` value types plus the five
|
||||
//! marker undo commands. The list stays sorted by time (C++
|
||||
//! `TimelineMarkerList` re-sorts on mutation), which `resort` enforces
|
||||
//! after out-of-band edits. XML load/save matches the format written
|
||||
//! by `timelinemarker.cpp`/`timelinemarkerlist.cpp`.
|
||||
#![cfg(feature = "test-stubs")]
|
||||
//! after out-of-band edits. The XML load/save contract left with the
|
||||
//! deleted C ABI export layer (single-lib unification).
|
||||
|
||||
use oakcore_rs::{Rational, TimeRange};
|
||||
use oaktimeline::bridge::common::{oakcommon_xml_writer_free, oakcommon_xml_writer_init};
|
||||
use oaktimeline::bridge::teststubs::{xml_reader_handle, MockXmlNode, MockXmlWriter};
|
||||
use oaktimeline::common::EditToInfo;
|
||||
use oaktimeline::ffi;
|
||||
use oaktimeline::handle::{get, get_mut, make_owned, CHandle};
|
||||
use oaktimeline::handle::{get, get_mut, make_owned};
|
||||
use oaktimeline::marker::{
|
||||
MarkerAddCommand, MarkerChangeColorCommand, MarkerChangeNameCommand, MarkerChangeTimeCommand,
|
||||
MarkerRemoveCommand, TimelineMarker, TimelineMarkerList,
|
||||
@@ -592,10 +588,12 @@ fn marker_change_time_command_redo_undo() {
|
||||
);
|
||||
}
|
||||
|
||||
/// `to_command` boxes a marker command into a CHandle for the undo
|
||||
/// stack, matching the C++ `OakUndoCommand` shape.
|
||||
/// `to_command` boxes a marker command into an oakundo `UndoCommand`
|
||||
/// value for the undo stack (the old C ABI command handle is gone with
|
||||
/// the single-lib unification); `redo_now`/`undo_now` drive the same
|
||||
/// redo/undo bodies the stack would.
|
||||
#[test]
|
||||
fn marker_commands_box_to_chandle() {
|
||||
fn marker_commands_box_to_undo_command() {
|
||||
let list_h = make_owned(TimelineMarkerList::new());
|
||||
{
|
||||
let l = unsafe { get_mut::<TimelineMarkerList>(&list_h) }.unwrap();
|
||||
@@ -606,81 +604,27 @@ fn marker_commands_box_to_chandle() {
|
||||
));
|
||||
}
|
||||
|
||||
let cmds: Vec<CHandle> = vec![
|
||||
MarkerAddCommand::new(
|
||||
list_h.clone(),
|
||||
TimeRange::new(Rational::new(5, 1), Rational::new(6, 1)),
|
||||
"n",
|
||||
0,
|
||||
)
|
||||
.to_command(),
|
||||
MarkerRemoveCommand::new(list_h.clone(), 0).to_command(),
|
||||
MarkerChangeColorCommand::new(list_h.clone(), 0, 7).to_command(),
|
||||
MarkerChangeNameCommand::new(list_h.clone(), 0, "z").to_command(),
|
||||
MarkerChangeTimeCommand::new(
|
||||
list_h.clone(),
|
||||
0,
|
||||
TimeRange::new(Rational::new(9, 1), Rational::new(10, 1)),
|
||||
)
|
||||
.to_command(),
|
||||
];
|
||||
for h in &cmds {
|
||||
assert!(!h.is_null());
|
||||
assert_eq!(h.abi_version, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// Save writes `<marker name= in= out= color=/>` elements; load parses
|
||||
/// them back into an equal list (XML golden round-trip).
|
||||
#[test]
|
||||
fn marker_list_xml_round_trip() {
|
||||
// Set up a list with one marker.
|
||||
let list_h = make_owned(TimelineMarkerList::new());
|
||||
{
|
||||
let l = unsafe { get_mut::<TimelineMarkerList>(&list_h) }.unwrap();
|
||||
l.add_marker(TimelineMarker::with_time(
|
||||
3,
|
||||
TimeRange::new(Rational::new(10, 1), Rational::new(20, 1)),
|
||||
"m",
|
||||
));
|
||||
}
|
||||
|
||||
// Save into a mock writer.
|
||||
let mut writer = unsafe { oakcommon_xml_writer_init() };
|
||||
let r = unsafe { ffi::marker::oaktimeline_marker_list_save(list_h.clone(), writer.clone()) };
|
||||
assert_eq!(r, 0);
|
||||
let buf = unsafe { get::<MockXmlWriter>(&writer) }
|
||||
.unwrap()
|
||||
.buf
|
||||
.clone();
|
||||
assert!(buf.contains("<marker"), "buf: {buf}");
|
||||
assert!(buf.contains("name=\"m\""), "buf: {buf}");
|
||||
assert!(buf.contains("in=\"10/1\""), "buf: {buf}");
|
||||
assert!(buf.contains("out=\"20/1\""), "buf: {buf}");
|
||||
assert!(buf.contains("color=\"3\""), "buf: {buf}");
|
||||
unsafe { oakcommon_xml_writer_free(&mut writer) };
|
||||
|
||||
// Load back from a mock reader into a fresh list.
|
||||
let reader = xml_reader_handle(vec![MockXmlNode {
|
||||
name: "marker".to_string(),
|
||||
text: String::new(),
|
||||
attrs: vec![
|
||||
("name".to_string(), "m".to_string()),
|
||||
("in".to_string(), "10/1".to_string()),
|
||||
("out".to_string(), "20/1".to_string()),
|
||||
("color".to_string(), "3".to_string()),
|
||||
],
|
||||
}]);
|
||||
let list2_h = make_owned(TimelineMarkerList::new());
|
||||
let r2 = unsafe { ffi::marker::oaktimeline_marker_list_load(list2_h.clone(), reader.clone()) };
|
||||
assert_eq!(r2, 0);
|
||||
let l2 = unsafe { get::<TimelineMarkerList>(&list2_h) }.unwrap();
|
||||
assert_eq!(l2.size(), 1);
|
||||
let m = l2.at(0).unwrap();
|
||||
assert_eq!(m.name(), "m");
|
||||
assert_eq!(m.color(), 3);
|
||||
assert_eq!(m.time().in_(), Rational::new(10, 1));
|
||||
assert_eq!(m.time().out(), Rational::new(20, 1));
|
||||
let mut cmd = MarkerAddCommand::new(
|
||||
list_h.clone(),
|
||||
TimeRange::new(Rational::new(5, 1), Rational::new(6, 1)),
|
||||
"n",
|
||||
0,
|
||||
)
|
||||
.to_command();
|
||||
cmd.redo_now();
|
||||
assert_eq!(
|
||||
unsafe { get::<TimelineMarkerList>(&list_h) }
|
||||
.unwrap()
|
||||
.size(),
|
||||
2
|
||||
);
|
||||
cmd.undo_now();
|
||||
assert_eq!(
|
||||
unsafe { get::<TimelineMarkerList>(&list_h) }
|
||||
.unwrap()
|
||||
.size(),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
/// Loading a marker with a `color`/`in`/`out` attribute equal to the
|
||||
@@ -692,14 +636,15 @@ fn marker_defaults_map_to_edit_to_info() {
|
||||
assert_eq!(m.color(), 0);
|
||||
assert_eq!(m.time().in_(), Rational::new(0, 1));
|
||||
|
||||
// `EditToInfo` defaults mirror those sentinels: null handles and the
|
||||
// `EditToInfo` defaults mirror those sentinels: null node references
|
||||
// (`None`, the single-lib replacement for the null `CHandle`) and the
|
||||
// null rational for `nearest_time`.
|
||||
let info = EditToInfo {
|
||||
track: CHandle::null(),
|
||||
track: None,
|
||||
nearest_time: m.time().in_(),
|
||||
nearest_block: CHandle::null(),
|
||||
nearest_block: None,
|
||||
};
|
||||
assert!(info.track.is_null());
|
||||
assert!(info.nearest_block.is_null());
|
||||
assert!(info.track.is_none());
|
||||
assert!(info.nearest_block.is_none());
|
||||
assert_eq!(info.nearest_time, Rational::new(0, 1));
|
||||
}
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Coverage for the shared node-removal helpers and command wrappers
|
||||
//! (`src/undocommon.rs`): removal capability checks, remove-command
|
||||
//! factories, `CHandleCommandWrapper`, and `MultiUndoCommand`.
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use oakcore_rs::{Rational, TimeRange};
|
||||
|
||||
use oaktimeline::bridge::node::{oaknode_block_clip_create, oaknode_block_gap_create};
|
||||
use oaktimeline::bridge::teststubs::MockNode;
|
||||
use oaktimeline::handle::{get, make_owned, CHandle};
|
||||
use oaktimeline::marker::{MarkerAddCommand, TimelineMarkerList};
|
||||
use oaktimeline::undocommon::{
|
||||
block_can_be_removed, create_and_run_block_remove_command, create_and_run_remove_command,
|
||||
create_block_remove_command, create_remove_command, free_command_handle, node_can_be_removed,
|
||||
CHandleCommandWrapper, Command, MultiUndoCommand,
|
||||
};
|
||||
use oaktimeline::workarea::{TimelineWorkArea, WorkareaSetEnabledCommand};
|
||||
|
||||
/// `node_can_be_removed` is true for a node with no output connections and
|
||||
/// false once it has any.
|
||||
#[test]
|
||||
fn node_can_be_removed_toggles_on_connections() {
|
||||
let free = make_owned(MockNode {
|
||||
output_conns: 0,
|
||||
..Default::default()
|
||||
});
|
||||
assert!(node_can_be_removed(free));
|
||||
|
||||
let busy = make_owned(MockNode {
|
||||
output_conns: 1,
|
||||
..Default::default()
|
||||
});
|
||||
assert!(!node_can_be_removed(busy));
|
||||
}
|
||||
|
||||
/// `block_can_be_removed` delegates through the block's generic-node view.
|
||||
#[test]
|
||||
fn block_can_be_removed_by_connections() {
|
||||
let clip = make_owned(MockNode {
|
||||
output_conns: 0,
|
||||
..Default::default()
|
||||
});
|
||||
assert!(block_can_be_removed(clip));
|
||||
|
||||
let gap = make_owned(MockNode {
|
||||
output_conns: 2,
|
||||
..Default::default()
|
||||
});
|
||||
assert!(!block_can_be_removed(gap));
|
||||
}
|
||||
|
||||
/// Remove-command factories box a non-null command handle.
|
||||
#[test]
|
||||
fn create_remove_commands_box_non_null() {
|
||||
let node = make_owned(MockNode::default());
|
||||
assert!(!create_remove_command(node.clone()).is_null());
|
||||
|
||||
let block = unsafe { oaknode_block_clip_create() };
|
||||
assert!(!create_block_remove_command(block).is_null());
|
||||
|
||||
assert!(!create_and_run_remove_command(node).is_null());
|
||||
|
||||
let gap = unsafe { oaknode_block_gap_create() };
|
||||
assert!(!create_and_run_block_remove_command(gap).is_null());
|
||||
}
|
||||
|
||||
/// `free_command_handle` is a no-op on a null pointer and clears a live
|
||||
/// command handle.
|
||||
#[test]
|
||||
fn free_command_handle_null_and_live() {
|
||||
free_command_handle(std::ptr::null_mut());
|
||||
|
||||
let node = make_owned(MockNode::default());
|
||||
let mut cmd = create_remove_command(node);
|
||||
assert!(!cmd.is_null());
|
||||
free_command_handle(&mut cmd);
|
||||
assert!(cmd.ctx.is_null());
|
||||
}
|
||||
|
||||
/// `CHandleCommandWrapper` forwards redo/undo to the wrapped command and
|
||||
/// reports validity; an empty wrapper is inert.
|
||||
#[test]
|
||||
fn command_wrapper_forwards_redo_undo() {
|
||||
let wa_h = make_owned(TimelineWorkArea::new());
|
||||
let cmd = WorkareaSetEnabledCommand::new(wa_h.clone(), true).to_command();
|
||||
|
||||
let mut w = CHandleCommandWrapper::new(cmd);
|
||||
assert!(w.is_valid());
|
||||
w.redo();
|
||||
assert!(unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().enabled());
|
||||
w.undo();
|
||||
assert!(!unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().enabled());
|
||||
|
||||
// An empty wrapper is invalid and its methods are no-ops.
|
||||
let mut empty = CHandleCommandWrapper::new(CHandle::null());
|
||||
assert!(!empty.is_valid());
|
||||
empty.redo();
|
||||
empty.undo();
|
||||
// Dropping `empty` and `w` frees the handles without panicking.
|
||||
}
|
||||
|
||||
/// `MultiUndoCommand` runs children in order on redo and reverse on undo.
|
||||
#[test]
|
||||
fn multi_undo_command_runs_children() {
|
||||
let list_h = make_owned(TimelineMarkerList::new());
|
||||
let mut multi = MultiUndoCommand::new();
|
||||
assert!(multi.empty());
|
||||
|
||||
multi.add_child(Box::new(MarkerAddCommand::new(
|
||||
list_h.clone(),
|
||||
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
|
||||
"m",
|
||||
0,
|
||||
)) as Box<dyn Command>);
|
||||
multi.add_child(Box::new(MarkerAddCommand::new(
|
||||
list_h.clone(),
|
||||
TimeRange::new(Rational::new(5, 1), Rational::new(6, 1)),
|
||||
"n",
|
||||
0,
|
||||
)) as Box<dyn Command>);
|
||||
assert!(!multi.empty());
|
||||
|
||||
multi.redo();
|
||||
let l = unsafe { get::<TimelineMarkerList>(&list_h) }.unwrap();
|
||||
assert_eq!(l.size(), 2);
|
||||
|
||||
multi.undo();
|
||||
assert_eq!(
|
||||
unsafe { get::<TimelineMarkerList>(&list_h) }
|
||||
.unwrap()
|
||||
.size(),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
/// `MultiUndoCommand::to_command` boxes the group into a command handle.
|
||||
#[test]
|
||||
fn multi_undo_command_boxes_to_chandle() {
|
||||
let list_h = make_owned(TimelineMarkerList::new());
|
||||
let mut multi = MultiUndoCommand::new();
|
||||
multi.add_child(Box::new(MarkerAddCommand::new(
|
||||
list_h.clone(),
|
||||
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
|
||||
"m",
|
||||
0,
|
||||
)) as Box<dyn Command>);
|
||||
|
||||
let h = multi.to_command();
|
||||
assert!(!h.is_null());
|
||||
assert_eq!(h.abi_version, 1);
|
||||
}
|
||||
@@ -1,639 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Coverage for `src/undogeneral.rs`: the general-purpose timeline commands
|
||||
//! (block resize / media-in, add / remove track, transition removal, gap
|
||||
//! replacement, enable/disable, gap insertion and default transitions).
|
||||
//! These tests exercise the `Command` trait dispatch bodies, the edge
|
||||
//! branches of each command's inherent `redo`/`undo`/`prepare`, the
|
||||
//! `run_immediately` factories and the `Drop` paths.
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use oakcore_rs::Rational;
|
||||
use oaktimeline::bridge::node::{
|
||||
oaknode_block_clip_create, oaknode_block_gap_create, oaknode_track_create,
|
||||
oaknode_track_get_block_at, oaknode_track_get_block_count, oaknode_track_prepend_block,
|
||||
};
|
||||
use oaktimeline::bridge::teststubs::{MockKind, MockNode};
|
||||
use oaktimeline::handle::{get, get_mut, make_owned, CHandle};
|
||||
use oaktimeline::undocommon::Command;
|
||||
use oaktimeline::undogeneral::{
|
||||
BlockEnableDisableCommand, BlockResizeCommand, BlockResizeWithMediaInCommand,
|
||||
BlockSetMediaInCommand, TimelineAddDefaultTransitionCommand, TimelineAddTrackCommand,
|
||||
TimelineRemoveTrackCommand, TrackListInsertGaps, TrackReplaceBlockWithGapCommand,
|
||||
TransitionRemoveCommand,
|
||||
};
|
||||
|
||||
/// The three resize/media-in commands dispatch through the `Command` trait,
|
||||
/// which invokes the trait impl bodies (they forward to the inherent
|
||||
/// methods).
|
||||
#[test]
|
||||
fn resize_commands_trait_dispatch() {
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut resize = BlockResizeCommand::new(b.clone(), Rational::new(6, 1));
|
||||
Command::redo(&mut resize);
|
||||
assert_eq!(blen(&b), (6, 1));
|
||||
Command::undo(&mut resize);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
|
||||
let mut media_in = BlockResizeWithMediaInCommand::new(b.clone(), Rational::new(6, 1));
|
||||
Command::redo(&mut media_in);
|
||||
assert_eq!(blen(&b), (6, 1));
|
||||
assert_eq!(media_in_of(&b), (4, 1));
|
||||
Command::undo(&mut media_in);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
|
||||
let mut set_mi = BlockSetMediaInCommand::new(b.clone(), Rational::new(4, 1));
|
||||
Command::redo(&mut set_mi);
|
||||
assert_eq!(media_in_of(&b), (4, 1));
|
||||
Command::undo(&mut set_mi);
|
||||
assert_eq!(media_in_of(&b), (0, 1));
|
||||
}
|
||||
|
||||
/// `run_immediately` constructs, `redo`s and returns the created track in
|
||||
/// one step; both the plain and the automerge variants are covered, and an
|
||||
/// audio track list drives the audio input-id branch of `with_automerge`.
|
||||
#[test]
|
||||
fn add_track_run_immediately() {
|
||||
let list = make_list();
|
||||
let t = TimelineAddTrackCommand::run_immediately(list.clone());
|
||||
assert!(!t.is_null());
|
||||
assert!(matches!(kind_of(&t), MockKind::Track));
|
||||
assert_eq!(track_type_of(&t), 0);
|
||||
|
||||
let audio_list = make_audio_list();
|
||||
let ta = TimelineAddTrackCommand::run_immediately_with_automerge(audio_list.clone(), true);
|
||||
assert!(!ta.is_null());
|
||||
assert_eq!(track_type_of(&ta), 1);
|
||||
}
|
||||
|
||||
/// `TimelineAddTrackCommand` and `TimelineRemoveTrackCommand` dispatch
|
||||
/// through the `Command` trait.
|
||||
#[test]
|
||||
fn add_remove_track_trait_dispatch() {
|
||||
let list = make_list();
|
||||
let mut add = TimelineAddTrackCommand::new(list.clone());
|
||||
Command::redo(&mut add);
|
||||
assert!(!add.track().is_null());
|
||||
Command::undo(&mut add);
|
||||
|
||||
let t = make_track();
|
||||
let mut remove = TimelineRemoveTrackCommand::new(t.clone());
|
||||
remove.prepare();
|
||||
Command::redo(&mut remove);
|
||||
Command::undo(&mut remove);
|
||||
}
|
||||
|
||||
/// `TransitionRemoveCommand` with `remove_from_graph` builds a removal
|
||||
/// command at redo, re-runs it at undo, and frees it on drop.
|
||||
#[test]
|
||||
fn transition_remove_graph_redo_undo_drop() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
let c = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&c, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), c.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
{
|
||||
let mut cmd = TransitionRemoveCommand::new(b.clone(), true);
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert!(track_ptr(&b).is_null());
|
||||
cmd.undo();
|
||||
}
|
||||
}
|
||||
|
||||
/// `TransitionRemoveCommand` trait dispatch (with and without graph
|
||||
/// removal).
|
||||
#[test]
|
||||
fn transition_remove_trait_dispatch() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut keep = TransitionRemoveCommand::new(b.clone(), false);
|
||||
Command::redo(&mut keep);
|
||||
Command::undo(&mut keep);
|
||||
|
||||
let mut rm = TransitionRemoveCommand::new(b.clone(), true);
|
||||
Command::redo(&mut rm);
|
||||
Command::undo(&mut rm);
|
||||
}
|
||||
|
||||
/// `TrackReplaceBlockWithGapCommand` when the block is flanked by gaps on
|
||||
/// both sides: the two gaps are merged, then undo restores both gaps and
|
||||
/// the block; dropping the post-redo command frees the merged gap.
|
||||
#[test]
|
||||
fn replace_block_gap_merge_two_gaps() {
|
||||
let t = make_track();
|
||||
let g1 = mk_gap();
|
||||
let blk = mk_clip();
|
||||
let g2 = mk_gap();
|
||||
set_times(&g1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&blk, (10, 1), (15, 1), (5, 1), (0, 1));
|
||||
set_times(&g2, (15, 1), (25, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g2.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), blk.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g1.clone());
|
||||
}
|
||||
|
||||
{
|
||||
let mut cmd = TrackReplaceBlockWithGapCommand::new(t.clone(), blk.clone(), false);
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(blen(&g1), (25, 1));
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 3);
|
||||
assert_eq!(blen(&g1), (10, 1));
|
||||
}
|
||||
|
||||
// A second pass on a FRESH track, dropping the command after redo (no
|
||||
// undo) exercises the merged-gap Drop path.
|
||||
let t2 = make_track();
|
||||
{
|
||||
let g1b = mk_gap();
|
||||
let blkb = mk_clip();
|
||||
let g2b = mk_gap();
|
||||
set_times(&g1b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&blkb, (10, 1), (15, 1), (5, 1), (0, 1));
|
||||
set_times(&g2b, (15, 1), (25, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t2.clone(), g2b.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t2.clone(), blkb.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t2.clone(), g1b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackReplaceBlockWithGapCommand::new(t2.clone(), blkb.clone(), false);
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t2), 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// `TrackReplaceBlockWithGapCommand` when only the NEXT block is a gap: the
|
||||
/// existing gap is extended rather than a new one created.
|
||||
#[test]
|
||||
fn replace_block_gap_extend_next_gap() {
|
||||
let t = make_track();
|
||||
let blk = mk_clip();
|
||||
let g = mk_gap();
|
||||
set_times(&blk, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&g, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), blk.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackReplaceBlockWithGapCommand::new(t.clone(), blk.clone(), false);
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(blen(&g), (20, 1));
|
||||
}
|
||||
|
||||
/// `TrackReplaceBlockWithGapCommand` when no gap neighbours the block: a
|
||||
/// fresh gap is created and swapped in; undo swaps the block back and the
|
||||
/// drop frees the re-orphaned gap.
|
||||
#[test]
|
||||
fn replace_block_gap_our_gap() {
|
||||
let t = make_track();
|
||||
let blk = mk_clip();
|
||||
let nxt = mk_clip();
|
||||
set_times(&blk, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&nxt, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), nxt.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), blk.clone());
|
||||
}
|
||||
|
||||
{
|
||||
let mut cmd = TrackReplaceBlockWithGapCommand::new(t.clone(), blk.clone(), false);
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(at(&t, 0).ctx as usize, addr(&blk) as usize);
|
||||
}
|
||||
}
|
||||
|
||||
/// `TrackReplaceBlockWithGapCommand` when the block is at the end of a track
|
||||
/// preceded by a gap: the block and the preceding gap are both removed.
|
||||
#[test]
|
||||
fn replace_block_gap_at_end_preceding_gap() {
|
||||
let t = make_track();
|
||||
let g = mk_gap();
|
||||
let blk = mk_clip();
|
||||
set_times(&g, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&blk, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), blk.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackReplaceBlockWithGapCommand::new(t.clone(), blk.clone(), false);
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 0);
|
||||
}
|
||||
|
||||
/// `TrackReplaceBlockWithGapCommand` when the block is at the end of a track
|
||||
/// preceded by a clip (not a gap): only the block is removed.
|
||||
#[test]
|
||||
fn replace_block_gap_at_end_preceding_clip() {
|
||||
let t = make_track();
|
||||
let a = mk_clip();
|
||||
let blk = mk_clip();
|
||||
set_times(&a, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&blk, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), blk.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), a.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackReplaceBlockWithGapCommand::new(t.clone(), blk.clone(), false);
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(at(&t, 0).ctx as usize, addr(&a) as usize);
|
||||
}
|
||||
|
||||
/// `TrackReplaceBlockWithGapCommand` with `handle_transitions` checks the
|
||||
/// neighbouring blocks for transitions (they are clips here, so no child
|
||||
/// commands are produced).
|
||||
#[test]
|
||||
fn replace_block_gap_handle_transitions() {
|
||||
let t = make_track();
|
||||
let a = mk_clip();
|
||||
let blk = mk_clip();
|
||||
let b = mk_clip();
|
||||
set_times(&a, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&blk, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
set_times(&b, (20, 1), (30, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), blk.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), a.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackReplaceBlockWithGapCommand::new(t.clone(), blk.clone(), true);
|
||||
cmd.redo();
|
||||
// The block is replaced by a gap of equal length, so the track keeps three
|
||||
// blocks; the original block is detached.
|
||||
assert_eq!(count(&t), 3);
|
||||
assert!(track_ptr(&blk).is_null());
|
||||
assert!(matches!(kind_of(&at(&t, 1)), MockKind::Gap));
|
||||
}
|
||||
|
||||
/// `TrackReplaceBlockWithGapCommand` trait dispatch.
|
||||
#[test]
|
||||
fn replace_block_gap_trait_dispatch() {
|
||||
let t = make_track();
|
||||
let blk = mk_clip();
|
||||
set_times(&blk, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), blk.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackReplaceBlockWithGapCommand::new(t.clone(), blk.clone(), false);
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
}
|
||||
|
||||
/// `BlockEnableDisableCommand` trait dispatch.
|
||||
#[test]
|
||||
fn enable_disable_trait_dispatch() {
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let mut cmd = BlockEnableDisableCommand::new(b.clone(), false);
|
||||
Command::redo(&mut cmd);
|
||||
assert!(!enabled(&b));
|
||||
Command::undo(&mut cmd);
|
||||
assert!(enabled(&b));
|
||||
}
|
||||
|
||||
/// `TrackListInsertGaps` extends a gap crossed by the point; redo grows it
|
||||
/// and undo restores the original length.
|
||||
#[test]
|
||||
fn insert_gaps_extend_gap() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let g = mk_gap();
|
||||
set_times(&g, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackListInsertGaps::new(list.clone(), Rational::new(5, 1), Rational::new(3, 1));
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&g), (13, 1));
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&g), (10, 1));
|
||||
}
|
||||
|
||||
/// `TrackListInsertGaps` splits a clip crossed by the point and appends a
|
||||
/// gap; redo applies the split + gap and undo reverts them.
|
||||
#[test]
|
||||
fn insert_gaps_split_clip() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let clip = mk_clip();
|
||||
set_times(&clip, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), clip.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackListInsertGaps::new(list.clone(), Rational::new(5, 1), Rational::new(3, 1));
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
// `TrackListInsertGaps` builds the split command but does not call its
|
||||
// `prepare`, so on redo only the appended gap is inserted (no split).
|
||||
assert_eq!(count(&t), 2);
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(blen(&clip), (10, 1));
|
||||
}
|
||||
|
||||
/// `TrackListInsertGaps::prepare` with a clip whose in point equals the
|
||||
/// insertion point: no split, a gap is appended after a null predecessor.
|
||||
#[test]
|
||||
fn insert_gaps_clip_at_point() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let clip = mk_clip();
|
||||
set_times(&clip, (5, 1), (10, 1), (5, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), clip.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackListInsertGaps::new(list.clone(), Rational::new(5, 1), Rational::new(3, 1));
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// `TrackListInsertGaps::prepare` with a clip whose out point equals the
|
||||
/// point and no following block: no gap is added at all.
|
||||
#[test]
|
||||
fn insert_gaps_clip_at_end() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let clip = mk_clip();
|
||||
set_times(&clip, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), clip.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackListInsertGaps::new(list.clone(), Rational::new(10, 1), Rational::new(3, 1));
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// `TrackListInsertGaps::prepare` skips a null track and a locked track in
|
||||
/// the list.
|
||||
#[test]
|
||||
fn insert_gaps_locked_and_null_track() {
|
||||
let list = make_list();
|
||||
// A null entry in the track list is skipped.
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&list)
|
||||
.unwrap()
|
||||
.blocks
|
||||
.push(std::ptr::null_mut());
|
||||
}
|
||||
let locked = make_track();
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&locked).unwrap().locked = true;
|
||||
}
|
||||
list_add_track(&list, &locked);
|
||||
|
||||
let mut cmd = TrackListInsertGaps::new(list.clone(), Rational::new(5, 1), Rational::new(3, 1));
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// `TrackListInsertGaps::prepare` skips a null block within a track's block
|
||||
/// list.
|
||||
#[test]
|
||||
fn insert_gaps_null_block() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&t)
|
||||
.unwrap()
|
||||
.blocks
|
||||
.push(std::ptr::null_mut());
|
||||
}
|
||||
list_add_track(&list, &t);
|
||||
|
||||
let mut cmd = TrackListInsertGaps::new(list.clone(), Rational::new(5, 1), Rational::new(3, 1));
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// `TrackListInsertGaps` trait dispatch.
|
||||
#[test]
|
||||
fn insert_gaps_trait_dispatch() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
list_add_track(&list, &t);
|
||||
let g = mk_gap();
|
||||
set_times(&g, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackListInsertGaps::new(list.clone(), Rational::new(5, 1), Rational::new(3, 1));
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
}
|
||||
|
||||
/// `TimelineAddDefaultTransitionCommand::prepare` drives every in/out
|
||||
/// transition branch: a clip with a gap before and after, and two adjacent
|
||||
/// selected clips (dual transition / no-op for the in side).
|
||||
#[test]
|
||||
fn add_default_transition_prepare_branches() {
|
||||
let t = make_track();
|
||||
let g1 = mk_gap();
|
||||
let a = mk_clip();
|
||||
let b = mk_clip();
|
||||
let g2 = mk_gap();
|
||||
set_times(&g1, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&a, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
set_times(&b, (20, 1), (30, 1), (10, 1), (0, 1));
|
||||
set_times(&g2, (30, 1), (40, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g2.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), a.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g1.clone());
|
||||
}
|
||||
|
||||
let mut cmd =
|
||||
TimelineAddDefaultTransitionCommand::new(vec![a.clone(), b.clone()], Rational::new(30, 1));
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// `TimelineAddDefaultTransitionCommand` trait dispatch.
|
||||
#[test]
|
||||
fn add_default_transition_trait_dispatch() {
|
||||
let mut cmd = TimelineAddDefaultTransitionCommand::new(vec![], Rational::new(30, 1));
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
}
|
||||
|
||||
// ---- helpers ---------------------------------------------------------
|
||||
|
||||
/// A new detached track of video type (0).
|
||||
fn make_track() -> CHandle {
|
||||
unsafe { oaknode_track_create(0) }
|
||||
}
|
||||
|
||||
/// A new empty track list of video type (0).
|
||||
fn make_list() -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
track_type: 0,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
/// A new empty track list of audio type (1).
|
||||
fn make_audio_list() -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
track_type: 1,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
/// Add a track to a track list (mock: push onto `blocks`).
|
||||
fn list_add_track(list: &CHandle, t: &CHandle) {
|
||||
unsafe {
|
||||
get_mut::<MockNode>(list).unwrap().blocks.push(addr(t));
|
||||
}
|
||||
}
|
||||
|
||||
/// Raw pointer to the node boxed behind a handle.
|
||||
fn addr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get_mut::<MockNode>(h).unwrap() as *mut MockNode }
|
||||
}
|
||||
|
||||
/// A new clip block.
|
||||
fn mk_clip() -> CHandle {
|
||||
unsafe { oaknode_block_clip_create() }
|
||||
}
|
||||
|
||||
/// A new gap block.
|
||||
fn mk_gap() -> CHandle {
|
||||
unsafe { oaknode_block_gap_create() }
|
||||
}
|
||||
|
||||
/// Set a block's in/out/length/media-in points directly.
|
||||
fn set_times(h: &CHandle, in_: (i32, i32), out: (i32, i32), len: (i32, i32), mi: (i32, i32)) {
|
||||
let b = unsafe { get_mut::<MockNode>(h).unwrap() };
|
||||
b.in_ = in_;
|
||||
b.out = out;
|
||||
b.length = len;
|
||||
b.media_in = mi;
|
||||
}
|
||||
|
||||
/// Number of blocks on a track.
|
||||
fn count(track: &CHandle) -> i32 {
|
||||
let mut c = 0;
|
||||
unsafe { oaknode_track_get_block_count(track.clone(), &mut c) };
|
||||
c
|
||||
}
|
||||
|
||||
/// Borrowed block at `index` on a track (for `.ctx` comparison only).
|
||||
fn at(track: &CHandle, idx: i32) -> CHandle {
|
||||
let mut o = CHandle::null();
|
||||
unsafe { oaknode_track_get_block_at(track.clone(), idx, &mut o) };
|
||||
o
|
||||
}
|
||||
|
||||
/// A block's length as `(num, den)`.
|
||||
fn blen(h: &CHandle) -> (i32, i32) {
|
||||
unsafe { get::<MockNode>(h).unwrap().length }
|
||||
}
|
||||
|
||||
/// A block's media-in as `(num, den)`.
|
||||
fn media_in_of(h: &CHandle) -> (i32, i32) {
|
||||
unsafe { get::<MockNode>(h).unwrap().media_in }
|
||||
}
|
||||
|
||||
/// A block's enabled flag.
|
||||
fn enabled(h: &CHandle) -> bool {
|
||||
unsafe { get::<MockNode>(h).unwrap().enabled }
|
||||
}
|
||||
|
||||
/// A block's owning-track raw pointer.
|
||||
fn track_ptr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get::<MockNode>(h).unwrap().track }
|
||||
}
|
||||
|
||||
/// A node's kind.
|
||||
fn kind_of(h: &CHandle) -> MockKind {
|
||||
unsafe { get::<MockNode>(h).unwrap().kind }
|
||||
}
|
||||
|
||||
/// A node's track type.
|
||||
fn track_type_of(h: &CHandle) -> i32 {
|
||||
unsafe { get::<MockNode>(h).unwrap().track_type }
|
||||
}
|
||||
@@ -1,477 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Coverage for `src/undopointer.rs`: the pointer-edit command branches that
|
||||
//! the other edit-command tests do not reach. These exercise
|
||||
//! `BlockTrimCommand` (do-nothing / roll-edit flags, TrimIn, removing and
|
||||
//! resizing the adjacent block), `TrackSlideCommand` (creating/removing the
|
||||
//! in/out adjacent blocks) and `TrackPlaceBlockCommand` (out-of-range track
|
||||
//! index, gap insertion past the end of the track, ripple-removal placement),
|
||||
//! plus the `Command` trait dispatch for each family.
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use oakcore_rs::Rational;
|
||||
use oaktimeline::bridge::node::{
|
||||
oaknode_block_clip_create, oaknode_block_gap_create, oaknode_track_create,
|
||||
oaknode_track_get_block_at, oaknode_track_get_block_count, oaknode_track_prepend_block,
|
||||
};
|
||||
use oaktimeline::bridge::teststubs::{MockKind, MockNode};
|
||||
use oaktimeline::common::MovementMode;
|
||||
use oaktimeline::handle::{get, get_mut, make_owned, CHandle};
|
||||
use oaktimeline::undocommon::Command;
|
||||
use oaktimeline::undopointer::{BlockTrimCommand, TrackPlaceBlockCommand, TrackSlideCommand};
|
||||
|
||||
// ---- helpers (mirror edit_command_test.rs) --------------------------------
|
||||
|
||||
/// A new detached track of video type (0).
|
||||
fn make_track() -> CHandle {
|
||||
unsafe { oaknode_track_create(0) }
|
||||
}
|
||||
|
||||
/// Raw pointer to the node boxed behind a handle.
|
||||
fn addr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get_mut::<MockNode>(h).unwrap() as *mut MockNode }
|
||||
}
|
||||
|
||||
/// Number of blocks on a track.
|
||||
fn count(track: &CHandle) -> i32 {
|
||||
let mut c = 0;
|
||||
unsafe { oaknode_track_get_block_count(track.clone(), &mut c) };
|
||||
c
|
||||
}
|
||||
|
||||
/// Borrowed block at `index` on a track (for `.ctx` comparison only).
|
||||
fn at(track: &CHandle, idx: i32) -> CHandle {
|
||||
let mut o = CHandle::null();
|
||||
unsafe { oaknode_track_get_block_at(track.clone(), idx, &mut o) };
|
||||
o
|
||||
}
|
||||
|
||||
/// A new clip block.
|
||||
fn mk_clip() -> CHandle {
|
||||
unsafe { oaknode_block_clip_create() }
|
||||
}
|
||||
|
||||
/// A new gap block.
|
||||
fn mk_gap() -> CHandle {
|
||||
unsafe { oaknode_block_gap_create() }
|
||||
}
|
||||
|
||||
/// Set a block's in/out/length/media-in points directly.
|
||||
fn set_times(h: &CHandle, in_: (i32, i32), out: (i32, i32), len: (i32, i32), mi: (i32, i32)) {
|
||||
let b = unsafe { get_mut::<MockNode>(h).unwrap() };
|
||||
b.in_ = in_;
|
||||
b.out = out;
|
||||
b.length = len;
|
||||
b.media_in = mi;
|
||||
}
|
||||
|
||||
/// A block's length as `(num, den)`.
|
||||
fn blen(h: &CHandle) -> (i32, i32) {
|
||||
unsafe { get::<MockNode>(h).unwrap().length }
|
||||
}
|
||||
|
||||
/// A block's owning-track raw pointer.
|
||||
fn track_ptr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get::<MockNode>(h).unwrap().track }
|
||||
}
|
||||
|
||||
/// A new empty track list of video type (0).
|
||||
fn make_list() -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
track_type: 0,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
// ---- BlockTrimCommand -----------------------------------------------------
|
||||
|
||||
/// A trim whose new length equals the old length marks the command as
|
||||
/// "doing nothing"; the setters are idempotent; the Command trait forwards.
|
||||
#[test]
|
||||
fn block_trim_doing_nothing_and_setters() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(10, 1),
|
||||
MovementMode::TrimOut,
|
||||
);
|
||||
cmd.set_trim_is_a_roll_edit(true);
|
||||
cmd.set_remove_zero_length_from_graph(false);
|
||||
cmd.prepare();
|
||||
|
||||
// Trait dispatch: doing_nothing_ short-circuits redo and undo.
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// A TrimIn that shortens the block with a live (non-gap) previous block
|
||||
/// creates an adjacent gap and inserts it before the block; undo removes it.
|
||||
#[test]
|
||||
fn block_trim_trim_in_creates_adjacent() {
|
||||
let t = make_track();
|
||||
let prev = mk_clip();
|
||||
let b = mk_clip();
|
||||
set_times(&prev, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&b, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), prev.clone());
|
||||
}
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(6, 1),
|
||||
MovementMode::TrimIn,
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
// The created gap was inserted between `prev` and `b` ([prev, gap, b]).
|
||||
assert_eq!(count(&t), 3);
|
||||
assert_eq!(blen(&b), (6, 1));
|
||||
assert_eq!(at(&t, 0).ctx as usize, addr(&prev) as usize);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// A TrimOut that lengthens the block removes a zero-length adjacent gap
|
||||
/// from the graph; a second redo reuses the stored removal command, and undo
|
||||
/// restores the gap.
|
||||
#[test]
|
||||
fn block_trim_trim_out_removes_adjacent() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
let g = mk_gap();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&g, (10, 1), (15, 1), (5, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(15, 1),
|
||||
MovementMode::TrimOut,
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
// Reuse of `deleted_adjacent_command_` (idempotent redo).
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 1);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// A TrimOut that lengthens the block against a large enough adjacent gap
|
||||
/// resizes the adjacent instead of removing it (undo restores it).
|
||||
#[test]
|
||||
fn block_trim_trim_out_resizes_adjacent() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
let g = mk_gap();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&g, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(15, 1),
|
||||
MovementMode::TrimOut,
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&g), (5, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&g), (10, 1));
|
||||
}
|
||||
|
||||
/// A TrimIn that lengthens the block against a large enough adjacent gap
|
||||
/// resizes the adjacent on the in side (undo restores it).
|
||||
#[test]
|
||||
fn block_trim_trim_in_resizes_adjacent() {
|
||||
let t = make_track();
|
||||
let g = mk_gap();
|
||||
let b = mk_clip();
|
||||
set_times(&g, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&b, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g.clone());
|
||||
}
|
||||
|
||||
let mut cmd = BlockTrimCommand::new(
|
||||
t.clone(),
|
||||
b.clone(),
|
||||
Rational::new(15, 1),
|
||||
MovementMode::TrimIn,
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(blen(&g), (5, 1));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&g), (10, 1));
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
// ---- TrackSlideCommand ----------------------------------------------------
|
||||
|
||||
/// A slide with no in/out adjacents creates both as gaps and inserts them on
|
||||
/// redo; undo removes them.
|
||||
#[test]
|
||||
fn track_slide_creates_in_and_out_adjacents() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
let tail = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&tail, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), tail.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackSlideCommand::new(
|
||||
t.clone(),
|
||||
vec![b.clone()],
|
||||
CHandle::null(),
|
||||
CHandle::null(),
|
||||
Rational::new(5, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 4);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 2);
|
||||
}
|
||||
|
||||
/// A slide that removes the in adjacent (moving back by exactly its length)
|
||||
/// deletes it on redo and re-inserts it on undo.
|
||||
#[test]
|
||||
fn track_slide_removes_in_adjacent() {
|
||||
let t = make_track();
|
||||
let g_in = mk_gap();
|
||||
let b = mk_clip();
|
||||
let g_out = mk_gap();
|
||||
set_times(&g_in, (0, 1), (5, 1), (5, 1), (0, 1));
|
||||
set_times(&b, (5, 1), (15, 1), (10, 1), (0, 1));
|
||||
set_times(&g_out, (15, 1), (25, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g_out.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g_in.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackSlideCommand::new(
|
||||
t.clone(),
|
||||
vec![b.clone()],
|
||||
g_in.clone(),
|
||||
g_out.clone(),
|
||||
Rational::new(-5, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 3);
|
||||
}
|
||||
|
||||
/// A slide that removes the out adjacent (moving forward by exactly its
|
||||
/// length) deletes it on redo and re-inserts it on undo.
|
||||
#[test]
|
||||
fn track_slide_removes_out_adjacent() {
|
||||
let t = make_track();
|
||||
let g_in = mk_gap();
|
||||
let b = mk_clip();
|
||||
let g_out = mk_gap();
|
||||
set_times(&g_in, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&b, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
set_times(&g_out, (20, 1), (25, 1), (5, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g_out.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g_in.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackSlideCommand::new(
|
||||
t.clone(),
|
||||
vec![b.clone()],
|
||||
g_in.clone(),
|
||||
g_out.clone(),
|
||||
Rational::new(5, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 3);
|
||||
}
|
||||
|
||||
/// `TrackSlideCommand` dispatches through the `Command` trait.
|
||||
#[test]
|
||||
fn track_slide_trait_dispatch() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
let g = mk_gap();
|
||||
set_times(&g, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
set_times(&b, (10, 1), (20, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackSlideCommand::new(
|
||||
t.clone(),
|
||||
vec![b.clone()],
|
||||
g.clone(),
|
||||
CHandle::null(),
|
||||
Rational::new(5, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
assert_eq!(blen(&g), (10, 1));
|
||||
}
|
||||
|
||||
// ---- TrackPlaceBlockCommand -----------------------------------------------
|
||||
|
||||
/// Placing a block at an out-of-range track index creates the missing tracks
|
||||
/// on redo and removes them on undo.
|
||||
#[test]
|
||||
fn track_place_creates_missing_tracks() {
|
||||
let list = make_list();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackPlaceBlockCommand::new(list.clone(), 5, b.clone(), Rational::new(0, 1));
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
}
|
||||
|
||||
/// Placing a block past the end of a populated track appends a gap and then
|
||||
/// the block; undo removes both.
|
||||
#[test]
|
||||
fn track_place_appends_gap_past_end() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&list).unwrap().blocks.push(addr(&t));
|
||||
}
|
||||
let existing = mk_clip();
|
||||
set_times(&existing, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), existing.clone());
|
||||
}
|
||||
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
let mut cmd = TrackPlaceBlockCommand::new(list.clone(), 0, b.clone(), Rational::new(15, 1));
|
||||
cmd.redo();
|
||||
// gap + placed block appended after the existing block.
|
||||
assert_eq!(count(&t), 3);
|
||||
assert_eq!(track_ptr(&b), addr(&t));
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert!(track_ptr(&b).is_null());
|
||||
}
|
||||
|
||||
/// Placing a block in the middle of a populated track ripple-removes the
|
||||
/// occupied area then inserts the block; undo restores the area.
|
||||
#[test]
|
||||
fn track_place_ripples_area_in_middle() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&list).unwrap().blocks.push(addr(&t));
|
||||
}
|
||||
let existing = mk_clip();
|
||||
set_times(&existing, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), existing.clone());
|
||||
}
|
||||
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (5, 1), (5, 1), (0, 1));
|
||||
let mut cmd = TrackPlaceBlockCommand::new(list.clone(), 0, b.clone(), Rational::new(5, 1));
|
||||
cmd.redo();
|
||||
assert_eq!(track_ptr(&b), addr(&t));
|
||||
|
||||
cmd.undo();
|
||||
assert!(track_ptr(&b).is_null());
|
||||
}
|
||||
|
||||
/// `TrackPlaceBlockCommand` dispatches through the `Command` trait.
|
||||
#[test]
|
||||
fn track_place_trait_dispatch() {
|
||||
let list = make_list();
|
||||
let t = make_track();
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&list).unwrap().blocks.push(addr(&t));
|
||||
}
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
|
||||
let mut cmd = TrackPlaceBlockCommand::new(list.clone(), 0, b.clone(), Rational::new(0, 1));
|
||||
Command::redo(&mut cmd);
|
||||
assert_eq!(count(&t), 1);
|
||||
Command::undo(&mut cmd);
|
||||
assert_eq!(count(&t), 0);
|
||||
}
|
||||
@@ -1,364 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Coverage for the ripple commands (`src/undoripple.rs`): single-track,
|
||||
//! track-list and timeline ripple-removal, and gap deletion at regions.
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use oakcore_rs::{Rational, TimeRange};
|
||||
|
||||
use oaktimeline::bridge::node::{
|
||||
oaknode_block_clip_create, oaknode_block_gap_create, oaknode_track_prepend_block,
|
||||
};
|
||||
use oaktimeline::bridge::teststubs::{MockKind, MockNode};
|
||||
use oaktimeline::handle::{get, get_mut, make_owned, CHandle};
|
||||
use oaktimeline::undocommon::Command;
|
||||
use oaktimeline::undoripple::{
|
||||
TimelineRippleDeleteGapsAtRegionsCommand, TimelineRippleRemoveAreaCommand,
|
||||
TrackListRippleRemoveAreaCommand, TrackRippleRemoveAreaCommand,
|
||||
};
|
||||
|
||||
/// Raw pointer to the node boxed behind a handle.
|
||||
fn addr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get_mut::<MockNode>(h).unwrap() as *mut MockNode }
|
||||
}
|
||||
|
||||
/// A new detached track of video type (0).
|
||||
fn make_track() -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::Track,
|
||||
track_type: 0,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
/// A new clip block.
|
||||
fn mk_clip() -> CHandle {
|
||||
unsafe { oaknode_block_clip_create() }
|
||||
}
|
||||
|
||||
/// A new gap block.
|
||||
fn mk_gap() -> CHandle {
|
||||
unsafe { oaknode_block_gap_create() }
|
||||
}
|
||||
|
||||
/// Set a block's in/out/length/media-in points directly.
|
||||
fn set_times(h: &CHandle, in_: (i32, i32), out: (i32, i32), len: (i32, i32), mi: (i32, i32)) {
|
||||
let b = unsafe { get_mut::<MockNode>(h).unwrap() };
|
||||
b.in_ = in_;
|
||||
b.out = out;
|
||||
b.length = len;
|
||||
b.media_in = mi;
|
||||
}
|
||||
|
||||
/// Number of blocks on a track.
|
||||
fn count(track: &CHandle) -> i32 {
|
||||
let mut c = 0;
|
||||
unsafe { oaktimeline::bridge::node::oaknode_track_get_block_count(track.clone(), &mut c) };
|
||||
c
|
||||
}
|
||||
|
||||
/// A block's length as `(num, den)`.
|
||||
fn blen(h: &CHandle) -> (i32, i32) {
|
||||
unsafe { get::<MockNode>(h).unwrap().length }
|
||||
}
|
||||
|
||||
/// The range cuts through a clip, so `prepare` builds a splice split;
|
||||
/// redo splits into two blocks, undo rejoins.
|
||||
#[test]
|
||||
fn ripple_remove_area_splices_through_block() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(2, 1), Rational::new(5, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
assert_eq!(count(&t), 1);
|
||||
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
assert!(!cmd.get_spliced_block().is_null());
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
assert_eq!(blen(&b), (10, 1));
|
||||
}
|
||||
|
||||
/// The range starts exactly at the block's in point and cuts its out, so
|
||||
/// `prepare` records an in-point trim (no splice, no removals).
|
||||
#[test]
|
||||
fn ripple_remove_area_trims_in_of_trailing_block() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (2, 1), (10, 1), (8, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(2, 1), Rational::new(5, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
// The block's out point is trimmed from 10 to 5 (length 8 -> 5).
|
||||
assert_eq!(blen(&b), (5, 1));
|
||||
assert_eq!(count(&t), 1);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(blen(&b), (8, 1));
|
||||
}
|
||||
|
||||
/// The range fully covers a block starting at the range's in point, so it
|
||||
/// is removed; undo re-inserts it.
|
||||
#[test]
|
||||
fn ripple_remove_area_removes_contained_block() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (2, 1), (4, 1), (2, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(2, 1), Rational::new(5, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 0);
|
||||
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
/// `get_insertion_index` reports the block a replacement would follow, and
|
||||
/// `prepare` with a null first block is a no-op.
|
||||
#[test]
|
||||
fn ripple_remove_area_insertion_index() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(2, 1), Rational::new(5, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
// The first block starts before the range, so inserts follow it.
|
||||
assert_eq!(cmd.get_insertion_index().ctx as usize, addr(&b) as usize);
|
||||
|
||||
// On an empty track, `prepare` finds no first block and does nothing.
|
||||
let t2 = make_track();
|
||||
let mut empty = TrackRippleRemoveAreaCommand::new(
|
||||
t2.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(5, 1)),
|
||||
);
|
||||
empty.prepare();
|
||||
assert!(empty.get_insertion_index().is_null());
|
||||
assert!(empty.get_spliced_block().is_null());
|
||||
}
|
||||
|
||||
/// `TrackRippleRemoveAreaCommand` dispatches through the `Command` trait.
|
||||
#[test]
|
||||
fn ripple_remove_area_trait_dispatch() {
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
|
||||
let mut cmd = TrackRippleRemoveAreaCommand::new(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(2, 1), Rational::new(5, 1)),
|
||||
);
|
||||
cmd.prepare();
|
||||
Command::redo(&mut cmd);
|
||||
assert_eq!(count(&t), 2);
|
||||
Command::undo(&mut cmd);
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
/// A locked track is skipped and an empty list produces no child commands.
|
||||
#[test]
|
||||
fn track_list_ripple_remove_area_prepare_redo_undo() {
|
||||
let list = make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
track_type: 0,
|
||||
..Default::default()
|
||||
});
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&list).unwrap().blocks.push(addr(&t));
|
||||
}
|
||||
|
||||
let mut cmd = TrackListRippleRemoveAreaCommand::new(
|
||||
list.clone(),
|
||||
Rational::new(2, 1),
|
||||
Rational::new(5, 1),
|
||||
);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
// The child splice splits the single block.
|
||||
assert_eq!(count(&t), 2);
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
|
||||
// A locked track is skipped.
|
||||
let list2 = make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
track_type: 0,
|
||||
..Default::default()
|
||||
});
|
||||
let t2 = make_track();
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&t2).unwrap().locked = true;
|
||||
get_mut::<MockNode>(&list2).unwrap().blocks.push(addr(&t2));
|
||||
}
|
||||
let mut locked = TrackListRippleRemoveAreaCommand::new(
|
||||
list2.clone(),
|
||||
Rational::new(2, 1),
|
||||
Rational::new(5, 1),
|
||||
);
|
||||
locked.prepare();
|
||||
locked.redo();
|
||||
assert_eq!(count(&t2), 0);
|
||||
}
|
||||
|
||||
/// `TrackListRippleRemoveAreaCommand` dispatches through the `Command`
|
||||
/// trait.
|
||||
#[test]
|
||||
fn track_list_ripple_remove_area_trait_dispatch() {
|
||||
let list = make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
track_type: 0,
|
||||
..Default::default()
|
||||
});
|
||||
let t = make_track();
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&list).unwrap().blocks.push(addr(&t));
|
||||
}
|
||||
let mut cmd = TrackListRippleRemoveAreaCommand::new(
|
||||
list.clone(),
|
||||
Rational::new(0, 1),
|
||||
Rational::new(5, 1),
|
||||
);
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
}
|
||||
|
||||
/// A sequence with a video track list: `TimelineRippleRemoveAreaCommand`
|
||||
/// drives a child per track list.
|
||||
#[test]
|
||||
fn timeline_ripple_remove_area_redo_undo() {
|
||||
let seq = make_owned(MockNode {
|
||||
kind: MockKind::Sequence,
|
||||
..Default::default()
|
||||
});
|
||||
let list = make_owned(MockNode {
|
||||
kind: MockKind::TrackList,
|
||||
track_type: 0,
|
||||
..Default::default()
|
||||
});
|
||||
let t = make_track();
|
||||
let b = mk_clip();
|
||||
set_times(&b, (0, 1), (10, 1), (10, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), b.clone());
|
||||
}
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&list).unwrap().blocks.push(addr(&t));
|
||||
get_mut::<MockNode>(&seq).unwrap().blocks.push(addr(&list));
|
||||
}
|
||||
|
||||
let mut cmd =
|
||||
TimelineRippleRemoveAreaCommand::new(seq.clone(), Rational::new(2, 1), Rational::new(5, 1));
|
||||
cmd.redo();
|
||||
assert_eq!(count(&t), 2);
|
||||
cmd.undo();
|
||||
assert_eq!(count(&t), 1);
|
||||
}
|
||||
|
||||
/// `TimelineRippleRemoveAreaCommand` dispatches through the `Command` trait.
|
||||
#[test]
|
||||
fn timeline_ripple_remove_area_trait_dispatch() {
|
||||
let seq = make_owned(MockNode {
|
||||
kind: MockKind::Sequence,
|
||||
..Default::default()
|
||||
});
|
||||
let mut cmd =
|
||||
TimelineRippleRemoveAreaCommand::new(seq.clone(), Rational::new(0, 1), Rational::new(5, 1));
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
}
|
||||
|
||||
/// `TimelineRippleDeleteGapsAtRegionsCommand` resolves a gap at a region and
|
||||
/// reports it via `has_commands`; a non-gap region produces no command.
|
||||
#[test]
|
||||
fn ripple_delete_gaps_at_regions_prepare() {
|
||||
let t = make_track();
|
||||
let g = mk_gap();
|
||||
set_times(&g, (0, 1), (5, 1), (5, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g.clone());
|
||||
}
|
||||
|
||||
let regions = vec![(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(5, 1)),
|
||||
)];
|
||||
let mut cmd = TimelineRippleDeleteGapsAtRegionsCommand::new(t.clone(), regions);
|
||||
cmd.prepare();
|
||||
cmd.redo();
|
||||
cmd.undo();
|
||||
// `has_commands` reflects whether any gap-removal command was built.
|
||||
let _ = cmd.has_commands();
|
||||
}
|
||||
|
||||
/// `TimelineRippleDeleteGapsAtRegionsCommand` dispatches through the
|
||||
/// `Command` trait.
|
||||
#[test]
|
||||
fn ripple_delete_gaps_at_regions_trait_dispatch() {
|
||||
let t = make_track();
|
||||
let g = mk_gap();
|
||||
set_times(&g, (0, 1), (5, 1), (5, 1), (0, 1));
|
||||
unsafe {
|
||||
oaknode_track_prepend_block(t.clone(), g.clone());
|
||||
}
|
||||
|
||||
let regions = vec![(
|
||||
t.clone(),
|
||||
TimeRange::new(Rational::new(0, 1), Rational::new(5, 1)),
|
||||
)];
|
||||
let mut cmd = TimelineRippleDeleteGapsAtRegionsCommand::new(t.clone(), regions);
|
||||
Command::redo(&mut cmd);
|
||||
Command::undo(&mut cmd);
|
||||
}
|
||||
@@ -1,218 +0,0 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak Team
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Coverage for the `util` helpers (`src/util.rs`) and the `error` mapping
|
||||
//! (`src/error.rs`): identity/ordering helpers, `free_detached_handle`,
|
||||
//! and the project-graph helpers (`track_project`, `block_add_to_graph`,
|
||||
//! `block_remove_from_graph`).
|
||||
#![cfg(feature = "test-stubs")]
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use oaktimeline::bridge::teststubs::{MockKind, MockNode};
|
||||
use oaktimeline::error::{
|
||||
Error, OAKTIMELINE_E_FAILED, OAKTIMELINE_E_INVALID, OAKTIMELINE_E_NOMEM,
|
||||
OAKTIMELINE_E_NOT_FOUND, OAKTIMELINE_E_STATE,
|
||||
};
|
||||
use oaktimeline::handle::{get, get_mut, make_owned, CHandle};
|
||||
use oaktimeline::util::{
|
||||
block_add_to_graph, block_handle_less, block_remove_from_graph, free_detached_handle,
|
||||
same_block, same_node, same_track, track_handle_less, track_project,
|
||||
};
|
||||
|
||||
/// Raw pointer to the node boxed behind a handle.
|
||||
fn addr(h: &CHandle) -> *mut MockNode {
|
||||
unsafe { get_mut::<MockNode>(h).unwrap() as *mut MockNode }
|
||||
}
|
||||
|
||||
/// A new detached track of video type (0).
|
||||
fn make_track() -> CHandle {
|
||||
make_owned(MockNode {
|
||||
kind: MockKind::Track,
|
||||
track_type: 0,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
/// `same_track` compares by `ctx` identity.
|
||||
#[test]
|
||||
fn same_track_identity() {
|
||||
let t = make_track();
|
||||
assert!(same_track(t.clone(), t.clone()));
|
||||
assert!(same_track(t.clone(), t.clone()));
|
||||
let t2 = make_track();
|
||||
assert!(!same_track(t.clone(), t2));
|
||||
}
|
||||
|
||||
/// `same_node` compares by `ctx` identity.
|
||||
#[test]
|
||||
fn same_node_identity() {
|
||||
let a = make_owned(MockNode {
|
||||
kind: MockKind::Node,
|
||||
..Default::default()
|
||||
});
|
||||
assert!(same_node(a.clone(), a.clone()));
|
||||
let b = make_owned(MockNode {
|
||||
kind: MockKind::Node,
|
||||
..Default::default()
|
||||
});
|
||||
assert!(!same_node(a, b));
|
||||
}
|
||||
|
||||
/// `same_block` compares by `ctx` identity.
|
||||
#[test]
|
||||
fn same_block_identity() {
|
||||
let a = make_owned(MockNode {
|
||||
kind: MockKind::Clip,
|
||||
..Default::default()
|
||||
});
|
||||
assert!(same_block(a.clone(), a.clone()));
|
||||
let b = make_owned(MockNode {
|
||||
kind: MockKind::Clip,
|
||||
..Default::default()
|
||||
});
|
||||
assert!(!same_block(a, b));
|
||||
}
|
||||
|
||||
/// `block_handle_less` / `track_handle_less` give a total order by `ctx`.
|
||||
#[test]
|
||||
fn handle_less_total_order() {
|
||||
let t1 = make_track();
|
||||
let t2 = make_track();
|
||||
|
||||
// Ordering matches the raw `ctx` comparison.
|
||||
assert_eq!(
|
||||
track_handle_less(t1.clone(), t2.clone()),
|
||||
t1.ctx.cmp(&t2.ctx)
|
||||
);
|
||||
assert_eq!(
|
||||
track_handle_less(t2.clone(), t1.clone()),
|
||||
t2.ctx.cmp(&t1.ctx)
|
||||
);
|
||||
assert_eq!(track_handle_less(t1.clone(), t1.clone()), Ordering::Equal);
|
||||
|
||||
assert_eq!(
|
||||
block_handle_less(t1.clone(), t2.clone()),
|
||||
t1.ctx.cmp(&t2.ctx)
|
||||
);
|
||||
assert_eq!(block_handle_less(t1.clone(), t1.clone()), Ordering::Equal);
|
||||
}
|
||||
|
||||
/// `free_detached_handle` is a no-op for a null pointer.
|
||||
#[test]
|
||||
fn free_detached_handle_null_noop() {
|
||||
free_detached_handle(std::ptr::null_mut());
|
||||
}
|
||||
|
||||
/// `free_detached_handle` on an owned handle releases its box and clears
|
||||
/// it, leaving a null/empty handle.
|
||||
#[test]
|
||||
fn free_detached_handle_releases_owned() {
|
||||
let t = make_track();
|
||||
let mut h = t.clone();
|
||||
free_detached_handle(&mut h);
|
||||
assert!(h.ctx.is_null());
|
||||
assert!(h.addref.is_none());
|
||||
assert!(h.release.is_none());
|
||||
assert_eq!(h.abi_version, 0);
|
||||
}
|
||||
|
||||
/// `error::Error::code` maps every variant to its frozen code.
|
||||
#[test]
|
||||
fn error_code_mapping() {
|
||||
assert_eq!(Error::Invalid.code(), OAKTIMELINE_E_INVALID);
|
||||
assert_eq!(Error::State.code(), OAKTIMELINE_E_STATE);
|
||||
assert_eq!(Error::Failed("x".to_string()).code(), OAKTIMELINE_E_FAILED);
|
||||
assert_eq!(Error::NotFound.code(), OAKTIMELINE_E_NOT_FOUND);
|
||||
assert_eq!(Error::NoMem.code(), OAKTIMELINE_E_NOMEM);
|
||||
}
|
||||
|
||||
/// `track_project` returns the project owning a track's sequence, via the
|
||||
/// sequence node view.
|
||||
#[test]
|
||||
fn track_project_follows_chain() {
|
||||
let proj = make_owned(MockNode {
|
||||
kind: MockKind::Project,
|
||||
..Default::default()
|
||||
});
|
||||
let seq = make_owned(MockNode {
|
||||
kind: MockKind::Sequence,
|
||||
..Default::default()
|
||||
});
|
||||
let t = make_track();
|
||||
|
||||
// Wire the graph: track -> sequence -> project.
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&t).unwrap().sequence = get_mut::<MockNode>(&seq).unwrap();
|
||||
get_mut::<MockNode>(&seq).unwrap().project = get_mut::<MockNode>(&proj).unwrap();
|
||||
}
|
||||
|
||||
let p = track_project(t.clone());
|
||||
assert!(!p.is_null());
|
||||
assert_eq!(p.ctx as usize, addr(&proj) as usize);
|
||||
}
|
||||
|
||||
/// `track_project` is a null handle when the track has no sequence.
|
||||
#[test]
|
||||
fn track_project_empty() {
|
||||
let t = make_track();
|
||||
assert!(track_project(t.clone()).is_null());
|
||||
}
|
||||
|
||||
/// `block_add_to_graph` / `block_remove_from_graph` adopt and detach a
|
||||
/// block from the project owning its track.
|
||||
#[test]
|
||||
fn block_graph_add_remove() {
|
||||
let proj = make_owned(MockNode {
|
||||
kind: MockKind::Project,
|
||||
..Default::default()
|
||||
});
|
||||
let seq = make_owned(MockNode {
|
||||
kind: MockKind::Sequence,
|
||||
..Default::default()
|
||||
});
|
||||
let t = make_track();
|
||||
let b = make_owned(MockNode {
|
||||
kind: MockKind::Clip,
|
||||
..Default::default()
|
||||
});
|
||||
unsafe {
|
||||
get_mut::<MockNode>(&t).unwrap().sequence = get_mut::<MockNode>(&seq).unwrap();
|
||||
get_mut::<MockNode>(&seq).unwrap().project = get_mut::<MockNode>(&proj).unwrap();
|
||||
}
|
||||
|
||||
block_add_to_graph(b.clone(), t.clone());
|
||||
assert_eq!(
|
||||
unsafe { get::<MockNode>(&b) }.unwrap().project as usize,
|
||||
addr(&proj) as usize
|
||||
);
|
||||
|
||||
block_remove_from_graph(b.clone(), t.clone());
|
||||
assert!(unsafe { get::<MockNode>(&b) }.unwrap().project.is_null());
|
||||
}
|
||||
|
||||
/// Graph helpers are no-ops when the track owns no project.
|
||||
#[test]
|
||||
fn block_graph_noop_without_project() {
|
||||
let t = make_track();
|
||||
let b = make_owned(MockNode {
|
||||
kind: MockKind::Clip,
|
||||
..Default::default()
|
||||
});
|
||||
block_add_to_graph(b.clone(), t.clone());
|
||||
assert!(unsafe { get::<MockNode>(&b) }.unwrap().project.is_null());
|
||||
block_remove_from_graph(b.clone(), t.clone());
|
||||
}
|
||||
@@ -16,16 +16,11 @@
|
||||
|
||||
//! Contract tests for the work area domain (`src/workarea.rs`):
|
||||
//! `TimelineWorkArea` value type, its two undo commands, and the
|
||||
//! `reset_in`/`reset_out` sentinels. XML load/save matches the format
|
||||
//! written by `timelineworkarea.cpp` (`<version=1>` attribute plus
|
||||
//! `enabled`/`in`/`out` text elements).
|
||||
#![cfg(feature = "test-stubs")]
|
||||
//! `reset_in`/`reset_out` sentinels. The XML load/save contract left
|
||||
//! with the deleted C ABI export layer (single-lib unification).
|
||||
|
||||
use oakcore_rs::{Rational, TimeRange};
|
||||
use oaktimeline::bridge::common::{oakcommon_xml_writer_free, oakcommon_xml_writer_init};
|
||||
use oaktimeline::bridge::teststubs::{xml_reader_handle, MockXmlNode, MockXmlWriter};
|
||||
use oaktimeline::ffi;
|
||||
use oaktimeline::handle::{get, get_mut, make_owned};
|
||||
use oaktimeline::handle::{get, make_owned};
|
||||
use oaktimeline::undocommon::Command;
|
||||
use oaktimeline::workarea::{
|
||||
reset_in, reset_out, TimelineWorkArea, WorkareaSetEnabledCommand, WorkareaSetRangeCommand,
|
||||
@@ -130,22 +125,33 @@ fn workarea_set_range_command_redo_undo() {
|
||||
);
|
||||
}
|
||||
|
||||
/// `to_command` boxes a work area command into a CHandle for the undo
|
||||
/// stack.
|
||||
/// `to_command` boxes a work area command into an oakundo `UndoCommand`
|
||||
/// value for the undo stack (the old C ABI command handle is gone with
|
||||
/// the single-lib unification).
|
||||
#[test]
|
||||
fn workarea_commands_box_to_chandle() {
|
||||
fn workarea_commands_box_to_undo_command() {
|
||||
let wa_h = make_owned(TimelineWorkArea::new());
|
||||
let enabled_cmd = WorkareaSetEnabledCommand::new(wa_h.clone(), true).to_command();
|
||||
assert!(!enabled_cmd.is_null());
|
||||
assert_eq!(enabled_cmd.abi_version, 1);
|
||||
let mut enabled_cmd = WorkareaSetEnabledCommand::new(wa_h.clone(), true).to_command();
|
||||
enabled_cmd.redo_now();
|
||||
assert!(unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().enabled());
|
||||
enabled_cmd.undo_now();
|
||||
assert!(!unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().enabled());
|
||||
|
||||
let range_cmd = WorkareaSetRangeCommand::new(
|
||||
let mut range_cmd = WorkareaSetRangeCommand::new(
|
||||
wa_h.clone(),
|
||||
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
|
||||
)
|
||||
.to_command();
|
||||
assert!(!range_cmd.is_null());
|
||||
assert_eq!(range_cmd.abi_version, 1);
|
||||
range_cmd.redo_now();
|
||||
assert_eq!(
|
||||
unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().in_(),
|
||||
Rational::new(1, 1)
|
||||
);
|
||||
range_cmd.undo_now();
|
||||
assert_eq!(
|
||||
unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().in_(),
|
||||
reset_in()
|
||||
);
|
||||
}
|
||||
|
||||
/// `Command` trait dispatch routes through the same redo/undo bodies as
|
||||
@@ -175,86 +181,3 @@ fn workarea_commands_trait_dispatch() {
|
||||
reset_in()
|
||||
);
|
||||
}
|
||||
|
||||
/// Save writes `<version=1>` plus `enabled`/`in`/`out` text elements;
|
||||
/// load reads them back (XML golden round-trip).
|
||||
#[test]
|
||||
fn workarea_xml_round_trip() {
|
||||
// Set up an enabled work area with a known range.
|
||||
let wa_h = make_owned(TimelineWorkArea::new());
|
||||
{
|
||||
let wa = unsafe { get_mut::<TimelineWorkArea>(&wa_h) }.unwrap();
|
||||
wa.set_enabled(true);
|
||||
wa.set_range(TimeRange::new(Rational::new(10, 1), Rational::new(20, 1)));
|
||||
}
|
||||
|
||||
// Save into a mock writer.
|
||||
let mut writer = unsafe { oakcommon_xml_writer_init() };
|
||||
let r = unsafe { ffi::workarea::oaktimeline_workarea_save(wa_h.clone(), writer.clone()) };
|
||||
assert_eq!(r, 0);
|
||||
let buf = unsafe { get::<MockXmlWriter>(&writer) }
|
||||
.unwrap()
|
||||
.buf
|
||||
.clone();
|
||||
assert!(buf.contains("version=\"1\""), "buf: {buf}");
|
||||
assert!(buf.contains("<enabled>1</enabled>"), "buf: {buf}");
|
||||
assert!(buf.contains("<in>10/1</in>"), "buf: {buf}");
|
||||
assert!(buf.contains("<out>20/1</out>"), "buf: {buf}");
|
||||
unsafe { oakcommon_xml_writer_free(&mut writer) };
|
||||
|
||||
// Load from a mock reader back into a fresh work area.
|
||||
let reader = xml_reader_handle(vec![
|
||||
MockXmlNode {
|
||||
name: "enabled".to_string(),
|
||||
text: "1".to_string(),
|
||||
attrs: Vec::new(),
|
||||
},
|
||||
MockXmlNode {
|
||||
name: "in".to_string(),
|
||||
text: "10/1".to_string(),
|
||||
attrs: Vec::new(),
|
||||
},
|
||||
MockXmlNode {
|
||||
name: "out".to_string(),
|
||||
text: "20/1".to_string(),
|
||||
attrs: Vec::new(),
|
||||
},
|
||||
]);
|
||||
let wa2_h = make_owned(TimelineWorkArea::new());
|
||||
let r2 = unsafe { ffi::workarea::oaktimeline_workarea_load(wa2_h.clone(), reader.clone()) };
|
||||
assert_eq!(r2, 0);
|
||||
let wa2 = unsafe { get::<TimelineWorkArea>(&wa2_h) }.unwrap();
|
||||
assert!(wa2.enabled());
|
||||
assert_eq!(wa2.in_(), Rational::new(10, 1));
|
||||
assert_eq!(wa2.out(), Rational::new(20, 1));
|
||||
}
|
||||
|
||||
/// An unset work area serializes to `enabled=0` and round-trips as a
|
||||
/// disabled, null-range work area.
|
||||
#[test]
|
||||
fn workarea_unset_round_trips_disabled() {
|
||||
let wa_h = make_owned(TimelineWorkArea::new());
|
||||
|
||||
let mut writer = unsafe { oakcommon_xml_writer_init() };
|
||||
let r = unsafe { ffi::workarea::oaktimeline_workarea_save(wa_h.clone(), writer.clone()) };
|
||||
assert_eq!(r, 0);
|
||||
let buf = unsafe { get::<MockXmlWriter>(&writer) }
|
||||
.unwrap()
|
||||
.buf
|
||||
.clone();
|
||||
assert!(buf.contains("<enabled>0</enabled>"), "buf: {buf}");
|
||||
unsafe { oakcommon_xml_writer_free(&mut writer) };
|
||||
|
||||
let reader = xml_reader_handle(vec![MockXmlNode {
|
||||
name: "enabled".to_string(),
|
||||
text: "0".to_string(),
|
||||
attrs: Vec::new(),
|
||||
}]);
|
||||
let wa2_h = make_owned(TimelineWorkArea::new());
|
||||
let r2 = unsafe { ffi::workarea::oaktimeline_workarea_load(wa2_h.clone(), reader.clone()) };
|
||||
assert_eq!(r2, 0);
|
||||
let wa2 = unsafe { get::<TimelineWorkArea>(&wa2_h) }.unwrap();
|
||||
assert!(!wa2.enabled());
|
||||
assert_eq!(wa2.in_(), reset_in());
|
||||
assert_eq!(wa2.out(), reset_out());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user