From f8474306e5a42ac44eeccd7e01abe44ebeef79f6 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Fri, 25 Sep 2020 16:54:50 +0200 Subject: QPrinter: fix unit tests for special case when no printer is default The unit tests of QPrinter assume that a printer which is default- initialized is the same printer as the default printer. However, when no printer is set to default, this is not the case. When no printer is the default printer, a default-initialized QPrinter will be the first printer found. This patch adapts the unit tests to work also when no printer is the default printer, even though printers are available. Change-Id: I4967e5b1c4fb8a7c33c911184289ec5cd283fc58 Reviewed-by: Volker Hilsheimer --- tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp index fef7c4905d..81a53bd6b6 100644 --- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp +++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp @@ -1516,7 +1516,13 @@ void tst_QPrinter::outputFormat() QCOMPARE(printer.printerName(), QString()); } else { QCOMPARE(printer.outputFormat(), QPrinter::NativeFormat); - QCOMPARE(printer.printerName(), QPrinterInfo::defaultPrinter().printerName()); + + // If no printer is default, the first available printer should be used. + // Otherwise, the default printer should be used. + if (QPrinterInfo::defaultPrinter().isNull()) + QCOMPARE(printer.printerName(), QPrinterInfo::availablePrinters().at(0).printerName()); + else + QCOMPARE(printer.printerName(), QPrinterInfo::defaultPrinter().printerName()); } printer.setOutputFormat(QPrinter::PdfFormat); -- cgit v1.2.3