1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
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.
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.
28 ** GNU General Public License Usage
29 ** Alternatively, this file may be used under the terms of the GNU
30 ** General Public License version 3.0 as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL included in the
32 ** packaging of this file. Please review the following information to
33 ** ensure the GNU General Public License version 3.0 requirements will be
34 ** met: http://www.gnu.org/copyleft/gpl.html.
36 ** If you have questions regarding the use of this file, please contact
37 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
43 #include <QtTest/QtTest>
44 #include <QtGui/QtGui>
45 #include <qeventloop.h>
48 #include <qlistwidget.h>
55 class tst_QWidget_window
: public QWidget
60 tst_QWidget_window(){};
64 void cleanupTestCase();
69 void tst_show_move_hide_show();
71 void tst_resize_show();
72 void tst_show_resize();
73 void tst_show_resize_hide_show();
75 void tst_windowFilePathAndwindowTitle_data();
76 void tst_windowFilePathAndwindowTitle();
77 void tst_windowFilePath_data();
78 void tst_windowFilePath();
80 void tst_showWithoutActivating();
81 void tst_paintEventOnSecondShow();
84 void tst_QWidget_window::initTestCase()
88 void tst_QWidget_window::cleanupTestCase()
92 void tst_QWidget_window::tst_move_show()
97 QCOMPARE(w
.pos(), QPoint(100, 100));
98 // QCoreApplication::processEvents(QEventLoop::AllEvents, 3000);
101 void tst_QWidget_window::tst_show_move()
106 QCOMPARE(w
.pos(), QPoint(100, 100));
107 // QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
110 void tst_QWidget_window::tst_show_move_hide_show()
117 QCOMPARE(w
.pos(), QPoint(100, 100));
118 // QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
121 void tst_QWidget_window::tst_resize_show()
126 QCOMPARE(w
.size(), QSize(200, 200));
127 // QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
130 void tst_QWidget_window::tst_show_resize()
135 QCOMPARE(w
.size(), QSize(200, 200));
136 // QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
139 void tst_QWidget_window::tst_show_resize_hide_show()
146 QCOMPARE(w
.size(), QSize(200, 200));
147 // QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
150 class TestWidget
: public QWidget
154 bool paintEventReceived
;
156 void reset(){ m_first
= m_next
= 0; paintEventReceived
= false; }
157 bool event(QEvent
*event
)
159 switch (event
->type()) {
160 case QEvent::WindowActivate
:
161 case QEvent::WindowDeactivate
:
165 m_next
= event
->type();
167 m_first
= event
->type();
170 paintEventReceived
= true;
175 return QWidget::event(event
);
179 void tst_QWidget_window::tst_windowFilePathAndwindowTitle_data()
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");
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");
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
;
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
;
213 void tst_QWidget_window::tst_windowFilePathAndwindowTitle()
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
);
225 QCOMPARE(widget
.windowFilePath(), QString());
227 if (!applicationName
.isEmpty())
228 qApp
->setApplicationName(applicationName
);
230 qApp
->setApplicationName(QString());
232 if (setWindowTitleBefore
) {
233 widget
.setWindowTitle(indyWindowTitle
);
235 widget
.setWindowFilePath(filePath
);
236 QCOMPARE(finalTitleBefore
, widget
.windowTitle());
237 QCOMPARE(widget
.windowFilePath(), filePath
);
239 if (setWindowTitleAfter
) {
240 widget
.setWindowTitle(indyWindowTitle
);
242 QCOMPARE(finalTitleAfter
, widget
.windowTitle());
243 QCOMPARE(widget
.windowFilePath(), filePath
);
246 void tst_QWidget_window::tst_windowFilePath_data()
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");
254 QString validPath
= QApplication::applicationFilePath();
255 QString invalidPath
= QLatin1String("::**Never a Real Path**::");
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
;
267 void tst_QWidget_window::tst_windowFilePath()
269 QFETCH(QString
, filePath
);
270 QFETCH(QString
, result
);
272 QFETCH(QString
, filePath2
);
273 QFETCH(QString
, result2
);
276 QCOMPARE(widget
.windowFilePath(), QString());
277 widget
.setWindowFilePath(filePath
);
278 QCOMPARE(widget
.windowFilePath(), result
);
280 widget
.setWindowFilePath(filePath2
);
281 QCOMPARE(widget
.windowFilePath(), result2
);
285 void tst_QWidget_window::tst_showWithoutActivating()
288 QSKIP("This test is X11-only.", SkipAll
);
292 qt_x11_wait_for_window_manager(&w
);
293 QApplication::processEvents();
295 QApplication::clipboard();
296 QLineEdit
*lineEdit
= new QLineEdit
;
297 lineEdit
->setAttribute(Qt::WA_ShowWithoutActivating
, true);
299 lineEdit
->setAttribute(Qt::WA_ShowWithoutActivating
, false);
301 lineEdit
->activateWindow();
305 XGetInputFocus(QX11Info::display(), &window
, &revertto
);
306 QCOMPARE(lineEdit
->winId(), window
);
310 void tst_QWidget_window::tst_paintEventOnSecondShow()
321 QApplication::processEvents();
322 QVERIFY(w
.paintEventReceived
);
325 QTEST_MAIN(tst_QWidget_window
)
326 #include "tst_qwidget_window.moc"