#[cfg(target_os = "macos")]
#[cfg(test)]
mod tests {
use image::GenericImageView;
use std::path::PathBuf;
use uni_ocr::{perform_ocr_apple, Language};
#[tokio::test]
async fn test_apple_native_ocr() {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("tests");
path.push("testing_OCR.png");
println!("Path to testing_OCR.png: {:?}", path);
if let Ok(metadata) = std::fs::metadata(&path) {
println!("File size: {} bytes", metadata.len());
}
let image = image::open(&path).expect("Failed to open image");
println!("Image dimensions: {:?}", image.dimensions());
let rgb_image = image.to_rgb8();
println!("RGB image dimensions: {:?}", rgb_image.dimensions());
let (ocr_text, _, _) = perform_ocr_apple(&image, &[]);
println!("OCR text: {:?}", ocr_text);
assert!(
ocr_text.contains("receiver_count"),
"OCR failed: {:?}",
ocr_text
);
}
#[tokio::test]
async fn test_apple_native_ocr_chinese() {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("tests");
path.push("testing_OCR_chinese.png");
println!("Path to testing_OCR_chinese.png: {:?}", path);
let image = image::open(&path).expect("Failed to open Chinese test image");
println!("Image dimensions: {:?}", image.dimensions());
let (ocr_text, _, _) = perform_ocr_apple(&image, &[Language::Chinese]);
println!("OCR text: {:?}", ocr_text);
assert!(
ocr_text.contains("管理分支"),
"OCR failed to recognize Chinese text: {:?}",
ocr_text
);
}
}