1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
tst_QAbstractSpinBox()71 tst_QAbstractSpinBox::tst_QAbstractSpinBox()
72 {
73 }
74 
~tst_QAbstractSpinBox()75 tst_QAbstractSpinBox::~tst_QAbstractSpinBox()
76 {
77 }
78 
79 class MyAbstractSpinBox : public QAbstractSpinBox
80 {
81 public:
MyAbstractSpinBox()82     MyAbstractSpinBox() : QAbstractSpinBox() {}
lineEdit()83     QLineEdit *lineEdit() { return QAbstractSpinBox::lineEdit(); }
setLineEdit(QLineEdit * le)84     void setLineEdit(QLineEdit *le) { QAbstractSpinBox::setLineEdit(le); }
85 };
86 
87 // Testing get/set functions
getSetCheck()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 
task183108_clear()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 
task228728_cssselector()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("[alignment=\"1\"], [text=\"foo\"] { color:black; }" );
158     QSpinBox box;
159 }
160 
161 
162 QTEST_MAIN(tst_QAbstractSpinBox)
163 #include "tst_qabstractspinbox.moc"
164