| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | |
| 30 | #include <QtTest/QtTest> |
| 31 | |
| 32 | #include <qcoreapplication.h> |
| 33 | #include <qdebug.h> |
| 34 | #include <QtPrintSupport/qtprintsupportglobal.h> |
| 35 | #if QT_CONFIG(printdialog) |
| 36 | #include <qabstractprintdialog.h> |
| 37 | #include <qprinter.h> |
| 38 | #endif |
| 39 | |
| 40 | class tst_QAbstractPrintDialog : public QObject |
| 41 | { |
| 42 | Q_OBJECT |
| 43 | |
| 44 | #if !QT_CONFIG(printdialog) |
| 45 | public slots: |
| 46 | void initTestCase(); |
| 47 | #else |
| 48 | private slots: |
| 49 | void getSetCheck(); |
| 50 | void setMinMax(); |
| 51 | void setFromTo(); |
| 52 | #endif |
| 53 | }; |
| 54 | |
| 55 | #if !QT_CONFIG(printdialog) |
| 56 | void tst_QAbstractPrintDialog::initTestCase() |
| 57 | { |
| 58 | QSKIP("This test requires printing and print dialog support" ); |
| 59 | } |
| 60 | |
| 61 | #else |
| 62 | |
| 63 | class MyAbstractPrintDialog : public QAbstractPrintDialog |
| 64 | { |
| 65 | public: |
| 66 | MyAbstractPrintDialog(QPrinter *p) : QAbstractPrintDialog(p) {} |
| 67 | int exec() { return 0; } |
| 68 | }; |
| 69 | |
| 70 | // Testing get/set functions |
| 71 | void tst_QAbstractPrintDialog::getSetCheck() |
| 72 | { |
| 73 | QPrinter printer; |
| 74 | MyAbstractPrintDialog obj1(&printer); |
| 75 | QCOMPARE(obj1.printer(), &printer); |
| 76 | // PrintDialogOptions QAbstractPrintDialog::enabledOptions() |
| 77 | // void QAbstractPrintDialog::setEnabledOptions(PrintDialogOptions) |
| 78 | obj1.setEnabledOptions(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::None)); |
| 79 | QCOMPARE(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::None), obj1.enabledOptions()); |
| 80 | obj1.setEnabledOptions(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintToFile)); |
| 81 | QCOMPARE(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintToFile), obj1.enabledOptions()); |
| 82 | obj1.setEnabledOptions(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintSelection)); |
| 83 | QCOMPARE(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintSelection), obj1.enabledOptions()); |
| 84 | obj1.setEnabledOptions(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintPageRange)); |
| 85 | QCOMPARE(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintPageRange), obj1.enabledOptions()); |
| 86 | obj1.setEnabledOptions(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintCollateCopies)); |
| 87 | QCOMPARE(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintCollateCopies), obj1.enabledOptions()); |
| 88 | |
| 89 | // PrintRange QAbstractPrintDialog::printRange() |
| 90 | // void QAbstractPrintDialog::setPrintRange(PrintRange) |
| 91 | obj1.setPrintRange(QAbstractPrintDialog::PrintRange(QAbstractPrintDialog::AllPages)); |
| 92 | QCOMPARE(QAbstractPrintDialog::PrintRange(QAbstractPrintDialog::AllPages), obj1.printRange()); |
| 93 | obj1.setPrintRange(QAbstractPrintDialog::PrintRange(QAbstractPrintDialog::Selection)); |
| 94 | QCOMPARE(QAbstractPrintDialog::PrintRange(QAbstractPrintDialog::Selection), obj1.printRange()); |
| 95 | obj1.setPrintRange(QAbstractPrintDialog::PrintRange(QAbstractPrintDialog::PageRange)); |
| 96 | QCOMPARE(QAbstractPrintDialog::PrintRange(QAbstractPrintDialog::PageRange), obj1.printRange()); |
| 97 | } |
| 98 | |
| 99 | void tst_QAbstractPrintDialog::setMinMax() |
| 100 | { |
| 101 | QPrinter printer; |
| 102 | MyAbstractPrintDialog obj1(&printer); |
| 103 | obj1.setEnabledOptions(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::None)); |
| 104 | QCOMPARE(obj1.minPage(), 0); |
| 105 | QCOMPARE(obj1.maxPage(), INT_MAX); |
| 106 | QVERIFY(!obj1.isOptionEnabled(QAbstractPrintDialog::PrintPageRange)); |
| 107 | obj1.setMinMax(min: 2,max: 5); |
| 108 | QCOMPARE(obj1.minPage(), 2); |
| 109 | QCOMPARE(obj1.maxPage(), 5); |
| 110 | QVERIFY(obj1.enabledOptions() & QAbstractPrintDialog::PrintPageRange); |
| 111 | QVERIFY(obj1.isOptionEnabled(QAbstractPrintDialog::PrintPageRange)); |
| 112 | } |
| 113 | |
| 114 | void tst_QAbstractPrintDialog::setFromTo() |
| 115 | { |
| 116 | QPrinter printer; |
| 117 | MyAbstractPrintDialog obj1(&printer); |
| 118 | QCOMPARE(obj1.fromPage(), 0); |
| 119 | QCOMPARE(obj1.toPage(), 0); |
| 120 | obj1.setMinMax(min: 0,max: 0); |
| 121 | QCOMPARE(obj1.minPage(), 0); |
| 122 | QCOMPARE(obj1.maxPage(), 0); |
| 123 | obj1.setFromTo(fromPage: 20,toPage: 50); |
| 124 | QCOMPARE(obj1.fromPage(), 20); |
| 125 | QCOMPARE(obj1.toPage(), 50); |
| 126 | QCOMPARE(obj1.minPage(), 1); |
| 127 | QCOMPARE(obj1.maxPage(), 50); |
| 128 | } |
| 129 | |
| 130 | #endif |
| 131 | |
| 132 | QTEST_MAIN(tst_QAbstractPrintDialog) |
| 133 | #include "tst_qabstractprintdialog.moc" |
| 134 | |