author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
void QTBUG4334_hiddenOnMaximizedWindow(); |
0 | 81 |
|
82 |
private: |
|
83 |
QStatusBar *testWidget; |
|
84 |
QString currentMessage; |
|
85 |
}; |
|
86 |
||
87 |
tst_QStatusBar::tst_QStatusBar() |
|
88 |
{ |
|
89 |
} |
|
90 |
||
91 |
tst_QStatusBar::~tst_QStatusBar() |
|
92 |
{ |
|
93 |
} |
|
94 |
||
95 |
void tst_QStatusBar::init() |
|
96 |
{ |
|
97 |
testWidget = new QStatusBar; |
|
98 |
connect(testWidget, SIGNAL(messageChanged(QString)), this, SLOT(messageChanged(QString))); |
|
99 |
||
100 |
QWidget *item1 = new QWidget(testWidget); |
|
101 |
testWidget->addWidget(item1); |
|
102 |
} |
|
103 |
||
104 |
void tst_QStatusBar::cleanup() |
|
105 |
{ |
|
106 |
delete testWidget; |
|
107 |
} |
|
108 |
||
109 |
void tst_QStatusBar::initTestCase() |
|
110 |
{ |
|
111 |
} |
|
112 |
||
113 |
void tst_QStatusBar::cleanupTestCase() |
|
114 |
{ |
|
115 |
} |
|
116 |
||
117 |
void tst_QStatusBar::messageChanged(const QString &m) |
|
118 |
{ |
|
119 |
currentMessage = m; |
|
120 |
} |
|
121 |
||
122 |
void tst_QStatusBar::tempMessage() |
|
123 |
{ |
|
124 |
QVERIFY(testWidget->currentMessage().isNull()); |
|
125 |
QVERIFY(currentMessage.isNull()); |
|
126 |
||
127 |
testWidget->showMessage("Ready", 500); |
|
128 |
QCOMPARE(testWidget->currentMessage(), QString("Ready")); |
|
129 |
QCOMPARE(testWidget->currentMessage(), currentMessage); |
|
130 |
||
131 |
QTest::qWait(1000); |
|
132 |
||
133 |
QVERIFY(testWidget->currentMessage().isNull()); |
|
134 |
QVERIFY(currentMessage.isNull()); |
|
135 |
||
136 |
testWidget->showMessage("Ready again", 500); |
|
137 |
QCOMPARE(testWidget->currentMessage(), QString("Ready again")); |
|
138 |
QCOMPARE(testWidget->currentMessage(), currentMessage); |
|
139 |
||
140 |
testWidget->clearMessage(); |
|
141 |
QVERIFY(testWidget->currentMessage().isNull()); |
|
142 |
QVERIFY(currentMessage.isNull()); |
|
143 |
} |
|
144 |
||
145 |
void tst_QStatusBar::insertWidget() |
|
146 |
{ |
|
147 |
QStatusBar sb; |
|
148 |
sb.addPermanentWidget(new QLabel("foo")); |
|
149 |
QTest::ignoreMessage(QtWarningMsg, "QStatusBar::insertWidget: Index out of range (-1), appending widget"); |
|
150 |
QCOMPARE(sb.insertWidget(-1, new QLabel("foo")), 0); |
|
151 |
QTest::ignoreMessage(QtWarningMsg, "QStatusBar::insertWidget: Index out of range (2), appending widget"); |
|
152 |
QCOMPARE(sb.insertWidget(2, new QLabel("foo")), 1); |
|
153 |
QCOMPARE(sb.insertWidget(0, new QLabel("foo")), 0); |
|
154 |
QCOMPARE(sb.insertWidget(3, new QLabel("foo")), 3); |
|
155 |
} |
|
156 |
||
157 |
void tst_QStatusBar::insertPermanentWidget() |
|
158 |
{ |
|
159 |
QStatusBar sb; |
|
160 |
sb.addWidget(new QLabel("foo")); |
|
161 |
QTest::ignoreMessage(QtWarningMsg, "QStatusBar::insertPermanentWidget: Index out of range (-1), appending widget"); |
|
162 |
QCOMPARE(sb.insertPermanentWidget(-1, new QLabel("foo")), 1); |
|
163 |
QTest::ignoreMessage(QtWarningMsg, "QStatusBar::insertPermanentWidget: Index out of range (0), appending widget"); |
|
164 |
QCOMPARE(sb.insertPermanentWidget(0, new QLabel("foo")), 2); |
|
165 |
QCOMPARE(sb.insertPermanentWidget(2, new QLabel("foo")), 2); |
|
166 |
QTest::ignoreMessage(QtWarningMsg, "QStatusBar::insertPermanentWidget: Index out of range (5), appending widget"); |
|
167 |
QCOMPARE(sb.insertPermanentWidget(5, new QLabel("foo")), 4); |
|
168 |
QCOMPARE(sb.insertWidget(1, new QLabel("foo")), 1); |
|
169 |
QTest::ignoreMessage(QtWarningMsg, "QStatusBar::insertPermanentWidget: Index out of range (1), appending widget"); |
|
170 |
QCOMPARE(sb.insertPermanentWidget(1, new QLabel("foo")), 6); |
|
171 |
} |
|
172 |
||
173 |
void tst_QStatusBar::setSizeGripEnabled() |
|
174 |
{ |
|
175 |
QMainWindow mainWindow; |
|
176 |
QPointer<QStatusBar> statusBar = mainWindow.statusBar(); |
|
177 |
QVERIFY(statusBar); |
|
178 |
mainWindow.show(); |
|
179 |
#ifdef Q_WS_X11 |
|
180 |
qt_x11_wait_for_window_manager(&mainWindow); |
|
181 |
#endif |
|
182 |
||
183 |
QTRY_VERIFY(statusBar->isVisible()); |
|
184 |
QPointer<QSizeGrip> sizeGrip = qFindChild<QSizeGrip *>(statusBar); |
|
185 |
QVERIFY(sizeGrip); |
|
186 |
QVERIFY(sizeGrip->isVisible()); |
|
187 |
||
188 |
statusBar->setSizeGripEnabled(true); |
|
189 |
QVERIFY(sizeGrip); |
|
190 |
QVERIFY(sizeGrip->isVisible()); |
|
191 |
||
192 |
statusBar->hide(); |
|
193 |
QVERIFY(!sizeGrip->isVisible()); |
|
194 |
statusBar->show(); |
|
195 |
QVERIFY(sizeGrip->isVisible()); |
|
196 |
||
197 |
sizeGrip->setVisible(false); |
|
198 |
QVERIFY(!sizeGrip->isVisible()); |
|
199 |
statusBar->hide(); |
|
200 |
statusBar->show(); |
|
201 |
QVERIFY(!sizeGrip->isVisible()); |
|
202 |
||
203 |
statusBar->setSizeGripEnabled(false); |
|
204 |
QVERIFY(!sizeGrip); |
|
205 |
||
206 |
qApp->processEvents(); |
|
207 |
mainWindow.showFullScreen(); |
|
208 |
#ifdef Q_WS_X11 |
|
209 |
qt_x11_wait_for_window_manager(&mainWindow); |
|
210 |
#endif |
|
211 |
qApp->processEvents(); |
|
212 |
||
213 |
mainWindow.setStatusBar(new QStatusBar(&mainWindow)); |
|
214 |
//we now call deleteLater on the previous statusbar |
|
215 |
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); |
|
216 |
QVERIFY(!statusBar); |
|
217 |
statusBar = mainWindow.statusBar(); |
|
218 |
QVERIFY(statusBar); |
|
219 |
||
220 |
sizeGrip = qFindChild<QSizeGrip *>(statusBar); |
|
221 |
QVERIFY(sizeGrip); |
|
222 |
QVERIFY(!sizeGrip->isVisible()); |
|
223 |
||
224 |
statusBar->setSizeGripEnabled(true); |
|
225 |
QVERIFY(!sizeGrip->isVisible()); |
|
226 |
||
227 |
qApp->processEvents(); |
|
228 |
mainWindow.showNormal(); |
|
229 |
qApp->processEvents(); |
|
230 |
QTRY_VERIFY(sizeGrip->isVisible()); |
|
231 |
} |
|
232 |
||
233 |
void tst_QStatusBar::task194017_hiddenWidget() |
|
234 |
{ |
|
235 |
QStatusBar sb; |
|
236 |
||
237 |
QWidget *label= new QLabel("bar",&sb); |
|
238 |
sb.addWidget(label); |
|
239 |
sb.show(); |
|
240 |
QVERIFY(label->isVisible()); |
|
241 |
sb.showMessage("messssage"); |
|
242 |
QVERIFY(!label->isVisible()); |
|
243 |
sb.hide(); |
|
244 |
QVERIFY(!label->isVisible()); |
|
245 |
sb.show(); |
|
246 |
QVERIFY(!label->isVisible()); |
|
247 |
sb.clearMessage(); |
|
248 |
QVERIFY(label->isVisible()); |
|
249 |
label->hide(); |
|
250 |
QVERIFY(!label->isVisible()); |
|
251 |
sb.showMessage("messssage"); |
|
252 |
QVERIFY(!label->isVisible()); |
|
253 |
sb.clearMessage(); |
|
254 |
QVERIFY(!label->isVisible()); |
|
255 |
sb.hide(); |
|
256 |
QVERIFY(!label->isVisible()); |
|
257 |
sb.show(); |
|
258 |
QVERIFY(!label->isVisible()); |
|
259 |
} |
|
260 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
void tst_QStatusBar::QTBUG4334_hiddenOnMaximizedWindow() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
QMainWindow main; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
QStatusBar statusbar; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
statusbar.setSizeGripEnabled(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
main.setStatusBar(&statusbar); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
267 |
main.showMaximized(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
QTest::qWaitForWindowShown(&main); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
#ifndef Q_WS_MAC |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
QVERIFY(!statusbar.findChild<QSizeGrip*>()->isVisible()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
main.showNormal(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
QTest::qWaitForWindowShown(&main); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
QVERIFY(statusbar.findChild<QSizeGrip*>()->isVisible()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
main.showFullScreen(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
276 |
QTest::qWaitForWindowShown(&main); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
QVERIFY(!statusbar.findChild<QSizeGrip*>()->isVisible()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
} |
0 | 279 |
|
280 |
QTEST_MAIN(tst_QStatusBar) |
|
281 |
#include "tst_qstatusbar.moc" |