refactor: purge CHandle from module internals (M14 R5)

Module-internal object references are Rust types now (values, Arc,
Mutex); CHandle remains only at the oakengine C-ABI boundary:

- oakundo: the global stack holds UndoStack/UndoCommand values
  directly (stack token is the static's address)
- oaktimeline: marker/workarea boxes carry Arc<Mutex<T>>; commands
  share the same allocation through Arc clones (readers in oakengine
  stubs and the app's graphops updated to lock)
- oaktask/oakstorage: sessions, write-through bindings and the
  database backend pass ProjectArc; the Session drops its manual
  release bookkeeping; nodeutil keeps the CHandle<->Arc boundary
  conversion (release_project restored for the app)
- oakcodec: handle.rs deleted outright (no facade entry needed it);
  texture/block placeholders are unit structs
- oakrender: copier's project handle is an identity u64; alive-count
  machinery removed; handle.rs is make_owned/get/get_mut only
- oakplugin: the instance registry is gone (its unregister key never
  matched, leaking weak entries); handle.rs is the RefBox boundary type
- oaknode/oakcommon: only dead guard/borrow helpers removed; external
  payload handles (texture/processor) documented as the boundary

Flake hunts landed along the way: the audio recording test serializes
on the shared manager lock with a normalized state; the autocacher
cancel test uses a slow producer so cancellation is deterministic.
This commit is contained in:
2026-08-17 16:40:15 +08:00
parent ede03d0bfe
commit b36cbd6b6f
53 changed files with 1260 additions and 2369 deletions
+36 -102
View File
@@ -17,16 +17,16 @@
//! Contract tests for the refcounted-handle scaffolding
//! (`src/handle.rs`). The C++ gtest suite (`src/timeline/tests`)
//! drives the ABI-level refcount behaviour through the exports; these
//! tests pin the Rust-side primitive semantics that every export
//! relies on: null sentinel, `make_owned`/`make_borrowed` ownership,
//! panics escaping through `guard*`, and the ABI version stamp.
//! tests pin the Rust-side primitive semantics every facade-facing
//! entry relies on: the null sentinel, `make_owned`'s shared
//! `Arc<Mutex<T>>` box, and the ABI version stamp. The old
//! `guard*`/`make_borrowed` helpers left with the deleted C ABI export
//! layer.
use oaktimeline::error::{
Error, OAKTIMELINE_ABI_VERSION, OAKTIMELINE_E_FAILED, OAKTIMELINE_E_INVALID, OAKTIMELINE_OK,
};
use oaktimeline::handle::{
get, guard, guard_handle, guard_void, make_borrowed, make_owned, CHandle,
};
use std::sync::{Arc, Mutex};
use oaktimeline::error::OAKTIMELINE_ABI_VERSION;
use oaktimeline::handle::{get, make_owned, CHandle};
/// `CHandle::null()` is the all-null sentinel with abi_version 0.
#[test]
@@ -50,87 +50,45 @@ fn make_owned_starts_at_one_and_releases() {
// Addref bumps the count so the box is still live afterwards.
let addref = h.addref.unwrap();
// Safety: `h` is an owned handle whose box is `RefBox<i32>`.
// Safety: `h` is an owned handle whose box is `RefBox<Arc<Mutex<i32>>>`.
unsafe { addref(h.ctx) };
let val = unsafe { get::<i32>(&h) };
assert_eq!(val, Some(&42));
// SAFETY: `make_owned` boxes an `Arc<Mutex<T>>`.
let val = unsafe { get::<Arc<Mutex<i32>>>(&h) };
assert_eq!(*val.unwrap().lock().unwrap(), 42);
}
/// `make_owned` boxes a `Send + 'static` value and `get` returns the
/// boxed value back out.
/// `make_owned` boxes a `Send + 'static` value behind a shared
/// `Arc<Mutex<T>>` and `get` hands the shared `Arc` back out.
#[test]
fn make_owned_round_trips_value() {
let h = make_owned(7i32);
let val = unsafe { get::<i32>(&h) };
assert_eq!(val, Some(&7));
// SAFETY: `make_owned` boxes an `Arc<Mutex<T>>`.
let val = unsafe { get::<Arc<Mutex<i32>>>(&h) };
assert_eq!(*val.unwrap().lock().unwrap(), 7);
}
/// `make_borrowed` wraps a caller-owned pointer without transferring
/// ownership: releasing the borrowed handle frees only the box, never
/// the underlying object.
///
/// # Safety
/// The borrowed allocation must outlive the handle; the caller frees
/// it afterwards.
/// Every handle produced by `make_owned` shares one object: mutating
/// through a clone of the boxed `Arc` is visible through any other clone
/// of the same handle.
#[test]
fn make_borrowed_release_does_not_free_owner() {
let mut v = 5i32;
let h = unsafe { make_borrowed::<i32>(&mut v) };
assert!(!h.is_null());
// Releasing the borrowed handle destroys only the internal copy.
let release = h.release.unwrap();
// Safety: `h` is an owned box (see `make_borrowed`), release boxed copy.
unsafe { release(h.ctx) };
// The caller's object is untouched.
assert_eq!(v, 5);
fn make_owned_shares_one_object() {
let h1 = make_owned(0i32);
let h2 = h1.clone();
// SAFETY: both handles box the same `Arc<Mutex<i32>>` allocation.
let a = unsafe { get::<Arc<Mutex<i32>>>(&h1) }.unwrap().clone();
let b = unsafe { get::<Arc<Mutex<i32>>>(&h2) }.unwrap().clone();
assert!(Arc::ptr_eq(&a, &b));
*a.lock().unwrap() = 42;
assert_eq!(*b.lock().unwrap(), 42);
}
/// `guard` maps a successful closure to `OAKTIMELINE_OK`.
/// `get` on a null handle yields `None` (the null-handle sentinel maps
/// to "no object" everywhere).
#[test]
fn guard_success_returns_ok() {
assert_eq!(guard(|| Ok(())), OAKTIMELINE_OK);
}
/// `guard` maps an `Err(Error::Invalid)` to `OAKTIMELINE_E_INVALID`.
#[test]
fn guard_error_maps_code() {
assert_eq!(guard(|| Err(Error::Invalid)), OAKTIMELINE_E_INVALID);
}
/// `guard_handle` returns the inner handle on success.
#[test]
fn guard_handle_success_returns_handle() {
let inner = make_owned(3i32);
let out = guard_handle(|| Ok(inner.clone()));
assert!(!out.is_null());
assert_eq!(unsafe { get::<i32>(&out) }, Some(&3));
}
/// `guard_handle` returns a null handle on error so callers never see
/// a partially-built object.
#[test]
fn guard_handle_error_returns_null() {
let out = guard_handle(|| Err(Error::Invalid));
assert!(out.is_null());
}
/// A panicking closure does not unwind across the `guard_void` FFI
/// boundary; it is caught and converted to the failed code.
#[test]
fn guard_catches_panic() {
// `guard` maps the panic to the failed code.
let code = guard(|| -> oaktimeline::error::Result<()> {
panic!("boom");
});
assert_eq!(code, OAKTIMELINE_E_FAILED);
// `guard_void` swallows the panic without unwinding into the caller.
let mut reached = false;
guard_void(|| {
panic!("no unwind");
});
reached = true;
assert!(reached);
fn get_null_handle_is_none() {
let h = CHandle::null();
// SAFETY: null handle -> None without touching any pointer.
assert!(unsafe { get::<i32>(&h) }.is_none());
}
/// Every handle produced through the crate carries
@@ -141,27 +99,3 @@ fn handles_are_stamped_with_abi_version() {
assert_eq!(h.abi_version, OAKTIMELINE_ABI_VERSION);
assert_ne!(h.abi_version, 0);
}
/// Null and invalid handles are rejected uniformly: every `guard`
/// family returns the error code / null handle without touching the
/// pointer.
#[test]
fn guard_rejects_invalid_handles() {
let null_h = CHandle::null();
// Reading through a null handle yields None, which maps to invalid.
let code = guard(|| {
if unsafe { get::<i32>(&null_h) }.is_none() {
return Err(Error::Invalid);
}
Ok(())
});
assert_eq!(code, OAKTIMELINE_E_INVALID);
let h_out = guard_handle(|| {
if unsafe { get::<i32>(&null_h) }.is_none() {
return Err(Error::Invalid);
}
Ok(make_owned(0i32))
});
assert!(h_out.is_null());
}
+75 -213
View File
@@ -21,15 +21,28 @@
//! after out-of-band edits. The XML load/save contract left with the
//! deleted C ABI export layer (single-lib unification).
use std::sync::{Arc, Mutex, MutexGuard};
use oakcore_rs::{Rational, TimeRange};
use oaktimeline::common::EditToInfo;
use oaktimeline::handle::{get, get_mut, make_owned};
use oaktimeline::handle::{get, make_owned, CHandle};
use oaktimeline::marker::{
MarkerAddCommand, MarkerChangeColorCommand, MarkerChangeNameCommand, MarkerChangeTimeCommand,
MarkerRemoveCommand, TimelineMarker, TimelineMarkerList,
};
use oaktimeline::undocommon::Command;
/// Lock the shared marker list behind a live handle. Every marker-list
/// handle in these tests comes from `make_owned`, which boxes an
/// `Arc<Mutex<TimelineMarkerList>>`.
fn list_of(h: &CHandle) -> MutexGuard<'_, TimelineMarkerList> {
// SAFETY: as above; the handle is live.
unsafe { get::<Arc<Mutex<TimelineMarkerList>>>(h) }
.expect("live marker-list handle")
.lock()
.unwrap_or_else(|e| e.into_inner())
}
/// A default `TimelineMarker` starts at the null time with no name.
#[test]
fn marker_default_is_null_time() {
@@ -234,35 +247,22 @@ fn marker_add_command_undo_before_redo() {
0,
);
cmd.undo();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.size(),
0
);
assert_eq!(list_of(&list_h).size(), 0);
}
/// `MarkerRemoveCommand` redo is idempotent (a second redo is a no-op).
#[test]
fn marker_remove_command_double_redo() {
let list_h = make_owned(TimelineMarkerList::new());
{
let l = unsafe { get_mut::<TimelineMarkerList>(&list_h) }.unwrap();
l.add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
}
list_of(&list_h).add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
let mut cmd = MarkerRemoveCommand::new(list_h.clone(), 0);
cmd.redo();
cmd.redo();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.size(),
0
);
assert_eq!(list_of(&list_h).size(), 0);
}
/// Every marker command dispatches through the `Command` trait, which is
@@ -270,14 +270,11 @@ fn marker_remove_command_double_redo() {
#[test]
fn marker_commands_trait_dispatch() {
let list_h = make_owned(TimelineMarkerList::new());
{
let l = unsafe { get_mut::<TimelineMarkerList>(&list_h) }.unwrap();
l.add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
}
list_of(&list_h).add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
let mut add = MarkerAddCommand::new(
list_h.clone(),
@@ -286,75 +283,27 @@ fn marker_commands_trait_dispatch() {
0,
);
Command::redo(&mut add);
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.size(),
2
);
assert_eq!(list_of(&list_h).size(), 2);
Command::undo(&mut add);
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.size(),
1
);
assert_eq!(list_of(&list_h).size(), 1);
let mut remove = MarkerRemoveCommand::new(list_h.clone(), 0);
Command::redo(&mut remove);
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.size(),
0
);
assert_eq!(list_of(&list_h).size(), 0);
Command::undo(&mut remove);
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.size(),
1
);
assert_eq!(list_of(&list_h).size(), 1);
let mut color = MarkerChangeColorCommand::new(list_h.clone(), 0, 7);
Command::redo(&mut color);
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.at(0)
.unwrap()
.color(),
7
);
assert_eq!(list_of(&list_h).at(0).unwrap().color(), 7);
Command::undo(&mut color);
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.at(0)
.unwrap()
.color(),
1
);
assert_eq!(list_of(&list_h).at(0).unwrap().color(), 1);
let mut name = MarkerChangeNameCommand::new(list_h.clone(), 0, "z");
Command::redo(&mut name);
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.at(0)
.unwrap()
.name(),
"z"
);
assert_eq!(list_of(&list_h).at(0).unwrap().name(), "z");
Command::undo(&mut name);
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.at(0)
.unwrap()
.name(),
"m"
);
assert_eq!(list_of(&list_h).at(0).unwrap().name(), "m");
let mut time = MarkerChangeTimeCommand::new(
list_h.clone(),
@@ -363,22 +312,12 @@ fn marker_commands_trait_dispatch() {
);
Command::redo(&mut time);
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.at(0)
.unwrap()
.time()
.in_(),
list_of(&list_h).at(0).unwrap().time().in_(),
Rational::new(50, 1)
);
Command::undo(&mut time);
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.at(0)
.unwrap()
.time()
.in_(),
list_of(&list_h).at(0).unwrap().time().in_(),
Rational::new(1, 1)
);
}
@@ -428,27 +367,18 @@ fn marker_add_command_redo_undo() {
);
cmd.redo();
let list = unsafe { get::<TimelineMarkerList>(&list_h) }.unwrap();
let list = list_of(&list_h);
assert_eq!(list.size(), 1);
assert_eq!(list.at(0).unwrap().name(), "m");
assert_eq!(list.at(0).unwrap().color(), 4);
drop(list);
// Redo is idempotent.
cmd.redo();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.size(),
1
);
assert_eq!(list_of(&list_h).size(), 1);
cmd.undo();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.size(),
0
);
assert_eq!(list_of(&list_h).size(), 0);
}
/// A `MarkerRemoveCommand` redo drops the marker; undo re-inserts it
@@ -456,26 +386,18 @@ fn marker_add_command_redo_undo() {
#[test]
fn marker_remove_command_redo_undo() {
let list_h = make_owned(TimelineMarkerList::new());
{
let l = unsafe { get_mut::<TimelineMarkerList>(&list_h) }.unwrap();
l.add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
}
list_of(&list_h).add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
let mut cmd = MarkerRemoveCommand::new(list_h.clone(), 0);
cmd.redo();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.size(),
0
);
assert_eq!(list_of(&list_h).size(), 0);
cmd.undo();
let list = unsafe { get::<TimelineMarkerList>(&list_h) }.unwrap();
let list = list_of(&list_h);
assert_eq!(list.size(), 1);
assert_eq!(list.at(0).unwrap().name(), "m");
}
@@ -485,34 +407,17 @@ fn marker_remove_command_redo_undo() {
#[test]
fn marker_change_color_command_redo_undo() {
let list_h = make_owned(TimelineMarkerList::new());
{
let l = unsafe { get_mut::<TimelineMarkerList>(&list_h) }.unwrap();
l.add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
}
list_of(&list_h).add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
let mut cmd = MarkerChangeColorCommand::new(list_h.clone(), 0, 9);
cmd.redo();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.at(0)
.unwrap()
.color(),
9
);
assert_eq!(list_of(&list_h).at(0).unwrap().color(), 9);
cmd.undo();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.at(0)
.unwrap()
.color(),
1
);
assert_eq!(list_of(&list_h).at(0).unwrap().color(), 1);
}
/// `MarkerChangeNameCommand` redo changes the name and undo restores
@@ -520,34 +425,17 @@ fn marker_change_color_command_redo_undo() {
#[test]
fn marker_change_name_command_redo_undo() {
let list_h = make_owned(TimelineMarkerList::new());
{
let l = unsafe { get_mut::<TimelineMarkerList>(&list_h) }.unwrap();
l.add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
}
list_of(&list_h).add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
let mut cmd = MarkerChangeNameCommand::new(list_h.clone(), 0, "renamed");
cmd.redo();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.at(0)
.unwrap()
.name(),
"renamed"
);
assert_eq!(list_of(&list_h).at(0).unwrap().name(), "renamed");
cmd.undo();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.at(0)
.unwrap()
.name(),
"m"
);
assert_eq!(list_of(&list_h).at(0).unwrap().name(), "m");
}
/// `MarkerChangeTimeCommand` redo moves the marker and undo restores
@@ -555,35 +443,22 @@ fn marker_change_name_command_redo_undo() {
#[test]
fn marker_change_time_command_redo_undo() {
let list_h = make_owned(TimelineMarkerList::new());
{
let l = unsafe { get_mut::<TimelineMarkerList>(&list_h) }.unwrap();
l.add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
}
list_of(&list_h).add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
let new_t = TimeRange::new(Rational::new(50, 1), Rational::new(51, 1));
let mut cmd = MarkerChangeTimeCommand::new(list_h.clone(), 0, new_t);
cmd.redo();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.at(0)
.unwrap()
.time()
.in_(),
list_of(&list_h).at(0).unwrap().time().in_(),
Rational::new(50, 1)
);
cmd.undo();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.at(0)
.unwrap()
.time()
.in_(),
list_of(&list_h).at(0).unwrap().time().in_(),
Rational::new(1, 1)
);
}
@@ -595,14 +470,11 @@ fn marker_change_time_command_redo_undo() {
#[test]
fn marker_commands_box_to_undo_command() {
let list_h = make_owned(TimelineMarkerList::new());
{
let l = unsafe { get_mut::<TimelineMarkerList>(&list_h) }.unwrap();
l.add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
}
list_of(&list_h).add_marker(TimelineMarker::with_time(
1,
TimeRange::new(Rational::new(1, 1), Rational::new(2, 1)),
"m",
));
let mut cmd = MarkerAddCommand::new(
list_h.clone(),
@@ -612,19 +484,9 @@ fn marker_commands_box_to_undo_command() {
)
.to_command();
cmd.redo_now();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.size(),
2
);
assert_eq!(list_of(&list_h).size(), 2);
cmd.undo_now();
assert_eq!(
unsafe { get::<TimelineMarkerList>(&list_h) }
.unwrap()
.size(),
1
);
assert_eq!(list_of(&list_h).size(), 1);
}
/// Loading a marker with a `color`/`in`/`out` attribute equal to the
+27 -35
View File
@@ -19,13 +19,26 @@
//! `reset_in`/`reset_out` sentinels. The XML load/save contract left
//! with the deleted C ABI export layer (single-lib unification).
use std::sync::{Arc, Mutex, MutexGuard};
use oakcore_rs::{Rational, TimeRange};
use oaktimeline::handle::{get, make_owned};
use oaktimeline::handle::{get, make_owned, CHandle};
use oaktimeline::undocommon::Command;
use oaktimeline::workarea::{
reset_in, reset_out, TimelineWorkArea, WorkareaSetEnabledCommand, WorkareaSetRangeCommand,
};
/// Lock the shared work area behind a live handle. Every work-area handle
/// in these tests comes from `make_owned`, which boxes an
/// `Arc<Mutex<TimelineWorkArea>>`.
fn wa_of(h: &CHandle) -> MutexGuard<'_, TimelineWorkArea> {
// SAFETY: as above; the handle is live.
unsafe { get::<Arc<Mutex<TimelineWorkArea>>>(h) }
.expect("live work-area handle")
.lock()
.unwrap_or_else(|e| e.into_inner())
}
/// `reset_in` is the null rational (0/1) marking an unset work area
/// start.
#[test]
@@ -96,9 +109,9 @@ fn workarea_set_enabled_command_redo_undo() {
let wa_h = make_owned(TimelineWorkArea::new());
let mut cmd = WorkareaSetEnabledCommand::new(wa_h.clone(), true);
cmd.redo();
assert!(unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().enabled());
assert!(wa_of(&wa_h).enabled());
cmd.undo();
assert!(!unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().enabled());
assert!(!wa_of(&wa_h).enabled());
}
/// `WorkareaSetRangeCommand` redo stores the new range and undo
@@ -109,20 +122,11 @@ fn workarea_set_range_command_redo_undo() {
let new_range = TimeRange::new(Rational::new(10, 1), Rational::new(20, 1));
let mut cmd = WorkareaSetRangeCommand::new(wa_h.clone(), new_range);
cmd.redo();
assert_eq!(
*unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().range(),
new_range
);
assert_eq!(*wa_of(&wa_h).range(), new_range);
cmd.undo();
// Undo restores the range captured at construction (the reset range).
assert_eq!(
unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().in_(),
reset_in()
);
assert_eq!(
unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().out(),
reset_out()
);
assert_eq!(wa_of(&wa_h).in_(), reset_in());
assert_eq!(wa_of(&wa_h).out(), reset_out());
}
/// `to_command` boxes a work area command into an oakundo `UndoCommand`
@@ -133,9 +137,9 @@ fn workarea_commands_box_to_undo_command() {
let wa_h = make_owned(TimelineWorkArea::new());
let mut enabled_cmd = WorkareaSetEnabledCommand::new(wa_h.clone(), true).to_command();
enabled_cmd.redo_now();
assert!(unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().enabled());
assert!(wa_of(&wa_h).enabled());
enabled_cmd.undo_now();
assert!(!unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().enabled());
assert!(!wa_of(&wa_h).enabled());
let mut range_cmd = WorkareaSetRangeCommand::new(
wa_h.clone(),
@@ -143,15 +147,9 @@ fn workarea_commands_box_to_undo_command() {
)
.to_command();
range_cmd.redo_now();
assert_eq!(
unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().in_(),
Rational::new(1, 1)
);
assert_eq!(wa_of(&wa_h).in_(), Rational::new(1, 1));
range_cmd.undo_now();
assert_eq!(
unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().in_(),
reset_in()
);
assert_eq!(wa_of(&wa_h).in_(), reset_in());
}
/// `Command` trait dispatch routes through the same redo/undo bodies as
@@ -162,22 +160,16 @@ fn workarea_commands_trait_dispatch() {
let mut e = WorkareaSetEnabledCommand::new(wa_h.clone(), true);
Command::redo(&mut e);
assert!(unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().enabled());
assert!(wa_of(&wa_h).enabled());
Command::undo(&mut e);
assert!(!unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().enabled());
assert!(!wa_of(&wa_h).enabled());
let mut r = WorkareaSetRangeCommand::new(
wa_h.clone(),
TimeRange::new(Rational::new(3, 1), Rational::new(4, 1)),
);
Command::redo(&mut r);
assert_eq!(
unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().in_(),
Rational::new(3, 1)
);
assert_eq!(wa_of(&wa_h).in_(), Rational::new(3, 1));
Command::undo(&mut r);
assert_eq!(
unsafe { get::<TimelineWorkArea>(&wa_h) }.unwrap().in_(),
reset_in()
);
assert_eq!(wa_of(&wa_h).in_(), reset_in());
}