tests/auto/qabstractspinbox/tst_qabstractspinbox.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 <qabstractspinbox.h>
       
    48 #include <qlineedit.h>
       
    49 #include <qspinbox.h>
       
    50 
       
    51 
       
    52 //TESTED_CLASS=
       
    53 //TESTED_FILES=
       
    54 
       
    55 class tst_QAbstractSpinBox : public QObject
       
    56 {
       
    57 Q_OBJECT
       
    58 
       
    59 public:
       
    60     tst_QAbstractSpinBox();
       
    61     virtual ~tst_QAbstractSpinBox();
       
    62 
       
    63 private slots:
       
    64     void getSetCheck();
       
    65 
       
    66     // task-specific tests below me:
       
    67     void task183108_clear();
       
    68     void task228728_cssselector();
       
    69 };
       
    70 
       
    71 tst_QAbstractSpinBox::tst_QAbstractSpinBox()
       
    72 {
       
    73 }
       
    74 
       
    75 tst_QAbstractSpinBox::~tst_QAbstractSpinBox()
       
    76 {
       
    77 }
       
    78 
       
    79 class MyAbstractSpinBox : public QAbstractSpinBox
       
    80 {
       
    81 public:
       
    82     MyAbstractSpinBox() : QAbstractSpinBox() {}
       
    83     QLineEdit *lineEdit() { return QAbstractSpinBox::lineEdit(); }
       
    84     void setLineEdit(QLineEdit *le) { QAbstractSpinBox::setLineEdit(le); }
       
    85 };
       
    86 
       
    87 // Testing get/set functions
       
    88 void tst_QAbstractSpinBox::getSetCheck()
       
    89 {
       
    90     MyAbstractSpinBox obj1;
       
    91     // ButtonSymbols QAbstractSpinBox::buttonSymbols()
       
    92     // void QAbstractSpinBox::setButtonSymbols(ButtonSymbols)
       
    93     obj1.setButtonSymbols(QAbstractSpinBox::ButtonSymbols(QAbstractSpinBox::UpDownArrows));
       
    94     QCOMPARE(QAbstractSpinBox::ButtonSymbols(QAbstractSpinBox::UpDownArrows), obj1.buttonSymbols());
       
    95     obj1.setButtonSymbols(QAbstractSpinBox::ButtonSymbols(QAbstractSpinBox::PlusMinus));
       
    96     QCOMPARE(QAbstractSpinBox::ButtonSymbols(QAbstractSpinBox::PlusMinus), obj1.buttonSymbols());
       
    97 
       
    98     // bool QAbstractSpinBox::wrapping()
       
    99     // void QAbstractSpinBox::setWrapping(bool)
       
   100     obj1.setWrapping(false);
       
   101     QCOMPARE(false, obj1.wrapping());
       
   102     obj1.setWrapping(true);
       
   103     QCOMPARE(true, obj1.wrapping());
       
   104 
       
   105     // QLineEdit * QAbstractSpinBox::lineEdit()
       
   106     // void QAbstractSpinBox::setLineEdit(QLineEdit *)
       
   107     QLineEdit *var3 = new QLineEdit(0);
       
   108     obj1.setLineEdit(var3);
       
   109     QCOMPARE(var3, obj1.lineEdit());
       
   110 #ifndef QT_DEBUG
       
   111     obj1.setLineEdit((QLineEdit *)0); // Will assert in debug, so only test in release
       
   112     QCOMPARE(var3, obj1.lineEdit()); // Setting 0 should keep the current editor
       
   113 #endif
       
   114     // delete var3; // No delete, since QAbstractSpinBox takes ownership
       
   115 }
       
   116 
       
   117 void tst_QAbstractSpinBox::task183108_clear()
       
   118 {
       
   119     QAbstractSpinBox *sbox;
       
   120 
       
   121     sbox = new QSpinBox;
       
   122     sbox->clear();
       
   123     sbox->show();
       
   124     qApp->processEvents();
       
   125     QVERIFY(sbox->text().isEmpty());
       
   126 
       
   127     delete sbox;
       
   128     sbox = new QSpinBox;
       
   129     sbox->clear();
       
   130     sbox->show();
       
   131     sbox->hide();
       
   132     qApp->processEvents();
       
   133     QCOMPARE(sbox->text(), QString());
       
   134 
       
   135     delete sbox;
       
   136     sbox = new QSpinBox;
       
   137     sbox->show();
       
   138     sbox->clear();
       
   139     qApp->processEvents();
       
   140     QCOMPARE(sbox->text(), QString());
       
   141 
       
   142     delete sbox;
       
   143     sbox = new QSpinBox;
       
   144     sbox->show();
       
   145     sbox->clear();
       
   146     sbox->hide();
       
   147     qApp->processEvents();
       
   148     QCOMPARE(sbox->text(), QString());
       
   149 
       
   150     delete sbox;
       
   151 }
       
   152 
       
   153 void tst_QAbstractSpinBox::task228728_cssselector()
       
   154 {
       
   155     //QAbstractSpinBox does some call to stylehint into his constructor.
       
   156     //so while the stylesheet want to access property, it should not crash
       
   157     qApp->setStyleSheet("[alignement=\"1\"], [text=\"foo\"] { color:black; }" );
       
   158     QSpinBox box;
       
   159 }
       
   160 
       
   161 
       
   162 QTEST_MAIN(tst_QAbstractSpinBox)
       
   163 #include "tst_qabstractspinbox.moc"