Fixes a crash in QDoubleSpinBox
[qt-netbsd.git] / tests / auto / qwidget_window / tst_qwidget_window.cpp
blobee904640cd2cd8ce9e914ccab6c2b15890f80cc1
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 ** Commercial Usage
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.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
43 #include <QtTest/QtTest>
44 #include <QtGui/QtGui>
45 #include <qeventloop.h>
46 #include <qlist.h>
48 #include <qlistwidget.h>
50 #ifdef Q_WS_X11
51 #include <X11/Xlib.h>
52 #include <QX11Info>
53 #endif // Q_WS_X11
55 class tst_QWidget_window : public QWidget
57 Q_OBJECT
59 public:
60 tst_QWidget_window(){};
62 public slots:
63 void initTestCase();
64 void cleanupTestCase();
66 private slots:
67 void tst_move_show();
68 void tst_show_move();
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()
94 QWidget w;
95 w.move(100, 100);
96 w.show();
97 QCOMPARE(w.pos(), QPoint(100, 100));
98 // QCoreApplication::processEvents(QEventLoop::AllEvents, 3000);
101 void tst_QWidget_window::tst_show_move()
103 QWidget w;
104 w.show();
105 w.move(100, 100);
106 QCOMPARE(w.pos(), QPoint(100, 100));
107 // QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
110 void tst_QWidget_window::tst_show_move_hide_show()
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);
121 void tst_QWidget_window::tst_resize_show()
123 QWidget w;
124 w.resize(200, 200);
125 w.show();
126 QCOMPARE(w.size(), QSize(200, 200));
127 // QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
130 void tst_QWidget_window::tst_show_resize()
132 QWidget w;
133 w.show();
134 w.resize(200, 200);
135 QCOMPARE(w.size(), QSize(200, 200));
136 // QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
139 void tst_QWidget_window::tst_show_resize_hide_show()
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);
150 class TestWidget : public QWidget
152 public:
153 int m_first, m_next;
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:
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;
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;
200 QString platString =
201 #ifdef Q_WS_MAC
202 fileNameOnly;
203 #else
204 fileAndApp;
205 #endif
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);
224 QWidget widget;
225 QCOMPARE(widget.windowFilePath(), QString());
227 if (!applicationName.isEmpty())
228 qApp->setApplicationName(applicationName);
229 else
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);
271 QFETCH(bool, again);
272 QFETCH(QString, filePath2);
273 QFETCH(QString, result2);
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);
285 void tst_QWidget_window::tst_showWithoutActivating()
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();
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();
303 Window window;
304 int revertto;
305 XGetInputFocus(QX11Info::display(), &window, &revertto);
306 QCOMPARE(lineEdit->winId(), window);
307 #endif // Q_WS_X11
310 void tst_QWidget_window::tst_paintEventOnSecondShow()
312 TestWidget w;
313 w.show();
314 w.hide();
316 w.reset();
317 w.show();
318 #ifdef Q_WS_X11
319 QTest::qWait(500);
320 #endif
321 QApplication::processEvents();
322 QVERIFY(w.paintEventReceived);
325 QTEST_MAIN(tst_QWidget_window)
326 #include "tst_qwidget_window.moc"