diff options
Diffstat (limited to 'tests/auto/corelib/kernel')
6 files changed, 107 insertions, 16 deletions
diff --git a/tests/auto/corelib/kernel/qobject/.gitignore b/tests/auto/corelib/kernel/qobject/.gitignore index 7970e32c8f..d609065333 100644 --- a/tests/auto/corelib/kernel/qobject/.gitignore +++ b/tests/auto/corelib/kernel/qobject/.gitignore @@ -1,3 +1,7 @@ tst_qobject -signalbug/signalbug -signalbug/signalbug.exe +signalbug_helper +signalbug_helper.exe +debug/signalbug_helper +release/signalbug_helper +debug/signalbug_helper.exe +release/signalbug_helper.exe diff --git a/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro b/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro index cc51b4c661..755fecbd04 100644 --- a/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro +++ b/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro @@ -1,6 +1,15 @@ -CONFIG -= app_bundle debug_and_release +CONFIG -= app_bundle CONFIG += console -DESTDIR = ./ +debug_and_release { + CONFIG(debug, debug|release) { + TARGET = ../../debug/signalbug_helper + } else { + TARGET = ../../release/signalbug_helper + } +} else { + TARGET = ../signalbug_helper +} + QT = core HEADERS += signalbug.h diff --git a/tests/auto/corelib/kernel/qobject/test/test.pro b/tests/auto/corelib/kernel/qobject/test/test.pro index 4e77cb48c5..be15074523 100644 --- a/tests/auto/corelib/kernel/qobject/test/test.pro +++ b/tests/auto/corelib/kernel/qobject/test/test.pro @@ -1,10 +1,29 @@ CONFIG += testcase console -TARGET = ../tst_qobject +debug_and_release { + CONFIG(debug, debug|release) { + TARGET = ../../debug/tst_qobject + } else { + TARGET = ../../release/tst_qobject + } +} else { + TARGET = ../tst_qobject +} + QT = core-private network testlib SOURCES = ../tst_qobject.cpp # Force C++17 if available (needed due to P0012R1) contains(QT_CONFIG, c++1z): CONFIG += c++1z -!winrt: TEST_HELPER_INSTALLS = ../signalbug/signalbug +!winrt { + debug_and_release { + CONFIG(debug, debug|release) { + TEST_HELPER_INSTALLS = ../debug/signalbug_helper + } else { + TEST_HELPER_INSTALLS = ../release/signalbug_helper + } + } else { + TEST_HELPER_INSTALLS = ../signalbug_helper + } +} DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index c734cfe4dd..fdacf83eb2 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -55,7 +55,6 @@ class tst_QObject : public QObject { Q_OBJECT private slots: - void initTestCase(); void disconnect(); void connectSlotsByName(); void connectSignalsToSignalsWithDefaultArguments(); @@ -145,6 +144,7 @@ private slots: void disconnectDoesNotLeakFunctor(); void contextDoesNotLeakFunctor(); void connectBase(); + void connectWarnings(); void qmlConnect(); void exceptions(); void noDeclarativeParentChangedOnDestruction(); @@ -282,14 +282,6 @@ static void playWithObjects() } } -void tst_QObject::initTestCase() -{ -#if QT_CONFIG(process) - const QString testDataDir = QFileInfo(QFINDTESTDATA("signalbug")).absolutePath(); - QVERIFY2(QDir::setCurrent(testDataDir), qPrintable("Could not chdir to " + testDataDir)); -#endif -} - void tst_QObject::disconnect() { SenderObject *s = new SenderObject; @@ -3014,7 +3006,7 @@ void tst_QObject::recursiveSignalEmission() #else QProcess proc; // signalbug helper app should always be next to this test binary - const QString path = QStringLiteral("signalbug/signalbug"); + const QString path = QStringLiteral("signalbug_helper"); proc.start(path); QVERIFY2(proc.waitForStarted(), qPrintable(QString::fromLatin1("Cannot start '%1': %2").arg(path, proc.errorString()))); QVERIFY(proc.waitForFinished()); @@ -6685,6 +6677,26 @@ void tst_QObject::connectBase() QCOMPARE( r1.count_slot3, 1 ); } +void tst_QObject::connectWarnings() +{ + SubSender sub; + SenderObject obj; + ReceiverObject r1; + r1.reset(); + + QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, ReceiverObject): invalid null parameter"); + connect(nullptr, &SubSender::signal1, &r1, &ReceiverObject::slot1); + + QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SubSender, Unknown): invalid null parameter"); + connect(&sub, &SubSender::signal1, nullptr, &ReceiverObject::slot1); + + QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, ReceiverObject): invalid null parameter"); + connect(nullptr, &SenderObject::signal1, &r1, &ReceiverObject::slot1); + + QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, Unknown): invalid null parameter"); + connect(&obj, &SenderObject::signal1, nullptr, &ReceiverObject::slot1); +} + struct QmlReceiver : public QtPrivate::QSlotObjectBase { int callCount; diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 5b2d77a02c..f004ec7856 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -75,6 +75,7 @@ private slots: void dontBlockEvents(); void postedEventsShouldNotStarveTimers(); + void connectTo(); }; void tst_QTimer::zeroTimer() @@ -979,5 +980,30 @@ void tst_QTimer::crossThreadSingleShotToFunctor() delete o; } +void tst_QTimer::connectTo() +{ + QTimer timer; + QSignalSpy timeoutSpy(&timer, &QTimer::timeout); + timer.setInterval(0); + timer.start(); + + auto context = new QObject(); + + int count = 0; + timer.connectTo([&count] { count++; }); + QMetaObject::Connection connection = timer.connectTo(context, [&count] { count++; }); + timer.connectTo(&timer, &QTimer::stop); + + + QTest::qWait(100); + QCOMPARE(count, 2); + QCOMPARE(timeoutSpy.count(), 1); + + // Test that connection is bound to context lifetime + QVERIFY(connection); + delete context; + QVERIFY(!connection); +} + QTEST_MAIN(tst_QTimer) #include "tst_qtimer.moc" diff --git a/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp b/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp index e2a0c2dad3..ac8aaa1327 100644 --- a/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp +++ b/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp @@ -46,6 +46,7 @@ protected slots: private slots: void simple_data(); void simple(); + void blockedWaiting(); void manyNotifiers(); void disableNotifiersInActivatedSlot_data(); void disableNotifiersInActivatedSlot(); @@ -104,6 +105,26 @@ void tst_QWinEventNotifier::simple() QVERIFY(simpleActivated); } +void tst_QWinEventNotifier::blockedWaiting() +{ + simpleHEvent = CreateEvent(0, true, false, 0); + QWinEventNotifier n(simpleHEvent); + QObject::connect(&n, &QWinEventNotifier::activated, + this, &tst_QWinEventNotifier::simple_activated); + simpleActivated = false; + + SetEvent(simpleHEvent); + QCOMPARE(WaitForSingleObject(simpleHEvent, 1000), WAIT_OBJECT_0); + + n.setEnabled(false); + ResetEvent(simpleHEvent); + n.setEnabled(true); + + QTestEventLoop::instance().enterLoop(1); + QVERIFY(QTestEventLoop::instance().timeout()); + QVERIFY(!simpleActivated); +} + class EventWithNotifier : public QObject { Q_OBJECT |