QThread: check various ways users may use start(Priority)

Some of these would break if we changed the start(Priority) to say
start(QThread::Priority) instead.

Manual conflict resolution:
 - added <chrono> include and std:chrono_literals using
   declaration which 6.7 already had in tst_qthread.cpp

Pick-to: 6.2
Task-number: QTBUG-124723
Change-Id: Id3ebe73718c8acbc54a2c88158f4062fd0dd5be1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit cf19105e018314d1fb05bc91959f233d3d6747ba)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit a4c271007743719dc74aa333b37bd1ec78831c94)
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Marc Mutz 2024-04-24 18:06:52 +02:00
parent f51b799fe5
commit 9ea2ff075e

View File

@ -38,6 +38,10 @@
#include <QtTest/private/qemulationdetector_p.h>
#include <chrono>
using namespace std::chrono_literals;
class tst_QThread : public QObject
{
Q_OBJECT
@ -51,6 +55,7 @@ private slots:
void setStackSize();
void exit();
void start();
void startSlotUsedInStringBasedLookups();
void terminate();
void quit();
void started();
@ -462,6 +467,56 @@ void tst_QThread::start()
}
}
class QThreadStarter : public QObject
{
Q_OBJECT
public:
using QObject::QObject;
Q_SIGNALS:
void start(QThread::Priority);
};
class QThreadSelfStarter : public QThread
{
Q_OBJECT
public:
using QThread::QThread;
void check()
{
QVERIFY(connect(this, SIGNAL(starting(Priority)),
this, SLOT(start(Priority))));
QVERIFY(QMetaObject::invokeMethod(this, "start", Q_ARG(Priority, IdlePriority)));
}
Q_SIGNALS:
void starting(Priority);
};
void tst_QThread::startSlotUsedInStringBasedLookups()
{
// QTBUG-124723
QThread thread;
{
QThreadStarter starter;
QVERIFY(QObject::connect(&starter, SIGNAL(start(QThread::Priority)),
&thread, SLOT(start(QThread::Priority))));
}
{
QThreadSelfStarter selfStarter;
selfStarter.check();
if (QTest::currentTestFailed())
return;
selfStarter.exit();
selfStarter.wait(30s);
}
QVERIFY(QMetaObject::invokeMethod(&thread, "start",
Q_ARG(QThread::Priority, QThread::IdlePriority)));
thread.exit();
thread.wait(30s);
}
void tst_QThread::terminate()
{
#if defined(Q_OS_ANDROID)