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