33 lines
876 B
Rust
33 lines
876 B
Rust
use std::cell::RefCell;
|
|
use std::rc::Rc;
|
|
|
|
use niom_webrtc::components::ErrorActions;
|
|
|
|
#[test]
|
|
fn report_and_clear_delegate_to_callbacks() {
|
|
let reported: Rc<RefCell<Vec<String>>> = Rc::new(RefCell::new(Vec::new()));
|
|
let cleared: Rc<RefCell<u32>> = Rc::new(RefCell::new(0));
|
|
|
|
let report_fn = {
|
|
let reported = Rc::clone(&reported);
|
|
Rc::new(move |msg: String| {
|
|
reported.borrow_mut().push(msg);
|
|
}) as Rc<dyn Fn(String)>
|
|
};
|
|
|
|
let clear_fn = {
|
|
let cleared = Rc::clone(&cleared);
|
|
Rc::new(move || {
|
|
*cleared.borrow_mut() += 1;
|
|
}) as Rc<dyn Fn()>
|
|
};
|
|
|
|
let actions = ErrorActions::new(report_fn, clear_fn);
|
|
actions.report("boom");
|
|
actions.report("bam");
|
|
actions.clear();
|
|
|
|
assert_eq!(reported.borrow().as_slice(), ["boom", "bam"]);
|
|
assert_eq!(*cleared.borrow(), 1);
|
|
}
|