mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 17:41:05 +00:00
gstreamer/pad: Add tests for getrange functions
This commit is contained in:
parent
d7e6c2e37f
commit
7120d54a46
1 changed files with 57 additions and 0 deletions
|
@ -1612,6 +1612,63 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_getrange_function() {
|
||||
::init().unwrap();
|
||||
|
||||
let pad = ::Pad::new(Some("src"), ::PadDirection::Src);
|
||||
pad.set_activate_function(|pad, _parent| {
|
||||
pad.activate_mode(::PadMode::Pull, true)
|
||||
.map_err(|err| err.into())
|
||||
});
|
||||
pad.set_getrange_function(|_pad, _parent, offset, _buffer, size| {
|
||||
assert_eq!(offset, 0);
|
||||
assert_eq!(size, 5);
|
||||
let buffer = ::Buffer::from_slice(b"abcde");
|
||||
Ok(PadGetRangeSuccess::NewBuffer(buffer))
|
||||
});
|
||||
pad.set_active(true).unwrap();
|
||||
|
||||
let buffer = pad.get_range(0, 5).unwrap();
|
||||
let map = buffer.map_readable().unwrap();
|
||||
assert_eq!(&*map, b"abcde");
|
||||
|
||||
let mut buffer = ::Buffer::with_size(5).unwrap();
|
||||
pad.get_range_fill(0, buffer.get_mut().unwrap(), 5).unwrap();
|
||||
let map = buffer.map_readable().unwrap();
|
||||
assert_eq!(&*map, b"abcde");
|
||||
|
||||
pad.set_active(false).unwrap();
|
||||
drop(pad);
|
||||
|
||||
let pad = ::Pad::new(Some("src"), ::PadDirection::Src);
|
||||
pad.set_activate_function(|pad, _parent| {
|
||||
pad.activate_mode(::PadMode::Pull, true)
|
||||
.map_err(|err| err.into())
|
||||
});
|
||||
pad.set_getrange_function(|_pad, _parent, offset, buffer, size| {
|
||||
assert_eq!(offset, 0);
|
||||
assert_eq!(size, 5);
|
||||
if let Some(buffer) = buffer {
|
||||
buffer.copy_from_slice(0, b"fghij").unwrap();
|
||||
Ok(PadGetRangeSuccess::FilledBuffer)
|
||||
} else {
|
||||
let buffer = ::Buffer::from_slice(b"abcde");
|
||||
Ok(PadGetRangeSuccess::NewBuffer(buffer))
|
||||
}
|
||||
});
|
||||
pad.set_active(true).unwrap();
|
||||
|
||||
let buffer = pad.get_range(0, 5).unwrap();
|
||||
let map = buffer.map_readable().unwrap();
|
||||
assert_eq!(&*map, b"abcde");
|
||||
|
||||
let mut buffer = ::Buffer::with_size(5).unwrap();
|
||||
pad.get_range_fill(0, buffer.get_mut().unwrap(), 5).unwrap();
|
||||
let map = buffer.map_readable().unwrap();
|
||||
assert_eq!(&*map, b"fghij");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_task() {
|
||||
::init().unwrap();
|
||||
|
|
Loading…
Reference in a new issue