108 lines
2.7 KiB
Rust
108 lines
2.7 KiB
Rust
//! Integration tests for camera functionality
|
|
//!
|
|
//! These tests require camera hardware or will use mocks on non-Linux systems.
|
|
|
|
use linux_hello_common::Result;
|
|
use linux_hello_daemon::camera::{enumerate_cameras, Camera, IrEmitterControl};
|
|
|
|
#[test]
|
|
fn test_camera_enumeration() -> Result<()> {
|
|
let cameras = enumerate_cameras()?;
|
|
|
|
// Should at least enumerate (may be empty if no cameras)
|
|
println!("Found {} camera(s)", cameras.len());
|
|
for cam in &cameras {
|
|
println!(" - {}", cam);
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn test_camera_open_and_capture() -> Result<()> {
|
|
let cameras = enumerate_cameras()?;
|
|
|
|
if cameras.is_empty() {
|
|
println!("No cameras available, skipping capture test");
|
|
return Ok(());
|
|
}
|
|
|
|
// Try to open the first camera
|
|
let first_cam = &cameras[0];
|
|
println!("Opening camera: {}", first_cam.device_path);
|
|
|
|
let mut camera = Camera::open(&first_cam.device_path)?;
|
|
let (width, height) = camera.resolution();
|
|
println!("Camera resolution: {}x{}", width, height);
|
|
|
|
// Capture a few frames
|
|
for i in 0..3 {
|
|
let frame = camera.capture_frame()?;
|
|
println!(
|
|
"Frame {}: {}x{}, format: {:?}, size: {} bytes, timestamp: {} us",
|
|
i + 1,
|
|
frame.width,
|
|
frame.height,
|
|
frame.format,
|
|
frame.data.len(),
|
|
frame.timestamp_us
|
|
);
|
|
|
|
// Verify frame properties
|
|
assert_eq!(frame.width, width);
|
|
assert_eq!(frame.height, height);
|
|
assert!(!frame.data.is_empty());
|
|
}
|
|
|
|
camera.stop();
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn test_ir_emitter_control() -> Result<()> {
|
|
let cameras = enumerate_cameras()?;
|
|
|
|
// Find an IR camera if available
|
|
let ir_camera = cameras.iter().find(|c| c.is_ir);
|
|
|
|
if let Some(cam) = ir_camera {
|
|
println!("Testing IR emitter on: {}", cam.device_path);
|
|
|
|
let mut emitter = IrEmitterControl::new(&cam.device_path);
|
|
|
|
// Try to enable
|
|
emitter.enable()?;
|
|
assert!(emitter.is_active());
|
|
println!("IR emitter enabled");
|
|
|
|
// Try to disable
|
|
emitter.disable()?;
|
|
assert!(!emitter.is_active());
|
|
println!("IR emitter disabled");
|
|
} else {
|
|
println!("No IR camera found, skipping IR emitter test");
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn test_camera_info_properties() -> Result<()> {
|
|
let cameras = enumerate_cameras()?;
|
|
|
|
for cam in cameras {
|
|
// Verify all cameras have valid properties
|
|
assert!(!cam.device_path.is_empty());
|
|
assert!(!cam.name.is_empty());
|
|
|
|
println!(
|
|
"Camera: {} (IR: {}, Resolutions: {})",
|
|
cam.device_path,
|
|
cam.is_ir,
|
|
cam.resolutions.len()
|
|
);
|
|
}
|
|
|
|
Ok(())
|
|
}
|