tests/auto/qabstractprintdialog/tst_qabstractprintdialog.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 
       
    43 #include <QtTest/QtTest>
       
    44 
       
    45 #include <qcoreapplication.h>
       
    46 #include <qdebug.h>
       
    47 #include <qabstractprintdialog.h>
       
    48 #include <qprinter.h>
       
    49 
       
    50 //TESTED_CLASS=
       
    51 //TESTED_FILES=
       
    52 
       
    53 class tst_QAbstractPrintDialog : public QObject
       
    54 {
       
    55 Q_OBJECT
       
    56 
       
    57 public:
       
    58     tst_QAbstractPrintDialog();
       
    59     virtual ~tst_QAbstractPrintDialog();
       
    60 
       
    61 private slots:
       
    62     void getSetCheck();
       
    63     void setMinMax();
       
    64     void setFromTo();
       
    65 };
       
    66 
       
    67 class MyAbstractPrintDialog : public QAbstractPrintDialog
       
    68 {
       
    69 public:
       
    70     MyAbstractPrintDialog(QPrinter *p) : QAbstractPrintDialog(p) {}
       
    71     int exec() { return 0; }
       
    72 };
       
    73 
       
    74 tst_QAbstractPrintDialog::tst_QAbstractPrintDialog()
       
    75 {
       
    76 }
       
    77 
       
    78 tst_QAbstractPrintDialog::~tst_QAbstractPrintDialog()
       
    79 {
       
    80 }
       
    81 
       
    82 // Testing get/set functions
       
    83 void tst_QAbstractPrintDialog::getSetCheck()
       
    84 {
       
    85     QPrinter printer;
       
    86     MyAbstractPrintDialog obj1(&printer);
       
    87     QCOMPARE(obj1.printer(), &printer);
       
    88     // PrintDialogOptions QAbstractPrintDialog::enabledOptions()
       
    89     // void QAbstractPrintDialog::setEnabledOptions(PrintDialogOptions)
       
    90     obj1.setEnabledOptions(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::None));
       
    91     QCOMPARE(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::None), obj1.enabledOptions());
       
    92     obj1.setEnabledOptions(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintToFile));
       
    93     QCOMPARE(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintToFile), obj1.enabledOptions());
       
    94     obj1.setEnabledOptions(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintSelection));
       
    95     QCOMPARE(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintSelection), obj1.enabledOptions());
       
    96     obj1.setEnabledOptions(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintPageRange));
       
    97     QCOMPARE(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintPageRange), obj1.enabledOptions());
       
    98     obj1.setEnabledOptions(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintCollateCopies));
       
    99     QCOMPARE(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintCollateCopies), obj1.enabledOptions());
       
   100 
       
   101     // PrintRange QAbstractPrintDialog::printRange()
       
   102     // void QAbstractPrintDialog::setPrintRange(PrintRange)
       
   103     obj1.setPrintRange(QAbstractPrintDialog::PrintRange(QAbstractPrintDialog::AllPages));
       
   104     QCOMPARE(QAbstractPrintDialog::PrintRange(QAbstractPrintDialog::AllPages), obj1.printRange());
       
   105     obj1.setPrintRange(QAbstractPrintDialog::PrintRange(QAbstractPrintDialog::Selection));
       
   106     QCOMPARE(QAbstractPrintDialog::PrintRange(QAbstractPrintDialog::Selection), obj1.printRange());
       
   107     obj1.setPrintRange(QAbstractPrintDialog::PrintRange(QAbstractPrintDialog::PageRange));
       
   108     QCOMPARE(QAbstractPrintDialog::PrintRange(QAbstractPrintDialog::PageRange), obj1.printRange());
       
   109 }
       
   110 
       
   111 void tst_QAbstractPrintDialog::setMinMax()
       
   112 {
       
   113     QPrinter printer;
       
   114     MyAbstractPrintDialog obj1(&printer);
       
   115     obj1.setEnabledOptions(QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::None));
       
   116     QCOMPARE(obj1.minPage(), 1);
       
   117     QCOMPARE(obj1.maxPage(), INT_MAX);
       
   118     QVERIFY(!obj1.isOptionEnabled(QAbstractPrintDialog::PrintPageRange));
       
   119     obj1.setMinMax(2,5);
       
   120     QCOMPARE(obj1.minPage(), 2);
       
   121     QCOMPARE(obj1.maxPage(), 5);
       
   122     QVERIFY(obj1.enabledOptions() & QAbstractPrintDialog::PrintPageRange);
       
   123     QVERIFY(obj1.isOptionEnabled(QAbstractPrintDialog::PrintPageRange));
       
   124 }
       
   125 
       
   126 void tst_QAbstractPrintDialog::setFromTo()
       
   127 {
       
   128     QPrinter printer;
       
   129     MyAbstractPrintDialog obj1(&printer);
       
   130     QCOMPARE(obj1.fromPage(), 0);
       
   131     QCOMPARE(obj1.toPage(), 0);
       
   132     obj1.setMinMax(0,0);
       
   133     QCOMPARE(obj1.minPage(), 0);
       
   134     QCOMPARE(obj1.maxPage(), 0);
       
   135     obj1.setFromTo(20,50);
       
   136     QCOMPARE(obj1.fromPage(), 20);
       
   137     QCOMPARE(obj1.toPage(), 50);
       
   138     QCOMPARE(obj1.minPage(), 1);
       
   139     QCOMPARE(obj1.maxPage(), 50);
       
   140 }
       
   141 
       
   142 QTEST_MAIN(tst_QAbstractPrintDialog)
       
   143 #include "tst_qabstractprintdialog.moc"