author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
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 |
#include <QtGui/QtGui> |
|
45 |
#include <qeventloop.h> |
|
46 |
#include <qlist.h> |
|
47 |
||
48 |
#include <qlistwidget.h> |
|
49 |
||
50 |
#ifdef Q_WS_X11 |
|
51 |
#include <X11/Xlib.h> |
|
52 |
#include <QX11Info> |
|
53 |
#endif // Q_WS_X11 |
|
54 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
#include "../../shared/util.h" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
|
0 | 58 |
class tst_QWidget_window : public QWidget |
59 |
{ |
|
60 |
Q_OBJECT |
|
61 |
||
62 |
public: |
|
63 |
tst_QWidget_window(){}; |
|
64 |
||
65 |
public slots: |
|
66 |
void initTestCase(); |
|
67 |
void cleanupTestCase(); |
|
68 |
||
69 |
private slots: |
|
70 |
void tst_move_show(); |
|
71 |
void tst_show_move(); |
|
72 |
void tst_show_move_hide_show(); |
|
73 |
||
74 |
void tst_resize_show(); |
|
75 |
void tst_show_resize(); |
|
76 |
void tst_show_resize_hide_show(); |
|
77 |
||
78 |
void tst_windowFilePathAndwindowTitle_data(); |
|
79 |
void tst_windowFilePathAndwindowTitle(); |
|
80 |
void tst_windowFilePath_data(); |
|
81 |
void tst_windowFilePath(); |
|
82 |
||
83 |
void tst_showWithoutActivating(); |
|
84 |
void tst_paintEventOnSecondShow(); |
|
85 |
}; |
|
86 |
||
87 |
void tst_QWidget_window::initTestCase() |
|
88 |
{ |
|
89 |
} |
|
90 |
||
91 |
void tst_QWidget_window::cleanupTestCase() |
|
92 |
{ |
|
93 |
} |
|
94 |
||
95 |
void tst_QWidget_window::tst_move_show() |
|
96 |
{ |
|
97 |
QWidget w; |
|
98 |
w.move(100, 100); |
|
99 |
w.show(); |
|
100 |
QCOMPARE(w.pos(), QPoint(100, 100)); |
|
101 |
// QCoreApplication::processEvents(QEventLoop::AllEvents, 3000); |
|
102 |
} |
|
103 |
||
104 |
void tst_QWidget_window::tst_show_move() |
|
105 |
{ |
|
106 |
QWidget w; |
|
107 |
w.show(); |
|
108 |
w.move(100, 100); |
|
109 |
QCOMPARE(w.pos(), QPoint(100, 100)); |
|
110 |
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
111 |
} |
|
112 |
||
113 |
void tst_QWidget_window::tst_show_move_hide_show() |
|
114 |
{ |
|
115 |
QWidget w; |
|
116 |
w.show(); |
|
117 |
w.move(100, 100); |
|
118 |
w.hide(); |
|
119 |
w.show(); |
|
120 |
QCOMPARE(w.pos(), QPoint(100, 100)); |
|
121 |
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
122 |
} |
|
123 |
||
124 |
void tst_QWidget_window::tst_resize_show() |
|
125 |
{ |
|
126 |
QWidget w; |
|
127 |
w.resize(200, 200); |
|
128 |
w.show(); |
|
129 |
QCOMPARE(w.size(), QSize(200, 200)); |
|
130 |
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
131 |
} |
|
132 |
||
133 |
void tst_QWidget_window::tst_show_resize() |
|
134 |
{ |
|
135 |
QWidget w; |
|
136 |
w.show(); |
|
137 |
w.resize(200, 200); |
|
138 |
QCOMPARE(w.size(), QSize(200, 200)); |
|
139 |
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
140 |
} |
|
141 |
||
142 |
void tst_QWidget_window::tst_show_resize_hide_show() |
|
143 |
{ |
|
144 |
QWidget w; |
|
145 |
w.show(); |
|
146 |
w.resize(200, 200); |
|
147 |
w.hide(); |
|
148 |
w.show(); |
|
149 |
QCOMPARE(w.size(), QSize(200, 200)); |
|
150 |
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
151 |
} |
|
152 |
||
153 |
class TestWidget : public QWidget |
|
154 |
{ |
|
155 |
public: |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
int m_first, m_next; |
0 | 157 |
bool paintEventReceived; |
158 |
||
159 |
void reset(){ m_first = m_next = 0; paintEventReceived = false; } |
|
160 |
bool event(QEvent *event) |
|
161 |
{ |
|
162 |
switch (event->type()) { |
|
163 |
case QEvent::WindowActivate: |
|
164 |
case QEvent::WindowDeactivate: |
|
165 |
case QEvent::Hide: |
|
166 |
case QEvent::Show: |
|
167 |
if (m_first) |
|
168 |
m_next = event->type(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
else |
0 | 170 |
m_first = event->type(); |
171 |
break; |
|
172 |
case QEvent::Paint: |
|
173 |
paintEventReceived = true; |
|
174 |
break; |
|
175 |
default: |
|
176 |
break; |
|
177 |
} |
|
178 |
return QWidget::event(event); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
} |
0 | 180 |
}; |
181 |
||
182 |
void tst_QWidget_window::tst_windowFilePathAndwindowTitle_data() |
|
183 |
{ |
|
184 |
QTest::addColumn<bool>("setWindowTitleBefore"); |
|
185 |
QTest::addColumn<bool>("setWindowTitleAfter"); |
|
186 |
QTest::addColumn<QString>("filePath"); |
|
187 |
QTest::addColumn<QString>("applicationName"); |
|
188 |
QTest::addColumn<QString>("indyWindowTitle"); |
|
189 |
QTest::addColumn<QString>("finalTitleBefore"); |
|
190 |
QTest::addColumn<QString>("finalTitleAfter"); |
|
191 |
||
192 |
QString validPath = QApplication::applicationFilePath(); |
|
193 |
QString appName = QLatin1String("Killer App"); |
|
194 |
QString fileNameOnly = QFileInfo(validPath).fileName() + QLatin1String("[*]"); |
|
195 |
QString fileAndApp = fileNameOnly + QLatin1String(" ") + QChar(0x2014) + QLatin1String(" ") + appName; |
|
196 |
QString windowTitle = QLatin1String("Here is a Window Title"); |
|
197 |
||
198 |
QTest::newRow("never Set Title nor AppName") << false << false << validPath << QString() << windowTitle << fileNameOnly << fileNameOnly; |
|
199 |
QTest::newRow("set title after only, but no AppName") << false << true << validPath << QString() << windowTitle << fileNameOnly << windowTitle; |
|
200 |
QTest::newRow("set title before only, not AppName") << true << false << validPath << QString() << windowTitle << windowTitle << windowTitle; |
|
201 |
QTest::newRow("always set title, not appName") << true << true << validPath << QString() << windowTitle << windowTitle << windowTitle; |
|
202 |
||
203 |
QString platString = |
|
204 |
#ifdef Q_WS_MAC |
|
205 |
fileNameOnly; |
|
206 |
#else |
|
207 |
fileAndApp; |
|
208 |
#endif |
|
209 |
||
210 |
QTest::newRow("never Set Title, yes AppName") << false << false << validPath << appName << windowTitle << platString << platString; |
|
211 |
QTest::newRow("set title after only, yes AppName") << false << true << validPath << appName << windowTitle << platString << windowTitle; |
|
212 |
QTest::newRow("set title before only, yes AppName") << true << false << validPath << appName << windowTitle << windowTitle << windowTitle; |
|
213 |
QTest::newRow("always set title, yes appName") << true << true << validPath << appName << windowTitle << windowTitle << windowTitle; |
|
214 |
} |
|
215 |
||
216 |
void tst_QWidget_window::tst_windowFilePathAndwindowTitle() |
|
217 |
{ |
|
218 |
QFETCH(bool, setWindowTitleBefore); |
|
219 |
QFETCH(bool, setWindowTitleAfter); |
|
220 |
QFETCH(QString, filePath); |
|
221 |
QFETCH(QString, applicationName); |
|
222 |
QFETCH(QString, indyWindowTitle); |
|
223 |
QFETCH(QString, finalTitleBefore); |
|
224 |
QFETCH(QString, finalTitleAfter); |
|
225 |
||
226 |
||
227 |
QWidget widget; |
|
228 |
QCOMPARE(widget.windowFilePath(), QString()); |
|
229 |
||
230 |
if (!applicationName.isEmpty()) |
|
231 |
qApp->setApplicationName(applicationName); |
|
232 |
else |
|
233 |
qApp->setApplicationName(QString()); |
|
234 |
||
235 |
if (setWindowTitleBefore) { |
|
236 |
widget.setWindowTitle(indyWindowTitle); |
|
237 |
} |
|
238 |
widget.setWindowFilePath(filePath); |
|
239 |
QCOMPARE(finalTitleBefore, widget.windowTitle()); |
|
240 |
QCOMPARE(widget.windowFilePath(), filePath); |
|
241 |
||
242 |
if (setWindowTitleAfter) { |
|
243 |
widget.setWindowTitle(indyWindowTitle); |
|
244 |
} |
|
245 |
QCOMPARE(finalTitleAfter, widget.windowTitle()); |
|
246 |
QCOMPARE(widget.windowFilePath(), filePath); |
|
247 |
} |
|
248 |
||
249 |
void tst_QWidget_window::tst_windowFilePath_data() |
|
250 |
{ |
|
251 |
QTest::addColumn<QString>("filePath"); |
|
252 |
QTest::addColumn<QString>("result"); |
|
253 |
QTest::addColumn<bool>("again"); |
|
254 |
QTest::addColumn<QString>("filePath2"); |
|
255 |
QTest::addColumn<QString>("result2"); |
|
256 |
||
257 |
QString validPath = QApplication::applicationFilePath(); |
|
258 |
QString invalidPath = QLatin1String("::**Never a Real Path**::"); |
|
259 |
||
260 |
QTest::newRow("never Set Path") << QString() << QString() << false << QString() << QString(); |
|
261 |
QTest::newRow("never EVER Set Path") << QString() << QString() << true << QString() << QString(); |
|
262 |
QTest::newRow("Valid Path") << validPath << validPath << false << QString() << QString(); |
|
263 |
QTest::newRow("invalid Path") << invalidPath << invalidPath << false << QString() << QString(); |
|
264 |
QTest::newRow("Valid Path then empty") << validPath << validPath << true << QString() << QString(); |
|
265 |
QTest::newRow("invalid Path then empty") << invalidPath << invalidPath << true << QString() << QString(); |
|
266 |
QTest::newRow("invalid Path then valid") << invalidPath << invalidPath << true << validPath << validPath; |
|
267 |
QTest::newRow("valid Path then invalid") << validPath << validPath << true << invalidPath << invalidPath; |
|
268 |
} |
|
269 |
||
270 |
void tst_QWidget_window::tst_windowFilePath() |
|
271 |
{ |
|
272 |
QFETCH(QString, filePath); |
|
273 |
QFETCH(QString, result); |
|
274 |
QFETCH(bool, again); |
|
275 |
QFETCH(QString, filePath2); |
|
276 |
QFETCH(QString, result2); |
|
277 |
||
278 |
QWidget widget; |
|
279 |
QCOMPARE(widget.windowFilePath(), QString()); |
|
280 |
widget.setWindowFilePath(filePath); |
|
281 |
QCOMPARE(widget.windowFilePath(), result); |
|
282 |
if (again) { |
|
283 |
widget.setWindowFilePath(filePath2); |
|
284 |
QCOMPARE(widget.windowFilePath(), result2); |
|
285 |
} |
|
286 |
} |
|
287 |
||
288 |
void tst_QWidget_window::tst_showWithoutActivating() |
|
289 |
{ |
|
290 |
#ifndef Q_WS_X11 |
|
291 |
QSKIP("This test is X11-only.", SkipAll); |
|
292 |
#else |
|
293 |
QWidget w; |
|
294 |
w.show(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
295 |
QTest::qWaitForWindowShown(&w); |
0 | 296 |
QApplication::processEvents(); |
297 |
||
298 |
QApplication::clipboard(); |
|
299 |
QLineEdit *lineEdit = new QLineEdit; |
|
300 |
lineEdit->setAttribute(Qt::WA_ShowWithoutActivating, true); |
|
301 |
lineEdit->show(); |
|
302 |
lineEdit->setAttribute(Qt::WA_ShowWithoutActivating, false); |
|
303 |
lineEdit->raise(); |
|
304 |
lineEdit->activateWindow(); |
|
305 |
||
306 |
Window window; |
|
307 |
int revertto; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
308 |
QTRY_COMPARE(lineEdit->winId(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
309 |
(XGetInputFocus(QX11Info::display(), &window, &revertto), window) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
310 |
// Note the use of the , before window because we want the XGetInputFocus to be re-executed |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
311 |
// in each iteration of the inside loop of the QTRY_COMPARE macro |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
312 |
|
0 | 313 |
#endif // Q_WS_X11 |
314 |
} |
|
315 |
||
316 |
void tst_QWidget_window::tst_paintEventOnSecondShow() |
|
317 |
{ |
|
318 |
TestWidget w; |
|
319 |
w.show(); |
|
320 |
w.hide(); |
|
321 |
||
322 |
w.reset(); |
|
323 |
w.show(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
324 |
QTest::qWaitForWindowShown(&w); |
0 | 325 |
QApplication::processEvents(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
326 |
QTRY_VERIFY(w.paintEventReceived); |
0 | 327 |
} |
328 |
||
329 |
QTEST_MAIN(tst_QWidget_window) |
|
330 |
#include "tst_qwidget_window.moc" |