ui::testing::TestPrintHost¶
Header: winui/testing/TestPrintHost.hpp.
Derives from ui::PrintHost.
PrintHost test double: shows no dialog and prints to nothing. It runs the job on US Letter paper with the headless measurer, keeps each page's drawing, and answers as told.
Install it with set_print_host(); ui::print() then reaches it. It uninstalls itself when destroyed.
Example:
ui::testing::TestPrintHost printer;
ui::testing::set_print_host(&printer);
const ui::PrintResult result = ui::print(window, ui::PrintJob{
.title = "Report",
.page_count = [](const ui::PrintPage&, const ui::PrintContext&) { return std::size_t{3}; },
.draw_page = [](ui::Renderer&, const ui::PrintPage&, const ui::PrintContext&) { /* draw the page */ },
});
REQUIRE(result == ui::PrintResult::Printed);
REQUIRE(printer.pages.size() == 3);
answer¶
The answer: Printed draws the chosen pages, Canceled and Failed draw nothing.
sheet¶
The sheet, US Letter (8.5 x 11 inches) by default, with a quarter inch the printer can't reach.
unprintable¶
chosen¶
The pages the user picked in the print dialog (0-based); unset prints them all.
titles¶
Each job's title and owner, in order.
owners¶
pages¶
The drawing of each printed page, in order, and its index in the document.
indices¶
TestPrintHost¶
~TestPrintHost¶
TestPrintHost¶
operator=¶
print¶
Runs job over owner (nullptr: none) and says how it ended.