mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-18 00:26:04 +00:00
M10: the missing-DLL test checks that printers() never asked the backend
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pq7HyCfwzyRXj4VfQAVVdv
This commit is contained in:
1 parent
f1753c1431
commit
914001a784
2 files changed
+9
-1
No files matched your search
@@ -24,6 +24,9 @@ thread_local! {
|
||||
/// Tests: the folder the print DLLs are looked for in, instead of the system's, so the
|
||||
/// public entry points can be checked against a Windows that lacks them.
|
||||
pub(crate) static SYSTEM32_FOR_TEST: std::cell::RefCell<Option<std::path::PathBuf>> = const { std::cell::RefCell::new(None) };
|
||||
/// Tests: how many times [`printers`] asked the system's printer backend, so a test can tell
|
||||
/// the guard answered without relying on the machine having no printers.
|
||||
pub(crate) static PRINTER_BACKEND_CALLS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
/// The first print DLL this Windows installation lacks. `None` when all are there, and when the
|
||||
@@ -51,6 +54,8 @@ pub fn printers() -> Vec<Printer> {
|
||||
if missing_print_dll().is_some() {
|
||||
return Vec::new();
|
||||
}
|
||||
#[cfg(all(windows, test))]
|
||||
PRINTER_BACKEND_CALLS.with(|c| c.set(c.get().saturating_add(1)));
|
||||
craft_print::printers()
|
||||
}
|
||||
|
||||
|
||||
@@ -1169,7 +1169,7 @@ fn missing_print_dlls_are_named() {
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn printing_without_the_print_dlls_is_refused_before_the_spooler() {
|
||||
use crate::spool::{PRINT_DLLS, SYSTEM32_FOR_TEST, printers, submit, submit_with_progress};
|
||||
use crate::spool::{PRINT_DLLS, PRINTER_BACKEND_CALLS, SYSTEM32_FOR_TEST, printers, submit, submit_with_progress};
|
||||
let dir = std::env::temp_dir().join(format!("pdfcraft-print-no-dlls-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
@@ -1183,7 +1183,10 @@ fn printing_without_the_print_dlls_is_refused_before_the_spooler() {
|
||||
let mut called = false;
|
||||
assert!(named(submit_with_progress(b"not a PDF", &job, &mut |_, _| called = true)), "submit_with_progress names it");
|
||||
assert!(!called, "no sheet reached a spooler");
|
||||
// Not only an empty list, which a machine without printers gives anyway: the backend wasn't asked.
|
||||
PRINTER_BACKEND_CALLS.with(|c| c.set(0));
|
||||
assert!(printers().is_empty(), "no printers are listed");
|
||||
assert_eq!(PRINTER_BACKEND_CALLS.with(|c| c.get()), 0, "the printer backend wasn't asked");
|
||||
SYSTEM32_FOR_TEST.with(|d| *d.borrow_mut() = None);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
Reference in new issue
Block a user