Skip to content

sound: add tests to Alsa and other test stuff #579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 14, 2023
2 changes: 1 addition & 1 deletion staging/coverage_config_x86_64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 67.98,
"coverage_score": 71.65,
"exclude_path": "",
"crate_features": ""
}
35 changes: 35 additions & 0 deletions staging/vhost-device-sound/src/audio_backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub trait AudioBackend {
fn stop(&self, _stream_id: u32) -> Result<()> {
Ok(())
}

#[cfg(test)]
fn as_any(&self) -> &dyn std::any::Any;
}

pub fn alloc_audio_backend(
Expand All @@ -56,3 +59,35 @@ pub fn alloc_audio_backend(
BackendType::Alsa => Ok(Box::new(AlsaBackend::new(streams))),
}
}

#[cfg(test)]
mod tests {
use std::any::TypeId;

use super::*;

#[test]
fn test_alloc_audio_backend() {
crate::init_logger();
{
let v = BackendType::Null;
let value = alloc_audio_backend(v, Default::default()).unwrap();
assert_eq!(TypeId::of::<NullBackend>(), value.as_any().type_id());
}
#[cfg(feature = "pw-backend")]
{
use pipewire::{test_utils::PipewireTestHarness, *};

let _test_harness = PipewireTestHarness::new();
let v = BackendType::Pipewire;
let value = alloc_audio_backend(v, Default::default()).unwrap();
assert_eq!(TypeId::of::<PwBackend>(), value.as_any().type_id());
}
#[cfg(feature = "alsa-backend")]
{
let v = BackendType::Alsa;
let value = alloc_audio_backend(v, Default::default()).unwrap();
assert_eq!(TypeId::of::<AlsaBackend>(), value.as_any().type_id());
}
}
}
Loading