Skip to content

Commit

Permalink
Add test for AVChannelLayoutIter
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 committed Jan 1, 2024
1 parent 550e989 commit c2a0afd
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/avutil/channel_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl AVChannelLayout {

/// Iterate over all standard channel layouts.
pub struct AVChannelLayoutIter {
opaque: *mut *mut c_void,
opaque: *mut c_void,
}

impl Default for AVChannelLayoutIter {
Expand All @@ -196,8 +196,26 @@ impl Iterator for AVChannelLayoutIter {
type Item = AVChannelLayoutRef<'static>;

fn next(&mut self) -> Option<Self::Item> {
unsafe { ffi::av_channel_layout_standard(self.opaque) }
unsafe { ffi::av_channel_layout_standard(&mut self.opaque) }
.upgrade()
.map(|ptr| unsafe { AVChannelLayoutRef::from_raw(ptr) })
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn channel_layout_iterator_test() {
let mut iter = AVChannelLayoutIter::default();
let item = iter.next().unwrap();
assert_eq!(item.describe().unwrap().to_str().unwrap(), "mono");
let mut item = iter.next().unwrap();
assert_eq!(item.describe().unwrap().to_str().unwrap(), "stereo");
for x in iter {
item = x;
}
assert_eq!(item.describe().unwrap().to_str().unwrap(), "22.2");
}
}

0 comments on commit c2a0afd

Please sign in to comment.