diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp | 63 | ||||
-rw-r--r-- | tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp | 24 |
2 files changed, 87 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 578ea9f693..372dd65ff4 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -57,6 +57,7 @@ private slots: void changeFocusWindow(); void keyboardModifiers(); void modalWindow(); + void quitOnLastWindowClosed(); }; class DummyWindow : public QWindow @@ -491,5 +492,67 @@ void tst_QGuiApplication::modalWindow() delete window1; } +void tst_QGuiApplication::quitOnLastWindowClosed() +{ + { + int argc = 0; + QGuiApplication app(argc, 0); + + QTimer timer; + timer.setInterval(100); + + QSignalSpy spy(&app, SIGNAL(aboutToQuit())); + QSignalSpy spy2(&timer, SIGNAL(timeout())); + + QPointer<QWindow> mainWindow = new QWindow; + QPointer<QWindow> dialog = new QWindow; + + dialog->setTransientParent(mainWindow); + + QVERIFY(app.quitOnLastWindowClosed()); + + mainWindow->show(); + dialog->show(); + + timer.start(); + QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should quit the application + QTimer::singleShot(2000, &app, SLOT(quit())); // This makes sure we quit even if it didn't + + app.exec(); + + QCOMPARE(spy.count(), 1); + QVERIFY(spy2.count() < 15); // Should be around 10 if closing caused the quit + } + { + int argc = 0; + QGuiApplication app(argc, 0); + + QTimer timer; + timer.setInterval(100); + + QSignalSpy spy(&app, SIGNAL(aboutToQuit())); + QSignalSpy spy2(&timer, SIGNAL(timeout())); + + QPointer<QWindow> mainWindow = new QWindow; + QPointer<QWindow> dialog = new QWindow; + + QVERIFY(!dialog->transientParent()); + QVERIFY(app.quitOnLastWindowClosed()); + + mainWindow->show(); + dialog->show(); + + timer.start(); + QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should not quit the application + QTimer::singleShot(2000, &app, SLOT(quit())); + + app.exec(); + + QCOMPARE(spy.count(), 1); + QVERIFY(spy2.count() > 15); // Should be around 20 if closing did not cause the quit + } +} + + QTEST_APPLESS_MAIN(tst_QGuiApplication) #include "tst_qguiapplication.moc" diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 000eea8555..120ed9127c 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -718,6 +718,30 @@ void tst_QApplication::quitOnLastWindowClosed() QCOMPARE(timerSpy.count(), 1); QCOMPARE(appSpy.count(), 2); } + { + int argc = 0; + QApplication app(argc, 0, QApplication::GuiServer); + QVERIFY(app.quitOnLastWindowClosed()); + + QTimer timer; + timer.setInterval(100); + QSignalSpy timerSpy(&timer, SIGNAL(timeout())); + + QWindow w; + w.show(); + + QWidget wid; + wid.show(); + + timer.start(); + QTimer::singleShot(1000, &wid, SLOT(close())); // This should NOT quit the application because the + // QWindow is still there. + QTimer::singleShot(2000, &app, SLOT(quit())); // This causes the quit. + + app.exec(); + + QVERIFY(timerSpy.count() > 15); // Should be around 20 if closing did not caused the quit + } } class PromptOnCloseWidget : public QWidget |