use budget_capture::desktop::packed_rgb; #[test] fn padded_bgra_rows_and_offset_are_respected() { let bytes = [ 99, 99, 3, 2, 1, 255, 6, 5, 4, 255, 0, 0, 0, 0, 9, 8, 7, 255, 12, 11, 10, 255, ]; assert_eq!( packed_rgb(&bytes, 2, 2, 12, 2, true, 4).unwrap(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] ); } #[test] fn invalid_buffers_are_rejected_before_copy() { for (w, h, stride, offset, channels) in [ (0, 1, 4, 0, 4), (1, 0, 4, 0, 4), (1, 1, -4, 0, 4), (2, 1, 4, 0, 4), (1, 1, 4, usize::MAX, 4), (1, 2, 4, 0, 4), (1, 1, 4, 0, 2), (16384, 16384, 65536, 0, 4), ] { assert!(packed_rgb(&[1, 2, 3, 4], w, h, stride, offset, false, channels).is_err()); } } #[test] fn rgb_and_rgba_channel_orders() { assert_eq!( packed_rgb(&[1, 2, 3], 1, 1, 3, 0, false, 3).unwrap(), [1, 2, 3] ); assert_eq!( packed_rgb(&[1, 2, 3, 0], 1, 1, 4, 0, false, 4).unwrap(), [1, 2, 3] ); } #[cfg(all(target_os = "linux", not(target_env = "ohos")))] #[test] fn real_x11_one_frame_and_offline_ocr_when_opted_in() { if std::env::var("BUDGET_LIVE_X11_TEST").as_deref() != Ok("1") { return; } assert!( std::env::var_os("DISPLAY").is_some(), "run under Xvfb or an explicit test display" ); assert!(std::env::var_os("WAYLAND_DISPLAY").is_none()); let (send, recv) = std::sync::mpsc::channel(); let job = budget_capture::desktop::CaptureJob::start(std::sync::Arc::new(move || { let _ = send.send(()); })) .unwrap(); recv.recv_timeout(std::time::Duration::from_secs(90)) .expect("bounded worker completion"); assert!( job.poll().unwrap().is_ok(), "capture/OCR must succeed, not silently skip" ); }