1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtTest/QtTest>
#include <QtGui/QtGui>
#include <qeventloop.h>
#include <qlist.h>
#include <qlistwidget.h>
#ifdef Q_WS_X11
#include <X11/Xlib.h>
#include <QX11Info>
#endif // Q_WS_X11
class tst_QWidget_window : public QWidget
{
Q_OBJECT
public:
tst_QWidget_window(){};
public slots:
void initTestCase();
void cleanupTestCase();
private slots:
void tst_move_show();
void tst_show_move();
void tst_show_move_hide_show();
void tst_resize_show();
void tst_show_resize();
void tst_show_resize_hide_show();
void tst_windowFilePathAndwindowTitle_data();
void tst_windowFilePathAndwindowTitle();
void tst_windowFilePath_data();
void tst_windowFilePath();
void tst_showWithoutActivating();
void tst_paintEventOnSecondShow();
};
void tst_QWidget_window::initTestCase()
{
}
void tst_QWidget_window::cleanupTestCase()
{
}
void tst_QWidget_window::tst_move_show()
{
QWidget w;
w.move(100, 100);
w.show();
QCOMPARE(w.pos(), QPoint(100, 100));
// QCoreApplication::processEvents(QEventLoop::AllEvents, 3000);
}
void tst_QWidget_window::tst_show_move()
{
QWidget w;
w.show();
w.move(100, 100);
QCOMPARE(w.pos(), QPoint(100, 100));
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
}
void tst_QWidget_window::tst_show_move_hide_show()
{
QWidget w;
w.show();
w.move(100, 100);
w.hide();
w.show();
QCOMPARE(w.pos(), QPoint(100, 100));
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
}
void tst_QWidget_window::tst_resize_show()
{
QWidget w;
w.resize(200, 200);
w.show();
QCOMPARE(w.size(), QSize(200, 200));
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
}
void tst_QWidget_window::tst_show_resize()
{
QWidget w;
w.show();
w.resize(200, 200);
QCOMPARE(w.size(), QSize(200, 200));
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
}
void tst_QWidget_window::tst_show_resize_hide_show()
{
QWidget w;
w.show();
w.resize(200, 200);
w.hide();
w.show();
QCOMPARE(w.size(), QSize(200, 200));
// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
}
class TestWidget : public QWidget
{
public:
int m_first, m_next;
bool paintEventReceived;
void reset(){ m_first = m_next = 0; paintEventReceived = false; }
bool event(QEvent *event)
{
switch (event->type()) {
case QEvent::WindowActivate:
case QEvent::WindowDeactivate:
case QEvent::Hide:
case QEvent::Show:
if (m_first)
m_next = event->type();
else
m_first = event->type();
break;
case QEvent::Paint:
paintEventReceived = true;
break;
default:
break;
}
return QWidget::event(event);
}
};
void tst_QWidget_window::tst_windowFilePathAndwindowTitle_data()
{
QTest::addColumn<bool>("setWindowTitleBefore");
QTest::addColumn<bool>("setWindowTitleAfter");
QTest::addColumn<QString>("filePath");
QTest::addColumn<QString>("applicationName");
QTest::addColumn<QString>("indyWindowTitle");
QTest::addColumn<QString>("finalTitleBefore");
QTest::addColumn<QString>("finalTitleAfter");
QString validPath = QApplication::applicationFilePath();
QString appName = QLatin1String("Killer App");
QString fileNameOnly = QFileInfo(validPath).fileName() + QLatin1String("[*]");
QString fileAndApp = fileNameOnly + QLatin1String(" ") + QChar(0x2014) + QLatin1String(" ") + appName;
QString windowTitle = QLatin1String("Here is a Window Title");
QTest::newRow("never Set Title nor AppName") << false << false << validPath << QString() << windowTitle << fileNameOnly << fileNameOnly;
QTest::newRow("set title after only, but no AppName") << false << true << validPath << QString() << windowTitle << fileNameOnly << windowTitle;
QTest::newRow("set title before only, not AppName") << true << false << validPath << QString() << windowTitle << windowTitle << windowTitle;
QTest::newRow("always set title, not appName") << true << true << validPath << QString() << windowTitle << windowTitle << windowTitle;
QString platString =
#ifdef Q_WS_MAC
fileNameOnly;
#else
fileAndApp;
#endif
QTest::newRow("never Set Title, yes AppName") << false << false << validPath << appName << windowTitle << platString << platString;
QTest::newRow("set title after only, yes AppName") << false << true << validPath << appName << windowTitle << platString << windowTitle;
QTest::newRow("set title before only, yes AppName") << true << false << validPath << appName << windowTitle << windowTitle << windowTitle;
QTest::newRow("always set title, yes appName") << true << true << validPath << appName << windowTitle << windowTitle << windowTitle;
}
void tst_QWidget_window::tst_windowFilePathAndwindowTitle()
{
QFETCH(bool, setWindowTitleBefore);
QFETCH(bool, setWindowTitleAfter);
QFETCH(QString, filePath);
QFETCH(QString, applicationName);
QFETCH(QString, indyWindowTitle);
QFETCH(QString, finalTitleBefore);
QFETCH(QString, finalTitleAfter);
QWidget widget;
QCOMPARE(widget.windowFilePath(), QString());
if (!applicationName.isEmpty())
qApp->setApplicationName(applicationName);
else
qApp->setApplicationName(QString());
if (setWindowTitleBefore) {
widget.setWindowTitle(indyWindowTitle);
}
widget.setWindowFilePath(filePath);
QCOMPARE(finalTitleBefore, widget.windowTitle());
QCOMPARE(widget.windowFilePath(), filePath);
if (setWindowTitleAfter) {
widget.setWindowTitle(indyWindowTitle);
}
QCOMPARE(finalTitleAfter, widget.windowTitle());
QCOMPARE(widget.windowFilePath(), filePath);
}
void tst_QWidget_window::tst_windowFilePath_data()
{
QTest::addColumn<QString>("filePath");
QTest::addColumn<QString>("result");
QTest::addColumn<bool>("again");
QTest::addColumn<QString>("filePath2");
QTest::addColumn<QString>("result2");
QString validPath = QApplication::applicationFilePath();
QString invalidPath = QLatin1String("::**Never a Real Path**::");
QTest::newRow("never Set Path") << QString() << QString() << false << QString() << QString();
QTest::newRow("never EVER Set Path") << QString() << QString() << true << QString() << QString();
QTest::newRow("Valid Path") << validPath << validPath << false << QString() << QString();
QTest::newRow("invalid Path") << invalidPath << invalidPath << false << QString() << QString();
QTest::newRow("Valid Path then empty") << validPath << validPath << true << QString() << QString();
QTest::newRow("invalid Path then empty") << invalidPath << invalidPath << true << QString() << QString();
QTest::newRow("invalid Path then valid") << invalidPath << invalidPath << true << validPath << validPath;
QTest::newRow("valid Path then invalid") << validPath << validPath << true << invalidPath << invalidPath;
}
void tst_QWidget_window::tst_windowFilePath()
{
QFETCH(QString, filePath);
QFETCH(QString, result);
QFETCH(bool, again);
QFETCH(QString, filePath2);
QFETCH(QString, result2);
QWidget widget;
QCOMPARE(widget.windowFilePath(), QString());
widget.setWindowFilePath(filePath);
QCOMPARE(widget.windowFilePath(), result);
if (again) {
widget.setWindowFilePath(filePath2);
QCOMPARE(widget.windowFilePath(), result2);
}
}
void tst_QWidget_window::tst_showWithoutActivating()
{
#ifndef Q_WS_X11
QSKIP("This test is X11-only.", SkipAll);
#else
QWidget w;
w.show();
qt_x11_wait_for_window_manager(&w);
QApplication::processEvents();
QApplication::clipboard();
QLineEdit *lineEdit = new QLineEdit;
lineEdit->setAttribute(Qt::WA_ShowWithoutActivating, true);
lineEdit->show();
lineEdit->setAttribute(Qt::WA_ShowWithoutActivating, false);
lineEdit->raise();
lineEdit->activateWindow();
Window window;
int revertto;
XGetInputFocus(QX11Info::display(), &window, &revertto);
QCOMPARE(lineEdit->winId(), window);
#endif // Q_WS_X11
}
void tst_QWidget_window::tst_paintEventOnSecondShow()
{
TestWidget w;
w.show();
w.hide();
w.reset();
w.show();
#ifdef Q_WS_X11
QTest::qWait(500);
#endif
QApplication::processEvents();
QVERIFY(w.paintEventReceived);
}
QTEST_MAIN(tst_QWidget_window)
#include "tst_qwidget_window.moc"
|