use assert_cmd::Command;
use std::env;
fn cmd() -> Command {
Command::cargo_bin("oximedia-cv2").expect("binary not found")
}
fn make_test_png() -> (Vec<u8>, std::path::PathBuf) {
let png_bytes: Vec<u8> = vec![
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53, 0xDE, 0x00, 0x00, 0x00, 0x0C, 0x49, 0x44, 0x41, 0x54, 0x08, 0xD7, 0x63, 0xF8, 0xCF, 0xC0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0xE2, 0x21, 0xBC, 0x33, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82, ];
let tmp_dir = env::temp_dir();
let input = tmp_dir.join("cv2_test_input.png");
std::fs::write(&input, &png_bytes).expect("write test png");
(png_bytes, input)
}
#[test]
fn imread_imwrite_round_trip_png() {
let (_, input) = make_test_png();
let output = env::temp_dir().join("cv2_test_output.png");
let result = cmd()
.args(["imread", input.to_str().unwrap(), output.to_str().unwrap()])
.output()
.expect("failed to run");
if result.status.success() {
let out_bytes = std::fs::read(&output).expect("read output png");
assert_eq!(
&out_bytes[0..4],
&[0x89, 0x50, 0x4E, 0x47],
"output is not PNG"
);
let _ = std::fs::remove_file(&output);
} else {
let stderr = String::from_utf8_lossy(&result.stderr);
eprintln!("imread skipped — decode failed: {stderr}");
}
let _ = std::fs::remove_file(&input);
}
#[test]
fn probe_works_on_valid_png() {
let (_, input) = make_test_png();
let result = cmd()
.args(["probe", input.to_str().unwrap()])
.output()
.expect("failed to run");
if result.status.success() {
let stdout = String::from_utf8_lossy(&result.stdout);
assert!(stdout.contains("rows:"), "expected 'rows:' in probe output");
assert!(stdout.contains("cols:"), "expected 'cols:' in probe output");
} else {
let stderr = String::from_utf8_lossy(&result.stderr);
eprintln!("probe skipped — decode failed: {stderr}");
}
let _ = std::fs::remove_file(&input);
}