From bd3799916696c583b2da78468e49ab7c043a7840 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 11 Sep 2024 14:17:17 -0400 Subject: [PATCH] gstreamer: Add tests for pad probes taking and dropping data This is quite similar to the HANDLED case, so reuse that code. Part-of: --- gstreamer/src/pad.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index b4509397e..7b9d25e82 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -2416,8 +2416,8 @@ mod tests { assert_eq!(counter.load(std::sync::atomic::Ordering::SeqCst), 1); } - #[test] - fn test_probe() { + fn do_probe_with_return(probe_return: crate::PadProbeReturn) { + skip_assert_initialized!(); crate::init().unwrap(); let (major, minor, micro, _) = crate::version(); @@ -2457,7 +2457,7 @@ mod tests { } else { unreachable!(); } - crate::PadProbeReturn::Handled + probe_return }); } @@ -2475,7 +2475,7 @@ mod tests { } else { unreachable!(); } - crate::PadProbeReturn::Handled + probe_return }); } @@ -2491,7 +2491,15 @@ mod tests { assert!(pad.push_event(crate::event::Segment::new(segment.as_ref()))); assert_eq!(pad.push(crate::Buffer::new()), Ok(FlowSuccess::Ok)); - assert_eq!(pad.push(crate::Buffer::new()), flow_override); + assert_eq!( + pad.push(crate::Buffer::new()), + // On Drop, we will get an Ok, not whatever value we returned + if probe_return == crate::PadProbeReturn::Drop { + Ok(FlowSuccess::Ok) + } else { + flow_override + } + ); let events = events.lock().unwrap(); let buffers = buffers.lock().unwrap(); @@ -2514,6 +2522,18 @@ mod tests { ); } + #[test] + fn test_probe() { + crate::init().unwrap(); + do_probe_with_return(crate::PadProbeReturn::Handled); + } + + #[test] + fn test_probe_drop() { + crate::init().unwrap(); + do_probe_with_return(crate::PadProbeReturn::Drop); + } + #[test] fn test_sticky_events() { crate::init().unwrap();