diff options
author | Andreas Buhr <andreas.buhr@qt.io> | 2020-09-25 16:54:50 +0200 |
---|---|---|
committer | Andreas Buhr <andreas.buhr@qt.io> | 2020-09-29 09:59:02 +0200 |
commit | f8474306e5a42ac44eeccd7e01abe44ebeef79f6 (patch) | |
tree | 58e1860d70d5262b6c9a1e03ec96a81e5bf42d26 /tests/auto | |
parent | b05e444a923e8362b6912da6dcda8247f7233322 (diff) |
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 <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
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); |