mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2024-11-22 02:34:30 +08:00
Use C++11 curly braces initialization
This commit is contained in:
parent
0bfdddd887
commit
be5455a8c8
@ -145,11 +145,11 @@ will be resolved when the network request is finished:
|
|||||||
```cpp
|
```cpp
|
||||||
QtPromise::QPromise<QByteArray> download(const QUrl& url)
|
QtPromise::QPromise<QByteArray> download(const QUrl& url)
|
||||||
{
|
{
|
||||||
return QtPromise::QPromise<QByteArray>([&](
|
return QtPromise::QPromise<QByteArray>{[&](
|
||||||
const QtPromise::QPromiseResolve<QByteArray>& resolve,
|
const QtPromise::QPromiseResolve<QByteArray>& resolve,
|
||||||
const QtPromise::QPromiseReject<QByteArray>& reject) {
|
const QtPromise::QPromiseReject<QByteArray>& reject) {
|
||||||
|
|
||||||
QNetworkReply* reply = manager->get(QNetworkRequest(url));
|
QNetworkReply* reply = manager->get(QNetworkRequest{url});
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
||||||
if (reply->error() == QNetworkReply::NoError) {
|
if (reply->error() == QNetworkReply::NoError) {
|
||||||
resolve(reply->readAll());
|
resolve(reply->readAll());
|
||||||
@ -159,7 +159,7 @@ QtPromise::QPromise<QByteArray> download(const QUrl& url)
|
|||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ QtPromise::QPromise<Entries> uncompress(const QByteArray& data)
|
|||||||
// {...} uncompress data and parse content.
|
// {...} uncompress data and parse content.
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
throw MalformedException();
|
throw MalformedException{};
|
||||||
}
|
}
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
@ -193,7 +193,7 @@ It's then easy to chain the whole asynchronous process using promises:
|
|||||||
```cpp
|
```cpp
|
||||||
download(url).then(&uncompress).then([](const Entries& entries) {
|
download(url).then(&uncompress).then([](const Entries& entries) {
|
||||||
if (entries.isEmpty()) {
|
if (entries.isEmpty()) {
|
||||||
throw UpdateException("No entries");
|
throw UpdateException{"No entries"};
|
||||||
}
|
}
|
||||||
// {...} process entries
|
// {...} process entries
|
||||||
}).finally([]() {
|
}).finally([]() {
|
||||||
|
@ -29,7 +29,7 @@ QPromise<QByteArray> process(const QUrl& url)
|
|||||||
{
|
{
|
||||||
return QtPromise::attempt([&]() {
|
return QtPromise::attempt([&]() {
|
||||||
if (!url.isValid()) {
|
if (!url.isValid()) {
|
||||||
throw InvalidUrlException();
|
throw InvalidUrlException{};
|
||||||
}
|
}
|
||||||
|
|
||||||
return download(url);
|
return download(url);
|
||||||
|
@ -31,7 +31,7 @@ Q_SIGNALS:
|
|||||||
void error(ErrorCode);
|
void error(ErrorCode);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto sender = new Sender();
|
auto sender = new Sender{};
|
||||||
auto output = QtPromise::connect(sender, &Sender::finished, &Sender::error);
|
auto output = QtPromise::connect(sender, &Sender::finished, &Sender::error);
|
||||||
|
|
||||||
// 'output' resolves as soon as one of the following events happens:
|
// 'output' resolves as soon as one of the following events happens:
|
||||||
|
@ -27,9 +27,9 @@ auto output = QtPromise::each(QVector<QUrl>{
|
|||||||
QUrl("http://b..."),
|
QUrl("http://b..."),
|
||||||
QUrl("http://c...")
|
QUrl("http://c...")
|
||||||
}, [](const QUrl& url, ...) {
|
}, [](const QUrl& url, ...) {
|
||||||
return QPromise<void>([&](auto resolve, auto reject) {
|
return QPromise<void>{[&](auto resolve, auto reject) {
|
||||||
// process url asynchronously ...
|
// process url asynchronously ...
|
||||||
})
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
// `output` resolves as soon as all promises returned by
|
// `output` resolves as soon as all promises returned by
|
||||||
|
@ -29,10 +29,10 @@ auto output = QtPromise::filter(QVector{
|
|||||||
QUrl("http://b..."),
|
QUrl("http://b..."),
|
||||||
QUrl("http://c...")
|
QUrl("http://c...")
|
||||||
}, [](const QUrl& url, ...) {
|
}, [](const QUrl& url, ...) {
|
||||||
return QPromise<bool>([&](auto resolve, auto reject) {
|
return QPromise<bool>{[&](auto resolve, auto reject) {
|
||||||
// resolve(true) if 'url' is reachable, else resolve(false)
|
// resolve(true) if 'url' is reachable, else resolve(false)
|
||||||
// {...}
|
// {...}
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
// 'output' resolves as soon as all promises returned by
|
// 'output' resolves as soon as all promises returned by
|
||||||
|
@ -28,10 +28,10 @@ auto output = QtPromise::map(QVector{
|
|||||||
QUrl("http://b..."),
|
QUrl("http://b..."),
|
||||||
QUrl("http://c...")
|
QUrl("http://c...")
|
||||||
}, [](const QUrl& url, ...) {
|
}, [](const QUrl& url, ...) {
|
||||||
return QPromise<QByteArray>([&](auto resolve, auto reject) {
|
return QPromise<QByteArray>{[&](auto resolve, auto reject) {
|
||||||
// download content at url and resolve
|
// download content at url and resolve
|
||||||
// {...}
|
// {...}
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
// 'output' resolves as soon as all promises returned by
|
// 'output' resolves as soon as all promises returned by
|
||||||
|
@ -33,9 +33,9 @@ auto output = QtPromise::reduce(QList<QUrl>{
|
|||||||
"file:f2.txt" // contains "42"
|
"file:f2.txt" // contains "42"
|
||||||
}, [](const QString& acc, const QString& cur, int idx) {
|
}, [](const QString& acc, const QString& cur, int idx) {
|
||||||
return readAsync(cur).then([=](const QString& res) {
|
return readAsync(cur).then([=](const QString& res) {
|
||||||
return QString("%1;%2:%3").arg(acc).arg(idx).arg(res);
|
return QString{"%1;%2:%3"}.arg(acc).arg(idx).arg(res);
|
||||||
});
|
});
|
||||||
}, QString("index:text"));
|
}, QString{"index:text"});
|
||||||
|
|
||||||
// 'output' resolves as soon as all promises returned by
|
// 'output' resolves as soon as all promises returned by
|
||||||
// 'reducer' are fulfilled or at least one is rejected.
|
// 'reducer' are fulfilled or at least one is rejected.
|
||||||
|
@ -16,7 +16,7 @@ resolved from a given `value` but without the extra typing:
|
|||||||
```cpp
|
```cpp
|
||||||
auto promise = QtPromise::resolve(); // QPromise<void>
|
auto promise = QtPromise::resolve(); // QPromise<void>
|
||||||
auto promise = QtPromise::resolve(42); // QPromise<int>
|
auto promise = QtPromise::resolve(42); // QPromise<int>
|
||||||
auto promise = QtPromise::resolve(QString("foo")); // QPromise<QString>
|
auto promise = QtPromise::resolve(QString{"foo"}); // QPromise<QString>
|
||||||
```
|
```
|
||||||
|
|
||||||
This method also allows to convert `QFuture<T>` to `QPromise<T>`, delayed until the `QFuture` is
|
This method also allows to convert `QFuture<T>` to `QPromise<T>`, delayed until the `QFuture` is
|
||||||
|
@ -18,7 +18,7 @@ QPromise<int> promise([](const QPromiseResolve<int>& resolve, const QPromiseReje
|
|||||||
if (success) {
|
if (success) {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
} else {
|
} else {
|
||||||
reject(customException());
|
reject(customException{});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -32,9 +32,9 @@ no argument.
|
|||||||
C++14 alternative:
|
C++14 alternative:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
QPromise<int> promise([](const auto& resolve, const auto& reject) {
|
QPromise<int> promise{[](const auto& resolve, const auto& reject) {
|
||||||
// {...}
|
// {...}
|
||||||
});
|
}};
|
||||||
```
|
```
|
||||||
|
|
||||||
## Undefined rejection reason
|
## Undefined rejection reason
|
||||||
@ -46,7 +46,7 @@ a promise without explicit reason, in which case, a built-in [`QPromiseUndefined
|
|||||||
is thrown:
|
is thrown:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
QPromise<int> promise([](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
|
QPromise<int> promise{[](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
|
||||||
async_method([=](bool success, int result) {
|
async_method([=](bool success, int result) {
|
||||||
if (success) {
|
if (success) {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
@ -54,7 +54,7 @@ QPromise<int> promise([](const QPromiseResolve<int>& resolve, const QPromiseReje
|
|||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
```
|
```
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
@ -43,9 +43,9 @@ of the promise that rejected, whether or not the other promises are resolved.
|
|||||||
QPromise<QList<QUrl>> input = {...}
|
QPromise<QList<QUrl>> input = {...}
|
||||||
|
|
||||||
auto output = input.each([](const QUrl& url, ...) {
|
auto output = input.each([](const QUrl& url, ...) {
|
||||||
return QPromise<void>([&](auto resolve, auto reject) {
|
return QPromise<void>{[&](auto resolve, auto reject) {
|
||||||
// process url asynchronously ...
|
// process url asynchronously ...
|
||||||
})
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
// `output` resolves as soon as all promises returned by
|
// `output` resolves as soon as all promises returned by
|
||||||
|
@ -33,9 +33,9 @@ QPromise<QList<QUrl>> input = {...}
|
|||||||
auto output = input.filter([](const QUrl& url, ...) {
|
auto output = input.filter([](const QUrl& url, ...) {
|
||||||
return url.isValid(); // Keep only valid URLs
|
return url.isValid(); // Keep only valid URLs
|
||||||
}).filter([](const QUrl& url, ...) {
|
}).filter([](const QUrl& url, ...) {
|
||||||
return QPromise<bool>([&](auto resolve, auto reject) {
|
return QPromise<bool>{[&](auto resolve, auto reject) {
|
||||||
// resolve(true) if `url` is reachable, else resolve(false)
|
// resolve(true) if `url` is reachable, else resolve(false)
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
// 'output' resolves as soon as all promises returned by
|
// 'output' resolves as soon as all promises returned by
|
||||||
|
@ -30,14 +30,14 @@ promise that rejected, whether or not the other promises are resolved.
|
|||||||
QPromise<QList<QUrl>> input = {...}
|
QPromise<QList<QUrl>> input = {...}
|
||||||
|
|
||||||
auto output = input.map([](const QUrl& url, int index) {
|
auto output = input.map([](const QUrl& url, int index) {
|
||||||
return QPromise<QByteArray>([&](auto resolve, auto reject) {
|
return QPromise<QByteArray>{[&](auto resolve, auto reject) {
|
||||||
// download content at 'url' and resolve
|
// download content at 'url' and resolve
|
||||||
// {...}
|
// {...}
|
||||||
});
|
}};
|
||||||
}).map([](const QByteArray& value, ...) {
|
}).map([](const QByteArray& value, ...) {
|
||||||
// process the downloaded QByteArray
|
// process the downloaded QByteArray
|
||||||
// {...}
|
// {...}
|
||||||
return DownloadResult(value);
|
return DownloadResult{value};
|
||||||
});
|
});
|
||||||
|
|
||||||
// 'output' resolves as soon as all promises returned by
|
// 'output' resolves as soon as all promises returned by
|
||||||
|
@ -44,9 +44,9 @@ auto input = QtPromise::resolve(QList<QUrl>{
|
|||||||
// Concatenate the content of the given files, read asynchronously
|
// Concatenate the content of the given files, read asynchronously
|
||||||
auto output = input.reduce([](const QString& acc, const QString& cur, int idx) {
|
auto output = input.reduce([](const QString& acc, const QString& cur, int idx) {
|
||||||
return readAsync(cur).then([=](const QString& res) {
|
return readAsync(cur).then([=](const QString& res) {
|
||||||
return QString("%1;%2:%3").arg(acc).arg(idx).arg(res);
|
return QString{"%1;%2:%3"}.arg(acc).arg(idx).arg(res);
|
||||||
});
|
});
|
||||||
}, QString("index:text"));
|
}, QString{"index:text"});
|
||||||
|
|
||||||
// 'output' resolves as soon as all promises returned by
|
// 'output' resolves as soon as all promises returned by
|
||||||
// 'reducer' are fulfilled or at least one is rejected.
|
// 'reducer' are fulfilled or at least one is rejected.
|
||||||
|
@ -16,11 +16,11 @@ Creates a `QPromise<T>` that is rejected with the given `reason` of *whatever ty
|
|||||||
QPromise<int> compute(const QString& type)
|
QPromise<int> compute(const QString& type)
|
||||||
{
|
{
|
||||||
if (type == "foobar") {
|
if (type == "foobar") {
|
||||||
return QPromise<int>::reject(QString("Unknown type: %1").arg(type));
|
return QPromise<int>::reject(QString{"Unknown type: %1"}.arg(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
return QPromise<int>([](const QPromiseResolve<int>& resolve) {
|
return QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
||||||
// {...}
|
// {...}
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -19,9 +19,9 @@ QPromise<int> compute(const QString& type)
|
|||||||
return QPromise<int>::resolve(42);
|
return QPromise<int>::resolve(42);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QPromise<int>([](const QPromiseResolve<int>& resolve) {
|
return QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
||||||
// {...}
|
// {...}
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ QPromise<int> input = ...
|
|||||||
auto output = input.then([](int res) {
|
auto output = input.then([](int res) {
|
||||||
return QtConcurrent::run([]() {
|
return QtConcurrent::run([]() {
|
||||||
// {...}
|
// {...}
|
||||||
return QString("42");
|
return QString{"42"};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -62,10 +62,10 @@ promise.then([](int res) {
|
|||||||
// {...}
|
// {...}
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw CustomException();
|
throw CustomException{};
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString("42");
|
return QString{"42"};
|
||||||
});
|
});
|
||||||
}).fail([](const CustomException& error) {
|
}).fail([](const CustomException& error) {
|
||||||
// {...}
|
// {...}
|
||||||
|
@ -31,8 +31,8 @@ public:
|
|||||||
template <typename F, typename std::enable_if<QtPromisePrivate::ArgsOf<F>::count == 2, int>::type = 0>
|
template <typename F, typename std::enable_if<QtPromisePrivate::ArgsOf<F>::count == 2, int>::type = 0>
|
||||||
inline QPromiseBase(F resolver);
|
inline QPromiseBase(F resolver);
|
||||||
|
|
||||||
QPromiseBase(const QPromiseBase<T>& other): m_d(other.m_d) {}
|
QPromiseBase(const QPromiseBase<T>& other): m_d{other.m_d} {}
|
||||||
QPromiseBase(const QPromise<T>& other): m_d(other.m_d) {}
|
QPromiseBase(const QPromise<T>& other): m_d{other.m_d} {}
|
||||||
QPromiseBase(QPromiseBase<T>&& other) Q_DECL_NOEXCEPT { swap(other); }
|
QPromiseBase(QPromiseBase<T>&& other) Q_DECL_NOEXCEPT { swap(other); }
|
||||||
|
|
||||||
virtual ~QPromiseBase() { }
|
virtual ~QPromiseBase() { }
|
||||||
@ -72,10 +72,10 @@ public:
|
|||||||
inline QPromise<T> tapFail(THandler handler) const;
|
inline QPromise<T> tapFail(THandler handler) const;
|
||||||
|
|
||||||
template <typename E = QPromiseTimeoutException>
|
template <typename E = QPromiseTimeoutException>
|
||||||
inline QPromise<T> timeout(int msec, E&& error = E()) const;
|
inline QPromise<T> timeout(int msec, E&& error = E{}) const;
|
||||||
|
|
||||||
template <typename E = QPromiseTimeoutException>
|
template <typename E = QPromiseTimeoutException>
|
||||||
inline QPromise<T> timeout(std::chrono::milliseconds msec, E&& error = E()) const;
|
inline QPromise<T> timeout(std::chrono::milliseconds msec, E&& error = E{}) const;
|
||||||
|
|
||||||
inline QPromise<T> delay(int msec) const;
|
inline QPromise<T> delay(int msec) const;
|
||||||
inline QPromise<T> delay(std::chrono::milliseconds msec) const;
|
inline QPromise<T> delay(std::chrono::milliseconds msec) const;
|
||||||
|
@ -17,9 +17,9 @@ namespace QtPromise {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
template <typename F, typename std::enable_if<QtPromisePrivate::ArgsOf<F>::count == 1, int>::type>
|
template <typename F, typename std::enable_if<QtPromisePrivate::ArgsOf<F>::count == 1, int>::type>
|
||||||
inline QPromiseBase<T>::QPromiseBase(F callback)
|
inline QPromiseBase<T>::QPromiseBase(F callback)
|
||||||
: m_d(new QtPromisePrivate::PromiseData<T>())
|
: m_d{new QtPromisePrivate::PromiseData<T>{}}
|
||||||
{
|
{
|
||||||
QtPromisePrivate::PromiseResolver<T> resolver(*this);
|
QtPromisePrivate::PromiseResolver<T> resolver{*this};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
callback(QPromiseResolve<T>(resolver));
|
callback(QPromiseResolve<T>(resolver));
|
||||||
@ -31,9 +31,9 @@ inline QPromiseBase<T>::QPromiseBase(F callback)
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
template <typename F, typename std::enable_if<QtPromisePrivate::ArgsOf<F>::count == 2, int>::type>
|
template <typename F, typename std::enable_if<QtPromisePrivate::ArgsOf<F>::count == 2, int>::type>
|
||||||
inline QPromiseBase<T>::QPromiseBase(F callback)
|
inline QPromiseBase<T>::QPromiseBase(F callback)
|
||||||
: m_d(new QtPromisePrivate::PromiseData<T>())
|
: m_d{new QtPromisePrivate::PromiseData<T>{}}
|
||||||
{
|
{
|
||||||
QtPromisePrivate::PromiseResolver<T> resolver(*this);
|
QtPromisePrivate::PromiseResolver<T> resolver{*this};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
callback(QPromiseResolve<T>(resolver), QPromiseReject<T>(resolver));
|
callback(QPromiseResolve<T>(resolver), QPromiseReject<T>(resolver));
|
||||||
@ -115,7 +115,7 @@ template <typename E>
|
|||||||
inline QPromise<T> QPromiseBase<T>::timeout(int msec, E&& error) const
|
inline QPromise<T> QPromiseBase<T>::timeout(int msec, E&& error) const
|
||||||
{
|
{
|
||||||
QPromise<T> p = *this;
|
QPromise<T> p = *this;
|
||||||
return QPromise<T>([&](
|
return QPromise<T>{[&](
|
||||||
const QPromiseResolve<T>& resolve,
|
const QPromiseResolve<T>& resolve,
|
||||||
const QPromiseReject<T>& reject) {
|
const QPromiseReject<T>& reject) {
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ inline QPromise<T> QPromiseBase<T>::timeout(int msec, E&& error) const
|
|||||||
});
|
});
|
||||||
|
|
||||||
QtPromisePrivate::PromiseFulfill<QPromise<T>>::call(p, resolve, reject);
|
QtPromisePrivate::PromiseFulfill<QPromise<T>>::call(p, resolve, reject);
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -141,9 +141,9 @@ template <typename T>
|
|||||||
inline QPromise<T> QPromiseBase<T>::delay(int msec) const
|
inline QPromise<T> QPromiseBase<T>::delay(int msec) const
|
||||||
{
|
{
|
||||||
return tap([=]() {
|
return tap([=]() {
|
||||||
return QPromise<void>([&](const QPromiseResolve<void>& resolve) {
|
return QPromise<void>{[&](const QPromiseResolve<void>& resolve) {
|
||||||
QTimer::singleShot(msec, resolve);
|
QTimer::singleShot(msec, resolve);
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,9 +169,9 @@ template <typename T>
|
|||||||
template <typename E>
|
template <typename E>
|
||||||
inline QPromise<T> QPromiseBase<T>::reject(E&& error)
|
inline QPromise<T> QPromiseBase<T>::reject(E&& error)
|
||||||
{
|
{
|
||||||
return QPromise<T>([&](const QPromiseResolve<T>&, const QPromiseReject<T>& reject) {
|
return QPromise<T>{[&](const QPromiseResolve<T>&, const QPromiseReject<T>& reject) {
|
||||||
reject(std::forward<E>(error));
|
reject(std::forward<E>(error));
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -246,17 +246,17 @@ inline QPromise<QVector<T>> QPromise<T>::all(const Sequence<QPromise<T>, Args...
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
inline QPromise<T> QPromise<T>::resolve(const T& value)
|
inline QPromise<T> QPromise<T>::resolve(const T& value)
|
||||||
{
|
{
|
||||||
return QPromise<T>([&](const QPromiseResolve<T>& resolve) {
|
return QPromise<T>{[&](const QPromiseResolve<T>& resolve) {
|
||||||
resolve(value);
|
resolve(value);
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline QPromise<T> QPromise<T>::resolve(T&& value)
|
inline QPromise<T> QPromise<T>::resolve(T&& value)
|
||||||
{
|
{
|
||||||
return QPromise<T>([&](const QPromiseResolve<T>& resolve) {
|
return QPromise<T>{[&](const QPromiseResolve<T>& resolve) {
|
||||||
resolve(std::forward<T>(value));
|
resolve(std::forward<T>(value));
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <template <typename, typename...> class Sequence, typename ...Args>
|
template <template <typename, typename...> class Sequence, typename ...Args>
|
||||||
|
@ -42,8 +42,8 @@ static void qtpromise_defer(F&& f, const QPointer<QThread>& thread)
|
|||||||
|
|
||||||
struct Event : public QEvent
|
struct Event : public QEvent
|
||||||
{
|
{
|
||||||
Event(FType&& f) : QEvent(QEvent::None), m_f(std::move(f)) { }
|
Event(FType&& f) : QEvent{QEvent::None}, m_f{std::move(f)} { }
|
||||||
Event(const FType& f) : QEvent(QEvent::None), m_f(f) { }
|
Event(const FType& f) : QEvent{QEvent::None}, m_f{f} { }
|
||||||
~Event() { m_f(); }
|
~Event() { m_f(); }
|
||||||
FType m_f;
|
FType m_f;
|
||||||
};
|
};
|
||||||
@ -66,7 +66,7 @@ static void qtpromise_defer(F&& f, const QPointer<QThread>& thread)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT_X(target, "postMetaCall", "Target thread must have an event loop");
|
Q_ASSERT_X(target, "postMetaCall", "Target thread must have an event loop");
|
||||||
QCoreApplication::postEvent(target, new Event(std::forward<F>(f)));
|
QCoreApplication::postEvent(target, new Event{std::forward<F>(f)});
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
@ -104,7 +104,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
PromiseError() { }
|
PromiseError() { }
|
||||||
PromiseError(const std::exception_ptr& exception) : m_data(exception) { }
|
PromiseError(const std::exception_ptr& exception) : m_data{exception} { }
|
||||||
void rethrow() const { std::rethrow_exception(m_data); }
|
void rethrow() const { std::rethrow_exception(m_data); }
|
||||||
bool isNull() const { return m_data == nullptr; }
|
bool isNull() const { return m_data == nullptr; }
|
||||||
|
|
||||||
@ -422,19 +422,19 @@ public:
|
|||||||
|
|
||||||
bool isPending() const
|
bool isPending() const
|
||||||
{
|
{
|
||||||
QReadLocker lock(&m_lock);
|
QReadLocker lock{&m_lock};
|
||||||
return !m_settled;
|
return !m_settled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addHandler(std::function<F> handler)
|
void addHandler(std::function<F> handler)
|
||||||
{
|
{
|
||||||
QWriteLocker lock(&m_lock);
|
QWriteLocker lock{&m_lock};
|
||||||
m_handlers.append({QThread::currentThread(), std::move(handler)});
|
m_handlers.append({QThread::currentThread(), std::move(handler)});
|
||||||
}
|
}
|
||||||
|
|
||||||
void addCatcher(std::function<void(const PromiseError&)> catcher)
|
void addCatcher(std::function<void(const PromiseError&)> catcher)
|
||||||
{
|
{
|
||||||
QWriteLocker lock(&m_lock);
|
QWriteLocker lock{&m_lock};
|
||||||
m_catchers.append({QThread::currentThread(), std::move(catcher)});
|
m_catchers.append({QThread::currentThread(), std::move(catcher)});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,7 +443,7 @@ public:
|
|||||||
{
|
{
|
||||||
Q_ASSERT(isPending());
|
Q_ASSERT(isPending());
|
||||||
Q_ASSERT(m_error.isNull());
|
Q_ASSERT(m_error.isNull());
|
||||||
m_error = PromiseError(std::forward<E>(error));
|
m_error = PromiseError{std::forward<E>(error)};
|
||||||
setSettled();
|
setSettled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,8 +467,8 @@ public:
|
|||||||
// captured in the handler and/or catcher lambdas.
|
// captured in the handler and/or catcher lambdas.
|
||||||
|
|
||||||
m_lock.lockForWrite();
|
m_lock.lockForWrite();
|
||||||
QVector<Handler> handlers(std::move(m_handlers));
|
QVector<Handler> handlers = std::move(m_handlers);
|
||||||
QVector<Catcher> catchers(std::move(m_catchers));
|
QVector<Catcher> catchers = std::move(m_catchers);
|
||||||
m_lock.unlock();
|
m_lock.unlock();
|
||||||
|
|
||||||
if (m_error.isNull()) {
|
if (m_error.isNull()) {
|
||||||
@ -476,7 +476,7 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PromiseError error(m_error);
|
PromiseError error = m_error;
|
||||||
Q_ASSERT(!error.isNull());
|
Q_ASSERT(!error.isNull());
|
||||||
|
|
||||||
for (const auto& catcher: catchers) {
|
for (const auto& catcher: catchers) {
|
||||||
@ -492,7 +492,7 @@ protected:
|
|||||||
|
|
||||||
void setSettled()
|
void setSettled()
|
||||||
{
|
{
|
||||||
QWriteLocker lock(&m_lock);
|
QWriteLocker lock{&m_lock};
|
||||||
Q_ASSERT(!m_settled);
|
Q_ASSERT(!m_settled);
|
||||||
m_settled = true;
|
m_settled = true;
|
||||||
}
|
}
|
||||||
@ -517,7 +517,7 @@ public:
|
|||||||
{
|
{
|
||||||
Q_ASSERT(this->isPending());
|
Q_ASSERT(this->isPending());
|
||||||
Q_ASSERT(m_value.isNull());
|
Q_ASSERT(m_value.isNull());
|
||||||
m_value = PromiseValue<T>(std::forward<V>(value));
|
m_value = PromiseValue<T>{std::forward<V>(value)};
|
||||||
this->setSettled();
|
this->setSettled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,7 +529,7 @@ public:
|
|||||||
|
|
||||||
void notify(const QVector<Handler>& handlers) Q_DECL_OVERRIDE
|
void notify(const QVector<Handler>& handlers) Q_DECL_OVERRIDE
|
||||||
{
|
{
|
||||||
PromiseValue<T> value(m_value);
|
PromiseValue<T> value = m_value;
|
||||||
Q_ASSERT(!value.isNull());
|
Q_ASSERT(!value.isNull());
|
||||||
|
|
||||||
for (const auto& handler: handlers) {
|
for (const auto& handler: handlers) {
|
||||||
|
@ -21,7 +21,7 @@ public:
|
|||||||
void raise() const Q_DECL_OVERRIDE { throw *this; }
|
void raise() const Q_DECL_OVERRIDE { throw *this; }
|
||||||
QPromiseCanceledException* clone() const Q_DECL_OVERRIDE
|
QPromiseCanceledException* clone() const Q_DECL_OVERRIDE
|
||||||
{
|
{
|
||||||
return new QPromiseCanceledException(*this);
|
return new QPromiseCanceledException{*this};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ public:
|
|||||||
void raise() const Q_DECL_OVERRIDE { throw *this; }
|
void raise() const Q_DECL_OVERRIDE { throw *this; }
|
||||||
QPromiseContextException* clone() const Q_DECL_OVERRIDE
|
QPromiseContextException* clone() const Q_DECL_OVERRIDE
|
||||||
{
|
{
|
||||||
return new QPromiseContextException(*this);
|
return new QPromiseContextException{*this};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ public:
|
|||||||
void raise() const Q_DECL_OVERRIDE { throw *this; }
|
void raise() const Q_DECL_OVERRIDE { throw *this; }
|
||||||
QPromiseTimeoutException* clone() const Q_DECL_OVERRIDE
|
QPromiseTimeoutException* clone() const Q_DECL_OVERRIDE
|
||||||
{
|
{
|
||||||
return new QPromiseTimeoutException(*this);
|
return new QPromiseTimeoutException{*this};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ public:
|
|||||||
void raise() const Q_DECL_OVERRIDE { throw *this; }
|
void raise() const Q_DECL_OVERRIDE { throw *this; }
|
||||||
QPromiseUndefinedException* clone() const Q_DECL_OVERRIDE
|
QPromiseUndefinedException* clone() const Q_DECL_OVERRIDE
|
||||||
{
|
{
|
||||||
return new QPromiseUndefinedException(*this);
|
return new QPromiseUndefinedException{*this};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ struct PromiseFulfill<QFuture<T>>
|
|||||||
{
|
{
|
||||||
using Watcher = QFutureWatcher<T>;
|
using Watcher = QFutureWatcher<T>;
|
||||||
|
|
||||||
Watcher* watcher = new Watcher();
|
Watcher* watcher = new Watcher{};
|
||||||
QObject::connect(watcher, &Watcher::finished, [=]() mutable {
|
QObject::connect(watcher, &Watcher::finished, [=]() mutable {
|
||||||
try {
|
try {
|
||||||
if (watcher->isCanceled()) {
|
if (watcher->isCanceled()) {
|
||||||
@ -40,7 +40,7 @@ struct PromiseFulfill<QFuture<T>>
|
|||||||
// rethrown potential exceptions using waitForFinished() and thus detect
|
// rethrown potential exceptions using waitForFinished() and thus detect
|
||||||
// if the future has been canceled by the user or an exception.
|
// if the future has been canceled by the user or an exception.
|
||||||
watcher->waitForFinished();
|
watcher->waitForFinished();
|
||||||
reject(QtPromise::QPromiseCanceledException());
|
reject(QtPromise::QPromiseCanceledException{});
|
||||||
} else {
|
} else {
|
||||||
PromiseFulfill<T>::call(watcher->result(), resolve, reject);
|
PromiseFulfill<T>::call(watcher->result(), resolve, reject);
|
||||||
}
|
}
|
||||||
@ -65,13 +65,13 @@ struct PromiseFulfill<QFuture<void>>
|
|||||||
{
|
{
|
||||||
using Watcher = QFutureWatcher<void>;
|
using Watcher = QFutureWatcher<void>;
|
||||||
|
|
||||||
Watcher* watcher = new Watcher();
|
Watcher* watcher = new Watcher{};
|
||||||
QObject::connect(watcher, &Watcher::finished, [=]() mutable {
|
QObject::connect(watcher, &Watcher::finished, [=]() mutable {
|
||||||
try {
|
try {
|
||||||
if (watcher->isCanceled()) {
|
if (watcher->isCanceled()) {
|
||||||
// let's rethrown potential exception
|
// let's rethrown potential exception
|
||||||
watcher->waitForFinished();
|
watcher->waitForFinished();
|
||||||
reject(QtPromise::QPromiseCanceledException());
|
reject(QtPromise::QPromiseCanceledException{});
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,12 @@ resolve(T&& value)
|
|||||||
using ResolveType = QPromiseResolve<ValueType>;
|
using ResolveType = QPromiseResolve<ValueType>;
|
||||||
using RejectType = QPromiseReject<ValueType>;
|
using RejectType = QPromiseReject<ValueType>;
|
||||||
|
|
||||||
return PromiseType([&](ResolveType&& resolve, RejectType&& reject) {
|
return PromiseType{[&](ResolveType&& resolve, RejectType&& reject) {
|
||||||
PromiseFulfill<Unqualified<T>>::call(
|
PromiseFulfill<Unqualified<T>>::call(
|
||||||
std::forward<T>(value),
|
std::forward<T>(value),
|
||||||
std::forward<ResolveType>(resolve),
|
std::forward<ResolveType>(resolve),
|
||||||
std::forward<RejectType>(reject));
|
std::forward<RejectType>(reject));
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -41,9 +41,9 @@ resolve(QPromise<T> value)
|
|||||||
static inline QPromise<void>
|
static inline QPromise<void>
|
||||||
resolve()
|
resolve()
|
||||||
{
|
{
|
||||||
return QPromise<void>([](const QPromiseResolve<void>& resolve) {
|
return QPromise<void>{[](const QPromiseResolve<void>& resolve) {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, template <typename, typename...> class Sequence = QVector, typename ...Args>
|
template <typename T, template <typename, typename...> class Sequence = QVector, typename ...Args>
|
||||||
@ -55,7 +55,7 @@ all(const Sequence<QPromise<T>, Args...>& promises)
|
|||||||
return QtPromise::resolve(QVector<T>{});
|
return QtPromise::resolve(QVector<T>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
return QPromise<QVector<T>>([=](
|
return QPromise<QVector<T>>{[=](
|
||||||
const QPromiseResolve<QVector<T>>& resolve,
|
const QPromiseResolve<QVector<T>>& resolve,
|
||||||
const QPromiseReject<QVector<T>>& reject) {
|
const QPromiseReject<QVector<T>>& reject) {
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ all(const Sequence<QPromise<T>, Args...>& promises)
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <template <typename, typename...> class Sequence = QVector, typename ...Args>
|
template <template <typename, typename...> class Sequence = QVector, typename ...Args>
|
||||||
@ -90,7 +90,7 @@ all(const Sequence<QPromise<void>, Args...>& promises)
|
|||||||
return QtPromise::resolve();
|
return QtPromise::resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QPromise<void>([=](
|
return QPromise<void>{[=](
|
||||||
const QPromiseResolve<void>& resolve,
|
const QPromiseResolve<void>& resolve,
|
||||||
const QPromiseReject<void>& reject) {
|
const QPromiseReject<void>& reject) {
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ all(const Sequence<QPromise<void>, Args...>& promises)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Functor, typename... Args>
|
template <typename Functor, typename... Args>
|
||||||
@ -127,14 +127,14 @@ attempt(Functor&& fn, Args&&... args)
|
|||||||
using ResolveType = QPromiseResolve<ValueType>;
|
using ResolveType = QPromiseResolve<ValueType>;
|
||||||
using RejectType = QPromiseReject<ValueType>;
|
using RejectType = QPromiseReject<ValueType>;
|
||||||
|
|
||||||
return PromiseType(
|
return PromiseType{
|
||||||
[&](ResolveType&& resolve, RejectType&& reject) {
|
[&](ResolveType&& resolve, RejectType&& reject) {
|
||||||
PromiseDispatch<typename FunctorType::ResultType>::call(
|
PromiseDispatch<typename FunctorType::ResultType>::call(
|
||||||
std::forward<ResolveType>(resolve),
|
std::forward<ResolveType>(resolve),
|
||||||
std::forward<RejectType>(reject),
|
std::forward<RejectType>(reject),
|
||||||
std::forward<Functor>(fn),
|
std::forward<Functor>(fn),
|
||||||
std::forward<Args>(args)...);
|
std::forward<Args>(args)...);
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Sender, typename Signal>
|
template <typename Sender, typename Signal>
|
||||||
@ -144,12 +144,12 @@ connect(const Sender* sender, Signal signal)
|
|||||||
using namespace QtPromisePrivate;
|
using namespace QtPromisePrivate;
|
||||||
using T = typename PromiseFromSignal<Signal>::Type;
|
using T = typename PromiseFromSignal<Signal>::Type;
|
||||||
|
|
||||||
return QPromise<T>(
|
return QPromise<T>{
|
||||||
[&](const QPromiseResolve<T>& resolve, const QPromiseReject<T>& reject) {
|
[&](const QPromiseResolve<T>& resolve, const QPromiseReject<T>& reject) {
|
||||||
QPromiseConnections connections;
|
QPromiseConnections connections;
|
||||||
connectSignalToResolver(connections, resolve, sender, signal);
|
connectSignalToResolver(connections, resolve, sender, signal);
|
||||||
connectDestroyedToReject(connections, reject, sender);
|
connectDestroyedToReject(connections, reject, sender);
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FSender, typename FSignal, typename RSender, typename RSignal>
|
template <typename FSender, typename FSignal, typename RSender, typename RSignal>
|
||||||
@ -159,13 +159,13 @@ connect(const FSender* fsender, FSignal fsignal, const RSender* rsender, RSignal
|
|||||||
using namespace QtPromisePrivate;
|
using namespace QtPromisePrivate;
|
||||||
using T = typename PromiseFromSignal<FSignal>::Type;
|
using T = typename PromiseFromSignal<FSignal>::Type;
|
||||||
|
|
||||||
return QPromise<T>(
|
return QPromise<T>{
|
||||||
[&](const QPromiseResolve<T>& resolve, const QPromiseReject<T>& reject) {
|
[&](const QPromiseResolve<T>& resolve, const QPromiseReject<T>& reject) {
|
||||||
QPromiseConnections connections;
|
QPromiseConnections connections;
|
||||||
connectSignalToResolver(connections, resolve, fsender, fsignal);
|
connectSignalToResolver(connections, resolve, fsender, fsignal);
|
||||||
connectSignalToResolver(connections, reject, rsender, rsignal);
|
connectSignalToResolver(connections, reject, rsender, rsignal);
|
||||||
connectDestroyedToReject(connections, reject, fsender);
|
connectDestroyedToReject(connections, reject, fsender);
|
||||||
});
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Sender, typename FSignal, typename RSignal>
|
template <typename Sender, typename FSignal, typename RSignal>
|
||||||
@ -195,11 +195,11 @@ map(const Sequence& values, Functor fn)
|
|||||||
|
|
||||||
std::vector<QPromise<ResType>> promises;
|
std::vector<QPromise<ResType>> promises;
|
||||||
for (const auto& v : values) {
|
for (const auto& v : values) {
|
||||||
promises.push_back(QPromise<ResType>([&](
|
promises.push_back(QPromise<ResType>{[&](
|
||||||
const QPromiseResolve<ResType>& resolve,
|
const QPromiseResolve<ResType>& resolve,
|
||||||
const QPromiseReject<ResType>& reject) {
|
const QPromiseReject<ResType>& reject) {
|
||||||
PromiseFulfill<RetType>::call(fn(v, i), resolve, reject);
|
PromiseFulfill<RetType>::call(fn(v, i), resolve, reject);
|
||||||
}));
|
}});
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ connectSignalToResolver(
|
|||||||
{
|
{
|
||||||
connections << QObject::connect(sender, signal, [=]() {
|
connections << QObject::connect(sender, signal, [=]() {
|
||||||
connections.disconnect();
|
connections.disconnect();
|
||||||
reject(QtPromise::QPromiseUndefinedException());
|
reject(QtPromise::QPromiseUndefinedException{});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ void connectDestroyedToReject(
|
|||||||
{
|
{
|
||||||
connections << QObject::connect(sender, &QObject::destroyed, [=]() {
|
connections << QObject::connect(sender, &QObject::destroyed, [=]() {
|
||||||
connections.disconnect();
|
connections.disconnect();
|
||||||
reject(QtPromise::QPromiseContextException());
|
reject(QtPromise::QPromiseContextException{});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,9 +25,9 @@ class PromiseResolver
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PromiseResolver(QtPromise::QPromise<T> promise)
|
PromiseResolver(QtPromise::QPromise<T> promise)
|
||||||
: m_d(new Data())
|
: m_d{new Data{}}
|
||||||
{
|
{
|
||||||
m_d->promise = new QtPromise::QPromise<T>(std::move(promise));
|
m_d->promise = new QtPromise::QPromise<T>{std::move(promise)};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename E>
|
template <typename E>
|
||||||
@ -47,7 +47,7 @@ public:
|
|||||||
auto promise = m_d->promise;
|
auto promise = m_d->promise;
|
||||||
if (promise) {
|
if (promise) {
|
||||||
Q_ASSERT(promise->isPending());
|
Q_ASSERT(promise->isPending());
|
||||||
promise->m_d->reject(QtPromise::QPromiseUndefinedException());
|
promise->m_d->reject(QtPromise::QPromiseUndefinedException{});
|
||||||
promise->m_d->dispatch();
|
promise->m_d->dispatch();
|
||||||
release();
|
release();
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ class QPromiseResolve
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QPromiseResolve(QtPromisePrivate::PromiseResolver<T> resolver)
|
QPromiseResolve(QtPromisePrivate::PromiseResolver<T> resolver)
|
||||||
: m_resolver(std::move(resolver))
|
: m_resolver{std::move(resolver)}
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
@ -125,7 +125,7 @@ class QPromiseReject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QPromiseReject(QtPromisePrivate::PromiseResolver<T> resolver)
|
QPromiseReject(QtPromisePrivate::PromiseResolver<T> resolver)
|
||||||
: m_resolver(std::move(resolver))
|
: m_resolver{std::move(resolver)}
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
template <typename E>
|
template <typename E>
|
||||||
|
@ -43,9 +43,9 @@ void tst_benchmark::valueResolve()
|
|||||||
{
|
{
|
||||||
{ // should move the value when resolved by rvalue
|
{ // should move the value when resolved by rvalue
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>([&](const QPromiseResolve<Data>& resolve) {
|
QPromise<Data>{[&](const QPromiseResolve<Data>& resolve) {
|
||||||
resolve(Data(42));
|
resolve(Data{42});
|
||||||
}).wait();
|
}}.wait();
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 1);
|
QCOMPARE(Data::logs().ctor, 1);
|
||||||
QCOMPARE(Data::logs().copy, 0);
|
QCOMPARE(Data::logs().copy, 0);
|
||||||
@ -54,10 +54,10 @@ void tst_benchmark::valueResolve()
|
|||||||
}
|
}
|
||||||
{ // should create one copy of the value when resolved by lvalue
|
{ // should create one copy of the value when resolved by lvalue
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>([&](const QPromiseResolve<Data>& resolve) {
|
QPromise<Data>{[&](const QPromiseResolve<Data>& resolve) {
|
||||||
Data value(42);
|
Data value{42};
|
||||||
resolve(value);
|
resolve(value);
|
||||||
}).wait();
|
}}.wait();
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 1);
|
QCOMPARE(Data::logs().ctor, 1);
|
||||||
QCOMPARE(Data::logs().copy, 1); // copy value to the promise data
|
QCOMPARE(Data::logs().copy, 1); // copy value to the promise data
|
||||||
@ -70,9 +70,9 @@ void tst_benchmark::valueReject()
|
|||||||
{
|
{
|
||||||
{ // should not create any data if rejected
|
{ // should not create any data if rejected
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>([&](const QPromiseResolve<Data>&, const QPromiseReject<Data>& reject) {
|
QPromise<Data>{[&](const QPromiseResolve<Data>&, const QPromiseReject<Data>& reject) {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
}).wait();
|
}}.wait();
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 0);
|
QCOMPARE(Data::logs().ctor, 0);
|
||||||
QCOMPARE(Data::logs().copy, 0);
|
QCOMPARE(Data::logs().copy, 0);
|
||||||
@ -86,7 +86,7 @@ void tst_benchmark::valueThen()
|
|||||||
{ // should not copy value on continutation if fulfilled
|
{ // should not copy value on continutation if fulfilled
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>::resolve(Data(42)).then([&](const Data& res) {
|
QPromise<Data>::resolve(Data{42}).then([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ void tst_benchmark::valueThen()
|
|||||||
int value = -1;
|
int value = -1;
|
||||||
QString error;
|
QString error;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>::reject(QString("foo")).then([&](const Data& res) {
|
QPromise<Data>::reject(QString{"foo"}).then([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
}, [&](const QString& err) {
|
}, [&](const QString& err) {
|
||||||
error = err;
|
error = err;
|
||||||
@ -110,14 +110,14 @@ void tst_benchmark::valueThen()
|
|||||||
QCOMPARE(Data::logs().copy, 0);
|
QCOMPARE(Data::logs().copy, 0);
|
||||||
QCOMPARE(Data::logs().move, 0);
|
QCOMPARE(Data::logs().move, 0);
|
||||||
QCOMPARE(Data::logs().refs, 0);
|
QCOMPARE(Data::logs().refs, 0);
|
||||||
QCOMPARE(error, QString("foo"));
|
QCOMPARE(error, QString{"foo"});
|
||||||
QCOMPARE(value, -1);
|
QCOMPARE(value, -1);
|
||||||
}
|
}
|
||||||
{ // should move the returned value when fulfilled
|
{ // should move the returned value when fulfilled
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<int>::resolve(42).then([&](int res) {
|
QPromise<int>::resolve(42).then([&](int res) {
|
||||||
return Data(res+2);
|
return Data{res+2};
|
||||||
}).then([&](const Data& res) {
|
}).then([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
}).wait();
|
}).wait();
|
||||||
@ -131,8 +131,8 @@ void tst_benchmark::valueThen()
|
|||||||
{ // should not create any data if handler throws
|
{ // should not create any data if handler throws
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<int>::resolve(42).then([&](int res) {
|
QPromise<int>::resolve(42).then([&](int res) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
return Data(res+2);
|
return Data{res+2};
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 0);
|
QCOMPARE(Data::logs().ctor, 0);
|
||||||
@ -148,7 +148,7 @@ void tst_benchmark::valueDelayed()
|
|||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<int>::resolve(42).then([&](int res) {
|
QPromise<int>::resolve(42).then([&](int res) {
|
||||||
return QPromise<Data>::resolve(Data(res + 1));
|
return QPromise<Data>::resolve(Data{res + 1});
|
||||||
}).then([&](const Data& res) {
|
}).then([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
}).wait();
|
}).wait();
|
||||||
@ -162,7 +162,7 @@ void tst_benchmark::valueDelayed()
|
|||||||
{ // should not create value on continutation if rejected
|
{ // should not create value on continutation if rejected
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<int>::resolve(42).then([&]() {
|
QPromise<int>::resolve(42).then([&]() {
|
||||||
return QPromise<Data>::reject(QString("foo"));
|
return QPromise<Data>::reject(QString{"foo"});
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 0);
|
QCOMPARE(Data::logs().ctor, 0);
|
||||||
@ -177,7 +177,7 @@ void tst_benchmark::valueFinally()
|
|||||||
{ // should not copy the value on continutation if fulfilled
|
{ // should not copy the value on continutation if fulfilled
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>::resolve(Data(42)).finally([&]() {
|
QPromise<Data>::resolve(Data{42}).finally([&]() {
|
||||||
value = 42;
|
value = 42;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ void tst_benchmark::valueFinally()
|
|||||||
{ // should not create value on continutation if rejected
|
{ // should not create value on continutation if rejected
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>::reject(QString("foo")).finally([&]() {
|
QPromise<Data>::reject(QString{"foo"}).finally([&]() {
|
||||||
value = 42;
|
value = 42;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ void tst_benchmark::valueTap()
|
|||||||
{ // should not copy the value on continutation if fulfilled
|
{ // should not copy the value on continutation if fulfilled
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>::resolve(Data(42)).tap([&](const Data& res) {
|
QPromise<Data>::resolve(Data{42}).tap([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ void tst_benchmark::valueTap()
|
|||||||
{ // should not create value on continutation if rejected
|
{ // should not create value on continutation if rejected
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>::reject(QString("foo")).tap([&](const Data& res) {
|
QPromise<Data>::reject(QString{"foo"}).tap([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
@ -236,9 +236,9 @@ void tst_benchmark::errorReject()
|
|||||||
{
|
{
|
||||||
{ // should create one copy of the error when rejected by rvalue
|
{ // should create one copy of the error when rejected by rvalue
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<int>([&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QPromise<int>{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
reject(Data(42));
|
reject(Data{42});
|
||||||
}).wait();
|
}}.wait();
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 1);
|
QCOMPARE(Data::logs().ctor, 1);
|
||||||
QCOMPARE(Data::logs().copy, 1 + EXCEPT_CALL_COPY_CTOR); // copy value in std::exception_ptr
|
QCOMPARE(Data::logs().copy, 1 + EXCEPT_CALL_COPY_CTOR); // copy value in std::exception_ptr
|
||||||
@ -247,10 +247,10 @@ void tst_benchmark::errorReject()
|
|||||||
}
|
}
|
||||||
{ // should create one copy of the error when rejected by lvalue (no extra copy)
|
{ // should create one copy of the error when rejected by lvalue (no extra copy)
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<int>([&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QPromise<int>{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
Data error(42);
|
Data error{42};
|
||||||
reject(error);
|
reject(error);
|
||||||
}).wait();
|
}}.wait();
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 1);
|
QCOMPARE(Data::logs().ctor, 1);
|
||||||
QCOMPARE(Data::logs().copy, 1 + EXCEPT_CALL_COPY_CTOR); // copy value to the promise data
|
QCOMPARE(Data::logs().copy, 1 + EXCEPT_CALL_COPY_CTOR); // copy value to the promise data
|
||||||
@ -264,7 +264,7 @@ void tst_benchmark::errorThen()
|
|||||||
{ // should not copy error on continutation if rejected
|
{ // should not copy error on continutation if rejected
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<void>::reject(Data(42)).fail([&](const Data& res) {
|
QPromise<void>::reject(Data{42}).fail([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
@ -277,7 +277,7 @@ void tst_benchmark::errorThen()
|
|||||||
{ // should not copy error on continutation if rethrown
|
{ // should not copy error on continutation if rethrown
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<void>::reject(Data(42)).fail([](const Data&) {
|
QPromise<void>::reject(Data{42}).fail([](const Data&) {
|
||||||
throw;
|
throw;
|
||||||
}).fail([&](const Data& res) {
|
}).fail([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
|
@ -72,7 +72,7 @@ void tst_deprecations_helpers_qpromise::moveRValue()
|
|||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
{
|
{
|
||||||
auto p = qPromise(Data(42)).wait();
|
auto p = qPromise(Data{42}).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ void tst_deprecations_helpers_qpromise::copyLValue()
|
|||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
{
|
{
|
||||||
Data value(42);
|
Data value{42};
|
||||||
auto p = qPromise(value).wait();
|
auto p = qPromise(value).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
||||||
@ -119,8 +119,8 @@ void tst_deprecations_helpers_qpromise::qtSharedPtr()
|
|||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<QSharedPointer<Data>>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<QSharedPointer<Data>>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p1, QSharedPointer<Data>()), sptr0);
|
QCOMPARE(waitForValue(p1, QSharedPointer<Data>{}), sptr0);
|
||||||
QCOMPARE(waitForValue(p2, QSharedPointer<Data>()), sptr1);
|
QCOMPARE(waitForValue(p2, QSharedPointer<Data>{}), sptr1);
|
||||||
|
|
||||||
wptr = sptr0;
|
wptr = sptr0;
|
||||||
|
|
||||||
@ -155,8 +155,8 @@ void tst_deprecations_helpers_qpromise::stdSharedPtr()
|
|||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<std::shared_ptr<Data>>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<std::shared_ptr<Data>>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p1, std::shared_ptr<Data>()), sptr0);
|
QCOMPARE(waitForValue(p1, std::shared_ptr<Data>{}), sptr0);
|
||||||
QCOMPARE(waitForValue(p2, std::shared_ptr<Data>()), sptr1);
|
QCOMPARE(waitForValue(p2, std::shared_ptr<Data>{}), sptr1);
|
||||||
|
|
||||||
wptr = sptr0;
|
wptr = sptr0;
|
||||||
|
|
||||||
@ -180,10 +180,10 @@ void tst_deprecations_helpers_qpromise::typedPromise()
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
QPromise<int> v0(resolver);
|
QPromise<int> v0{resolver};
|
||||||
const QPromise<int> v1 = v0;
|
const QPromise<int> v1 = v0;
|
||||||
|
|
||||||
auto p0 = qPromise(QPromise<int>(resolver));
|
auto p0 = qPromise(QPromise<int>{resolver});
|
||||||
auto p1 = qPromise(v0);
|
auto p1 = qPromise(v0);
|
||||||
auto p2 = qPromise(v1);
|
auto p2 = qPromise(v1);
|
||||||
|
|
||||||
@ -207,10 +207,10 @@ void tst_deprecations_helpers_qpromise::voidPromise()
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
QPromise<void> v0(resolver);
|
QPromise<void> v0{resolver};
|
||||||
const QPromise<void> v1 = v0;
|
const QPromise<void> v1 = v0;
|
||||||
|
|
||||||
auto p0 = qPromise(QPromise<void>(resolver));
|
auto p0 = qPromise(QPromise<void>{resolver});
|
||||||
auto p1 = qPromise(v0);
|
auto p1 = qPromise(v0);
|
||||||
auto p2 = qPromise(v1);
|
auto p2 = qPromise(v1);
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ struct SequenceTester
|
|||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 46, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 46, 43, 44}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ void tst_deprecations_helpers_qpromiseall::emptySequence()
|
|||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_deprecations_helpers_qpromiseall::emptySequence_void()
|
void tst_deprecations_helpers_qpromiseall::emptySequence_void()
|
||||||
@ -105,11 +105,11 @@ void tst_deprecations_helpers_qpromiseall::allPromisesSucceed()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve(42);
|
auto p0 = QtPromise::resolve(42);
|
||||||
auto p1 = QtPromise::resolve(44);
|
auto p1 = QtPromise::resolve(44);
|
||||||
auto p2 = QPromise<int>([](const QPromiseResolve<int>& resolve) {
|
auto p2 = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=](){
|
QtPromisePrivate::qtpromise_defer([=](){
|
||||||
resolve(43);
|
resolve(43);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
auto p = qPromiseAll(QVector<QPromise<int>>{p0, p2, p1});
|
auto p = qPromiseAll(QVector<QPromise<int>>{p0, p2, p1});
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ void tst_deprecations_helpers_qpromiseall::allPromisesSucceed()
|
|||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(p2.isFulfilled(), true);
|
QCOMPARE(p2.isFulfilled(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,11 +126,11 @@ void tst_deprecations_helpers_qpromiseall::allPromisesSucceed_void()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve();
|
auto p0 = QtPromise::resolve();
|
||||||
auto p1 = QtPromise::resolve();
|
auto p1 = QtPromise::resolve();
|
||||||
auto p2 = QPromise<void>([](const QPromiseResolve<void>& resolve) {
|
auto p2 = QPromise<void>{[](const QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=](){
|
QtPromisePrivate::qtpromise_defer([=](){
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
auto p = qPromiseAll(QVector<QPromise<void>>{p0, p2, p1});
|
auto p = qPromiseAll(QVector<QPromise<void>>{p0, p2, p1});
|
||||||
|
|
||||||
@ -147,11 +147,11 @@ void tst_deprecations_helpers_qpromiseall::atLeastOnePromiseReject()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve(42);
|
auto p0 = QtPromise::resolve(42);
|
||||||
auto p1 = QtPromise::resolve(44);
|
auto p1 = QtPromise::resolve(44);
|
||||||
auto p2 = QPromise<int>([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
auto p2 = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=](){
|
QtPromisePrivate::qtpromise_defer([=](){
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p = qPromiseAll(QVector<QPromise<int>>{p0, p2, p1});
|
auto p = qPromiseAll(QVector<QPromise<int>>{p0, p2, p1});
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ void tst_deprecations_helpers_qpromiseall::atLeastOnePromiseReject()
|
|||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p2.isRejected(), true);
|
QCOMPARE(p2.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,11 +168,11 @@ void tst_deprecations_helpers_qpromiseall::atLeastOnePromiseReject_void()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve();
|
auto p0 = QtPromise::resolve();
|
||||||
auto p1 = QtPromise::resolve();
|
auto p1 = QtPromise::resolve();
|
||||||
auto p2 = QPromise<void>([](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
auto p2 = QPromise<void>{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=](){
|
QtPromisePrivate::qtpromise_defer([=](){
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p = qPromiseAll(QVector<QPromise<void>>{p0, p2, p1});
|
auto p = qPromiseAll(QVector<QPromise<void>>{p0, p2, p1});
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ void tst_deprecations_helpers_qpromiseall::atLeastOnePromiseReject_void()
|
|||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p2.isRejected(), true);
|
QCOMPARE(p2.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ void tst_deprecations_helpers_qpromiseall::preserveOrder()
|
|||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isFulfilled(), true);
|
QCOMPARE(p2.isFulfilled(), true);
|
||||||
|
@ -55,7 +55,7 @@ struct SequenceTester
|
|||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 46, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 46, 43, 44}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ void tst_deprecations_qpromise_all::emptySequence()
|
|||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>{});
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_deprecations_qpromise_all::emptySequence_void()
|
void tst_deprecations_qpromise_all::emptySequence_void()
|
||||||
@ -109,11 +109,11 @@ void tst_deprecations_qpromise_all::allPromisesSucceed()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve(42);
|
auto p0 = QtPromise::resolve(42);
|
||||||
auto p1 = QtPromise::resolve(44);
|
auto p1 = QtPromise::resolve(44);
|
||||||
auto p2 = QPromise<int>([](const QPromiseResolve<int>& resolve) {
|
auto p2 = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=](){
|
QtPromisePrivate::qtpromise_defer([=](){
|
||||||
resolve(43);
|
resolve(43);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
auto p = QPromise<int>::all(QVector<QPromise<int>>{p0, p2, p1});
|
auto p = QPromise<int>::all(QVector<QPromise<int>>{p0, p2, p1});
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ void tst_deprecations_qpromise_all::allPromisesSucceed()
|
|||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(p2.isFulfilled(), true);
|
QCOMPARE(p2.isFulfilled(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,11 +131,11 @@ void tst_deprecations_qpromise_all::allPromisesSucceed_void()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve();
|
auto p0 = QtPromise::resolve();
|
||||||
auto p1 = QtPromise::resolve();
|
auto p1 = QtPromise::resolve();
|
||||||
auto p2 = QPromise<void>([](const QPromiseResolve<void>& resolve) {
|
auto p2 = QPromise<void>{[](const QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=](){
|
QtPromisePrivate::qtpromise_defer([=](){
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
auto p = QPromise<void>::all(QVector<QPromise<void>>{p0, p2, p1});
|
auto p = QPromise<void>::all(QVector<QPromise<void>>{p0, p2, p1});
|
||||||
|
|
||||||
@ -153,11 +153,11 @@ void tst_deprecations_qpromise_all::atLeastOnePromiseReject()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve(42);
|
auto p0 = QtPromise::resolve(42);
|
||||||
auto p1 = QtPromise::resolve(44);
|
auto p1 = QtPromise::resolve(44);
|
||||||
auto p2 = QPromise<int>([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
auto p2 = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=](){
|
QtPromisePrivate::qtpromise_defer([=](){
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p = QPromise<int>::all(QVector<QPromise<int>>{p0, p2, p1});
|
auto p = QPromise<int>::all(QVector<QPromise<int>>{p0, p2, p1});
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ void tst_deprecations_qpromise_all::atLeastOnePromiseReject()
|
|||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p2.isRejected(), true);
|
QCOMPARE(p2.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,11 +175,11 @@ void tst_deprecations_qpromise_all::atLeastOnePromiseReject_void()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve();
|
auto p0 = QtPromise::resolve();
|
||||||
auto p1 = QtPromise::resolve();
|
auto p1 = QtPromise::resolve();
|
||||||
auto p2 = QPromise<void>([](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
auto p2 = QPromise<void>{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=](){
|
QtPromisePrivate::qtpromise_defer([=](){
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p = QPromise<void>::all(QVector<QPromise<void>>{p0, p2, p1});
|
auto p = QPromise<void>::all(QVector<QPromise<void>>{p0, p2, p1});
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ void tst_deprecations_qpromise_all::atLeastOnePromiseReject_void()
|
|||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p2.isRejected(), true);
|
QCOMPARE(p2.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ void tst_deprecations_qpromise_all::preserveOrder()
|
|||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isFulfilled(), true);
|
QCOMPARE(p2.isFulfilled(), true);
|
||||||
|
@ -38,13 +38,13 @@ class MyException : public QException
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyException(const QString& error)
|
MyException(const QString& error)
|
||||||
: m_error(error)
|
: m_error{error}
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
const QString& error() const { return m_error; }
|
const QString& error() const { return m_error; }
|
||||||
|
|
||||||
void raise() const { throw *this; }
|
void raise() const { throw *this; }
|
||||||
MyException* clone() const { return new MyException(*this); }
|
MyException* clone() const { return new MyException{*this}; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_error;
|
QString m_error;
|
||||||
@ -91,7 +91,7 @@ void tst_future::rejected()
|
|||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
auto p = QtPromise::resolve(QtConcurrent::run([]() {
|
auto p = QtPromise::resolve(QtConcurrent::run([]() {
|
||||||
throw MyException("foo");
|
throw MyException{"foo"};
|
||||||
return 42;
|
return 42;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -104,14 +104,14 @@ void tst_future::rejected()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(error, QString("foo"));
|
QCOMPARE(error, QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_future::rejected_void()
|
void tst_future::rejected_void()
|
||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
auto p = QtPromise::resolve(QtConcurrent::run([]() {
|
auto p = QtPromise::resolve(QtConcurrent::run([]() {
|
||||||
throw MyException("foo");
|
throw MyException{"foo"};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
||||||
@ -123,14 +123,14 @@ void tst_future::rejected_void()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(error, QString("foo"));
|
QCOMPARE(error, QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_future::unhandled()
|
void tst_future::unhandled()
|
||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
auto p = QtPromise::resolve(QtConcurrent::run([]() {
|
auto p = QtPromise::resolve(QtConcurrent::run([]() {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
return 42;
|
return 42;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -147,14 +147,14 @@ void tst_future::unhandled()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(error, QString("bar"));
|
QCOMPARE(error, QString{"bar"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_future::unhandled_void()
|
void tst_future::unhandled_void()
|
||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
auto p = QtPromise::resolve(QtConcurrent::run([]() {
|
auto p = QtPromise::resolve(QtConcurrent::run([]() {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
||||||
@ -167,7 +167,7 @@ void tst_future::unhandled_void()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(error, QString("bar"));
|
QCOMPARE(error, QString{"bar"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_future::canceled()
|
void tst_future::canceled()
|
||||||
@ -183,7 +183,7 @@ void tst_future::canceled()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(error, QString("canceled"));
|
QCOMPARE(error, QString{"canceled"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_future::canceled_void()
|
void tst_future::canceled_void()
|
||||||
@ -198,14 +198,14 @@ void tst_future::canceled_void()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(error, QString("canceled"));
|
QCOMPARE(error, QString{"canceled"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_future::canceledFromThread()
|
void tst_future::canceledFromThread()
|
||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
auto p = QtPromise::resolve(QtConcurrent::run([]() {
|
auto p = QtPromise::resolve(QtConcurrent::run([]() {
|
||||||
throw QPromiseCanceledException();
|
throw QPromiseCanceledException{};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
@ -215,7 +215,7 @@ void tst_future::canceledFromThread()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(error, QString("bar"));
|
QCOMPARE(error, QString{"bar"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_future::then()
|
void tst_future::then()
|
||||||
@ -224,7 +224,7 @@ void tst_future::then()
|
|||||||
auto input = QtPromise::resolve(42);
|
auto input = QtPromise::resolve(42);
|
||||||
auto output = input.then([](int res) {
|
auto output = input.then([](int res) {
|
||||||
return QtConcurrent::run([=]() {
|
return QtConcurrent::run([=]() {
|
||||||
return QString("foo%1").arg(res);
|
return QString{"foo%1"}.arg(res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ void tst_future::then()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(output.isFulfilled(), true);
|
QCOMPARE(output.isFulfilled(), true);
|
||||||
QCOMPARE(result, QString("foo42"));
|
QCOMPARE(result, QString{"foo42"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_future::then_void()
|
void tst_future::then_void()
|
||||||
@ -257,16 +257,16 @@ void tst_future::then_void()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(input.isFulfilled(), true);
|
QCOMPARE(input.isFulfilled(), true);
|
||||||
QCOMPARE(result, QString("foobar"));
|
QCOMPARE(result, QString{"foobar"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_future::fail()
|
void tst_future::fail()
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
auto input = QPromise<QString>::reject(MyException("bar"));
|
auto input = QPromise<QString>::reject(MyException{"bar"});
|
||||||
auto output = input.fail([](const MyException& e) {
|
auto output = input.fail([](const MyException& e) {
|
||||||
return QtConcurrent::run([](const QString& error) {
|
return QtConcurrent::run([](const QString& error) {
|
||||||
return QString("foo%1").arg(error);
|
return QString{"foo%1"}.arg(error);
|
||||||
}, e.error());
|
}, e.error());
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -278,13 +278,13 @@ void tst_future::fail()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(output.isFulfilled(), true);
|
QCOMPARE(output.isFulfilled(), true);
|
||||||
QCOMPARE(result, QString("foobar"));
|
QCOMPARE(result, QString{"foobar"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_future::fail_void()
|
void tst_future::fail_void()
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
auto input = QPromise<void>::reject(MyException("bar"));
|
auto input = QPromise<void>::reject(MyException{"bar"});
|
||||||
auto output = input.fail([&](const MyException& e) {
|
auto output = input.fail([&](const MyException& e) {
|
||||||
return QtConcurrent::run([&](const QString& error) {
|
return QtConcurrent::run([&](const QString& error) {
|
||||||
result = error;
|
result = error;
|
||||||
@ -299,7 +299,7 @@ void tst_future::fail_void()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(output.isFulfilled(), true);
|
QCOMPARE(output.isFulfilled(), true);
|
||||||
QCOMPARE(result, QString("foobar"));
|
QCOMPARE(result, QString{"foobar"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_future::finally()
|
void tst_future::finally()
|
||||||
@ -307,7 +307,7 @@ void tst_future::finally()
|
|||||||
auto input = QtPromise::resolve(42);
|
auto input = QtPromise::resolve(42);
|
||||||
auto output = input.finally([]() {
|
auto output = input.finally([]() {
|
||||||
return QtConcurrent::run([]() {
|
return QtConcurrent::run([]() {
|
||||||
return QString("foo");
|
return QString{"foo"};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -330,7 +330,7 @@ void tst_future::finallyRejected()
|
|||||||
auto input = QtPromise::resolve(42);
|
auto input = QtPromise::resolve(42);
|
||||||
auto output = input.finally([]() {
|
auto output = input.finally([]() {
|
||||||
return QtConcurrent::run([]() {
|
return QtConcurrent::run([]() {
|
||||||
throw MyException("foo");
|
throw MyException{"foo"};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -346,5 +346,5 @@ void tst_future::finallyRejected()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(output.isRejected(), true);
|
QCOMPARE(output.isRejected(), true);
|
||||||
QCOMPARE(error, QString("foo"));
|
QCOMPARE(error, QString{"foo"});
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ struct SequenceTester
|
|||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 46, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 46, 43, 44}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ void tst_helpers_all::emptySequence()
|
|||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_all::emptySequence_void()
|
void tst_helpers_all::emptySequence_void()
|
||||||
@ -105,11 +105,11 @@ void tst_helpers_all::allPromisesSucceed()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve(42);
|
auto p0 = QtPromise::resolve(42);
|
||||||
auto p1 = QtPromise::resolve(44);
|
auto p1 = QtPromise::resolve(44);
|
||||||
auto p2 = QPromise<int>([](const QPromiseResolve<int>& resolve) {
|
auto p2 = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=](){
|
QtPromisePrivate::qtpromise_defer([=](){
|
||||||
resolve(43);
|
resolve(43);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
auto p = QtPromise::all(QVector<QPromise<int>>{p0, p2, p1});
|
auto p = QtPromise::all(QVector<QPromise<int>>{p0, p2, p1});
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ void tst_helpers_all::allPromisesSucceed()
|
|||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(p2.isFulfilled(), true);
|
QCOMPARE(p2.isFulfilled(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,11 +126,11 @@ void tst_helpers_all::allPromisesSucceed_void()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve();
|
auto p0 = QtPromise::resolve();
|
||||||
auto p1 = QtPromise::resolve();
|
auto p1 = QtPromise::resolve();
|
||||||
auto p2 = QPromise<void>([](const QPromiseResolve<void>& resolve) {
|
auto p2 = QPromise<void>{[](const QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=](){
|
QtPromisePrivate::qtpromise_defer([=](){
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
auto p = QtPromise::all(QVector<QPromise<void>>{p0, p2, p1});
|
auto p = QtPromise::all(QVector<QPromise<void>>{p0, p2, p1});
|
||||||
|
|
||||||
@ -147,11 +147,11 @@ void tst_helpers_all::atLeastOnePromiseReject()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve(42);
|
auto p0 = QtPromise::resolve(42);
|
||||||
auto p1 = QtPromise::resolve(44);
|
auto p1 = QtPromise::resolve(44);
|
||||||
auto p2 = QPromise<int>([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
auto p2 = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=](){
|
QtPromisePrivate::qtpromise_defer([=](){
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p = QtPromise::all(QVector<QPromise<int>>{p0, p2, p1});
|
auto p = QtPromise::all(QVector<QPromise<int>>{p0, p2, p1});
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ void tst_helpers_all::atLeastOnePromiseReject()
|
|||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p2.isRejected(), true);
|
QCOMPARE(p2.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,11 +168,11 @@ void tst_helpers_all::atLeastOnePromiseReject_void()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve();
|
auto p0 = QtPromise::resolve();
|
||||||
auto p1 = QtPromise::resolve();
|
auto p1 = QtPromise::resolve();
|
||||||
auto p2 = QPromise<void>([](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
auto p2 = QPromise<void>{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=](){
|
QtPromisePrivate::qtpromise_defer([=](){
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p = QtPromise::all(QVector<QPromise<void>>{p0, p2, p1});
|
auto p = QtPromise::all(QVector<QPromise<void>>{p0, p2, p1});
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ void tst_helpers_all::atLeastOnePromiseReject_void()
|
|||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p2.isRejected(), true);
|
QCOMPARE(p2.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ void tst_helpers_all::preserveOrder()
|
|||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isFulfilled(), true);
|
QCOMPARE(p2.isFulfilled(), true);
|
||||||
|
@ -43,25 +43,25 @@ void tst_helpers_attempt::voidResult()
|
|||||||
void tst_helpers_attempt::typedResult()
|
void tst_helpers_attempt::typedResult()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::attempt([]() {
|
auto p = QtPromise::attempt([]() {
|
||||||
return QString("foo");
|
return QString{"foo"};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, QString()), QString("foo"));
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_attempt::futureResult()
|
void tst_helpers_attempt::futureResult()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::attempt([]() {
|
auto p = QtPromise::attempt([]() {
|
||||||
return QtConcurrent::run([]() {
|
return QtConcurrent::run([]() {
|
||||||
return QString("foo");
|
return QString{"foo"};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QString()), QString("foo"));
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_attempt::promiseResult()
|
void tst_helpers_attempt::promiseResult()
|
||||||
@ -79,23 +79,23 @@ void tst_helpers_attempt::functorThrows()
|
|||||||
{
|
{
|
||||||
auto p = QtPromise::attempt([]() {
|
auto p = QtPromise::attempt([]() {
|
||||||
if (true) {
|
if (true) {
|
||||||
throw QString("bar");
|
throw QString{"bar"};
|
||||||
}
|
}
|
||||||
return 42;
|
return 42;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("bar"));
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_attempt::callWithParams()
|
void tst_helpers_attempt::callWithParams()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::attempt([&](int i, const QString& s) {
|
auto p = QtPromise::attempt([&](int i, const QString& s) {
|
||||||
return QString("%1:%2").arg(i).arg(s);
|
return QString{"%1:%2"}.arg(i).arg(s);
|
||||||
}, 42, "foo");
|
}, 42, "foo");
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, QString()), QString("42:foo"));
|
QCOMPARE(waitForValue(p, QString{}), QString{"42:foo"});
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ void tst_helpers_connect::resolveOneSenderOneArg()
|
|||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
||||||
QCOMPARE(sender.hasConnections(), true);
|
QCOMPARE(sender.hasConnections(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QString()), QString("foo"));
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(sender.hasConnections(), false);
|
QCOMPARE(sender.hasConnections(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ void tst_helpers_connect::rejectOneSenderOneArg()
|
|||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
||||||
QCOMPARE(sender.hasConnections(), true);
|
QCOMPARE(sender.hasConnections(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("bar"));
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(sender.hasConnections(), false);
|
QCOMPARE(sender.hasConnections(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ void tst_helpers_connect::rejectOneSenderManyArgs()
|
|||||||
|
|
||||||
void tst_helpers_connect::rejectOneSenderDestroyed()
|
void tst_helpers_connect::rejectOneSenderDestroyed()
|
||||||
{
|
{
|
||||||
Object* sender = new Object();
|
auto sender = new Object{};
|
||||||
QtPromisePrivate::qtpromise_defer([&]() {
|
QtPromisePrivate::qtpromise_defer([&]() {
|
||||||
sender->deleteLater();
|
sender->deleteLater();
|
||||||
});
|
});
|
||||||
@ -171,7 +171,7 @@ void tst_helpers_connect::rejectTwoSendersOneArg()
|
|||||||
QCOMPARE(s0.hasConnections(), true);
|
QCOMPARE(s0.hasConnections(), true);
|
||||||
QCOMPARE(s1.hasConnections(), true);
|
QCOMPARE(s1.hasConnections(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("bar"));
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(s0.hasConnections(), false);
|
QCOMPARE(s0.hasConnections(), false);
|
||||||
QCOMPARE(s1.hasConnections(), false);
|
QCOMPARE(s1.hasConnections(), false);
|
||||||
}
|
}
|
||||||
@ -195,8 +195,8 @@ void tst_helpers_connect::rejectTwoSendersManyArgs()
|
|||||||
|
|
||||||
void tst_helpers_connect::rejectTwoSendersDestroyed()
|
void tst_helpers_connect::rejectTwoSendersDestroyed()
|
||||||
{
|
{
|
||||||
Object* s0 = new Object();
|
auto s0 = new Object{};
|
||||||
Object* s1 = new Object();
|
auto s1 = new Object{};
|
||||||
|
|
||||||
QtPromisePrivate::qtpromise_defer([&]() {
|
QtPromisePrivate::qtpromise_defer([&]() {
|
||||||
QObject::connect(s1, &QObject::destroyed, [&]() {
|
QObject::connect(s1, &QObject::destroyed, [&]() {
|
||||||
|
@ -43,8 +43,8 @@ struct SequenceTester
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Sequence>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Sequence>>::value));
|
||||||
QCOMPARE(waitForValue(p, Sequence()), Sequence({42, 43, 44}));
|
QCOMPARE(waitForValue(p, Sequence{}), (Sequence{42, 43, 44}));
|
||||||
QCOMPARE(values, QVector<int>({0, 42, 1, 43, 2, 44}));
|
QCOMPARE(values, (QVector<int>{0, 42, 1, 43, 2, 44}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -58,8 +58,8 @@ void tst_helpers_each::emptySequence()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>());
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
QCOMPARE(values, QVector<int>({}));
|
QCOMPARE(values, QVector<int>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_each::preserveValues()
|
void tst_helpers_each::preserveValues()
|
||||||
@ -70,8 +70,8 @@ void tst_helpers_each::preserveValues()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(values, QVector<int>({43, 44, 45}));
|
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_each::ignoreResult()
|
void tst_helpers_each::ignoreResult()
|
||||||
@ -83,24 +83,24 @@ void tst_helpers_each::ignoreResult()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(values, QVector<int>({43, 44, 45}));
|
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_each::delayedFulfilled()
|
void tst_helpers_each::delayedFulfilled()
|
||||||
{
|
{
|
||||||
QMap<int, int> values;
|
QMap<int, int> values;
|
||||||
auto p = QtPromise::each(QVector<int>{42, 43, 44}, [&](int v, int index) {
|
auto p = QtPromise::each(QVector<int>{42, 43, 44}, [&](int v, int index) {
|
||||||
return QPromise<int>([&](const QPromiseResolve<int>& resolve) {
|
return QPromise<int>{[&](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values[v] = index;
|
values[v] = index;
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
||||||
QCOMPARE(values, expected);
|
QCOMPARE(values, expected);
|
||||||
}
|
}
|
||||||
@ -108,32 +108,32 @@ void tst_helpers_each::delayedFulfilled()
|
|||||||
void tst_helpers_each::delayedRejected()
|
void tst_helpers_each::delayedRejected()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::each(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::each(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
return QPromise<int>([&](
|
return QPromise<int>{[&](
|
||||||
const QPromiseResolve<int>& resolve,
|
const QPromiseResolve<int>& resolve,
|
||||||
const QPromiseReject<int>& reject) {
|
const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
if (v == 43) {
|
if (v == 43) {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
resolve(v);
|
resolve(v);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_each::functorThrows()
|
void tst_helpers_each::functorThrows()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::each(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::each(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
if (v == 44) {
|
if (v == 44) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_each::functorArguments()
|
void tst_helpers_each::functorArguments()
|
||||||
@ -144,8 +144,8 @@ void tst_helpers_each::functorArguments()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(values, QVector<int>({0, 42, 1, 43, 2, 44}));
|
QCOMPARE(values, (QVector<int>{0, 42, 1, 43, 2, 44}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_each::sequenceTypes()
|
void tst_helpers_each::sequenceTypes()
|
||||||
|
@ -44,7 +44,7 @@ struct SequenceTester
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Sequence>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Sequence>>::value));
|
||||||
QCOMPARE(waitForValue(p, Sequence()), Sequence({42, 45, 48, 51}));
|
QCOMPARE(waitForValue(p, Sequence{}), (Sequence{42, 45, 48, 51}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ void tst_helpers_filter::emptySequence()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>{});
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_filter::filterValues()
|
void tst_helpers_filter::filterValues()
|
||||||
@ -67,53 +67,53 @@ void tst_helpers_filter::filterValues()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_filter::delayedFulfilled()
|
void tst_helpers_filter::delayedFulfilled()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::filter(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::filter(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
return QPromise<bool>([&](const QPromiseResolve<bool>& resolve) {
|
return QPromise<bool>{[&](const QPromiseResolve<bool>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(v % 2 == 0);
|
resolve(v % 2 == 0);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_filter::delayedRejected()
|
void tst_helpers_filter::delayedRejected()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::filter(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::filter(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
return QPromise<bool>([&](
|
return QPromise<bool>{[&](
|
||||||
const QPromiseResolve<bool>& resolve,
|
const QPromiseResolve<bool>& resolve,
|
||||||
const QPromiseReject<bool>& reject) {
|
const QPromiseReject<bool>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
if (v == 44) {
|
if (v == 44) {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_filter::functorThrows()
|
void tst_helpers_filter::functorThrows()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::filter(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::filter(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
if (v == 44) {
|
if (v == 44) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_filter::functorArguments()
|
void tst_helpers_filter::functorArguments()
|
||||||
@ -125,7 +125,7 @@ void tst_helpers_filter::functorArguments()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
||||||
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
||||||
QCOMPARE(args, expected);
|
QCOMPARE(args, expected);
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ void tst_helpers_filter::preserveOrder()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({500, 300, 250, 400}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{500, 300, 250, 400}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_filter::sequenceTypes()
|
void tst_helpers_filter::sequenceTypes()
|
||||||
|
@ -43,7 +43,7 @@ struct SequenceTester
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<QString>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<QString>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<QString>()), QVector<QString>({"43", "44", "45"}));
|
QCOMPARE(waitForValue(p, QVector<QString>{}), (QVector<QString>{"43", "44", "45"}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ void tst_helpers_map::emptySequence()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_map::modifyValues()
|
void tst_helpers_map::modifyValues()
|
||||||
@ -66,7 +66,7 @@ void tst_helpers_map::modifyValues()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({43, 44, 45}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_map::convertValues()
|
void tst_helpers_map::convertValues()
|
||||||
@ -76,53 +76,53 @@ void tst_helpers_map::convertValues()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<QString>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<QString>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<QString>()), QVector<QString>({"43", "44", "45"}));
|
QCOMPARE(waitForValue(p, QVector<QString>{}), (QVector<QString>{"43", "44", "45"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_map::delayedFulfilled()
|
void tst_helpers_map::delayedFulfilled()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::map(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::map(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
return QPromise<int>([&](const QPromiseResolve<int>& resolve) {
|
return QPromise<int>{[&](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(v + 1);
|
resolve(v + 1);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({43, 44, 45}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_map::delayedRejected()
|
void tst_helpers_map::delayedRejected()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::map(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::map(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
return QPromise<int>([&](
|
return QPromise<int>{[&](
|
||||||
const QPromiseResolve<int>& resolve,
|
const QPromiseResolve<int>& resolve,
|
||||||
const QPromiseReject<int>& reject) {
|
const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
if (v == 43) {
|
if (v == 43) {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
resolve(v);
|
resolve(v);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_map::functorThrows()
|
void tst_helpers_map::functorThrows()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::map(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::map(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
if (v == 43) {
|
if (v == 43) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
}
|
}
|
||||||
return v + 1;
|
return v + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_map::functorArguments()
|
void tst_helpers_map::functorArguments()
|
||||||
@ -132,7 +132,7 @@ void tst_helpers_map::functorArguments()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({0, 42, 84}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{0, 42, 84}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_map::preserveOrder()
|
void tst_helpers_map::preserveOrder()
|
||||||
@ -142,7 +142,7 @@ void tst_helpers_map::preserveOrder()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({501, 101, 251}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{501, 101, 251}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_map::sequenceTypes()
|
void tst_helpers_map::sequenceTypes()
|
||||||
|
@ -63,8 +63,8 @@ struct SequenceTester
|
|||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1), 21);
|
QCOMPARE(waitForValue(p0, -1), 21);
|
||||||
QCOMPARE(waitForValue(p1, -1), 23);
|
QCOMPARE(waitForValue(p1, -1), 23);
|
||||||
QCOMPARE(v0, QVector<int>({4, 6, 1, 11, 8, 2}));
|
QCOMPARE(v0, (QVector<int>{4, 6, 1, 11, 8, 2}));
|
||||||
QCOMPARE(v1, QVector<int>({2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
QCOMPARE(v1, (QVector<int>{2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -109,8 +109,8 @@ void tst_helpers_reduce::regularValues()
|
|||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1), 21);
|
QCOMPARE(waitForValue(p0, -1), 21);
|
||||||
QCOMPARE(waitForValue(p1, -1), 23);
|
QCOMPARE(waitForValue(p1, -1), 23);
|
||||||
QCOMPARE(v0, QVector<int>({4, 6, 1, 11, 8, 2}));
|
QCOMPARE(v0, (QVector<int>{4, 6, 1, 11, 8, 2}));
|
||||||
QCOMPARE(v1, QVector<int>({2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
QCOMPARE(v1, (QVector<int>{2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_reduce::promiseValues()
|
void tst_helpers_reduce::promiseValues()
|
||||||
@ -139,8 +139,8 @@ void tst_helpers_reduce::promiseValues()
|
|||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1), 21);
|
QCOMPARE(waitForValue(p0, -1), 21);
|
||||||
QCOMPARE(waitForValue(p1, -1), 23);
|
QCOMPARE(waitForValue(p1, -1), 23);
|
||||||
QCOMPARE(v0, QVector<int>({4, 6, 1, 11, 8, 2}));
|
QCOMPARE(v0, (QVector<int>{4, 6, 1, 11, 8, 2}));
|
||||||
QCOMPARE(v1, QVector<int>({2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
QCOMPARE(v1, (QVector<int>{2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_reduce::convertResultType()
|
void tst_helpers_reduce::convertResultType()
|
||||||
@ -148,15 +148,15 @@ void tst_helpers_reduce::convertResultType()
|
|||||||
QVector<int> inputs{4, 6, 8};
|
QVector<int> inputs{4, 6, 8};
|
||||||
|
|
||||||
auto p = QtPromise::reduce(inputs, [&](const QString& acc, int cur, int idx) {
|
auto p = QtPromise::reduce(inputs, [&](const QString& acc, int cur, int idx) {
|
||||||
return QString("%1:%2:%3").arg(acc).arg(cur).arg(idx);
|
return QString{"%1:%2:%3"}.arg(acc).arg(cur).arg(idx);
|
||||||
}, QString("foo"));
|
}, QString{"foo"});
|
||||||
|
|
||||||
// NOTE(SB): when no initial value is given, the result type is the sequence type.
|
// NOTE(SB): when no initial value is given, the result type is the sequence type.
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QString()), QString("foo:4:0:6:1:8:2"));
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo:4:0:6:1:8:2"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_reduce::delayedInitialValue()
|
void tst_helpers_reduce::delayedInitialValue()
|
||||||
@ -172,7 +172,7 @@ void tst_helpers_reduce::delayedInitialValue()
|
|||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), 23);
|
QCOMPARE(waitForValue(p, -1), 23);
|
||||||
QCOMPARE(values, QVector<int>({2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
QCOMPARE(values, (QVector<int>{2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_reduce::delayedFulfilled()
|
void tst_helpers_reduce::delayedFulfilled()
|
||||||
@ -197,8 +197,8 @@ void tst_helpers_reduce::delayedFulfilled()
|
|||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1), 21);
|
QCOMPARE(waitForValue(p0, -1), 21);
|
||||||
QCOMPARE(waitForValue(p1, -1), 23);
|
QCOMPARE(waitForValue(p1, -1), 23);
|
||||||
QCOMPARE(v0, QVector<int>({4, 6, 1, 11, 8, 2}));
|
QCOMPARE(v0, (QVector<int>{4, 6, 1, 11, 8, 2}));
|
||||||
QCOMPARE(v1, QVector<int>({2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
QCOMPARE(v1, (QVector<int>{2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_reduce::delayedRejected()
|
void tst_helpers_reduce::delayedRejected()
|
||||||
@ -210,14 +210,14 @@ void tst_helpers_reduce::delayedRejected()
|
|||||||
auto p0 = QtPromise::reduce(inputs, [&](int acc, int cur, int idx) {
|
auto p0 = QtPromise::reduce(inputs, [&](int acc, int cur, int idx) {
|
||||||
v0 << acc << cur << idx;
|
v0 << acc << cur << idx;
|
||||||
if (cur == 6) {
|
if (cur == 6) {
|
||||||
return QPromise<int>::reject(QString("foo"));
|
return QPromise<int>::reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
return QtPromise::resolve(acc + cur + idx);
|
return QtPromise::resolve(acc + cur + idx);
|
||||||
});
|
});
|
||||||
auto p1 = QtPromise::reduce(inputs, [&](int acc, int cur, int idx) {
|
auto p1 = QtPromise::reduce(inputs, [&](int acc, int cur, int idx) {
|
||||||
v1 << acc << cur << idx;
|
v1 << acc << cur << idx;
|
||||||
if (cur == 6) {
|
if (cur == 6) {
|
||||||
return QPromise<int>::reject(QString("bar"));
|
return QPromise<int>::reject(QString{"bar"});
|
||||||
}
|
}
|
||||||
return QtPromise::resolve(acc + cur + idx);
|
return QtPromise::resolve(acc + cur + idx);
|
||||||
}, 2);
|
}, 2);
|
||||||
@ -227,10 +227,10 @@ void tst_helpers_reduce::delayedRejected()
|
|||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(waitForError(p0, QString()), QString("foo"));
|
QCOMPARE(waitForError(p0, QString{}), QString{"foo"});
|
||||||
QCOMPARE(waitForError(p1, QString()), QString("bar"));
|
QCOMPARE(waitForError(p1, QString{}), QString{"bar"});
|
||||||
QCOMPARE(v0, QVector<int>({4, 6, 1}));
|
QCOMPARE(v0, (QVector<int>{4, 6, 1}));
|
||||||
QCOMPARE(v1, QVector<int>({2, 4, 0, 6, 6, 1}));
|
QCOMPARE(v1, (QVector<int>{2, 4, 0, 6, 6, 1}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_reduce::functorThrows()
|
void tst_helpers_reduce::functorThrows()
|
||||||
@ -242,14 +242,14 @@ void tst_helpers_reduce::functorThrows()
|
|||||||
auto p0 = QtPromise::reduce(inputs, [&](int acc, int cur, int idx) {
|
auto p0 = QtPromise::reduce(inputs, [&](int acc, int cur, int idx) {
|
||||||
v0 << acc << cur << idx;
|
v0 << acc << cur << idx;
|
||||||
if (cur == 6) {
|
if (cur == 6) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
}
|
}
|
||||||
return acc + cur + idx;
|
return acc + cur + idx;
|
||||||
});
|
});
|
||||||
auto p1 = QtPromise::reduce(inputs, [&](int acc, int cur, int idx) {
|
auto p1 = QtPromise::reduce(inputs, [&](int acc, int cur, int idx) {
|
||||||
v1 << acc << cur << idx;
|
v1 << acc << cur << idx;
|
||||||
if (cur == 6) {
|
if (cur == 6) {
|
||||||
throw QString("bar");
|
throw QString{"bar"};
|
||||||
}
|
}
|
||||||
return acc + cur + idx;
|
return acc + cur + idx;
|
||||||
}, 2);
|
}, 2);
|
||||||
@ -259,10 +259,10 @@ void tst_helpers_reduce::functorThrows()
|
|||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(waitForError(p0, QString()), QString("foo"));
|
QCOMPARE(waitForError(p0, QString{}), QString{"foo"});
|
||||||
QCOMPARE(waitForError(p1, QString()), QString("bar"));
|
QCOMPARE(waitForError(p1, QString{}), QString{"bar"});
|
||||||
QCOMPARE(v0, QVector<int>({4, 6, 1}));
|
QCOMPARE(v0, (QVector<int>{4, 6, 1}));
|
||||||
QCOMPARE(v1, QVector<int>({2, 4, 0, 6, 6, 1}));
|
QCOMPARE(v1, (QVector<int>{2, 4, 0, 6, 6, 1}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_reduce::sequenceTypes()
|
void tst_helpers_reduce::sequenceTypes()
|
||||||
|
@ -44,7 +44,7 @@ void tst_helpers_reject::rejectWithQSharedPtr()
|
|||||||
auto sptr = QSharedPointer<int>::create(42);
|
auto sptr = QSharedPointer<int>::create(42);
|
||||||
auto p = QPromise<int>::reject(sptr);
|
auto p = QPromise<int>::reject(sptr);
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QSharedPointer<int>()), sptr);
|
QCOMPARE(waitForError(p, QSharedPointer<int>{}), sptr);
|
||||||
|
|
||||||
wptr = sptr;
|
wptr = sptr;
|
||||||
sptr.reset();
|
sptr.reset();
|
||||||
@ -64,7 +64,7 @@ void tst_helpers_reject::rejectWithStdSharedPtr()
|
|||||||
auto sptr = std::make_shared<int>(42);
|
auto sptr = std::make_shared<int>(42);
|
||||||
auto p = QPromise<int>::reject(sptr);
|
auto p = QPromise<int>::reject(sptr);
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, std::shared_ptr<int>()), sptr);
|
QCOMPARE(waitForError(p, std::shared_ptr<int>{}), sptr);
|
||||||
|
|
||||||
wptr = sptr;
|
wptr = sptr;
|
||||||
sptr.reset();
|
sptr.reset();
|
||||||
|
@ -72,7 +72,7 @@ void tst_helpers_resolve::moveRValue()
|
|||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
{
|
{
|
||||||
auto p = QtPromise::resolve(Data(42)).wait();
|
auto p = QtPromise::resolve(Data{42}).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ void tst_helpers_resolve::copyLValue()
|
|||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
{
|
{
|
||||||
Data value(42);
|
Data value{42};
|
||||||
auto p = QtPromise::resolve(value).wait();
|
auto p = QtPromise::resolve(value).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
||||||
@ -119,8 +119,8 @@ void tst_helpers_resolve::qtSharedPtr()
|
|||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<QSharedPointer<Data>>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<QSharedPointer<Data>>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p1, QSharedPointer<Data>()), sptr0);
|
QCOMPARE(waitForValue(p1, QSharedPointer<Data>{}), sptr0);
|
||||||
QCOMPARE(waitForValue(p2, QSharedPointer<Data>()), sptr1);
|
QCOMPARE(waitForValue(p2, QSharedPointer<Data>{}), sptr1);
|
||||||
|
|
||||||
wptr = sptr0;
|
wptr = sptr0;
|
||||||
|
|
||||||
@ -155,8 +155,8 @@ void tst_helpers_resolve::stdSharedPtr()
|
|||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<std::shared_ptr<Data>>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<std::shared_ptr<Data>>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p1, std::shared_ptr<Data>()), sptr0);
|
QCOMPARE(waitForValue(p1, std::shared_ptr<Data>{}), sptr0);
|
||||||
QCOMPARE(waitForValue(p2, std::shared_ptr<Data>()), sptr1);
|
QCOMPARE(waitForValue(p2, std::shared_ptr<Data>{}), sptr1);
|
||||||
|
|
||||||
wptr = sptr0;
|
wptr = sptr0;
|
||||||
|
|
||||||
@ -180,10 +180,10 @@ void tst_helpers_resolve::typedPromise()
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
QPromise<int> v0(resolver);
|
QPromise<int> v0{resolver};
|
||||||
const QPromise<int> v1 = v0;
|
const QPromise<int> v1 = v0;
|
||||||
|
|
||||||
auto p0 = QtPromise::resolve(QPromise<int>(resolver));
|
auto p0 = QtPromise::resolve(QPromise<int>{resolver});
|
||||||
auto p1 = QtPromise::resolve(v0);
|
auto p1 = QtPromise::resolve(v0);
|
||||||
auto p2 = QtPromise::resolve(v1);
|
auto p2 = QtPromise::resolve(v1);
|
||||||
|
|
||||||
@ -207,10 +207,10 @@ void tst_helpers_resolve::voidPromise()
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
QPromise<void> v0(resolver);
|
QPromise<void> v0{resolver};
|
||||||
const QPromise<void> v1 = v0;
|
const QPromise<void> v1 = v0;
|
||||||
|
|
||||||
auto p0 = QtPromise::resolve(QPromise<void>(resolver));
|
auto p0 = QtPromise::resolve(QPromise<void>{resolver});
|
||||||
auto p1 = QtPromise::resolve(v0);
|
auto p1 = QtPromise::resolve(v0);
|
||||||
auto p2 = QtPromise::resolve(v1);
|
auto p2 = QtPromise::resolve(v1);
|
||||||
|
|
||||||
|
@ -46,205 +46,205 @@ QTEST_MAIN(tst_qpromise_construct)
|
|||||||
|
|
||||||
void tst_qpromise_construct::resolveSyncOneArg()
|
void tst_qpromise_construct::resolveSyncOneArg()
|
||||||
{
|
{
|
||||||
QPromise<int> p([](const QPromiseResolve<int>& resolve) {
|
QPromise<int> p{[](const QPromiseResolve<int>& resolve) {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString());
|
QCOMPARE(waitForError(p, QString{}), QString{});
|
||||||
QCOMPARE(waitForValue(p, -1), 42);
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::resolveSyncOneArg_void()
|
void tst_qpromise_construct::resolveSyncOneArg_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p([](const QPromiseResolve<void>& resolve) {
|
QPromise<void> p{[](const QPromiseResolve<void>& resolve) {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString());
|
QCOMPARE(waitForError(p, QString{}), QString{});
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::resolveSyncTwoArgs()
|
void tst_qpromise_construct::resolveSyncTwoArgs()
|
||||||
{
|
{
|
||||||
QPromise<int> p([](const QPromiseResolve<int>& resolve, const QPromiseReject<int>&) {
|
QPromise<int> p{[](const QPromiseResolve<int>& resolve, const QPromiseReject<int>&) {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString());
|
QCOMPARE(waitForError(p, QString{}), QString{});
|
||||||
QCOMPARE(waitForValue(p, -1), 42);
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::resolveSyncTwoArgs_void()
|
void tst_qpromise_construct::resolveSyncTwoArgs_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p([](const QPromiseResolve<void>& resolve, const QPromiseReject<void>&) {
|
QPromise<void> p{[](const QPromiseResolve<void>& resolve, const QPromiseReject<void>&) {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString());
|
QCOMPARE(waitForError(p, QString{}), QString{});
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::resolveAsyncOneArg()
|
void tst_qpromise_construct::resolveAsyncOneArg()
|
||||||
{
|
{
|
||||||
QPromise<int> p([](const QPromiseResolve<int>& resolve) {
|
QPromise<int> p{[](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString());
|
QCOMPARE(waitForError(p, QString{}), QString{});
|
||||||
QCOMPARE(waitForValue(p, -1), 42);
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::resolveAsyncOneArg_void()
|
void tst_qpromise_construct::resolveAsyncOneArg_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p([](const QPromiseResolve<void>& resolve) {
|
QPromise<void> p{[](const QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString());
|
QCOMPARE(waitForError(p, QString{}), QString{});
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::resolveAsyncTwoArgs()
|
void tst_qpromise_construct::resolveAsyncTwoArgs()
|
||||||
{
|
{
|
||||||
QPromise<int> p([](const QPromiseResolve<int>& resolve, const QPromiseReject<int>&) {
|
QPromise<int> p{[](const QPromiseResolve<int>& resolve, const QPromiseReject<int>&) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString());
|
QCOMPARE(waitForError(p, QString{}), QString{});
|
||||||
QCOMPARE(waitForValue(p, -1), 42);
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::resolveAsyncTwoArgs_void()
|
void tst_qpromise_construct::resolveAsyncTwoArgs_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p([](const QPromiseResolve<void>& resolve, const QPromiseReject<void>&) {
|
QPromise<void> p{[](const QPromiseResolve<void>& resolve, const QPromiseReject<void>&) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString()), QString());
|
QCOMPARE(waitForError(p, QString{}), QString{});
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::rejectSync()
|
void tst_qpromise_construct::rejectSync()
|
||||||
{
|
{
|
||||||
QPromise<int> p([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QPromise<int> p{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), -1);
|
QCOMPARE(waitForValue(p, -1), -1);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::rejectSync_void()
|
void tst_qpromise_construct::rejectSync_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p([](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
QPromise<void> p{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), -1);
|
QCOMPARE(waitForValue(p, -1, 42), -1);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::rejectAsync()
|
void tst_qpromise_construct::rejectAsync()
|
||||||
{
|
{
|
||||||
QPromise<int> p([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QPromise<int> p{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), -1);
|
QCOMPARE(waitForValue(p, -1), -1);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::rejectAsync_void()
|
void tst_qpromise_construct::rejectAsync_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p([](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
QPromise<void> p{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), -1);
|
QCOMPARE(waitForValue(p, -1, 42), -1);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::rejectThrowOneArg()
|
void tst_qpromise_construct::rejectThrowOneArg()
|
||||||
{
|
{
|
||||||
QPromise<int> p([](const QPromiseResolve<int>&) {
|
QPromise<int> p{[](const QPromiseResolve<int>&) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), -1);
|
QCOMPARE(waitForValue(p, -1), -1);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::rejectThrowOneArg_void()
|
void tst_qpromise_construct::rejectThrowOneArg_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p([](const QPromiseResolve<void>&) {
|
QPromise<void> p{[](const QPromiseResolve<void>&) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), -1);
|
QCOMPARE(waitForValue(p, -1, 42), -1);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::rejectThrowTwoArgs()
|
void tst_qpromise_construct::rejectThrowTwoArgs()
|
||||||
{
|
{
|
||||||
QPromise<int> p([](const QPromiseResolve<int>&, const QPromiseReject<int>&) {
|
QPromise<int> p{[](const QPromiseResolve<int>&, const QPromiseReject<int>&) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), -1);
|
QCOMPARE(waitForValue(p, -1), -1);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::rejectThrowTwoArgs_void()
|
void tst_qpromise_construct::rejectThrowTwoArgs_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p([](const QPromiseResolve<void>&, const QPromiseReject<void>&) {
|
QPromise<void> p{[](const QPromiseResolve<void>&, const QPromiseReject<void>&) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), -1);
|
QCOMPARE(waitForValue(p, -1, 42), -1);
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::rejectUndefined()
|
void tst_qpromise_construct::rejectUndefined()
|
||||||
{
|
{
|
||||||
QPromise<int> p([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QPromise<int> p{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject();
|
reject();
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForRejected<QPromiseUndefinedException>(p), true);
|
QCOMPARE(waitForRejected<QPromiseUndefinedException>(p), true);
|
||||||
@ -252,11 +252,11 @@ void tst_qpromise_construct::rejectUndefined()
|
|||||||
|
|
||||||
void tst_qpromise_construct::rejectUndefined_void()
|
void tst_qpromise_construct::rejectUndefined_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p([](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
QPromise<void> p{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject();
|
reject();
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForRejected<QPromiseUndefinedException>(p), true);
|
QCOMPARE(waitForRejected<QPromiseUndefinedException>(p), true);
|
||||||
@ -265,12 +265,12 @@ void tst_qpromise_construct::rejectUndefined_void()
|
|||||||
// https://github.com/simonbrunel/qtpromise/issues/6
|
// https://github.com/simonbrunel/qtpromise/issues/6
|
||||||
void tst_qpromise_construct::connectAndResolve()
|
void tst_qpromise_construct::connectAndResolve()
|
||||||
{
|
{
|
||||||
QScopedPointer<QObject> object(new QObject());
|
QScopedPointer<QObject> object(new QObject{});
|
||||||
|
|
||||||
std::weak_ptr<int> wptr;
|
std::weak_ptr<int> wptr;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto p = QPromise<std::shared_ptr<int>>([&](
|
auto p = QPromise<std::shared_ptr<int>>{[&](
|
||||||
const QPromiseResolve<std::shared_ptr<int>>& resolve,
|
const QPromiseResolve<std::shared_ptr<int>>& resolve,
|
||||||
const QPromiseReject<std::shared_ptr<int>>& reject) {
|
const QPromiseReject<std::shared_ptr<int>>& reject) {
|
||||||
|
|
||||||
@ -286,13 +286,13 @@ void tst_qpromise_construct::connectAndResolve()
|
|||||||
reject(42);
|
reject(42);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
|
|
||||||
object->setObjectName("foobar");
|
object->setObjectName("foobar");
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p, std::shared_ptr<int>()), wptr.lock());
|
QCOMPARE(waitForValue(p, std::shared_ptr<int>{}), wptr.lock());
|
||||||
QCOMPARE(wptr.use_count(), 1l); // "p" still holds a reference
|
QCOMPARE(wptr.use_count(), 1l); // "p" still holds a reference
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,12 +302,12 @@ void tst_qpromise_construct::connectAndResolve()
|
|||||||
// https://github.com/simonbrunel/qtpromise/issues/6
|
// https://github.com/simonbrunel/qtpromise/issues/6
|
||||||
void tst_qpromise_construct::connectAndReject()
|
void tst_qpromise_construct::connectAndReject()
|
||||||
{
|
{
|
||||||
QScopedPointer<QObject> object(new QObject());
|
QScopedPointer<QObject> object(new QObject{});
|
||||||
|
|
||||||
std::weak_ptr<int> wptr;
|
std::weak_ptr<int> wptr;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>([&](
|
auto p = QPromise<int>{[&](
|
||||||
const QPromiseResolve<int>& resolve,
|
const QPromiseResolve<int>& resolve,
|
||||||
const QPromiseReject<int>& reject) {
|
const QPromiseReject<int>& reject) {
|
||||||
|
|
||||||
@ -323,13 +323,13 @@ void tst_qpromise_construct::connectAndReject()
|
|||||||
resolve(42);
|
resolve(42);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
|
|
||||||
object->setObjectName("foobar");
|
object->setObjectName("foobar");
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, std::shared_ptr<int>()), wptr.lock());
|
QCOMPARE(waitForError(p, std::shared_ptr<int>{}), wptr.lock());
|
||||||
QCOMPARE(wptr.use_count(), 1l); // "p" still holds a reference
|
QCOMPARE(wptr.use_count(), 1l); // "p" still holds a reference
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,11 +57,11 @@ void tst_qpromise_delay::rejected()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>::reject(QString("foo")).delay(1000).finally([&]() {
|
auto p = QPromise<int>::reject(QString{"foo"}).delay(1000).finally([&]() {
|
||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QVERIFY(elapsed <= 10);
|
QVERIFY(elapsed <= 10);
|
||||||
}
|
}
|
||||||
@ -94,11 +94,11 @@ void tst_qpromise_delay::rejectedStdChrono()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>::reject(QString("foo")).delay(std::chrono::seconds{1}).finally([&]() {
|
auto p = QPromise<int>::reject(QString{"foo"}).delay(std::chrono::seconds{1}).finally([&]() {
|
||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QVERIFY(elapsed <= 10);
|
QVERIFY(elapsed <= 10);
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,10 @@ struct SequenceTester
|
|||||||
values << i << v;
|
values << i << v;
|
||||||
}).each([&](int v, ...) {
|
}).each([&](int v, ...) {
|
||||||
values << v;
|
values << v;
|
||||||
return QString("foo");
|
return QString{"foo"};
|
||||||
}).each([&](int v, ...) {
|
}).each([&](int v, ...) {
|
||||||
values << v + 1;
|
values << v + 1;
|
||||||
return QtPromise::resolve(QString("foo")).then([&](){
|
return QtPromise::resolve(QString{"foo"}).then([&](){
|
||||||
values << -1;
|
values << -1;
|
||||||
});
|
});
|
||||||
}).each([&](int v, ...) {
|
}).each([&](int v, ...) {
|
||||||
@ -53,7 +53,7 @@ struct SequenceTester
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Sequence>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Sequence>>::value));
|
||||||
QCOMPARE(waitForValue(p, Sequence()), Sequence({42, 43, 44}));
|
QCOMPARE(waitForValue(p, Sequence{}), (Sequence{42, 43, 44}));
|
||||||
|
|
||||||
QVector<int> expected{
|
QVector<int> expected{
|
||||||
0, 42, 1, 43, 2, 44,
|
0, 42, 1, 43, 2, 44,
|
||||||
@ -76,8 +76,8 @@ void tst_qpromise_each::emptySequence()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>());
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
QCOMPARE(values, QVector<int>({}));
|
QCOMPARE(values, (QVector<int>{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_each::preserveValues()
|
void tst_qpromise_each::preserveValues()
|
||||||
@ -88,8 +88,8 @@ void tst_qpromise_each::preserveValues()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(values, QVector<int>({43, 44, 45}));
|
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_each::ignoreResult()
|
void tst_qpromise_each::ignoreResult()
|
||||||
@ -101,8 +101,8 @@ void tst_qpromise_each::ignoreResult()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(values, QVector<int>({43, 44, 45}));
|
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_each::delayedFulfilled()
|
void tst_qpromise_each::delayedFulfilled()
|
||||||
@ -116,7 +116,7 @@ void tst_qpromise_each::delayedFulfilled()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
||||||
QCOMPARE(values, expected);
|
QCOMPARE(values, expected);
|
||||||
}
|
}
|
||||||
@ -124,32 +124,32 @@ void tst_qpromise_each::delayedFulfilled()
|
|||||||
void tst_qpromise_each::delayedRejected()
|
void tst_qpromise_each::delayedRejected()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).each([](int v, ...) {
|
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).each([](int v, ...) {
|
||||||
return QPromise<int>([&](
|
return QPromise<int>{[&](
|
||||||
const QPromiseResolve<int>& resolve,
|
const QPromiseResolve<int>& resolve,
|
||||||
const QPromiseReject<int>& reject) {
|
const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
if (v == 44) {
|
if (v == 44) {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
resolve(v);
|
resolve(v);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_each::functorThrows()
|
void tst_qpromise_each::functorThrows()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).each([](int v, ...) {
|
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).each([](int v, ...) {
|
||||||
if (v == 44) {
|
if (v == 44) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_each::functorArguments()
|
void tst_qpromise_each::functorArguments()
|
||||||
@ -160,8 +160,8 @@ void tst_qpromise_each::functorArguments()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(values, QVector<int>({0, 42, 1, 43, 2, 44}));
|
QCOMPARE(values, (QVector<int>{0, 42, 1, 43, 2, 44}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_each::sequenceTypes()
|
void tst_qpromise_each::sequenceTypes()
|
||||||
|
@ -32,7 +32,7 @@ QTEST_MAIN(tst_qpromise_fail)
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const QString kErr = "0.42";
|
const QString kErr{"0.42"};
|
||||||
const float kRes = 0.42f;
|
const float kRes = 0.42f;
|
||||||
const float kFail = -1.f;
|
const float kFail = -1.f;
|
||||||
|
|
||||||
@ -66,17 +66,17 @@ void tst_qpromise_fail::sameType()
|
|||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
p.fail([&](const std::domain_error& e) {
|
p.fail([&](const std::domain_error& e) {
|
||||||
error += QString(e.what()) + "0";
|
error += QString{e.what()} + "0";
|
||||||
return -1;
|
return -1;
|
||||||
}).fail([&](const std::out_of_range& e) {
|
}).fail([&](const std::out_of_range& e) {
|
||||||
error += QString(e.what()) + "1";
|
error += QString{e.what()} + "1";
|
||||||
return -1;
|
return -1;
|
||||||
}).fail([&](const std::exception& e) {
|
}).fail([&](const std::exception& e) {
|
||||||
error += QString(e.what()) + "2";
|
error += QString{e.what()} + "2";
|
||||||
return -1;
|
return -1;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(error, QString("foo1"));
|
QCOMPARE(error, QString{"foo1"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_fail::baseClass()
|
void tst_qpromise_fail::baseClass()
|
||||||
@ -86,17 +86,17 @@ void tst_qpromise_fail::baseClass()
|
|||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
p.fail([&](const std::runtime_error& e) {
|
p.fail([&](const std::runtime_error& e) {
|
||||||
error += QString(e.what()) + "0";
|
error += QString{e.what()} + "0";
|
||||||
return -1;
|
return -1;
|
||||||
}).fail([&](const std::logic_error& e) {
|
}).fail([&](const std::logic_error& e) {
|
||||||
error += QString(e.what()) + "1";
|
error += QString{e.what()} + "1";
|
||||||
return -1;
|
return -1;
|
||||||
}).fail([&](const std::exception& e) {
|
}).fail([&](const std::exception& e) {
|
||||||
error += QString(e.what()) + "2";
|
error += QString{e.what()} + "2";
|
||||||
return -1;
|
return -1;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(error, QString("foo1"));
|
QCOMPARE(error, QString{"foo1"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_fail::catchAll()
|
void tst_qpromise_fail::catchAll()
|
||||||
@ -105,17 +105,17 @@ void tst_qpromise_fail::catchAll()
|
|||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
p.fail([&](const std::runtime_error& e) {
|
p.fail([&](const std::runtime_error& e) {
|
||||||
error += QString(e.what()) + "0";
|
error += QString{e.what()} + "0";
|
||||||
return -1;
|
return -1;
|
||||||
}).fail([&]() {
|
}).fail([&]() {
|
||||||
error += "bar";
|
error += "bar";
|
||||||
return -1;
|
return -1;
|
||||||
}).fail([&](const std::exception& e) {
|
}).fail([&](const std::exception& e) {
|
||||||
error += QString(e.what()) + "2";
|
error += QString{e.what()} + "2";
|
||||||
return -1;
|
return -1;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(error, QString("bar"));
|
QCOMPARE(error, QString{"bar"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_fail::functionPtrHandlers()
|
void tst_qpromise_fail::functionPtrHandlers()
|
||||||
@ -185,7 +185,7 @@ void tst_qpromise_fail::stdBindHandlers()
|
|||||||
{
|
{
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
const float val{42.f};
|
const float val = 42.f;
|
||||||
const Klass obj{val};
|
const Klass obj{val};
|
||||||
|
|
||||||
const std::function<float()> bindNoArg = std::bind(&Klass::fnNoArg, &obj);
|
const std::function<float()> bindNoArg = std::bind(&Klass::fnNoArg, &obj);
|
||||||
|
@ -49,7 +49,7 @@ struct SequenceTester
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Sequence>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Sequence>>::value));
|
||||||
QCOMPARE(waitForValue(p, Sequence()), Sequence({43, 47, 49}));
|
QCOMPARE(waitForValue(p, Sequence{}), (Sequence{43, 47, 49}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ void tst_qpromise_filter::emptySequence()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>{});
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_filter::filterValues()
|
void tst_qpromise_filter::filterValues()
|
||||||
@ -72,53 +72,53 @@ void tst_qpromise_filter::filterValues()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_filter::delayedFulfilled()
|
void tst_qpromise_filter::delayedFulfilled()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
||||||
return QPromise<bool>([&](const QPromiseResolve<bool>& resolve) {
|
return QPromise<bool>{[&](const QPromiseResolve<bool>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(v % 2 == 0);
|
resolve(v % 2 == 0);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_filter::delayedRejected()
|
void tst_qpromise_filter::delayedRejected()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
||||||
return QPromise<bool>([&](
|
return QPromise<bool>{[&](
|
||||||
const QPromiseResolve<bool>& resolve,
|
const QPromiseResolve<bool>& resolve,
|
||||||
const QPromiseReject<bool>& reject) {
|
const QPromiseReject<bool>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
if (v == 43) {
|
if (v == 43) {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_filter::functorThrows()
|
void tst_qpromise_filter::functorThrows()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
||||||
if (v == 43) {
|
if (v == 43) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_filter::functorArguments()
|
void tst_qpromise_filter::functorArguments()
|
||||||
@ -130,7 +130,7 @@ void tst_qpromise_filter::functorArguments()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({42, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
||||||
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
||||||
QCOMPARE(args, expected);
|
QCOMPARE(args, expected);
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ void tst_qpromise_filter::preserveOrder()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({250, 400, 300}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{250, 400, 300}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_filter::sequenceTypes()
|
void tst_qpromise_filter::sequenceTypes()
|
||||||
|
@ -65,22 +65,22 @@ void tst_qpromise_finally::fulfilledSync_void()
|
|||||||
void tst_qpromise_finally::fulfilledThrows()
|
void tst_qpromise_finally::fulfilledThrows()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::resolve(42).finally([&]() {
|
auto p = QPromise<int>::resolve(42).finally([&]() {
|
||||||
throw QString("bar");
|
throw QString{"bar"};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("bar"));
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_finally::fulfilledThrows_void()
|
void tst_qpromise_finally::fulfilledThrows_void()
|
||||||
{
|
{
|
||||||
auto p = QPromise<void>::resolve().finally([&]() {
|
auto p = QPromise<void>::resolve().finally([&]() {
|
||||||
throw QString("bar");
|
throw QString{"bar"};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("bar"));
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,12 +88,12 @@ void tst_qpromise_finally::fulfilledAsyncResolve()
|
|||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<int>::resolve(42).finally([&]() {
|
auto p = QPromise<int>::resolve(42).finally([&]() {
|
||||||
QPromise<int> p([&](const QPromiseResolve<int>& resolve) {
|
QPromise<int> p{[&](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values << 64;
|
values << 64;
|
||||||
resolve(16); // ignored!
|
resolve(16); // ignored!
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
values << 8;
|
values << 8;
|
||||||
return p;
|
return p;
|
||||||
@ -101,33 +101,33 @@ void tst_qpromise_finally::fulfilledAsyncResolve()
|
|||||||
|
|
||||||
QCOMPARE(waitForValue(p, -1), 42);
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(values, QVector<int>({8, 64}));
|
QCOMPARE(values, (QVector<int>{8, 64}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_finally::fulfilledAsyncReject()
|
void tst_qpromise_finally::fulfilledAsyncReject()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::resolve(42).finally([]() {
|
auto p = QPromise<int>::resolve(42).finally([]() {
|
||||||
return QPromise<int>([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
return QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString("bar"));
|
reject(QString{"bar"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("bar"));
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_finally::rejectedSync()
|
void tst_qpromise_finally::rejectedSync()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<int>::reject(QString("foo")).finally([&]() {
|
auto p = QPromise<int>::reject(QString{"foo"}).finally([&]() {
|
||||||
value = 8;
|
value = 8;
|
||||||
return 16; // ignored!
|
return 16; // ignored!
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(value, 8);
|
QCOMPARE(value, 8);
|
||||||
}
|
}
|
||||||
@ -135,49 +135,49 @@ void tst_qpromise_finally::rejectedSync()
|
|||||||
void tst_qpromise_finally::rejectedSync_void()
|
void tst_qpromise_finally::rejectedSync_void()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<void>::reject(QString("foo")).finally([&]() {
|
auto p = QPromise<void>::reject(QString{"foo"}).finally([&]() {
|
||||||
value = 8;
|
value = 8;
|
||||||
return 16; // ignored!
|
return 16; // ignored!
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(value, 8);
|
QCOMPARE(value, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_finally::rejectedThrows()
|
void tst_qpromise_finally::rejectedThrows()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::reject(QString("foo")).finally([&]() {
|
auto p = QPromise<int>::reject(QString{"foo"}).finally([&]() {
|
||||||
throw QString("bar");
|
throw QString{"bar"};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("bar"));
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_finally::rejectedThrows_void()
|
void tst_qpromise_finally::rejectedThrows_void()
|
||||||
{
|
{
|
||||||
auto p = QPromise<void>::reject(QString("foo")).finally([&]() {
|
auto p = QPromise<void>::reject(QString{"foo"}).finally([&]() {
|
||||||
throw QString("bar");
|
throw QString{"bar"};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("bar"));
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_finally::rejectedAsyncResolve()
|
void tst_qpromise_finally::rejectedAsyncResolve()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<int>::reject(QString("foo")).finally([&]() {
|
auto p = QPromise<int>::reject(QString{"foo"}).finally([&]() {
|
||||||
QPromise<int> p([&](const QPromiseResolve<int>& resolve) {
|
QPromise<int> p{[&](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values << 64;
|
values << 64;
|
||||||
resolve(16); // ignored!
|
resolve(16); // ignored!
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
values << 8;
|
values << 8;
|
||||||
return p;
|
return p;
|
||||||
@ -187,21 +187,21 @@ void tst_qpromise_finally::rejectedAsyncResolve()
|
|||||||
values << r;
|
values << r;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(values, QVector<int>({8, 64}));
|
QCOMPARE(values, (QVector<int>{8, 64}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_finally::rejectedAsyncReject()
|
void tst_qpromise_finally::rejectedAsyncReject()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::reject(QString("foo")).finally([]() {
|
auto p = QPromise<int>::reject(QString{"foo"}).finally([]() {
|
||||||
return QPromise<int>([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
return QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString("bar"));
|
reject(QString{"bar"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("bar"));
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ struct SequenceTester
|
|||||||
auto p = QtPromise::resolve(Sequence{42, 43, 44}).map([](int v, ...) {
|
auto p = QtPromise::resolve(Sequence{42, 43, 44}).map([](int v, ...) {
|
||||||
return QString::number(v + 1);
|
return QString::number(v + 1);
|
||||||
}).map([](const QString& v, int i) {
|
}).map([](const QString& v, int i) {
|
||||||
return QtPromise::resolve(QString("%1:%2").arg(i).arg(v));
|
return QtPromise::resolve(QString{"%1:%2"}.arg(i).arg(v));
|
||||||
}).map([](const QString& v, ...) {
|
}).map([](const QString& v, ...) {
|
||||||
return QtPromise::resolve((v + "!").toUtf8());
|
return QtPromise::resolve((v + "!").toUtf8());
|
||||||
}).map([](const QByteArray& v, ...) {
|
}).map([](const QByteArray& v, ...) {
|
||||||
@ -49,7 +49,7 @@ struct SequenceTester
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<QString>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<QString>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<QString>()), QVector<QString>({"0:43!", "1:44!", "2:45!"}));
|
QCOMPARE(waitForValue(p, QVector<QString>{}), (QVector<QString>{"0:43!", "1:44!", "2:45!"}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ void tst_qpromise_map::emptySequence()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_map::modifyValues()
|
void tst_qpromise_map::modifyValues()
|
||||||
@ -72,7 +72,7 @@ void tst_qpromise_map::modifyValues()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({43, 44, 45}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_map::convertValues()
|
void tst_qpromise_map::convertValues()
|
||||||
@ -82,53 +82,53 @@ void tst_qpromise_map::convertValues()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<QString>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<QString>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<QString>()), QVector<QString>({"43", "44", "45"}));
|
QCOMPARE(waitForValue(p, QVector<QString>{}), (QVector<QString>{"43", "44", "45"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_map::delayedFulfilled()
|
void tst_qpromise_map::delayedFulfilled()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::resolve(QVector<int>{42, 43, 44}).map([](int v, ...) {
|
auto p = QtPromise::resolve(QVector<int>{42, 43, 44}).map([](int v, ...) {
|
||||||
return QPromise<int>([&](const QPromiseResolve<int>& resolve) {
|
return QPromise<int>{[&](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(v + 1);
|
resolve(v + 1);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({43, 44, 45}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_map::delayedRejected()
|
void tst_qpromise_map::delayedRejected()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::resolve(QVector<int>{42, 43, 44}).map([](int v, ...) {
|
auto p = QtPromise::resolve(QVector<int>{42, 43, 44}).map([](int v, ...) {
|
||||||
return QPromise<int>([&](
|
return QPromise<int>{[&](
|
||||||
const QPromiseResolve<int>& resolve,
|
const QPromiseResolve<int>& resolve,
|
||||||
const QPromiseReject<int>& reject) {
|
const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
if (v == 43) {
|
if (v == 43) {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
resolve(v);
|
resolve(v);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_map::functorThrows()
|
void tst_qpromise_map::functorThrows()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::resolve(QVector<int>{42, 43, 44}).map([](int v, ...) {
|
auto p = QtPromise::resolve(QVector<int>{42, 43, 44}).map([](int v, ...) {
|
||||||
if (v == 43) {
|
if (v == 43) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
}
|
}
|
||||||
return v + 1;
|
return v + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_map::functorArguments()
|
void tst_qpromise_map::functorArguments()
|
||||||
@ -138,7 +138,7 @@ void tst_qpromise_map::functorArguments()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p1, QVector<int>()), QVector<int>({0, 42, 84}));
|
QCOMPARE(waitForValue(p1, QVector<int>{}), (QVector<int>{0, 42, 84}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_map::preserveOrder()
|
void tst_qpromise_map::preserveOrder()
|
||||||
@ -148,7 +148,7 @@ void tst_qpromise_map::preserveOrder()
|
|||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>()), QVector<int>({251, 501, 101}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{251, 501, 101}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_map::sequenceTypes()
|
void tst_qpromise_map::sequenceTypes()
|
||||||
|
@ -39,20 +39,20 @@ void tst_qpromise_operators::move()
|
|||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1), 42);
|
QCOMPARE(waitForValue(p0, -1), 42);
|
||||||
|
|
||||||
p0 = QPromise<int>([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
p0 = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(waitForError(p0, QString()), QString("foo"));
|
QCOMPARE(waitForError(p0, QString{}), QString{"foo"});
|
||||||
|
|
||||||
p0 = QPromise<int>([](const QPromiseResolve<int>& resolve) {
|
p0 = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(43);
|
resolve(43);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1), 43);
|
QCOMPARE(waitForValue(p0, -1), 43);
|
||||||
@ -65,20 +65,20 @@ void tst_qpromise_operators::move_void()
|
|||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1, 42), 42);
|
QCOMPARE(waitForValue(p0, -1, 42), 42);
|
||||||
|
|
||||||
p0 = QPromise<void>([](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
p0 = QPromise<void>{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(waitForError(p0, QString()), QString("foo"));
|
QCOMPARE(waitForError(p0, QString{}), QString{"foo"});
|
||||||
|
|
||||||
p0 = QPromise<void>([](const QPromiseResolve<void>& resolve) {
|
p0 = QPromise<void>{[](const QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1, 43), 43);
|
QCOMPARE(waitForValue(p0, -1, 43), 43);
|
||||||
@ -86,17 +86,17 @@ void tst_qpromise_operators::move_void()
|
|||||||
|
|
||||||
void tst_qpromise_operators::copy()
|
void tst_qpromise_operators::copy()
|
||||||
{
|
{
|
||||||
auto p0 = QPromise<int>([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
auto p0 = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p1 = QPromise<int>([](const QPromiseResolve<int>& resolve) {
|
auto p1 = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p0 == p1, false);
|
QCOMPARE(p0 == p1, false);
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
@ -113,17 +113,17 @@ void tst_qpromise_operators::copy()
|
|||||||
|
|
||||||
void tst_qpromise_operators::copy_void()
|
void tst_qpromise_operators::copy_void()
|
||||||
{
|
{
|
||||||
auto p0 = QPromise<void>([](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
auto p0 = QPromise<void>{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p1 = QPromise<void>([](const QPromiseResolve<void>& resolve) {
|
auto p1 = QPromise<void>{[](const QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QCOMPARE(p0 == p1, false);
|
QCOMPARE(p0 == p1, false);
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
@ -229,5 +229,5 @@ void tst_qpromise_operators::chaining_void()
|
|||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
QCOMPARE(values, QVector<int>({0, 2, 4, 6}));
|
QCOMPARE(values, (QVector<int>{0, 2, 4, 6}));
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,8 @@ struct SequenceTester
|
|||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1), 21);
|
QCOMPARE(waitForValue(p0, -1), 21);
|
||||||
QCOMPARE(waitForValue(p1, -1), 23);
|
QCOMPARE(waitForValue(p1, -1), 23);
|
||||||
QCOMPARE(v0, QVector<int>({4, 6, 1, 11, 8, 2}));
|
QCOMPARE(v0, (QVector<int>{4, 6, 1, 11, 8, 2}));
|
||||||
QCOMPARE(v1, QVector<int>({2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
QCOMPARE(v1, (QVector<int>{2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -109,8 +109,8 @@ void tst_qpromise_reduce::regularValues()
|
|||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1), 21);
|
QCOMPARE(waitForValue(p0, -1), 21);
|
||||||
QCOMPARE(waitForValue(p1, -1), 23);
|
QCOMPARE(waitForValue(p1, -1), 23);
|
||||||
QCOMPARE(v0, QVector<int>({4, 6, 1, 11, 8, 2}));
|
QCOMPARE(v0, (QVector<int>{4, 6, 1, 11, 8, 2}));
|
||||||
QCOMPARE(v1, QVector<int>({2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
QCOMPARE(v1, (QVector<int>{2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_reduce::promiseValues()
|
void tst_qpromise_reduce::promiseValues()
|
||||||
@ -139,8 +139,8 @@ void tst_qpromise_reduce::promiseValues()
|
|||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1), 21);
|
QCOMPARE(waitForValue(p0, -1), 21);
|
||||||
QCOMPARE(waitForValue(p1, -1), 23);
|
QCOMPARE(waitForValue(p1, -1), 23);
|
||||||
QCOMPARE(v0, QVector<int>({4, 6, 1, 11, 8, 2}));
|
QCOMPARE(v0, (QVector<int>{4, 6, 1, 11, 8, 2}));
|
||||||
QCOMPARE(v1, QVector<int>({2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
QCOMPARE(v1, (QVector<int>{2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_reduce::convertResultType()
|
void tst_qpromise_reduce::convertResultType()
|
||||||
@ -148,15 +148,15 @@ void tst_qpromise_reduce::convertResultType()
|
|||||||
QVector<int> inputs{4, 6, 8};
|
QVector<int> inputs{4, 6, 8};
|
||||||
|
|
||||||
auto p = QtPromise::resolve(inputs).reduce([&](const QString& acc, int cur, int idx) {
|
auto p = QtPromise::resolve(inputs).reduce([&](const QString& acc, int cur, int idx) {
|
||||||
return QString("%1:%2:%3").arg(acc).arg(cur).arg(idx);
|
return QString{"%1:%2:%3"}.arg(acc).arg(cur).arg(idx);
|
||||||
}, QString("foo"));
|
}, QString{"foo"});
|
||||||
|
|
||||||
// NOTE(SB): when no initial value is given, the result type is the sequence type.
|
// NOTE(SB): when no initial value is given, the result type is the sequence type.
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QString()), QString("foo:4:0:6:1:8:2"));
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo:4:0:6:1:8:2"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_reduce::delayedInitialValue()
|
void tst_qpromise_reduce::delayedInitialValue()
|
||||||
@ -172,7 +172,7 @@ void tst_qpromise_reduce::delayedInitialValue()
|
|||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), 23);
|
QCOMPARE(waitForValue(p, -1), 23);
|
||||||
QCOMPARE(values, QVector<int>({2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
QCOMPARE(values, (QVector<int>{2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_reduce::delayedFulfilled()
|
void tst_qpromise_reduce::delayedFulfilled()
|
||||||
@ -197,8 +197,8 @@ void tst_qpromise_reduce::delayedFulfilled()
|
|||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1), 21);
|
QCOMPARE(waitForValue(p0, -1), 21);
|
||||||
QCOMPARE(waitForValue(p1, -1), 23);
|
QCOMPARE(waitForValue(p1, -1), 23);
|
||||||
QCOMPARE(v0, QVector<int>({4, 6, 1, 11, 8, 2}));
|
QCOMPARE(v0, (QVector<int>{4, 6, 1, 11, 8, 2}));
|
||||||
QCOMPARE(v1, QVector<int>({2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
QCOMPARE(v1, (QVector<int>{2, 4, 0, 6, 6, 1, 13, 8, 2}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_reduce::delayedRejected()
|
void tst_qpromise_reduce::delayedRejected()
|
||||||
@ -210,14 +210,14 @@ void tst_qpromise_reduce::delayedRejected()
|
|||||||
auto p0 = QtPromise::resolve(inputs).reduce([&](int acc, int cur, int idx) {
|
auto p0 = QtPromise::resolve(inputs).reduce([&](int acc, int cur, int idx) {
|
||||||
v0 << acc << cur << idx;
|
v0 << acc << cur << idx;
|
||||||
if (cur == 6) {
|
if (cur == 6) {
|
||||||
return QPromise<int>::reject(QString("foo"));
|
return QPromise<int>::reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
return QtPromise::resolve(acc + cur + idx);
|
return QtPromise::resolve(acc + cur + idx);
|
||||||
});
|
});
|
||||||
auto p1 = QtPromise::resolve(inputs).reduce([&](int acc, int cur, int idx) {
|
auto p1 = QtPromise::resolve(inputs).reduce([&](int acc, int cur, int idx) {
|
||||||
v1 << acc << cur << idx;
|
v1 << acc << cur << idx;
|
||||||
if (cur == 6) {
|
if (cur == 6) {
|
||||||
return QPromise<int>::reject(QString("bar"));
|
return QPromise<int>::reject(QString{"bar"});
|
||||||
}
|
}
|
||||||
return QtPromise::resolve(acc + cur + idx);
|
return QtPromise::resolve(acc + cur + idx);
|
||||||
}, 2);
|
}, 2);
|
||||||
@ -227,10 +227,10 @@ void tst_qpromise_reduce::delayedRejected()
|
|||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(waitForError(p0, QString()), QString("foo"));
|
QCOMPARE(waitForError(p0, QString{}), QString{"foo"});
|
||||||
QCOMPARE(waitForError(p1, QString()), QString("bar"));
|
QCOMPARE(waitForError(p1, QString{}), QString{"bar"});
|
||||||
QCOMPARE(v0, QVector<int>({4, 6, 1}));
|
QCOMPARE(v0, (QVector<int>{4, 6, 1}));
|
||||||
QCOMPARE(v1, QVector<int>({2, 4, 0, 6, 6, 1}));
|
QCOMPARE(v1, (QVector<int>{2, 4, 0, 6, 6, 1}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_reduce::functorThrows()
|
void tst_qpromise_reduce::functorThrows()
|
||||||
@ -242,14 +242,14 @@ void tst_qpromise_reduce::functorThrows()
|
|||||||
auto p0 = QtPromise::resolve(inputs).reduce([&](int acc, int cur, int idx) {
|
auto p0 = QtPromise::resolve(inputs).reduce([&](int acc, int cur, int idx) {
|
||||||
v0 << acc << cur << idx;
|
v0 << acc << cur << idx;
|
||||||
if (cur == 6) {
|
if (cur == 6) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
}
|
}
|
||||||
return acc + cur + idx;
|
return acc + cur + idx;
|
||||||
});
|
});
|
||||||
auto p1 = QtPromise::resolve(inputs).reduce([&](int acc, int cur, int idx) {
|
auto p1 = QtPromise::resolve(inputs).reduce([&](int acc, int cur, int idx) {
|
||||||
v1 << acc << cur << idx;
|
v1 << acc << cur << idx;
|
||||||
if (cur == 6) {
|
if (cur == 6) {
|
||||||
throw QString("bar");
|
throw QString{"bar"};
|
||||||
}
|
}
|
||||||
return acc + cur + idx;
|
return acc + cur + idx;
|
||||||
}, 2);
|
}, 2);
|
||||||
@ -259,10 +259,10 @@ void tst_qpromise_reduce::functorThrows()
|
|||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(waitForError(p0, QString()), QString("foo"));
|
QCOMPARE(waitForError(p0, QString{}), QString{"foo"});
|
||||||
QCOMPARE(waitForError(p1, QString()), QString("bar"));
|
QCOMPARE(waitForError(p1, QString{}), QString{"bar"});
|
||||||
QCOMPARE(v0, QVector<int>({4, 6, 1}));
|
QCOMPARE(v0, (QVector<int>{4, 6, 1}));
|
||||||
QCOMPARE(v1, QVector<int>({2, 4, 0, 6, 6, 1}));
|
QCOMPARE(v1, (QVector<int>{2, 4, 0, 6, 6, 1}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_reduce::sequenceTypes()
|
void tst_qpromise_reduce::sequenceTypes()
|
||||||
|
@ -67,7 +67,7 @@ void tst_qpromise_resolve::moveRValue()
|
|||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
{
|
{
|
||||||
auto p = QtPromise::resolve(Data(42)).wait();
|
auto p = QtPromise::resolve(Data{42}).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ void tst_qpromise_resolve::copyLValue()
|
|||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
{
|
{
|
||||||
Data value(42);
|
Data value{42};
|
||||||
auto p = QtPromise::resolve(value).wait();
|
auto p = QtPromise::resolve(value).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
||||||
@ -114,8 +114,8 @@ void tst_qpromise_resolve::qtSharedPtr()
|
|||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<QSharedPointer<Data>>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<QSharedPointer<Data>>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p1, QSharedPointer<Data>()), sptr0);
|
QCOMPARE(waitForValue(p1, QSharedPointer<Data>{}), sptr0);
|
||||||
QCOMPARE(waitForValue(p2, QSharedPointer<Data>()), sptr1);
|
QCOMPARE(waitForValue(p2, QSharedPointer<Data>{}), sptr1);
|
||||||
|
|
||||||
wptr = sptr0;
|
wptr = sptr0;
|
||||||
|
|
||||||
@ -150,8 +150,8 @@ void tst_qpromise_resolve::stdSharedPtr()
|
|||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<std::shared_ptr<Data>>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<std::shared_ptr<Data>>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p1, std::shared_ptr<Data>()), sptr0);
|
QCOMPARE(waitForValue(p1, std::shared_ptr<Data>{}), sptr0);
|
||||||
QCOMPARE(waitForValue(p2, std::shared_ptr<Data>()), sptr1);
|
QCOMPARE(waitForValue(p2, std::shared_ptr<Data>{}), sptr1);
|
||||||
|
|
||||||
wptr = sptr0;
|
wptr = sptr0;
|
||||||
|
|
||||||
|
@ -59,20 +59,20 @@ void tst_qpromise_tap::fulfilledSync_void()
|
|||||||
void tst_qpromise_tap::fulfilledThrows()
|
void tst_qpromise_tap::fulfilledThrows()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::resolve(42).tap([&](int) {
|
auto p = QPromise<int>::resolve(42).tap([&](int) {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_tap::fulfilledThrows_void()
|
void tst_qpromise_tap::fulfilledThrows_void()
|
||||||
{
|
{
|
||||||
auto p = QPromise<void>::resolve().tap([&]() {
|
auto p = QPromise<void>::resolve().tap([&]() {
|
||||||
throw QString("foo");
|
throw QString{"foo"};
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,12 +80,12 @@ void tst_qpromise_tap::fulfilledAsyncResolve()
|
|||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<int>::resolve(1).tap([&](int) {
|
auto p = QPromise<int>::resolve(1).tap([&](int) {
|
||||||
QPromise<int> p([&](const QPromiseResolve<int>& resolve) {
|
QPromise<int> p{[&](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values << 3;
|
values << 3;
|
||||||
resolve(4); // ignored!
|
resolve(4); // ignored!
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
values << 2;
|
values << 2;
|
||||||
return p;
|
return p;
|
||||||
@ -96,19 +96,19 @@ void tst_qpromise_tap::fulfilledAsyncResolve()
|
|||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(values, QVector<int>({2, 3, 1}));
|
QCOMPARE(values, (QVector<int>{2, 3, 1}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_tap::fulfilledAsyncReject()
|
void tst_qpromise_tap::fulfilledAsyncReject()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<int>::resolve(1).tap([&](int) {
|
auto p = QPromise<int>::resolve(1).tap([&](int) {
|
||||||
QPromise<int> p([&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QPromise<int> p{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values << 3;
|
values << 3;
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
values << 2;
|
values << 2;
|
||||||
return p;
|
return p;
|
||||||
@ -118,19 +118,19 @@ void tst_qpromise_tap::fulfilledAsyncReject()
|
|||||||
values << r;
|
values << r;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(values, QVector<int>({2, 3}));
|
QCOMPARE(values, (QVector<int>{2, 3}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_tap::rejectedSync()
|
void tst_qpromise_tap::rejectedSync()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<int>::reject(QString("foo")).tap([&](int res) {
|
auto p = QPromise<int>::reject(QString{"foo"}).tap([&](int res) {
|
||||||
value = res + 1;
|
value = res + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(value, -1);
|
QCOMPARE(value, -1);
|
||||||
}
|
}
|
||||||
@ -138,11 +138,11 @@ void tst_qpromise_tap::rejectedSync()
|
|||||||
void tst_qpromise_tap::rejectedSync_void()
|
void tst_qpromise_tap::rejectedSync_void()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<void>::reject(QString("foo")).tap([&]() {
|
auto p = QPromise<void>::reject(QString{"foo"}).tap([&]() {
|
||||||
value = 43;
|
value = 43;
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(value, -1);
|
QCOMPARE(value, -1);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ void tst_qpromise_tapfail::rejected()
|
|||||||
{
|
{
|
||||||
QStringList errors;
|
QStringList errors;
|
||||||
|
|
||||||
auto p0 = QPromise<int>::reject(QString("foo"))
|
auto p0 = QPromise<int>::reject(QString{"foo"})
|
||||||
.tapFail([&](const QString& err) {
|
.tapFail([&](const QString& err) {
|
||||||
errors << "1:" + err;
|
errors << "1:" + err;
|
||||||
});
|
});
|
||||||
@ -69,18 +69,18 @@ void tst_qpromise_tapfail::rejected()
|
|||||||
return 43;
|
return 43;
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p0, QString()), QString("foo"));
|
QCOMPARE(waitForError(p0, QString{}), QString{"foo"});
|
||||||
QCOMPARE(waitForValue(p1, -1), 43);
|
QCOMPARE(waitForValue(p1, -1), 43);
|
||||||
QCOMPARE(p0.isRejected(), true);
|
QCOMPARE(p0.isRejected(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(errors, QStringList() << "1:foo" << "2:foo");
|
QCOMPARE(errors, (QStringList{"1:foo", "2:foo"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_tapfail::rejected_void()
|
void tst_qpromise_tapfail::rejected_void()
|
||||||
{
|
{
|
||||||
QStringList errors;
|
QStringList errors;
|
||||||
|
|
||||||
auto p0 = QPromise<void>::reject(QString("foo"))
|
auto p0 = QPromise<void>::reject(QString{"foo"})
|
||||||
.tapFail([&](const QString& err) {
|
.tapFail([&](const QString& err) {
|
||||||
errors << "1:" + err;
|
errors << "1:" + err;
|
||||||
});
|
});
|
||||||
@ -90,73 +90,73 @@ void tst_qpromise_tapfail::rejected_void()
|
|||||||
errors << "2:" + err;
|
errors << "2:" + err;
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p0, QString()), QString("foo"));
|
QCOMPARE(waitForError(p0, QString{}), QString{"foo"});
|
||||||
QCOMPARE(waitForValue(p1, -1, 43), 43);
|
QCOMPARE(waitForValue(p1, -1, 43), 43);
|
||||||
QCOMPARE(p0.isRejected(), true);
|
QCOMPARE(p0.isRejected(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(errors, QStringList() << "1:foo" << "2:foo");
|
QCOMPARE(errors, (QStringList{"1:foo", "2:foo"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_tapfail::throws()
|
void tst_qpromise_tapfail::throws()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::reject(QString("foo"))
|
auto p = QPromise<int>::reject(QString{"foo"})
|
||||||
.tapFail([&]() {
|
.tapFail([&]() {
|
||||||
throw QString("bar");
|
throw QString{"bar"};
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("bar"));
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_tapfail::throws_void()
|
void tst_qpromise_tapfail::throws_void()
|
||||||
{
|
{
|
||||||
auto p = QPromise<void>::reject(QString("foo"))
|
auto p = QPromise<void>::reject(QString{"foo"})
|
||||||
.tapFail([&]() {
|
.tapFail([&]() {
|
||||||
throw QString("bar");
|
throw QString{"bar"};
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("bar"));
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_tapfail::delayedResolved()
|
void tst_qpromise_tapfail::delayedResolved()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<int>::reject(QString("foo"))
|
auto p = QPromise<int>::reject(QString{"foo"})
|
||||||
.tapFail([&]() {
|
.tapFail([&]() {
|
||||||
QPromise<void> p([&](const QPromiseResolve<void>& resolve) {
|
QPromise<void> p{[&](const QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values << 3;
|
values << 3;
|
||||||
resolve(); // ignored!
|
resolve(); // ignored!
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
values << 2;
|
values << 2;
|
||||||
return p;
|
return p;
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(values, QVector<int>({2, 3}));
|
QCOMPARE(values, (QVector<int>{2, 3}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_tapfail::delayedRejected()
|
void tst_qpromise_tapfail::delayedRejected()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<int>::reject(QString("foo"))
|
auto p = QPromise<int>::reject(QString{"foo"})
|
||||||
.tapFail([&]() {
|
.tapFail([&]() {
|
||||||
QPromise<void> p([&](
|
QPromise<void> p{[&](
|
||||||
const QPromiseResolve<void>&,
|
const QPromiseResolve<void>&,
|
||||||
const QPromiseReject<void>& reject){
|
const QPromiseReject<void>& reject){
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values << 3;
|
values << 3;
|
||||||
reject(QString("bar"));
|
reject(QString{"bar"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
values << 2;
|
values << 2;
|
||||||
return p;
|
return p;
|
||||||
});
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("bar"));
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(values, QVector<int>({2, 3}));
|
QCOMPARE(values, (QVector<int>{2, 3}));
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ void tst_qpromise_then::resolveSync()
|
|||||||
values << 44;
|
values << 44;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(values, QVariantList({42, QString("43"), 44}));
|
QCOMPARE(values, (QVariantList{42, QString{"43"}, 44}));
|
||||||
QCOMPARE(input.isFulfilled(), true);
|
QCOMPARE(input.isFulfilled(), true);
|
||||||
QCOMPARE(output.isFulfilled(), true);
|
QCOMPARE(output.isFulfilled(), true);
|
||||||
}
|
}
|
||||||
@ -86,15 +86,15 @@ void tst_qpromise_then::resolveSync()
|
|||||||
void tst_qpromise_then::resolveAsync()
|
void tst_qpromise_then::resolveAsync()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::resolve(42).then([](int res) {
|
auto p = QPromise<int>::resolve(42).then([](int res) {
|
||||||
return QPromise<QString>([=](const QPromiseResolve<QString>& resolve) {
|
return QPromise<QString>{[=](const QPromiseResolve<QString>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(QString("foo%1").arg(res));
|
resolve(QString{"foo%1"}.arg(res));
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
||||||
QCOMPARE(waitForValue(p, QString()), QString("foo42"));
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo42"});
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ void tst_qpromise_then::rejectSync()
|
|||||||
{
|
{
|
||||||
auto input = QPromise<int>::resolve(42);
|
auto input = QPromise<int>::resolve(42);
|
||||||
auto output = input.then([](int res) {
|
auto output = input.then([](int res) {
|
||||||
throw QString("foo%1").arg(res);
|
throw QString{"foo%1"}.arg(res);
|
||||||
return 42;
|
return 42;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ void tst_qpromise_then::rejectSync()
|
|||||||
error += err;
|
error += err;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(error, QString("foo42"));
|
QCOMPARE(error, QString{"foo42"});
|
||||||
QCOMPARE(input.isFulfilled(), true);
|
QCOMPARE(input.isFulfilled(), true);
|
||||||
QCOMPARE(output.isRejected(), true);
|
QCOMPARE(output.isRejected(), true);
|
||||||
}
|
}
|
||||||
@ -121,15 +121,15 @@ void tst_qpromise_then::rejectSync()
|
|||||||
void tst_qpromise_then::rejectAsync()
|
void tst_qpromise_then::rejectAsync()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::resolve(42).then([](int res) {
|
auto p = QPromise<int>::resolve(42).then([](int res) {
|
||||||
return QPromise<void>([=](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
return QPromise<void>{[=](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString("foo%1").arg(res));
|
reject(QString{"foo%1"}.arg(res));
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo42"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo42"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,9 +155,9 @@ void tst_qpromise_then::nullHandler()
|
|||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
}
|
}
|
||||||
{ // rejected
|
{ // rejected
|
||||||
auto p = QPromise<int>::reject(QString("foo")).then(nullptr);
|
auto p = QPromise<int>::reject(QString{"foo"}).then(nullptr);
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,11 @@ void tst_qpromise_timeout::fulfilled()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>([](const QPromiseResolve<int>& resolve) {
|
auto p = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
||||||
QTimer::singleShot(1000, [=]() {
|
QTimer::singleShot(1000, [=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
}).timeout(2000).finally([&]() {
|
}}.timeout(2000).finally([&]() {
|
||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -58,16 +58,16 @@ void tst_qpromise_timeout::rejected()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
auto p = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QTimer::singleShot(1000, [=]() {
|
QTimer::singleShot(1000, [=]() {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
});
|
||||||
}).timeout(2000).finally([&]() {
|
}}.timeout(2000).finally([&]() {
|
||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QVERIFY(elapsed < 2000);
|
QVERIFY(elapsed < 2000);
|
||||||
}
|
}
|
||||||
@ -80,11 +80,11 @@ void tst_qpromise_timeout::timeout()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>([](const QPromiseResolve<int>& resolve) {
|
auto p = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
||||||
QTimer::singleShot(4000, [=]() {
|
QTimer::singleShot(4000, [=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
}).timeout(2000).finally([&]() {
|
}}.timeout(2000).finally([&]() {
|
||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -111,11 +111,11 @@ void tst_qpromise_timeout::fulfilledStdChrono()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>([](const QPromiseResolve<int>& resolve) {
|
auto p = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
||||||
QTimer::singleShot(1000, [=]() {
|
QTimer::singleShot(1000, [=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
}).timeout(std::chrono::seconds{2}).finally([&]() {
|
}}.timeout(std::chrono::seconds{2}).finally([&]() {
|
||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -131,16 +131,16 @@ void tst_qpromise_timeout::rejectedStdChrono()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
auto p = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QTimer::singleShot(1000, [=]() {
|
QTimer::singleShot(1000, [=]() {
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
});
|
||||||
}).timeout(std::chrono::seconds{2}).finally([&]() {
|
}}.timeout(std::chrono::seconds{2}).finally([&]() {
|
||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString()), QString("foo"));
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QVERIFY(elapsed < 2000);
|
QVERIFY(elapsed < 2000);
|
||||||
}
|
}
|
||||||
@ -153,11 +153,11 @@ void tst_qpromise_timeout::timeoutStdChrono()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>([](const QPromiseResolve<int>& resolve) {
|
auto p = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
||||||
QTimer::singleShot(4000, [=]() {
|
QTimer::singleShot(4000, [=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
}).timeout(std::chrono::seconds{2}).finally([&]() {
|
}}.timeout(std::chrono::seconds{2}).finally([&]() {
|
||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -43,9 +43,9 @@ void tst_requirements::statePending()
|
|||||||
// 2.1.1. When pending, a promise:
|
// 2.1.1. When pending, a promise:
|
||||||
// 2.1.1.1. may transition to either the fulfilled state
|
// 2.1.1.1. may transition to either the fulfilled state
|
||||||
{
|
{
|
||||||
QPromise<int> p([&](const QPromiseResolve<int>& resolve) {
|
QPromise<int> p{[&](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() { resolve(42); });
|
QtPromisePrivate::qtpromise_defer([=]() { resolve(42); });
|
||||||
});
|
}};
|
||||||
|
|
||||||
QVERIFY(p.isPending());
|
QVERIFY(p.isPending());
|
||||||
QVERIFY(!p.isFulfilled());
|
QVERIFY(!p.isFulfilled());
|
||||||
@ -60,9 +60,9 @@ void tst_requirements::statePending()
|
|||||||
|
|
||||||
// 2.1.1.1. ... or the rejected state
|
// 2.1.1.1. ... or the rejected state
|
||||||
{
|
{
|
||||||
QPromise<int> p([&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QPromise<int> p{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() { reject(QString("foo")); });
|
QtPromisePrivate::qtpromise_defer([=]() { reject(QString{"foo"}); });
|
||||||
});
|
}};
|
||||||
|
|
||||||
QVERIFY(p.isPending());
|
QVERIFY(p.isPending());
|
||||||
QVERIFY(!p.isFulfilled());
|
QVERIFY(!p.isFulfilled());
|
||||||
@ -82,7 +82,7 @@ void tst_requirements::stateFulfilled()
|
|||||||
int value = -1;
|
int value = -1;
|
||||||
|
|
||||||
// 2.1.2. When fulfilled, a promise:
|
// 2.1.2. When fulfilled, a promise:
|
||||||
QPromise<int> p([](
|
QPromise<int> p{[](
|
||||||
const QPromiseResolve<int>& resolve,
|
const QPromiseResolve<int>& resolve,
|
||||||
const QPromiseReject<int>& reject) {
|
const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
@ -91,9 +91,9 @@ void tst_requirements::stateFulfilled()
|
|||||||
resolve(43);
|
resolve(43);
|
||||||
|
|
||||||
// 2.1.2.1. must not transition to any other state.
|
// 2.1.2.1. must not transition to any other state.
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
QVERIFY(p.isPending());
|
QVERIFY(p.isPending());
|
||||||
|
|
||||||
@ -115,18 +115,18 @@ void tst_requirements::stateRejected()
|
|||||||
int value = -1;
|
int value = -1;
|
||||||
|
|
||||||
// 2.1.3 When rejected, a promise:
|
// 2.1.3 When rejected, a promise:
|
||||||
QPromise<int> p([](
|
QPromise<int> p{[](
|
||||||
const QPromiseResolve<int>& resolve,
|
const QPromiseResolve<int>& resolve,
|
||||||
const QPromiseReject<int>& reject) {
|
const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
// 2.1.3.2. must have a reason, which must not change.
|
// 2.1.3.2. must have a reason, which must not change.
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
reject(QString("bar"));
|
reject(QString{"bar"});
|
||||||
|
|
||||||
// 2.1.3.1. must not transition to any other state.
|
// 2.1.3.1. must not transition to any other state.
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QVERIFY(p.isPending());
|
QVERIFY(p.isPending());
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ void tst_requirements::stateRejected()
|
|||||||
|
|
||||||
QVERIFY(!p.isFulfilled());
|
QVERIFY(!p.isFulfilled());
|
||||||
QVERIFY(p.isRejected());
|
QVERIFY(p.isRejected());
|
||||||
QCOMPARE(error, QString("foo"));
|
QCOMPARE(error, QString{"foo"});
|
||||||
QCOMPARE(value, -1);
|
QCOMPARE(value, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,24 +159,24 @@ void tst_requirements::thenArguments()
|
|||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
int value = -1;
|
int value = -1;
|
||||||
QPromise<int>::reject(QString("foo")).then(
|
QPromise<int>::reject(QString{"foo"}).then(
|
||||||
[&](int res) { value = res; },
|
[&](int res) { value = res; },
|
||||||
[&](const QString& err){ error = err; }
|
[&](const QString& err){ error = err; }
|
||||||
).wait();
|
).wait();
|
||||||
|
|
||||||
QCOMPARE(error, QString("foo"));
|
QCOMPARE(error, QString{"foo"});
|
||||||
QCOMPARE(value, -1);
|
QCOMPARE(value, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.2.1. onFulfilled is an optional arguments:
|
// 2.2.1. onFulfilled is an optional arguments:
|
||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
QPromise<int>::reject(QString("foo")).then(
|
QPromise<int>::reject(QString{"foo"}).then(
|
||||||
nullptr,
|
nullptr,
|
||||||
[&](const QString& err){ error = err; return 42; }
|
[&](const QString& err){ error = err; return 42; }
|
||||||
).wait();
|
).wait();
|
||||||
|
|
||||||
QCOMPARE(error, QString("foo"));
|
QCOMPARE(error, QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.2.1. onRejected is an optional arguments:
|
// 2.2.1. onRejected is an optional arguments:
|
||||||
@ -198,13 +198,13 @@ void tst_requirements::thenOnFulfilled()
|
|||||||
{
|
{
|
||||||
// 2.2.2. If onFulfilled is a function:
|
// 2.2.2. If onFulfilled is a function:
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
QPromise<int> p0([](const QPromiseResolve<int>& resolve) {
|
QPromise<int> p0{[](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
// 2.2.2.3. it must not be called more than once
|
// 2.2.2.3. it must not be called more than once
|
||||||
resolve(42);
|
resolve(42);
|
||||||
resolve(43);
|
resolve(43);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
auto p1 = p0.then([&](int res) { values << res; });
|
auto p1 = p0.then([&](int res) { values << res; });
|
||||||
|
|
||||||
@ -226,13 +226,13 @@ void tst_requirements::thenOnRejected()
|
|||||||
{
|
{
|
||||||
// 2.2.3. If onRejected is a function:
|
// 2.2.3. If onRejected is a function:
|
||||||
QStringList errors;
|
QStringList errors;
|
||||||
QPromise<void> p0([](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
QPromise<void> p0{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
// 2.2.3.3. it must not be called more than once.
|
// 2.2.3.3. it must not be called more than once.
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
reject(QString("bar"));
|
reject(QString{"bar"});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p1 = p0.then(nullptr, [&](const QString& err) { errors << err; });
|
auto p1 = p0.then(nullptr, [&](const QString& err) { errors << err; });
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ void tst_requirements::thenOnRejected()
|
|||||||
// with promise’s reason as its first argument.
|
// with promise’s reason as its first argument.
|
||||||
QVERIFY(p0.isRejected());
|
QVERIFY(p0.isRejected());
|
||||||
QVERIFY(p1.isFulfilled());
|
QVERIFY(p1.isFulfilled());
|
||||||
QCOMPARE(errors, QStringList({"foo"}));
|
QCOMPARE(errors, (QStringList{"foo"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_requirements::thenAsynchronous()
|
void tst_requirements::thenAsynchronous()
|
||||||
@ -277,11 +277,11 @@ void tst_requirements::thenMultipleCalls()
|
|||||||
// must execute in the order of their originating calls to then:
|
// must execute in the order of their originating calls to then:
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
QPromise<int> p([](const QPromiseResolve<int>& resolve) {
|
QPromise<int> p{[](const QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QtPromise::all(QVector<QPromise<void>>{
|
QtPromise::all(QVector<QPromise<void>>{
|
||||||
p.then([&](int r) { values << r + 1; }),
|
p.then([&](int r) { values << r + 1; }),
|
||||||
@ -289,18 +289,18 @@ void tst_requirements::thenMultipleCalls()
|
|||||||
p.then([&](int r) { values << r + 3; })
|
p.then([&](int r) { values << r + 3; })
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(values, QVector<int>({43, 44, 45}));
|
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.2.6.2. If/when promise is rejected, all respective onRejected callbacks
|
// 2.2.6.2. If/when promise is rejected, all respective onRejected callbacks
|
||||||
// must execute in the order of their originating calls to then:
|
// must execute in the order of their originating calls to then:
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
QPromise<int> p([](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QPromise<int> p{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(8);
|
reject(8);
|
||||||
});
|
});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QtPromise::all(QVector<QPromise<int>>{
|
QtPromise::all(QVector<QPromise<int>>{
|
||||||
p.then(nullptr, [&](int r) { values << r + 1; return r + 1; }),
|
p.then(nullptr, [&](int r) { values << r + 1; return r + 1; }),
|
||||||
@ -308,7 +308,7 @@ void tst_requirements::thenMultipleCalls()
|
|||||||
p.then(nullptr, [&](int r) { values << r + 3; return r + 3; })
|
p.then(nullptr, [&](int r) { values << r + 3; return r + 3; })
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QCOMPARE(values, QVector<int>({9, 10, 11}));
|
QCOMPARE(values, (QVector<int>{9, 10, 11}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,22 +331,22 @@ void tst_requirements::thenHandlers()
|
|||||||
{
|
{
|
||||||
QString reason;
|
QString reason;
|
||||||
auto p1 = QPromise<int>::resolve(42);
|
auto p1 = QPromise<int>::resolve(42);
|
||||||
auto p2 = p1.then([](){ throw QString("foo"); });
|
auto p2 = p1.then([](){ throw QString{"foo"}; });
|
||||||
p2.then(nullptr, [&](const QString& e) { reason = e; }).wait();
|
p2.then(nullptr, [&](const QString& e) { reason = e; }).wait();
|
||||||
|
|
||||||
QVERIFY(p1.isFulfilled());
|
QVERIFY(p1.isFulfilled());
|
||||||
QVERIFY(p2.isRejected());
|
QVERIFY(p2.isRejected());
|
||||||
QCOMPARE(reason, QString("foo"));
|
QCOMPARE(reason, QString{"foo"});
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
QString reason;
|
QString reason;
|
||||||
auto p1 = QPromise<int>::reject(QString("foo"));
|
auto p1 = QPromise<int>::reject(QString{"foo"});
|
||||||
auto p2 = p1.then(nullptr, [](){ throw QString("bar"); return 42; });
|
auto p2 = p1.then(nullptr, [](){ throw QString{"bar"}; return 42; });
|
||||||
p2.then(nullptr, [&](const QString& e) { reason = e; return 0; }).wait();
|
p2.then(nullptr, [&](const QString& e) { reason = e; return 0; }).wait();
|
||||||
|
|
||||||
QVERIFY(p1.isRejected());
|
QVERIFY(p1.isRejected());
|
||||||
QVERIFY(p2.isRejected());
|
QVERIFY(p2.isRejected());
|
||||||
QCOMPARE(reason, QString("bar"));
|
QCOMPARE(reason, QString{"bar"});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.2.7.3. If onFulfilled is not a function and promise1 is fulfilled,
|
// 2.2.7.3. If onFulfilled is not a function and promise1 is fulfilled,
|
||||||
@ -354,12 +354,12 @@ void tst_requirements::thenHandlers()
|
|||||||
{
|
{
|
||||||
QString value;
|
QString value;
|
||||||
auto p1 = QPromise<QString>::resolve("42");
|
auto p1 = QPromise<QString>::resolve("42");
|
||||||
auto p2 = p1.then(nullptr, [](){ return QString(); });
|
auto p2 = p1.then(nullptr, [](){ return QString{}; });
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<QString>>::value));
|
||||||
p2.then([&](const QString& e) { value = e; }).wait();
|
p2.then([&](const QString& e) { value = e; }).wait();
|
||||||
|
|
||||||
QVERIFY(p1.isFulfilled());
|
QVERIFY(p1.isFulfilled());
|
||||||
QVERIFY(p2.isFulfilled());
|
QVERIFY(p2.isFulfilled());
|
||||||
QCOMPARE(value, QString("42"));
|
QCOMPARE(value, QString{"42"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public: // STATICS
|
|||||||
|
|
||||||
struct Data : public Logger
|
struct Data : public Logger
|
||||||
{
|
{
|
||||||
Data(int v) : Logger(), m_value(v) {}
|
Data(int v) : Logger{}, m_value{v} {}
|
||||||
int value() const { return m_value; }
|
int value() const { return m_value; }
|
||||||
|
|
||||||
// MSVC 2013 doesn't support implicit generation of the move constructor and
|
// MSVC 2013 doesn't support implicit generation of the move constructor and
|
||||||
@ -49,11 +49,11 @@ struct Data : public Logger
|
|||||||
// https://stackoverflow.com/a/26581337
|
// https://stackoverflow.com/a/26581337
|
||||||
|
|
||||||
Data(const Data& other)
|
Data(const Data& other)
|
||||||
: Logger(other)
|
: Logger{other}
|
||||||
, m_value(other.m_value)
|
, m_value{other.m_value}
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Data(Data&& other) : Logger(std::forward<Data>(other))
|
Data(Data&& other) : Logger{std::forward<Data>(other)}
|
||||||
{
|
{
|
||||||
std::swap(m_value, other.m_value);
|
std::swap(m_value, other.m_value);
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,12 @@ void tst_thread::resolve()
|
|||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
|
|
||||||
QPromise<int>([&](const QPromiseResolve<int>& resolve) {
|
QPromise<int>{[&](const QPromiseResolve<int>& resolve) {
|
||||||
QtConcurrent::run([=, &source]() {
|
QtConcurrent::run([=, &source]() {
|
||||||
source = QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
}).then([&](int res) {
|
}}.then([&](int res) {
|
||||||
target = QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
value = res;
|
value = res;
|
||||||
}).wait();
|
}).wait();
|
||||||
@ -57,12 +57,12 @@ void tst_thread::resolve_void()
|
|||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
|
|
||||||
QPromise<void>([&](const QPromiseResolve<void>& resolve) {
|
QPromise<void>{[&](const QPromiseResolve<void>& resolve) {
|
||||||
QtConcurrent::run([=, &source]() {
|
QtConcurrent::run([=, &source]() {
|
||||||
source = QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}).then([&]() {
|
}}.then([&]() {
|
||||||
target = QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
value = 43;
|
value = 43;
|
||||||
}).wait();
|
}).wait();
|
||||||
@ -79,12 +79,12 @@ void tst_thread::reject()
|
|||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
|
|
||||||
QPromise<int>([&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QPromise<int>{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtConcurrent::run([=, &source]() {
|
QtConcurrent::run([=, &source]() {
|
||||||
source = QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
});
|
||||||
}).fail([&](const QString& err) {
|
}}.fail([&](const QString& err) {
|
||||||
target = QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
error = err;
|
error = err;
|
||||||
return -1;
|
return -1;
|
||||||
@ -93,16 +93,16 @@ void tst_thread::reject()
|
|||||||
QVERIFY(source != nullptr);
|
QVERIFY(source != nullptr);
|
||||||
QVERIFY(source != target);
|
QVERIFY(source != target);
|
||||||
QCOMPARE(target, QThread::currentThread());
|
QCOMPARE(target, QThread::currentThread());
|
||||||
QCOMPARE(error, QString("foo"));
|
QCOMPARE(error, QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_thread::then()
|
void tst_thread::then()
|
||||||
{
|
{
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
QPromise<int> p([&](const QPromiseResolve<int>& resolve) {
|
QPromise<int> p{[&](const QPromiseResolve<int>& resolve) {
|
||||||
source = QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
}};
|
||||||
|
|
||||||
int value = -1;
|
int value = -1;
|
||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
@ -122,10 +122,10 @@ void tst_thread::then()
|
|||||||
void tst_thread::then_void()
|
void tst_thread::then_void()
|
||||||
{
|
{
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
QPromise<void> p([&](const QPromiseResolve<void>& resolve) {
|
QPromise<void> p{[&](const QPromiseResolve<void>& resolve) {
|
||||||
source = QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
}};
|
||||||
|
|
||||||
int value = -1;
|
int value = -1;
|
||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
@ -145,10 +145,10 @@ void tst_thread::then_void()
|
|||||||
void tst_thread::fail()
|
void tst_thread::fail()
|
||||||
{
|
{
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
QPromise<int> p([&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QPromise<int> p{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
source = QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
reject(QString("foo"));
|
reject(QString{"foo"});
|
||||||
});
|
}};
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
@ -163,16 +163,16 @@ void tst_thread::fail()
|
|||||||
QVERIFY(target != nullptr);
|
QVERIFY(target != nullptr);
|
||||||
QVERIFY(source != target);
|
QVERIFY(source != target);
|
||||||
QCOMPARE(source, QThread::currentThread());
|
QCOMPARE(source, QThread::currentThread());
|
||||||
QCOMPARE(error, QString("foo"));
|
QCOMPARE(error, QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_thread::finally()
|
void tst_thread::finally()
|
||||||
{
|
{
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
QPromise<int> p([&](const QPromiseResolve<int>& resolve) {
|
QPromise<int> p{[&](const QPromiseResolve<int>& resolve) {
|
||||||
source = QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
}};
|
||||||
|
|
||||||
int value = -1;
|
int value = -1;
|
||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user