mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-07 12:13:20 +00:00
craft-print: the Windows test counts driver queries during printer_queues
The live spooler test only checked that printer_queues() reports two_sided as unknown, which would still pass if it called printers() and cleared the field (CodeRabbit on #618). A test-only per-thread counter in two_sided(), the one PrintCapabilities query printer discovery makes, now shows printers() querying the test queue's driver (the control) and printer_queues() querying none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
62b0fe5edb
commit
a20c900ce0
@@ -409,9 +409,15 @@ fn windows_jobs_reach_the_spooler() {
|
||||
eprintln!("skipping the real print: the test printer could not be prepared: {why}");
|
||||
return;
|
||||
}
|
||||
let queries = || crate::windows::CAPABILITY_QUERIES.with(std::cell::Cell::get);
|
||||
let start = queries();
|
||||
let listed = spool::printers().into_iter().find(|p| p.name == name);
|
||||
// The list a Print dialog shows first: the same queue, named without asking its driver.
|
||||
let probed = queries().saturating_sub(start);
|
||||
// The list a Print dialog shows first: the same queue, named without asking its driver (a
|
||||
// networked printer in power save can hold that query, storytold/wordcraft#5710).
|
||||
let start = queries();
|
||||
let queue = spool::printer_queues().into_iter().find(|p| p.name == name);
|
||||
let unprobed = queries().saturating_sub(start);
|
||||
let mixed = test_pdf(&[LETTER, LETTER_LANDSCAPE, LETTER], true);
|
||||
let job = Job { printer: Some(name.into()), title: "mixed.pdf".into(), ..Job::default() };
|
||||
let caller = std::thread::current().id();
|
||||
@@ -452,7 +458,9 @@ fn windows_jobs_reach_the_spooler() {
|
||||
name,
|
||||
);
|
||||
assert!(listed.as_ref().is_some_and(|p| p.two_sided.is_some()), "the new printer is listed, its duplex support known: {listed:?}");
|
||||
assert!(queue.as_ref().is_some_and(|p| p.two_sided.is_none()), "the new printer is listed with no driver query: {queue:?}");
|
||||
assert!(queue.as_ref().is_some_and(|p| p.two_sided.is_none()), "the new printer is listed, its duplex support unknown: {queue:?}");
|
||||
assert!(probed > 0, "printers() asks each driver, so the count sees driver queries: {probed}");
|
||||
assert_eq!(unprobed, 0, "printer_queues() asks no driver");
|
||||
assert_eq!(sent.as_deref(), Ok("spooled 3 sheet(s)"), "{sent:?}");
|
||||
if let Some(refused) = duplex_refused {
|
||||
assert!(matches!(refused, Err(Error::Spool(ref m)) if m.contains("simplex/duplex") && m.contains("nothing was sent")), "{refused:?}");
|
||||
|
||||
@@ -60,10 +60,19 @@ fn spooler_list(two_sided: impl Fn(&PrinterDevice) -> Option<bool>) -> Vec<Print
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
thread_local! {
|
||||
/// The driver capability queries printer discovery made on this thread, so a test can show
|
||||
/// that [`printer_queues`] makes none.
|
||||
pub(crate) static CAPABILITY_QUERIES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
/// Whether the printer's driver takes two-sided settings: its PrintCapabilities offer a two-sided
|
||||
/// option for the feature the job's ticket sets. `None` when the capabilities can't be read. A
|
||||
/// driver without one cannot confirm an explicit two-sided request, which is refused before submission.
|
||||
fn two_sided(device: &PrinterDevice) -> Option<bool> {
|
||||
#[cfg(test)]
|
||||
CAPABILITY_QUERIES.with(|n| n.set(n.get().saturating_add(1)));
|
||||
let capabilities = {
|
||||
let _provider = print_ticket_provider();
|
||||
PrintCapabilities::fetch(device)
|
||||
|
||||
Reference in New Issue
Block a user