author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
//#define QT_TST_QAPP_DEBUG |
|
44 |
#include <qdebug.h> |
|
45 |
||
46 |
#include <QtTest/QtTest> |
|
47 |
||
48 |
#include "qabstracteventdispatcher.h" |
|
49 |
#include <QtGui> |
|
50 |
||
51 |
#include "private/qapplication_p.h" |
|
52 |
#include "private/qstylesheetstyle_p.h" |
|
53 |
#ifdef Q_OS_WINCE |
|
54 |
#include <windows.h> |
|
55 |
#endif |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
56 |
#ifdef Q_OS_SYMBIAN |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
57 |
#include <aknenv.h> |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
58 |
#endif |
0 | 59 |
|
60 |
//TESTED_CLASS= |
|
61 |
//TESTED_FILES= |
|
62 |
||
63 |
#if defined(Q_OS_SYMBIAN) |
|
64 |
// In Symbian, the PluginsPath doesn't specify the only absolute path; just the dir that can be found on any drive |
|
65 |
static void addExpectedSymbianPluginsPath(QStringList& expected) |
|
66 |
{ |
|
67 |
QString installPathPlugins = QDir::fromNativeSeparators(QLibraryInfo::location(QLibraryInfo::PluginsPath)); |
|
68 |
QFileInfoList driveList = QDir::drives(); |
|
69 |
QListIterator<QFileInfo> iter(driveList); |
|
70 |
while (iter.hasNext()) { |
|
71 |
QFileInfo testFi(iter.next().canonicalPath().append(installPathPlugins)); |
|
72 |
if (testFi.exists()) |
|
73 |
expected << testFi.canonicalFilePath(); |
|
74 |
} |
|
75 |
} |
|
76 |
#endif |
|
77 |
||
78 |
class tst_QApplication : public QObject |
|
79 |
{ |
|
80 |
Q_OBJECT |
|
81 |
||
82 |
public: |
|
83 |
tst_QApplication(); |
|
84 |
virtual ~tst_QApplication(); |
|
85 |
||
86 |
public slots: |
|
87 |
void init(); |
|
88 |
void cleanup(); |
|
89 |
private slots: |
|
90 |
void sendEventsOnProcessEvents(); // this must be the first test |
|
91 |
void getSetCheck(); |
|
92 |
void staticSetup(); |
|
93 |
||
94 |
void alert(); |
|
95 |
||
96 |
void multiple_data(); |
|
97 |
void multiple(); |
|
98 |
||
99 |
void nonGui(); |
|
100 |
||
101 |
void setFont_data(); |
|
102 |
void setFont(); |
|
103 |
||
104 |
void args_data(); |
|
105 |
void args(); |
|
106 |
||
107 |
void lastWindowClosed(); |
|
108 |
void quitOnLastWindowClosed(); |
|
109 |
void testDeleteLater(); |
|
110 |
void testDeleteLaterProcessEvents(); |
|
111 |
||
112 |
void libraryPaths(); |
|
113 |
void libraryPaths_qt_plugin_path(); |
|
114 |
void libraryPaths_qt_plugin_path_2(); |
|
115 |
||
116 |
void sendPostedEvents(); |
|
117 |
||
118 |
void thread(); |
|
119 |
void desktopSettingsAware(); |
|
120 |
||
121 |
void setActiveWindow(); |
|
122 |
||
123 |
void focusChanged(); |
|
124 |
void focusOut(); |
|
125 |
||
126 |
void execAfterExit(); |
|
127 |
||
128 |
void wheelScrollLines(); |
|
129 |
||
130 |
void task109149(); |
|
131 |
||
132 |
void style(); |
|
133 |
||
134 |
void allWidgets(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
void topLevelWidgets(); |
0 | 136 |
|
137 |
void setAttribute(); |
|
138 |
||
139 |
void windowsCommandLine_data(); |
|
140 |
void windowsCommandLine(); |
|
141 |
||
142 |
void touchEventPropagation(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
144 |
void symbianNoApplicationPanes(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
145 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
void symbianNeedForTraps(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
void symbianLeaveThroughMain(); |
0 | 148 |
}; |
149 |
||
150 |
class EventSpy : public QObject |
|
151 |
{ |
|
152 |
Q_OBJECT |
|
153 |
||
154 |
public: |
|
155 |
QList<int> recordedEvents; |
|
156 |
bool eventFilter(QObject *, QEvent *event) |
|
157 |
{ |
|
158 |
recordedEvents.append(event->type()); |
|
159 |
return false; |
|
160 |
} |
|
161 |
}; |
|
162 |
||
163 |
void tst_QApplication::sendEventsOnProcessEvents() |
|
164 |
{ |
|
165 |
int argc = 0; |
|
166 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
167 |
||
168 |
EventSpy spy; |
|
169 |
app.installEventFilter(&spy); |
|
170 |
||
171 |
QCoreApplication::postEvent(&app, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
172 |
QCoreApplication::processEvents(); |
|
173 |
QVERIFY(spy.recordedEvents.contains(QEvent::User + 1)); |
|
174 |
} |
|
175 |
||
176 |
class MyInputContext : public QInputContext |
|
177 |
{ |
|
178 |
public: |
|
179 |
MyInputContext() : QInputContext() {} |
|
180 |
QString identifierName() { return QString("NoName"); } |
|
181 |
QString language() { return QString("NoLanguage"); } |
|
182 |
void reset() {} |
|
183 |
bool isComposing() const { return false; } |
|
184 |
}; |
|
185 |
||
186 |
// Testing get/set functions |
|
187 |
void tst_QApplication::getSetCheck() |
|
188 |
{ |
|
189 |
int argc = 0; |
|
190 |
QApplication obj1(argc, 0, QApplication::GuiServer); |
|
191 |
// QInputContext * QApplication::inputContext() |
|
192 |
// void QApplication::setInputContext(QInputContext *) |
|
193 |
MyInputContext *var1 = new MyInputContext; |
|
194 |
obj1.setInputContext(var1); |
|
195 |
QCOMPARE((QInputContext *)var1, obj1.inputContext()); |
|
196 |
QTest::ignoreMessage(QtWarningMsg, "QApplication::setInputContext: called with 0 input context"); |
|
197 |
obj1.setInputContext((QInputContext *)0); |
|
198 |
QCOMPARE((QInputContext *)var1, obj1.inputContext()); |
|
199 |
// delete var1; // No delete, since QApplication takes ownership |
|
200 |
} |
|
201 |
||
202 |
class CloseEventTestWindow : public QWidget |
|
203 |
{ |
|
204 |
public: |
|
205 |
CloseEventTestWindow(QWidget *parent = 0) |
|
206 |
: QWidget(parent) |
|
207 |
{ |
|
208 |
} |
|
209 |
||
210 |
void closeEvent(QCloseEvent *event) |
|
211 |
{ |
|
212 |
QWidget dialog; |
|
213 |
dialog.show(); |
|
214 |
dialog.close(); |
|
215 |
||
216 |
hide(); |
|
217 |
event->ignore(); |
|
218 |
} |
|
219 |
}; |
|
220 |
||
221 |
static char *argv0; |
|
222 |
||
223 |
tst_QApplication::tst_QApplication() |
|
224 |
{ |
|
225 |
#ifdef Q_OS_WINCE |
|
226 |
// Clean up environment previously to launching test |
|
227 |
qputenv("QT_PLUGIN_PATH", QByteArray()); |
|
228 |
#endif |
|
229 |
} |
|
230 |
||
231 |
tst_QApplication::~tst_QApplication() |
|
232 |
{ |
|
233 |
||
234 |
} |
|
235 |
||
236 |
void tst_QApplication::init() |
|
237 |
{ |
|
238 |
// TODO: Add initialization code here. |
|
239 |
// This will be executed immediately before each test is run. |
|
240 |
} |
|
241 |
||
242 |
void tst_QApplication::cleanup() |
|
243 |
{ |
|
244 |
// TODO: Add cleanup code here. |
|
245 |
// This will be executed immediately after each test is run. |
|
246 |
} |
|
247 |
||
248 |
void tst_QApplication::staticSetup() |
|
249 |
{ |
|
250 |
QVERIFY(!qApp); |
|
251 |
||
252 |
QStyle *style = QStyleFactory::create(QLatin1String("Windows")); |
|
253 |
QVERIFY(style); |
|
254 |
QApplication::setStyle(style); |
|
255 |
||
256 |
QPalette pal; |
|
257 |
QApplication::setPalette(pal); |
|
258 |
||
259 |
/*QFont font; |
|
260 |
QApplication::setFont(font);*/ |
|
261 |
||
262 |
int argc = 0; |
|
263 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
264 |
} |
|
265 |
||
266 |
||
267 |
// QApp subclass that exits the event loop after 150ms |
|
268 |
class TestApplication : public QApplication |
|
269 |
{ |
|
270 |
public: |
|
271 |
TestApplication( int &argc, char **argv ) |
|
272 |
: QApplication( argc, argv, QApplication::GuiServer ) |
|
273 |
{ |
|
274 |
startTimer( 150 ); |
|
275 |
} |
|
276 |
||
277 |
void timerEvent( QTimerEvent * ) |
|
278 |
{ |
|
279 |
quit(); |
|
280 |
} |
|
281 |
}; |
|
282 |
||
283 |
void tst_QApplication::alert() |
|
284 |
{ |
|
285 |
int argc = 0; |
|
286 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
287 |
app.alert(0, 0); |
|
288 |
||
289 |
QWidget widget; |
|
290 |
QWidget widget2; |
|
291 |
app.alert(&widget, 100); |
|
292 |
widget.show(); |
|
293 |
widget2.show(); |
|
294 |
#ifdef Q_WS_X11 |
|
295 |
qt_x11_wait_for_window_manager(&widget); |
|
296 |
qt_x11_wait_for_window_manager(&widget2); |
|
297 |
#endif |
|
298 |
QTest::qWait(100); |
|
299 |
app.alert(&widget, -1); |
|
300 |
app.alert(&widget, 250); |
|
301 |
widget2.activateWindow(); |
|
302 |
QApplication::setActiveWindow(&widget2); |
|
303 |
app.alert(&widget, 0); |
|
304 |
widget.activateWindow(); |
|
305 |
QApplication::setActiveWindow(&widget); |
|
306 |
app.alert(&widget, 200); |
|
307 |
app.syncX(); |
|
308 |
} |
|
309 |
||
310 |
void tst_QApplication::multiple_data() |
|
311 |
{ |
|
312 |
QTest::addColumn<QStringList>("features"); |
|
313 |
||
314 |
// return a list of things to try |
|
315 |
QTest::newRow( "data0" ) << QStringList( "" ); |
|
316 |
QTest::newRow( "data1" ) << QStringList( "QFont" ); |
|
317 |
QTest::newRow( "data2" ) << QStringList( "QPixmap" ); |
|
318 |
QTest::newRow( "data3" ) << QStringList( "QWidget" ); |
|
319 |
} |
|
320 |
||
321 |
void tst_QApplication::multiple() |
|
322 |
{ |
|
323 |
QFETCH(QStringList,features); |
|
324 |
||
325 |
int i = 0; |
|
326 |
int argc = 0; |
|
327 |
while ( i++ < 5 ) { |
|
328 |
TestApplication app( argc, 0 ); |
|
329 |
||
330 |
if ( features.contains( "QFont" ) ) { |
|
331 |
// create font and force loading |
|
332 |
QFont font( "Arial", 12 ); |
|
333 |
QFontInfo finfo( font ); |
|
334 |
finfo.exactMatch(); |
|
335 |
} |
|
336 |
if ( features.contains( "QPixmap" ) ) { |
|
337 |
QPixmap pix( 100, 100 ); |
|
338 |
pix.fill( Qt::black ); |
|
339 |
} |
|
340 |
if ( features.contains( "QWidget" ) ) { |
|
341 |
QWidget widget; |
|
342 |
} |
|
343 |
||
344 |
QVERIFY(!app.exec()); |
|
345 |
} |
|
346 |
} |
|
347 |
||
348 |
void tst_QApplication::nonGui() |
|
349 |
{ |
|
350 |
#ifdef Q_OS_HPUX |
|
351 |
// ### This is only to allow us to generate a test report for now. |
|
352 |
QSKIP("This test shuts down the window manager on HP-UX.", SkipAll); |
|
353 |
#endif |
|
354 |
||
355 |
int argc = 0; |
|
356 |
QApplication app(argc, 0, false); |
|
357 |
QCOMPARE(qApp, &app); |
|
358 |
} |
|
359 |
||
360 |
void tst_QApplication::setFont_data() |
|
361 |
{ |
|
362 |
QTest::addColumn<QString>("family"); |
|
363 |
QTest::addColumn<int>("pointsize"); |
|
364 |
QTest::addColumn<bool>("beforeAppConstructor"); |
|
365 |
||
366 |
int argc = 0; |
|
367 |
QApplication app(argc, 0, QApplication::GuiServer); // Needed for QFontDatabase |
|
368 |
||
369 |
int cnt = 0; |
|
370 |
QFontDatabase fdb; |
|
371 |
QStringList families = fdb.families(); |
|
372 |
for (QStringList::const_iterator itr = families.begin(); |
|
373 |
itr != families.end(); |
|
374 |
++itr) { |
|
375 |
if (cnt < 3) { |
|
376 |
QString family = *itr; |
|
377 |
QStringList styles = fdb.styles(family); |
|
378 |
if (styles.size() > 0) { |
|
379 |
QString style = styles.first(); |
|
380 |
QList<int> sizes = fdb.pointSizes(family, style); |
|
381 |
if (!sizes.size()) |
|
382 |
sizes = fdb.standardSizes(); |
|
383 |
if (sizes.size() > 0) { |
|
384 |
QTest::newRow(QString("data%1a").arg(cnt).toLatin1().constData()) |
|
385 |
<< family |
|
386 |
<< sizes.first() |
|
387 |
<< false; |
|
388 |
QTest::newRow(QString("data%1b").arg(cnt).toLatin1().constData()) |
|
389 |
<< family |
|
390 |
<< sizes.first() |
|
391 |
<< true; |
|
392 |
} |
|
393 |
} |
|
394 |
} |
|
395 |
++cnt; |
|
396 |
} |
|
397 |
||
398 |
QTest::newRow("nonexistingfont") << "nosuchfont_probably_quiteunlikely" |
|
399 |
<< 0 << false; |
|
400 |
QTest::newRow("nonexistingfont") << "nosuchfont_probably_quiteunlikely" |
|
401 |
<< 0 << true; |
|
402 |
||
403 |
QTest::newRow("largescaleable") << "smoothtimes" << 100 << false; |
|
404 |
QTest::newRow("largescaleable") << "smoothtimes" << 100 << true; |
|
405 |
||
406 |
QTest::newRow("largeunscaleale") << "helvetica" << 100 << false; |
|
407 |
QTest::newRow("largeunscaleale") << "helvetica" << 100 << true; |
|
408 |
} |
|
409 |
||
410 |
void tst_QApplication::setFont() |
|
411 |
{ |
|
412 |
QFETCH( QString, family ); |
|
413 |
QFETCH( int, pointsize ); |
|
414 |
QFETCH( bool, beforeAppConstructor ); |
|
415 |
||
416 |
QFont font( family, pointsize ); |
|
417 |
if (beforeAppConstructor) { |
|
418 |
QApplication::setFont( font ); |
|
419 |
QCOMPARE(QApplication::font(), font); |
|
420 |
} |
|
421 |
||
422 |
int argc = 0; |
|
423 |
QApplication app( argc, 0, QApplication::GuiServer ); |
|
424 |
if (!beforeAppConstructor) |
|
425 |
QApplication::setFont( font ); |
|
426 |
||
427 |
QCOMPARE( app.font(), font ); |
|
428 |
} |
|
429 |
||
430 |
void tst_QApplication::args_data() |
|
431 |
{ |
|
432 |
QTest::addColumn<int>("argc_in"); |
|
433 |
QTest::addColumn<QString>("args_in"); |
|
434 |
QTest::addColumn<int>("argc_out"); |
|
435 |
QTest::addColumn<QString>("args_out"); |
|
436 |
||
437 |
QTest::newRow( "App name" ) << 1 << "/usr/bin/appname" << 1 << "/usr/bin/appname"; |
|
438 |
QTest::newRow( "No arguments" ) << 0 << QString() << 0 << QString(); |
|
439 |
QTest::newRow( "App name, style" ) << 3 << "/usr/bin/appname -style motif" << 1 << "/usr/bin/appname"; |
|
440 |
QTest::newRow( "App name, style, arbitrary, reverse" ) << 5 << "/usr/bin/appname -style motif -arbitrary -reverse" |
|
441 |
<< 2 << "/usr/bin/appname -arbitrary"; |
|
442 |
} |
|
443 |
||
444 |
void tst_QApplication::task109149() |
|
445 |
{ |
|
446 |
int argc = 0; |
|
447 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
448 |
QApplication::setFont(QFont("helvetica", 100)); |
|
449 |
||
450 |
QWidget w; |
|
451 |
w.setWindowTitle("hello"); |
|
452 |
w.show(); |
|
453 |
||
454 |
app.processEvents(); |
|
455 |
} |
|
456 |
||
457 |
static char ** QString2cstrings( const QString &args ) |
|
458 |
{ |
|
459 |
static QList<QByteArray> cache; |
|
460 |
||
461 |
int i; |
|
462 |
char **argarray = 0; |
|
463 |
QStringList list = args.split(' ');; |
|
464 |
argarray = new char*[list.count()+1]; |
|
465 |
||
466 |
for (i = 0; i < (int)list.count(); ++i ) { |
|
467 |
QByteArray l1 = list[i].toLatin1(); |
|
468 |
argarray[i] = l1.data(); |
|
469 |
cache.append(l1); |
|
470 |
} |
|
471 |
argarray[i] = 0; |
|
472 |
||
473 |
return argarray; |
|
474 |
} |
|
475 |
||
476 |
static QString cstrings2QString( char **args ) |
|
477 |
{ |
|
478 |
QString string; |
|
479 |
if ( !args ) |
|
480 |
return string; |
|
481 |
||
482 |
int i = 0; |
|
483 |
while ( args[i] ) { |
|
484 |
string += args[i]; |
|
485 |
if ( args[i+1] ) |
|
486 |
string += " "; |
|
487 |
++i; |
|
488 |
} |
|
489 |
return string; |
|
490 |
} |
|
491 |
||
492 |
void tst_QApplication::args() |
|
493 |
{ |
|
494 |
QFETCH( int, argc_in ); |
|
495 |
QFETCH( QString, args_in ); |
|
496 |
QFETCH( int, argc_out ); |
|
497 |
QFETCH( QString, args_out ); |
|
498 |
||
499 |
char **argv = QString2cstrings( args_in ); |
|
500 |
||
501 |
QApplication app( argc_in, argv, QApplication::GuiServer ); |
|
502 |
QString argv_out = cstrings2QString(argv); |
|
503 |
||
504 |
QCOMPARE( argc_in, argc_out ); |
|
505 |
QCOMPARE( argv_out, args_out ); |
|
506 |
||
507 |
delete [] argv; |
|
508 |
} |
|
509 |
||
510 |
class CloseWidget : public QWidget |
|
511 |
{ |
|
512 |
Q_OBJECT |
|
513 |
public: |
|
514 |
CloseWidget() |
|
515 |
{ |
|
516 |
startTimer(500); |
|
517 |
} |
|
518 |
||
519 |
protected: |
|
520 |
void timerEvent(QTimerEvent *) |
|
521 |
{ |
|
522 |
close(); |
|
523 |
} |
|
524 |
||
525 |
}; |
|
526 |
||
527 |
void tst_QApplication::lastWindowClosed() |
|
528 |
{ |
|
529 |
int argc = 0; |
|
530 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
531 |
||
532 |
QSignalSpy spy(&app, SIGNAL(lastWindowClosed())); |
|
533 |
||
534 |
QPointer<QDialog> dialog = new QDialog; |
|
535 |
QVERIFY(dialog->testAttribute(Qt::WA_QuitOnClose)); |
|
536 |
QTimer::singleShot(1000, dialog, SLOT(accept())); |
|
537 |
dialog->exec(); |
|
538 |
QVERIFY(dialog); |
|
539 |
QCOMPARE(spy.count(), 0); |
|
540 |
||
541 |
QPointer<CloseWidget>widget = new CloseWidget; |
|
542 |
QVERIFY(widget->testAttribute(Qt::WA_QuitOnClose)); |
|
543 |
QObject::connect(&app, SIGNAL(lastWindowClosed()), widget, SLOT(deleteLater())); |
|
544 |
app.exec(); |
|
545 |
QVERIFY(!widget); |
|
546 |
QCOMPARE(spy.count(), 1); |
|
547 |
spy.clear(); |
|
548 |
||
549 |
#if 0 |
|
550 |
// everything is closed, so doing this should not emit lastWindowClosed() again |
|
551 |
QMetaObject::invokeMethod(dialog, "close", Qt::QueuedConnection); |
|
552 |
QTimer::singleShot(1000, &app, SLOT(quit())); |
|
553 |
app.exec(); |
|
554 |
QCOMPARE(spy.count(), 0); |
|
555 |
#endif |
|
556 |
||
557 |
delete dialog; |
|
558 |
||
559 |
// show 3 windows, close them, should only get lastWindowClosed once |
|
560 |
QWidget w1; |
|
561 |
QWidget w2; |
|
562 |
QWidget w3; |
|
563 |
w1.show(); |
|
564 |
w2.show(); |
|
565 |
w3.show(); |
|
566 |
||
567 |
QTimer::singleShot(1000, &app, SLOT(closeAllWindows())); |
|
568 |
app.exec(); |
|
569 |
QCOMPARE(spy.count(), 1); |
|
570 |
} |
|
571 |
||
572 |
class QuitOnLastWindowClosedDialog : public QDialog |
|
573 |
{ |
|
574 |
Q_OBJECT |
|
575 |
public: |
|
576 |
QPushButton *okButton; |
|
577 |
||
578 |
QuitOnLastWindowClosedDialog() |
|
579 |
{ |
|
580 |
QHBoxLayout *hbox = new QHBoxLayout(this); |
|
581 |
okButton = new QPushButton("&ok", this); |
|
582 |
||
583 |
hbox->addWidget(okButton); |
|
584 |
connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); |
|
585 |
connect(okButton, SIGNAL(clicked()), this, SLOT(ok_clicked())); |
|
586 |
} |
|
587 |
||
588 |
public slots: |
|
589 |
void ok_clicked() |
|
590 |
{ |
|
591 |
QDialog other; |
|
592 |
||
593 |
QTimer timer; |
|
594 |
connect(&timer, SIGNAL(timeout()), &other, SLOT(accept())); |
|
595 |
QSignalSpy spy(&timer, SIGNAL(timeout())); |
|
596 |
QSignalSpy appSpy(qApp, SIGNAL(lastWindowClosed())); |
|
597 |
||
598 |
timer.start(1000); |
|
599 |
other.exec(); |
|
600 |
||
601 |
// verify that the eventloop ran and let the timer fire |
|
602 |
QCOMPARE(spy.count(), 1); |
|
603 |
QCOMPARE(appSpy.count(), 1); |
|
604 |
} |
|
605 |
}; |
|
606 |
||
607 |
class QuitOnLastWindowClosedWindow : public QWidget |
|
608 |
{ |
|
609 |
Q_OBJECT |
|
610 |
||
611 |
public: |
|
612 |
QuitOnLastWindowClosedWindow() |
|
613 |
{ } |
|
614 |
||
615 |
public slots: |
|
616 |
void execDialogThenShow() |
|
617 |
{ |
|
618 |
QDialog dialog; |
|
619 |
QTimer timer1; |
|
620 |
connect(&timer1, SIGNAL(timeout()), &dialog, SLOT(accept())); |
|
621 |
QSignalSpy spy1(&timer1, SIGNAL(timeout())); |
|
622 |
timer1.setSingleShot(true); |
|
623 |
timer1.start(1000); |
|
624 |
dialog.exec(); |
|
625 |
QCOMPARE(spy1.count(), 1); |
|
626 |
||
627 |
show(); |
|
628 |
} |
|
629 |
}; |
|
630 |
||
631 |
void tst_QApplication::quitOnLastWindowClosed() |
|
632 |
{ |
|
633 |
{ |
|
634 |
int argc = 0; |
|
635 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
636 |
||
637 |
QuitOnLastWindowClosedDialog d; |
|
638 |
d.show(); |
|
639 |
QTimer::singleShot(1000, d.okButton, SLOT(animateClick())); |
|
640 |
||
641 |
QSignalSpy appSpy(&app, SIGNAL(lastWindowClosed())); |
|
642 |
app.exec(); |
|
643 |
||
644 |
// lastWindowClosed() signal should only be sent after the last dialog is closed |
|
645 |
QCOMPARE(appSpy.count(), 2); |
|
646 |
} |
|
647 |
{ |
|
648 |
int argc = 0; |
|
649 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
650 |
QSignalSpy appSpy(&app, SIGNAL(lastWindowClosed())); |
|
651 |
||
652 |
QDialog dialog; |
|
653 |
QTimer timer1; |
|
654 |
connect(&timer1, SIGNAL(timeout()), &dialog, SLOT(accept())); |
|
655 |
QSignalSpy spy1(&timer1, SIGNAL(timeout())); |
|
656 |
timer1.setSingleShot(true); |
|
657 |
timer1.start(1000); |
|
658 |
dialog.exec(); |
|
659 |
QCOMPARE(spy1.count(), 1); |
|
660 |
QCOMPARE(appSpy.count(), 0); |
|
661 |
||
662 |
QTimer timer2; |
|
663 |
connect(&timer2, SIGNAL(timeout()), &app, SLOT(quit())); |
|
664 |
QSignalSpy spy2(&timer2, SIGNAL(timeout())); |
|
665 |
timer2.setSingleShot(true); |
|
666 |
timer2.start(1000); |
|
667 |
int returnValue = app.exec(); |
|
668 |
QCOMPARE(returnValue, 0); |
|
669 |
QCOMPARE(spy2.count(), 1); |
|
670 |
QCOMPARE(appSpy.count(), 0); |
|
671 |
} |
|
672 |
{ |
|
673 |
int argc = 0; |
|
674 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
675 |
QTimer timer; |
|
676 |
timer.setInterval(100); |
|
677 |
||
678 |
QSignalSpy spy(&app, SIGNAL(aboutToQuit())); |
|
679 |
QSignalSpy spy2(&timer, SIGNAL(timeout())); |
|
680 |
||
681 |
QPointer<QMainWindow> mainWindow = new QMainWindow; |
|
682 |
QPointer<QDialog> dialog = new QDialog(mainWindow); |
|
683 |
||
684 |
QVERIFY(app.quitOnLastWindowClosed()); |
|
685 |
QVERIFY(mainWindow->testAttribute(Qt::WA_QuitOnClose)); |
|
686 |
QVERIFY(dialog->testAttribute(Qt::WA_QuitOnClose)); |
|
687 |
||
688 |
mainWindow->show(); |
|
689 |
dialog->show(); |
|
690 |
||
691 |
timer.start(); |
|
692 |
QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should quit the application |
|
693 |
QTimer::singleShot(2000, &app, SLOT(quit())); // This makes sure we quit even if it didn't |
|
694 |
||
695 |
app.exec(); |
|
696 |
||
697 |
QCOMPARE(spy.count(), 1); |
|
698 |
QVERIFY(spy2.count() < 15); // Should be around 10 if closing caused the quit |
|
699 |
} |
|
700 |
{ |
|
701 |
int argc = 0; |
|
702 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
703 |
QTimer timer; |
|
704 |
timer.setInterval(100); |
|
705 |
||
706 |
QSignalSpy spy(&app, SIGNAL(aboutToQuit())); |
|
707 |
QSignalSpy spy2(&timer, SIGNAL(timeout())); |
|
708 |
||
709 |
QPointer<QMainWindow> mainWindow = new QMainWindow; |
|
710 |
QPointer<QWidget> invisibleTopLevelWidget = new QWidget; |
|
711 |
invisibleTopLevelWidget->setAttribute(Qt::WA_DontShowOnScreen); |
|
712 |
||
713 |
QVERIFY(app.quitOnLastWindowClosed()); |
|
714 |
QVERIFY(mainWindow->testAttribute(Qt::WA_QuitOnClose)); |
|
715 |
QVERIFY(invisibleTopLevelWidget->testAttribute(Qt::WA_QuitOnClose)); |
|
716 |
QVERIFY(invisibleTopLevelWidget->testAttribute(Qt::WA_DontShowOnScreen)); |
|
717 |
||
718 |
mainWindow->show(); |
|
719 |
invisibleTopLevelWidget->show(); |
|
720 |
||
721 |
timer.start(); |
|
722 |
QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should quit the application |
|
723 |
QTimer::singleShot(2000, &app, SLOT(quit())); // This makes sure we quit even if it didn't |
|
724 |
||
725 |
app.exec(); |
|
726 |
||
727 |
QCOMPARE(spy.count(), 1); |
|
728 |
QVERIFY(spy2.count() < 15); // Should be around 10 if closing caused the quit |
|
729 |
} |
|
730 |
{ |
|
731 |
int argc = 0; |
|
732 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
733 |
QTimer timer; |
|
734 |
timer.setInterval(100); |
|
735 |
||
736 |
QSignalSpy spy(&app, SIGNAL(aboutToQuit())); |
|
737 |
QSignalSpy spy2(&timer, SIGNAL(timeout())); |
|
738 |
||
739 |
QPointer<CloseEventTestWindow> mainWindow = new CloseEventTestWindow; |
|
740 |
||
741 |
QVERIFY(app.quitOnLastWindowClosed()); |
|
742 |
QVERIFY(mainWindow->testAttribute(Qt::WA_QuitOnClose)); |
|
743 |
||
744 |
mainWindow->show(); |
|
745 |
||
746 |
timer.start(); |
|
747 |
QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should quit the application |
|
748 |
QTimer::singleShot(2000, &app, SLOT(quit())); // This makes sure we quit even if it didn't |
|
749 |
||
750 |
app.exec(); |
|
751 |
||
752 |
QCOMPARE(spy.count(), 1); |
|
753 |
QVERIFY(spy2.count() > 15); // Should be around 20 if closing did not caused the quit |
|
754 |
} |
|
755 |
{ |
|
756 |
int argc = 0; |
|
757 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
758 |
QSignalSpy appSpy(&app, SIGNAL(lastWindowClosed())); |
|
759 |
||
760 |
// exec a dialog for 1 second, then show the window |
|
761 |
QuitOnLastWindowClosedWindow window; |
|
762 |
QTimer::singleShot(0, &window, SLOT(execDialogThenShow())); |
|
763 |
||
764 |
QTimer timer; |
|
765 |
QSignalSpy timerSpy(&timer, SIGNAL(timeout())); |
|
766 |
connect(&timer, SIGNAL(timeout()), &window, SLOT(close())); |
|
767 |
timer.setSingleShot(true); |
|
768 |
timer.start(2000); |
|
769 |
int returnValue = app.exec(); |
|
770 |
QCOMPARE(returnValue, 0); |
|
771 |
// failure here means the timer above didn't fire, and the |
|
772 |
// quit was caused the the dialog being closed (not the window) |
|
773 |
QCOMPARE(timerSpy.count(), 1); |
|
774 |
QCOMPARE(appSpy.count(), 2); |
|
775 |
} |
|
776 |
} |
|
777 |
||
778 |
bool isPathListIncluded(const QStringList &l, const QStringList &r) |
|
779 |
{ |
|
780 |
int size = r.count(); |
|
781 |
if (size > l.count()) |
|
782 |
return false; |
|
783 |
#if defined (Q_OS_WIN) |
|
784 |
Qt::CaseSensitivity cs = Qt::CaseInsensitive; |
|
785 |
#else |
|
786 |
Qt::CaseSensitivity cs = Qt::CaseSensitive; |
|
787 |
#endif |
|
788 |
int i = 0, j = 0; |
|
789 |
for ( ; i < l.count() && j < r.count(); ++i) { |
|
790 |
if (QDir::toNativeSeparators(l[i]).compare(QDir::toNativeSeparators(r[j]), cs) == 0) { |
|
791 |
++j; |
|
792 |
i = -1; |
|
793 |
} |
|
794 |
} |
|
795 |
return j == r.count(); |
|
796 |
} |
|
797 |
||
798 |
#define QT_TST_QAPP_DEBUG |
|
799 |
void tst_QApplication::libraryPaths() |
|
800 |
{ |
|
801 |
{ |
|
802 |
#ifndef Q_OS_WINCE |
|
803 |
QString testDir = QDir::current().canonicalPath() + "/test"; |
|
804 |
#else |
|
805 |
// On Windows CE we need QApplication object to have valid |
|
806 |
// current Path. Therefore we need to identify it ourselves |
|
807 |
// here for the test. |
|
808 |
QFileInfo filePath; |
|
809 |
wchar_t module_name[MAX_PATH]; |
|
810 |
GetModuleFileName(0, module_name, MAX_PATH); |
|
811 |
filePath = QString::fromWCharArray(module_name); |
|
812 |
QString testDir = filePath.path() + "/test"; |
|
813 |
#endif |
|
814 |
QApplication::setLibraryPaths(QStringList() << testDir); |
|
815 |
QCOMPARE(QApplication::libraryPaths(), (QStringList() << testDir)); |
|
816 |
||
817 |
// creating QApplication adds the applicationDirPath to the libraryPath |
|
818 |
int argc = 1; |
|
819 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
820 |
QString appDirPath = QDir(app.applicationDirPath()).canonicalPath(); |
|
821 |
||
822 |
QStringList actual = QApplication::libraryPaths(); |
|
823 |
actual.sort(); |
|
824 |
QStringList expected = QSet<QString>::fromList((QStringList() << testDir << appDirPath)).toList(); |
|
825 |
expected.sort(); |
|
826 |
||
827 |
QVERIFY2(isPathListIncluded(actual, expected), |
|
828 |
qPrintable("actual:\n - " + actual.join("\n - ") + |
|
829 |
"\nexpected:\n - " + expected.join("\n - "))); |
|
830 |
} |
|
831 |
{ |
|
832 |
// creating QApplication adds the applicationDirPath and plugin install path to the libraryPath |
|
833 |
int argc = 1; |
|
834 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
835 |
QString appDirPath = app.applicationDirPath(); |
|
836 |
QString installPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath); |
|
837 |
||
838 |
QStringList actual = QApplication::libraryPaths(); |
|
839 |
actual.sort(); |
|
840 |
||
841 |
#if defined(Q_OS_SYMBIAN) |
|
842 |
QStringList expected; |
|
843 |
addExpectedSymbianPluginsPath(expected); |
|
844 |
expected << appDirPath; |
|
845 |
#else |
|
846 |
QStringList expected = QSet<QString>::fromList((QStringList() << installPathPlugins << appDirPath)).toList(); |
|
847 |
#endif |
|
848 |
expected.sort(); |
|
849 |
||
850 |
QVERIFY2(isPathListIncluded(actual, expected), |
|
851 |
qPrintable("actual:\n - " + actual.join("\n - ") + |
|
852 |
"\nexpected:\n - " + expected.join("\n - "))); |
|
853 |
||
854 |
// setting the library paths overrides everything |
|
855 |
QString testDir = QDir::currentPath() + "/test"; |
|
856 |
QApplication::setLibraryPaths(QStringList() << testDir); |
|
857 |
QVERIFY2(isPathListIncluded(QApplication::libraryPaths(), (QStringList() << testDir)), |
|
858 |
qPrintable("actual:\n - " + QApplication::libraryPaths().join("\n - ") + |
|
859 |
"\nexpected:\n - " + testDir)); |
|
860 |
} |
|
861 |
{ |
|
862 |
#ifdef QT_TST_QAPP_DEBUG |
|
863 |
qDebug() << "Initial library path:" << QApplication::libraryPaths(); |
|
864 |
#endif |
|
865 |
||
866 |
int count = QApplication::libraryPaths().count(); |
|
867 |
#if 0 |
|
868 |
// this test doesn't work if KDE 4 is installed |
|
869 |
QCOMPARE(count, 1); // before creating QApplication, only the PluginsPath is in the libraryPaths() |
|
870 |
#endif |
|
871 |
QString installPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath); |
|
872 |
QApplication::addLibraryPath(installPathPlugins); |
|
873 |
#ifdef QT_TST_QAPP_DEBUG |
|
874 |
qDebug() << "installPathPlugins" << installPathPlugins; |
|
875 |
qDebug() << "After adding plugins path:" << QApplication::libraryPaths(); |
|
876 |
#endif |
|
877 |
QCOMPARE(QApplication::libraryPaths().count(), count); |
|
878 |
||
879 |
QApplication::addLibraryPath(QDir::currentPath() + "/test"); |
|
880 |
QCOMPARE(QApplication::libraryPaths().count(), count + 1); |
|
881 |
||
882 |
// creating QApplication adds the applicationDirPath to the libraryPath |
|
883 |
int argc = 1; |
|
884 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
885 |
QString appDirPath = app.applicationDirPath(); |
|
886 |
qDebug() << QApplication::libraryPaths(); |
|
887 |
// On Windows CE these are identical and might also be the case for other |
|
888 |
// systems too |
|
889 |
if (appDirPath != installPathPlugins) |
|
890 |
QCOMPARE(QApplication::libraryPaths().count(), count + 2); |
|
891 |
} |
|
892 |
{ |
|
893 |
int argc = 1; |
|
894 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
895 |
||
896 |
#ifdef QT_TST_QAPP_DEBUG |
|
897 |
qDebug() << "Initial library path:" << app.libraryPaths(); |
|
898 |
#endif |
|
899 |
int count = app.libraryPaths().count(); |
|
900 |
QString installPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath); |
|
901 |
app.addLibraryPath(installPathPlugins); |
|
902 |
#ifdef QT_TST_QAPP_DEBUG |
|
903 |
qDebug() << "installPathPlugins" << installPathPlugins; |
|
904 |
qDebug() << "After adding plugins path:" << app.libraryPaths(); |
|
905 |
#endif |
|
906 |
QCOMPARE(app.libraryPaths().count(), count); |
|
907 |
||
908 |
QString appDirPath = app.applicationDirPath(); |
|
909 |
||
910 |
app.addLibraryPath(appDirPath); |
|
911 |
#ifdef Q_OS_WINCE |
|
912 |
app.addLibraryPath(appDirPath + "/../.."); |
|
913 |
#else |
|
914 |
app.addLibraryPath(appDirPath + "/.."); |
|
915 |
#endif |
|
916 |
#ifdef QT_TST_QAPP_DEBUG |
|
917 |
qDebug() << "appDirPath" << appDirPath; |
|
918 |
qDebug() << "After adding appDirPath && appDirPath + /..:" << app.libraryPaths(); |
|
919 |
#endif |
|
920 |
QCOMPARE(app.libraryPaths().count(), count + 1); |
|
921 |
#ifdef Q_OS_MAC |
|
922 |
app.addLibraryPath(appDirPath + "/../MacOS"); |
|
923 |
#else |
|
924 |
app.addLibraryPath(appDirPath + "/tmp/.."); |
|
925 |
#endif |
|
926 |
#ifdef QT_TST_QAPP_DEBUG |
|
927 |
qDebug() << "After adding appDirPath + /tmp/..:" << app.libraryPaths(); |
|
928 |
#endif |
|
929 |
QCOMPARE(app.libraryPaths().count(), count + 1); |
|
930 |
} |
|
931 |
} |
|
932 |
||
933 |
void tst_QApplication::libraryPaths_qt_plugin_path() |
|
934 |
{ |
|
935 |
int argc = 1; |
|
936 |
||
937 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
938 |
QString appDirPath = app.applicationDirPath(); |
|
939 |
||
940 |
// Our hook into libraryPaths() initialization: Set the QT_PLUGIN_PATH environment variable |
|
941 |
QString installPathPluginsDeCanon = appDirPath + QString::fromLatin1("/tmp/.."); |
|
942 |
QByteArray ascii = installPathPluginsDeCanon.toAscii(); |
|
943 |
qputenv("QT_PLUGIN_PATH", ascii); |
|
944 |
||
945 |
QVERIFY(!app.libraryPaths().contains(appDirPath + QString::fromLatin1("/tmp/.."))); |
|
946 |
} |
|
947 |
||
948 |
void tst_QApplication::libraryPaths_qt_plugin_path_2() |
|
949 |
{ |
|
950 |
#ifdef Q_OS_SYMBIAN |
|
951 |
QByteArray validPath = "C:\\data"; |
|
952 |
QByteArray nonExistentPath = "Z:\\nonexistent"; |
|
953 |
QByteArray pluginPath = validPath + ";" + nonExistentPath; |
|
954 |
#elif defined(Q_OS_UNIX) |
|
955 |
QByteArray validPath = QDir("/tmp").canonicalPath().toLatin1(); |
|
956 |
QByteArray nonExistentPath = "/nonexistent"; |
|
957 |
QByteArray pluginPath = validPath + ":" + nonExistentPath; |
|
958 |
#elif defined(Q_OS_WIN) |
|
959 |
# ifdef Q_OS_WINCE |
|
960 |
QByteArray validPath = "/Temp"; |
|
961 |
QByteArray nonExistentPath = "/nonexistent"; |
|
962 |
QByteArray pluginPath = validPath + ";" + nonExistentPath; |
|
963 |
# else |
|
964 |
QByteArray validPath = "C:\\windows"; |
|
965 |
QByteArray nonExistentPath = "Z:\\nonexistent"; |
|
966 |
QByteArray pluginPath = validPath + ";" + nonExistentPath; |
|
967 |
# endif |
|
968 |
#endif |
|
969 |
||
970 |
{ |
|
971 |
// Our hook into libraryPaths() initialization: Set the QT_PLUGIN_PATH environment variable |
|
972 |
qputenv("QT_PLUGIN_PATH", pluginPath); |
|
973 |
||
974 |
int argc = 1; |
|
975 |
||
976 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
977 |
||
978 |
// library path list should contain the default plus the one valid path |
|
979 |
#if defined(Q_OS_SYMBIAN) |
|
980 |
// In Symbian, the PluginsPath doesn't specify the only absolute path; just the dir that can be found on any drive |
|
981 |
QStringList expected; |
|
982 |
addExpectedSymbianPluginsPath(expected); |
|
983 |
expected << QDir(app.applicationDirPath()).canonicalPath() |
|
984 |
<< QDir(QDir::fromNativeSeparators(QString::fromLatin1(validPath))).canonicalPath(); |
|
985 |
#else |
|
986 |
QStringList expected = |
|
987 |
QStringList() |
|
988 |
<< QLibraryInfo::location(QLibraryInfo::PluginsPath) |
|
989 |
<< QDir(app.applicationDirPath()).canonicalPath() |
|
990 |
<< QDir(QDir::fromNativeSeparators(QString::fromLatin1(validPath))).canonicalPath(); |
|
991 |
# ifdef Q_OS_WINCE |
|
992 |
expected = QSet<QString>::fromList(expected).toList(); |
|
993 |
# endif |
|
994 |
#endif |
|
995 |
QVERIFY2(isPathListIncluded(app.libraryPaths(), expected), |
|
996 |
qPrintable("actual:\n - " + app.libraryPaths().join("\n - ") + |
|
997 |
"\nexpected:\n - " + expected.join("\n - "))); |
|
998 |
} |
|
999 |
||
1000 |
{ |
|
1001 |
int argc = 1; |
|
1002 |
||
1003 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
1004 |
||
1005 |
// library paths are initialized by the QApplication, setting |
|
1006 |
// the environment variable here doesn't work |
|
1007 |
qputenv("QT_PLUGIN_PATH", pluginPath); |
|
1008 |
||
1009 |
// library path list should contain the default |
|
1010 |
#if defined(Q_OS_SYMBIAN) |
|
1011 |
QStringList expected; |
|
1012 |
addExpectedSymbianPluginsPath(expected); |
|
1013 |
expected << app.applicationDirPath(); |
|
1014 |
#else |
|
1015 |
QStringList expected = |
|
1016 |
QStringList() |
|
1017 |
<< QLibraryInfo::location(QLibraryInfo::PluginsPath) |
|
1018 |
<< app.applicationDirPath(); |
|
1019 |
# ifdef Q_OS_WINCE |
|
1020 |
expected = QSet<QString>::fromList(expected).toList(); |
|
1021 |
# endif |
|
1022 |
#endif |
|
1023 |
QVERIFY(isPathListIncluded(app.libraryPaths(), expected)); |
|
1024 |
||
1025 |
qputenv("QT_PLUGIN_PATH", QByteArray()); |
|
1026 |
} |
|
1027 |
} |
|
1028 |
||
1029 |
class SendPostedEventsTester : public QObject |
|
1030 |
{ |
|
1031 |
Q_OBJECT |
|
1032 |
public: |
|
1033 |
QList<int> eventSpy; |
|
1034 |
bool event(QEvent *e); |
|
1035 |
private slots: |
|
1036 |
void doTest(); |
|
1037 |
}; |
|
1038 |
||
1039 |
bool SendPostedEventsTester::event(QEvent *e) |
|
1040 |
{ |
|
1041 |
eventSpy.append(e->type()); |
|
1042 |
return QObject::event(e); |
|
1043 |
} |
|
1044 |
||
1045 |
void SendPostedEventsTester::doTest() |
|
1046 |
{ |
|
1047 |
QPointer<SendPostedEventsTester> p = this; |
|
1048 |
QApplication::postEvent(this, new QEvent(QEvent::User)); |
|
1049 |
// DeferredDelete should not be delivered until returning from this function |
|
1050 |
QApplication::postEvent(this, new QEvent(QEvent::DeferredDelete)); |
|
1051 |
||
1052 |
QEventLoop eventLoop; |
|
1053 |
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection); |
|
1054 |
eventLoop.exec(); |
|
1055 |
QVERIFY(p != 0); |
|
1056 |
||
1057 |
QCOMPARE(eventSpy.count(), 2); |
|
1058 |
QCOMPARE(eventSpy.at(0), int(QEvent::MetaCall)); |
|
1059 |
QCOMPARE(eventSpy.at(1), int(QEvent::User)); |
|
1060 |
eventSpy.clear(); |
|
1061 |
} |
|
1062 |
||
1063 |
void tst_QApplication::sendPostedEvents() |
|
1064 |
{ |
|
1065 |
int argc = 0; |
|
1066 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
1067 |
SendPostedEventsTester *tester = new SendPostedEventsTester; |
|
1068 |
QMetaObject::invokeMethod(tester, "doTest", Qt::QueuedConnection); |
|
1069 |
QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection); |
|
1070 |
QPointer<SendPostedEventsTester> p = tester; |
|
1071 |
(void) app.exec(); |
|
1072 |
QVERIFY(p == 0); |
|
1073 |
} |
|
1074 |
||
1075 |
void tst_QApplication::thread() |
|
1076 |
{ |
|
1077 |
QThread *currentThread = QThread::currentThread(); |
|
1078 |
// no app, but still have a valid thread |
|
1079 |
QVERIFY(currentThread != 0); |
|
1080 |
||
1081 |
// the thread should be running and not finished |
|
1082 |
QVERIFY(currentThread->isRunning()); |
|
1083 |
QVERIFY(!currentThread->isFinished()); |
|
1084 |
||
1085 |
// this should probably be in the tst_QObject::thread() test, but |
|
1086 |
// we put it here since we want to make sure that objects created |
|
1087 |
// *before* the QApplication has a thread |
|
1088 |
QObject object; |
|
1089 |
QObject child(&object); |
|
1090 |
QVERIFY(object.thread() == currentThread); |
|
1091 |
QVERIFY(child.thread() == currentThread); |
|
1092 |
||
1093 |
{ |
|
1094 |
int argc = 0; |
|
1095 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
1096 |
||
1097 |
// current thread still valid |
|
1098 |
QVERIFY(QThread::currentThread() != 0); |
|
1099 |
// thread should be the same as before |
|
1100 |
QCOMPARE(QThread::currentThread(), currentThread); |
|
1101 |
||
1102 |
// app's thread should be the current thread |
|
1103 |
QCOMPARE(app.thread(), currentThread); |
|
1104 |
||
1105 |
// the thread should still be running and not finished |
|
1106 |
QVERIFY(currentThread->isRunning()); |
|
1107 |
QVERIFY(!currentThread->isFinished()); |
|
1108 |
||
1109 |
QTestEventLoop::instance().enterLoop(1); |
|
1110 |
} |
|
1111 |
||
1112 |
// app dead, current thread still valid |
|
1113 |
QVERIFY(QThread::currentThread() != 0); |
|
1114 |
QCOMPARE(QThread::currentThread(), currentThread); |
|
1115 |
||
1116 |
// the thread should still be running and not finished |
|
1117 |
QVERIFY(currentThread->isRunning()); |
|
1118 |
QVERIFY(!currentThread->isFinished()); |
|
1119 |
||
1120 |
// should still have a thread |
|
1121 |
QVERIFY(object.thread() == currentThread); |
|
1122 |
QVERIFY(child.thread() == currentThread); |
|
1123 |
||
1124 |
// do the test again, making sure that the thread is the same as |
|
1125 |
// before |
|
1126 |
{ |
|
1127 |
int argc = 0; |
|
1128 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
1129 |
||
1130 |
// current thread still valid |
|
1131 |
QVERIFY(QThread::currentThread() != 0); |
|
1132 |
// thread should be the same as before |
|
1133 |
QCOMPARE(QThread::currentThread(), currentThread); |
|
1134 |
||
1135 |
// app's thread should be the current thread |
|
1136 |
QCOMPARE(app.thread(), currentThread); |
|
1137 |
||
1138 |
// the thread should be running and not finished |
|
1139 |
QVERIFY(currentThread->isRunning()); |
|
1140 |
QVERIFY(!currentThread->isFinished()); |
|
1141 |
||
1142 |
// should still have a thread |
|
1143 |
QVERIFY(object.thread() == currentThread); |
|
1144 |
QVERIFY(child.thread() == currentThread); |
|
1145 |
||
1146 |
QTestEventLoop::instance().enterLoop(1); |
|
1147 |
} |
|
1148 |
||
1149 |
// app dead, current thread still valid |
|
1150 |
QVERIFY(QThread::currentThread() != 0); |
|
1151 |
QCOMPARE(QThread::currentThread(), currentThread); |
|
1152 |
||
1153 |
// the thread should still be running and not finished |
|
1154 |
QVERIFY(currentThread->isRunning()); |
|
1155 |
QVERIFY(!currentThread->isFinished()); |
|
1156 |
||
1157 |
// should still have a thread |
|
1158 |
QVERIFY(object.thread() == currentThread); |
|
1159 |
QVERIFY(child.thread() == currentThread); |
|
1160 |
} |
|
1161 |
||
1162 |
class DeleteLaterWidget : public QWidget |
|
1163 |
{ |
|
1164 |
Q_OBJECT |
|
1165 |
public: |
|
1166 |
DeleteLaterWidget(QApplication *_app, QWidget *parent = 0) |
|
1167 |
: QWidget(parent) { app = _app; child_deleted = false; } |
|
1168 |
||
1169 |
bool child_deleted; |
|
1170 |
QApplication *app; |
|
1171 |
||
1172 |
public slots: |
|
1173 |
void runTest(); |
|
1174 |
void checkDeleteLater(); |
|
1175 |
void childDeleted() { child_deleted = true; } |
|
1176 |
}; |
|
1177 |
||
1178 |
||
1179 |
void DeleteLaterWidget::runTest() |
|
1180 |
{ |
|
1181 |
QObject *stillAlive = qFindChild<QObject*>(this, "deleteLater"); |
|
1182 |
||
1183 |
QWidget *w = new QWidget(this); |
|
1184 |
connect(w, SIGNAL(destroyed()), this, SLOT(childDeleted())); |
|
1185 |
||
1186 |
w->deleteLater(); |
|
1187 |
QVERIFY(!child_deleted); |
|
1188 |
||
1189 |
QDialog dlg; |
|
1190 |
QTimer::singleShot(500, &dlg, SLOT(reject())); |
|
1191 |
dlg.exec(); |
|
1192 |
||
1193 |
QVERIFY(!child_deleted); |
|
1194 |
app->processEvents(); |
|
1195 |
QVERIFY(!child_deleted); |
|
1196 |
||
1197 |
QTimer::singleShot(500, this, SLOT(checkDeleteLater())); |
|
1198 |
||
1199 |
app->processEvents(); |
|
1200 |
||
1201 |
QVERIFY(!stillAlive); // verify at the end to make test terminate |
|
1202 |
} |
|
1203 |
||
1204 |
void DeleteLaterWidget::checkDeleteLater() |
|
1205 |
{ |
|
1206 |
QVERIFY(child_deleted); |
|
1207 |
||
1208 |
close(); |
|
1209 |
} |
|
1210 |
||
1211 |
void tst_QApplication::testDeleteLater() |
|
1212 |
{ |
|
1213 |
int argc = 0; |
|
1214 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
1215 |
connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); |
|
1216 |
||
1217 |
DeleteLaterWidget *wgt = new DeleteLaterWidget(&app); |
|
1218 |
QTimer::singleShot(500, wgt, SLOT(runTest())); |
|
1219 |
||
1220 |
QObject *object = new QObject(wgt); |
|
1221 |
object->setObjectName("deleteLater"); |
|
1222 |
object->deleteLater(); |
|
1223 |
||
1224 |
QObject *stillAlive = qFindChild<QObject*>(wgt, "deleteLater"); |
|
1225 |
QVERIFY(stillAlive); |
|
1226 |
||
1227 |
app.exec(); |
|
1228 |
||
1229 |
delete wgt; |
|
1230 |
||
1231 |
} |
|
1232 |
||
1233 |
class EventLoopNester : public QObject |
|
1234 |
{ |
|
1235 |
Q_OBJECT |
|
1236 |
public slots: |
|
1237 |
void deleteLaterAndEnterLoop() |
|
1238 |
{ |
|
1239 |
QEventLoop eventLoop; |
|
1240 |
QPointer<QObject> p(this); |
|
1241 |
deleteLater(); |
|
1242 |
/* |
|
1243 |
DeferredDelete events are compressed, meaning this second |
|
1244 |
deleteLater() will *not* delete the object in the nested |
|
1245 |
event loop |
|
1246 |
*/ |
|
1247 |
QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection); |
|
1248 |
QTimer::singleShot(1000, &eventLoop, SLOT(quit())); |
|
1249 |
eventLoop.exec(); |
|
1250 |
QVERIFY(p); |
|
1251 |
} |
|
1252 |
void deleteLaterAndExitLoop() |
|
1253 |
{ |
|
1254 |
// Check that 'p' is not deleted before exec returns, since the call |
|
1255 |
// to QEventLoop::quit() should stop 'eventLoop' from processing |
|
1256 |
// any more events (that is, delete later) until we return to the |
|
1257 |
// _current_ event loop: |
|
1258 |
QEventLoop eventLoop; |
|
1259 |
QPointer<QObject> p(this); |
|
1260 |
QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection); |
|
1261 |
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection); |
|
1262 |
eventLoop.exec(); |
|
1263 |
QVERIFY(p); // not dead yet |
|
1264 |
} |
|
1265 |
||
1266 |
void processEventsOnly() |
|
1267 |
{ |
|
1268 |
QApplication::processEvents(); |
|
1269 |
} |
|
1270 |
void processEventsWithDeferredDeletion() |
|
1271 |
{ |
|
1272 |
QApplication::processEvents(QEventLoop::DeferredDeletion); |
|
1273 |
} |
|
1274 |
void sendPostedEventsWithDeferredDelete() |
|
1275 |
{ |
|
1276 |
QApplication::sendPostedEvents(0, QEvent::DeferredDelete); |
|
1277 |
} |
|
1278 |
void deleteLaterAndProcessEvents1() |
|
1279 |
{ |
|
1280 |
QEventLoop eventLoop; |
|
1281 |
||
1282 |
QPointer<QObject> p = this; |
|
1283 |
deleteLater(); |
|
1284 |
||
1285 |
// trying to delete this object in a deeper eventloop just won't work |
|
1286 |
QMetaObject::invokeMethod(this, |
|
1287 |
"processEventsOnly", |
|
1288 |
Qt::QueuedConnection); |
|
1289 |
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection); |
|
1290 |
eventLoop.exec(); |
|
1291 |
QVERIFY(p); |
|
1292 |
QMetaObject::invokeMethod(this, |
|
1293 |
"processEventsWithDeferredDeletion", |
|
1294 |
Qt::QueuedConnection); |
|
1295 |
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection); |
|
1296 |
eventLoop.exec(); |
|
1297 |
QVERIFY(p); |
|
1298 |
QMetaObject::invokeMethod(this, |
|
1299 |
"sendPostedEventsWithDeferredDelete", |
|
1300 |
Qt::QueuedConnection); |
|
1301 |
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection); |
|
1302 |
eventLoop.exec(); |
|
1303 |
QVERIFY(p); |
|
1304 |
||
1305 |
// trying to delete it from this eventloop still doesn't work |
|
1306 |
QApplication::processEvents(); |
|
1307 |
QVERIFY(p); |
|
1308 |
||
1309 |
// however, it *will* work with this magic incantation |
|
1310 |
QApplication::processEvents(QEventLoop::DeferredDeletion); |
|
1311 |
QVERIFY(!p); |
|
1312 |
} |
|
1313 |
||
1314 |
void deleteLaterAndProcessEvents2() |
|
1315 |
{ |
|
1316 |
QEventLoop eventLoop; |
|
1317 |
||
1318 |
QPointer<QObject> p = this; |
|
1319 |
deleteLater(); |
|
1320 |
||
1321 |
// trying to delete this object in a deeper eventloop just won't work |
|
1322 |
QMetaObject::invokeMethod(this, |
|
1323 |
"processEventsOnly", |
|
1324 |
Qt::QueuedConnection); |
|
1325 |
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection); |
|
1326 |
eventLoop.exec(); |
|
1327 |
QVERIFY(p); |
|
1328 |
QMetaObject::invokeMethod(this, |
|
1329 |
"processEventsWithDeferredDeletion", |
|
1330 |
Qt::QueuedConnection); |
|
1331 |
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection); |
|
1332 |
eventLoop.exec(); |
|
1333 |
QVERIFY(p); |
|
1334 |
QMetaObject::invokeMethod(this, |
|
1335 |
"sendPostedEventsWithDeferredDelete", |
|
1336 |
Qt::QueuedConnection); |
|
1337 |
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection); |
|
1338 |
eventLoop.exec(); |
|
1339 |
QVERIFY(p); |
|
1340 |
||
1341 |
// trying to delete it from this eventloop still doesn't work |
|
1342 |
QApplication::processEvents(); |
|
1343 |
QVERIFY(p); |
|
1344 |
||
1345 |
// however, it *will* work with this magic incantation |
|
1346 |
QApplication::sendPostedEvents(0, QEvent::DeferredDelete); |
|
1347 |
QVERIFY(!p); |
|
1348 |
} |
|
1349 |
}; |
|
1350 |
||
1351 |
void tst_QApplication::testDeleteLaterProcessEvents() |
|
1352 |
{ |
|
1353 |
int argc = 0; |
|
1354 |
||
1355 |
// Calling processEvents() with no event dispatcher does nothing. |
|
1356 |
QObject *object = new QObject; |
|
1357 |
QPointer<QObject> p(object); |
|
1358 |
object->deleteLater(); |
|
1359 |
QApplication::processEvents(); |
|
1360 |
QVERIFY(p); |
|
1361 |
delete object; |
|
1362 |
||
1363 |
{ |
|
1364 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
1365 |
// If you call processEvents() with an event dispatcher present, but |
|
1366 |
// outside any event loops, deferred deletes are not processed unless |
|
1367 |
// QEventLoop::DeferredDeletion is passed. |
|
1368 |
object = new QObject; |
|
1369 |
p = object; |
|
1370 |
object->deleteLater(); |
|
1371 |
app.processEvents(); |
|
1372 |
QVERIFY(p); |
|
1373 |
app.processEvents(QEventLoop::ProcessEventsFlag(0x10)); // 0x10 == QEventLoop::DeferredDeletion |
|
1374 |
QVERIFY(!p); |
|
1375 |
||
1376 |
// sendPostedEvents(0, DeferredDelete); also works |
|
1377 |
object = new QObject; |
|
1378 |
p = object; |
|
1379 |
object->deleteLater(); |
|
1380 |
app.processEvents(); |
|
1381 |
QVERIFY(p); |
|
1382 |
QApplication::sendPostedEvents(0, QEvent::DeferredDelete); |
|
1383 |
QVERIFY(!p); |
|
1384 |
||
1385 |
// If you call deleteLater() on an object when there is no parent |
|
1386 |
// event loop, and then enter an event loop, the object will get |
|
1387 |
// deleted. |
|
1388 |
object = new QObject; |
|
1389 |
p = object; |
|
1390 |
object->deleteLater(); |
|
1391 |
QEventLoop loop; |
|
1392 |
QTimer::singleShot(1000, &loop, SLOT(quit())); |
|
1393 |
loop.exec(); |
|
1394 |
QVERIFY(!p); |
|
1395 |
} |
|
1396 |
{ |
|
1397 |
// When an object is in an event loop, then calls deleteLater() and enters |
|
1398 |
// an event loop recursively, it should not die until the parent event |
|
1399 |
// loop continues. |
|
1400 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
1401 |
QEventLoop loop; |
|
1402 |
EventLoopNester *nester = new EventLoopNester; |
|
1403 |
p = nester; |
|
1404 |
QTimer::singleShot(3000, &loop, SLOT(quit())); |
|
1405 |
QTimer::singleShot(0, nester, SLOT(deleteLaterAndEnterLoop())); |
|
1406 |
||
1407 |
loop.exec(); |
|
1408 |
QVERIFY(!p); |
|
1409 |
} |
|
1410 |
||
1411 |
{ |
|
1412 |
// When the event loop that calls deleteLater() is exited |
|
1413 |
// immediately, the object should die when returning to the |
|
1414 |
// parent event loop |
|
1415 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
1416 |
QEventLoop loop; |
|
1417 |
EventLoopNester *nester = new EventLoopNester; |
|
1418 |
p = nester; |
|
1419 |
QTimer::singleShot(3000, &loop, SLOT(quit())); |
|
1420 |
QTimer::singleShot(0, nester, SLOT(deleteLaterAndExitLoop())); |
|
1421 |
||
1422 |
loop.exec(); |
|
1423 |
QVERIFY(!p); |
|
1424 |
} |
|
1425 |
||
1426 |
{ |
|
1427 |
// when the event loop that calls deleteLater() also calls |
|
1428 |
// processEvents() immediately afterwards, the object should |
|
1429 |
// not die until the parent loop continues |
|
1430 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
1431 |
QEventLoop loop; |
|
1432 |
EventLoopNester *nester = new EventLoopNester(); |
|
1433 |
p = nester; |
|
1434 |
QTimer::singleShot(3000, &loop, SLOT(quit())); |
|
1435 |
QTimer::singleShot(0, nester, SLOT(deleteLaterAndProcessEvents1())); |
|
1436 |
||
1437 |
loop.exec(); |
|
1438 |
QVERIFY(!p); |
|
1439 |
} |
|
1440 |
||
1441 |
{ |
|
1442 |
// when the event loop that calls deleteLater() also calls |
|
1443 |
// processEvents() immediately afterwards, the object should |
|
1444 |
// not die until the parent loop continues |
|
1445 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
1446 |
QEventLoop loop; |
|
1447 |
EventLoopNester *nester = new EventLoopNester(); |
|
1448 |
p = nester; |
|
1449 |
QTimer::singleShot(3000, &loop, SLOT(quit())); |
|
1450 |
QTimer::singleShot(0, nester, SLOT(deleteLaterAndProcessEvents2())); |
|
1451 |
||
1452 |
loop.exec(); |
|
1453 |
QVERIFY(!p); |
|
1454 |
} |
|
1455 |
} |
|
1456 |
||
1457 |
/* |
|
1458 |
Test for crash whith QApplication::setDesktopSettingsAware(false). |
|
1459 |
*/ |
|
1460 |
void tst_QApplication::desktopSettingsAware() |
|
1461 |
{ |
|
1462 |
#ifndef QT_NO_PROCESS |
|
1463 |
QProcess testProcess; |
|
1464 |
#ifdef Q_OS_WINCE |
|
1465 |
int argc = 0; |
|
1466 |
QApplication tmpApp(argc, 0, QApplication::GuiServer); |
|
1467 |
testProcess.start("desktopsettingsaware/desktopsettingsaware"); |
|
1468 |
#else |
|
1469 |
#if defined(Q_OS_WIN) && defined(QT_DEBUG) |
|
1470 |
testProcess.start("desktopsettingsaware/debug/desktopsettingsaware"); |
|
1471 |
#elif defined(Q_OS_WIN) |
|
1472 |
testProcess.start("desktopsettingsaware/release/desktopsettingsaware"); |
|
1473 |
#elif defined(Q_OS_SYMBIAN) |
|
1474 |
testProcess.start("desktopsettingsaware"); |
|
1475 |
#if defined(Q_CC_NOKIAX86) |
|
1476 |
QEXPECT_FAIL("", "QProcess on Q_CC_NOKIAX86 cannot launch another Qt application, due to DLL conflicts.", Abort); |
|
1477 |
// TODO: Remove XFAIL, as soon as we can launch Qt applications from within Qt applications on Symbian |
|
1478 |
QVERIFY(testProcess.error() != QProcess::FailedToStart); |
|
1479 |
#endif // defined(Q_CC_NOKIAX86) |
|
1480 |
#else |
|
1481 |
testProcess.start("desktopsettingsaware/desktopsettingsaware"); |
|
1482 |
#endif |
|
1483 |
#endif |
|
1484 |
QVERIFY(testProcess.waitForFinished(10000)); |
|
1485 |
QCOMPARE(int(testProcess.state()), int(QProcess::NotRunning)); |
|
1486 |
QVERIFY(int(testProcess.error()) != int(QProcess::Crashed)); |
|
1487 |
#endif |
|
1488 |
} |
|
1489 |
||
1490 |
void tst_QApplication::setActiveWindow() |
|
1491 |
{ |
|
1492 |
int argc = 0; |
|
1493 |
QApplication MyApp(argc, 0, QApplication::GuiServer); |
|
1494 |
||
1495 |
QWidget* w = new QWidget; |
|
1496 |
QVBoxLayout* layout = new QVBoxLayout(w); |
|
1497 |
||
1498 |
QLineEdit* pb1 = new QLineEdit("Testbutton1", w); |
|
1499 |
QLineEdit* pb2 = new QLineEdit("Test Line Edit", w); |
|
1500 |
||
1501 |
layout->addWidget(pb1); |
|
1502 |
layout->addWidget(pb2); |
|
1503 |
||
1504 |
pb2->setFocus(); |
|
1505 |
pb2->setParent(0); |
|
1506 |
delete pb2; |
|
1507 |
||
1508 |
w->show(); |
|
1509 |
QApplication::setActiveWindow(w); // needs this on twm (focus follows mouse) |
|
1510 |
QVERIFY(pb1->hasFocus()); |
|
1511 |
delete w; |
|
1512 |
} |
|
1513 |
||
1514 |
||
1515 |
/* This might fail on some X11 window managers? */ |
|
1516 |
void tst_QApplication::focusChanged() |
|
1517 |
{ |
|
1518 |
int argc = 0; |
|
1519 |
QApplication app(argc, 0, QApplication::GuiServer); |
|
1520 |
||
1521 |
QSignalSpy spy(&app, SIGNAL(focusChanged(QWidget *, QWidget *))); |
|
1522 |
QWidget *now = 0; |
|
1523 |
QWidget *old = 0; |
|
1524 |
||
1525 |
QWidget parent1; |
|
1526 |
QHBoxLayout hbox1(&parent1); |
|
1527 |
QLabel lb1(&parent1); |
|
1528 |
QLineEdit le1(&parent1); |
|
1529 |
QPushButton pb1(&parent1); |
|
1530 |
hbox1.addWidget(&lb1); |
|
1531 |
hbox1.addWidget(&le1); |
|
1532 |
hbox1.addWidget(&pb1); |
|
1533 |
||
1534 |
QCOMPARE(spy.count(), 0); |
|
1535 |
||
1536 |
parent1.show(); |
|
1537 |
QApplication::setActiveWindow(&parent1); // needs this on twm (focus follows mouse) |
|
1538 |
QCOMPARE(spy.count(), 1); |
|
1539 |
QCOMPARE(spy.at(0).count(), 2); |
|
1540 |
old = qVariantValue<QWidget*>(spy.at(0).at(0)); |
|
1541 |
now = qVariantValue<QWidget*>(spy.at(0).at(1)); |
|
1542 |
QVERIFY(now == &le1); |
|
1543 |
QVERIFY(now == QApplication::focusWidget()); |
|
1544 |
QVERIFY(old == 0); |
|
1545 |
spy.clear(); |
|
1546 |
QCOMPARE(spy.count(), 0); |
|
1547 |
||
1548 |
pb1.setFocus(); |
|
1549 |
QCOMPARE(spy.count(), 1); |
|
1550 |
old = qVariantValue<QWidget*>(spy.at(0).at(0)); |
|
1551 |
now = qVariantValue<QWidget*>(spy.at(0).at(1)); |
|
1552 |
QVERIFY(now == &pb1); |
|
1553 |
QVERIFY(now == QApplication::focusWidget()); |
|
1554 |
QVERIFY(old == &le1); |
|
1555 |
spy.clear(); |
|
1556 |
||
1557 |
lb1.setFocus(); |
|
1558 |
QCOMPARE(spy.count(), 1); |
|
1559 |
old = qVariantValue<QWidget*>(spy.at(0).at(0)); |
|
1560 |
now = qVariantValue<QWidget*>(spy.at(0).at(1)); |
|
1561 |
QVERIFY(now == &lb1); |
|
1562 |
QVERIFY(now == QApplication::focusWidget()); |
|
1563 |
QVERIFY(old == &pb1); |
|
1564 |
spy.clear(); |
|
1565 |
||
1566 |
lb1.clearFocus(); |
|
1567 |
QCOMPARE(spy.count(), 1); |
|
1568 |
old = qVariantValue<QWidget*>(spy.at(0).at(0)); |
|
1569 |
now = qVariantValue<QWidget*>(spy.at(0).at(1)); |
|
1570 |
QVERIFY(now == 0); |
|
1571 |
QVERIFY(now == QApplication::focusWidget()); |
|
1572 |
QVERIFY(old == &lb1); |
|
1573 |
spy.clear(); |
|
1574 |
||
1575 |
QWidget parent2; |
|
1576 |
QHBoxLayout hbox2(&parent2); |
|
1577 |
QLabel lb2(&parent2); |
|
1578 |
QLineEdit le2(&parent2); |
|
1579 |
QPushButton pb2(&parent2); |
|
1580 |
hbox2.addWidget(&lb2); |
|
1581 |
hbox2.addWidget(&le2); |
|
1582 |
hbox2.addWidget(&pb2); |
|
1583 |
||
1584 |
parent2.show(); |
|
1585 |
QApplication::setActiveWindow(&parent2); // needs this on twm (focus follows mouse) |
|
1586 |
QVERIFY(spy.count() > 0); // one for deactivation, one for activation on Windows |
|
1587 |
old = qVariantValue<QWidget*>(spy.at(spy.count()-1).at(0)); |
|
1588 |
now = qVariantValue<QWidget*>(spy.at(spy.count()-1).at(1)); |
|
1589 |
QVERIFY(now == &le2); |
|
1590 |
QVERIFY(now == QApplication::focusWidget()); |
|
1591 |
QVERIFY(old == 0); |
|
1592 |
spy.clear(); |
|
1593 |
||
1594 |
QTestKeyEvent tab(QTest::Press, Qt::Key_Tab, 0, 0); |
|
1595 |
QTestKeyEvent backtab(QTest::Press, Qt::Key_Backtab, 0, 0); |
|
1596 |
QTestMouseEvent click(QTest::MouseClick, Qt::LeftButton, 0, QPoint(5, 5), 0); |
|
1597 |
||
1598 |
bool tabAllControls = true; |
|
1599 |
#ifdef Q_WS_MAC |
|
1600 |
// Mac has two modes, one where you tab to everything, one where you can |
|
1601 |
// only tab to input controls, here's what we get. Determine which ones we |
|
1602 |
// should get. |
|
1603 |
QSettings appleSettings(QLatin1String("apple.com")); |
|
1604 |
QVariant appleValue = appleSettings.value(QLatin1String("AppleKeyboardUIMode"), 0); |
|
1605 |
tabAllControls = (appleValue.toInt() & 0x2); |
|
1606 |
#endif |
|
1607 |
||
1608 |
tab.simulate(now); |
|
1609 |
if (!tabAllControls) { |
|
1610 |
QVERIFY(spy.count() == 0); |
|
1611 |
QVERIFY(now == QApplication::focusWidget()); |
|
1612 |
} else { |
|
1613 |
QVERIFY(spy.count() > 0); |
|
1614 |
old = qVariantValue<QWidget*>(spy.at(0).at(0)); |
|
1615 |
now = qVariantValue<QWidget*>(spy.at(0).at(1)); |
|
1616 |
QVERIFY(now == &pb2); |
|
1617 |
QVERIFY(now == QApplication::focusWidget()); |
|
1618 |
QVERIFY(old == &le2); |
|
1619 |
spy.clear(); |
|
1620 |
} |
|
1621 |
||
1622 |
if (!tabAllControls) { |
|
1623 |
QVERIFY(spy.count() == 0); |
|
1624 |
QVERIFY(now == QApplication::focusWidget()); |
|
1625 |
} else { |
|
1626 |
tab.simulate(now); |
|
1627 |
QVERIFY(spy.count() > 0); |
|
1628 |
old = qVariantValue<QWidget*>(spy.at(0).at(0)); |
|
1629 |
now = qVariantValue<QWidget*>(spy.at(0).at(1)); |
|
1630 |
QVERIFY(now == &le2); |
|
1631 |
QVERIFY(now == QApplication::focusWidget()); |
|
1632 |
QVERIFY(old == &pb2); |
|
1633 |
spy.clear(); |
|
1634 |
} |
|
1635 |
||
1636 |
if (!tabAllControls) { |
|
1637 |
QVERIFY(spy.count() == 0); |
|
1638 |
QVERIFY(now == QApplication::focusWidget()); |
|
1639 |
} else { |
|
1640 |
backtab.simulate(now); |
|
1641 |
QVERIFY(spy.count() > 0); |
|
1642 |
old = qVariantValue<QWidget*>(spy.at(0).at(0)); |
|
1643 |
now = qVariantValue<QWidget*>(spy.at(0).at(1)); |
|
1644 |
QVERIFY(now == &pb2); |
|
1645 |
QVERIFY(now == QApplication::focusWidget()); |
|
1646 |
QVERIFY(old == &le2); |
|
1647 |
spy.clear(); |
|
1648 |
} |
|
1649 |
||
1650 |
||
1651 |
if (!tabAllControls) { |
|
1652 |
QVERIFY(spy.count() == 0); |
|
1653 |
QVERIFY(now == QApplication::focusWidget()); |
|
1654 |
old = &pb2; |
|
1655 |
} else { |
|
1656 |
backtab.simulate(now); |
|
1657 |
QVERIFY(spy.count() > 0); |
|
1658 |
old = qVariantValue<QWidget*>(spy.at(0).at(0)); |
|
1659 |
now = qVariantValue<QWidget*>(spy.at(0).at(1)); |
|
1660 |
QVERIFY(now == &le2); |
|
1661 |
QVERIFY(now == QApplication::focusWidget()); |
|
1662 |
QVERIFY(old == &pb2); |
|
1663 |
spy.clear(); |
|
1664 |
} |
|
1665 |
||
1666 |
click.simulate(old); |
|
1667 |
if (!(pb2.focusPolicy() & Qt::ClickFocus)) { |
|
1668 |
QVERIFY(spy.count() == 0); |
|
1669 |
QVERIFY(now == QApplication::focusWidget()); |
|
1670 |
} else { |
|
1671 |
QVERIFY(spy.count() > 0); |
|
1672 |
old = qVariantValue<QWidget*>(spy.at(0).at(0)); |
|
1673 |
now = qVariantValue<QWidget*>(spy.at(0).at(1)); |
|
1674 |
QVERIFY(now == &pb2); |
|
1675 |
QVERIFY(now == QApplication::focusWidget()); |
|
1676 |
QVERIFY(old == &le2); |
|
1677 |
spy.clear(); |
|
1678 |
||
1679 |
click.simulate(old); |
|
1680 |
QVERIFY(spy.count() > 0); |
|
1681 |
old = qVariantValue<QWidget*>(spy.at(0).at(0)); |
|
1682 |
now = qVariantValue<QWidget*>(spy.at(0).at(1)); |
|
1683 |
QVERIFY(now == &le2); |
|
1684 |
QVERIFY(now == QApplication::focusWidget()); |
|
1685 |
QVERIFY(old == &pb2); |
|
1686 |
spy.clear(); |
|
1687 |
} |
|
1688 |
||
1689 |
parent1.activateWindow(); |
|
1690 |
QApplication::setActiveWindow(&parent1); // needs this on twm (focus follows mouse) |
|
1691 |
QVERIFY(spy.count() == 1 || spy.count() == 2); // one for deactivation, one for activation on Windows |
|
1692 |
||
1693 |
//on windows, the change of focus is made in 2 steps |
|
1694 |
//(the focusChanged SIGNAL is emitted twice) |
|
1695 |
if (spy.count()==1) |
|
1696 |
old = qVariantValue<QWidget*>(spy.at(spy.count()-1).at(0)); |
|
1697 |
else |
|
1698 |
old = qVariantValue<QWidget*>(spy.at(spy.count()-2).at(0)); |
|
1699 |
now = qVariantValue<QWidget*>(spy.at(spy.count()-1).at(1)); |
|
1700 |
QVERIFY(now == &le1); |
|
1701 |
QVERIFY(now == QApplication::focusWidget()); |
|
1702 |
QVERIFY(old == &le2); |
|
1703 |
spy.clear(); |
|
1704 |
} |
|
1705 |
||
1706 |
class LineEdit : public QLineEdit |
|
1707 |
{ |
|
1708 |
public: |
|
1709 |
LineEdit(QWidget *parent = 0) : QLineEdit(parent) { } |
|
1710 |
||
1711 |
protected: |
|
1712 |
void focusOutEvent(QFocusEvent *e) { |
|
1713 |
QLineEdit::focusOutEvent(e); |
|
1714 |
if (objectName() == "le1") |
|
1715 |
setStyleSheet(""); |
|
1716 |
} |
|
1717 |
||
1718 |
void focusInEvent(QFocusEvent *e) { |
|
1719 |
QLineEdit::focusInEvent(e); |
|
1720 |
if (objectName() == "le2") |
|
1721 |
setStyleSheet(""); |
|
1722 |
} |
|
1723 |
}; |
|
1724 |
||
1725 |
void tst_QApplication::focusOut() |
|
1726 |
{ |
|
1727 |
int argc = 1; |
|
1728 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
1729 |
||
1730 |
// Tests the case where the style pointer changes when on focus in/out |
|
1731 |
// (the above is the case when the stylesheet changes) |
|
1732 |
QWidget w; |
|
1733 |
QLineEdit *le1 = new LineEdit(&w); |
|
1734 |
le1->setObjectName("le1"); |
|
1735 |
le1->setStyleSheet("background: #fee"); |
|
1736 |
le1->setFocus(); |
|
1737 |
||
1738 |
QLineEdit *le2 = new LineEdit(&w); |
|
1739 |
le2->setObjectName("le2"); |
|
1740 |
le2->setStyleSheet("background: #fee"); |
|
1741 |
le2->move(100, 100); |
|
1742 |
w.show(); |
|
1743 |
||
1744 |
QTest::qWait(2000); |
|
1745 |
le2->setFocus(); |
|
1746 |
QTest::qWait(2000); |
|
1747 |
} |
|
1748 |
||
1749 |
void tst_QApplication::execAfterExit() |
|
1750 |
{ |
|
1751 |
int argc = 1; |
|
1752 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
1753 |
QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection); |
|
1754 |
// this should be ignored, as exec() will reset the exitCode |
|
1755 |
QApplication::exit(1); |
|
1756 |
int exitCode = app.exec(); |
|
1757 |
QCOMPARE(exitCode, 0); |
|
1758 |
||
1759 |
// the quitNow flag should have been reset, so we can spin an |
|
1760 |
// eventloop after QApplication::exec() returns |
|
1761 |
QEventLoop eventLoop; |
|
1762 |
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection); |
|
1763 |
exitCode = eventLoop.exec(); |
|
1764 |
QCOMPARE(exitCode, 0); |
|
1765 |
} |
|
1766 |
||
1767 |
void tst_QApplication::wheelScrollLines() |
|
1768 |
{ |
|
1769 |
int argc = 1; |
|
1770 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
1771 |
// If wheelScrollLines returns 0, the mose wheel will be disabled. |
|
1772 |
QVERIFY(app.wheelScrollLines() > 0); |
|
1773 |
} |
|
1774 |
||
1775 |
void tst_QApplication::style() |
|
1776 |
{ |
|
1777 |
int argc = 1; |
|
1778 |
||
1779 |
{ |
|
1780 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
1781 |
QPointer<QStyle> style = app.style(); |
|
1782 |
app.setStyle(new QWindowsStyle); |
|
1783 |
QVERIFY(style.isNull()); |
|
1784 |
} |
|
1785 |
||
1786 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
1787 |
||
1788 |
// qApp style can never be 0 |
|
1789 |
QVERIFY(QApplication::style() != 0); |
|
1790 |
} |
|
1791 |
||
1792 |
void tst_QApplication::allWidgets() |
|
1793 |
{ |
|
1794 |
int argc = 1; |
|
1795 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
1796 |
QWidget *w = new QWidget; |
|
1797 |
QVERIFY(app.allWidgets().contains(w)); // uncreate widget test |
|
1798 |
QVERIFY(app.allWidgets().contains(w)); // created widget test |
|
1799 |
delete w; |
|
1800 |
w = 0; |
|
1801 |
QVERIFY(!app.allWidgets().contains(w)); // removal test |
|
1802 |
} |
|
1803 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1804 |
void tst_QApplication::topLevelWidgets() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1805 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1806 |
int argc = 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1807 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1808 |
QWidget *w = new QWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1809 |
w->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1810 |
#ifndef QT_NO_CLIPBOARD |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1811 |
QClipboard *clipboard = QApplication::clipboard(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1812 |
QString originalText = clipboard->text(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1813 |
clipboard->setText(QString("newText")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1814 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1815 |
app.processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1816 |
QVERIFY(QApplication::topLevelWidgets().contains(w)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1817 |
QCOMPARE(QApplication::topLevelWidgets().count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1818 |
delete w; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1819 |
w = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1820 |
app.processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1821 |
QCOMPARE(QApplication::topLevelWidgets().count(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1822 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1823 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1824 |
|
0 | 1825 |
|
1826 |
void tst_QApplication::setAttribute() |
|
1827 |
{ |
|
1828 |
int argc = 1; |
|
1829 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
1830 |
QVERIFY(!QApplication::testAttribute(Qt::AA_ImmediateWidgetCreation)); |
|
1831 |
QWidget *w = new QWidget; |
|
1832 |
QVERIFY(!w->testAttribute(Qt::WA_WState_Created)); |
|
1833 |
delete w; |
|
1834 |
||
1835 |
QApplication::setAttribute(Qt::AA_ImmediateWidgetCreation); |
|
1836 |
QVERIFY(QApplication::testAttribute(Qt::AA_ImmediateWidgetCreation)); |
|
1837 |
w = new QWidget; |
|
1838 |
QVERIFY(w->testAttribute(Qt::WA_WState_Created)); |
|
1839 |
QWidget *w2 = new QWidget(w); |
|
1840 |
w2->setParent(0); |
|
1841 |
QVERIFY(w2->testAttribute(Qt::WA_WState_Created)); |
|
1842 |
delete w; |
|
1843 |
delete w2; |
|
1844 |
||
1845 |
QApplication::setAttribute(Qt::AA_ImmediateWidgetCreation, false); |
|
1846 |
QVERIFY(!QApplication::testAttribute(Qt::AA_ImmediateWidgetCreation)); |
|
1847 |
w = new QWidget; |
|
1848 |
QVERIFY(!w->testAttribute(Qt::WA_WState_Created)); |
|
1849 |
delete w; |
|
1850 |
} |
|
1851 |
||
1852 |
void tst_QApplication::windowsCommandLine_data() |
|
1853 |
{ |
|
1854 |
#if defined(Q_OS_WIN) |
|
1855 |
QTest::addColumn<QString>("args"); |
|
1856 |
QTest::addColumn<QString>("expected"); |
|
1857 |
||
1858 |
QTest::newRow("hello world") |
|
1859 |
<< QString("Hello \"World\"") |
|
1860 |
<< QString("Hello \"World\""); |
|
1861 |
QTest::newRow("sql") |
|
1862 |
<< QString("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'PNR' AND TABLE_TYPE = 'VIEW' ORDER BY TABLE_NAME") |
|
1863 |
<< QString("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'PNR' AND TABLE_TYPE = 'VIEW' ORDER BY TABLE_NAME"); |
|
1864 |
#endif |
|
1865 |
} |
|
1866 |
||
1867 |
void tst_QApplication::windowsCommandLine() |
|
1868 |
{ |
|
1869 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
1870 |
QFETCH(QString, args); |
|
1871 |
QFETCH(QString, expected); |
|
1872 |
||
1873 |
QProcess testProcess; |
|
1874 |
#if defined(QT_DEBUG) |
|
1875 |
testProcess.start("wincmdline/debug/wincmdline", QStringList(args)); |
|
1876 |
#else |
|
1877 |
testProcess.start("wincmdline/release/wincmdline", QStringList(args)); |
|
1878 |
#endif |
|
1879 |
QVERIFY(testProcess.waitForFinished(10000)); |
|
1880 |
QByteArray error = testProcess.readAllStandardError(); |
|
1881 |
QString procError(error); |
|
1882 |
QCOMPARE(procError, expected); |
|
1883 |
#endif |
|
1884 |
} |
|
1885 |
||
1886 |
class TouchEventPropagationTestWidget : public QWidget |
|
1887 |
{ |
|
1888 |
Q_OBJECT |
|
1889 |
||
1890 |
public: |
|
1891 |
bool seenTouchEvent, acceptTouchEvent, seenMouseEvent, acceptMouseEvent; |
|
1892 |
||
1893 |
TouchEventPropagationTestWidget(QWidget *parent = 0) |
|
1894 |
: QWidget(parent), seenTouchEvent(false), acceptTouchEvent(false), seenMouseEvent(false), acceptMouseEvent(false) |
|
1895 |
{ } |
|
1896 |
||
1897 |
void reset() |
|
1898 |
{ |
|
1899 |
seenTouchEvent = acceptTouchEvent = seenMouseEvent = acceptMouseEvent = false; |
|
1900 |
} |
|
1901 |
||
1902 |
bool event(QEvent *event) |
|
1903 |
{ |
|
1904 |
switch (event->type()) { |
|
1905 |
case QEvent::MouseButtonPress: |
|
1906 |
case QEvent::MouseMove: |
|
1907 |
case QEvent::MouseButtonRelease: |
|
1908 |
// qDebug() << objectName() << "seenMouseEvent = true"; |
|
1909 |
seenMouseEvent = true; |
|
1910 |
event->setAccepted(acceptMouseEvent); |
|
1911 |
break; |
|
1912 |
case QEvent::TouchBegin: |
|
1913 |
case QEvent::TouchUpdate: |
|
1914 |
case QEvent::TouchEnd: |
|
1915 |
// qDebug() << objectName() << "seenTouchEvent = true"; |
|
1916 |
seenTouchEvent = true; |
|
1917 |
event->setAccepted(acceptTouchEvent); |
|
1918 |
break; |
|
1919 |
default: |
|
1920 |
return QWidget::event(event); |
|
1921 |
} |
|
1922 |
return true; |
|
1923 |
} |
|
1924 |
}; |
|
1925 |
||
1926 |
void tst_QApplication::touchEventPropagation() |
|
1927 |
{ |
|
1928 |
int argc = 1; |
|
1929 |
QApplication app(argc, &argv0, QApplication::GuiServer); |
|
1930 |
||
1931 |
QList<QTouchEvent::TouchPoint> pressedTouchPoints; |
|
1932 |
QTouchEvent::TouchPoint press(0); |
|
1933 |
press.setState(Qt::TouchPointPressed); |
|
1934 |
pressedTouchPoints << press; |
|
1935 |
||
1936 |
QList<QTouchEvent::TouchPoint> releasedTouchPoints; |
|
1937 |
QTouchEvent::TouchPoint release(0); |
|
1938 |
release.setState(Qt::TouchPointReleased); |
|
1939 |
releasedTouchPoints << release; |
|
1940 |
||
1941 |
{ |
|
1942 |
// touch event behavior on a window |
|
1943 |
TouchEventPropagationTestWidget window; |
|
1944 |
window.setObjectName("1. window"); |
|
1945 |
||
1946 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); |
|
1947 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); |
|
1948 |
QVERIFY(!window.seenTouchEvent); |
|
1949 |
QVERIFY(!window.seenMouseEvent); |
|
1950 |
||
1951 |
window.reset(); |
|
1952 |
window.setAttribute(Qt::WA_AcceptTouchEvents); |
|
1953 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); |
|
1954 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); |
|
1955 |
QVERIFY(window.seenTouchEvent); |
|
1956 |
QVERIFY(!window.seenMouseEvent); |
|
1957 |
||
1958 |
window.reset(); |
|
1959 |
window.acceptTouchEvent = true; |
|
1960 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); |
|
1961 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); |
|
1962 |
QVERIFY(window.seenTouchEvent); |
|
1963 |
QVERIFY(!window.seenMouseEvent); |
|
1964 |
} |
|
1965 |
||
1966 |
{ |
|
1967 |
// touch event behavior on a window with a child widget |
|
1968 |
TouchEventPropagationTestWidget window; |
|
1969 |
window.setObjectName("2. window"); |
|
1970 |
TouchEventPropagationTestWidget widget(&window); |
|
1971 |
widget.setObjectName("2. widget"); |
|
1972 |
||
1973 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); |
|
1974 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); |
|
1975 |
QVERIFY(!widget.seenTouchEvent); |
|
1976 |
QVERIFY(!widget.seenMouseEvent); |
|
1977 |
QVERIFY(!window.seenTouchEvent); |
|
1978 |
QVERIFY(!window.seenMouseEvent); |
|
1979 |
||
1980 |
window.reset(); |
|
1981 |
widget.reset(); |
|
1982 |
widget.setAttribute(Qt::WA_AcceptTouchEvents); |
|
1983 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); |
|
1984 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); |
|
1985 |
QVERIFY(widget.seenTouchEvent); |
|
1986 |
QVERIFY(!widget.seenMouseEvent); |
|
1987 |
QVERIFY(!window.seenTouchEvent); |
|
1988 |
QVERIFY(!window.seenMouseEvent); |
|
1989 |
||
1990 |
window.reset(); |
|
1991 |
widget.reset(); |
|
1992 |
widget.acceptMouseEvent = true; |
|
1993 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); |
|
1994 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); |
|
1995 |
QVERIFY(widget.seenTouchEvent); |
|
1996 |
QVERIFY(!widget.seenMouseEvent); |
|
1997 |
QVERIFY(!window.seenTouchEvent); |
|
1998 |
QVERIFY(!window.seenMouseEvent); |
|
1999 |
||
2000 |
window.reset(); |
|
2001 |
widget.reset(); |
|
2002 |
widget.acceptTouchEvent = true; |
|
2003 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); |
|
2004 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); |
|
2005 |
QVERIFY(widget.seenTouchEvent); |
|
2006 |
QVERIFY(!widget.seenMouseEvent); |
|
2007 |
QVERIFY(!window.seenTouchEvent); |
|
2008 |
QVERIFY(!window.seenMouseEvent); |
|
2009 |
||
2010 |
window.reset(); |
|
2011 |
widget.reset(); |
|
2012 |
widget.setAttribute(Qt::WA_AcceptTouchEvents, false); |
|
2013 |
window.setAttribute(Qt::WA_AcceptTouchEvents); |
|
2014 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); |
|
2015 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); |
|
2016 |
QVERIFY(!widget.seenTouchEvent); |
|
2017 |
QVERIFY(!widget.seenMouseEvent); |
|
2018 |
QVERIFY(window.seenTouchEvent); |
|
2019 |
QVERIFY(!window.seenMouseEvent); |
|
2020 |
||
2021 |
window.reset(); |
|
2022 |
widget.reset(); |
|
2023 |
window.acceptTouchEvent = true; |
|
2024 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); |
|
2025 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); |
|
2026 |
QVERIFY(!widget.seenTouchEvent); |
|
2027 |
QVERIFY(!widget.seenMouseEvent); |
|
2028 |
QVERIFY(window.seenTouchEvent); |
|
2029 |
QVERIFY(!window.seenMouseEvent); |
|
2030 |
||
2031 |
window.reset(); |
|
2032 |
widget.reset(); |
|
2033 |
widget.acceptMouseEvent = true; // doesn't matter, touch events are propagated first |
|
2034 |
window.acceptTouchEvent = true; |
|
2035 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); |
|
2036 |
qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); |
|
2037 |
QVERIFY(!widget.seenTouchEvent); |
|
2038 |
QVERIFY(!widget.seenMouseEvent); |
|
2039 |
QVERIFY(window.seenTouchEvent); |
|
2040 |
QVERIFY(!window.seenMouseEvent); |
|
2041 |
} |
|
2042 |
} |
|
2043 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2044 |
void tst_QApplication::symbianNoApplicationPanes() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2045 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2046 |
#ifndef Q_OS_SYMBIAN |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2047 |
QSKIP("This is a Symbian only test", SkipAll); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2048 |
#else |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2049 |
QApplication::setAttribute(Qt::AA_S60DontConstructApplicationPanes); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2050 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2051 |
// Run in a block so that QApplication is destroyed before resetting the attribute. |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2052 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2053 |
// Actually I wasn't able to get the forced orientation change to work properly, |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2054 |
// but I'll leave the code here for the future in case we manage to test that |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2055 |
// later. If someone knows how to force an orientation switch in an autotest, do |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2056 |
// feel free to fix this testcase. |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2057 |
int argc = 0; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2058 |
QApplication app(argc, 0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2059 |
QWidget *w; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2060 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2061 |
w = new QWidget; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2062 |
w->show(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2063 |
QT_TRAP_THROWING(static_cast<CAknAppUi *>(CCoeEnv::Static()->AppUi()) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2064 |
->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2065 |
app.processEvents(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2066 |
delete w; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2067 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2068 |
w = new QWidget; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2069 |
w->show(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2070 |
QT_TRAP_THROWING(static_cast<CAknAppUi *>(CCoeEnv::Static()->AppUi()) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2071 |
->SetOrientationL(CAknAppUi::EAppUiOrientationPortrait)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2072 |
app.processEvents(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2073 |
delete w; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2074 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2075 |
w = new QWidget; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2076 |
w->showMaximized(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2077 |
QT_TRAP_THROWING(static_cast<CAknAppUi *>(CCoeEnv::Static()->AppUi()) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2078 |
->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2079 |
app.processEvents(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2080 |
delete w; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2081 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2082 |
w = new QWidget; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2083 |
w->showMaximized(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2084 |
QT_TRAP_THROWING(static_cast<CAknAppUi *>(CCoeEnv::Static()->AppUi()) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2085 |
->SetOrientationL(CAknAppUi::EAppUiOrientationPortrait)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2086 |
app.processEvents(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2087 |
delete w; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2088 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2089 |
w = new QWidget; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2090 |
w->showFullScreen(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2091 |
QT_TRAP_THROWING(static_cast<CAknAppUi *>(CCoeEnv::Static()->AppUi()) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2092 |
->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2093 |
app.processEvents(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2094 |
delete w; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2095 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2096 |
w = new QWidget; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2097 |
w->showFullScreen(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2098 |
QT_TRAP_THROWING(static_cast<CAknAppUi *>(CCoeEnv::Static()->AppUi()) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2099 |
->SetOrientationL(CAknAppUi::EAppUiOrientationPortrait)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2100 |
app.processEvents(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2101 |
delete w; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2102 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2103 |
// These will have no effect, since there is no status pane, but they shouldn't |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2104 |
// crash either. |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2105 |
w = new QWidget; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2106 |
w->show(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2107 |
w->setWindowTitle("Testing title"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2108 |
app.processEvents(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2109 |
delete w; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2110 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2111 |
w = new QWidget; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2112 |
w->show(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2113 |
w->setWindowIcon(QIcon(QPixmap("heart.svg"))); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2114 |
app.processEvents(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2115 |
delete w; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2116 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2117 |
QDesktopWidget desktop; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2118 |
QCOMPARE(desktop.availableGeometry(), desktop.screenGeometry()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2119 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2120 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2121 |
QApplication::setAttribute(Qt::AA_S60DontConstructApplicationPanes, false); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2122 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2123 |
// No other error condition. Program will crash if unsuccessful. |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2124 |
#endif |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2125 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2126 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2127 |
#ifdef Q_OS_SYMBIAN |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2128 |
class CBaseDummy : public CBase |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2129 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2130 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2131 |
CBaseDummy(int *numDestroyed) : numDestroyed(numDestroyed) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2132 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2133 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2134 |
~CBaseDummy() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2135 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2136 |
(*numDestroyed)++; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2137 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2138 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2139 |
private: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2140 |
int *numDestroyed; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2141 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2142 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2143 |
static void fakeMain(int *numDestroyed) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2144 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2145 |
// Push a few objects, just so that the cleanup stack has something to clean up. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2146 |
CleanupStack::PushL(new (ELeave) CBaseDummy(numDestroyed)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2147 |
int argc = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2148 |
QApplication app(argc, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2149 |
CleanupStack::PushL(new (ELeave) CBaseDummy(numDestroyed)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2150 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2151 |
User::Leave(KErrGeneral); // Fake error |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2152 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2153 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2154 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2155 |
void tst_QApplication::symbianNeedForTraps() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2156 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2157 |
#ifndef Q_OS_SYMBIAN |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2158 |
QSKIP("This is a Symbian-only test", SkipAll); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2159 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2160 |
int argc = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2161 |
QApplication app(argc, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2162 |
int numDestroyed = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2163 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2164 |
// This next part should not require a trap. If it does, the test will crash. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2165 |
CleanupStack::PushL(new (ELeave) CBaseDummy(&numDestroyed)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2166 |
CleanupStack::PopAndDestroy(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2167 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2168 |
QCOMPARE(numDestroyed, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2169 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2170 |
// No other failure condition. The program will crash if it does not pass. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2171 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2172 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2173 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2174 |
void tst_QApplication::symbianLeaveThroughMain() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2175 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2176 |
#ifndef Q_OS_SYMBIAN |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2177 |
QSKIP("This is a Symbian-only test", SkipAll); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2178 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2179 |
int numDestroyed = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2180 |
TInt err; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2181 |
TRAP(err, fakeMain(&numDestroyed)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2182 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2183 |
QCOMPARE(numDestroyed, 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2184 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2185 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2186 |
|
0 | 2187 |
//QTEST_APPLESS_MAIN(tst_QApplication) |
2188 |
int main(int argc, char *argv[]) |
|
2189 |
{ |
|
2190 |
tst_QApplication tc; |
|
2191 |
argv0 = argv[0]; |
|
2192 |
return QTest::qExec(&tc, argc, argv); |
|
2193 |
} |
|
2194 |
||
2195 |
#include "tst_qapplication.moc" |