From 9f01c130cd061d151af80fa4d7ee7fc6f1f18ba0 Mon Sep 17 00:00:00 2001 From: Simon Brunel Date: Sun, 26 Jun 2022 18:10:20 +0200 Subject: [PATCH] Add support for Qt 6 --- CMakeLists.txt | 9 +- README.md | 2 +- cmake/QtPromiseAddTest.cmake | 4 +- docs/README.md | 2 +- src/qtpromise/qpromise_p.h | 9 +- src/qtpromise/qpromiseconnections.h | 3 +- tests/CMakeLists.txt | 2 +- .../qtpromise/benchmark/tst_benchmark.cpp | 63 ++++----- .../cpp14/tst_resolver_lambda_auto.cpp | 18 ++- .../deprecations/tst_helpers_qpromise.cpp | 128 +++++++++--------- .../deprecations/tst_helpers_qpromiseall.cpp | 86 ++++++------ .../deprecations/tst_qpromise_all.cpp | 90 ++++++------ .../qtpromise/exceptions/tst_exceptions.cpp | 12 +- tests/auto/qtpromise/future/tst_future.cpp | 30 ++-- tests/auto/qtpromise/helpers/tst_all.cpp | 82 +++++------ tests/auto/qtpromise/helpers/tst_attempt.cpp | 14 +- tests/auto/qtpromise/helpers/tst_connect.cpp | 30 ++-- tests/auto/qtpromise/helpers/tst_each.cpp | 38 +++--- tests/auto/qtpromise/helpers/tst_filter.cpp | 40 +++--- tests/auto/qtpromise/helpers/tst_map.cpp | 42 +++--- tests/auto/qtpromise/helpers/tst_reduce.cpp | 52 ++++--- tests/auto/qtpromise/helpers/tst_reject.cpp | 8 +- tests/auto/qtpromise/helpers/tst_resolve.cpp | 86 ++++++------ .../auto/qtpromise/qpromise/tst_construct.cpp | 124 +++++++++-------- tests/auto/qtpromise/qpromise/tst_convert.cpp | 44 +++--- tests/auto/qtpromise/qpromise/tst_delay.cpp | 16 +-- tests/auto/qtpromise/qpromise/tst_each.cpp | 52 ++++--- tests/auto/qtpromise/qpromise/tst_fail.cpp | 65 +++++---- tests/auto/qtpromise/qpromise/tst_filter.cpp | 59 ++++---- tests/auto/qtpromise/qpromise/tst_finally.cpp | 52 +++---- tests/auto/qtpromise/qpromise/tst_map.cpp | 40 +++--- .../auto/qtpromise/qpromise/tst_operators.cpp | 82 +++++------ tests/auto/qtpromise/qpromise/tst_reduce.cpp | 52 ++++--- tests/auto/qtpromise/qpromise/tst_resolve.cpp | 64 ++++----- tests/auto/qtpromise/qpromise/tst_tap.cpp | 23 ++-- tests/auto/qtpromise/qpromise/tst_tapfail.cpp | 23 ++-- tests/auto/qtpromise/qpromise/tst_then.cpp | 45 +++--- tests/auto/qtpromise/qpromise/tst_timeout.cpp | 20 +-- .../tst_qpromiseconnections.cpp | 8 +- .../requirements/tst_requirements.cpp | 112 +++++++-------- tests/auto/qtpromise/shared/CMakeLists.txt | 2 +- tests/auto/qtpromise/thread/tst_thread.cpp | 46 +++---- 42 files changed, 887 insertions(+), 892 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7967e59..68c4b3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,8 @@ project(qtpromise VERSION 0.6.0 LANGUAGES CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") -find_package(Qt5 5.6.0 REQUIRED COMPONENTS Core) +find_package(QT 5.6.0 NAMES Qt6 Qt5 REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_STANDARD 11) @@ -17,7 +18,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) add_library(qtpromise INTERFACE) add_library(qtpromise::qtpromise ALIAS qtpromise) -target_link_libraries(qtpromise INTERFACE Qt5::Core) +target_link_libraries(qtpromise INTERFACE Qt${QT_VERSION_MAJOR}::Core) target_include_directories(qtpromise INTERFACE "${CMAKE_CURRENT_LIST_DIR}/include") add_definitions( @@ -33,7 +34,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") -Wpedantic -Wall -Wextra - -Wconversion -Wdouble-promotion -Wformat=2 @@ -44,8 +44,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") -Wsign-conversion -Wswitch-default -Wunused-local-typedefs -# -Wuseless-cast # disabled due to Qt's moc warnings - -pedantic-errors ) @@ -68,7 +66,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") -Wall -Wextra -Wpedantic - -Wsuggest-destructor-override -Wsuggest-override ) diff --git a/README.md b/README.md index 5231ccb..7453268 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ [Promises/A+](https://promisesaplus.com/) implementation for [Qt/C++](https://www.qt.io/). -Requires [Qt 5.6](https://www.qt.io/download/) (or later) with [C++11 support enabled](https://wiki.qt.io/How_to_use_C++11_in_your_Qt_Projects). +Requires [Qt 5.6](https://doc.qt.io/qt-5/) (or later) with [C++11 support enabled](https://wiki.qt.io/How_to_use_C++11_in_your_Qt_Projects) or [Qt 6](https://doc.qt.io/qt-6/). ## Documentation diff --git a/cmake/QtPromiseAddTest.cmake b/cmake/QtPromiseAddTest.cmake index 3fc969b..4d356e5 100644 --- a/cmake/QtPromiseAddTest.cmake +++ b/cmake/QtPromiseAddTest.cmake @@ -17,8 +17,8 @@ function(qtpromise_add_test NAME) endif() target_link_libraries(${_TARGET} - Qt5::Concurrent - Qt5::Test + Qt${QT_VERSION_MAJOR}::Concurrent + Qt${QT_VERSION_MAJOR}::Test qtpromise qtpromise.tests.utils ${_ARG_LIBRARIES} diff --git a/docs/README.md b/docs/README.md index aaa2a20..732ccae 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,7 +15,7 @@ footer: MIT Licensed | Copyright © Simon Brunel, https://github.com/simonbrunel [Promises/A+](https://promisesaplus.com/) implementation for [Qt/C++](https://www.qt.io/). -Requires [Qt 5.6](https://www.qt.io/download/) (or later) with [C++11 support enabled](https://wiki.qt.io/How_to_use_C++11_in_your_Qt_Projects). +Requires [Qt 5.6](https://doc.qt.io/qt-5/) (or later) with [C++11 support enabled](https://wiki.qt.io/How_to_use_C++11_in_your_Qt_Projects) or [Qt 6](https://doc.qt.io/qt-6/). ## Documentation diff --git a/src/qtpromise/qpromise_p.h b/src/qtpromise/qpromise_p.h index 87b5cc5..2b5e674 100644 --- a/src/qtpromise/qpromise_p.h +++ b/src/qtpromise/qpromise_p.h @@ -578,11 +578,18 @@ struct PromiseConverterBase return [](const T& value) { auto tmp = QVariant::fromValue(value); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + // https://doc.qt.io/qt-6/qvariant.html#using-canconvert-and-convert-consecutively + if (tmp.canConvert(QMetaType{qMetaTypeId()}) + && tmp.convert(QMetaType{qMetaTypeId()})) { + return qvariant_cast(tmp); + } +#else // https://doc.qt.io/qt-5/qvariant.html#using-canconvert-and-convert-consecutively if (tmp.canConvert(qMetaTypeId()) && tmp.convert(qMetaTypeId())) { return qvariant_cast(tmp); } - +#endif throw QtPromise::QPromiseConversionException{}; }; } diff --git a/src/qtpromise/qpromiseconnections.h b/src/qtpromise/qpromiseconnections.h index 0754d66..5e8007f 100644 --- a/src/qtpromise/qpromiseconnections.h +++ b/src/qtpromise/qpromiseconnections.h @@ -9,6 +9,7 @@ #define QTPROMISE_QPROMISECONNECTIONS_H #include + #include namespace QtPromise { @@ -18,7 +19,7 @@ class QPromiseConnections public: QPromiseConnections() : m_d(std::make_shared()) { } - int count() const { return m_d->connections.count(); } + int count() const { return static_cast(m_d->connections.count()); } void disconnect() const { m_d->disconnect(); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a6911a5..77a2b48 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -find_package(Qt5 5.6.0 REQUIRED +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Concurrent Test diff --git a/tests/auto/qtpromise/benchmark/tst_benchmark.cpp b/tests/auto/qtpromise/benchmark/tst_benchmark.cpp index 29a62e6..380b64c 100644 --- a/tests/auto/qtpromise/benchmark/tst_benchmark.cpp +++ b/tests/auto/qtpromise/benchmark/tst_benchmark.cpp @@ -18,8 +18,6 @@ # define EXCEPT_CALL_COPY_CTOR 0 #endif -using namespace QtPromise; - class tst_benchmark : public QObject { Q_OBJECT @@ -43,7 +41,7 @@ void tst_benchmark::valueResolve() { { // should move the value when resolved by rvalue Data::logs().reset(); - QPromise{[&](const QPromiseResolve& resolve) { + QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve) { resolve(Data{42}); }}.wait(); @@ -54,7 +52,7 @@ void tst_benchmark::valueResolve() } { // should create one copy of the value when resolved by lvalue Data::logs().reset(); - QPromise{[&](const QPromiseResolve& resolve) { + QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve) { Data value{42}; resolve(value); }}.wait(); @@ -70,7 +68,8 @@ void tst_benchmark::valueReject() { { // should not create any data if rejected Data::logs().reset(); - QPromise{[&](const QPromiseResolve&, const QPromiseReject& reject) { + QtPromise::QPromise{[&](const QtPromise::QPromiseResolve&, + const QtPromise::QPromiseReject& reject) { reject(QString{"foo"}); }}.wait(); @@ -83,10 +82,10 @@ void tst_benchmark::valueReject() void tst_benchmark::valueThen() { - { // should not copy value on continutation if fulfilled + { // should not copy value on continuation if fulfilled int value = -1; Data::logs().reset(); - QPromise::resolve(Data{42}) + QtPromise::QPromise::resolve(Data{42}) .then([&](const Data& res) { value = res.value(); }) @@ -98,11 +97,11 @@ void tst_benchmark::valueThen() QCOMPARE(Data::logs().refs, 0); QCOMPARE(value, 42); } - { // should not create value on continutation if rejected + { // should not create value on continuation if rejected int value = -1; QString error; Data::logs().reset(); - QPromise::reject(QString{"foo"}) + QtPromise::QPromise::reject(QString{"foo"}) .then( [&](const Data& res) { value = res.value(); @@ -122,7 +121,7 @@ void tst_benchmark::valueThen() { // should move the returned value when fulfilled int value = -1; Data::logs().reset(); - QPromise::resolve(42) + QtPromise::QPromise::resolve(42) .then([&](int res) { return Data{res + 2}; }) @@ -139,7 +138,7 @@ void tst_benchmark::valueThen() } { // should not create any data if handler throws Data::logs().reset(); - QPromise::resolve(42) + QtPromise::QPromise::resolve(42) .then([&](int res) { throw QString{"foo"}; return Data{res + 2}; @@ -155,12 +154,12 @@ void tst_benchmark::valueThen() void tst_benchmark::valueDelayed() { - { // should not copy the value on continutation if fulfilled + { // should not copy the value on continuation if fulfilled int value = -1; Data::logs().reset(); - QPromise::resolve(42) + QtPromise::QPromise::resolve(42) .then([&](int res) { - return QPromise::resolve(Data{res + 1}); + return QtPromise::QPromise::resolve(Data{res + 1}); }) .then([&](const Data& res) { value = res.value(); @@ -173,11 +172,11 @@ void tst_benchmark::valueDelayed() QCOMPARE(Data::logs().refs, 0); QCOMPARE(value, 43); } - { // should not create value on continutation if rejected + { // should not create value on continuation if rejected Data::logs().reset(); - QPromise::resolve(42) + QtPromise::QPromise::resolve(42) .then([&]() { - return QPromise::reject(QString{"foo"}); + return QtPromise::QPromise::reject(QString{"foo"}); }) .wait(); @@ -190,10 +189,10 @@ void tst_benchmark::valueDelayed() void tst_benchmark::valueFinally() { - { // should not copy the value on continutation if fulfilled + { // should not copy the value on continuation if fulfilled int value = -1; Data::logs().reset(); - QPromise::resolve(Data{42}) + QtPromise::QPromise::resolve(Data{42}) .finally([&]() { value = 42; }) @@ -205,10 +204,10 @@ void tst_benchmark::valueFinally() QCOMPARE(Data::logs().refs, 0); QCOMPARE(value, 42); } - { // should not create value on continutation if rejected + { // should not create value on continuation if rejected int value = -1; Data::logs().reset(); - QPromise::reject(QString{"foo"}) + QtPromise::QPromise::reject(QString{"foo"}) .finally([&]() { value = 42; }) @@ -224,10 +223,10 @@ void tst_benchmark::valueFinally() void tst_benchmark::valueTap() { - { // should not copy the value on continutation if fulfilled + { // should not copy the value on continuation if fulfilled int value = -1; Data::logs().reset(); - QPromise::resolve(Data{42}) + QtPromise::QPromise::resolve(Data{42}) .tap([&](const Data& res) { value = res.value(); }) @@ -239,10 +238,10 @@ void tst_benchmark::valueTap() QCOMPARE(Data::logs().refs, 0); QCOMPARE(value, 42); } - { // should not create value on continutation if rejected + { // should not create value on continuation if rejected int value = -1; Data::logs().reset(); - QPromise::reject(QString{"foo"}) + QtPromise::QPromise::reject(QString{"foo"}) .tap([&](const Data& res) { value = res.value(); }) @@ -260,7 +259,8 @@ void tst_benchmark::errorReject() { { // should create one copy of the error when rejected by rvalue Data::logs().reset(); - QPromise{[&](const QPromiseResolve&, const QPromiseReject& reject) { + QtPromise::QPromise{[&](const QtPromise::QPromiseResolve&, + const QtPromise::QPromiseReject& reject) { reject(Data{42}); }}.wait(); @@ -271,7 +271,8 @@ void tst_benchmark::errorReject() } { // should create one copy of the error when rejected by lvalue (no extra copy) Data::logs().reset(); - QPromise{[&](const QPromiseResolve&, const QPromiseReject& reject) { + QtPromise::QPromise{[&](const QtPromise::QPromiseResolve&, + const QtPromise::QPromiseReject& reject) { Data error{42}; reject(error); }}.wait(); @@ -285,10 +286,10 @@ void tst_benchmark::errorReject() void tst_benchmark::errorThen() { - { // should not copy error on continutation if rejected + { // should not copy error on continuation if rejected int value = -1; Data::logs().reset(); - QPromise::reject(Data{42}) + QtPromise::QPromise::reject(Data{42}) .fail([&](const Data& res) { value = res.value(); }) @@ -301,10 +302,10 @@ void tst_benchmark::errorThen() QCOMPARE(Data::logs().refs, 0); QCOMPARE(value, 42); } - { // should not copy error on continutation if rethrown + { // should not copy error on continuation if rethrown int value = -1; Data::logs().reset(); - QPromise::reject(Data{42}) + QtPromise::QPromise::reject(Data{42}) .fail([](const Data&) { throw; }) diff --git a/tests/auto/qtpromise/cpp14/tst_resolver_lambda_auto.cpp b/tests/auto/qtpromise/cpp14/tst_resolver_lambda_auto.cpp index 3f4a7a7..f9d290c 100644 --- a/tests/auto/qtpromise/cpp14/tst_resolver_lambda_auto.cpp +++ b/tests/auto/qtpromise/cpp14/tst_resolver_lambda_auto.cpp @@ -12,8 +12,6 @@ #include -using namespace QtPromise; - class tst_cpp14_resolver_lambda_auto : public QObject { Q_OBJECT @@ -28,19 +26,19 @@ QTEST_MAIN(tst_cpp14_resolver_lambda_auto) void tst_cpp14_resolver_lambda_auto::resolverTwoAutoArgs() { - QPromise p0{[](auto resolve, auto reject) { + QtPromise::QPromise p0{[](auto resolve, auto reject) { Q_UNUSED(reject) resolve(42); }}; - QPromise p1{[](auto resolve, const auto& reject) { + QtPromise::QPromise p1{[](auto resolve, const auto& reject) { Q_UNUSED(reject) resolve(42); }}; - QPromise p2{[](const auto& resolve, auto reject) { + QtPromise::QPromise p2{[](const auto& resolve, auto reject) { Q_UNUSED(reject) resolve(42); }}; - QPromise p3{[](const auto& resolve, const auto& reject) { + QtPromise::QPromise p3{[](const auto& resolve, const auto& reject) { Q_UNUSED(reject) resolve(42); }}; @@ -54,19 +52,19 @@ void tst_cpp14_resolver_lambda_auto::resolverTwoAutoArgs() void tst_cpp14_resolver_lambda_auto::resolverTwoAutoArgs_void() { - QPromise p0{[](auto resolve, auto reject) { + QtPromise::QPromise p0{[](auto resolve, auto reject) { Q_UNUSED(reject) resolve(); }}; - QPromise p1{[](auto resolve, const auto& reject) { + QtPromise::QPromise p1{[](auto resolve, const auto& reject) { Q_UNUSED(reject) resolve(); }}; - QPromise p2{[](const auto& resolve, auto reject) { + QtPromise::QPromise p2{[](const auto& resolve, auto reject) { Q_UNUSED(reject) resolve(); }}; - QPromise p3{[](const auto& resolve, const auto& reject) { + QtPromise::QPromise p3{[](const auto& resolve, const auto& reject) { Q_UNUSED(reject) resolve(); }}; diff --git a/tests/auto/qtpromise/deprecations/tst_helpers_qpromise.cpp b/tests/auto/qtpromise/deprecations/tst_helpers_qpromise.cpp index f4bb173..4b45018 100644 --- a/tests/auto/qtpromise/deprecations/tst_helpers_qpromise.cpp +++ b/tests/auto/qtpromise/deprecations/tst_helpers_qpromise.cpp @@ -14,8 +14,6 @@ #include -using namespace QtPromise; - class tst_deprecations_helpers_qpromise : public QObject { Q_OBJECT @@ -41,13 +39,13 @@ void tst_deprecations_helpers_qpromise::value() int v0 = 42; const int v1 = 42; - auto p0 = qPromise(42); - auto p1 = qPromise(v0); - auto p2 = qPromise(v1); + auto p0 = QtPromise::qPromise(42); + auto p1 = QtPromise::qPromise(v0); + auto p2 = QtPromise::qPromise(v1); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); for (const auto& p : {p0, p1, p2}) { QCOMPARE(p.isFulfilled(), true); @@ -59,9 +57,9 @@ void tst_deprecations_helpers_qpromise::value() void tst_deprecations_helpers_qpromise::noValue() { - auto p = qPromise(); + auto p = QtPromise::qPromise(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForValue(p, -1, 42), 42); @@ -72,9 +70,9 @@ void tst_deprecations_helpers_qpromise::moveRValue() Data::logs().reset(); { - auto p = qPromise(Data{42}).wait(); + auto p = QtPromise::qPromise(Data{42}).wait(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); } QCOMPARE(Data::logs().ctor, 1); @@ -89,9 +87,9 @@ void tst_deprecations_helpers_qpromise::copyLValue() { Data value{42}; - auto p = qPromise(value).wait(); + auto p = QtPromise::qPromise(value).wait(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); } QCOMPARE(Data::logs().ctor, 1); @@ -103,24 +101,26 @@ void tst_deprecations_helpers_qpromise::copyLValue() // https://github.com/simonbrunel/qtpromise/issues/6 void tst_deprecations_helpers_qpromise::qtSharedPtr() { + using DataSPtr = QSharedPointer; + Data::logs().reset(); QWeakPointer wptr; { - auto sptr0 = QSharedPointer::create(42); - const QSharedPointer sptr1 = sptr0; + auto sptr0 = DataSPtr::create(42); + const DataSPtr sptr1 = sptr0; - auto p0 = qPromise(QSharedPointer::create(42)); - auto p1 = qPromise(sptr0); - auto p2 = qPromise(sptr1); + auto p0 = QtPromise::qPromise(DataSPtr::create(42)); + auto p1 = QtPromise::qPromise(sptr0); + auto p2 = QtPromise::qPromise(sptr1); - Q_STATIC_ASSERT((std::is_same>>::value)); - Q_STATIC_ASSERT((std::is_same>>::value)); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); - QCOMPARE(waitForValue(p1, QSharedPointer{}), sptr0); - QCOMPARE(waitForValue(p2, QSharedPointer{}), sptr1); + QCOMPARE(waitForValue(p1, DataSPtr{}), sptr0); + QCOMPARE(waitForValue(p2, DataSPtr{}), sptr1); wptr = sptr0; @@ -139,24 +139,26 @@ void tst_deprecations_helpers_qpromise::qtSharedPtr() // https://github.com/simonbrunel/qtpromise/issues/6 void tst_deprecations_helpers_qpromise::stdSharedPtr() { + using DataSPtr = std::shared_ptr; + Data::logs().reset(); std::weak_ptr wptr; { auto sptr0 = std::make_shared(42); - const std::shared_ptr sptr1 = sptr0; + const DataSPtr sptr1 = sptr0; - auto p0 = qPromise(std::make_shared(42)); - auto p1 = qPromise(sptr0); - auto p2 = qPromise(sptr1); + auto p0 = QtPromise::qPromise(std::make_shared(42)); + auto p1 = QtPromise::qPromise(sptr0); + auto p2 = QtPromise::qPromise(sptr1); - Q_STATIC_ASSERT((std::is_same>>::value)); - Q_STATIC_ASSERT((std::is_same>>::value)); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); - QCOMPARE(waitForValue(p1, std::shared_ptr{}), sptr0); - QCOMPARE(waitForValue(p2, std::shared_ptr{}), sptr1); + QCOMPARE(waitForValue(p1, DataSPtr{}), sptr0); + QCOMPARE(waitForValue(p2, DataSPtr{}), sptr1); wptr = sptr0; @@ -174,22 +176,22 @@ void tst_deprecations_helpers_qpromise::stdSharedPtr() void tst_deprecations_helpers_qpromise::typedPromise() { - auto resolver = [](const QPromiseResolve& resolve) { + auto resolver = [](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(42); }); }; - QPromise v0{resolver}; - const QPromise v1 = v0; + QtPromise::QPromise v0{resolver}; + const QtPromise::QPromise v1 = v0; - auto p0 = qPromise(QPromise{resolver}); - auto p1 = qPromise(v0); - auto p2 = qPromise(v1); + auto p0 = QtPromise::qPromise(QtPromise::QPromise{resolver}); + auto p1 = QtPromise::qPromise(v0); + auto p2 = QtPromise::qPromise(v1); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); for (const auto& promise : {p0, p1, p2}) { QCOMPARE(promise.isPending(), true); @@ -201,22 +203,22 @@ void tst_deprecations_helpers_qpromise::typedPromise() void tst_deprecations_helpers_qpromise::voidPromise() { - auto resolver = [](const QPromiseResolve& resolve) { + auto resolver = [](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(); }); }; - QPromise v0{resolver}; - const QPromise v1 = v0; + QtPromise::QPromise v0{resolver}; + const QtPromise::QPromise v1 = v0; - auto p0 = qPromise(QPromise{resolver}); - auto p1 = qPromise(v0); - auto p2 = qPromise(v1); + auto p0 = QtPromise::qPromise(QtPromise::QPromise{resolver}); + auto p1 = QtPromise::qPromise(v0); + auto p2 = QtPromise::qPromise(v1); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); for (const auto& promise : {p0, p1, p2}) { QCOMPARE(promise.isPending(), true); @@ -234,13 +236,13 @@ void tst_deprecations_helpers_qpromise::typedFuture() QFuture v0 = QtConcurrent::run(fn); const QFuture v1 = v0; - auto p0 = qPromise(QtConcurrent::run(fn)); - auto p1 = qPromise(v0); - auto p2 = qPromise(v1); + auto p0 = QtPromise::qPromise(QtConcurrent::run(fn)); + auto p1 = QtPromise::qPromise(v0); + auto p2 = QtPromise::qPromise(v1); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); for (const auto& promise : {p0, p1, p2}) { QCOMPARE(promise.isPending(), true); @@ -256,13 +258,13 @@ void tst_deprecations_helpers_qpromise::voidFuture() QFuture v0 = QtConcurrent::run(fn); const QFuture v1 = v0; - auto p0 = qPromise(QtConcurrent::run(fn)); - auto p1 = qPromise(v0); - auto p2 = qPromise(v1); + auto p0 = QtPromise::qPromise(QtConcurrent::run(fn)); + auto p1 = QtPromise::qPromise(v0); + auto p2 = QtPromise::qPromise(v1); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); for (const auto& promise : {p0, p1, p2}) { QCOMPARE(promise.isPending(), true); diff --git a/tests/auto/qtpromise/deprecations/tst_helpers_qpromiseall.cpp b/tests/auto/qtpromise/deprecations/tst_helpers_qpromiseall.cpp index 2f0f36a..04c171a 100644 --- a/tests/auto/qtpromise/deprecations/tst_helpers_qpromiseall.cpp +++ b/tests/auto/qtpromise/deprecations/tst_helpers_qpromiseall.cpp @@ -10,8 +10,6 @@ #include #include -using namespace QtPromise; - class tst_deprecations_helpers_qpromiseall : public QObject { Q_OBJECT @@ -36,7 +34,7 @@ namespace { template struct SequenceTester { - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); static void exec() { @@ -48,20 +46,20 @@ struct SequenceTester auto p = qPromiseAll(promises); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 46, 43, 44})); } }; template class Sequence, typename... Args> -struct SequenceTester, Args...>> +struct SequenceTester, Args...>> { static void exec() { - Sequence, Args...> promises{QtPromise::resolve(), - QtPromise::resolve(), - QtPromise::resolve()}; + Sequence, Args...> promises{QtPromise::resolve(), + QtPromise::resolve(), + QtPromise::resolve()}; promises.push_back(QtPromise::resolve()); promises.insert(++promises.begin(), QtPromise::resolve()); @@ -69,7 +67,7 @@ struct SequenceTester, Args...>> auto p = qPromiseAll(promises); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, -1, 42), 42); } @@ -79,18 +77,18 @@ struct SequenceTester, Args...>> void tst_deprecations_helpers_qpromiseall::emptySequence() { - auto p = qPromiseAll(QVector>()); + auto p = qPromiseAll(QVector>()); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForValue(p, QVector{}), QVector{}); } void tst_deprecations_helpers_qpromiseall::emptySequence_void() { - auto p = qPromiseAll(QVector>()); + auto p = qPromiseAll(QVector>()); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForValue(p, -1, 42), 42); } @@ -99,15 +97,15 @@ void tst_deprecations_helpers_qpromiseall::allPromisesSucceed() { auto p0 = QtPromise::resolve(42); auto p1 = QtPromise::resolve(44); - auto p2 = QPromise{[](const QPromiseResolve& resolve) { + auto p2 = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(43); }); }}; - auto p = qPromiseAll(QVector>{p0, p2, p1}); + auto p = QtPromise::qPromiseAll(QVector>{p0, p2, p1}); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(p1.isFulfilled(), true); QCOMPARE(p2.isPending(), true); @@ -120,15 +118,15 @@ void tst_deprecations_helpers_qpromiseall::allPromisesSucceed_void() { auto p0 = QtPromise::resolve(); auto p1 = QtPromise::resolve(); - auto p2 = QPromise{[](const QPromiseResolve& resolve) { + auto p2 = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(); }); }}; - auto p = qPromiseAll(QVector>{p0, p2, p1}); + auto p = QtPromise::qPromiseAll(QVector>{p0, p2, p1}); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(p1.isFulfilled(), true); QCOMPARE(p2.isPending(), true); @@ -141,15 +139,16 @@ void tst_deprecations_helpers_qpromiseall::atLeastOnePromiseReject() { auto p0 = QtPromise::resolve(42); auto p1 = QtPromise::resolve(44); - auto p2 = QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo"}); - }); - }}; + auto p2 = QtPromise::QPromise{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo"}); + }); + }}; - auto p = qPromiseAll(QVector>{p0, p2, p1}); + auto p = QtPromise::qPromiseAll(QVector>{p0, p2, p1}); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(p1.isFulfilled(), true); QCOMPARE(p2.isPending(), true); @@ -162,15 +161,16 @@ void tst_deprecations_helpers_qpromiseall::atLeastOnePromiseReject_void() { auto p0 = QtPromise::resolve(); auto p1 = QtPromise::resolve(); - auto p2 = QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo"}); - }); - }}; + auto p2 = QtPromise::QPromise{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo"}); + }); + }}; - auto p = qPromiseAll(QVector>{p0, p2, p1}); + auto p = QtPromise::qPromiseAll(QVector>{p0, p2, p1}); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(p1.isFulfilled(), true); QCOMPARE(p2.isPending(), true); @@ -185,9 +185,9 @@ void tst_deprecations_helpers_qpromiseall::preserveOrder() auto p1 = QtPromise::resolve(43).delay(100); auto p2 = QtPromise::resolve(44).delay(250); - auto p = qPromiseAll(QVector>{p0, p1, p2}); + auto p = QtPromise::qPromiseAll(QVector>{p0, p1, p2}); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); QCOMPARE(p2.isPending(), true); @@ -203,16 +203,16 @@ void tst_deprecations_helpers_qpromiseall::preserveOrder() void tst_deprecations_helpers_qpromiseall::sequenceTypes() { - SequenceTester>>::exec(); - // SequenceTester>>::exec(); - SequenceTester>>::exec(); - SequenceTester>>::exec(); + SequenceTester>>::exec(); + // SequenceTester>>::exec(); + SequenceTester>>::exec(); + SequenceTester>>::exec(); } void tst_deprecations_helpers_qpromiseall::sequenceTypes_void() { - SequenceTester>>::exec(); - // SequenceTester>>::exec(); - SequenceTester>>::exec(); - SequenceTester>>::exec(); + SequenceTester>>::exec(); + // SequenceTester>>::exec(); + SequenceTester>>::exec(); + SequenceTester>>::exec(); } diff --git a/tests/auto/qtpromise/deprecations/tst_qpromise_all.cpp b/tests/auto/qtpromise/deprecations/tst_qpromise_all.cpp index f6606c2..eaf8b3c 100644 --- a/tests/auto/qtpromise/deprecations/tst_qpromise_all.cpp +++ b/tests/auto/qtpromise/deprecations/tst_qpromise_all.cpp @@ -10,8 +10,6 @@ #include #include -using namespace QtPromise; - class tst_deprecations_qpromise_all : public QObject { Q_OBJECT @@ -36,7 +34,7 @@ namespace { template struct SequenceTester { - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); static void exec() { @@ -46,9 +44,9 @@ struct SequenceTester promises.insert(++promises.begin(), QtPromise::resolve(46)); promises.pop_back(); - auto p = QPromise::all(promises); + auto p = QtPromise::QPromise::all(promises); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 46, 43, 44})); @@ -56,21 +54,21 @@ struct SequenceTester }; template class Sequence, typename... Args> -struct SequenceTester, Args...>> +struct SequenceTester, Args...>> { static void exec() { - Sequence, Args...> promises{QtPromise::resolve(), - QtPromise::resolve(), - QtPromise::resolve()}; + Sequence, Args...> promises{QtPromise::resolve(), + QtPromise::resolve(), + QtPromise::resolve()}; promises.push_back(QtPromise::resolve()); promises.insert(++promises.begin(), QtPromise::resolve()); promises.pop_back(); - auto p = QPromise::all(promises); + auto p = QtPromise::QPromise::all(promises); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, -1, 42), 42); @@ -81,9 +79,9 @@ struct SequenceTester, Args...>> void tst_deprecations_qpromise_all::emptySequence() { - auto p = QPromise::all(QVector>{}); + auto p = QtPromise::QPromise::all(QVector>{}); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForValue(p, QVector{}), QVector{}); @@ -91,9 +89,9 @@ void tst_deprecations_qpromise_all::emptySequence() void tst_deprecations_qpromise_all::emptySequence_void() { - auto p = QPromise::all(QVector>{}); + auto p = QtPromise::QPromise::all(QVector>{}); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForValue(p, -1, 42), 42); @@ -103,15 +101,15 @@ void tst_deprecations_qpromise_all::allPromisesSucceed() { auto p0 = QtPromise::resolve(42); auto p1 = QtPromise::resolve(44); - auto p2 = QPromise{[](const QPromiseResolve& resolve) { + auto p2 = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(43); }); }}; - auto p = QPromise::all(QVector>{p0, p2, p1}); + auto p = QtPromise::QPromise::all(QVector>{p0, p2, p1}); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(p1.isFulfilled(), true); @@ -125,15 +123,15 @@ void tst_deprecations_qpromise_all::allPromisesSucceed_void() { auto p0 = QtPromise::resolve(); auto p1 = QtPromise::resolve(); - auto p2 = QPromise{[](const QPromiseResolve& resolve) { + auto p2 = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(); }); }}; - auto p = QPromise::all(QVector>{p0, p2, p1}); + auto p = QtPromise::QPromise::all(QVector>{p0, p2, p1}); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(p1.isFulfilled(), true); @@ -147,15 +145,16 @@ void tst_deprecations_qpromise_all::atLeastOnePromiseReject() { auto p0 = QtPromise::resolve(42); auto p1 = QtPromise::resolve(44); - auto p2 = QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo"}); - }); - }}; + auto p2 = QtPromise::QPromise{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo"}); + }); + }}; - auto p = QPromise::all(QVector>{p0, p2, p1}); + auto p = QtPromise::QPromise::all(QVector>{p0, p2, p1}); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(p1.isFulfilled(), true); @@ -169,15 +168,16 @@ void tst_deprecations_qpromise_all::atLeastOnePromiseReject_void() { auto p0 = QtPromise::resolve(); auto p1 = QtPromise::resolve(); - auto p2 = QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo"}); - }); - }}; + auto p2 = QtPromise::QPromise{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo"}); + }); + }}; - auto p = QPromise::all(QVector>{p0, p2, p1}); + auto p = QtPromise::QPromise::all(QVector>{p0, p2, p1}); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(p1.isFulfilled(), true); @@ -193,9 +193,9 @@ void tst_deprecations_qpromise_all::preserveOrder() auto p1 = QtPromise::resolve(43).delay(100); auto p2 = QtPromise::resolve(44).delay(250); - auto p = QPromise::all(QVector>{p0, p1, p2}); + auto p = QtPromise::QPromise::all(QVector>{p0, p1, p2}); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -212,16 +212,16 @@ void tst_deprecations_qpromise_all::preserveOrder() void tst_deprecations_qpromise_all::sequenceTypes() { - SequenceTester>>::exec(); - // SequenceTester>>::exec(); - SequenceTester>>::exec(); - SequenceTester>>::exec(); + SequenceTester>>::exec(); + // SequenceTester>>::exec(); + SequenceTester>>::exec(); + SequenceTester>>::exec(); } void tst_deprecations_qpromise_all::sequenceTypes_void() { - SequenceTester>>::exec(); - // SequenceTester>>::exec(); - SequenceTester>>::exec(); - SequenceTester>>::exec(); + SequenceTester>>::exec(); + // SequenceTester>>::exec(); + SequenceTester>>::exec(); + SequenceTester>>::exec(); } diff --git a/tests/auto/qtpromise/exceptions/tst_exceptions.cpp b/tests/auto/qtpromise/exceptions/tst_exceptions.cpp index 8250415..34972a1 100644 --- a/tests/auto/qtpromise/exceptions/tst_exceptions.cpp +++ b/tests/auto/qtpromise/exceptions/tst_exceptions.cpp @@ -11,8 +11,6 @@ #include #include -using namespace QtPromise; - class tst_exceptions : public QObject { Q_OBJECT @@ -46,25 +44,25 @@ void verify() void tst_exceptions::canceled() { - verify(); + verify(); } void tst_exceptions::context() { - verify(); + verify(); } void tst_exceptions::conversion() { - verify(); + verify(); } void tst_exceptions::timeout() { - verify(); + verify(); } void tst_exceptions::undefined() { - verify(); + verify(); } diff --git a/tests/auto/qtpromise/future/tst_future.cpp b/tests/auto/qtpromise/future/tst_future.cpp index ac2821c..902faad 100644 --- a/tests/auto/qtpromise/future/tst_future.cpp +++ b/tests/auto/qtpromise/future/tst_future.cpp @@ -9,8 +9,6 @@ #include #include -using namespace QtPromise; - class tst_future : public QObject { Q_OBJECT @@ -58,7 +56,7 @@ void tst_future::fulfilled() return 42; })); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); p.then([&](int res) { @@ -74,7 +72,7 @@ void tst_future::fulfilled_void() int result = -1; auto p = QtPromise::resolve(QtConcurrent::run([]() {})); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); p.then([&]() { @@ -93,7 +91,7 @@ void tst_future::rejected() return 42; })); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); p.fail([&](const MyException& e) { @@ -112,7 +110,7 @@ void tst_future::rejected_void() throw MyException{"foo"}; })); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); @@ -132,7 +130,7 @@ void tst_future::unhandled() return 42; })); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); @@ -157,7 +155,7 @@ void tst_future::unhandled_void() throw QString{"foo"}; })); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); p.fail([&](const QString& err) { @@ -179,7 +177,7 @@ void tst_future::canceled() QCOMPARE(p.isPending(), true); - p.fail([&](const QPromiseCanceledException&) { + p.fail([&](const QtPromise::QPromiseCanceledException&) { error = "canceled"; return -1; }).wait(); @@ -195,7 +193,7 @@ void tst_future::canceled_void() QCOMPARE(p.isPending(), true); - p.fail([&](const QPromiseCanceledException&) { + p.fail([&](const QtPromise::QPromiseCanceledException&) { error = "canceled"; }).wait(); @@ -207,12 +205,12 @@ void tst_future::canceledFromThread() { QString error; auto p = QtPromise::resolve(QtConcurrent::run([]() { - throw QPromiseCanceledException{}; + throw QtPromise::QPromiseCanceledException{}; })); QCOMPARE(p.isPending(), true); - p.fail([&](const QPromiseCanceledException&) { + p.fail([&](const QtPromise::QPromiseCanceledException&) { error = "bar"; }).wait(); @@ -269,7 +267,7 @@ void tst_future::then_void() void tst_future::fail() { QString result; - auto input = QPromise::reject(MyException{"bar"}); + auto input = QtPromise::QPromise::reject(MyException{"bar"}); auto output = input.fail([](const MyException& e) { return QtConcurrent::run( [](const QString& error) { @@ -294,7 +292,7 @@ void tst_future::fail() void tst_future::fail_void() { QString result; - auto input = QPromise::reject(MyException{"bar"}); + auto input = QtPromise::QPromise::reject(MyException{"bar"}); auto output = input.fail([&](const MyException& e) { return QtConcurrent::run( [&](const QString& error) { @@ -325,7 +323,7 @@ void tst_future::finally() }); }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(input.isFulfilled(), true); QCOMPARE(output.isPending(), true); @@ -350,7 +348,7 @@ void tst_future::finallyRejected() }); }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(input.isFulfilled(), true); QCOMPARE(output.isPending(), true); diff --git a/tests/auto/qtpromise/helpers/tst_all.cpp b/tests/auto/qtpromise/helpers/tst_all.cpp index 6b86696..5524bf2 100644 --- a/tests/auto/qtpromise/helpers/tst_all.cpp +++ b/tests/auto/qtpromise/helpers/tst_all.cpp @@ -10,8 +10,6 @@ #include #include -using namespace QtPromise; - class tst_helpers_all : public QObject { Q_OBJECT @@ -36,7 +34,7 @@ namespace { template struct SequenceTester { - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); static void exec() { @@ -48,20 +46,20 @@ struct SequenceTester auto p = QtPromise::all(promises); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 46, 43, 44})); } }; template class Sequence, typename... Args> -struct SequenceTester, Args...>> +struct SequenceTester, Args...>> { static void exec() { - Sequence, Args...> promises{QtPromise::resolve(), - QtPromise::resolve(), - QtPromise::resolve()}; + Sequence, Args...> promises{QtPromise::resolve(), + QtPromise::resolve(), + QtPromise::resolve()}; promises.push_back(QtPromise::resolve()); promises.insert(++promises.begin(), QtPromise::resolve()); @@ -69,7 +67,7 @@ struct SequenceTester, Args...>> auto p = QtPromise::all(promises); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, -1, 42), 42); } @@ -79,18 +77,18 @@ struct SequenceTester, Args...>> void tst_helpers_all::emptySequence() { - auto p = QtPromise::all(QVector>()); + auto p = QtPromise::all(QVector>()); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForValue(p, QVector{}), QVector{}); } void tst_helpers_all::emptySequence_void() { - auto p = QtPromise::all(QVector>()); + auto p = QtPromise::all(QVector>()); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForValue(p, -1, 42), 42); } @@ -99,15 +97,15 @@ void tst_helpers_all::allPromisesSucceed() { auto p0 = QtPromise::resolve(42); auto p1 = QtPromise::resolve(44); - auto p2 = QPromise{[](const QPromiseResolve& resolve) { + auto p2 = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(43); }); }}; - auto p = QtPromise::all(QVector>{p0, p2, p1}); + auto p = QtPromise::all(QVector>{p0, p2, p1}); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(p1.isFulfilled(), true); QCOMPARE(p2.isPending(), true); @@ -120,15 +118,15 @@ void tst_helpers_all::allPromisesSucceed_void() { auto p0 = QtPromise::resolve(); auto p1 = QtPromise::resolve(); - auto p2 = QPromise{[](const QPromiseResolve& resolve) { + auto p2 = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(); }); }}; - auto p = QtPromise::all(QVector>{p0, p2, p1}); + auto p = QtPromise::all(QVector>{p0, p2, p1}); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(p1.isFulfilled(), true); QCOMPARE(p2.isPending(), true); @@ -141,15 +139,16 @@ void tst_helpers_all::atLeastOnePromiseReject() { auto p0 = QtPromise::resolve(42); auto p1 = QtPromise::resolve(44); - auto p2 = QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo"}); - }); - }}; + auto p2 = QtPromise::QPromise{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo"}); + }); + }}; - auto p = QtPromise::all(QVector>{p0, p2, p1}); + auto p = QtPromise::all(QVector>{p0, p2, p1}); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(p1.isFulfilled(), true); QCOMPARE(p2.isPending(), true); @@ -162,15 +161,16 @@ void tst_helpers_all::atLeastOnePromiseReject_void() { auto p0 = QtPromise::resolve(); auto p1 = QtPromise::resolve(); - auto p2 = QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo"}); - }); - }}; + auto p2 = QtPromise::QPromise{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo"}); + }); + }}; - auto p = QtPromise::all(QVector>{p0, p2, p1}); + auto p = QtPromise::all(QVector>{p0, p2, p1}); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(p1.isFulfilled(), true); QCOMPARE(p2.isPending(), true); @@ -185,9 +185,9 @@ void tst_helpers_all::preserveOrder() auto p1 = QtPromise::resolve(43).delay(100); auto p2 = QtPromise::resolve(44).delay(250); - auto p = QtPromise::all(QVector>{p0, p1, p2}); + auto p = QtPromise::all(QVector>{p0, p1, p2}); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); QCOMPARE(p2.isPending(), true); @@ -203,16 +203,16 @@ void tst_helpers_all::preserveOrder() void tst_helpers_all::sequenceTypes() { - SequenceTester>>::exec(); + SequenceTester>>::exec(); // SequenceTester>>::exec(); - SequenceTester>>::exec(); - SequenceTester>>::exec(); + SequenceTester>>::exec(); + SequenceTester>>::exec(); } void tst_helpers_all::sequenceTypes_void() { - SequenceTester>>::exec(); + SequenceTester>>::exec(); // SequenceTester>>::exec(); - SequenceTester>>::exec(); - SequenceTester>>::exec(); + SequenceTester>>::exec(); + SequenceTester>>::exec(); } diff --git a/tests/auto/qtpromise/helpers/tst_attempt.cpp b/tests/auto/qtpromise/helpers/tst_attempt.cpp index f601d75..fc37880 100644 --- a/tests/auto/qtpromise/helpers/tst_attempt.cpp +++ b/tests/auto/qtpromise/helpers/tst_attempt.cpp @@ -13,8 +13,6 @@ #include -using namespace QtPromise; - class tst_helpers_attempt : public QObject { Q_OBJECT @@ -35,7 +33,7 @@ void tst_helpers_attempt::voidResult() { auto p = QtPromise::attempt([]() {}); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForValue(p, -1, 42), 42); } @@ -46,7 +44,7 @@ void tst_helpers_attempt::typedResult() return QString{"foo"}; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForValue(p, QString{}), QString{"foo"}); } @@ -59,7 +57,7 @@ void tst_helpers_attempt::futureResult() }); }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, QString{}), QString{"foo"}); } @@ -70,7 +68,7 @@ void tst_helpers_attempt::promiseResult() return QtPromise::resolve(42).delay(200); }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, -1), 42); } @@ -84,7 +82,7 @@ void tst_helpers_attempt::functorThrows() return 42; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isRejected(), true); QCOMPARE(waitForError(p, QString{}), QString{"bar"}); } @@ -98,7 +96,7 @@ void tst_helpers_attempt::callWithParams() 42, "foo"); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForValue(p, QString{}), QString{"42:foo"}); } diff --git a/tests/auto/qtpromise/helpers/tst_connect.cpp b/tests/auto/qtpromise/helpers/tst_connect.cpp index 2a99985..904edd9 100644 --- a/tests/auto/qtpromise/helpers/tst_connect.cpp +++ b/tests/auto/qtpromise/helpers/tst_connect.cpp @@ -11,8 +11,6 @@ #include #include -using namespace QtPromise; - class tst_helpers_connect : public QObject { Q_OBJECT @@ -47,7 +45,7 @@ void tst_helpers_connect::resolveOneSenderNoArg() }); auto p = QtPromise::connect(&sender, &Object::noArgSignal); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(sender.hasConnections(), true); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, -1, 42), 42); @@ -62,7 +60,7 @@ void tst_helpers_connect::resolveOneSenderOneArg() }); auto p = QtPromise::connect(&sender, &Object::oneArgSignal); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(sender.hasConnections(), true); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, QString{}), QString{"foo"}); @@ -77,7 +75,7 @@ void tst_helpers_connect::resolveOneSenderManyArgs() }); auto p = QtPromise::connect(&sender, &Object::twoArgsSignal); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(sender.hasConnections(), true); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, -1), 42); @@ -92,10 +90,10 @@ void tst_helpers_connect::rejectOneSenderNoArg() }); auto p = QtPromise::connect(&sender, &Object::oneArgSignal, &Object::noArgSignal); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(sender.hasConnections(), true); QCOMPARE(p.isPending(), true); - QCOMPARE(waitForRejected(p), true); + QCOMPARE(waitForRejected(p), true); QCOMPARE(sender.hasConnections(), false); } @@ -107,7 +105,7 @@ void tst_helpers_connect::rejectOneSenderOneArg() }); auto p = QtPromise::connect(&sender, &Object::noArgSignal, &Object::oneArgSignal); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(sender.hasConnections(), true); QCOMPARE(p.isPending(), true); QCOMPARE(waitForError(p, QString{}), QString{"bar"}); @@ -122,7 +120,7 @@ void tst_helpers_connect::rejectOneSenderManyArgs() }); auto p = QtPromise::connect(&sender, &Object::noArgSignal, &Object::twoArgsSignal); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(sender.hasConnections(), true); QCOMPARE(p.isPending(), true); QCOMPARE(waitForError(p, -1), 42); @@ -137,9 +135,9 @@ void tst_helpers_connect::rejectOneSenderDestroyed() }); auto p = QtPromise::connect(sender, &Object::twoArgsSignal); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); - QCOMPARE(waitForRejected(p), true); + QCOMPARE(waitForRejected(p), true); } void tst_helpers_connect::rejectTwoSendersNoArg() @@ -150,11 +148,11 @@ void tst_helpers_connect::rejectTwoSendersNoArg() }); auto p = QtPromise::connect(&s0, &Object::noArgSignal, &s1, &Object::noArgSignal); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(s0.hasConnections(), true); QCOMPARE(s1.hasConnections(), true); QCOMPARE(p.isPending(), true); - QCOMPARE(waitForRejected(p), true); + QCOMPARE(waitForRejected(p), true); QCOMPARE(s0.hasConnections(), false); QCOMPARE(s1.hasConnections(), false); } @@ -167,7 +165,7 @@ void tst_helpers_connect::rejectTwoSendersOneArg() }); auto p = QtPromise::connect(&s0, &Object::noArgSignal, &s1, &Object::oneArgSignal); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(s0.hasConnections(), true); QCOMPARE(s1.hasConnections(), true); QCOMPARE(p.isPending(), true); @@ -184,7 +182,7 @@ void tst_helpers_connect::rejectTwoSendersManyArgs() }); auto p = QtPromise::connect(&s0, &Object::noArgSignal, &s1, &Object::twoArgsSignal); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(s0.hasConnections(), true); QCOMPARE(s1.hasConnections(), true); QCOMPARE(p.isPending(), true); @@ -209,7 +207,7 @@ void tst_helpers_connect::rejectTwoSendersDestroyed() }); auto p = QtPromise::connect(s0, &Object::noArgSignal, s1, &Object::twoArgsSignal); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, -1, 42), 42); } diff --git a/tests/auto/qtpromise/helpers/tst_each.cpp b/tests/auto/qtpromise/helpers/tst_each.cpp index 52699cf..b0cfc2e 100644 --- a/tests/auto/qtpromise/helpers/tst_each.cpp +++ b/tests/auto/qtpromise/helpers/tst_each.cpp @@ -10,8 +10,6 @@ #include #include -using namespace QtPromise; - class tst_helpers_each : public QObject { Q_OBJECT @@ -42,7 +40,7 @@ struct SequenceTester values << i << v; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, Sequence{}), (Sequence{42, 43, 44})); QCOMPARE(values, (QVector{0, 42, 1, 43, 2, 44})); } @@ -57,7 +55,7 @@ void tst_helpers_each::emptySequence() values << v; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), QVector{}); QCOMPARE(values, QVector{}); } @@ -69,7 +67,7 @@ void tst_helpers_each::preserveValues() values << v + 1; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 43, 44})); QCOMPARE(values, (QVector{43, 44, 45})); } @@ -82,7 +80,7 @@ void tst_helpers_each::ignoreResult() return "Foo"; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 43, 44})); QCOMPARE(values, (QVector{43, 44, 45})); } @@ -91,7 +89,7 @@ void tst_helpers_each::delayedFulfilled() { QMap values; auto p = QtPromise::each(QVector{42, 43, 44}, [&](int v, int index) { - return QPromise{[&](const QPromiseResolve& resolve) { + return QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=, &values]() { values[v] = index; resolve(42); @@ -99,7 +97,7 @@ void tst_helpers_each::delayedFulfilled() }}; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 43, 44})); QMap expected{{42, 0}, {43, 1}, {44, 2}}; QCOMPARE(values, expected); @@ -108,18 +106,18 @@ void tst_helpers_each::delayedFulfilled() void tst_helpers_each::delayedRejected() { auto p = QtPromise::each(QVector{42, 43, 44}, [](int v, ...) { - return QPromise{ - [&](const QPromiseResolve& resolve, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - if (v == 43) { - reject(QString{"foo"}); - } - resolve(v); - }); - }}; + return QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve, + const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + if (v == 43) { + reject(QString{"foo"}); + } + resolve(v); + }); + }}; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); } @@ -131,7 +129,7 @@ void tst_helpers_each::functorThrows() } }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); } @@ -142,7 +140,7 @@ void tst_helpers_each::functorArguments() values << i << v; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 43, 44})); QCOMPARE(values, (QVector{0, 42, 1, 43, 2, 44})); } diff --git a/tests/auto/qtpromise/helpers/tst_filter.cpp b/tests/auto/qtpromise/helpers/tst_filter.cpp index fdd9509..e585047 100644 --- a/tests/auto/qtpromise/helpers/tst_filter.cpp +++ b/tests/auto/qtpromise/helpers/tst_filter.cpp @@ -11,8 +11,6 @@ #include #include -using namespace QtPromise; - class tst_helpers_filter : public QObject { Q_OBJECT @@ -43,7 +41,7 @@ struct SequenceTester return v % 3 == 0; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, Sequence{}), (Sequence{42, 45, 48, 51})); } }; @@ -56,7 +54,7 @@ void tst_helpers_filter::emptySequence() return v % 2 == 0; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), QVector{}); } @@ -66,39 +64,39 @@ void tst_helpers_filter::filterValues() return v % 2 == 0; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 44})); } void tst_helpers_filter::delayedFulfilled() { auto p = QtPromise::filter(QVector{42, 43, 44}, [](int v, ...) { - return QPromise{[&](const QPromiseResolve& resolve) { + return QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(v % 2 == 0); }); }}; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 44})); } void tst_helpers_filter::delayedRejected() { auto p = QtPromise::filter(QVector{42, 43, 44}, [](int v, ...) { - return QPromise{ - [&](const QPromiseResolve& resolve, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - if (v == 44) { - reject(QString{"foo"}); - } - resolve(true); - }); - }}; + return QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve, + const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + if (v == 44) { + reject(QString{"foo"}); + } + resolve(true); + }); + }}; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); } @@ -111,7 +109,7 @@ void tst_helpers_filter::functorThrows() return true; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); } @@ -123,7 +121,7 @@ void tst_helpers_filter::functorArguments() return i % 2 == 0; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 44})); QMap expected{{42, 0}, {43, 1}, {44, 2}}; QCOMPARE(args, expected); @@ -132,10 +130,10 @@ void tst_helpers_filter::functorArguments() void tst_helpers_filter::preserveOrder() { auto p = QtPromise::filter(QVector{500, 100, 300, 250, 400}, [](int v, ...) { - return QPromise::resolve(v > 200).delay(v); + return QtPromise::QPromise::resolve(v > 200).delay(v); }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{500, 300, 250, 400})); } diff --git a/tests/auto/qtpromise/helpers/tst_map.cpp b/tests/auto/qtpromise/helpers/tst_map.cpp index 72f8b88..a22325c 100644 --- a/tests/auto/qtpromise/helpers/tst_map.cpp +++ b/tests/auto/qtpromise/helpers/tst_map.cpp @@ -10,8 +10,6 @@ #include #include -using namespace QtPromise; - class tst_helpers_map : public QObject { Q_OBJECT @@ -42,7 +40,7 @@ struct SequenceTester return QString::number(v + 1); }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{"43", "44", "45"})); } }; @@ -55,7 +53,7 @@ void tst_helpers_map::emptySequence() return v + 1; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{})); } @@ -65,7 +63,7 @@ void tst_helpers_map::modifyValues() return v + 1; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{43, 44, 45})); } @@ -75,39 +73,39 @@ void tst_helpers_map::convertValues() return QString::number(v + 1); }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{"43", "44", "45"})); } void tst_helpers_map::delayedFulfilled() { auto p = QtPromise::map(QVector{42, 43, 44}, [](int v, ...) { - return QPromise{[&](const QPromiseResolve& resolve) { + return QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(v + 1); }); }}; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{43, 44, 45})); } void tst_helpers_map::delayedRejected() { auto p = QtPromise::map(QVector{42, 43, 44}, [](int v, ...) { - return QPromise{ - [&](const QPromiseResolve& resolve, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - if (v == 43) { - reject(QString{"foo"}); - } - resolve(v); - }); - }}; + return QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve, + const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + if (v == 43) { + reject(QString{"foo"}); + } + resolve(v); + }); + }}; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); } @@ -120,7 +118,7 @@ void tst_helpers_map::functorThrows() return v + 1; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); } @@ -130,17 +128,17 @@ void tst_helpers_map::functorArguments() return v * i; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{0, 42, 84})); } void tst_helpers_map::preserveOrder() { auto p = QtPromise::map(QVector{500, 100, 250}, [](int v, ...) { - return QPromise::resolve(v + 1).delay(v); + return QtPromise::QPromise::resolve(v + 1).delay(v); }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{501, 101, 251})); } diff --git a/tests/auto/qtpromise/helpers/tst_reduce.cpp b/tests/auto/qtpromise/helpers/tst_reduce.cpp index 15bf596..519e32d 100644 --- a/tests/auto/qtpromise/helpers/tst_reduce.cpp +++ b/tests/auto/qtpromise/helpers/tst_reduce.cpp @@ -11,8 +11,6 @@ #include #include -using namespace QtPromise; - class tst_helpers_reduce : public QObject { Q_OBJECT @@ -57,8 +55,8 @@ struct SequenceTester }, QtPromise::resolve(2).delay(100)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -85,7 +83,7 @@ void tst_helpers_reduce::emptySequence() // NOTE(SB): reduce() on an empty sequence without an initial value is an error! - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, -1), 42); QCOMPARE(called, false); @@ -109,8 +107,8 @@ void tst_helpers_reduce::regularValues() }, 2); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -122,9 +120,9 @@ void tst_helpers_reduce::regularValues() void tst_helpers_reduce::promiseValues() { - QVector> inputs{QtPromise::resolve(4).delay(400), - QtPromise::resolve(6).delay(300), - QtPromise::resolve(8).delay(200)}; + QVector> inputs{QtPromise::resolve(4).delay(400), + QtPromise::resolve(6).delay(300), + QtPromise::resolve(8).delay(200)}; QVector v0; QVector v1; @@ -140,8 +138,8 @@ void tst_helpers_reduce::promiseValues() }, 2); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -164,7 +162,7 @@ void tst_helpers_reduce::convertResultType() // NOTE(SB): when no initial value is given, the result type is the sequence type. - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, QString{}), QString{"foo:4:0:6:1:8:2"}); @@ -182,7 +180,7 @@ void tst_helpers_reduce::delayedInitialValue() }, QtPromise::resolve(2).delay(100)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, -1), 23); @@ -207,8 +205,8 @@ void tst_helpers_reduce::delayedFulfilled() }, 2); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -227,7 +225,7 @@ void tst_helpers_reduce::delayedRejected() auto p0 = QtPromise::reduce(inputs, [&](int acc, int cur, int idx) { v0 << acc << cur << idx; if (cur == 6) { - return QPromise::reject(QString{"foo"}); + return QtPromise::QPromise::reject(QString{"foo"}); } return QtPromise::resolve(acc + cur + idx); }); @@ -236,14 +234,14 @@ void tst_helpers_reduce::delayedRejected() [&](int acc, int cur, int idx) { v1 << acc << cur << idx; if (cur == 6) { - return QPromise::reject(QString{"bar"}); + return QtPromise::QPromise::reject(QString{"bar"}); } return QtPromise::resolve(acc + cur + idx); }, 2); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -277,8 +275,8 @@ void tst_helpers_reduce::functorThrows() }, 2); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -292,10 +290,10 @@ void tst_helpers_reduce::sequenceTypes() { #if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) // QLinkedList is deprecated since Qt 5.15. - SequenceTester>>::exec(); + SequenceTester>>::exec(); #endif - SequenceTester>>::exec(); - SequenceTester>>::exec(); - SequenceTester>>::exec(); - SequenceTester>>::exec(); + SequenceTester>>::exec(); + SequenceTester>>::exec(); + SequenceTester>>::exec(); + SequenceTester>>::exec(); } diff --git a/tests/auto/qtpromise/helpers/tst_reject.cpp b/tests/auto/qtpromise/helpers/tst_reject.cpp index 2fc2dd5..cbfa028 100644 --- a/tests/auto/qtpromise/helpers/tst_reject.cpp +++ b/tests/auto/qtpromise/helpers/tst_reject.cpp @@ -12,8 +12,6 @@ #include -using namespace QtPromise; - class tst_helpers_reject : public QObject { Q_OBJECT @@ -29,7 +27,7 @@ QTEST_MAIN(tst_helpers_reject) void tst_helpers_reject::rejectWithValue() { - auto p = QPromise::reject(42); + auto p = QtPromise::QPromise::reject(42); QCOMPARE(p.isRejected(), true); QCOMPARE(waitForError(p, -1), 42); @@ -42,7 +40,7 @@ void tst_helpers_reject::rejectWithQSharedPtr() { auto sptr = QSharedPointer::create(42); - auto p = QPromise::reject(sptr); + auto p = QtPromise::QPromise::reject(sptr); QCOMPARE(waitForError(p, QSharedPointer{}), sptr); @@ -62,7 +60,7 @@ void tst_helpers_reject::rejectWithStdSharedPtr() { auto sptr = std::make_shared(42); - auto p = QPromise::reject(sptr); + auto p = QtPromise::QPromise::reject(sptr); QCOMPARE(waitForError(p, std::shared_ptr{}), sptr); diff --git a/tests/auto/qtpromise/helpers/tst_resolve.cpp b/tests/auto/qtpromise/helpers/tst_resolve.cpp index f04b891..295af37 100644 --- a/tests/auto/qtpromise/helpers/tst_resolve.cpp +++ b/tests/auto/qtpromise/helpers/tst_resolve.cpp @@ -14,8 +14,6 @@ #include -using namespace QtPromise; - class tst_helpers_resolve : public QObject { Q_OBJECT @@ -45,9 +43,9 @@ void tst_helpers_resolve::value() auto p1 = QtPromise::resolve(v0); auto p2 = QtPromise::resolve(v1); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); for (const auto& p : {p0, p1, p2}) { QCOMPARE(p.isFulfilled(), true); @@ -61,7 +59,7 @@ void tst_helpers_resolve::noValue() { auto p = QtPromise::resolve(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForValue(p, -1, 42), 42); @@ -74,7 +72,7 @@ void tst_helpers_resolve::moveRValue() { auto p = QtPromise::resolve(Data{42}).wait(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); } QCOMPARE(Data::logs().ctor, 1); @@ -91,7 +89,7 @@ void tst_helpers_resolve::copyLValue() Data value{42}; auto p = QtPromise::resolve(value).wait(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); } QCOMPARE(Data::logs().ctor, 1); @@ -103,24 +101,26 @@ void tst_helpers_resolve::copyLValue() // https://github.com/simonbrunel/qtpromise/issues/6 void tst_helpers_resolve::qtSharedPtr() { + using DataSPtr = QSharedPointer; + Data::logs().reset(); QWeakPointer wptr; { - auto sptr0 = QSharedPointer::create(42); - const QSharedPointer sptr1 = sptr0; + auto sptr0 = DataSPtr::create(42); + const DataSPtr sptr1 = sptr0; - auto p0 = QtPromise::resolve(QSharedPointer::create(42)); + auto p0 = QtPromise::resolve(DataSPtr::create(42)); auto p1 = QtPromise::resolve(sptr0); auto p2 = QtPromise::resolve(sptr1); - Q_STATIC_ASSERT((std::is_same>>::value)); - Q_STATIC_ASSERT((std::is_same>>::value)); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); - QCOMPARE(waitForValue(p1, QSharedPointer{}), sptr0); - QCOMPARE(waitForValue(p2, QSharedPointer{}), sptr1); + QCOMPARE(waitForValue(p1, DataSPtr{}), sptr0); + QCOMPARE(waitForValue(p2, DataSPtr{}), sptr1); wptr = sptr0; @@ -139,24 +139,26 @@ void tst_helpers_resolve::qtSharedPtr() // https://github.com/simonbrunel/qtpromise/issues/6 void tst_helpers_resolve::stdSharedPtr() { + using DataSPtr = std::shared_ptr; + Data::logs().reset(); std::weak_ptr wptr; { auto sptr0 = std::make_shared(42); - const std::shared_ptr sptr1 = sptr0; + const DataSPtr sptr1 = sptr0; auto p0 = QtPromise::resolve(std::make_shared(42)); auto p1 = QtPromise::resolve(sptr0); auto p2 = QtPromise::resolve(sptr1); - Q_STATIC_ASSERT((std::is_same>>::value)); - Q_STATIC_ASSERT((std::is_same>>::value)); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); - QCOMPARE(waitForValue(p1, std::shared_ptr{}), sptr0); - QCOMPARE(waitForValue(p2, std::shared_ptr{}), sptr1); + QCOMPARE(waitForValue(p1, DataSPtr{}), sptr0); + QCOMPARE(waitForValue(p2, DataSPtr{}), sptr1); wptr = sptr0; @@ -174,22 +176,22 @@ void tst_helpers_resolve::stdSharedPtr() void tst_helpers_resolve::typedPromise() { - auto resolver = [](const QPromiseResolve& resolve) { + auto resolver = [](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(42); }); }; - QPromise v0{resolver}; - const QPromise v1 = v0; + QtPromise::QPromise v0{resolver}; + const QtPromise::QPromise v1 = v0; - auto p0 = QtPromise::resolve(QPromise{resolver}); + auto p0 = QtPromise::resolve(QtPromise::QPromise{resolver}); auto p1 = QtPromise::resolve(v0); auto p2 = QtPromise::resolve(v1); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); for (const auto& promise : {p0, p1, p2}) { QCOMPARE(promise.isPending(), true); @@ -201,22 +203,22 @@ void tst_helpers_resolve::typedPromise() void tst_helpers_resolve::voidPromise() { - auto resolver = [](const QPromiseResolve& resolve) { + auto resolver = [](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(); }); }; - QPromise v0{resolver}; - const QPromise v1 = v0; + QtPromise::QPromise v0{resolver}; + const QtPromise::QPromise v1 = v0; - auto p0 = QtPromise::resolve(QPromise{resolver}); + auto p0 = QtPromise::resolve(QtPromise::QPromise{resolver}); auto p1 = QtPromise::resolve(v0); auto p2 = QtPromise::resolve(v1); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); for (const auto& promise : {p0, p1, p2}) { QCOMPARE(promise.isPending(), true); @@ -238,9 +240,9 @@ void tst_helpers_resolve::typedFuture() auto p1 = QtPromise::resolve(v0); auto p2 = QtPromise::resolve(v1); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); for (const auto& promise : {p0, p1, p2}) { QCOMPARE(promise.isPending(), true); @@ -260,9 +262,9 @@ void tst_helpers_resolve::voidFuture() auto p1 = QtPromise::resolve(v0); auto p2 = QtPromise::resolve(v1); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); for (const auto& promise : {p0, p1, p2}) { QCOMPARE(promise.isPending(), true); diff --git a/tests/auto/qtpromise/qpromise/tst_construct.cpp b/tests/auto/qtpromise/qpromise/tst_construct.cpp index 18ace65..dc00ea6 100644 --- a/tests/auto/qtpromise/qpromise/tst_construct.cpp +++ b/tests/auto/qtpromise/qpromise/tst_construct.cpp @@ -12,8 +12,6 @@ #include -using namespace QtPromise; - class tst_qpromise_construct : public QObject { Q_OBJECT @@ -46,7 +44,7 @@ QTEST_MAIN(tst_qpromise_construct) void tst_qpromise_construct::resolveSyncOneArg() { - QPromise p{[](const QPromiseResolve& resolve) { + QtPromise::QPromise p{[](const QtPromise::QPromiseResolve& resolve) { resolve(42); }}; @@ -57,7 +55,7 @@ void tst_qpromise_construct::resolveSyncOneArg() void tst_qpromise_construct::resolveSyncOneArg_void() { - QPromise p{[](const QPromiseResolve& resolve) { + QtPromise::QPromise p{[](const QtPromise::QPromiseResolve& resolve) { resolve(); }}; @@ -68,9 +66,10 @@ void tst_qpromise_construct::resolveSyncOneArg_void() void tst_qpromise_construct::resolveSyncTwoArgs() { - QPromise p{[](const QPromiseResolve& resolve, const QPromiseReject&) { - resolve(42); - }}; + QtPromise::QPromise p{ + [](const QtPromise::QPromiseResolve& resolve, const QtPromise::QPromiseReject&) { + resolve(42); + }}; QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForError(p, QString{}), QString{}); @@ -79,7 +78,8 @@ void tst_qpromise_construct::resolveSyncTwoArgs() void tst_qpromise_construct::resolveSyncTwoArgs_void() { - QPromise p{[](const QPromiseResolve& resolve, const QPromiseReject&) { + QtPromise::QPromise p{[](const QtPromise::QPromiseResolve& resolve, + const QtPromise::QPromiseReject&) { resolve(); }}; @@ -90,7 +90,7 @@ void tst_qpromise_construct::resolveSyncTwoArgs_void() void tst_qpromise_construct::resolveAsyncOneArg() { - QPromise p{[](const QPromiseResolve& resolve) { + QtPromise::QPromise p{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(42); }); @@ -104,7 +104,7 @@ void tst_qpromise_construct::resolveAsyncOneArg() void tst_qpromise_construct::resolveAsyncOneArg_void() { - QPromise p{[](const QPromiseResolve& resolve) { + QtPromise::QPromise p{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(); }); @@ -118,11 +118,12 @@ void tst_qpromise_construct::resolveAsyncOneArg_void() void tst_qpromise_construct::resolveAsyncTwoArgs() { - QPromise p{[](const QPromiseResolve& resolve, const QPromiseReject&) { - QtPromisePrivate::qtpromise_defer([=]() { - resolve(42); - }); - }}; + QtPromise::QPromise p{ + [](const QtPromise::QPromiseResolve& resolve, const QtPromise::QPromiseReject&) { + QtPromisePrivate::qtpromise_defer([=]() { + resolve(42); + }); + }}; QCOMPARE(p.isPending(), true); QCOMPARE(waitForError(p, QString{}), QString{}); @@ -132,7 +133,8 @@ void tst_qpromise_construct::resolveAsyncTwoArgs() void tst_qpromise_construct::resolveAsyncTwoArgs_void() { - QPromise p{[](const QPromiseResolve& resolve, const QPromiseReject&) { + QtPromise::QPromise p{[](const QtPromise::QPromiseResolve& resolve, + const QtPromise::QPromiseReject&) { QtPromisePrivate::qtpromise_defer([=]() { resolve(); }); @@ -146,9 +148,10 @@ void tst_qpromise_construct::resolveAsyncTwoArgs_void() void tst_qpromise_construct::rejectSync() { - QPromise p{[](const QPromiseResolve&, const QPromiseReject& reject) { - reject(QString{"foo"}); - }}; + QtPromise::QPromise p{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + reject(QString{"foo"}); + }}; QCOMPARE(p.isRejected(), true); QCOMPARE(waitForValue(p, -1), -1); @@ -157,9 +160,10 @@ void tst_qpromise_construct::rejectSync() void tst_qpromise_construct::rejectSync_void() { - QPromise p{[](const QPromiseResolve&, const QPromiseReject& reject) { - reject(QString{"foo"}); - }}; + QtPromise::QPromise p{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + reject(QString{"foo"}); + }}; QCOMPARE(p.isRejected(), true); QCOMPARE(waitForValue(p, -1, 42), -1); @@ -168,11 +172,12 @@ void tst_qpromise_construct::rejectSync_void() void tst_qpromise_construct::rejectAsync() { - QPromise p{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo"}); - }); - }}; + QtPromise::QPromise p{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo"}); + }); + }}; QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, -1), -1); @@ -182,11 +187,12 @@ void tst_qpromise_construct::rejectAsync() void tst_qpromise_construct::rejectAsync_void() { - QPromise p{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo"}); - }); - }}; + QtPromise::QPromise p{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo"}); + }); + }}; QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, -1, 42), -1); @@ -196,7 +202,7 @@ void tst_qpromise_construct::rejectAsync_void() void tst_qpromise_construct::rejectThrowOneArg() { - QPromise p{[](const QPromiseResolve&) { + QtPromise::QPromise p{[](const QtPromise::QPromiseResolve&) { throw QString{"foo"}; }}; @@ -207,7 +213,7 @@ void tst_qpromise_construct::rejectThrowOneArg() void tst_qpromise_construct::rejectThrowOneArg_void() { - QPromise p{[](const QPromiseResolve&) { + QtPromise::QPromise p{[](const QtPromise::QPromiseResolve&) { throw QString{"foo"}; }}; @@ -218,9 +224,10 @@ void tst_qpromise_construct::rejectThrowOneArg_void() void tst_qpromise_construct::rejectThrowTwoArgs() { - QPromise p{[](const QPromiseResolve&, const QPromiseReject&) { - throw QString{"foo"}; - }}; + QtPromise::QPromise p{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject&) { + throw QString{"foo"}; + }}; QCOMPARE(p.isRejected(), true); QCOMPARE(waitForValue(p, -1), -1); @@ -229,9 +236,10 @@ void tst_qpromise_construct::rejectThrowTwoArgs() void tst_qpromise_construct::rejectThrowTwoArgs_void() { - QPromise p{[](const QPromiseResolve&, const QPromiseReject&) { - throw QString{"foo"}; - }}; + QtPromise::QPromise p{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject&) { + throw QString{"foo"}; + }}; QCOMPARE(p.isRejected(), true); QCOMPARE(waitForValue(p, -1, 42), -1); @@ -240,26 +248,28 @@ void tst_qpromise_construct::rejectThrowTwoArgs_void() void tst_qpromise_construct::rejectUndefined() { - QPromise p{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(); - }); - }}; + QtPromise::QPromise p{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(); + }); + }}; QCOMPARE(p.isPending(), true); - QCOMPARE(waitForRejected(p), true); + QCOMPARE(waitForRejected(p), true); } void tst_qpromise_construct::rejectUndefined_void() { - QPromise p{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(); - }); - }}; + QtPromise::QPromise p{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(); + }); + }}; QCOMPARE(p.isPending(), true); - QCOMPARE(waitForRejected(p), true); + QCOMPARE(waitForRejected(p), true); } // https://github.com/simonbrunel/qtpromise/issues/6 @@ -270,9 +280,9 @@ void tst_qpromise_construct::connectAndResolve() std::weak_ptr wptr; { - auto p = - QPromise>{[&](const QPromiseResolve>& resolve, - const QPromiseReject>& reject) { + auto p = QtPromise::QPromise>{ + [&](const QtPromise::QPromiseResolve>& resolve, + const QtPromise::QPromiseReject>& reject) { connect(object.data(), &QObject::objectNameChanged, [=, &wptr](const QString& name) { @@ -307,8 +317,8 @@ void tst_qpromise_construct::connectAndReject() std::weak_ptr wptr; { - auto p = QPromise{[&](const QPromiseResolve& resolve, - const QPromiseReject& reject) { + auto p = QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve, + const QtPromise::QPromiseReject& reject) { connect(object.data(), &QObject::objectNameChanged, [=, &wptr](const QString& name) { auto sptr = std::make_shared(42); diff --git a/tests/auto/qtpromise/qpromise/tst_convert.cpp b/tests/auto/qtpromise/qpromise/tst_convert.cpp index fecfc59..3a2f33d 100644 --- a/tests/auto/qtpromise/qpromise/tst_convert.cpp +++ b/tests/auto/qtpromise/qpromise/tst_convert.cpp @@ -12,8 +12,6 @@ #include -using namespace QtPromise; - class tst_qpromise_convert : public QObject { Q_OBJECT @@ -76,7 +74,7 @@ void tst_qpromise_convert::fulfillTAsU() { auto p = QtPromise::resolve(42.13).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, -1), 42); QVERIFY(p.isFulfilled()); @@ -86,7 +84,7 @@ void tst_qpromise_convert::fulfillTAsU() { auto p = QtPromise::resolve(Enum1::Value1).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, -1), 1); QVERIFY(p.isFulfilled()); @@ -96,7 +94,7 @@ void tst_qpromise_convert::fulfillTAsU() { auto p = QtPromise::resolve(1).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, Enum1::Value0), Enum1::Value1); QVERIFY(p.isFulfilled()); @@ -106,7 +104,7 @@ void tst_qpromise_convert::fulfillTAsU() { auto p = QtPromise::resolve(Enum1::Value1).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, Enum2::Value0), Enum2::Value1); QVERIFY(p.isFulfilled()); @@ -117,7 +115,7 @@ void tst_qpromise_convert::fulfillTAsU() { auto p = QtPromise::resolve(QByteArray{"foo"}).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, QString{}), QString{"foo"}); QVERIFY(p.isFulfilled()); @@ -128,7 +126,7 @@ void tst_qpromise_convert::fulfillTAsU() { auto p = QtPromise::resolve(Foo{42}).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, Bar{}), Bar{42}); QVERIFY(p.isFulfilled()); @@ -138,7 +136,7 @@ void tst_qpromise_convert::fulfillTAsU() { auto p = QtPromise::resolve(42).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, QString{}), QString{"42"}); QVERIFY(p.isFulfilled()); @@ -149,7 +147,7 @@ void tst_qpromise_convert::fulfillTAsU() { auto p = QtPromise::resolve(Foo{42}).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, QString{}), QString{"Foo{42}"}); QVERIFY(p.isFulfilled()); @@ -160,7 +158,7 @@ void tst_qpromise_convert::fulfillTAsVoid() { auto p = QtPromise::resolve(42).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, -1, 42), 42); QVERIFY(p.isFulfilled()); @@ -172,7 +170,7 @@ void tst_qpromise_convert::fulfillTAsQVariant() { auto p = QtPromise::resolve(42).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, QVariant{}), QVariant{42}); QVERIFY(p.isFulfilled()); @@ -182,7 +180,7 @@ void tst_qpromise_convert::fulfillTAsQVariant() { auto p = QtPromise::resolve(Foo{42}).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QVariant value = waitForValue(p, QVariant{}); QCOMPARE(value, QVariant::fromValue(Foo{42})); @@ -197,7 +195,7 @@ void tst_qpromise_convert::fulfillQVariantAsU() { auto p = QtPromise::resolve(QVariant{42}).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, -1), 42); QVERIFY(p.isFulfilled()); @@ -208,7 +206,7 @@ void tst_qpromise_convert::fulfillQVariantAsU() { auto p = QtPromise::resolve(QVariant{"42"}).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, -1), 42); QVERIFY(p.isFulfilled()); @@ -218,7 +216,7 @@ void tst_qpromise_convert::fulfillQVariantAsU() { auto p = QtPromise::resolve(QVariant::fromValue(Foo{42})).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, Foo{}), Foo{42}); QVERIFY(p.isFulfilled()); @@ -229,7 +227,7 @@ void tst_qpromise_convert::fulfillQVariantAsVoid() { auto p = QtPromise::resolve(QVariant{42}).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, -1, 42), 42); QVERIFY(p.isFulfilled()); @@ -241,26 +239,26 @@ void tst_qpromise_convert::rejectUnconvertibleTypes() { auto p = QtPromise::resolve(QString{"42foo"}).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); - QVERIFY(waitForRejected(p)); + QVERIFY(waitForRejected(p)); } // A user-defined type unconvertible to string because there is no converter. { auto p = QtPromise::resolve(QVariant::fromValue(Bar{42})).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); - QVERIFY(waitForRejected(p)); + QVERIFY(waitForRejected(p)); } // A standard library type unconvertible to a primitive type because there is no converter. { auto p = QtPromise::resolve(std::vector{42, -42}).convert(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); - QVERIFY(waitForRejected(p)); + QVERIFY(waitForRejected(p)); } } diff --git a/tests/auto/qtpromise/qpromise/tst_delay.cpp b/tests/auto/qtpromise/qpromise/tst_delay.cpp index 7b64afe..172a57c 100644 --- a/tests/auto/qtpromise/qpromise/tst_delay.cpp +++ b/tests/auto/qtpromise/qpromise/tst_delay.cpp @@ -12,8 +12,6 @@ #include -using namespace QtPromise; - class tst_qpromise_delay : public QObject { Q_OBJECT @@ -36,7 +34,7 @@ void tst_qpromise_delay::fulfilled() timer.start(); - auto p = QPromise::resolve(42).delay(1000).finally([&]() { + auto p = QtPromise::QPromise::resolve(42).delay(1000).finally([&]() { elapsed = timer.elapsed(); }); @@ -57,7 +55,7 @@ void tst_qpromise_delay::rejected() timer.start(); - auto p = QPromise::reject(QString{"foo"}).delay(1000).finally([&]() { + auto p = QtPromise::QPromise::reject(QString{"foo"}).delay(1000).finally([&]() { elapsed = timer.elapsed(); }); @@ -73,7 +71,7 @@ void tst_qpromise_delay::fulfilledStdChrono() timer.start(); - auto p = QPromise::resolve(42).delay(std::chrono::seconds{1}).finally([&]() { + auto p = QtPromise::QPromise::resolve(42).delay(std::chrono::seconds{1}).finally([&]() { elapsed = timer.elapsed(); }); @@ -94,9 +92,11 @@ void tst_qpromise_delay::rejectedStdChrono() timer.start(); - auto p = QPromise::reject(QString{"foo"}).delay(std::chrono::seconds{1}).finally([&]() { - elapsed = timer.elapsed(); - }); + auto p = QtPromise::QPromise::reject(QString{"foo"}) + .delay(std::chrono::seconds{1}) + .finally([&]() { + elapsed = timer.elapsed(); + }); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); QCOMPARE(p.isRejected(), true); diff --git a/tests/auto/qtpromise/qpromise/tst_each.cpp b/tests/auto/qtpromise/qpromise/tst_each.cpp index 7650e1e..59a4af0 100644 --- a/tests/auto/qtpromise/qpromise/tst_each.cpp +++ b/tests/auto/qtpromise/qpromise/tst_each.cpp @@ -10,8 +10,6 @@ #include #include -using namespace QtPromise; - class tst_qpromise_each : public QObject { Q_OBJECT @@ -56,7 +54,7 @@ struct SequenceTester values << v + 2; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, Sequence{}), (Sequence{42, 43, 44})); QVector expected{0, 42, 1, 43, 2, 44, 42, 43, 44, 43, 44, 45, -1, -1, -1, 44, 45, 46}; @@ -69,11 +67,11 @@ struct SequenceTester void tst_qpromise_each::emptySequence() { QVector values; - auto p = QPromise>::resolve({}).each([&](int v, ...) { + auto p = QtPromise::QPromise>::resolve({}).each([&](int v, ...) { values << v; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), QVector{}); QCOMPARE(values, (QVector{})); } @@ -81,11 +79,11 @@ void tst_qpromise_each::emptySequence() void tst_qpromise_each::preserveValues() { QVector values; - auto p = QPromise>::resolve({42, 43, 44}).each([&](int v, ...) { + auto p = QtPromise::QPromise>::resolve({42, 43, 44}).each([&](int v, ...) { values << v + 1; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 43, 44})); QCOMPARE(values, (QVector{43, 44, 45})); } @@ -93,12 +91,12 @@ void tst_qpromise_each::preserveValues() void tst_qpromise_each::ignoreResult() { QVector values; - auto p = QPromise>::resolve({42, 43, 44}).each([&](int v, ...) { + auto p = QtPromise::QPromise>::resolve({42, 43, 44}).each([&](int v, ...) { values << v + 1; return "Foo"; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 43, 44})); QCOMPARE(values, (QVector{43, 44, 45})); } @@ -106,14 +104,14 @@ void tst_qpromise_each::ignoreResult() void tst_qpromise_each::delayedFulfilled() { QMap values; - auto p = QPromise>::resolve({42, 43, 44}).each([&](int v, int index) { - return QPromise::resolve().delay(250).then([=, &values]() { + auto p = QtPromise::QPromise>::resolve({42, 43, 44}).each([&](int v, int index) { + return QtPromise::QPromise::resolve().delay(250).then([=, &values]() { values[v] = index; return 42; }); }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 43, 44})); QMap expected{{42, 0}, {43, 1}, {44, 2}}; QCOMPARE(values, expected); @@ -121,42 +119,42 @@ void tst_qpromise_each::delayedFulfilled() void tst_qpromise_each::delayedRejected() { - auto p = QPromise>::resolve({42, 43, 44}).each([](int v, ...) { - return QPromise{ - [&](const QPromiseResolve& resolve, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - if (v == 44) { - reject(QString{"foo"}); - } - resolve(v); - }); - }}; + auto p = QtPromise::QPromise>::resolve({42, 43, 44}).each([](int v, ...) { + return QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve, + const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + if (v == 44) { + reject(QString{"foo"}); + } + resolve(v); + }); + }}; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); } void tst_qpromise_each::functorThrows() { - auto p = QPromise>::resolve({42, 43, 44}).each([](int v, ...) { + auto p = QtPromise::QPromise>::resolve({42, 43, 44}).each([](int v, ...) { if (v == 44) { throw QString{"foo"}; } }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); } void tst_qpromise_each::functorArguments() { QVector values; - auto p = QPromise>::resolve({42, 43, 44}).each([&](int v, int i) { + auto p = QtPromise::QPromise>::resolve({42, 43, 44}).each([&](int v, int i) { values << i << v; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 43, 44})); QCOMPARE(values, (QVector{0, 42, 1, 43, 2, 44})); } diff --git a/tests/auto/qtpromise/qpromise/tst_fail.cpp b/tests/auto/qtpromise/qpromise/tst_fail.cpp index d5578a5..fa2244d 100644 --- a/tests/auto/qtpromise/qpromise/tst_fail.cpp +++ b/tests/auto/qtpromise/qpromise/tst_fail.cpp @@ -10,8 +10,6 @@ #include #include -using namespace QtPromise; - class tst_qpromise_fail : public QObject { Q_OBJECT @@ -72,7 +70,7 @@ private: void tst_qpromise_fail::sameType() { // http://en.cppreference.com/w/cpp/error/exception - auto p = QPromise::reject(std::out_of_range("foo")); + auto p = QtPromise::QPromise::reject(std::out_of_range("foo")); QString error; p.fail([&](const std::domain_error& e) { @@ -95,7 +93,7 @@ void tst_qpromise_fail::sameType() void tst_qpromise_fail::baseClass() { // http://en.cppreference.com/w/cpp/error/exception - auto p = QPromise::reject(std::out_of_range("foo")); + auto p = QtPromise::QPromise::reject(std::out_of_range("foo")); QString error; p.fail([&](const std::runtime_error& e) { @@ -117,7 +115,7 @@ void tst_qpromise_fail::baseClass() void tst_qpromise_fail::catchAll() { - auto p = QPromise::reject(std::out_of_range("foo")); + auto p = QtPromise::QPromise::reject(std::out_of_range("foo")); QString error; p.fail([&](const std::runtime_error& e) { @@ -140,18 +138,18 @@ void tst_qpromise_fail::catchAll() void tst_qpromise_fail::functionPtrHandlers() { { // Global functions. - auto p0 = QPromise::reject(kErr).fail(&fnNoArg); - auto p1 = QPromise::reject(kErr).fail(&fnArgByVal); - auto p2 = QPromise::reject(kErr).fail(&fnArgByRef); + auto p0 = QtPromise::QPromise::reject(kErr).fail(&fnNoArg); + auto p1 = QtPromise::QPromise::reject(kErr).fail(&fnArgByVal); + auto p2 = QtPromise::QPromise::reject(kErr).fail(&fnArgByRef); QCOMPARE(waitForValue(p0, kFail), kRes); QCOMPARE(waitForValue(p1, kFail), kRes); QCOMPARE(waitForValue(p2, kFail), kRes); } { // Static member functions. - auto p0 = QPromise::reject(kErr).fail(&Klass::kFnNoArg); - auto p1 = QPromise::reject(kErr).fail(&Klass::kFnArgByVal); - auto p2 = QPromise::reject(kErr).fail(&Klass::kFnArgByRef); + auto p0 = QtPromise::QPromise::reject(kErr).fail(&Klass::kFnNoArg); + auto p1 = QtPromise::QPromise::reject(kErr).fail(&Klass::kFnArgByVal); + auto p2 = QtPromise::QPromise::reject(kErr).fail(&Klass::kFnArgByRef); QCOMPARE(waitForValue(p0, kFail), kRes); QCOMPARE(waitForValue(p1, kFail), kRes); @@ -167,9 +165,9 @@ void tst_qpromise_fail::stdFunctionHandlers() std::function stdFnArgByVal = fnArgByVal; std::function stdFnArgByRef = fnArgByRef; - auto p0 = QPromise::reject(kErr).fail(stdFnNoArg); - auto p1 = QPromise::reject(kErr).fail(stdFnArgByVal); - auto p2 = QPromise::reject(kErr).fail(stdFnArgByRef); + auto p0 = QtPromise::QPromise::reject(kErr).fail(stdFnNoArg); + auto p1 = QtPromise::QPromise::reject(kErr).fail(stdFnArgByVal); + auto p2 = QtPromise::QPromise::reject(kErr).fail(stdFnArgByRef); QCOMPARE(waitForValue(p0, kFail), kRes); QCOMPARE(waitForValue(p1, kFail), kRes); @@ -180,19 +178,20 @@ void tst_qpromise_fail::stdFunctionHandlers() const std::function stdFnArgByVal = fnArgByVal; const std::function stdFnArgByRef = fnArgByRef; - auto p0 = QPromise::reject(kErr).fail(stdFnNoArg); - auto p1 = QPromise::reject(kErr).fail(stdFnArgByVal); - auto p2 = QPromise::reject(kErr).fail(stdFnArgByRef); + auto p0 = QtPromise::QPromise::reject(kErr).fail(stdFnNoArg); + auto p1 = QtPromise::QPromise::reject(kErr).fail(stdFnArgByVal); + auto p2 = QtPromise::QPromise::reject(kErr).fail(stdFnArgByRef); QCOMPARE(waitForValue(p0, kFail), kRes); QCOMPARE(waitForValue(p1, kFail), kRes); QCOMPARE(waitForValue(p2, kFail), kRes); } { // rvalue. - auto p0 = QPromise::reject(kErr).fail(std::function{fnNoArg}); - auto p1 = QPromise::reject(kErr).fail(std::function{fnArgByVal}); - auto p2 = - QPromise::reject(kErr).fail(std::function{fnArgByRef}); + auto p0 = QtPromise::QPromise::reject(kErr).fail(std::function{fnNoArg}); + auto p1 = QtPromise::QPromise::reject(kErr).fail( + std::function{fnArgByVal}); + auto p2 = QtPromise::QPromise::reject(kErr).fail( + std::function{fnArgByRef}); QCOMPARE(waitForValue(p0, kFail), kRes); QCOMPARE(waitForValue(p1, kFail), kRes); @@ -213,9 +212,9 @@ void tst_qpromise_fail::stdBindHandlers() const std::function bindArgByRef = std::bind(&Klass::fnArgByRef, &obj, _1); - auto p0 = QPromise::reject(kErr).fail(bindNoArg); - auto p1 = QPromise::reject(kErr).fail(bindArgByVal); - auto p2 = QPromise::reject(kErr).fail(bindArgByRef); + auto p0 = QtPromise::QPromise::reject(kErr).fail(bindNoArg); + auto p1 = QtPromise::QPromise::reject(kErr).fail(bindArgByVal); + auto p2 = QtPromise::QPromise::reject(kErr).fail(bindArgByRef); QCOMPARE(waitForValue(p0, kFail), val); QCOMPARE(waitForValue(p1, kFail), val + kRes); @@ -235,9 +234,9 @@ void tst_qpromise_fail::lambdaHandlers() return v.toFloat(); }; - auto p0 = QPromise::reject(kErr).fail(lambdaNoArg); - auto p1 = QPromise::reject(kErr).fail(lambdaArgByVal); - auto p2 = QPromise::reject(kErr).fail(lambdaArgByRef); + auto p0 = QtPromise::QPromise::reject(kErr).fail(lambdaNoArg); + auto p1 = QtPromise::QPromise::reject(kErr).fail(lambdaArgByVal); + auto p2 = QtPromise::QPromise::reject(kErr).fail(lambdaArgByRef); QCOMPARE(waitForValue(p0, kFail), kRes); QCOMPARE(waitForValue(p1, kFail), kRes); @@ -254,22 +253,22 @@ void tst_qpromise_fail::lambdaHandlers() return v.toFloat(); }; - auto p0 = QPromise::reject(kErr).fail(lambdaNoArg); - auto p1 = QPromise::reject(kErr).fail(lambdaArgByVal); - auto p2 = QPromise::reject(kErr).fail(lambdaArgByRef); + auto p0 = QtPromise::QPromise::reject(kErr).fail(lambdaNoArg); + auto p1 = QtPromise::QPromise::reject(kErr).fail(lambdaArgByVal); + auto p2 = QtPromise::QPromise::reject(kErr).fail(lambdaArgByRef); QCOMPARE(waitForValue(p0, kFail), kRes); QCOMPARE(waitForValue(p1, kFail), kRes); QCOMPARE(waitForValue(p2, kFail), kRes); } { // rvalue. - auto p0 = QPromise::reject(kErr).fail([]() { + auto p0 = QtPromise::QPromise::reject(kErr).fail([]() { return kRes; }); - auto p1 = QPromise::reject(kErr).fail([](QString v) { + auto p1 = QtPromise::QPromise::reject(kErr).fail([](QString v) { return v.toFloat(); }); - auto p2 = QPromise::reject(kErr).fail([](const QString& v) { + auto p2 = QtPromise::QPromise::reject(kErr).fail([](const QString& v) { return v.toFloat(); }); diff --git a/tests/auto/qtpromise/qpromise/tst_filter.cpp b/tests/auto/qtpromise/qpromise/tst_filter.cpp index ffede75..dfd1276 100644 --- a/tests/auto/qtpromise/qpromise/tst_filter.cpp +++ b/tests/auto/qtpromise/qpromise/tst_filter.cpp @@ -11,8 +11,6 @@ #include #include -using namespace QtPromise; - class tst_qpromise_filter : public QObject { Q_OBJECT @@ -43,13 +41,13 @@ struct SequenceTester return v > 42 && v < 51; }) .filter([](int, int i) { - return QPromise::resolve(i % 2 == 0); + return QtPromise::QPromise::resolve(i % 2 == 0); }) .filter([](int v, ...) { return v != 45; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, Sequence{}), (Sequence{43, 47, 49})); } }; @@ -58,78 +56,78 @@ struct SequenceTester void tst_qpromise_filter::emptySequence() { - auto p = QPromise>::resolve({}).filter([](int v, ...) { + auto p = QtPromise::QPromise>::resolve({}).filter([](int v, ...) { return v % 2 == 0; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), QVector{}); } void tst_qpromise_filter::filterValues() { - auto p = QPromise>::resolve({42, 43, 44}).filter([](int v, ...) { + auto p = QtPromise::QPromise>::resolve({42, 43, 44}).filter([](int v, ...) { return v % 2 == 0; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 44})); } void tst_qpromise_filter::delayedFulfilled() { - auto p = QPromise>::resolve({42, 43, 44}).filter([](int v, ...) { - return QPromise{[&](const QPromiseResolve& resolve) { + auto p = QtPromise::QPromise>::resolve({42, 43, 44}).filter([](int v, ...) { + return QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(v % 2 == 0); }); }}; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 44})); } void tst_qpromise_filter::delayedRejected() { - auto p = QPromise>::resolve({42, 43, 44}).filter([](int v, ...) { - return QPromise{ - [&](const QPromiseResolve& resolve, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - if (v == 43) { - reject(QString{"foo"}); - } - resolve(true); - }); - }}; + auto p = QtPromise::QPromise>::resolve({42, 43, 44}).filter([](int v, ...) { + return QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve, + const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + if (v == 43) { + reject(QString{"foo"}); + } + resolve(true); + }); + }}; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); } void tst_qpromise_filter::functorThrows() { - auto p = QPromise>::resolve({42, 43, 44}).filter([](int v, ...) { + auto p = QtPromise::QPromise>::resolve({42, 43, 44}).filter([](int v, ...) { if (v == 43) { throw QString{"foo"}; } return true; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); } void tst_qpromise_filter::functorArguments() { QMap args; - auto p = QPromise>::resolve({42, 43, 44}).filter([&](int v, int i) { + auto p = QtPromise::QPromise>::resolve({42, 43, 44}).filter([&](int v, int i) { args[v] = i; return i % 2 == 0; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{42, 44})); QMap expected{{42, 0}, {43, 1}, {44, 2}}; QCOMPARE(args, expected); @@ -137,11 +135,12 @@ void tst_qpromise_filter::functorArguments() void tst_qpromise_filter::preserveOrder() { - auto p = QPromise>::resolve({250, 50, 100, 400, 300}).filter([](int v, ...) { - return QPromise::resolve(v > 200).delay(v); - }); + auto p = + QtPromise::QPromise>::resolve({250, 50, 100, 400, 300}).filter([](int v, ...) { + return QtPromise::QPromise::resolve(v > 200).delay(v); + }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{250, 400, 300})); } diff --git a/tests/auto/qtpromise/qpromise/tst_finally.cpp b/tests/auto/qtpromise/qpromise/tst_finally.cpp index 299c70a..705ac3c 100644 --- a/tests/auto/qtpromise/qpromise/tst_finally.cpp +++ b/tests/auto/qtpromise/qpromise/tst_finally.cpp @@ -10,8 +10,6 @@ #include #include -using namespace QtPromise; - class tst_qpromise_finally : public QObject { Q_OBJECT @@ -37,12 +35,12 @@ QTEST_MAIN(tst_qpromise_finally) void tst_qpromise_finally::fulfilledSync() { int value = -1; - auto p = QPromise::resolve(42).finally([&]() { + auto p = QtPromise::QPromise::resolve(42).finally([&]() { value = 8; return 16; // ignored! }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, -1), 42); QCOMPARE(p.isFulfilled(), true); QCOMPARE(value, 8); @@ -51,12 +49,12 @@ void tst_qpromise_finally::fulfilledSync() void tst_qpromise_finally::fulfilledSync_void() { int value = -1; - auto p = QPromise::resolve().finally([&]() { + auto p = QtPromise::QPromise::resolve().finally([&]() { value = 8; return 16; // ignored! }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, -1, 42), 42); QCOMPARE(p.isFulfilled(), true); QCOMPARE(value, 8); @@ -64,22 +62,22 @@ void tst_qpromise_finally::fulfilledSync_void() void tst_qpromise_finally::fulfilledThrows() { - auto p = QPromise::resolve(42).finally([&]() { + auto p = QtPromise::QPromise::resolve(42).finally([&]() { throw QString{"bar"}; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForError(p, QString{}), QString{"bar"}); QCOMPARE(p.isRejected(), true); } void tst_qpromise_finally::fulfilledThrows_void() { - auto p = QPromise::resolve().finally([&]() { + auto p = QtPromise::QPromise::resolve().finally([&]() { throw QString{"bar"}; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForError(p, QString{}), QString{"bar"}); QCOMPARE(p.isRejected(), true); } @@ -87,8 +85,8 @@ void tst_qpromise_finally::fulfilledThrows_void() void tst_qpromise_finally::fulfilledAsyncResolve() { QVector values; - auto p = QPromise::resolve(42).finally([&]() { - QPromise p{[&](const QPromiseResolve& resolve) { + auto p = QtPromise::QPromise::resolve(42).finally([&]() { + QtPromise::QPromise p{[&](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=, &values]() { values << 64; resolve(16); // ignored! @@ -106,8 +104,9 @@ void tst_qpromise_finally::fulfilledAsyncResolve() void tst_qpromise_finally::fulfilledAsyncReject() { - auto p = QPromise::resolve(42).finally([]() { - return QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { + auto p = QtPromise::QPromise::resolve(42).finally([]() { + return QtPromise::QPromise{[](const QtPromise::QPromiseResolve&, + const QtPromise::QPromiseReject& reject) { QtPromisePrivate::qtpromise_defer([=]() { reject(QString{"bar"}); }); @@ -121,12 +120,12 @@ void tst_qpromise_finally::fulfilledAsyncReject() void tst_qpromise_finally::rejectedSync() { int value = -1; - auto p = QPromise::reject(QString{"foo"}).finally([&]() { + auto p = QtPromise::QPromise::reject(QString{"foo"}).finally([&]() { value = 8; return 16; // ignored! }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); QCOMPARE(p.isRejected(), true); QCOMPARE(value, 8); @@ -135,12 +134,12 @@ void tst_qpromise_finally::rejectedSync() void tst_qpromise_finally::rejectedSync_void() { int value = -1; - auto p = QPromise::reject(QString{"foo"}).finally([&]() { + auto p = QtPromise::QPromise::reject(QString{"foo"}).finally([&]() { value = 8; return 16; // ignored! }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); QCOMPARE(p.isRejected(), true); QCOMPARE(value, 8); @@ -148,22 +147,22 @@ void tst_qpromise_finally::rejectedSync_void() void tst_qpromise_finally::rejectedThrows() { - auto p = QPromise::reject(QString{"foo"}).finally([&]() { + auto p = QtPromise::QPromise::reject(QString{"foo"}).finally([&]() { throw QString{"bar"}; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForError(p, QString{}), QString{"bar"}); QCOMPARE(p.isRejected(), true); } void tst_qpromise_finally::rejectedThrows_void() { - auto p = QPromise::reject(QString{"foo"}).finally([&]() { + auto p = QtPromise::QPromise::reject(QString{"foo"}).finally([&]() { throw QString{"bar"}; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForError(p, QString{}), QString{"bar"}); QCOMPARE(p.isRejected(), true); } @@ -171,8 +170,8 @@ void tst_qpromise_finally::rejectedThrows_void() void tst_qpromise_finally::rejectedAsyncResolve() { QVector values; - auto p = QPromise::reject(QString{"foo"}).finally([&]() { - QPromise p{[&](const QPromiseResolve& resolve) { + auto p = QtPromise::QPromise::reject(QString{"foo"}).finally([&]() { + QtPromise::QPromise p{[&](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=, &values]() { values << 64; resolve(16); // ignored! @@ -194,8 +193,9 @@ void tst_qpromise_finally::rejectedAsyncResolve() void tst_qpromise_finally::rejectedAsyncReject() { - auto p = QPromise::reject(QString{"foo"}).finally([]() { - return QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { + auto p = QtPromise::QPromise::reject(QString{"foo"}).finally([]() { + return QtPromise::QPromise{[](const QtPromise::QPromiseResolve&, + const QtPromise::QPromiseReject& reject) { QtPromisePrivate::qtpromise_defer([=]() { reject(QString{"bar"}); }); diff --git a/tests/auto/qtpromise/qpromise/tst_map.cpp b/tests/auto/qtpromise/qpromise/tst_map.cpp index 7d5fc7a..dad8912 100644 --- a/tests/auto/qtpromise/qpromise/tst_map.cpp +++ b/tests/auto/qtpromise/qpromise/tst_map.cpp @@ -10,8 +10,6 @@ #include #include -using namespace QtPromise; - class tst_qpromise_map : public QObject { Q_OBJECT @@ -52,7 +50,7 @@ struct SequenceTester return QString::fromUtf8(v); }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{"0:43!", "1:44!", "2:45!"})); } @@ -66,7 +64,7 @@ void tst_qpromise_map::emptySequence() return v + 1; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), QVector{}); } @@ -76,7 +74,7 @@ void tst_qpromise_map::modifyValues() return v + 1; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{43, 44, 45})); } @@ -86,39 +84,39 @@ void tst_qpromise_map::convertValues() return QString::number(v + 1); }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{"43", "44", "45"})); } void tst_qpromise_map::delayedFulfilled() { auto p = QtPromise::resolve(QVector{42, 43, 44}).map([](int v, ...) { - return QPromise{[&](const QPromiseResolve& resolve) { + return QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(v + 1); }); }}; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{43, 44, 45})); } void tst_qpromise_map::delayedRejected() { auto p = QtPromise::resolve(QVector{42, 43, 44}).map([](int v, ...) { - return QPromise{ - [&](const QPromiseResolve& resolve, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - if (v == 43) { - reject(QString{"foo"}); - } - resolve(v); - }); - }}; + return QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve, + const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + if (v == 43) { + reject(QString{"foo"}); + } + resolve(v); + }); + }}; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); } @@ -131,7 +129,7 @@ void tst_qpromise_map::functorThrows() return v + 1; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); } @@ -141,7 +139,7 @@ void tst_qpromise_map::functorArguments() return v * i; }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p1, QVector{}), (QVector{0, 42, 84})); } @@ -151,7 +149,7 @@ void tst_qpromise_map::preserveOrder() return QtPromise::resolve(v + 1).delay(v); }); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>>::value)); QCOMPARE(waitForValue(p, QVector{}), (QVector{251, 501, 101})); } diff --git a/tests/auto/qtpromise/qpromise/tst_operators.cpp b/tests/auto/qtpromise/qpromise/tst_operators.cpp index dca0a2e..21ccee4 100644 --- a/tests/auto/qtpromise/qpromise/tst_operators.cpp +++ b/tests/auto/qtpromise/qpromise/tst_operators.cpp @@ -10,8 +10,6 @@ #include #include -using namespace QtPromise; - class tst_qpromise_operators : public QObject { Q_OBJECT @@ -34,21 +32,22 @@ QTEST_MAIN(tst_qpromise_operators) void tst_qpromise_operators::move() { - auto p0 = QPromise::resolve(42); + auto p0 = QtPromise::QPromise::resolve(42); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(waitForValue(p0, -1), 42); - p0 = QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo"}); - }); - }}; + p0 = QtPromise::QPromise{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo"}); + }); + }}; QCOMPARE(p0.isPending(), true); QCOMPARE(waitForError(p0, QString{}), QString{"foo"}); - p0 = QPromise{[](const QPromiseResolve& resolve) { + p0 = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(43); }); @@ -60,21 +59,22 @@ void tst_qpromise_operators::move() void tst_qpromise_operators::move_void() { - auto p0 = QPromise::resolve(); + auto p0 = QtPromise::QPromise::resolve(); QCOMPARE(p0.isFulfilled(), true); QCOMPARE(waitForValue(p0, -1, 42), 42); - p0 = QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo"}); - }); - }}; + p0 = QtPromise::QPromise{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo"}); + }); + }}; QCOMPARE(p0.isPending(), true); QCOMPARE(waitForError(p0, QString{}), QString{"foo"}); - p0 = QPromise{[](const QPromiseResolve& resolve) { + p0 = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(); }); @@ -86,13 +86,14 @@ void tst_qpromise_operators::move_void() void tst_qpromise_operators::copy() { - auto p0 = QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo"}); - }); - }}; + auto p0 = QtPromise::QPromise{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo"}); + }); + }}; - auto p1 = QPromise{[](const QPromiseResolve& resolve) { + auto p1 = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(42); }); @@ -113,13 +114,14 @@ void tst_qpromise_operators::copy() void tst_qpromise_operators::copy_void() { - auto p0 = QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo"}); - }); - }}; + auto p0 = QtPromise::QPromise{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo"}); + }); + }}; - auto p1 = QPromise{[](const QPromiseResolve& resolve) { + auto p1 = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(); }); @@ -143,8 +145,8 @@ void tst_qpromise_operators::copy_void() void tst_qpromise_operators::equalTo() { - auto p0 = QPromise::resolve(42); - auto p1 = QPromise::resolve(42); + auto p0 = QtPromise::QPromise::resolve(42); + auto p1 = QtPromise::QPromise::resolve(42); auto p2 = p1; auto p3(p2); @@ -158,8 +160,8 @@ void tst_qpromise_operators::equalTo() void tst_qpromise_operators::equalTo_void() { - auto p0 = QPromise::resolve(); - auto p1 = QPromise::resolve(); + auto p0 = QtPromise::QPromise::resolve(); + auto p1 = QtPromise::QPromise::resolve(); auto p2 = p1; auto p3(p2); @@ -173,8 +175,8 @@ void tst_qpromise_operators::equalTo_void() void tst_qpromise_operators::notEqualTo() { - auto p0 = QPromise::resolve(42); - auto p1 = QPromise::resolve(42); + auto p0 = QtPromise::QPromise::resolve(42); + auto p1 = QtPromise::QPromise::resolve(42); auto p2 = p1; auto p3(p2); @@ -188,8 +190,8 @@ void tst_qpromise_operators::notEqualTo() void tst_qpromise_operators::notEqualTo_void() { - auto p0 = QPromise::resolve(); - auto p1 = QPromise::resolve(); + auto p0 = QtPromise::QPromise::resolve(); + auto p1 = QtPromise::QPromise::resolve(); auto p2 = p1; auto p3(p2); @@ -203,10 +205,10 @@ void tst_qpromise_operators::notEqualTo_void() void tst_qpromise_operators::chaining() { - auto p = QPromise::resolve(1); + auto p = QtPromise::QPromise::resolve(1); for (int i = 0; i < 4; ++i) { p = p.then([](int res) { - return QPromise::resolve(res * 2); + return QtPromise::QPromise::resolve(res * 2); }); } @@ -218,12 +220,12 @@ void tst_qpromise_operators::chaining_void() { QVector values; - auto p = QPromise::resolve(); + auto p = QtPromise::QPromise::resolve(); for (int i = 0; i < 4; ++i) { p = p.then([i, &values]() { values.append(i * 2); - return QPromise::resolve(); + return QtPromise::QPromise::resolve(); }); } diff --git a/tests/auto/qtpromise/qpromise/tst_reduce.cpp b/tests/auto/qtpromise/qpromise/tst_reduce.cpp index 966bcfd..234d86a 100644 --- a/tests/auto/qtpromise/qpromise/tst_reduce.cpp +++ b/tests/auto/qtpromise/qpromise/tst_reduce.cpp @@ -11,8 +11,6 @@ #include #include -using namespace QtPromise; - class tst_qpromise_reduce : public QObject { Q_OBJECT @@ -56,8 +54,8 @@ struct SequenceTester }, QtPromise::resolve(2).delay(100)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -84,7 +82,7 @@ void tst_qpromise_reduce::emptySequence() // NOTE(SB): reduce() on an empty sequence without an initial value is an error! - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, -1), 42); QCOMPARE(called, false); @@ -107,8 +105,8 @@ void tst_qpromise_reduce::regularValues() }, 2); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -120,9 +118,9 @@ void tst_qpromise_reduce::regularValues() void tst_qpromise_reduce::promiseValues() { - QVector> inputs{QtPromise::resolve(4).delay(400), - QtPromise::resolve(6).delay(300), - QtPromise::resolve(8).delay(200)}; + QVector> inputs{QtPromise::resolve(4).delay(400), + QtPromise::resolve(6).delay(300), + QtPromise::resolve(8).delay(200)}; QVector v0; QVector v1; @@ -137,8 +135,8 @@ void tst_qpromise_reduce::promiseValues() }, 2); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -160,7 +158,7 @@ void tst_qpromise_reduce::convertResultType() // NOTE(SB): when no initial value is given, the result type is the sequence type. - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, QString{}), QString{"foo:4:0:6:1:8:2"}); @@ -178,7 +176,7 @@ void tst_qpromise_reduce::delayedInitialValue() }, QtPromise::resolve(2).delay(100)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isPending(), true); QCOMPARE(waitForValue(p, -1), 23); @@ -202,8 +200,8 @@ void tst_qpromise_reduce::delayedFulfilled() }, 2); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -222,7 +220,7 @@ void tst_qpromise_reduce::delayedRejected() auto p0 = QtPromise::resolve(inputs).reduce([&](int acc, int cur, int idx) { v0 << acc << cur << idx; if (cur == 6) { - return QPromise::reject(QString{"foo"}); + return QtPromise::QPromise::reject(QString{"foo"}); } return QtPromise::resolve(acc + cur + idx); }); @@ -230,14 +228,14 @@ void tst_qpromise_reduce::delayedRejected() [&](int acc, int cur, int idx) { v1 << acc << cur << idx; if (cur == 6) { - return QPromise::reject(QString{"bar"}); + return QtPromise::QPromise::reject(QString{"bar"}); } return QtPromise::resolve(acc + cur + idx); }, 2); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -270,8 +268,8 @@ void tst_qpromise_reduce::functorThrows() }, 2); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p0.isPending(), true); QCOMPARE(p1.isPending(), true); @@ -285,10 +283,10 @@ void tst_qpromise_reduce::sequenceTypes() { #if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) // QLinkedList is deprecated since Qt 5.15. - SequenceTester>>::exec(); + SequenceTester>>::exec(); #endif - SequenceTester>>::exec(); - SequenceTester>>::exec(); - SequenceTester>>::exec(); - SequenceTester>>::exec(); + SequenceTester>>::exec(); + SequenceTester>>::exec(); + SequenceTester>>::exec(); + SequenceTester>>::exec(); } diff --git a/tests/auto/qtpromise/qpromise/tst_resolve.cpp b/tests/auto/qtpromise/qpromise/tst_resolve.cpp index edacdec..889d3f8 100644 --- a/tests/auto/qtpromise/qpromise/tst_resolve.cpp +++ b/tests/auto/qtpromise/qpromise/tst_resolve.cpp @@ -13,8 +13,6 @@ #include -using namespace QtPromise; - class tst_qpromise_resolve : public QObject { Q_OBJECT @@ -36,13 +34,13 @@ void tst_qpromise_resolve::value() int v0 = 42; const int v1 = 42; - auto p0 = QPromise::resolve(42); - auto p1 = QPromise::resolve(v0); - auto p2 = QPromise::resolve(v1); + auto p0 = QtPromise::QPromise::resolve(42); + auto p1 = QtPromise::QPromise::resolve(v0); + auto p2 = QtPromise::QPromise::resolve(v1); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); for (const auto& p : {p0, p1, p2}) { QCOMPARE(p.isFulfilled(), true); @@ -54,9 +52,9 @@ void tst_qpromise_resolve::value() void tst_qpromise_resolve::noValue() { - auto p = QPromise::resolve(); + auto p = QtPromise::QPromise::resolve(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(p.isFulfilled(), true); QCOMPARE(waitForValue(p, -1, 42), 42); @@ -69,7 +67,7 @@ void tst_qpromise_resolve::moveRValue() { auto p = QtPromise::resolve(Data{42}).wait(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); } QCOMPARE(Data::logs().ctor, 1); @@ -86,7 +84,7 @@ void tst_qpromise_resolve::copyLValue() Data value{42}; auto p = QtPromise::resolve(value).wait(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); } QCOMPARE(Data::logs().ctor, 1); @@ -98,24 +96,26 @@ void tst_qpromise_resolve::copyLValue() // https://github.com/simonbrunel/qtpromise/issues/6 void tst_qpromise_resolve::qtSharedPtr() { + using DataSPtr = QSharedPointer; + Data::logs().reset(); QWeakPointer wptr; { - auto sptr0 = QSharedPointer::create(42); - const QSharedPointer sptr1 = sptr0; + auto sptr0 = DataSPtr::create(42); + const DataSPtr sptr1 = sptr0; - auto p0 = QPromise>::resolve(QSharedPointer::create(42)); - auto p1 = QPromise>::resolve(sptr0); - auto p2 = QPromise>::resolve(sptr1); + auto p0 = QtPromise::QPromise::resolve(DataSPtr::create(42)); + auto p1 = QtPromise::QPromise::resolve(sptr0); + auto p2 = QtPromise::QPromise::resolve(sptr1); - Q_STATIC_ASSERT((std::is_same>>::value)); - Q_STATIC_ASSERT((std::is_same>>::value)); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); - QCOMPARE(waitForValue(p1, QSharedPointer{}), sptr0); - QCOMPARE(waitForValue(p2, QSharedPointer{}), sptr1); + QCOMPARE(waitForValue(p1, DataSPtr{}), sptr0); + QCOMPARE(waitForValue(p2, DataSPtr{}), sptr1); wptr = sptr0; @@ -134,24 +134,26 @@ void tst_qpromise_resolve::qtSharedPtr() // https://github.com/simonbrunel/qtpromise/issues/6 void tst_qpromise_resolve::stdSharedPtr() { + using DataSPtr = std::shared_ptr; + Data::logs().reset(); std::weak_ptr wptr; { auto sptr0 = std::make_shared(42); - const std::shared_ptr sptr1 = sptr0; + const DataSPtr sptr1 = sptr0; - auto p0 = QPromise>::resolve(std::make_shared(42)); - auto p1 = QPromise>::resolve(sptr0); - auto p2 = QPromise>::resolve(sptr1); + auto p0 = QtPromise::QPromise::resolve(std::make_shared(42)); + auto p1 = QtPromise::QPromise::resolve(sptr0); + auto p2 = QtPromise::QPromise::resolve(sptr1); - Q_STATIC_ASSERT((std::is_same>>::value)); - Q_STATIC_ASSERT((std::is_same>>::value)); - Q_STATIC_ASSERT((std::is_same>>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); - QCOMPARE(waitForValue(p1, std::shared_ptr{}), sptr0); - QCOMPARE(waitForValue(p2, std::shared_ptr{}), sptr1); + QCOMPARE(waitForValue(p1, DataSPtr{}), sptr0); + QCOMPARE(waitForValue(p2, DataSPtr{}), sptr1); wptr = sptr0; diff --git a/tests/auto/qtpromise/qpromise/tst_tap.cpp b/tests/auto/qtpromise/qpromise/tst_tap.cpp index aebee92..09d0c6e 100644 --- a/tests/auto/qtpromise/qpromise/tst_tap.cpp +++ b/tests/auto/qtpromise/qpromise/tst_tap.cpp @@ -10,8 +10,6 @@ #include #include -using namespace QtPromise; - class tst_qpromise_tap : public QObject { Q_OBJECT @@ -33,7 +31,7 @@ QTEST_MAIN(tst_qpromise_tap) void tst_qpromise_tap::fulfilledSync() { int value = -1; - auto p = QPromise::resolve(42).tap([&](int res) { + auto p = QtPromise::QPromise::resolve(42).tap([&](int res) { value = res + 1; return 8; }); @@ -46,7 +44,7 @@ void tst_qpromise_tap::fulfilledSync() void tst_qpromise_tap::fulfilledSync_void() { int value = -1; - auto p = QPromise::resolve().tap([&]() { + auto p = QtPromise::QPromise::resolve().tap([&]() { value = 43; return 8; }); @@ -58,7 +56,7 @@ void tst_qpromise_tap::fulfilledSync_void() void tst_qpromise_tap::fulfilledThrows() { - auto p = QPromise::resolve(42).tap([&](int) { + auto p = QtPromise::QPromise::resolve(42).tap([&](int) { throw QString{"foo"}; }); @@ -68,7 +66,7 @@ void tst_qpromise_tap::fulfilledThrows() void tst_qpromise_tap::fulfilledThrows_void() { - auto p = QPromise::resolve().tap([&]() { + auto p = QtPromise::QPromise::resolve().tap([&]() { throw QString{"foo"}; }); @@ -79,8 +77,8 @@ void tst_qpromise_tap::fulfilledThrows_void() void tst_qpromise_tap::fulfilledAsyncResolve() { QVector values; - auto p = QPromise::resolve(1).tap([&](int) { - QPromise p{[&](const QPromiseResolve& resolve) { + auto p = QtPromise::QPromise::resolve(1).tap([&](int) { + QtPromise::QPromise p{[&](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=, &values]() { values << 3; resolve(4); // ignored! @@ -102,8 +100,9 @@ void tst_qpromise_tap::fulfilledAsyncResolve() void tst_qpromise_tap::fulfilledAsyncReject() { QVector values; - auto p = QPromise::resolve(1).tap([&](int) { - QPromise p{[&](const QPromiseResolve&, const QPromiseReject& reject) { + auto p = QtPromise::QPromise::resolve(1).tap([&](int) { + QtPromise::QPromise p{[&](const QtPromise::QPromiseResolve&, + const QtPromise::QPromiseReject& reject) { QtPromisePrivate::qtpromise_defer([=, &values]() { values << 3; reject(QString{"foo"}); @@ -126,7 +125,7 @@ void tst_qpromise_tap::fulfilledAsyncReject() void tst_qpromise_tap::rejectedSync() { int value = -1; - auto p = QPromise::reject(QString{"foo"}).tap([&](int res) { + auto p = QtPromise::QPromise::reject(QString{"foo"}).tap([&](int res) { value = res + 1; }); @@ -138,7 +137,7 @@ void tst_qpromise_tap::rejectedSync() void tst_qpromise_tap::rejectedSync_void() { int value = -1; - auto p = QPromise::reject(QString{"foo"}).tap([&]() { + auto p = QtPromise::QPromise::reject(QString{"foo"}).tap([&]() { value = 43; }); diff --git a/tests/auto/qtpromise/qpromise/tst_tapfail.cpp b/tests/auto/qtpromise/qpromise/tst_tapfail.cpp index 8e0b55d..7ce8198 100644 --- a/tests/auto/qtpromise/qpromise/tst_tapfail.cpp +++ b/tests/auto/qtpromise/qpromise/tst_tapfail.cpp @@ -10,8 +10,6 @@ #include #include -using namespace QtPromise; - class tst_qpromise_tapfail : public QObject { Q_OBJECT @@ -33,7 +31,7 @@ QTEST_MAIN(tst_qpromise_tapfail) void tst_qpromise_tapfail::fulfilled() { int value = -1; - auto p = QPromise::resolve(42).tapFail([&]() { + auto p = QtPromise::QPromise::resolve(42).tapFail([&]() { value = 43; }); @@ -45,7 +43,7 @@ void tst_qpromise_tapfail::fulfilled() void tst_qpromise_tapfail::fulfilled_void() { int value = -1; - auto p = QPromise::resolve().tapFail([&]() { + auto p = QtPromise::QPromise::resolve().tapFail([&]() { value = 43; }); @@ -58,7 +56,7 @@ void tst_qpromise_tapfail::rejected() { QStringList errors; - auto p0 = QPromise::reject(QString{"foo"}).tapFail([&](const QString& err) { + auto p0 = QtPromise::QPromise::reject(QString{"foo"}).tapFail([&](const QString& err) { errors << "1:" + err; }); @@ -78,7 +76,7 @@ void tst_qpromise_tapfail::rejected_void() { QStringList errors; - auto p0 = QPromise::reject(QString{"foo"}).tapFail([&](const QString& err) { + auto p0 = QtPromise::QPromise::reject(QString{"foo"}).tapFail([&](const QString& err) { errors << "1:" + err; }); @@ -95,7 +93,7 @@ void tst_qpromise_tapfail::rejected_void() void tst_qpromise_tapfail::throws() { - auto p = QPromise::reject(QString{"foo"}).tapFail([&]() { + auto p = QtPromise::QPromise::reject(QString{"foo"}).tapFail([&]() { throw QString{"bar"}; }); @@ -105,7 +103,7 @@ void tst_qpromise_tapfail::throws() void tst_qpromise_tapfail::throws_void() { - auto p = QPromise::reject(QString{"foo"}).tapFail([&]() { + auto p = QtPromise::QPromise::reject(QString{"foo"}).tapFail([&]() { throw QString{"bar"}; }); @@ -116,8 +114,8 @@ void tst_qpromise_tapfail::throws_void() void tst_qpromise_tapfail::delayedResolved() { QVector values; - auto p = QPromise::reject(QString{"foo"}).tapFail([&]() { - QPromise p{[&](const QPromiseResolve& resolve) { + auto p = QtPromise::QPromise::reject(QString{"foo"}).tapFail([&]() { + QtPromise::QPromise p{[&](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=, &values]() { values << 3; resolve(); // ignored! @@ -135,8 +133,9 @@ void tst_qpromise_tapfail::delayedResolved() void tst_qpromise_tapfail::delayedRejected() { QVector values; - auto p = QPromise::reject(QString{"foo"}).tapFail([&]() { - QPromise p{[&](const QPromiseResolve&, const QPromiseReject& reject) { + auto p = QtPromise::QPromise::reject(QString{"foo"}).tapFail([&]() { + QtPromise::QPromise p{[&](const QtPromise::QPromiseResolve&, + const QtPromise::QPromiseReject& reject) { QtPromisePrivate::qtpromise_defer([=, &values]() { values << 3; reject(QString{"bar"}); diff --git a/tests/auto/qtpromise/qpromise/tst_then.cpp b/tests/auto/qtpromise/qpromise/tst_then.cpp index fc21c96..9c897f4 100644 --- a/tests/auto/qtpromise/qpromise/tst_then.cpp +++ b/tests/auto/qtpromise/qpromise/tst_then.cpp @@ -12,8 +12,6 @@ #include -using namespace QtPromise; - class tst_qpromise_then : public QObject { Q_OBJECT @@ -76,7 +74,7 @@ void tst_qpromise_then::resolveSync() { QVariantList values; - auto input = QPromise::resolve(42); + auto input = QtPromise::QPromise::resolve(42); auto output = input.then([&](int res) { values << res; return QString::number(res + 1); @@ -98,22 +96,23 @@ void tst_qpromise_then::resolveSync() void tst_qpromise_then::resolveAsync() { - auto p = QPromise::resolve(42).then([](int res) { - return QPromise{[=](const QPromiseResolve& resolve) { - QtPromisePrivate::qtpromise_defer([=]() { - resolve(QString{"foo%1"}.arg(res)); - }); - }}; + auto p = QtPromise::QPromise::resolve(42).then([](int res) { + return QtPromise::QPromise{ + [=](const QtPromise::QPromiseResolve& resolve) { + QtPromisePrivate::qtpromise_defer([=]() { + resolve(QString{"foo%1"}.arg(res)); + }); + }}; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForValue(p, QString{}), QString{"foo42"}); QCOMPARE(p.isFulfilled(), true); } void tst_qpromise_then::rejectSync() { - auto input = QPromise::resolve(42); + auto input = QtPromise::QPromise::resolve(42); auto output = input.then([](int res) { throw QString{"foo%1"}.arg(res); return 42; @@ -136,43 +135,43 @@ void tst_qpromise_then::rejectSync() void tst_qpromise_then::rejectAsync() { - auto p = QPromise::resolve(42).then([](int res) { - return QPromise{ - [=](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - reject(QString{"foo%1"}.arg(res)); - }); - }}; + auto p = QtPromise::QPromise::resolve(42).then([](int res) { + return QtPromise::QPromise{[=](const QtPromise::QPromiseResolve&, + const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + reject(QString{"foo%1"}.arg(res)); + }); + }}; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(waitForError(p, QString{}), QString{"foo42"}); QCOMPARE(p.isRejected(), true); } void tst_qpromise_then::skipResult() { - auto p = QPromise::resolve(42); + auto p = QtPromise::QPromise::resolve(42); int value = -1; p.then([&]() { value = 43; }).wait(); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); QCOMPARE(value, 43); } void tst_qpromise_then::nullHandler() { { // resolved - auto p = QPromise::resolve(42).then(nullptr); + auto p = QtPromise::QPromise::resolve(42).then(nullptr); QCOMPARE(waitForValue(p, -1), 42); QCOMPARE(p.isFulfilled(), true); } { // rejected - auto p = QPromise::reject(QString{"foo"}).then(nullptr); + auto p = QtPromise::QPromise::reject(QString{"foo"}).then(nullptr); QCOMPARE(waitForError(p, QString{}), QString{"foo"}); QCOMPARE(p.isRejected(), true); diff --git a/tests/auto/qtpromise/qpromise/tst_timeout.cpp b/tests/auto/qtpromise/qpromise/tst_timeout.cpp index fd62ed0..ad0dfb8 100644 --- a/tests/auto/qtpromise/qpromise/tst_timeout.cpp +++ b/tests/auto/qtpromise/qpromise/tst_timeout.cpp @@ -12,8 +12,6 @@ #include -using namespace QtPromise; - class tst_qpromise_timeout : public QObject { Q_OBJECT @@ -38,7 +36,7 @@ void tst_qpromise_timeout::fulfilled() timer.start(); - auto p = QPromise{[](const QPromiseResolve& resolve) { + auto p = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QTimer::singleShot(1000, [=]() { resolve(42); }); @@ -59,7 +57,8 @@ void tst_qpromise_timeout::rejected() timer.start(); - auto p = QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { + auto p = QtPromise::QPromise{[](const QtPromise::QPromiseResolve&, + const QtPromise::QPromiseReject& reject) { QTimer::singleShot(1000, [=]() { reject(QString{"foo"}); }); @@ -81,7 +80,7 @@ void tst_qpromise_timeout::timeout() timer.start(); - auto p = QPromise{[](const QPromiseResolve& resolve) { + auto p = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QTimer::singleShot(4000, [=]() { resolve(42); }); @@ -90,7 +89,7 @@ void tst_qpromise_timeout::timeout() elapsed = timer.elapsed(); }); - p.fail([&](const QPromiseTimeoutException&) { + p.fail([&](const QtPromise::QPromiseTimeoutException&) { failed = true; return -1; }).wait(); @@ -113,7 +112,7 @@ void tst_qpromise_timeout::fulfilledStdChrono() timer.start(); - auto p = QPromise{[](const QPromiseResolve& resolve) { + auto p = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QTimer::singleShot(1000, [=]() { resolve(42); }); @@ -134,7 +133,8 @@ void tst_qpromise_timeout::rejectedStdChrono() timer.start(); - auto p = QPromise{[](const QPromiseResolve&, const QPromiseReject& reject) { + auto p = QtPromise::QPromise{[](const QtPromise::QPromiseResolve&, + const QtPromise::QPromiseReject& reject) { QTimer::singleShot(1000, [=]() { reject(QString{"foo"}); }); @@ -156,7 +156,7 @@ void tst_qpromise_timeout::timeoutStdChrono() timer.start(); - auto p = QPromise{[](const QPromiseResolve& resolve) { + auto p = QtPromise::QPromise{[](const QtPromise::QPromiseResolve& resolve) { QTimer::singleShot(4000, [=]() { resolve(42); }); @@ -165,7 +165,7 @@ void tst_qpromise_timeout::timeoutStdChrono() elapsed = timer.elapsed(); }); - p.fail([&](const QPromiseTimeoutException&) { + p.fail([&](const QtPromise::QPromiseTimeoutException&) { failed = true; return -1; }).wait(); diff --git a/tests/auto/qtpromise/qpromiseconnections/tst_qpromiseconnections.cpp b/tests/auto/qtpromise/qpromiseconnections/tst_qpromiseconnections.cpp index 339b1e3..0e8058c 100644 --- a/tests/auto/qtpromise/qpromiseconnections/tst_qpromiseconnections.cpp +++ b/tests/auto/qtpromise/qpromiseconnections/tst_qpromiseconnections.cpp @@ -11,8 +11,6 @@ #include #include -using namespace QtPromise; - class tst_qpromiseconnections : public QObject { Q_OBJECT @@ -31,7 +29,7 @@ void tst_qpromiseconnections::connections() { Object sender; - QPromiseConnections connections; + QtPromise::QPromiseConnections connections; QCOMPARE(sender.hasConnections(), false); QCOMPARE(connections.count(), 0); @@ -53,7 +51,7 @@ void tst_qpromiseconnections::destruction() Object sender; { - QPromiseConnections connections; + QtPromise::QPromiseConnections connections; QCOMPARE(sender.hasConnections(), false); QCOMPARE(connections.count(), 0); @@ -67,7 +65,7 @@ void tst_qpromiseconnections::destruction() void tst_qpromiseconnections::senderDestroyed() { - QPromiseConnections connections; + QtPromise::QPromiseConnections connections; QCOMPARE(connections.count(), 0); { diff --git a/tests/auto/qtpromise/requirements/tst_requirements.cpp b/tests/auto/qtpromise/requirements/tst_requirements.cpp index 83a31f3..7b4d2d9 100644 --- a/tests/auto/qtpromise/requirements/tst_requirements.cpp +++ b/tests/auto/qtpromise/requirements/tst_requirements.cpp @@ -8,8 +8,6 @@ #include #include -using namespace QtPromise; - // https://promisesaplus.com/#requirements class tst_requirements : public QObject { @@ -43,7 +41,7 @@ void tst_requirements::statePending() // 2.1.1. When pending, a promise: // 2.1.1.1. may transition to either the fulfilled state { - QPromise p{[&](const QPromiseResolve& resolve) { + QtPromise::QPromise p{[&](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(42); }); @@ -62,7 +60,8 @@ void tst_requirements::statePending() // 2.1.1.1. ... or the rejected state { - QPromise p{[&](const QPromiseResolve&, const QPromiseReject& reject) { + QtPromise::QPromise p{[&](const QtPromise::QPromiseResolve&, + const QtPromise::QPromiseReject& reject) { QtPromisePrivate::qtpromise_defer([=]() { reject(QString{"foo"}); }); @@ -86,7 +85,8 @@ void tst_requirements::stateFulfilled() int value = -1; // 2.1.2. When fulfilled, a promise: - QPromise p{[](const QPromiseResolve& resolve, const QPromiseReject& reject) { + QtPromise::QPromise p{[](const QtPromise::QPromiseResolve& resolve, + const QtPromise::QPromiseReject& reject) { QtPromisePrivate::qtpromise_defer([=]() { // 2.1.2.2. must have a value, which must not change. resolve(42); @@ -120,7 +120,8 @@ void tst_requirements::stateRejected() int value = -1; // 2.1.3 When rejected, a promise: - QPromise p{[](const QPromiseResolve& resolve, const QPromiseReject& reject) { + QtPromise::QPromise p{[](const QtPromise::QPromiseResolve& resolve, + const QtPromise::QPromiseReject& reject) { QtPromisePrivate::qtpromise_defer([=]() { // 2.1.3.2. must have a reason, which must not change. reject(QString{"foo"}); @@ -154,7 +155,7 @@ void tst_requirements::thenArguments() { QString error; int value = -1; - QPromise::resolve(42) + QtPromise::QPromise::resolve(42) .then( [&](int res) { value = res; @@ -170,7 +171,7 @@ void tst_requirements::thenArguments() { QString error; int value = -1; - QPromise::reject(QString{"foo"}) + QtPromise::QPromise::reject(QString{"foo"}) .then( [&](int res) { value = res; @@ -187,7 +188,7 @@ void tst_requirements::thenArguments() // 2.2.1. onFulfilled is an optional arguments: { QString error; - QPromise::reject(QString{"foo"}) + QtPromise::QPromise::reject(QString{"foo"}) .then(nullptr, [&](const QString& err) { error = err; @@ -201,7 +202,7 @@ void tst_requirements::thenArguments() // 2.2.1. onRejected is an optional arguments: { int value = -1; - QPromise::resolve(42) + QtPromise::QPromise::resolve(42) .then([&value](int res) { value = res; }) @@ -219,7 +220,7 @@ void tst_requirements::thenOnFulfilled() { // 2.2.2. If onFulfilled is a function: QVector values; - QPromise p0{[](const QPromiseResolve& resolve) { + QtPromise::QPromise p0{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { // 2.2.2.3. it must not be called more than once resolve(42); @@ -249,13 +250,14 @@ void tst_requirements::thenOnRejected() { // 2.2.3. If onRejected is a function: QStringList errors; - QPromise p0{[](const QPromiseResolve&, const QPromiseReject& reject) { - QtPromisePrivate::qtpromise_defer([=]() { - // 2.2.3.3. it must not be called more than once. - reject(QString{"foo"}); - reject(QString{"bar"}); - }); - }}; + QtPromise::QPromise p0{ + [](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + QtPromisePrivate::qtpromise_defer([=]() { + // 2.2.3.3. it must not be called more than once. + reject(QString{"foo"}); + reject(QString{"bar"}); + }); + }}; auto p1 = p0.then(nullptr, [&](const QString& err) { errors << err; @@ -282,7 +284,7 @@ void tst_requirements::thenAsynchronous() // loop turn in which then is called, and with a fresh stack). int value = -1; - auto p0 = QPromise::resolve(42); + auto p0 = QtPromise::QPromise::resolve(42); QVERIFY(p0.isFulfilled()); auto p1 = p0.then([&](int res) { @@ -304,21 +306,21 @@ void tst_requirements::thenMultipleCalls() // must execute in the order of their originating calls to then: { QVector values; - QPromise p{[](const QPromiseResolve& resolve) { + QtPromise::QPromise p{[](const QtPromise::QPromiseResolve& resolve) { QtPromisePrivate::qtpromise_defer([=]() { resolve(42); }); }}; - QtPromise::all(QVector>{p.then([&](int r) { - values << r + 1; - }), - p.then([&](int r) { - values << r + 2; - }), - p.then([&](int r) { - values << r + 3; - })}) + QtPromise::all(QVector>{p.then([&](int r) { + values << r + 1; + }), + p.then([&](int r) { + values << r + 2; + }), + p.then([&](int r) { + values << r + 3; + })}) .wait(); QCOMPARE(values, (QVector{43, 44, 45})); @@ -328,27 +330,28 @@ void tst_requirements::thenMultipleCalls() // must execute in the order of their originating calls to then: { QVector values; - QPromise p{[](const QPromiseResolve&, const QPromiseReject& reject) { + QtPromise::QPromise p{[](const QtPromise::QPromiseResolve&, + const QtPromise::QPromiseReject& reject) { QtPromisePrivate::qtpromise_defer([=]() { reject(8); }); }}; - QtPromise::all(QVector>{p.then(nullptr, - [&](int r) { - values << r + 1; - return r + 1; - }), - p.then(nullptr, - [&](int r) { - values << r + 2; - return r + 2; - }), - p.then(nullptr, - [&](int r) { - values << r + 3; - return r + 3; - })}) + QtPromise::all(QVector>{p.then(nullptr, + [&](int r) { + values << r + 1; + return r + 1; + }), + p.then(nullptr, + [&](int r) { + values << r + 2; + return r + 2; + }), + p.then(nullptr, + [&](int r) { + values << r + 3; + return r + 3; + })}) .wait(); QCOMPARE(values, (QVector{9, 10, 11})); @@ -362,10 +365,13 @@ void tst_requirements::thenHandlers() auto handler = []() { return 42; }; - auto p1 = QPromise::resolve(42); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); - Q_STATIC_ASSERT((std::is_same>::value)); + auto p1 = QtPromise::QPromise::resolve(42); + Q_STATIC_ASSERT( + (std::is_same>::value)); + Q_STATIC_ASSERT( + (std::is_same>::value)); + Q_STATIC_ASSERT( + (std::is_same>::value)); } // 2.2.7.1. If either onFulfilled or onRejected returns a value x, run the @@ -375,7 +381,7 @@ void tst_requirements::thenHandlers() // p2 must be rejected with e as the reason. { QString reason; - auto p1 = QPromise::resolve(42); + auto p1 = QtPromise::QPromise::resolve(42); auto p2 = p1.then([]() { throw QString{"foo"}; }); @@ -389,7 +395,7 @@ void tst_requirements::thenHandlers() } { QString reason; - auto p1 = QPromise::reject(QString{"foo"}); + auto p1 = QtPromise::QPromise::reject(QString{"foo"}); auto p2 = p1.then(nullptr, []() { throw QString{"bar"}; return 42; @@ -408,11 +414,11 @@ void tst_requirements::thenHandlers() // p2 must be fulfilled with the same value as promise1 { QString value; - auto p1 = QPromise::resolve("42"); + auto p1 = QtPromise::QPromise::resolve("42"); auto p2 = p1.then(nullptr, []() { return QString{}; }); - Q_STATIC_ASSERT((std::is_same>::value)); + Q_STATIC_ASSERT((std::is_same>::value)); p2.then([&](const QString& e) { value = e; }).wait(); diff --git a/tests/auto/qtpromise/shared/CMakeLists.txt b/tests/auto/qtpromise/shared/CMakeLists.txt index 7e77c7e..afb6498 100644 --- a/tests/auto/qtpromise/shared/CMakeLists.txt +++ b/tests/auto/qtpromise/shared/CMakeLists.txt @@ -7,6 +7,6 @@ add_library(${PROJECT_NAME} STATIC ) target_link_libraries(${PROJECT_NAME} PUBLIC - Qt5::Core + Qt${QT_VERSION_MAJOR}::Core qtpromise ) diff --git a/tests/auto/qtpromise/thread/tst_thread.cpp b/tests/auto/qtpromise/thread/tst_thread.cpp index 74dacd6..b98eb94 100644 --- a/tests/auto/qtpromise/thread/tst_thread.cpp +++ b/tests/auto/qtpromise/thread/tst_thread.cpp @@ -9,8 +9,6 @@ #include #include -using namespace QtPromise; - class tst_thread : public QObject { Q_OBJECT @@ -35,8 +33,8 @@ void tst_thread::resolve() QThread* target = nullptr; QThread* source = nullptr; - QPromise{[&](const QPromiseResolve& resolve) { - QtConcurrent::run([=, &source]() { + QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve) { + std::ignore = QtConcurrent::run([=, &source]() { source = QThread::currentThread(); resolve(42); }); @@ -59,8 +57,8 @@ void tst_thread::resolve_void() QThread* target = nullptr; QThread* source = nullptr; - QPromise{[&](const QPromiseResolve& resolve) { - QtConcurrent::run([=, &source]() { + QtPromise::QPromise{[&](const QtPromise::QPromiseResolve& resolve) { + std::ignore = QtConcurrent::run([=, &source]() { source = QThread::currentThread(); resolve(); }); @@ -83,12 +81,13 @@ void tst_thread::reject() QThread* target = nullptr; QThread* source = nullptr; - QPromise{[&](const QPromiseResolve&, const QPromiseReject& reject) { - QtConcurrent::run([=, &source]() { - source = QThread::currentThread(); - reject(QString{"foo"}); - }); - }} + QtPromise::QPromise{ + [&](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + std::ignore = QtConcurrent::run([=, &source]() { + source = QThread::currentThread(); + reject(QString{"foo"}); + }); + }} .fail([&](const QString& err) { target = QThread::currentThread(); error = err; @@ -105,7 +104,7 @@ void tst_thread::reject() void tst_thread::then() { QThread* source = nullptr; - QPromise p{[&](const QPromiseResolve& resolve) { + QtPromise::QPromise p{[&](const QtPromise::QPromiseResolve& resolve) { source = QThread::currentThread(); resolve(42); }}; @@ -113,7 +112,7 @@ void tst_thread::then() int value = -1; QThread* target = nullptr; QtPromise::resolve(QtConcurrent::run( - [&](const QPromise& p) { + [&](const QtPromise::QPromise& p) { p.then([&](int res) { target = QThread::currentThread(); value = res; @@ -131,7 +130,7 @@ void tst_thread::then() void tst_thread::then_void() { QThread* source = nullptr; - QPromise p{[&](const QPromiseResolve& resolve) { + QtPromise::QPromise p{[&](const QtPromise::QPromiseResolve& resolve) { source = QThread::currentThread(); resolve(); }}; @@ -139,7 +138,7 @@ void tst_thread::then_void() int value = -1; QThread* target = nullptr; QtPromise::resolve(QtConcurrent::run( - [&](const QPromise& p) { + [&](const QtPromise::QPromise& p) { p.then([&]() { target = QThread::currentThread(); value = 43; @@ -157,15 +156,16 @@ void tst_thread::then_void() void tst_thread::fail() { QThread* source = nullptr; - QPromise p{[&](const QPromiseResolve&, const QPromiseReject& reject) { - source = QThread::currentThread(); - reject(QString{"foo"}); - }}; + QtPromise::QPromise p{ + [&](const QtPromise::QPromiseResolve&, const QtPromise::QPromiseReject& reject) { + source = QThread::currentThread(); + reject(QString{"foo"}); + }}; QString error; QThread* target = nullptr; QtPromise::resolve(QtConcurrent::run( - [&](const QPromise& p) { + [&](const QtPromise::QPromise& p) { p.fail([&](const QString& err) { target = QThread::currentThread(); error = err; @@ -184,7 +184,7 @@ void tst_thread::fail() void tst_thread::finally() { QThread* source = nullptr; - QPromise p{[&](const QPromiseResolve& resolve) { + QtPromise::QPromise p{[&](const QtPromise::QPromiseResolve& resolve) { source = QThread::currentThread(); resolve(42); }}; @@ -192,7 +192,7 @@ void tst_thread::finally() int value = -1; QThread* target = nullptr; QtPromise::resolve(QtConcurrent::run( - [&](const QPromise& p) { + [&](const QtPromise::QPromise& p) { p.finally([&]() { target = QThread::currentThread(); value = 43;