6.5.3 clean

This commit is contained in:
kleuter
2023-11-01 18:02:52 +01:00
parent bbe896803b
commit 7018d9e6c8
2170 changed files with 57471 additions and 43550 deletions

View File

@ -3377,17 +3377,6 @@ void tst_QFuture::testFutureTaken(QFuture<T> &noMoreFuture)
{
QCOMPARE(noMoreFuture.isValid(), false);
QCOMPARE(noMoreFuture.resultCount(), 0);
QCOMPARE(noMoreFuture.isStarted(), false);
QCOMPARE(noMoreFuture.isRunning(), false);
QCOMPARE(noMoreFuture.isSuspending(), false);
QCOMPARE(noMoreFuture.isSuspended(), false);
#if QT_DEPRECATED_SINCE(6, 0)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
QCOMPARE(noMoreFuture.isPaused(), false);
QT_WARNING_POP
#endif
QCOMPARE(noMoreFuture.isFinished(), false);
QCOMPARE(noMoreFuture.progressValue(), 0);
}
@ -3806,8 +3795,6 @@ void tst_QFuture::signalConnect()
QSignalSpy spy(sender, &QObject::destroyed);
sender->deleteLater();
// emit the signal when sender is being destroyed
QObject::connect(sender, &QObject::destroyed, [sender] { sender->emitIntArg(42); });
spy.wait();
QVERIFY(future.isCanceled());

View File

