0
|
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 |
|
|
46 |
#include <qstatusbar.h>
|
|
47 |
#include <QLabel>
|
|
48 |
#include <QMainWindow>
|
|
49 |
#include <QSizeGrip>
|
|
50 |
|
|
51 |
#include "../../shared/util.h"
|
|
52 |
|
|
53 |
//TESTED_CLASS=
|
|
54 |
//TESTED_FILES=
|
|
55 |
|
|
56 |
class tst_QStatusBar: public QObject
|
|
57 |
{
|
|
58 |
Q_OBJECT
|
|
59 |
|
|
60 |
public:
|
|
61 |
tst_QStatusBar();
|
|
62 |
virtual ~tst_QStatusBar();
|
|
63 |
|
|
64 |
|
|
65 |
protected slots:
|
|
66 |
void messageChanged(const QString&);
|
|
67 |
|
|
68 |
public slots:
|
|
69 |
void initTestCase();
|
|
70 |
void cleanupTestCase();
|
|
71 |
void init();
|
|
72 |
void cleanup();
|
|
73 |
|
|
74 |
private slots:
|
|
75 |
void tempMessage();
|
|
76 |
void insertWidget();
|
|
77 |
void insertPermanentWidget();
|
|
78 |
void setSizeGripEnabled();
|
|
79 |
void task194017_hiddenWidget();
|
|
80 |
|
|
81 |
private:
|
|
82 |
QStatusBar *testWidget;
|
|
83 |
QString currentMessage;
|
|
84 |
};
|
|
85 |
|
|
86 |
tst_QStatusBar::tst_QStatusBar()
|
|
87 |
{
|
|
88 |
}
|
|
89 |
|
|
90 |
tst_QStatusBar::~tst_QStatusBar()
|
|
91 |
{
|
|
92 |
}
|
|
93 |
|
|
94 |
void tst_QStatusBar::init()
|
|
95 |
{
|
|
96 |
testWidget = new QStatusBar;
|
|
97 |
connect(testWidget, SIGNAL(messageChanged(QString)), this, SLOT(messageChanged(QString)));
|
|
98 |
|
|
99 |
QWidget *item1 = new QWidget(testWidget);
|
|
100 |
testWidget->addWidget(item1);
|
|
101 |
}
|
|
102 |
|
|
103 |
void tst_QStatusBar::cleanup()
|
|
104 |
{
|
|
105 |
delete testWidget;
|
|
106 |
}
|
|
107 |
|
|
108 |
void tst_QStatusBar::initTestCase()
|
|
109 |
{
|
|
110 |
}
|
|
111 |
|
|
112 |
void tst_QStatusBar::cleanupTestCase()
|
|
113 |
{
|
|
114 |
}
|
|
115 |
|
|
116 |
void tst_QStatusBar::messageChanged(const QString &m)
|
|
117 |
{
|
|
118 |
currentMessage = m;
|
|
119 |
}
|
|
120 |
|
|
121 |
void tst_QStatusBar::tempMessage()
|
|
122 |
{
|
|
123 |
QVERIFY(testWidget->currentMessage().isNull());
|
|
124 |
QVERIFY(currentMessage.isNull());
|
|
125 |
|
|
126 |
testWidget->showMessage("Ready", 500);
|
|
127 |
QCOMPARE(testWidget->currentMessage(), QString("Ready"));
|
|
128 |
QCOMPARE(testWidget->currentMessage(), currentMessage);
|
|
129 |
|
|
130 |
QTest::qWait(1000);
|
|
131 |
|
|
132 |
QVERIFY(testWidget->currentMessage().isNull());
|
|
133 |
QVERIFY(currentMessage.isNull());
|
|
134 |
|
|
135 |
testWidget->showMessage("Ready again", 500);
|
|
136 |
QCOMPARE(testWidget->currentMessage(), QString("Ready again"));
|
|
137 |
QCOMPARE(testWidget->currentMessage(), currentMessage);
|
|
138 |
|
|
139 |
testWidget->clearMessage();
|
|
140 |
QVERIFY(testWidget->currentMessage().isNull());
|
|
141 |
QVERIFY(currentMessage.isNull());
|
|
142 |
}
|
|
143 |
|
|
144 |
void tst_QStatusBar::insertWidget()
|
|
145 |
{
|
|
146 |
QStatusBar sb;
|
|
147 |
sb.addPermanentWidget(new QLabel("foo"));
|
|
148 |
QTest::ignoreMessage(QtWarningMsg, "QStatusBar::insertWidget: Index out of range (-1), appending widget");
|
|
149 |
QCOMPARE(sb.insertWidget(-1, new QLabel("foo")), 0);
|
|
150 |
QTest::ignoreMessage(QtWarningMsg, "QStatusBar::insertWidget: Index out of range (2), appending widget");
|
|
151 |
QCOMPARE(sb.insertWidget(2, new QLabel("foo")), 1);
|
|
152 |
QCOMPARE(sb.insertWidget(0, new QLabel("foo")), 0);
|
|
153 |
QCOMPARE(sb.insertWidget(3, new QLabel("foo")), 3);
|
|
154 |
}
|
|
155 |
|
|
156 |
void tst_QStatusBar::insertPermanentWidget()
|
|
157 |
{
|
|
158 |
QStatusBar sb;
|
|
159 |
sb.addWidget(new QLabel("foo"));
|
|
160 |
QTest::ignoreMessage(QtWarningMsg, "QStatusBar::insertPermanentWidget: Index out of range (-1), appending widget");
|
|
161 |
QCOMPARE(sb.insertPermanentWidget(-1, new QLabel("foo")), 1);
|
|
162 |
QTest::ignoreMessage(QtWarningMsg, "QStatusBar::insertPermanentWidget: Index out of range (0), appending widget");
|
|
163 |
QCOMPARE(sb.insertPermanentWidget(0, new QLabel("foo")), 2);
|
|
164 |
QCOMPARE(sb.insertPermanentWidget(2, new QLabel("foo")), 2);
|
|
165 |
QTest::ignoreMessage(QtWarningMsg, "QStatusBar::insertPermanentWidget: Index out of range (5), appending widget");
|
|
166 |
QCOMPARE(sb.insertPermanentWidget(5, new QLabel("foo")), 4);
|
|
167 |
QCOMPARE(sb.insertWidget(1, new QLabel("foo")), 1);
|
|
168 |
QTest::ignoreMessage(QtWarningMsg, "QStatusBar::insertPermanentWidget: Index out of range (1), appending widget");
|
|
169 |
QCOMPARE(sb.insertPermanentWidget(1, new QLabel("foo")), 6);
|
|
170 |
}
|
|
171 |
|
|
172 |
void tst_QStatusBar::setSizeGripEnabled()
|
|
173 |
{
|
|
174 |
QMainWindow mainWindow;
|
|
175 |
QPointer<QStatusBar> statusBar = mainWindow.statusBar();
|
|
176 |
QVERIFY(statusBar);
|
|
177 |
mainWindow.show();
|
|
178 |
#ifdef Q_WS_X11
|
|
179 |
qt_x11_wait_for_window_manager(&mainWindow);
|
|
180 |
#endif
|
|
181 |
|
|
182 |
QTRY_VERIFY(statusBar->isVisible());
|
|
183 |
QPointer<QSizeGrip> sizeGrip = qFindChild<QSizeGrip *>(statusBar);
|
|
184 |
QVERIFY(sizeGrip);
|
|
185 |
QVERIFY(sizeGrip->isVisible());
|
|
186 |
|
|
187 |
statusBar->setSizeGripEnabled(true);
|
|
188 |
QVERIFY(sizeGrip);
|
|
189 |
QVERIFY(sizeGrip->isVisible());
|
|
190 |
|
|
191 |
statusBar->hide();
|
|
192 |
QVERIFY(!sizeGrip->isVisible());
|
|
193 |
statusBar->show();
|
|
194 |
QVERIFY(sizeGrip->isVisible());
|
|
195 |
|
|
196 |
sizeGrip->setVisible(false);
|
|
197 |
QVERIFY(!sizeGrip->isVisible());
|
|
198 |
statusBar->hide();
|
|
199 |
statusBar->show();
|
|
200 |
QVERIFY(!sizeGrip->isVisible());
|
|
201 |
|
|
202 |
statusBar->setSizeGripEnabled(false);
|
|
203 |
QVERIFY(!sizeGrip);
|
|
204 |
|
|
205 |
qApp->processEvents();
|
|
206 |
mainWindow.showFullScreen();
|
|
207 |
#ifdef Q_WS_X11
|
|
208 |
qt_x11_wait_for_window_manager(&mainWindow);
|
|
209 |
#endif
|
|
210 |
qApp->processEvents();
|
|
211 |
|
|
212 |
mainWindow.setStatusBar(new QStatusBar(&mainWindow));
|
|
213 |
//we now call deleteLater on the previous statusbar
|
|
214 |
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
|
|
215 |
QVERIFY(!statusBar);
|
|
216 |
statusBar = mainWindow.statusBar();
|
|
217 |
QVERIFY(statusBar);
|
|
218 |
|
|
219 |
sizeGrip = qFindChild<QSizeGrip *>(statusBar);
|
|
220 |
QVERIFY(sizeGrip);
|
|
221 |
QVERIFY(!sizeGrip->isVisible());
|
|
222 |
|
|
223 |
statusBar->setSizeGripEnabled(true);
|
|
224 |
QVERIFY(!sizeGrip->isVisible());
|
|
225 |
|
|
226 |
qApp->processEvents();
|
|
227 |
mainWindow.showNormal();
|
|
228 |
qApp->processEvents();
|
|
229 |
QTRY_VERIFY(sizeGrip->isVisible());
|
|
230 |
}
|
|
231 |
|
|
232 |
void tst_QStatusBar::task194017_hiddenWidget()
|
|
233 |
{
|
|
234 |
QStatusBar sb;
|
|
235 |
|
|
236 |
QWidget *label= new QLabel("bar",&sb);
|
|
237 |
sb.addWidget(label);
|
|
238 |
sb.show();
|
|
239 |
QVERIFY(label->isVisible());
|
|
240 |
sb.showMessage("messssage");
|
|
241 |
QVERIFY(!label->isVisible());
|
|
242 |
sb.hide();
|
|
243 |
QVERIFY(!label->isVisible());
|
|
244 |
sb.show();
|
|
245 |
QVERIFY(!label->isVisible());
|
|
246 |
sb.clearMessage();
|
|
247 |
QVERIFY(label->isVisible());
|
|
248 |
label->hide();
|
|
249 |
QVERIFY(!label->isVisible());
|
|
250 |
sb.showMessage("messssage");
|
|
251 |
QVERIFY(!label->isVisible());
|
|
252 |
sb.clearMessage();
|
|
253 |
QVERIFY(!label->isVisible());
|
|
254 |
sb.hide();
|
|
255 |
QVERIFY(!label->isVisible());
|
|
256 |
sb.show();
|
|
257 |
QVERIFY(!label->isVisible());
|
|
258 |
}
|
|
259 |
|
|
260 |
|
|
261 |
QTEST_MAIN(tst_QStatusBar)
|
|
262 |
#include "tst_qstatusbar.moc"
|