summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2013-09-13 23:20:38 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-14 21:15:35 +0100
commit3396ba5612c1047d1b21a90c4996dff848c00114 (patch)
tree389849c5108de7ff946ba14ff28f0757a95af41f /tests/auto
parent127c18ff1100a9fb8559ca651dbc03ff1f8eabbd (diff)
Match up the specified paper size to an existing one if possible
When EnumForms was used then the dmPaperSize was not always correct for the custom paper sizes available on some printers. By using DeviceCapabilities we can be sure that the information is correct in this respect. This also fixes respecting of the custom paper size if one is given and there is no corresponding existing paper size for it. Task-number: QTBUG-34276 Change-Id: I9924d5be8527027fc434261e37f6c7aae66210c3 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp79
1 files changed, 77 insertions, 2 deletions
diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
index 7251cca528..644cd33e5c 100644
--- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
+++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
@@ -113,6 +113,8 @@ private slots:
void testCustomPageSizes();
void customPaperSizeAndMargins_data();
void customPaperSizeAndMargins();
+ void customPaperNameSettingBySize();
+ void customPaperNameSettingByName();
#if !defined(QT_NO_COMPLETER) && !defined(QT_NO_FILEDIALOG)
void printDialogCompleter();
#endif
@@ -967,6 +969,13 @@ void tst_QPrinter::errorReporting()
painter.end();
}
+static QByteArray msgSizeMismatch(const QSizeF &actual, const QSizeF &expected)
+{
+ QString result;
+ QDebug(&result) << "Paper size mismatch" << actual << "!=" << expected;
+ return result.toLocal8Bit();
+}
+
void tst_QPrinter::testCustomPageSizes()
{
QPrinter p;
@@ -975,12 +984,16 @@ void tst_QPrinter::testCustomPageSizes()
p.setPaperSize(customSize, QPrinter::Inch);
QSizeF paperSize = p.paperSize(QPrinter::Inch);
- QCOMPARE(paperSize, customSize);
+ // Due to the different calculations, the sizes may be off by a fraction so we have to check it manually
+ // instead of relying on QSizeF comparison
+ QVERIFY2(sqrt(pow(paperSize.width() - customSize.width(), 2.0) + pow(paperSize.height() - customSize.height(), 2.0)) < 0.01,
+ msgSizeMismatch(paperSize, customSize));
QPrinter p2(QPrinter::HighResolution);
p2.setPaperSize(customSize, QPrinter::Inch);
paperSize = p.paperSize(QPrinter::Inch);
- QCOMPARE(paperSize, customSize);
+ QVERIFY2(sqrt(pow(paperSize.width() - customSize.width(), 2.0) + pow(paperSize.height() - customSize.height(), 2.0)) < 0.01,
+ msgSizeMismatch(paperSize, customSize));
}
void tst_QPrinter::customPaperSizeAndMargins_data()
@@ -1193,6 +1206,68 @@ void tst_QPrinter::testPageMetrics()
QCOMPARE(printer.pageSizeMM(), QSizeF(widthMMf, heightMMf));
}
+void tst_QPrinter::customPaperNameSettingBySize()
+{
+#ifndef Q_OS_WIN
+ QSKIP("Currently this triggers a problem on non Windows platforms, this will be fixed separately - QTBUG-34521");
+#endif
+ QPrinter printer(QPrinter::HighResolution);
+ QPrinterInfo info(printer);
+ QList<QPair<QString, QSizeF> > sizes = info.supportedSizesWithNames();
+ if (sizes.size() == 0)
+ QSKIP("No printers installed on this machine");
+ for (int i=0; i<sizes.size(); i++) {
+ printer.setPaperSize(sizes.at(i).second, QPrinter::Millimeter);
+ QCOMPARE(sizes.at(i).second, printer.paperSize(QPrinter::Millimeter));
+ // Some printers have the same size under different names which can cause a problem for the test
+ // So we iterate up to the current position to check
+ QSizeF paperSize = sizes.at(i).second;
+ QString paperName = printer.paperName();
+ bool paperNameFound = (sizes.at(i).first == paperName);
+ if (!paperNameFound) {
+ for (int j=0; j<i; j++) {
+ if (sizes.at(j).second == paperSize && sizes.at(j).first == paperName) {
+ paperNameFound = true;
+ break;
+ }
+ }
+ }
+ // Fail with the original values
+ if (!paperNameFound)
+ QCOMPARE(sizes.at(i).first, printer.paperName());
+ }
+
+ // Check setting a custom size after setting a standard one works
+ QSizeF customSize(200, 200);
+ printer.setPaperSize(customSize, QPrinter::Millimeter);
+ QCOMPARE(printer.paperSize(QPrinter::Millimeter), customSize);
+ QCOMPARE(printer.paperSize(), QPrinter::Custom);
+
+ // Finally check setting a standard size after a custom one works
+ printer.setPaperSize(sizes.at(0).second, QPrinter::Millimeter);
+ QCOMPARE(printer.paperName(), sizes.at(0).first);
+ QCOMPARE(printer.paperSize(QPrinter::Millimeter), sizes.at(0).second);
+}
+
+void tst_QPrinter::customPaperNameSettingByName()
+{
+#ifndef Q_OS_WIN
+ QSKIP("Currently this triggers a problem on non Windows platforms, this will be fixed separately - QTBUG-34521");
+#endif
+ QPrinter printer(QPrinter::HighResolution);
+ QPrinterInfo info(printer);
+ QList<QPair<QString, QSizeF> > sizes = info.supportedSizesWithNames();
+ if (sizes.size() == 0)
+ QSKIP("No printers installed on this machine");
+ for (int i=0; i<sizes.size(); i++) {
+ printer.setPaperName(sizes.at(i).first);
+ QCOMPARE(sizes.at(i).first, printer.paperName());
+ QSizeF paperSize = printer.paperSize(QPrinter::Millimeter);
+ QVERIFY2(sqrt(pow(sizes.at(i).second.width() - paperSize.width(), 2.0) + pow(sizes.at(i).second.height() - paperSize.height(), 2.0)) < 0.01,
+ msgSizeMismatch(sizes.at(i).second, paperSize));
+ }
+}
+
#endif // QT_NO_PRINTER
QTEST_MAIN(tst_QPrinter)