tst_QPromise: QSKIP when !QT_CONFIG(cxx11_future)

Don't just silently succeed.

As a drive-by, keep the skipped code visible to the compiler.
QThread::create() is universally available since
4a5f3c8b930d319ce2ecc802a0868164f18034db, so the skipped code ought to
compile.

Amends ac6a9f9bfae88e21b3e589cc25e4632a69f67a50.

Change-Id: I193ecf802ffbfd103747aa34eb307fb1a814a94e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 4e1b20893aeeb9580bc6b52ac4baea297675bfee)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-10-28 11:10:40 +01:00 committed by Qt Cherry-pick Bot
parent c7771366e5
commit 0ac0ca8124

View File

@ -86,7 +86,6 @@ do { \
QFAIL("Test case " #test "(" #__VA_ARGS__ ") failed"); \ QFAIL("Test case " #test "(" #__VA_ARGS__ ") failed"); \
} while (false) } while (false)
#if QT_CONFIG(cxx11_future)
// std::thread-like wrapper that ensures that the thread is joined at the end of // std::thread-like wrapper that ensures that the thread is joined at the end of
// a scope to prevent potential std::terminate // a scope to prevent potential std::terminate
struct ThreadWrapper struct ThreadWrapper
@ -103,7 +102,6 @@ struct ThreadWrapper
join(); join();
} }
}; };
#endif
struct FutureWatcher struct FutureWatcher
{ {
@ -369,7 +367,9 @@ void tst_QPromise::progress()
void tst_QPromise::addInThread() void tst_QPromise::addInThread()
{ {
#if QT_CONFIG(cxx11_future) #if !QT_CONFIG(cxx11_future)
QSKIP("This test requires C++11 std threading enabled (and working) in the standard library.");
#endif
const auto testAddResult = [] (auto promise, const auto &result) { const auto testAddResult = [] (auto promise, const auto &result) {
promise.start(); promise.start();
auto f = promise.future(); auto f = promise.future();
@ -387,12 +387,13 @@ void tst_QPromise::addInThread()
RUN_TEST_FUNC(testAddResult, QPromise<int>(), 42); RUN_TEST_FUNC(testAddResult, QPromise<int>(), 42);
RUN_TEST_FUNC(testAddResult, QPromise<QString>(), u8"42"); RUN_TEST_FUNC(testAddResult, QPromise<QString>(), u8"42");
RUN_TEST_FUNC(testAddResult, QPromise<CopyOnlyType>(), CopyOnlyType{99}); RUN_TEST_FUNC(testAddResult, QPromise<CopyOnlyType>(), CopyOnlyType{99});
#endif
} }
void tst_QPromise::addInThreadMoveOnlyObject() void tst_QPromise::addInThreadMoveOnlyObject()
{ {
#if QT_CONFIG(cxx11_future) #if !QT_CONFIG(cxx11_future)
QSKIP("This test requires C++11 std threading enabled (and working) in the standard library.");
#endif
QPromise<MoveOnlyType> promise; QPromise<MoveOnlyType> promise;
promise.start(); promise.start();
auto f = promise.future(); auto f = promise.future();
@ -405,12 +406,13 @@ void tst_QPromise::addInThreadMoveOnlyObject()
// Iterators wait for result first // Iterators wait for result first
for (auto& result : f) for (auto& result : f)
QCOMPARE(result, MoveOnlyType{-11}); QCOMPARE(result, MoveOnlyType{-11});
#endif
} }
void tst_QPromise::reportFromMultipleThreads() void tst_QPromise::reportFromMultipleThreads()
{ {
#if QT_CONFIG(cxx11_future) #if !QT_CONFIG(cxx11_future)
QSKIP("This test requires C++11 std threading enabled (and working) in the standard library.");
#endif
QPromise<int> promise; QPromise<int> promise;
auto f = promise.future(); auto f = promise.future();
promise.start(); promise.start();
@ -429,12 +431,13 @@ void tst_QPromise::reportFromMultipleThreads()
QVERIFY(std::find(expected.begin(), expected.end(), actual) != expected.end()); QVERIFY(std::find(expected.begin(), expected.end(), actual) != expected.end());
expected.removeOne(actual); expected.removeOne(actual);
} }
#endif
} }
void tst_QPromise::reportFromMultipleThreadsByMovedPromise() void tst_QPromise::reportFromMultipleThreadsByMovedPromise()
{ {
#if QT_CONFIG(cxx11_future) #if !QT_CONFIG(cxx11_future)
QSKIP("This test requires C++11 std threading enabled (and working) in the standard library.");
#endif
QPromise<int> initialPromise; QPromise<int> initialPromise;
auto f = initialPromise.future(); auto f = initialPromise.future();
{ {
@ -461,12 +464,13 @@ void tst_QPromise::reportFromMultipleThreadsByMovedPromise()
QVERIFY(std::find(expected.begin(), expected.end(), actual) != expected.end()); QVERIFY(std::find(expected.begin(), expected.end(), actual) != expected.end());
expected.removeOne(actual); expected.removeOne(actual);
} }
#endif
} }
void tst_QPromise::doNotCancelWhenFinished() void tst_QPromise::doNotCancelWhenFinished()
{ {
#if QT_CONFIG(cxx11_future) #if !QT_CONFIG(cxx11_future)
QSKIP("This test requires C++11 std threading enabled (and working) in the standard library.");
#endif
const auto testFinishedPromise = [] (auto promise) { const auto testFinishedPromise = [] (auto promise) {
auto f = promise.future(); auto f = promise.future();
promise.start(); promise.start();
@ -485,13 +489,14 @@ void tst_QPromise::doNotCancelWhenFinished()
RUN_TEST_FUNC(testFinishedPromise, QPromise<QString>()); RUN_TEST_FUNC(testFinishedPromise, QPromise<QString>());
RUN_TEST_FUNC(testFinishedPromise, QPromise<CopyOnlyType>()); RUN_TEST_FUNC(testFinishedPromise, QPromise<CopyOnlyType>());
RUN_TEST_FUNC(testFinishedPromise, QPromise<MoveOnlyType>()); RUN_TEST_FUNC(testFinishedPromise, QPromise<MoveOnlyType>());
#endif
} }
#ifndef QT_NO_EXCEPTIONS #ifndef QT_NO_EXCEPTIONS
void tst_QPromise::cancelWhenDestroyed() void tst_QPromise::cancelWhenDestroyed()
{ {
#if QT_CONFIG(cxx11_future) #if !QT_CONFIG(cxx11_future)
QSKIP("This test requires C++11 std threading enabled (and working) in the standard library.");
#endif
QPromise<int> initialPromise; QPromise<int> initialPromise;
auto f = initialPromise.future(); auto f = initialPromise.future();
@ -519,13 +524,14 @@ void tst_QPromise::cancelWhenDestroyed()
QVERIFY(std::find(expected.begin(), expected.end(), actual) != expected.end()); QVERIFY(std::find(expected.begin(), expected.end(), actual) != expected.end());
expected.removeOne(actual); expected.removeOne(actual);
} }
#endif
} }
#endif #endif
void tst_QPromise::cancelWhenReassigned() void tst_QPromise::cancelWhenReassigned()
{ {
#if QT_CONFIG(cxx11_future) #if !QT_CONFIG(cxx11_future)
QSKIP("This test requires C++11 std threading enabled (and working) in the standard library.");
#endif
QPromise<int> promise; QPromise<int> promise;
auto f = promise.future(); auto f = promise.future();
promise.start(); promise.start();
@ -540,7 +546,6 @@ void tst_QPromise::cancelWhenReassigned()
QCOMPARE(f.isFinished(), true); QCOMPARE(f.isFinished(), true);
QCOMPARE(f.isCanceled(), true); QCOMPARE(f.isCanceled(), true);
#endif
} }
template <typename T> template <typename T>
@ -642,7 +647,9 @@ void tst_QPromise::continuationsRunWhenFinished()
void tst_QPromise::finishWhenSwapped() void tst_QPromise::finishWhenSwapped()
{ {
#if QT_CONFIG(cxx11_future) #if !QT_CONFIG(cxx11_future)
QSKIP("This test requires C++11 std threading enabled (and working) in the standard library.");
#endif
QPromise<int> promise1; QPromise<int> promise1;
auto f1 = promise1.future(); auto f1 = promise1.future();
promise1.start(); promise1.start();
@ -677,13 +684,14 @@ void tst_QPromise::finishWhenSwapped()
QCOMPARE(f2.resultAt(0), 1); QCOMPARE(f2.resultAt(0), 1);
QCOMPARE(f2.resultAt(1), 2); QCOMPARE(f2.resultAt(1), 2);
#endif
} }
template <typename T> template <typename T>
void testCancelWhenMoved() void testCancelWhenMoved()
{ {
#if QT_CONFIG(cxx11_future) #if !QT_CONFIG(cxx11_future)
QSKIP("This test requires C++11 std threading enabled (and working) in the standard library.");
#endif
QPromise<T> promise1; QPromise<T> promise1;
auto f1 = promise1.future(); auto f1 = promise1.future();
promise1.start(); promise1.start();
@ -711,7 +719,6 @@ void testCancelWhenMoved()
// Future #2 is explicitly finished inside thread // Future #2 is explicitly finished inside thread
QCOMPARE(f2.isFinished(), true); QCOMPARE(f2.isFinished(), true);
QCOMPARE(f2.isCanceled(), false); QCOMPARE(f2.isCanceled(), false);
#endif
} }
void tst_QPromise::cancelWhenMoved() void tst_QPromise::cancelWhenMoved()
@ -754,7 +761,9 @@ void tst_QPromise::waitUntilResumed()
void tst_QPromise::waitUntilCanceled() void tst_QPromise::waitUntilCanceled()
{ {
#if QT_CONFIG(cxx11_future) #if !QT_CONFIG(cxx11_future)
QSKIP("This test requires C++11 std threading enabled (and working) in the standard library.");
#endif
QPromise<int> promise; QPromise<int> promise;
promise.start(); promise.start();
auto f = promise.future(); auto f = promise.future();
@ -776,7 +785,6 @@ void tst_QPromise::waitUntilCanceled()
f.waitForFinished(); f.waitForFinished();
QCOMPARE(f.resultCount(), 0); QCOMPARE(f.resultCount(), 0);
#endif
} }
// Below is a quick and dirty hack to make snippets a part of a test suite // Below is a quick and dirty hack to make snippets a part of a test suite