Add tests for Element::foreach_pad() and Bus::set_sync_handler()

This commit is contained in:
Sebastian Dröge 2019-01-29 16:14:06 +02:00
parent 5625a75b1b
commit 49c5fa33ba
2 changed files with 44 additions and 0 deletions

View file

@ -223,3 +223,31 @@ mod futures {
#[cfg(any(feature = "futures", feature = "dox"))]
pub use bus::futures::BusStream;
#[cfg(test)]
mod tests {
use super::*;
use std::sync::{Arc, Mutex};
#[test]
fn test_sync_handler() {
::init().unwrap();
let bus = Bus::new();
let msgs = Arc::new(Mutex::new(Vec::new()));
let msgs_clone = msgs.clone();
bus.set_sync_handler(move |_, msg| {
msgs_clone.lock().unwrap().push(msg.clone());
BusSyncReply::Pass
});
bus.post(&::Message::new_eos().build()).unwrap();
let msgs = msgs.lock().unwrap();
assert_eq!(msgs.len(), 1);
match msgs[0].view() {
::MessageView::Eos(_) => (),
_ => unreachable!(),
}
}
}

View file

@ -1257,6 +1257,22 @@ mod tests {
assert_eq!(pad_names, vec![String::from("src")]);
}
#[test]
fn test_foreach_pad() {
::init().unwrap();
let identity = ::ElementFactory::make("identity", None).unwrap();
let mut pad_names = Vec::new();
identity.foreach_pad(|_element, pad| {
pad_names.push(pad.get_name());
true
});
pad_names.sort();
assert_eq!(pad_names, vec![String::from("sink"), String::from("src")]);
}
#[cfg(feature = "v1_10")]
#[test]
fn test_call_async() {