@ -13,6 +13,7 @@ class tst_QFutureSynchronizer : public QObject
private Q_SLOTS:
void construction();
void setFutureAliasingExistingMember();
void addFuture();
void cancelOnWait();
void clearFutures();
@ -33,6 +34,38 @@ void tst_QFutureSynchronizer::construction()
QCOMPARE(synchronizerWithFuture.futures().size(), 1);
}
void tst_QFutureSynchronizer::setFutureAliasingExistingMember()
{
//
// GIVEN: a QFutureSynchronizer with one QFuture:
//
QFutureSynchronizer synchronizer(QtFuture::makeReadyFuture(42));
//
// WHEN: calling setFuture() with an alias of the QFuture already in `synchronizer`:
//
for (int i = 0; i < 2; ++i) {
// The next line triggers -Wdangling-reference, but it's a FP because
// of implicit sharing. We cannot keep a copy of synchronizer.futures()
// around to avoid the warning, as the extra copy would cause a detach()
// of m_futures inside setFuture() with the consequence that `f` no longer
// aliases an element in m_futures, which is the goal of this test.
QT_WARNING_PUSH
#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 1301
QT_WARNING_DISABLE_GCC("-Wdangling-reference")
#endif
const auto &f = synchronizer.futures().constFirst();
QT_WARNING_POP
synchronizer.setFuture(f);
}
//
// THEN: it didn't crash
//
QCOMPARE(synchronizer.futures().size(), 1);
QCOMPARE(synchronizer.futures().constFirst().result(), 42);
}
void tst_QFutureSynchronizer::addFuture()
{
QFutureSynchronizer<void> synchronizer;

View File

@ -41,6 +41,8 @@ private slots:
void cancelWhenReassigned();
void cancelWhenDestroyedWithoutStarting();
void cancelWhenDestroyedRunsContinuations();
void cancelWhenDestroyedWithFailureHandler(); // QTBUG-114606
void continuationsRunWhenFinished();
void finishWhenSwapped();
void cancelWhenMoved();
void waitUntilResumed();
@ -256,6 +258,10 @@ void tst_QPromise::setException()
std::make_exception_ptr(TestException()));
RUN_TEST_FUNC(testExceptionCaught, QPromise<int>(),
std::make_exception_ptr(TestException()));
RUN_TEST_FUNC(testExceptionCaught, QPromise<CopyOnlyType>(),
std::make_exception_ptr(TestException()));
RUN_TEST_FUNC(testExceptionCaught, QPromise<MoveOnlyType>(),
std::make_exception_ptr(TestException()));
}
#endif
@ -269,6 +275,8 @@ void tst_QPromise::cancel()
testCancel(QPromise<void>());
testCancel(QPromise<int>());
testCancel(QPromise<CopyOnlyType>());
testCancel(QPromise<MoveOnlyType>());
}
void tst_QPromise::progress()
@ -296,6 +304,8 @@ void tst_QPromise::progress()
RUN_TEST_FUNC(testProgress, QPromise<void>());
RUN_TEST_FUNC(testProgress, QPromise<int>());
RUN_TEST_FUNC(testProgress, QPromise<CopyOnlyType>());
RUN_TEST_FUNC(testProgress, QPromise<MoveOnlyType>());
}
void tst_QPromise::addInThread()
@ -421,6 +431,8 @@ void tst_QPromise::doNotCancelWhenFinished()
RUN_TEST_FUNC(testFinishedPromise, QPromise<void>());
RUN_TEST_FUNC(testFinishedPromise, QPromise<int>());
RUN_TEST_FUNC(testFinishedPromise, QPromise<QString>());
RUN_TEST_FUNC(testFinishedPromise, QPromise<CopyOnlyType>());
RUN_TEST_FUNC(testFinishedPromise, QPromise<MoveOnlyType>());
#endif
}
@ -482,11 +494,12 @@ void tst_QPromise::cancelWhenReassigned()
#endif
}
void tst_QPromise::cancelWhenDestroyedWithoutStarting()
template <typename T>
static inline void testCancelWhenDestroyedWithoutStarting()
{
QFuture<void> future;
QFuture<T> future;
{
QPromise<void> promise;
QPromise<T> promise;
future = promise.future();
}
future.waitForFinished();
@ -495,17 +508,26 @@ void tst_QPromise::cancelWhenDestroyedWithoutStarting()
QVERIFY(future.isFinished());
}
void tst_QPromise::cancelWhenDestroyedRunsContinuations()
void tst_QPromise::cancelWhenDestroyedWithoutStarting()
{
QFuture<void> future;
testCancelWhenDestroyedWithoutStarting<void>();
testCancelWhenDestroyedWithoutStarting<int>();
testCancelWhenDestroyedWithoutStarting<CopyOnlyType>();
testCancelWhenDestroyedWithoutStarting<MoveOnlyType>();
}
template <typename T>
static inline void testCancelWhenDestroyedRunsContinuations()
{
QFuture<T> future;
bool onCanceledCalled = false;
bool thenCalled = false;
{
QPromise<void> promise;
QPromise<T> promise;
future = promise.future();
future.then([&] {
future.then([&] (auto&&) {
thenCalled = true;
}).onCanceled([&] {
}).onCanceled([&] () {
onCanceledCalled = true;
});
}
@ -514,6 +536,74 @@ void tst_QPromise::cancelWhenDestroyedRunsContinuations()
QVERIFY(onCanceledCalled);
}
void tst_QPromise::cancelWhenDestroyedRunsContinuations()
{
testCancelWhenDestroyedRunsContinuations<void>();
testCancelWhenDestroyedRunsContinuations<int>();
testCancelWhenDestroyedRunsContinuations<CopyOnlyType>();
testCancelWhenDestroyedRunsContinuations<MoveOnlyType>();
}
template <typename T>
static inline void testCancelWhenDestroyedWithFailureHandler()
{
QFuture<T> future;
bool onFailedCalled = false;
bool thenCalled = false;
{
QPromise<T> promise;
future = promise.future();
future
.onFailed([&] () {
onFailedCalled = true;
if constexpr (!std::is_same_v<void, T>)
return T{};
})
.then([&] (auto&&) {
thenCalled = true;
});
}
QVERIFY(future.isFinished());
QVERIFY(!onFailedCalled);
QVERIFY(!thenCalled);
}
void tst_QPromise::cancelWhenDestroyedWithFailureHandler()
{
testCancelWhenDestroyedWithFailureHandler<void>();
testCancelWhenDestroyedWithFailureHandler<int>();
testCancelWhenDestroyedWithFailureHandler<CopyOnlyType>();
testCancelWhenDestroyedWithFailureHandler<MoveOnlyType>();
}
template <typename T>
static inline void testContinuationsRunWhenFinished()
{
QPromise<T> promise;
QFuture<T> future = promise.future();
bool thenCalled = false;
future.then([&] (auto&&) {
thenCalled = true;
});
promise.start();
if constexpr (!std::is_void_v<T>) {
promise.addResult(T{});
}
promise.finish();
QVERIFY(thenCalled);
}
void tst_QPromise::continuationsRunWhenFinished()
{
testContinuationsRunWhenFinished<void>();
testContinuationsRunWhenFinished<int>();
testContinuationsRunWhenFinished<CopyOnlyType>();
testContinuationsRunWhenFinished<MoveOnlyType>();
}
void tst_QPromise::finishWhenSwapped()
{
#if !QT_CONFIG(cxx11_future)
@ -556,16 +646,17 @@ void tst_QPromise::finishWhenSwapped()
#endif
}
void tst_QPromise::cancelWhenMoved()
template <typename T>
void testCancelWhenMoved()
{
#if !QT_CONFIG(cxx11_future)
QSKIP("This test requires QThread::create");
#else
QPromise<int> promise1;
QPromise<T> promise1;
auto f1 = promise1.future();
promise1.start();
QPromise<int> promise2;
QPromise<T> promise2;
auto f2 = promise2.future();
promise2.start();
@ -589,6 +680,14 @@ void tst_QPromise::cancelWhenMoved()
#endif
}
void tst_QPromise::cancelWhenMoved()
{
testCancelWhenMoved<void>();
testCancelWhenMoved<int>();
testCancelWhenMoved<CopyOnlyType>();
testCancelWhenMoved<MoveOnlyType>();
}
void tst_QPromise::waitUntilResumed()
{
#if !QT_CONFIG(cxx11_future)