tst_QApplication::testDeleteLaterProcessEvents(): Split the test

The test can trigger timeouts in COIN, split into subtests.

Change-Id: I1fa5d52422275f89b2858d90c5979632aa7058e2
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Friedemann Kleint 2020-03-31 11:52:19 +02:00
parent d934fd7f54
commit ae653fc08b

View File

@ -93,7 +93,11 @@ private slots:
void quitOnLastWindowClosed();
void closeAllWindows();
void testDeleteLater();
void testDeleteLaterProcessEvents();
void testDeleteLaterProcessEvents1();
void testDeleteLaterProcessEvents2();
void testDeleteLaterProcessEvents3();
void testDeleteLaterProcessEvents4();
void testDeleteLaterProcessEvents5();
#if QT_CONFIG(library)
void libraryPaths();
@ -1333,10 +1337,8 @@ public slots:
}
};
void tst_QApplication::testDeleteLaterProcessEvents()
void tst_QApplication::testDeleteLaterProcessEvents1()
{
int argc = 0;
// Calling processEvents() with no event dispatcher does nothing.
QObject *object = new QObject;
QPointer<QObject> p(object);
@ -1344,14 +1346,17 @@ void tst_QApplication::testDeleteLaterProcessEvents()
QApplication::processEvents();
QVERIFY(p);
delete object;
}
void tst_QApplication::testDeleteLaterProcessEvents2()
{
int argc = 0;
QApplication app(argc, nullptr);
// If you call processEvents() with an event dispatcher present, but
// outside any event loops, deferred deletes are not processed unless
// sendPostedEvents(0, DeferredDelete) is called.
object = new QObject;
p = object;
auto object = new QObject;
QPointer<QObject> p(object);
object->deleteLater();
QCoreApplication::processEvents();
QVERIFY(p);
@ -1369,14 +1374,17 @@ void tst_QApplication::testDeleteLaterProcessEvents()
loop.exec();
QVERIFY(!p);
}
void tst_QApplication::testDeleteLaterProcessEvents3()
{
int argc = 0;
// When an object is in an event loop, then calls deleteLater() and enters
// an event loop recursively, it should not die until the parent event
// loop continues.
QApplication app(argc, nullptr);
QEventLoop loop;
EventLoopNester *nester = new EventLoopNester;
p = nester;
QPointer<QObject> p(nester);
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndEnterLoop);
@ -1384,14 +1392,16 @@ void tst_QApplication::testDeleteLaterProcessEvents()
QVERIFY(!p);
}
void tst_QApplication::testDeleteLaterProcessEvents4()
{
int argc = 0;
// When the event loop that calls deleteLater() is exited
// immediately, the object should die when returning to the
// parent event loop
QApplication app(argc, nullptr);
QEventLoop loop;
EventLoopNester *nester = new EventLoopNester;
p = nester;
QPointer<QObject> p(nester);
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndExitLoop);
@ -1399,21 +1409,22 @@ void tst_QApplication::testDeleteLaterProcessEvents()
QVERIFY(!p);
}
void tst_QApplication::testDeleteLaterProcessEvents5()
{
// when the event loop that calls deleteLater() also calls
// processEvents() immediately afterwards, the object should
// not die until the parent loop continues
int argc = 0;
QApplication app(argc, nullptr);
QEventLoop loop;
EventLoopNester *nester = new EventLoopNester();
p = nester;
QPointer<QObject> p(nester);
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndProcessEvents);
loop.exec();
QVERIFY(!p);
}
}
/*
Test for crash with QApplication::setDesktopSettingsAware(false).