mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-08 10:29:09 +08:00
qt 6.6.0 clean
This commit is contained in:
@ -14,6 +14,8 @@
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class tst_QPromise : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -22,6 +24,7 @@ private slots:
|
||||
void promise();
|
||||
void futureFromPromise();
|
||||
void addResult();
|
||||
void addResultWithBracedInitializer();
|
||||
void addResultOutOfOrder();
|
||||
#ifndef QT_NO_EXCEPTIONS
|
||||
void setException();
|
||||
@ -170,6 +173,15 @@ void tst_QPromise::addResult()
|
||||
QCOMPARE(f.resultCount(), 3);
|
||||
QCOMPARE(f.resultAt(2), result);
|
||||
}
|
||||
// add multiple results in one go:
|
||||
{
|
||||
QList results = {42, 4242, 424242};
|
||||
QVERIFY(promise.addResults(results));
|
||||
QCOMPARE(f.resultCount(), 6);
|
||||
QCOMPARE(f.resultAt(3), 42);
|
||||
QCOMPARE(f.resultAt(4), 4242);
|
||||
QCOMPARE(f.resultAt(5), 424242);
|
||||
}
|
||||
// add as lvalue at position and overwrite
|
||||
{
|
||||
int result = -1;
|
||||
@ -187,6 +199,28 @@ void tst_QPromise::addResult()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QPromise::addResultWithBracedInitializer() // QTBUG-111826
|
||||
{
|
||||
struct MyClass
|
||||
{
|
||||
QString strValue;
|
||||
int intValue = 0;
|
||||
#ifndef __cpp_aggregate_paren_init // make emplacement work with MyClass
|
||||
MyClass(QString s, int i) : strValue(std::move(s)), intValue(i) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
{
|
||||
QPromise<MyClass> myPromise;
|
||||
myPromise.addResult({"bar", 1});
|
||||
}
|
||||
|
||||
{
|
||||
QPromise<MyClass> myPromise;
|
||||
myPromise.emplaceResult("bar", 1);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QPromise::addResultOutOfOrder()
|
||||
{
|
||||
// Compare results available in QFuture to expected results
|
||||
@ -483,7 +517,7 @@ void tst_QPromise::cancelWhenReassigned()
|
||||
promise.start();
|
||||
|
||||
ThreadWrapper thr([p = std::move(promise)] () mutable {
|
||||
QThread::msleep(100);
|
||||
QThread::sleep(100ms);
|
||||
p = QPromise<int>(); // assign new promise, old must be correctly destroyed
|
||||
});
|
||||
|
||||
@ -618,7 +652,7 @@ void tst_QPromise::finishWhenSwapped()
|
||||
promise2.start();
|
||||
|
||||
ThreadWrapper thr([&promise1, &promise2] () mutable {
|
||||
QThread::msleep(100);
|
||||
QThread::sleep(100ms);
|
||||
promise1.addResult(0);
|
||||
promise2.addResult(1);
|
||||
swap(promise1, promise2); // ADL must resolve this
|
||||
@ -662,7 +696,7 @@ void testCancelWhenMoved()
|
||||
|
||||
// Move promises to local scope to test cancellation behavior
|
||||
ThreadWrapper thr([p1 = std::move(promise1), p2 = std::move(promise2)] () mutable {
|
||||
QThread::msleep(100);
|
||||
QThread::sleep(100ms);
|
||||
p1 = std::move(p2);
|
||||
p1.finish(); // this finish is for future #2
|
||||
});
|
||||
@ -706,7 +740,7 @@ void tst_QPromise::waitUntilResumed()
|
||||
|
||||
while (!f.isSuspended()) { // busy wait until worker thread suspends
|
||||
QCOMPARE(f.isFinished(), false); // exit condition in case of failure
|
||||
QThread::msleep(50); // allow another thread to actually carry on
|
||||
QThread::sleep(50ms); // allow another thread to actually carry on
|
||||
}
|
||||
|
||||
f.resume();
|
||||
@ -735,7 +769,7 @@ void tst_QPromise::waitUntilCanceled()
|
||||
|
||||
while (!f.isSuspended()) { // busy wait until worker thread suspends
|
||||
QCOMPARE(f.isFinished(), false); // exit condition in case of failure
|
||||
QThread::msleep(50); // allow another thread to actually carry on
|
||||
QThread::sleep(50ms); // allow another thread to actually carry on
|
||||
}
|
||||
|
||||
f.cancel();
|
||||
|
Reference in New Issue
Block a user