diff options
Diffstat (limited to 'tests/auto/printsupport')
-rw-r--r-- | tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp index a612f0749b..a65dd0bf8f 100644 --- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp +++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp @@ -122,6 +122,7 @@ private slots: void testPageMetrics_data(); void testPageMetrics(); + void reusePageMetrics(); #endif private: QString testFileName(const QString &prefix, const QString &suffix); @@ -1955,6 +1956,50 @@ QString tst_QPrinter::testFileName(const QString &prefix, const QString &suffix) return result; } +void tst_QPrinter::reusePageMetrics() +{ + QList<QPrinterInfo> availablePrinters = QPrinterInfo::availablePrinters(); + if (availablePrinters.size() < 2) + QSKIP("Not enough printers to do this test with, need at least 2 setup"); + QPrinter defaultP; + QPrinterInfo info(defaultP); + QString otherPrinterName; + for (QPrinterInfo i : qAsConst(availablePrinters)) { + if (i.printerName() != defaultP.printerName()) { + otherPrinterName = i.printerName(); + break; + } + } + QPrinter otherP(QPrinterInfo::printerInfo(otherPrinterName)); + QList<QPageSize> defaultPageSizes = info.supportedPageSizes(); + QList<QPageSize> otherPageSizes = QPrinterInfo(otherP).supportedPageSizes(); + QPageSize unavailableSizeToSet; + for (QPageSize s : qAsConst(defaultPageSizes)) { + bool found = false; + for (QPageSize os : qAsConst(otherPageSizes)) { + if (os.isEquivalentTo(s)) { + found = true; + break; + } + } + const QPageSize tmpSize(s.size(QPageSize::Point), QPageSize::Point); + if (!tmpSize.name().startsWith("Custom")) + found = true; + if (!found) { + unavailableSizeToSet = s; + break; + } + } + if (!unavailableSizeToSet.isValid()) + QSKIP("Could not find a size that was not available on the non default printer. The test " + "requires this"); + defaultP.setPageSize(unavailableSizeToSet); + defaultP.setPrinterName(otherP.printerName()); + QVERIFY(defaultP.pageLayout().pageSize().isEquivalentTo(unavailableSizeToSet)); + QVERIFY(defaultP.pageLayout().pageSize().name() != unavailableSizeToSet.name()); + QCOMPARE(defaultP.pageLayout().pageSize().sizePoints(), unavailableSizeToSet.sizePoints()); +} + #endif // QT_CONFIG(printer) QTEST_MAIN(tst_QPrinter) |