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:
parent
d934fd7f54
commit
ae653fc08b
@ -93,7 +93,11 @@ private slots:
|
|||||||
void quitOnLastWindowClosed();
|
void quitOnLastWindowClosed();
|
||||||
void closeAllWindows();
|
void closeAllWindows();
|
||||||
void testDeleteLater();
|
void testDeleteLater();
|
||||||
void testDeleteLaterProcessEvents();
|
void testDeleteLaterProcessEvents1();
|
||||||
|
void testDeleteLaterProcessEvents2();
|
||||||
|
void testDeleteLaterProcessEvents3();
|
||||||
|
void testDeleteLaterProcessEvents4();
|
||||||
|
void testDeleteLaterProcessEvents5();
|
||||||
|
|
||||||
#if QT_CONFIG(library)
|
#if QT_CONFIG(library)
|
||||||
void libraryPaths();
|
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.
|
// Calling processEvents() with no event dispatcher does nothing.
|
||||||
QObject *object = new QObject;
|
QObject *object = new QObject;
|
||||||
QPointer<QObject> p(object);
|
QPointer<QObject> p(object);
|
||||||
@ -1344,75 +1346,84 @@ void tst_QApplication::testDeleteLaterProcessEvents()
|
|||||||
QApplication::processEvents();
|
QApplication::processEvents();
|
||||||
QVERIFY(p);
|
QVERIFY(p);
|
||||||
delete object;
|
delete object;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
void tst_QApplication::testDeleteLaterProcessEvents2()
|
||||||
QApplication app(argc, nullptr);
|
{
|
||||||
// If you call processEvents() with an event dispatcher present, but
|
int argc = 0;
|
||||||
// outside any event loops, deferred deletes are not processed unless
|
QApplication app(argc, nullptr);
|
||||||
// sendPostedEvents(0, DeferredDelete) is called.
|
// If you call processEvents() with an event dispatcher present, but
|
||||||
object = new QObject;
|
// outside any event loops, deferred deletes are not processed unless
|
||||||
p = object;
|
// sendPostedEvents(0, DeferredDelete) is called.
|
||||||
object->deleteLater();
|
auto object = new QObject;
|
||||||
QCoreApplication::processEvents();
|
QPointer<QObject> p(object);
|
||||||
QVERIFY(p);
|
object->deleteLater();
|
||||||
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
|
QCoreApplication::processEvents();
|
||||||
QVERIFY(!p);
|
QVERIFY(p);
|
||||||
|
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
|
||||||
|
QVERIFY(!p);
|
||||||
|
|
||||||
// If you call deleteLater() on an object when there is no parent
|
// If you call deleteLater() on an object when there is no parent
|
||||||
// event loop, and then enter an event loop, the object will get
|
// event loop, and then enter an event loop, the object will get
|
||||||
// deleted.
|
// deleted.
|
||||||
object = new QObject;
|
object = new QObject;
|
||||||
p = object;
|
p = object;
|
||||||
object->deleteLater();
|
object->deleteLater();
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QTimer::singleShot(1000, &loop, &QEventLoop::quit);
|
QTimer::singleShot(1000, &loop, &QEventLoop::quit);
|
||||||
loop.exec();
|
loop.exec();
|
||||||
QVERIFY(!p);
|
QVERIFY(!p);
|
||||||
}
|
}
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
|
|
||||||
QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndEnterLoop);
|
|
||||||
|
|
||||||
loop.exec();
|
void tst_QApplication::testDeleteLaterProcessEvents3()
|
||||||
QVERIFY(!p);
|
{
|
||||||
}
|
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;
|
||||||
|
QPointer<QObject> p(nester);
|
||||||
|
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
|
||||||
|
QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndEnterLoop);
|
||||||
|
|
||||||
{
|
loop.exec();
|
||||||
// When the event loop that calls deleteLater() is exited
|
QVERIFY(!p);
|
||||||
// immediately, the object should die when returning to the
|
}
|
||||||
// parent event loop
|
|
||||||
QApplication app(argc, nullptr);
|
|
||||||
QEventLoop loop;
|
|
||||||
EventLoopNester *nester = new EventLoopNester;
|
|
||||||
p = nester;
|
|
||||||
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
|
|
||||||
QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndExitLoop);
|
|
||||||
|
|
||||||
loop.exec();
|
void tst_QApplication::testDeleteLaterProcessEvents4()
|
||||||
QVERIFY(!p);
|
{
|
||||||
}
|
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;
|
||||||
|
QPointer<QObject> p(nester);
|
||||||
|
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
|
||||||
|
QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndExitLoop);
|
||||||
|
|
||||||
{
|
loop.exec();
|
||||||
// when the event loop that calls deleteLater() also calls
|
QVERIFY(!p);
|
||||||
// processEvents() immediately afterwards, the object should
|
}
|
||||||
// not die until the parent loop continues
|
|
||||||
QApplication app(argc, nullptr);
|
|
||||||
QEventLoop loop;
|
|
||||||
EventLoopNester *nester = new EventLoopNester();
|
|
||||||
p = nester;
|
|
||||||
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
|
|
||||||
QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndProcessEvents);
|
|
||||||
|
|
||||||
loop.exec();
|
void tst_QApplication::testDeleteLaterProcessEvents5()
|
||||||
QVERIFY(!p);
|
{
|
||||||
}
|
// 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();
|
||||||
|
QPointer<QObject> p(nester);
|
||||||
|
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
|
||||||
|
QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndProcessEvents);
|
||||||
|
|
||||||
|
loop.exec();
|
||||||
|
QVERIFY(!p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user