mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2025-04-10 02:51:29 +08:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1a905cbd4f | ||
|
14031392ac | ||
|
f382ad25fc | ||
|
ac9b936959 | ||
|
21faa67b58 | ||
|
9f01c130cd | ||
|
461f09bef8 | ||
|
bac405febf | ||
|
0c3955cca5 | ||
|
60b36e7a70 |
@ -1,27 +1,34 @@
|
|||||||
image: Visual Studio 2015
|
# https://www.appveyor.com/docs/build-configuration/
|
||||||
|
# https://www.appveyor.com/docs/lang/cpp/#visual-studio
|
||||||
init:
|
|
||||||
- cmd: call "C:\Program Files (x86)\Microsoft Visual Studio "%VSVER%".0\VC\vcvarsall.bat" %ARCH%
|
|
||||||
- cmd: qmake --version
|
|
||||||
|
|
||||||
# https://www.appveyor.com/docs/windows-images-software/#qt
|
# https://www.appveyor.com/docs/windows-images-software/#qt
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
PATH: '%PATH%;%QTDIR%\bin'
|
PATH: '%PATH%;%QTDIR%\bin'
|
||||||
matrix:
|
matrix:
|
||||||
- QTDIR: C:\Qt\5.6\msvc2013
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||||
VSVER: 12
|
QTDIR: C:\Qt\5.6\msvc2013
|
||||||
ARCH: x86
|
SETUP_CMD: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat
|
||||||
- QTDIR: C:\Qt\5.9\msvc2013_64
|
SETUP_ARG: x86
|
||||||
VSVER: 12
|
|
||||||
ARCH: x64
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||||
- QTDIR: C:\Qt\latest\msvc2015_64
|
QTDIR: C:\Qt\5.15\msvc2019_64
|
||||||
VSVER: 14
|
SETUP_CMD: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat
|
||||||
ARCH: x64
|
|
||||||
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||||
|
QTDIR: C:\Qt\6.2\msvc2019_64
|
||||||
|
SETUP_CMD: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat
|
||||||
|
|
||||||
|
before_build:
|
||||||
|
- call "%SETUP_CMD%" %SETUP_ARG%
|
||||||
|
- cmake --version
|
||||||
|
- qmake --version
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
- cmd: cmake -G "NMake Makefiles"
|
- cmake -G "NMake Makefiles"
|
||||||
- cmd: cmake --build .
|
- cmake --build .
|
||||||
|
|
||||||
test_script:
|
test_script:
|
||||||
- cmd: cmake --build . --target test
|
- cmake --build . --target test
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
fast_finish: true
|
||||||
|
43
.github/workflows/ci.yaml
vendored
Normal file
43
.github/workflows/ci.yaml
vendored
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# https://docs.github.com/actions/reference/workflow-syntax-for-github-actions
|
||||||
|
# https://doc.qt.io/qt-6/supported-platforms.html
|
||||||
|
# https://ddalcino.github.io/aqt-list-server/
|
||||||
|
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
qt:
|
||||||
|
- 5.9.9
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: jurplel/install-qt-action@v4
|
||||||
|
with:
|
||||||
|
version: ${{ matrix.qt }}
|
||||||
|
archives: qtbase icu
|
||||||
|
tools: tools_cmake
|
||||||
|
arch: gcc_64
|
||||||
|
host: linux
|
||||||
|
- run: |
|
||||||
|
qmake --version
|
||||||
|
cmake --version
|
||||||
|
gcc --version
|
||||||
|
g++ --version
|
||||||
|
- run: |
|
||||||
|
cmake -G "Unix Makefiles"
|
||||||
|
cmake --build . -- -j12
|
||||||
|
cmake --build . --target test
|
||||||
|
- run: |
|
||||||
|
sudo apt-get install lcov > /dev/null
|
||||||
|
lcov --version
|
||||||
|
lcov --capture --directory . -o coverage.info
|
||||||
|
lcov -e coverage.info '**/src/**/*' -o coverage.info
|
||||||
|
- uses: codecov/codecov-action@v3
|
||||||
|
env:
|
||||||
|
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
with:
|
||||||
|
files: coverage.info
|
38
.travis.yml
38
.travis.yml
@ -1,38 +0,0 @@
|
|||||||
sudo: required
|
|
||||||
dist: trusty
|
|
||||||
language: cpp
|
|
||||||
compiler: gcc
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
|
|
||||||
- sudo add-apt-repository -y ppa:beineri/opt-qt563-trusty
|
|
||||||
- sudo apt-get update -qq
|
|
||||||
|
|
||||||
install:
|
|
||||||
- sudo apt-get install -qq gcc-4.9 g++-4.9
|
|
||||||
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 90
|
|
||||||
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 90
|
|
||||||
- sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-4.9 90
|
|
||||||
- sudo apt-get install -qq qt56base
|
|
||||||
- source /opt/qt56/bin/qt56-env.sh
|
|
||||||
- wget http://archive.ubuntu.com/ubuntu/pool/universe/l/lcov/lcov_1.13.orig.tar.gz
|
|
||||||
- tar xf lcov_1.13.orig.tar.gz
|
|
||||||
- cd lcov-1.13/
|
|
||||||
- sudo make install
|
|
||||||
- cd ..
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- cmake --version
|
|
||||||
- qmake --version
|
|
||||||
- gcc --version && g++ --version
|
|
||||||
- lcov --version && gcov --version
|
|
||||||
|
|
||||||
script:
|
|
||||||
- cmake -G "Unix Makefiles"
|
|
||||||
- cmake --build . -- -j12
|
|
||||||
- cmake --build . --target test
|
|
||||||
- lcov -capture --directory . --o coverage.info
|
|
||||||
- lcov -e coverage.info '**/src/**/*' -o coverage.info
|
|
||||||
|
|
||||||
after_success:
|
|
||||||
- bash <(curl -s https://codecov.io/bash) -f coverage.info
|
|
@ -4,11 +4,12 @@ if(DEFINED PROJECT_NAME)
|
|||||||
set(SUBPROJECT ON)
|
set(SUBPROJECT ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
project(qtpromise VERSION 0.6.0 LANGUAGES CXX)
|
project(qtpromise VERSION 0.7.0 LANGUAGES CXX)
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
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_AUTOMOC ON)
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
@ -17,7 +18,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||||||
add_library(qtpromise INTERFACE)
|
add_library(qtpromise INTERFACE)
|
||||||
add_library(qtpromise::qtpromise ALIAS qtpromise)
|
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")
|
target_include_directories(qtpromise INTERFACE "${CMAKE_CURRENT_LIST_DIR}/include")
|
||||||
|
|
||||||
add_definitions(
|
add_definitions(
|
||||||
@ -34,11 +35,40 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
|||||||
-Wall
|
-Wall
|
||||||
-Wextra
|
-Wextra
|
||||||
-Wconversion
|
-Wconversion
|
||||||
-Wsign-conversion
|
-Wdouble-promotion
|
||||||
|
-Wformat=2
|
||||||
|
-Wlogical-op
|
||||||
|
-Wmissing-noreturn
|
||||||
-Wold-style-cast
|
-Wold-style-cast
|
||||||
|
# -Wshadow # disabled due to many findings in the current code
|
||||||
|
-Wsign-conversion
|
||||||
|
-Wswitch-default
|
||||||
-Wunused-local-typedefs
|
-Wunused-local-typedefs
|
||||||
-pedantic-errors
|
-pedantic-errors
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# https://github.com/Barro/compiler-warnings/blob/master/gcc/warnings-gcc-6.txt
|
||||||
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6)
|
||||||
|
add_compile_options(
|
||||||
|
-Wduplicated-cond
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# https://github.com/Barro/compiler-warnings/blob/master/gcc/warnings-gcc-7.txt
|
||||||
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7)
|
||||||
|
add_compile_options(
|
||||||
|
-Wduplicated-branches
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
|
# https://clang.llvm.org/docs/DiagnosticsReference.html
|
||||||
|
add_compile_options(
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
||||||
|
-Wpedantic
|
||||||
|
-Wsuggest-destructor-override
|
||||||
|
-Wsuggest-override
|
||||||
|
)
|
||||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||||
# https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
|
# https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
|
||||||
add_compile_options(
|
add_compile_options(
|
||||||
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2017-2020 Simon Brunel, https://github.com/simonbrunel
|
Copyright (c) 2017-present Simon Brunel, https://github.com/simonbrunel
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
[Promises/A+](https://promisesaplus.com/) implementation for [Qt/C++](https://www.qt.io/).
|
[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
|
## Documentation
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ function(qtpromise_add_test NAME)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(${_TARGET}
|
target_link_libraries(${_TARGET}
|
||||||
Qt5::Concurrent
|
Qt${QT_VERSION_MAJOR}::Concurrent
|
||||||
Qt5::Test
|
Qt${QT_VERSION_MAJOR}::Test
|
||||||
qtpromise
|
qtpromise
|
||||||
qtpromise.tests.utils
|
qtpromise.tests.utils
|
||||||
${_ARG_LIBRARIES}
|
${_ARG_LIBRARIES}
|
||||||
|
@ -40,6 +40,7 @@ module.exports = {
|
|||||||
title: 'QPromise',
|
title: 'QPromise',
|
||||||
children: [
|
children: [
|
||||||
'/qtpromise/qpromise/constructor',
|
'/qtpromise/qpromise/constructor',
|
||||||
|
'/qtpromise/qpromise/convert',
|
||||||
'/qtpromise/qpromise/delay',
|
'/qtpromise/qpromise/delay',
|
||||||
'/qtpromise/qpromise/each',
|
'/qtpromise/qpromise/each',
|
||||||
'/qtpromise/qpromise/fail',
|
'/qtpromise/qpromise/fail',
|
||||||
@ -77,6 +78,7 @@ module.exports = {
|
|||||||
children: [
|
children: [
|
||||||
'/qtpromise/exceptions/canceled',
|
'/qtpromise/exceptions/canceled',
|
||||||
'/qtpromise/exceptions/context',
|
'/qtpromise/exceptions/context',
|
||||||
|
'/qtpromise/exceptions/conversion',
|
||||||
'/qtpromise/exceptions/timeout',
|
'/qtpromise/exceptions/timeout',
|
||||||
'/qtpromise/exceptions/undefined'
|
'/qtpromise/exceptions/undefined'
|
||||||
]
|
]
|
||||||
|
@ -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/).
|
[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
|
## Documentation
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
- [`QPromise<T>::QPromise`](qpromise/constructor.md)
|
- [`QPromise<T>::QPromise`](qpromise/constructor.md)
|
||||||
|
- [`QPromise<T>::convert`](qpromise/convert.md)
|
||||||
- [`QPromise<T>::delay`](qpromise/delay.md)
|
- [`QPromise<T>::delay`](qpromise/delay.md)
|
||||||
- [`QPromise<T>::each`](qpromise/each.md)
|
- [`QPromise<T>::each`](qpromise/each.md)
|
||||||
- [`QPromise<T>::fail`](qpromise/fail.md)
|
- [`QPromise<T>::fail`](qpromise/fail.md)
|
||||||
@ -39,6 +40,7 @@
|
|||||||
|
|
||||||
- [`QPromiseCanceledException`](exceptions/canceled.md)
|
- [`QPromiseCanceledException`](exceptions/canceled.md)
|
||||||
- [`QPromiseContextException`](exceptions/context.md)
|
- [`QPromiseContextException`](exceptions/context.md)
|
||||||
|
- [`QPromiseConversionException`](exceptions/conversion.md)
|
||||||
- [`QPromiseTimeoutException`](exceptions/timeout.md)
|
- [`QPromiseTimeoutException`](exceptions/timeout.md)
|
||||||
- [`QPromiseUndefinedException`](exceptions/undefined.md)
|
- [`QPromiseUndefinedException`](exceptions/undefined.md)
|
||||||
|
|
||||||
|
13
docs/qtpromise/exceptions/conversion.md
Normal file
13
docs/qtpromise/exceptions/conversion.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# QPromiseConversionException
|
||||||
|
|
||||||
|
*Since: 0.7.0*
|
||||||
|
|
||||||
|
This exception is thrown whenever a promise result conversion fails, for example:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
QPromise<QVariant> input = {...};
|
||||||
|
auto output = input.convert<int>()
|
||||||
|
.fail([](const QPromiseconversionException& e) {
|
||||||
|
// conversion may fail because input could not be converted to number
|
||||||
|
});
|
||||||
|
```
|
@ -28,7 +28,7 @@ installed either as a [`subtree`](#subtree) or a [`submodule`](#submodule). Read
|
|||||||
commands in ["Git: submodules vs subtrees"](https://nering.dev/2016/git-submodules-vs-subtrees/)
|
commands in ["Git: submodules vs subtrees"](https://nering.dev/2016/git-submodules-vs-subtrees/)
|
||||||
which provides a good comparison between these two workflows.
|
which provides a good comparison between these two workflows.
|
||||||
|
|
||||||
The following examples install QtPromise version 0.6.0 under the `3rdparty/qtpromise` subdirectory.
|
The following examples install QtPromise version 0.7.0 under the `3rdparty/qtpromise` subdirectory.
|
||||||
Note that the install directory is arbitrary and can be any empty directory under your repository.
|
Note that the install directory is arbitrary and can be any empty directory under your repository.
|
||||||
Once installed, refer to the [CMake](#cmake) or [qmake](#qmake) sections for details of integrating
|
Once installed, refer to the [CMake](#cmake) or [qmake](#qmake) sections for details of integrating
|
||||||
QtPromise into your project.
|
QtPromise into your project.
|
||||||
@ -38,7 +38,7 @@ QtPromise into your project.
|
|||||||
```sh
|
```sh
|
||||||
cd <your/project/repository>
|
cd <your/project/repository>
|
||||||
git remote add qtpromise https://github.com/simonbrunel/qtpromise.git
|
git remote add qtpromise https://github.com/simonbrunel/qtpromise.git
|
||||||
git subtree add -P 3rdparty/qtpromise qtpromise v0.6.0 --squash -m "Add QtPromise v0.6.0"
|
git subtree add -P 3rdparty/qtpromise qtpromise v0.7.0 --squash -m "Add QtPromise v0.7.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### submodule
|
#### submodule
|
||||||
@ -47,10 +47,10 @@ git subtree add -P 3rdparty/qtpromise qtpromise v0.6.0 --squash -m "Add QtPromis
|
|||||||
cd <your/project/repository>
|
cd <your/project/repository>
|
||||||
git submodule add https://github.com/simonbrunel/qtpromise.git 3rdparty/qtpromise
|
git submodule add https://github.com/simonbrunel/qtpromise.git 3rdparty/qtpromise
|
||||||
cd 3rdparty/qtpromise
|
cd 3rdparty/qtpromise
|
||||||
git checkout v0.6.0
|
git checkout v0.7.0
|
||||||
cd ../..
|
cd ../..
|
||||||
git add 3rdparty/qtpromise
|
git add 3rdparty/qtpromise
|
||||||
git commit -m "Add QtPromise v0.6.0"
|
git commit -m "Add QtPromise v0.7.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Download
|
### Download
|
||||||
@ -60,7 +60,7 @@ as a `zip` or `tar.gz` archive. Under Linux, you can use the following commands:
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
cd <your/project/repository>
|
cd <your/project/repository>
|
||||||
wget -q -O qtpromise.tar.gz https://github.com/simonbrunel/qtpromise/archive/v0.5.0.tar.gz
|
wget -q -O qtpromise.tar.gz https://github.com/simonbrunel/qtpromise/archive/v0.7.0.tar.gz
|
||||||
tar xzf qtpromise.tar.gz --strip 1 --one-top-level=3rdparty/qtpromise
|
tar xzf qtpromise.tar.gz --strip 1 --one-top-level=3rdparty/qtpromise
|
||||||
rm qtpromise.tar.gz
|
rm qtpromise.tar.gz
|
||||||
```
|
```
|
||||||
@ -97,7 +97,7 @@ include(FetchContent)
|
|||||||
|
|
||||||
FetchContent_Declare(qtpromise
|
FetchContent_Declare(qtpromise
|
||||||
GIT_REPOSITORY https://github.com/simonbrunel/qtpromise.git
|
GIT_REPOSITORY https://github.com/simonbrunel/qtpromise.git
|
||||||
GIT_TAG v0.6.0
|
GIT_TAG v0.7.0
|
||||||
GIT_SHALLOW true
|
GIT_SHALLOW true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
124
docs/qtpromise/qpromise/convert.md
Normal file
124
docs/qtpromise/qpromise/convert.md
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
---
|
||||||
|
title: .convert
|
||||||
|
---
|
||||||
|
|
||||||
|
# QPromise::convert
|
||||||
|
|
||||||
|
*Since: 0.7.0*
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
QPromise<T>::convert<U>() -> QPromise<U>
|
||||||
|
```
|
||||||
|
|
||||||
|
This method converts the resolved value of `QPromise<T>` to the type `U`. Depending on types `T`
|
||||||
|
and `U`, it performs a [static cast](https://en.cppreference.com/w/cpp/language/static_cast),
|
||||||
|
calls a [converting constructor](https://en.cppreference.com/w/cpp/language/converting_constructor),
|
||||||
|
or tries to convert using [QVariant](https://doc.qt.io/qt-5/qvariant.html).
|
||||||
|
|
||||||
|
If `T` and `U` are [fundamental types](https://en.cppreference.com/w/cpp/language/types) or
|
||||||
|
[enumerations](https://en.cppreference.com/w/cpp/language/enum), the result of the conversion is
|
||||||
|
the same as calling `static_cast<U>` for type `T`:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
QPromise<int> input = {...}
|
||||||
|
|
||||||
|
// output type: QPromise<double>
|
||||||
|
auto output = input.convert<double>();
|
||||||
|
|
||||||
|
output.then([](double value) {
|
||||||
|
// the value has been converted using static_cast
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
If `U` has a [converting constructor](https://en.cppreference.com/w/cpp/language/converting_constructor)
|
||||||
|
from `T`, i.e., a non-explicit constructor with a single argument accepting `T`, it is used to
|
||||||
|
convert the value:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
QPromise<QByteArray> input = {...}
|
||||||
|
|
||||||
|
// output type: QPromise<QString>
|
||||||
|
auto output = input.convert<QString>();
|
||||||
|
|
||||||
|
output.then([](const QString& value) {
|
||||||
|
// the value has been converted using static_cast that effectively calls QString(QByteArray)
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
::: tip NOTE
|
||||||
|
When using this method to convert to your own classes, make sure that the constructor meeting the
|
||||||
|
converting constructor criteria actually performs conversion.
|
||||||
|
:::
|
||||||
|
|
||||||
|
::: tip NOTE
|
||||||
|
If `U` is `void`, the resolved value of `QPromise<T>` is dropped.
|
||||||
|
:::
|
||||||
|
|
||||||
|
Calling this method for `QPromise<QVariant>` tries to convert the resolved `QVariant` to type `U`
|
||||||
|
using the `QVariant` [conversion algorithm](https://doc.qt.io/qt-5/qvariant.html#using-canconvert-and-convert-consecutively).
|
||||||
|
For example, this allows to convert a string contained in `QVariant` to number. If such a
|
||||||
|
conversion fails, the promise is rejected with
|
||||||
|
[`QPromiseConversionException`](../exceptions/conversion.md).
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// resolves to QVariant(int, 42) or QVariant(string, "foo")
|
||||||
|
QPromise<QVariant> input = {...};
|
||||||
|
|
||||||
|
auto output = input.convert<int>();
|
||||||
|
|
||||||
|
// output type: QPromise<int>
|
||||||
|
output.then([](int value) {
|
||||||
|
// input was QVariant(int, 42), value is 42
|
||||||
|
})
|
||||||
|
.fail(const QPromiseConversionException& e) {
|
||||||
|
// input was QVariant(string, "foo")
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Conversion of `T` to `QVariant` using this method effectively calls `QVariant::fromValue<T>()`.
|
||||||
|
All custom types must be registered with
|
||||||
|
[`Q_DECLARE_METATYPE`](https://doc.qt.io/qt-5/qmetatype.html#Q_DECLARE_METATYPE) for this
|
||||||
|
conversion to work:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
struct Foo {};
|
||||||
|
Q_DECLARE_METATYPE(Foo);
|
||||||
|
|
||||||
|
QPromise<Foo> input = {...}
|
||||||
|
|
||||||
|
auto output = input.convert<QVariant>();
|
||||||
|
|
||||||
|
// output type: QPromise<QVariant>
|
||||||
|
output.then([](const QVariant& value) {
|
||||||
|
// value contains an instance of Foo
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
All other combinations of `T` and `U` are converted via `QVariant`. All non-Qt types should provide
|
||||||
|
a [conversion function](https://doc.qt.io/qt-5/qmetatype.html#registerConverter), otherwise the
|
||||||
|
promise is rejected with [`QPromiseConversionException`](../exceptions/conversion.md):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
struct Foo {};
|
||||||
|
Q_DECLARE_METATYPE(Foo);
|
||||||
|
|
||||||
|
QMetaType::registerConverter<Foo, QString>([](const Foo& foo) {
|
||||||
|
return QString{...};
|
||||||
|
});
|
||||||
|
|
||||||
|
QPromise<Foo> input = {...}
|
||||||
|
|
||||||
|
auto output = input.convert<QVariant>();
|
||||||
|
|
||||||
|
// output type: QPromise<QString>
|
||||||
|
output.then([](const QString& value) {
|
||||||
|
// value contains a result produced by the custom converter
|
||||||
|
})
|
||||||
|
.fail([](const QPromiseConversionException& e) {
|
||||||
|
// QVariant was unable to convert Foo to QString
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
::: warning IMPORTANT
|
||||||
|
Calling this method for `QPromise<void>` is not supported.
|
||||||
|
:::
|
@ -95,5 +95,5 @@ auto output = input.then([](int res) {
|
|||||||
// output.isRejected() is true
|
// output.isRejected() is true
|
||||||
```
|
```
|
||||||
|
|
||||||
If an handler returns a promise (or QFuture), the `output` promise is delayed and will be resolved
|
If a handler returns a promise (or QFuture), the `output` promise is delayed and will be resolved
|
||||||
by the returned promise.
|
by the returned promise.
|
||||||
|
28505
package-lock.json
generated
28505
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -7,12 +7,12 @@
|
|||||||
"docs:lint": "remark --quiet --frail ."
|
"docs:lint": "remark --quiet --frail ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vuepress/plugin-google-analytics": "^1.6.0",
|
"@vuepress/plugin-google-analytics": "^1.9.9",
|
||||||
"remark-cli": "^8.0.1",
|
"remark-cli": "^11.0.0",
|
||||||
"remark-frontmatter": "^2.0.0",
|
"remark-frontmatter": "^4.0.1",
|
||||||
"remark-preset-lint-markdown-style-guide": "^3.0.1",
|
"remark-preset-lint-markdown-style-guide": "^5.1.2",
|
||||||
"remark-preset-lint-recommended": "^4.0.1",
|
"remark-preset-lint-recommended": "^6.1.2",
|
||||||
"remark-validate-links": "^10.0.2",
|
"remark-validate-links": "^12.1.0",
|
||||||
"vuepress": "^1.6.0"
|
"vuepress": "^1.9.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
qpm.json
2
qpm.json
@ -10,7 +10,7 @@
|
|||||||
"url": "https://github.com/simonbrunel/qtpromise.git"
|
"url": "https://github.com/simonbrunel/qtpromise.git"
|
||||||
},
|
},
|
||||||
"version": {
|
"version": {
|
||||||
"label": "0.6.0"
|
"label": "0.7.0"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"pri_filename": "qtpromise.pri",
|
"pri_filename": "qtpromise.pri",
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
#ifndef QTPROMISE_QPROMISE_H
|
#ifndef QTPROMISE_QPROMISE_H
|
||||||
#define QTPROMISE_QPROMISE_H
|
#define QTPROMISE_QPROMISE_H
|
||||||
|
|
||||||
#include "qpromise_p.h"
|
|
||||||
#include "qpromiseexceptions.h"
|
#include "qpromiseexceptions.h"
|
||||||
|
#include "qpromise_p.h"
|
||||||
#include "qpromiseglobal.h"
|
#include "qpromiseglobal.h"
|
||||||
#include "qpromiseresolver.h"
|
#include "qpromiseresolver.h"
|
||||||
|
|
||||||
@ -111,6 +111,9 @@ public:
|
|||||||
QPromise(F&& resolver) : QPromiseBase<T>(std::forward<F>(resolver))
|
QPromise(F&& resolver) : QPromiseBase<T>(std::forward<F>(resolver))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
template<typename U>
|
||||||
|
inline QPromise<U> convert() const;
|
||||||
|
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
inline QPromise<T> each(Functor fn);
|
inline QPromise<T> each(Functor fn);
|
||||||
|
|
||||||
|
@ -242,6 +242,13 @@ inline QPromise<QVector<T>> QPromise<T>::all(const Sequence<QPromise<T>, Args...
|
|||||||
return QtPromise::all(promises);
|
return QtPromise::all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
template<typename U>
|
||||||
|
inline QPromise<U> QPromise<T>::convert() const
|
||||||
|
{
|
||||||
|
return QPromiseBase<T>::then(QtPromisePrivate::PromiseConverter<T, U>::create());
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline QPromise<T> QPromise<T>::resolve(const T& value)
|
inline QPromise<T> QPromise<T>::resolve(const T& value)
|
||||||
{
|
{
|
||||||
|
@ -17,8 +17,11 @@
|
|||||||
#include <QtCore/QSharedData>
|
#include <QtCore/QSharedData>
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
|
#include <QtCore/QVariant>
|
||||||
#include <QtCore/QVector>
|
#include <QtCore/QVector>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace QtPromise {
|
namespace QtPromise {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -30,6 +33,8 @@ class QPromiseResolve;
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
class QPromiseReject;
|
class QPromiseReject;
|
||||||
|
|
||||||
|
class QPromiseConversionException;
|
||||||
|
|
||||||
} // namespace QtPromise
|
} // namespace QtPromise
|
||||||
|
|
||||||
namespace QtPromisePrivate {
|
namespace QtPromisePrivate {
|
||||||
@ -52,7 +57,7 @@ static void qtpromise_defer(F&& f, const QPointer<QThread>& thread)
|
|||||||
{
|
{
|
||||||
Event(FType&& f) : QEvent{QEvent::None}, m_f{std::move(f)} { }
|
Event(FType&& f) : QEvent{QEvent::None}, m_f{std::move(f)} { }
|
||||||
Event(const FType& f) : QEvent{QEvent::None}, m_f{f} { }
|
Event(const FType& f) : QEvent{QEvent::None}, m_f{f} { }
|
||||||
~Event() { m_f(); }
|
~Event() override { m_f(); }
|
||||||
FType m_f;
|
FType m_f;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -89,13 +94,13 @@ class PromiseValue
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PromiseValue() { }
|
PromiseValue() { }
|
||||||
PromiseValue(const T& data) : m_data(QSharedPointer<T>::create(data)) { }
|
PromiseValue(const T& data) : m_data(std::make_shared<T>(data)) { }
|
||||||
PromiseValue(T&& data) : m_data(QSharedPointer<T>::create(std::forward<T>(data))) { }
|
PromiseValue(T&& data) : m_data(std::make_shared<T>(std::forward<T>(data))) { }
|
||||||
bool isNull() const { return m_data.isNull(); }
|
bool isNull() const { return m_data == nullptr; }
|
||||||
const T& data() const { return *m_data; }
|
const T& data() const { return *m_data; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedPointer<T> m_data;
|
std::shared_ptr<T> m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PromiseError
|
class PromiseError
|
||||||
@ -113,7 +118,7 @@ public:
|
|||||||
|
|
||||||
PromiseError() { }
|
PromiseError() { }
|
||||||
PromiseError(const std::exception_ptr& exception) : m_data{exception} { }
|
PromiseError(const std::exception_ptr& exception) : m_data{exception} { }
|
||||||
void rethrow() const { std::rethrow_exception(m_data); }
|
Q_NORETURN void rethrow() const { std::rethrow_exception(m_data); }
|
||||||
bool isNull() const { return m_data == nullptr; }
|
bool isNull() const { return m_data == nullptr; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -329,8 +334,8 @@ struct PromiseCatcher
|
|||||||
return [=](const PromiseError& error) {
|
return [=](const PromiseError& error) {
|
||||||
try {
|
try {
|
||||||
error.rethrow();
|
error.rethrow();
|
||||||
} catch (const TArg& error) {
|
} catch (const TArg& argError) {
|
||||||
PromiseDispatch<ResType>::call(resolve, reject, handler, error);
|
PromiseDispatch<ResType>::call(resolve, reject, handler, argError);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
reject(std::current_exception());
|
reject(std::current_exception());
|
||||||
}
|
}
|
||||||
@ -553,6 +558,70 @@ struct PromiseInspect
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T, typename U, bool IsConvertibleViaStaticCast>
|
||||||
|
struct PromiseConverterBase;
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
struct PromiseConverterBase<T, U, true>
|
||||||
|
{
|
||||||
|
static std::function<U(const T&)> create()
|
||||||
|
{
|
||||||
|
return [](const T& value) {
|
||||||
|
return static_cast<U>(value);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
struct PromiseConverterBase<T, U, false>
|
||||||
|
{
|
||||||
|
static std::function<U(const T&)> create()
|
||||||
|
{
|
||||||
|
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<U>()})
|
||||||
|
&& tmp.convert(QMetaType{qMetaTypeId<U>()})) {
|
||||||
|
return qvariant_cast<U>(tmp);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// https://doc.qt.io/qt-5/qvariant.html#using-canconvert-and-convert-consecutively
|
||||||
|
if (tmp.canConvert(qMetaTypeId<U>()) && tmp.convert(qMetaTypeId<U>())) {
|
||||||
|
return qvariant_cast<U>(tmp);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
throw QtPromise::QPromiseConversionException{};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct PromiseConverterBase<T, QVariant, false>
|
||||||
|
{
|
||||||
|
static std::function<QVariant(const T&)> create()
|
||||||
|
{
|
||||||
|
return [](const T& value) {
|
||||||
|
return QVariant::fromValue(value);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
struct PromiseConverter
|
||||||
|
: PromiseConverterBase<T,
|
||||||
|
U,
|
||||||
|
// Fundamental types and converting constructors.
|
||||||
|
std::is_convertible<T, U>::value ||
|
||||||
|
// Conversion to void.
|
||||||
|
std::is_same<U, void>::value ||
|
||||||
|
// Conversion between enums and arithmetic types.
|
||||||
|
((std::is_enum<T>::value && std::is_arithmetic<U>::value)
|
||||||
|
|| (std::is_arithmetic<T>::value && std::is_enum<U>::value)
|
||||||
|
|| (std::is_enum<T>::value && std::is_enum<U>::value))>
|
||||||
|
{ };
|
||||||
|
|
||||||
} // namespace QtPromisePrivate
|
} // namespace QtPromisePrivate
|
||||||
|
|
||||||
#endif // QTPROMISE_QPROMISE_H
|
#endif // QTPROMISE_QPROMISE_H
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#define QTPROMISE_QPROMISECONNECTIONS_H
|
#define QTPROMISE_QPROMISECONNECTIONS_H
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace QtPromise {
|
namespace QtPromise {
|
||||||
@ -18,7 +19,7 @@ class QPromiseConnections
|
|||||||
public:
|
public:
|
||||||
QPromiseConnections() : m_d(std::make_shared<Data>()) { }
|
QPromiseConnections() : m_d(std::make_shared<Data>()) { }
|
||||||
|
|
||||||
int count() const { return m_d->connections.count(); }
|
int count() const { return static_cast<int>(m_d->connections.count()); }
|
||||||
|
|
||||||
void disconnect() const { m_d->disconnect(); }
|
void disconnect() const { m_d->disconnect(); }
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#ifndef QTPROMISE_QPROMISEEXCEPTIONS_H
|
#ifndef QTPROMISE_QPROMISEEXCEPTIONS_H
|
||||||
#define QTPROMISE_QPROMISEEXCEPTIONS_H
|
#define QTPROMISE_QPROMISEEXCEPTIONS_H
|
||||||
|
|
||||||
#include "qpromise_p.h"
|
|
||||||
#include "qpromiseglobal.h"
|
#include "qpromiseglobal.h"
|
||||||
|
|
||||||
#include <QtCore/QException>
|
#include <QtCore/QException>
|
||||||
@ -35,6 +34,16 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class QPromiseConversionException : public QException
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void raise() const Q_DECL_OVERRIDE { throw *this; }
|
||||||
|
QPromiseConversionException* clone() const Q_DECL_OVERRIDE
|
||||||
|
{
|
||||||
|
return new QPromiseConversionException{*this};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class QPromiseTimeoutException : public QException
|
class QPromiseTimeoutException : public QException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -55,12 +64,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// QPromiseError is provided for backward compatibility and will be
|
|
||||||
// removed in the next major version: it wasn't intended to be used
|
|
||||||
// directly and thus should not be part of the public API.
|
|
||||||
// TODO Remove QPromiseError at version 1.0
|
|
||||||
using QPromiseError = QtPromisePrivate::PromiseError;
|
|
||||||
|
|
||||||
} // namespace QtPromise
|
} // namespace QtPromise
|
||||||
|
|
||||||
#endif // QTPROMISE_QPROMISEEXCEPTIONS_H
|
#endif // QTPROMISE_QPROMISEEXCEPTIONS_H
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
find_package(Qt5 5.6.0 REQUIRED
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED
|
||||||
COMPONENTS
|
COMPONENTS
|
||||||
Concurrent
|
Concurrent
|
||||||
Test
|
Test
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
# define EXCEPT_CALL_COPY_CTOR 0
|
# define EXCEPT_CALL_COPY_CTOR 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_benchmark : public QObject
|
class tst_benchmark : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -43,7 +41,7 @@ void tst_benchmark::valueResolve()
|
|||||||
{
|
{
|
||||||
{ // should move the value when resolved by rvalue
|
{ // should move the value when resolved by rvalue
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>{[&](const QPromiseResolve<Data>& resolve) {
|
QtPromise::QPromise<Data>{[&](const QtPromise::QPromiseResolve<Data>& resolve) {
|
||||||
resolve(Data{42});
|
resolve(Data{42});
|
||||||
}}.wait();
|
}}.wait();
|
||||||
|
|
||||||
@ -54,7 +52,7 @@ void tst_benchmark::valueResolve()
|
|||||||
}
|
}
|
||||||
{ // should create one copy of the value when resolved by lvalue
|
{ // should create one copy of the value when resolved by lvalue
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>{[&](const QPromiseResolve<Data>& resolve) {
|
QtPromise::QPromise<Data>{[&](const QtPromise::QPromiseResolve<Data>& resolve) {
|
||||||
Data value{42};
|
Data value{42};
|
||||||
resolve(value);
|
resolve(value);
|
||||||
}}.wait();
|
}}.wait();
|
||||||
@ -70,7 +68,8 @@ void tst_benchmark::valueReject()
|
|||||||
{
|
{
|
||||||
{ // should not create any data if rejected
|
{ // should not create any data if rejected
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>{[&](const QPromiseResolve<Data>&, const QPromiseReject<Data>& reject) {
|
QtPromise::QPromise<Data>{[&](const QtPromise::QPromiseResolve<Data>&,
|
||||||
|
const QtPromise::QPromiseReject<Data>& reject) {
|
||||||
reject(QString{"foo"});
|
reject(QString{"foo"});
|
||||||
}}.wait();
|
}}.wait();
|
||||||
|
|
||||||
@ -83,10 +82,10 @@ void tst_benchmark::valueReject()
|
|||||||
|
|
||||||
void tst_benchmark::valueThen()
|
void tst_benchmark::valueThen()
|
||||||
{
|
{
|
||||||
{ // should not copy value on continutation if fulfilled
|
{ // should not copy value on continuation if fulfilled
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>::resolve(Data{42})
|
QtPromise::QPromise<Data>::resolve(Data{42})
|
||||||
.then([&](const Data& res) {
|
.then([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
})
|
})
|
||||||
@ -98,11 +97,11 @@ void tst_benchmark::valueThen()
|
|||||||
QCOMPARE(Data::logs().refs, 0);
|
QCOMPARE(Data::logs().refs, 0);
|
||||||
QCOMPARE(value, 42);
|
QCOMPARE(value, 42);
|
||||||
}
|
}
|
||||||
{ // should not create value on continutation if rejected
|
{ // should not create value on continuation if rejected
|
||||||
int value = -1;
|
int value = -1;
|
||||||
QString error;
|
QString error;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>::reject(QString{"foo"})
|
QtPromise::QPromise<Data>::reject(QString{"foo"})
|
||||||
.then(
|
.then(
|
||||||
[&](const Data& res) {
|
[&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
@ -122,7 +121,7 @@ void tst_benchmark::valueThen()
|
|||||||
{ // should move the returned value when fulfilled
|
{ // should move the returned value when fulfilled
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<int>::resolve(42)
|
QtPromise::QPromise<int>::resolve(42)
|
||||||
.then([&](int res) {
|
.then([&](int res) {
|
||||||
return Data{res + 2};
|
return Data{res + 2};
|
||||||
})
|
})
|
||||||
@ -139,7 +138,7 @@ void tst_benchmark::valueThen()
|
|||||||
}
|
}
|
||||||
{ // should not create any data if handler throws
|
{ // should not create any data if handler throws
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<int>::resolve(42)
|
QtPromise::QPromise<int>::resolve(42)
|
||||||
.then([&](int res) {
|
.then([&](int res) {
|
||||||
throw QString{"foo"};
|
throw QString{"foo"};
|
||||||
return Data{res + 2};
|
return Data{res + 2};
|
||||||
@ -155,12 +154,12 @@ void tst_benchmark::valueThen()
|
|||||||
|
|
||||||
void tst_benchmark::valueDelayed()
|
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;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<int>::resolve(42)
|
QtPromise::QPromise<int>::resolve(42)
|
||||||
.then([&](int res) {
|
.then([&](int res) {
|
||||||
return QPromise<Data>::resolve(Data{res + 1});
|
return QtPromise::QPromise<Data>::resolve(Data{res + 1});
|
||||||
})
|
})
|
||||||
.then([&](const Data& res) {
|
.then([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
@ -173,11 +172,11 @@ void tst_benchmark::valueDelayed()
|
|||||||
QCOMPARE(Data::logs().refs, 0);
|
QCOMPARE(Data::logs().refs, 0);
|
||||||
QCOMPARE(value, 43);
|
QCOMPARE(value, 43);
|
||||||
}
|
}
|
||||||
{ // should not create value on continutation if rejected
|
{ // should not create value on continuation if rejected
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<int>::resolve(42)
|
QtPromise::QPromise<int>::resolve(42)
|
||||||
.then([&]() {
|
.then([&]() {
|
||||||
return QPromise<Data>::reject(QString{"foo"});
|
return QtPromise::QPromise<Data>::reject(QString{"foo"});
|
||||||
})
|
})
|
||||||
.wait();
|
.wait();
|
||||||
|
|
||||||
@ -190,10 +189,10 @@ void tst_benchmark::valueDelayed()
|
|||||||
|
|
||||||
void tst_benchmark::valueFinally()
|
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;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>::resolve(Data{42})
|
QtPromise::QPromise<Data>::resolve(Data{42})
|
||||||
.finally([&]() {
|
.finally([&]() {
|
||||||
value = 42;
|
value = 42;
|
||||||
})
|
})
|
||||||
@ -205,10 +204,10 @@ void tst_benchmark::valueFinally()
|
|||||||
QCOMPARE(Data::logs().refs, 0);
|
QCOMPARE(Data::logs().refs, 0);
|
||||||
QCOMPARE(value, 42);
|
QCOMPARE(value, 42);
|
||||||
}
|
}
|
||||||
{ // should not create value on continutation if rejected
|
{ // should not create value on continuation if rejected
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>::reject(QString{"foo"})
|
QtPromise::QPromise<Data>::reject(QString{"foo"})
|
||||||
.finally([&]() {
|
.finally([&]() {
|
||||||
value = 42;
|
value = 42;
|
||||||
})
|
})
|
||||||
@ -224,10 +223,10 @@ void tst_benchmark::valueFinally()
|
|||||||
|
|
||||||
void tst_benchmark::valueTap()
|
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;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>::resolve(Data{42})
|
QtPromise::QPromise<Data>::resolve(Data{42})
|
||||||
.tap([&](const Data& res) {
|
.tap([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
})
|
})
|
||||||
@ -239,10 +238,10 @@ void tst_benchmark::valueTap()
|
|||||||
QCOMPARE(Data::logs().refs, 0);
|
QCOMPARE(Data::logs().refs, 0);
|
||||||
QCOMPARE(value, 42);
|
QCOMPARE(value, 42);
|
||||||
}
|
}
|
||||||
{ // should not create value on continutation if rejected
|
{ // should not create value on continuation if rejected
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<Data>::reject(QString{"foo"})
|
QtPromise::QPromise<Data>::reject(QString{"foo"})
|
||||||
.tap([&](const Data& res) {
|
.tap([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
})
|
})
|
||||||
@ -260,7 +259,8 @@ void tst_benchmark::errorReject()
|
|||||||
{
|
{
|
||||||
{ // should create one copy of the error when rejected by rvalue
|
{ // should create one copy of the error when rejected by rvalue
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<int>{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>&,
|
||||||
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
reject(Data{42});
|
reject(Data{42});
|
||||||
}}.wait();
|
}}.wait();
|
||||||
|
|
||||||
@ -271,7 +271,8 @@ void tst_benchmark::errorReject()
|
|||||||
}
|
}
|
||||||
{ // should create one copy of the error when rejected by lvalue (no extra copy)
|
{ // should create one copy of the error when rejected by lvalue (no extra copy)
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<int>{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>&,
|
||||||
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
Data error{42};
|
Data error{42};
|
||||||
reject(error);
|
reject(error);
|
||||||
}}.wait();
|
}}.wait();
|
||||||
@ -285,10 +286,10 @@ void tst_benchmark::errorReject()
|
|||||||
|
|
||||||
void tst_benchmark::errorThen()
|
void tst_benchmark::errorThen()
|
||||||
{
|
{
|
||||||
{ // should not copy error on continutation if rejected
|
{ // should not copy error on continuation if rejected
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<void>::reject(Data{42})
|
QtPromise::QPromise<void>::reject(Data{42})
|
||||||
.fail([&](const Data& res) {
|
.fail([&](const Data& res) {
|
||||||
value = res.value();
|
value = res.value();
|
||||||
})
|
})
|
||||||
@ -301,10 +302,10 @@ void tst_benchmark::errorThen()
|
|||||||
QCOMPARE(Data::logs().refs, 0);
|
QCOMPARE(Data::logs().refs, 0);
|
||||||
QCOMPARE(value, 42);
|
QCOMPARE(value, 42);
|
||||||
}
|
}
|
||||||
{ // should not copy error on continutation if rethrown
|
{ // should not copy error on continuation if rethrown
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
QPromise<void>::reject(Data{42})
|
QtPromise::QPromise<void>::reject(Data{42})
|
||||||
.fail([](const Data&) {
|
.fail([](const Data&) {
|
||||||
throw;
|
throw;
|
||||||
})
|
})
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_cpp14_resolver_lambda_auto : public QObject
|
class tst_cpp14_resolver_lambda_auto : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -28,19 +26,19 @@ QTEST_MAIN(tst_cpp14_resolver_lambda_auto)
|
|||||||
|
|
||||||
void tst_cpp14_resolver_lambda_auto::resolverTwoAutoArgs()
|
void tst_cpp14_resolver_lambda_auto::resolverTwoAutoArgs()
|
||||||
{
|
{
|
||||||
QPromise<int> p0{[](auto resolve, auto reject) {
|
QtPromise::QPromise<int> p0{[](auto resolve, auto reject) {
|
||||||
Q_UNUSED(reject)
|
Q_UNUSED(reject)
|
||||||
resolve(42);
|
resolve(42);
|
||||||
}};
|
}};
|
||||||
QPromise<int> p1{[](auto resolve, const auto& reject) {
|
QtPromise::QPromise<int> p1{[](auto resolve, const auto& reject) {
|
||||||
Q_UNUSED(reject)
|
Q_UNUSED(reject)
|
||||||
resolve(42);
|
resolve(42);
|
||||||
}};
|
}};
|
||||||
QPromise<int> p2{[](const auto& resolve, auto reject) {
|
QtPromise::QPromise<int> p2{[](const auto& resolve, auto reject) {
|
||||||
Q_UNUSED(reject)
|
Q_UNUSED(reject)
|
||||||
resolve(42);
|
resolve(42);
|
||||||
}};
|
}};
|
||||||
QPromise<int> p3{[](const auto& resolve, const auto& reject) {
|
QtPromise::QPromise<int> p3{[](const auto& resolve, const auto& reject) {
|
||||||
Q_UNUSED(reject)
|
Q_UNUSED(reject)
|
||||||
resolve(42);
|
resolve(42);
|
||||||
}};
|
}};
|
||||||
@ -54,19 +52,19 @@ void tst_cpp14_resolver_lambda_auto::resolverTwoAutoArgs()
|
|||||||
|
|
||||||
void tst_cpp14_resolver_lambda_auto::resolverTwoAutoArgs_void()
|
void tst_cpp14_resolver_lambda_auto::resolverTwoAutoArgs_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p0{[](auto resolve, auto reject) {
|
QtPromise::QPromise<void> p0{[](auto resolve, auto reject) {
|
||||||
Q_UNUSED(reject)
|
Q_UNUSED(reject)
|
||||||
resolve();
|
resolve();
|
||||||
}};
|
}};
|
||||||
QPromise<void> p1{[](auto resolve, const auto& reject) {
|
QtPromise::QPromise<void> p1{[](auto resolve, const auto& reject) {
|
||||||
Q_UNUSED(reject)
|
Q_UNUSED(reject)
|
||||||
resolve();
|
resolve();
|
||||||
}};
|
}};
|
||||||
QPromise<void> p2{[](const auto& resolve, auto reject) {
|
QtPromise::QPromise<void> p2{[](const auto& resolve, auto reject) {
|
||||||
Q_UNUSED(reject)
|
Q_UNUSED(reject)
|
||||||
resolve();
|
resolve();
|
||||||
}};
|
}};
|
||||||
QPromise<void> p3{[](const auto& resolve, const auto& reject) {
|
QtPromise::QPromise<void> p3{[](const auto& resolve, const auto& reject) {
|
||||||
Q_UNUSED(reject)
|
Q_UNUSED(reject)
|
||||||
resolve();
|
resolve();
|
||||||
}};
|
}};
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_deprecations_helpers_qpromise : public QObject
|
class tst_deprecations_helpers_qpromise : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -41,13 +39,13 @@ void tst_deprecations_helpers_qpromise::value()
|
|||||||
int v0 = 42;
|
int v0 = 42;
|
||||||
const int v1 = 42;
|
const int v1 = 42;
|
||||||
|
|
||||||
auto p0 = qPromise(42);
|
auto p0 = QtPromise::qPromise(42);
|
||||||
auto p1 = qPromise(v0);
|
auto p1 = QtPromise::qPromise(v0);
|
||||||
auto p2 = qPromise(v1);
|
auto p2 = QtPromise::qPromise(v1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
for (const auto& p : {p0, p1, p2}) {
|
for (const auto& p : {p0, p1, p2}) {
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
@ -59,9 +57,9 @@ void tst_deprecations_helpers_qpromise::value()
|
|||||||
|
|
||||||
void tst_deprecations_helpers_qpromise::noValue()
|
void tst_deprecations_helpers_qpromise::noValue()
|
||||||
{
|
{
|
||||||
auto p = qPromise();
|
auto p = QtPromise::qPromise();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
@ -72,9 +70,9 @@ void tst_deprecations_helpers_qpromise::moveRValue()
|
|||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
{
|
{
|
||||||
auto p = qPromise(Data{42}).wait();
|
auto p = QtPromise::qPromise(Data{42}).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Data>>::value));
|
||||||
}
|
}
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 1);
|
QCOMPARE(Data::logs().ctor, 1);
|
||||||
@ -89,9 +87,9 @@ void tst_deprecations_helpers_qpromise::copyLValue()
|
|||||||
|
|
||||||
{
|
{
|
||||||
Data value{42};
|
Data value{42};
|
||||||
auto p = qPromise(value).wait();
|
auto p = QtPromise::qPromise(value).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Data>>::value));
|
||||||
}
|
}
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 1);
|
QCOMPARE(Data::logs().ctor, 1);
|
||||||
@ -103,24 +101,26 @@ void tst_deprecations_helpers_qpromise::copyLValue()
|
|||||||
// https://github.com/simonbrunel/qtpromise/issues/6
|
// https://github.com/simonbrunel/qtpromise/issues/6
|
||||||
void tst_deprecations_helpers_qpromise::qtSharedPtr()
|
void tst_deprecations_helpers_qpromise::qtSharedPtr()
|
||||||
{
|
{
|
||||||
|
using DataSPtr = QSharedPointer<Data>;
|
||||||
|
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
QWeakPointer<Data> wptr;
|
QWeakPointer<Data> wptr;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto sptr0 = QSharedPointer<Data>::create(42);
|
auto sptr0 = DataSPtr::create(42);
|
||||||
const QSharedPointer<Data> sptr1 = sptr0;
|
const DataSPtr sptr1 = sptr0;
|
||||||
|
|
||||||
auto p0 = qPromise(QSharedPointer<Data>::create(42));
|
auto p0 = QtPromise::qPromise(DataSPtr::create(42));
|
||||||
auto p1 = qPromise(sptr0);
|
auto p1 = QtPromise::qPromise(sptr0);
|
||||||
auto p2 = qPromise(sptr1);
|
auto p2 = QtPromise::qPromise(sptr1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p1, QSharedPointer<Data>{}), sptr0);
|
QCOMPARE(waitForValue(p1, DataSPtr{}), sptr0);
|
||||||
QCOMPARE(waitForValue(p2, QSharedPointer<Data>{}), sptr1);
|
QCOMPARE(waitForValue(p2, DataSPtr{}), sptr1);
|
||||||
|
|
||||||
wptr = sptr0;
|
wptr = sptr0;
|
||||||
|
|
||||||
@ -139,24 +139,26 @@ void tst_deprecations_helpers_qpromise::qtSharedPtr()
|
|||||||
// https://github.com/simonbrunel/qtpromise/issues/6
|
// https://github.com/simonbrunel/qtpromise/issues/6
|
||||||
void tst_deprecations_helpers_qpromise::stdSharedPtr()
|
void tst_deprecations_helpers_qpromise::stdSharedPtr()
|
||||||
{
|
{
|
||||||
|
using DataSPtr = std::shared_ptr<Data>;
|
||||||
|
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
std::weak_ptr<Data> wptr;
|
std::weak_ptr<Data> wptr;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto sptr0 = std::make_shared<Data>(42);
|
auto sptr0 = std::make_shared<Data>(42);
|
||||||
const std::shared_ptr<Data> sptr1 = sptr0;
|
const DataSPtr sptr1 = sptr0;
|
||||||
|
|
||||||
auto p0 = qPromise(std::make_shared<Data>(42));
|
auto p0 = QtPromise::qPromise(std::make_shared<Data>(42));
|
||||||
auto p1 = qPromise(sptr0);
|
auto p1 = QtPromise::qPromise(sptr0);
|
||||||
auto p2 = qPromise(sptr1);
|
auto p2 = QtPromise::qPromise(sptr1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p1, std::shared_ptr<Data>{}), sptr0);
|
QCOMPARE(waitForValue(p1, DataSPtr{}), sptr0);
|
||||||
QCOMPARE(waitForValue(p2, std::shared_ptr<Data>{}), sptr1);
|
QCOMPARE(waitForValue(p2, DataSPtr{}), sptr1);
|
||||||
|
|
||||||
wptr = sptr0;
|
wptr = sptr0;
|
||||||
|
|
||||||
@ -174,22 +176,22 @@ void tst_deprecations_helpers_qpromise::stdSharedPtr()
|
|||||||
|
|
||||||
void tst_deprecations_helpers_qpromise::typedPromise()
|
void tst_deprecations_helpers_qpromise::typedPromise()
|
||||||
{
|
{
|
||||||
auto resolver = [](const QPromiseResolve<int>& resolve) {
|
auto resolver = [](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
QPromise<int> v0{resolver};
|
QtPromise::QPromise<int> v0{resolver};
|
||||||
const QPromise<int> v1 = v0;
|
const QtPromise::QPromise<int> v1 = v0;
|
||||||
|
|
||||||
auto p0 = qPromise(QPromise<int>{resolver});
|
auto p0 = QtPromise::qPromise(QtPromise::QPromise<int>{resolver});
|
||||||
auto p1 = qPromise(v0);
|
auto p1 = QtPromise::qPromise(v0);
|
||||||
auto p2 = qPromise(v1);
|
auto p2 = QtPromise::qPromise(v1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
for (const auto& promise : {p0, p1, p2}) {
|
for (const auto& promise : {p0, p1, p2}) {
|
||||||
QCOMPARE(promise.isPending(), true);
|
QCOMPARE(promise.isPending(), true);
|
||||||
@ -201,22 +203,22 @@ void tst_deprecations_helpers_qpromise::typedPromise()
|
|||||||
|
|
||||||
void tst_deprecations_helpers_qpromise::voidPromise()
|
void tst_deprecations_helpers_qpromise::voidPromise()
|
||||||
{
|
{
|
||||||
auto resolver = [](const QPromiseResolve<void>& resolve) {
|
auto resolver = [](const QtPromise::QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
QPromise<void> v0{resolver};
|
QtPromise::QPromise<void> v0{resolver};
|
||||||
const QPromise<void> v1 = v0;
|
const QtPromise::QPromise<void> v1 = v0;
|
||||||
|
|
||||||
auto p0 = qPromise(QPromise<void>{resolver});
|
auto p0 = QtPromise::qPromise(QtPromise::QPromise<void>{resolver});
|
||||||
auto p1 = qPromise(v0);
|
auto p1 = QtPromise::qPromise(v0);
|
||||||
auto p2 = qPromise(v1);
|
auto p2 = QtPromise::qPromise(v1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<void>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<void>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
for (const auto& promise : {p0, p1, p2}) {
|
for (const auto& promise : {p0, p1, p2}) {
|
||||||
QCOMPARE(promise.isPending(), true);
|
QCOMPARE(promise.isPending(), true);
|
||||||
@ -234,13 +236,13 @@ void tst_deprecations_helpers_qpromise::typedFuture()
|
|||||||
QFuture<int> v0 = QtConcurrent::run(fn);
|
QFuture<int> v0 = QtConcurrent::run(fn);
|
||||||
const QFuture<int> v1 = v0;
|
const QFuture<int> v1 = v0;
|
||||||
|
|
||||||
auto p0 = qPromise(QtConcurrent::run(fn));
|
auto p0 = QtPromise::qPromise(QtConcurrent::run(fn));
|
||||||
auto p1 = qPromise(v0);
|
auto p1 = QtPromise::qPromise(v0);
|
||||||
auto p2 = qPromise(v1);
|
auto p2 = QtPromise::qPromise(v1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
for (const auto& promise : {p0, p1, p2}) {
|
for (const auto& promise : {p0, p1, p2}) {
|
||||||
QCOMPARE(promise.isPending(), true);
|
QCOMPARE(promise.isPending(), true);
|
||||||
@ -256,13 +258,13 @@ void tst_deprecations_helpers_qpromise::voidFuture()
|
|||||||
QFuture<void> v0 = QtConcurrent::run(fn);
|
QFuture<void> v0 = QtConcurrent::run(fn);
|
||||||
const QFuture<void> v1 = v0;
|
const QFuture<void> v1 = v0;
|
||||||
|
|
||||||
auto p0 = qPromise(QtConcurrent::run(fn));
|
auto p0 = QtPromise::qPromise(QtConcurrent::run(fn));
|
||||||
auto p1 = qPromise(v0);
|
auto p1 = QtPromise::qPromise(v0);
|
||||||
auto p2 = qPromise(v1);
|
auto p2 = QtPromise::qPromise(v1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<void>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<void>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
for (const auto& promise : {p0, p1, p2}) {
|
for (const auto& promise : {p0, p1, p2}) {
|
||||||
QCOMPARE(promise.isPending(), true);
|
QCOMPARE(promise.isPending(), true);
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_deprecations_helpers_qpromiseall : public QObject
|
class tst_deprecations_helpers_qpromiseall : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -36,7 +34,7 @@ namespace {
|
|||||||
template<class Sequence>
|
template<class Sequence>
|
||||||
struct SequenceTester
|
struct SequenceTester
|
||||||
{
|
{
|
||||||
Q_STATIC_ASSERT((std::is_same<typename Sequence::value_type, QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<typename Sequence::value_type, QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
static void exec()
|
static void exec()
|
||||||
{
|
{
|
||||||
@ -48,20 +46,20 @@ struct SequenceTester
|
|||||||
|
|
||||||
auto p = qPromiseAll(promises);
|
auto p = qPromiseAll(promises);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 46, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 46, 43, 44}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<template<typename, typename...> class Sequence, typename... Args>
|
template<template<typename, typename...> class Sequence, typename... Args>
|
||||||
struct SequenceTester<Sequence<QPromise<void>, Args...>>
|
struct SequenceTester<Sequence<QtPromise::QPromise<void>, Args...>>
|
||||||
{
|
{
|
||||||
static void exec()
|
static void exec()
|
||||||
{
|
{
|
||||||
Sequence<QPromise<void>, Args...> promises{QtPromise::resolve(),
|
Sequence<QtPromise::QPromise<void>, Args...> promises{QtPromise::resolve(),
|
||||||
QtPromise::resolve(),
|
QtPromise::resolve(),
|
||||||
QtPromise::resolve()};
|
QtPromise::resolve()};
|
||||||
|
|
||||||
promises.push_back(QtPromise::resolve());
|
promises.push_back(QtPromise::resolve());
|
||||||
promises.insert(++promises.begin(), QtPromise::resolve());
|
promises.insert(++promises.begin(), QtPromise::resolve());
|
||||||
@ -69,7 +67,7 @@ struct SequenceTester<Sequence<QPromise<void>, Args...>>
|
|||||||
|
|
||||||
auto p = qPromiseAll(promises);
|
auto p = qPromiseAll(promises);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
}
|
}
|
||||||
@ -79,18 +77,18 @@ struct SequenceTester<Sequence<QPromise<void>, Args...>>
|
|||||||
|
|
||||||
void tst_deprecations_helpers_qpromiseall::emptySequence()
|
void tst_deprecations_helpers_qpromiseall::emptySequence()
|
||||||
{
|
{
|
||||||
auto p = qPromiseAll(QVector<QPromise<int>>());
|
auto p = qPromiseAll(QVector<QtPromise::QPromise<int>>());
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_deprecations_helpers_qpromiseall::emptySequence_void()
|
void tst_deprecations_helpers_qpromiseall::emptySequence_void()
|
||||||
{
|
{
|
||||||
auto p = qPromiseAll(QVector<QPromise<void>>());
|
auto p = qPromiseAll(QVector<QtPromise::QPromise<void>>());
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
}
|
}
|
||||||
@ -99,15 +97,15 @@ void tst_deprecations_helpers_qpromiseall::allPromisesSucceed()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve(42);
|
auto p0 = QtPromise::resolve(42);
|
||||||
auto p1 = QtPromise::resolve(44);
|
auto p1 = QtPromise::resolve(44);
|
||||||
auto p2 = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
auto p2 = QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(43);
|
resolve(43);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
|
|
||||||
auto p = qPromiseAll(QVector<QPromise<int>>{p0, p2, p1});
|
auto p = QtPromise::qPromiseAll(QVector<QtPromise::QPromise<int>>{p0, p2, p1});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
@ -120,15 +118,15 @@ void tst_deprecations_helpers_qpromiseall::allPromisesSucceed_void()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve();
|
auto p0 = QtPromise::resolve();
|
||||||
auto p1 = QtPromise::resolve();
|
auto p1 = QtPromise::resolve();
|
||||||
auto p2 = QPromise<void>{[](const QPromiseResolve<void>& resolve) {
|
auto p2 = QtPromise::QPromise<void>{[](const QtPromise::QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
|
|
||||||
auto p = qPromiseAll(QVector<QPromise<void>>{p0, p2, p1});
|
auto p = QtPromise::qPromiseAll(QVector<QtPromise::QPromise<void>>{p0, p2, p1});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
@ -141,15 +139,16 @@ void tst_deprecations_helpers_qpromiseall::atLeastOnePromiseReject()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve(42);
|
auto p0 = QtPromise::resolve(42);
|
||||||
auto p1 = QtPromise::resolve(44);
|
auto p1 = QtPromise::resolve(44);
|
||||||
auto p2 = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
auto p2 = QtPromise::QPromise<int>{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<int>&, const QtPromise::QPromiseReject<int>& reject) {
|
||||||
reject(QString{"foo"});
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p = qPromiseAll(QVector<QPromise<int>>{p0, p2, p1});
|
auto p = QtPromise::qPromiseAll(QVector<QtPromise::QPromise<int>>{p0, p2, p1});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
@ -162,15 +161,16 @@ void tst_deprecations_helpers_qpromiseall::atLeastOnePromiseReject_void()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve();
|
auto p0 = QtPromise::resolve();
|
||||||
auto p1 = QtPromise::resolve();
|
auto p1 = QtPromise::resolve();
|
||||||
auto p2 = QPromise<void>{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
auto p2 = QtPromise::QPromise<void>{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<void>&, const QtPromise::QPromiseReject<void>& reject) {
|
||||||
reject(QString{"foo"});
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p = qPromiseAll(QVector<QPromise<void>>{p0, p2, p1});
|
auto p = QtPromise::qPromiseAll(QVector<QtPromise::QPromise<void>>{p0, p2, p1});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
@ -185,9 +185,9 @@ void tst_deprecations_helpers_qpromiseall::preserveOrder()
|
|||||||
auto p1 = QtPromise::resolve(43).delay(100);
|
auto p1 = QtPromise::resolve(43).delay(100);
|
||||||
auto p2 = QtPromise::resolve(44).delay(250);
|
auto p2 = QtPromise::resolve(44).delay(250);
|
||||||
|
|
||||||
auto p = qPromiseAll(QVector<QPromise<int>>{p0, p1, p2});
|
auto p = QtPromise::qPromiseAll(QVector<QtPromise::QPromise<int>>{p0, p1, p2});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
@ -203,16 +203,16 @@ void tst_deprecations_helpers_qpromiseall::preserveOrder()
|
|||||||
|
|
||||||
void tst_deprecations_helpers_qpromiseall::sequenceTypes()
|
void tst_deprecations_helpers_qpromiseall::sequenceTypes()
|
||||||
{
|
{
|
||||||
SequenceTester<QList<QPromise<int>>>::exec();
|
SequenceTester<QList<QtPromise::QPromise<int>>>::exec();
|
||||||
// SequenceTester<QVector<QPromise<int>>>::exec();
|
// SequenceTester<QVector<QtPromise::QPromise<int>>>::exec();
|
||||||
SequenceTester<std::list<QPromise<int>>>::exec();
|
SequenceTester<std::list<QtPromise::QPromise<int>>>::exec();
|
||||||
SequenceTester<std::vector<QPromise<int>>>::exec();
|
SequenceTester<std::vector<QtPromise::QPromise<int>>>::exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_deprecations_helpers_qpromiseall::sequenceTypes_void()
|
void tst_deprecations_helpers_qpromiseall::sequenceTypes_void()
|
||||||
{
|
{
|
||||||
SequenceTester<QList<QPromise<void>>>::exec();
|
SequenceTester<QList<QtPromise::QPromise<void>>>::exec();
|
||||||
// SequenceTester<QVector<QPromise<void>>>::exec();
|
// SequenceTester<QVector<QtPromise::QPromise<void>>>::exec();
|
||||||
SequenceTester<std::list<QPromise<void>>>::exec();
|
SequenceTester<std::list<QtPromise::QPromise<void>>>::exec();
|
||||||
SequenceTester<std::vector<QPromise<void>>>::exec();
|
SequenceTester<std::vector<QtPromise::QPromise<void>>>::exec();
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_deprecations_qpromise_all : public QObject
|
class tst_deprecations_qpromise_all : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -36,7 +34,7 @@ namespace {
|
|||||||
template<class Sequence>
|
template<class Sequence>
|
||||||
struct SequenceTester
|
struct SequenceTester
|
||||||
{
|
{
|
||||||
Q_STATIC_ASSERT((std::is_same<typename Sequence::value_type, QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<typename Sequence::value_type, QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
static void exec()
|
static void exec()
|
||||||
{
|
{
|
||||||
@ -46,9 +44,9 @@ struct SequenceTester
|
|||||||
promises.insert(++promises.begin(), QtPromise::resolve(46));
|
promises.insert(++promises.begin(), QtPromise::resolve(46));
|
||||||
promises.pop_back();
|
promises.pop_back();
|
||||||
|
|
||||||
auto p = QPromise<int>::all(promises);
|
auto p = QtPromise::QPromise<int>::all(promises);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 46, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 46, 43, 44}));
|
||||||
@ -56,21 +54,21 @@ struct SequenceTester
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<template<typename, typename...> class Sequence, typename... Args>
|
template<template<typename, typename...> class Sequence, typename... Args>
|
||||||
struct SequenceTester<Sequence<QPromise<void>, Args...>>
|
struct SequenceTester<Sequence<QtPromise::QPromise<void>, Args...>>
|
||||||
{
|
{
|
||||||
static void exec()
|
static void exec()
|
||||||
{
|
{
|
||||||
Sequence<QPromise<void>, Args...> promises{QtPromise::resolve(),
|
Sequence<QtPromise::QPromise<void>, Args...> promises{QtPromise::resolve(),
|
||||||
QtPromise::resolve(),
|
QtPromise::resolve(),
|
||||||
QtPromise::resolve()};
|
QtPromise::resolve()};
|
||||||
|
|
||||||
promises.push_back(QtPromise::resolve());
|
promises.push_back(QtPromise::resolve());
|
||||||
promises.insert(++promises.begin(), QtPromise::resolve());
|
promises.insert(++promises.begin(), QtPromise::resolve());
|
||||||
promises.pop_back();
|
promises.pop_back();
|
||||||
|
|
||||||
auto p = QPromise<void>::all(promises);
|
auto p = QtPromise::QPromise<void>::all(promises);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
@ -81,9 +79,9 @@ struct SequenceTester<Sequence<QPromise<void>, Args...>>
|
|||||||
|
|
||||||
void tst_deprecations_qpromise_all::emptySequence()
|
void tst_deprecations_qpromise_all::emptySequence()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::all(QVector<QPromise<int>>{});
|
auto p = QtPromise::QPromise<int>::all(QVector<QtPromise::QPromise<int>>{});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
@ -91,9 +89,9 @@ void tst_deprecations_qpromise_all::emptySequence()
|
|||||||
|
|
||||||
void tst_deprecations_qpromise_all::emptySequence_void()
|
void tst_deprecations_qpromise_all::emptySequence_void()
|
||||||
{
|
{
|
||||||
auto p = QPromise<void>::all(QVector<QPromise<void>>{});
|
auto p = QtPromise::QPromise<void>::all(QVector<QtPromise::QPromise<void>>{});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
@ -103,15 +101,15 @@ void tst_deprecations_qpromise_all::allPromisesSucceed()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve(42);
|
auto p0 = QtPromise::resolve(42);
|
||||||
auto p1 = QtPromise::resolve(44);
|
auto p1 = QtPromise::resolve(44);
|
||||||
auto p2 = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
auto p2 = QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(43);
|
resolve(43);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
|
|
||||||
auto p = QPromise<int>::all(QVector<QPromise<int>>{p0, p2, p1});
|
auto p = QtPromise::QPromise<int>::all(QVector<QtPromise::QPromise<int>>{p0, p2, p1});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
@ -125,15 +123,15 @@ void tst_deprecations_qpromise_all::allPromisesSucceed_void()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve();
|
auto p0 = QtPromise::resolve();
|
||||||
auto p1 = QtPromise::resolve();
|
auto p1 = QtPromise::resolve();
|
||||||
auto p2 = QPromise<void>{[](const QPromiseResolve<void>& resolve) {
|
auto p2 = QtPromise::QPromise<void>{[](const QtPromise::QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
|
|
||||||
auto p = QPromise<void>::all(QVector<QPromise<void>>{p0, p2, p1});
|
auto p = QtPromise::QPromise<void>::all(QVector<QtPromise::QPromise<void>>{p0, p2, p1});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
@ -147,15 +145,16 @@ void tst_deprecations_qpromise_all::atLeastOnePromiseReject()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve(42);
|
auto p0 = QtPromise::resolve(42);
|
||||||
auto p1 = QtPromise::resolve(44);
|
auto p1 = QtPromise::resolve(44);
|
||||||
auto p2 = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
auto p2 = QtPromise::QPromise<int>{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<int>&, const QtPromise::QPromiseReject<int>& reject) {
|
||||||
reject(QString{"foo"});
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p = QPromise<int>::all(QVector<QPromise<int>>{p0, p2, p1});
|
auto p = QtPromise::QPromise<int>::all(QVector<QtPromise::QPromise<int>>{p0, p2, p1});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
@ -169,15 +168,16 @@ void tst_deprecations_qpromise_all::atLeastOnePromiseReject_void()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve();
|
auto p0 = QtPromise::resolve();
|
||||||
auto p1 = QtPromise::resolve();
|
auto p1 = QtPromise::resolve();
|
||||||
auto p2 = QPromise<void>{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
auto p2 = QtPromise::QPromise<void>{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<void>&, const QtPromise::QPromiseReject<void>& reject) {
|
||||||
reject(QString{"foo"});
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p = QPromise<void>::all(QVector<QPromise<void>>{p0, p2, p1});
|
auto p = QtPromise::QPromise<void>::all(QVector<QtPromise::QPromise<void>>{p0, p2, p1});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
@ -193,9 +193,9 @@ void tst_deprecations_qpromise_all::preserveOrder()
|
|||||||
auto p1 = QtPromise::resolve(43).delay(100);
|
auto p1 = QtPromise::resolve(43).delay(100);
|
||||||
auto p2 = QtPromise::resolve(44).delay(250);
|
auto p2 = QtPromise::resolve(44).delay(250);
|
||||||
|
|
||||||
auto p = QPromise<int>::all(QVector<QPromise<int>>{p0, p1, p2});
|
auto p = QtPromise::QPromise<int>::all(QVector<QtPromise::QPromise<int>>{p0, p1, p2});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
@ -212,16 +212,16 @@ void tst_deprecations_qpromise_all::preserveOrder()
|
|||||||
|
|
||||||
void tst_deprecations_qpromise_all::sequenceTypes()
|
void tst_deprecations_qpromise_all::sequenceTypes()
|
||||||
{
|
{
|
||||||
SequenceTester<QList<QPromise<int>>>::exec();
|
SequenceTester<QList<QtPromise::QPromise<int>>>::exec();
|
||||||
// SequenceTester<QVector<QPromise<int>>>::exec();
|
// SequenceTester<QVector<QtPromise::QPromise<int>>>::exec();
|
||||||
SequenceTester<std::list<QPromise<int>>>::exec();
|
SequenceTester<std::list<QtPromise::QPromise<int>>>::exec();
|
||||||
SequenceTester<std::vector<QPromise<int>>>::exec();
|
SequenceTester<std::vector<QtPromise::QPromise<int>>>::exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_deprecations_qpromise_all::sequenceTypes_void()
|
void tst_deprecations_qpromise_all::sequenceTypes_void()
|
||||||
{
|
{
|
||||||
SequenceTester<QList<QPromise<void>>>::exec();
|
SequenceTester<QList<QtPromise::QPromise<void>>>::exec();
|
||||||
// SequenceTester<QVector<QPromise<void>>>::exec();
|
// SequenceTester<QVector<QtPromise::QPromise<void>>>::exec();
|
||||||
SequenceTester<std::list<QPromise<void>>>::exec();
|
SequenceTester<std::list<QtPromise::QPromise<void>>>::exec();
|
||||||
SequenceTester<std::vector<QPromise<void>>>::exec();
|
SequenceTester<std::vector<QtPromise::QPromise<void>>>::exec();
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_exceptions : public QObject
|
class tst_exceptions : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -20,6 +18,7 @@ class tst_exceptions : public QObject
|
|||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void canceled();
|
void canceled();
|
||||||
void context();
|
void context();
|
||||||
|
void conversion();
|
||||||
void timeout();
|
void timeout();
|
||||||
void undefined();
|
void undefined();
|
||||||
|
|
||||||
@ -45,20 +44,25 @@ void verify()
|
|||||||
|
|
||||||
void tst_exceptions::canceled()
|
void tst_exceptions::canceled()
|
||||||
{
|
{
|
||||||
verify<QPromiseCanceledException>();
|
verify<QtPromise::QPromiseCanceledException>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_exceptions::context()
|
void tst_exceptions::context()
|
||||||
{
|
{
|
||||||
verify<QPromiseContextException>();
|
verify<QtPromise::QPromiseContextException>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_exceptions::conversion()
|
||||||
|
{
|
||||||
|
verify<QtPromise::QPromiseConversionException>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_exceptions::timeout()
|
void tst_exceptions::timeout()
|
||||||
{
|
{
|
||||||
verify<QPromiseTimeoutException>();
|
verify<QtPromise::QPromiseTimeoutException>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_exceptions::undefined()
|
void tst_exceptions::undefined()
|
||||||
{
|
{
|
||||||
verify<QPromiseUndefinedException>();
|
verify<QtPromise::QPromiseUndefinedException>();
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_future : public QObject
|
class tst_future : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -58,7 +56,7 @@ void tst_future::fulfilled()
|
|||||||
return 42;
|
return 42;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
|
|
||||||
p.then([&](int res) {
|
p.then([&](int res) {
|
||||||
@ -74,7 +72,7 @@ void tst_future::fulfilled_void()
|
|||||||
int result = -1;
|
int result = -1;
|
||||||
auto p = QtPromise::resolve(QtConcurrent::run([]() {}));
|
auto p = QtPromise::resolve(QtConcurrent::run([]() {}));
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
|
|
||||||
p.then([&]() {
|
p.then([&]() {
|
||||||
@ -93,7 +91,7 @@ void tst_future::rejected()
|
|||||||
return 42;
|
return 42;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
|
|
||||||
p.fail([&](const MyException& e) {
|
p.fail([&](const MyException& e) {
|
||||||
@ -112,7 +110,7 @@ void tst_future::rejected_void()
|
|||||||
throw MyException{"foo"};
|
throw MyException{"foo"};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
|
|
||||||
@ -132,7 +130,7 @@ void tst_future::unhandled()
|
|||||||
return 42;
|
return 42;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
|
|
||||||
@ -157,7 +155,7 @@ void tst_future::unhandled_void()
|
|||||||
throw QString{"foo"};
|
throw QString{"foo"};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
|
|
||||||
p.fail([&](const QString& err) {
|
p.fail([&](const QString& err) {
|
||||||
@ -179,7 +177,7 @@ void tst_future::canceled()
|
|||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
|
|
||||||
p.fail([&](const QPromiseCanceledException&) {
|
p.fail([&](const QtPromise::QPromiseCanceledException&) {
|
||||||
error = "canceled";
|
error = "canceled";
|
||||||
return -1;
|
return -1;
|
||||||
}).wait();
|
}).wait();
|
||||||
@ -195,7 +193,7 @@ void tst_future::canceled_void()
|
|||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
|
|
||||||
p.fail([&](const QPromiseCanceledException&) {
|
p.fail([&](const QtPromise::QPromiseCanceledException&) {
|
||||||
error = "canceled";
|
error = "canceled";
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
@ -207,12 +205,12 @@ void tst_future::canceledFromThread()
|
|||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
auto p = QtPromise::resolve(QtConcurrent::run([]() {
|
auto p = QtPromise::resolve(QtConcurrent::run([]() {
|
||||||
throw QPromiseCanceledException{};
|
throw QtPromise::QPromiseCanceledException{};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
|
|
||||||
p.fail([&](const QPromiseCanceledException&) {
|
p.fail([&](const QtPromise::QPromiseCanceledException&) {
|
||||||
error = "bar";
|
error = "bar";
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
@ -269,7 +267,7 @@ void tst_future::then_void()
|
|||||||
void tst_future::fail()
|
void tst_future::fail()
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
auto input = QPromise<QString>::reject(MyException{"bar"});
|
auto input = QtPromise::QPromise<QString>::reject(MyException{"bar"});
|
||||||
auto output = input.fail([](const MyException& e) {
|
auto output = input.fail([](const MyException& e) {
|
||||||
return QtConcurrent::run(
|
return QtConcurrent::run(
|
||||||
[](const QString& error) {
|
[](const QString& error) {
|
||||||
@ -294,7 +292,7 @@ void tst_future::fail()
|
|||||||
void tst_future::fail_void()
|
void tst_future::fail_void()
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
auto input = QPromise<void>::reject(MyException{"bar"});
|
auto input = QtPromise::QPromise<void>::reject(MyException{"bar"});
|
||||||
auto output = input.fail([&](const MyException& e) {
|
auto output = input.fail([&](const MyException& e) {
|
||||||
return QtConcurrent::run(
|
return QtConcurrent::run(
|
||||||
[&](const QString& error) {
|
[&](const QString& error) {
|
||||||
@ -325,7 +323,7 @@ void tst_future::finally()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(output), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(output), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(input.isFulfilled(), true);
|
QCOMPARE(input.isFulfilled(), true);
|
||||||
QCOMPARE(output.isPending(), true);
|
QCOMPARE(output.isPending(), true);
|
||||||
@ -350,7 +348,7 @@ void tst_future::finallyRejected()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(output), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(output), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(input.isFulfilled(), true);
|
QCOMPARE(input.isFulfilled(), true);
|
||||||
QCOMPARE(output.isPending(), true);
|
QCOMPARE(output.isPending(), true);
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_helpers_all : public QObject
|
class tst_helpers_all : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -36,7 +34,7 @@ namespace {
|
|||||||
template<class Sequence>
|
template<class Sequence>
|
||||||
struct SequenceTester
|
struct SequenceTester
|
||||||
{
|
{
|
||||||
Q_STATIC_ASSERT((std::is_same<typename Sequence::value_type, QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<typename Sequence::value_type, QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
static void exec()
|
static void exec()
|
||||||
{
|
{
|
||||||
@ -48,20 +46,20 @@ struct SequenceTester
|
|||||||
|
|
||||||
auto p = QtPromise::all(promises);
|
auto p = QtPromise::all(promises);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 46, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 46, 43, 44}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<template<typename, typename...> class Sequence, typename... Args>
|
template<template<typename, typename...> class Sequence, typename... Args>
|
||||||
struct SequenceTester<Sequence<QPromise<void>, Args...>>
|
struct SequenceTester<Sequence<QtPromise::QPromise<void>, Args...>>
|
||||||
{
|
{
|
||||||
static void exec()
|
static void exec()
|
||||||
{
|
{
|
||||||
Sequence<QPromise<void>, Args...> promises{QtPromise::resolve(),
|
Sequence<QtPromise::QPromise<void>, Args...> promises{QtPromise::resolve(),
|
||||||
QtPromise::resolve(),
|
QtPromise::resolve(),
|
||||||
QtPromise::resolve()};
|
QtPromise::resolve()};
|
||||||
|
|
||||||
promises.push_back(QtPromise::resolve());
|
promises.push_back(QtPromise::resolve());
|
||||||
promises.insert(++promises.begin(), QtPromise::resolve());
|
promises.insert(++promises.begin(), QtPromise::resolve());
|
||||||
@ -69,7 +67,7 @@ struct SequenceTester<Sequence<QPromise<void>, Args...>>
|
|||||||
|
|
||||||
auto p = QtPromise::all(promises);
|
auto p = QtPromise::all(promises);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
}
|
}
|
||||||
@ -79,18 +77,18 @@ struct SequenceTester<Sequence<QPromise<void>, Args...>>
|
|||||||
|
|
||||||
void tst_helpers_all::emptySequence()
|
void tst_helpers_all::emptySequence()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::all(QVector<QPromise<int>>());
|
auto p = QtPromise::all(QVector<QtPromise::QPromise<int>>());
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_all::emptySequence_void()
|
void tst_helpers_all::emptySequence_void()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::all(QVector<QPromise<void>>());
|
auto p = QtPromise::all(QVector<QtPromise::QPromise<void>>());
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
}
|
}
|
||||||
@ -99,15 +97,15 @@ void tst_helpers_all::allPromisesSucceed()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve(42);
|
auto p0 = QtPromise::resolve(42);
|
||||||
auto p1 = QtPromise::resolve(44);
|
auto p1 = QtPromise::resolve(44);
|
||||||
auto p2 = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
auto p2 = QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(43);
|
resolve(43);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
|
|
||||||
auto p = QtPromise::all(QVector<QPromise<int>>{p0, p2, p1});
|
auto p = QtPromise::all(QVector<QtPromise::QPromise<int>>{p0, p2, p1});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
@ -120,15 +118,15 @@ void tst_helpers_all::allPromisesSucceed_void()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve();
|
auto p0 = QtPromise::resolve();
|
||||||
auto p1 = QtPromise::resolve();
|
auto p1 = QtPromise::resolve();
|
||||||
auto p2 = QPromise<void>{[](const QPromiseResolve<void>& resolve) {
|
auto p2 = QtPromise::QPromise<void>{[](const QtPromise::QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
|
|
||||||
auto p = QtPromise::all(QVector<QPromise<void>>{p0, p2, p1});
|
auto p = QtPromise::all(QVector<QtPromise::QPromise<void>>{p0, p2, p1});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
@ -141,15 +139,16 @@ void tst_helpers_all::atLeastOnePromiseReject()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve(42);
|
auto p0 = QtPromise::resolve(42);
|
||||||
auto p1 = QtPromise::resolve(44);
|
auto p1 = QtPromise::resolve(44);
|
||||||
auto p2 = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
auto p2 = QtPromise::QPromise<int>{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<int>&, const QtPromise::QPromiseReject<int>& reject) {
|
||||||
reject(QString{"foo"});
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p = QtPromise::all(QVector<QPromise<int>>{p0, p2, p1});
|
auto p = QtPromise::all(QVector<QtPromise::QPromise<int>>{p0, p2, p1});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
@ -162,15 +161,16 @@ void tst_helpers_all::atLeastOnePromiseReject_void()
|
|||||||
{
|
{
|
||||||
auto p0 = QtPromise::resolve();
|
auto p0 = QtPromise::resolve();
|
||||||
auto p1 = QtPromise::resolve();
|
auto p1 = QtPromise::resolve();
|
||||||
auto p2 = QPromise<void>{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
auto p2 = QtPromise::QPromise<void>{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<void>&, const QtPromise::QPromiseReject<void>& reject) {
|
||||||
reject(QString{"foo"});
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p = QtPromise::all(QVector<QPromise<void>>{p0, p2, p1});
|
auto p = QtPromise::all(QVector<QtPromise::QPromise<void>>{p0, p2, p1});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(p1.isFulfilled(), true);
|
QCOMPARE(p1.isFulfilled(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
@ -185,9 +185,9 @@ void tst_helpers_all::preserveOrder()
|
|||||||
auto p1 = QtPromise::resolve(43).delay(100);
|
auto p1 = QtPromise::resolve(43).delay(100);
|
||||||
auto p2 = QtPromise::resolve(44).delay(250);
|
auto p2 = QtPromise::resolve(44).delay(250);
|
||||||
|
|
||||||
auto p = QtPromise::all(QVector<QPromise<int>>{p0, p1, p2});
|
auto p = QtPromise::all(QVector<QtPromise::QPromise<int>>{p0, p1, p2});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
QCOMPARE(p2.isPending(), true);
|
QCOMPARE(p2.isPending(), true);
|
||||||
@ -203,16 +203,16 @@ void tst_helpers_all::preserveOrder()
|
|||||||
|
|
||||||
void tst_helpers_all::sequenceTypes()
|
void tst_helpers_all::sequenceTypes()
|
||||||
{
|
{
|
||||||
SequenceTester<QList<QPromise<int>>>::exec();
|
SequenceTester<QList<QtPromise::QPromise<int>>>::exec();
|
||||||
// SequenceTester<QVector<QPromise<int>>>::exec();
|
// SequenceTester<QVector<QPromise<int>>>::exec();
|
||||||
SequenceTester<std::list<QPromise<int>>>::exec();
|
SequenceTester<std::list<QtPromise::QPromise<int>>>::exec();
|
||||||
SequenceTester<std::vector<QPromise<int>>>::exec();
|
SequenceTester<std::vector<QtPromise::QPromise<int>>>::exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_all::sequenceTypes_void()
|
void tst_helpers_all::sequenceTypes_void()
|
||||||
{
|
{
|
||||||
SequenceTester<QList<QPromise<void>>>::exec();
|
SequenceTester<QList<QtPromise::QPromise<void>>>::exec();
|
||||||
// SequenceTester<QVector<QPromise<void>>>::exec();
|
// SequenceTester<QVector<QPromise<void>>>::exec();
|
||||||
SequenceTester<std::list<QPromise<void>>>::exec();
|
SequenceTester<std::list<QtPromise::QPromise<void>>>::exec();
|
||||||
SequenceTester<std::vector<QPromise<void>>>::exec();
|
SequenceTester<std::vector<QtPromise::QPromise<void>>>::exec();
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_helpers_attempt : public QObject
|
class tst_helpers_attempt : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -35,7 +33,7 @@ void tst_helpers_attempt::voidResult()
|
|||||||
{
|
{
|
||||||
auto p = QtPromise::attempt([]() {});
|
auto p = QtPromise::attempt([]() {});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
}
|
}
|
||||||
@ -46,7 +44,7 @@ void tst_helpers_attempt::typedResult()
|
|||||||
return QString{"foo"};
|
return QString{"foo"};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QString>>::value));
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
@ -59,7 +57,7 @@ void tst_helpers_attempt::futureResult()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QString>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
@ -70,7 +68,7 @@ void tst_helpers_attempt::promiseResult()
|
|||||||
return QtPromise::resolve(42).delay(200);
|
return QtPromise::resolve(42).delay(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), 42);
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
}
|
}
|
||||||
@ -84,7 +82,7 @@ void tst_helpers_attempt::functorThrows()
|
|||||||
return 42;
|
return 42;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
}
|
}
|
||||||
@ -98,7 +96,7 @@ void tst_helpers_attempt::callWithParams()
|
|||||||
42,
|
42,
|
||||||
"foo");
|
"foo");
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QString>>::value));
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, QString{}), QString{"42:foo"});
|
QCOMPARE(waitForValue(p, QString{}), QString{"42:foo"});
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_helpers_connect : public QObject
|
class tst_helpers_connect : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -47,7 +45,7 @@ void tst_helpers_connect::resolveOneSenderNoArg()
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto p = QtPromise::connect(&sender, &Object::noArgSignal);
|
auto p = QtPromise::connect(&sender, &Object::noArgSignal);
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(sender.hasConnections(), true);
|
QCOMPARE(sender.hasConnections(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
@ -62,7 +60,7 @@ void tst_helpers_connect::resolveOneSenderOneArg()
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto p = QtPromise::connect(&sender, &Object::oneArgSignal);
|
auto p = QtPromise::connect(&sender, &Object::oneArgSignal);
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QString>>::value));
|
||||||
QCOMPARE(sender.hasConnections(), true);
|
QCOMPARE(sender.hasConnections(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo"});
|
||||||
@ -77,7 +75,7 @@ void tst_helpers_connect::resolveOneSenderManyArgs()
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto p = QtPromise::connect(&sender, &Object::twoArgsSignal);
|
auto p = QtPromise::connect(&sender, &Object::twoArgsSignal);
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
QCOMPARE(sender.hasConnections(), true);
|
QCOMPARE(sender.hasConnections(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), 42);
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
@ -92,10 +90,10 @@ void tst_helpers_connect::rejectOneSenderNoArg()
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto p = QtPromise::connect(&sender, &Object::oneArgSignal, &Object::noArgSignal);
|
auto p = QtPromise::connect(&sender, &Object::oneArgSignal, &Object::noArgSignal);
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QString>>::value));
|
||||||
QCOMPARE(sender.hasConnections(), true);
|
QCOMPARE(sender.hasConnections(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForRejected<QPromiseUndefinedException>(p), true);
|
QCOMPARE(waitForRejected<QtPromise::QPromiseUndefinedException>(p), true);
|
||||||
QCOMPARE(sender.hasConnections(), false);
|
QCOMPARE(sender.hasConnections(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +105,7 @@ void tst_helpers_connect::rejectOneSenderOneArg()
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto p = QtPromise::connect(&sender, &Object::noArgSignal, &Object::oneArgSignal);
|
auto p = QtPromise::connect(&sender, &Object::noArgSignal, &Object::oneArgSignal);
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(sender.hasConnections(), true);
|
QCOMPARE(sender.hasConnections(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
@ -122,7 +120,7 @@ void tst_helpers_connect::rejectOneSenderManyArgs()
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto p = QtPromise::connect(&sender, &Object::noArgSignal, &Object::twoArgsSignal);
|
auto p = QtPromise::connect(&sender, &Object::noArgSignal, &Object::twoArgsSignal);
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(sender.hasConnections(), true);
|
QCOMPARE(sender.hasConnections(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, -1), 42);
|
QCOMPARE(waitForError(p, -1), 42);
|
||||||
@ -137,9 +135,9 @@ void tst_helpers_connect::rejectOneSenderDestroyed()
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto p = QtPromise::connect(sender, &Object::twoArgsSignal);
|
auto p = QtPromise::connect(sender, &Object::twoArgsSignal);
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForRejected<QPromiseContextException>(p), true);
|
QCOMPARE(waitForRejected<QtPromise::QPromiseContextException>(p), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_connect::rejectTwoSendersNoArg()
|
void tst_helpers_connect::rejectTwoSendersNoArg()
|
||||||
@ -150,11 +148,11 @@ void tst_helpers_connect::rejectTwoSendersNoArg()
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto p = QtPromise::connect(&s0, &Object::noArgSignal, &s1, &Object::noArgSignal);
|
auto p = QtPromise::connect(&s0, &Object::noArgSignal, &s1, &Object::noArgSignal);
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(s0.hasConnections(), true);
|
QCOMPARE(s0.hasConnections(), true);
|
||||||
QCOMPARE(s1.hasConnections(), true);
|
QCOMPARE(s1.hasConnections(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForRejected<QPromiseUndefinedException>(p), true);
|
QCOMPARE(waitForRejected<QtPromise::QPromiseUndefinedException>(p), true);
|
||||||
QCOMPARE(s0.hasConnections(), false);
|
QCOMPARE(s0.hasConnections(), false);
|
||||||
QCOMPARE(s1.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);
|
auto p = QtPromise::connect(&s0, &Object::noArgSignal, &s1, &Object::oneArgSignal);
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(s0.hasConnections(), true);
|
QCOMPARE(s0.hasConnections(), true);
|
||||||
QCOMPARE(s1.hasConnections(), true);
|
QCOMPARE(s1.hasConnections(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
@ -184,7 +182,7 @@ void tst_helpers_connect::rejectTwoSendersManyArgs()
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto p = QtPromise::connect(&s0, &Object::noArgSignal, &s1, &Object::twoArgsSignal);
|
auto p = QtPromise::connect(&s0, &Object::noArgSignal, &s1, &Object::twoArgsSignal);
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(s0.hasConnections(), true);
|
QCOMPARE(s0.hasConnections(), true);
|
||||||
QCOMPARE(s1.hasConnections(), true);
|
QCOMPARE(s1.hasConnections(), true);
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
@ -209,7 +207,7 @@ void tst_helpers_connect::rejectTwoSendersDestroyed()
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto p = QtPromise::connect(s0, &Object::noArgSignal, s1, &Object::twoArgsSignal);
|
auto p = QtPromise::connect(s0, &Object::noArgSignal, s1, &Object::twoArgsSignal);
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_helpers_each : public QObject
|
class tst_helpers_each : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -42,7 +40,7 @@ struct SequenceTester
|
|||||||
values << i << v;
|
values << i << v;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Sequence>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Sequence>>::value));
|
||||||
QCOMPARE(waitForValue(p, Sequence{}), (Sequence{42, 43, 44}));
|
QCOMPARE(waitForValue(p, Sequence{}), (Sequence{42, 43, 44}));
|
||||||
QCOMPARE(values, (QVector<int>{0, 42, 1, 43, 2, 44}));
|
QCOMPARE(values, (QVector<int>{0, 42, 1, 43, 2, 44}));
|
||||||
}
|
}
|
||||||
@ -57,7 +55,7 @@ void tst_helpers_each::emptySequence()
|
|||||||
values << v;
|
values << v;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
QCOMPARE(values, QVector<int>{});
|
QCOMPARE(values, QVector<int>{});
|
||||||
}
|
}
|
||||||
@ -69,7 +67,7 @@ void tst_helpers_each::preserveValues()
|
|||||||
values << v + 1;
|
values << v + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
@ -82,7 +80,7 @@ void tst_helpers_each::ignoreResult()
|
|||||||
return "Foo";
|
return "Foo";
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
@ -91,7 +89,7 @@ void tst_helpers_each::delayedFulfilled()
|
|||||||
{
|
{
|
||||||
QMap<int, int> values;
|
QMap<int, int> values;
|
||||||
auto p = QtPromise::each(QVector<int>{42, 43, 44}, [&](int v, int index) {
|
auto p = QtPromise::each(QVector<int>{42, 43, 44}, [&](int v, int index) {
|
||||||
return QPromise<int>{[&](const QPromiseResolve<int>& resolve) {
|
return QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values[v] = index;
|
values[v] = index;
|
||||||
resolve(42);
|
resolve(42);
|
||||||
@ -99,7 +97,7 @@ void tst_helpers_each::delayedFulfilled()
|
|||||||
}};
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
||||||
QCOMPARE(values, expected);
|
QCOMPARE(values, expected);
|
||||||
@ -108,18 +106,18 @@ void tst_helpers_each::delayedFulfilled()
|
|||||||
void tst_helpers_each::delayedRejected()
|
void tst_helpers_each::delayedRejected()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::each(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::each(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
return QPromise<int>{
|
return QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>& resolve,
|
||||||
[&](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
if (v == 43) {
|
if (v == 43) {
|
||||||
reject(QString{"foo"});
|
reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
resolve(v);
|
resolve(v);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +129,7 @@ void tst_helpers_each::functorThrows()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +140,7 @@ void tst_helpers_each::functorArguments()
|
|||||||
values << i << v;
|
values << i << v;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(values, (QVector<int>{0, 42, 1, 43, 2, 44}));
|
QCOMPARE(values, (QVector<int>{0, 42, 1, 43, 2, 44}));
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_helpers_filter : public QObject
|
class tst_helpers_filter : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -43,7 +41,7 @@ struct SequenceTester
|
|||||||
return v % 3 == 0;
|
return v % 3 == 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Sequence>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Sequence>>::value));
|
||||||
QCOMPARE(waitForValue(p, Sequence{}), (Sequence{42, 45, 48, 51}));
|
QCOMPARE(waitForValue(p, Sequence{}), (Sequence{42, 45, 48, 51}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -56,7 +54,7 @@ void tst_helpers_filter::emptySequence()
|
|||||||
return v % 2 == 0;
|
return v % 2 == 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,39 +64,39 @@ void tst_helpers_filter::filterValues()
|
|||||||
return v % 2 == 0;
|
return v % 2 == 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_filter::delayedFulfilled()
|
void tst_helpers_filter::delayedFulfilled()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::filter(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::filter(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
return QPromise<bool>{[&](const QPromiseResolve<bool>& resolve) {
|
return QtPromise::QPromise<bool>{[&](const QtPromise::QPromiseResolve<bool>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(v % 2 == 0);
|
resolve(v % 2 == 0);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_filter::delayedRejected()
|
void tst_helpers_filter::delayedRejected()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::filter(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::filter(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
return QPromise<bool>{
|
return QtPromise::QPromise<bool>{[&](const QtPromise::QPromiseResolve<bool>& resolve,
|
||||||
[&](const QPromiseResolve<bool>& resolve, const QPromiseReject<bool>& reject) {
|
const QtPromise::QPromiseReject<bool>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
if (v == 44) {
|
if (v == 44) {
|
||||||
reject(QString{"foo"});
|
reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +109,7 @@ void tst_helpers_filter::functorThrows()
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +121,7 @@ void tst_helpers_filter::functorArguments()
|
|||||||
return i % 2 == 0;
|
return i % 2 == 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
||||||
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
||||||
QCOMPARE(args, expected);
|
QCOMPARE(args, expected);
|
||||||
@ -132,10 +130,10 @@ void tst_helpers_filter::functorArguments()
|
|||||||
void tst_helpers_filter::preserveOrder()
|
void tst_helpers_filter::preserveOrder()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::filter(QVector<int>{500, 100, 300, 250, 400}, [](int v, ...) {
|
auto p = QtPromise::filter(QVector<int>{500, 100, 300, 250, 400}, [](int v, ...) {
|
||||||
return QPromise<bool>::resolve(v > 200).delay(v);
|
return QtPromise::QPromise<bool>::resolve(v > 200).delay(v);
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{500, 300, 250, 400}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{500, 300, 250, 400}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_helpers_map : public QObject
|
class tst_helpers_map : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -42,7 +40,7 @@ struct SequenceTester
|
|||||||
return QString::number(v + 1);
|
return QString::number(v + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<QString>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<QString>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<QString>{}), (QVector<QString>{"43", "44", "45"}));
|
QCOMPARE(waitForValue(p, QVector<QString>{}), (QVector<QString>{"43", "44", "45"}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -55,7 +53,7 @@ void tst_helpers_map::emptySequence()
|
|||||||
return v + 1;
|
return v + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +63,7 @@ void tst_helpers_map::modifyValues()
|
|||||||
return v + 1;
|
return v + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{43, 44, 45}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,39 +73,39 @@ void tst_helpers_map::convertValues()
|
|||||||
return QString::number(v + 1);
|
return QString::number(v + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<QString>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<QString>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<QString>{}), (QVector<QString>{"43", "44", "45"}));
|
QCOMPARE(waitForValue(p, QVector<QString>{}), (QVector<QString>{"43", "44", "45"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_map::delayedFulfilled()
|
void tst_helpers_map::delayedFulfilled()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::map(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::map(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
return QPromise<int>{[&](const QPromiseResolve<int>& resolve) {
|
return QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(v + 1);
|
resolve(v + 1);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{43, 44, 45}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_map::delayedRejected()
|
void tst_helpers_map::delayedRejected()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::map(QVector<int>{42, 43, 44}, [](int v, ...) {
|
auto p = QtPromise::map(QVector<int>{42, 43, 44}, [](int v, ...) {
|
||||||
return QPromise<int>{
|
return QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>& resolve,
|
||||||
[&](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
if (v == 43) {
|
if (v == 43) {
|
||||||
reject(QString{"foo"});
|
reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
resolve(v);
|
resolve(v);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +118,7 @@ void tst_helpers_map::functorThrows()
|
|||||||
return v + 1;
|
return v + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,17 +128,17 @@ void tst_helpers_map::functorArguments()
|
|||||||
return v * i;
|
return v * i;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{0, 42, 84}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{0, 42, 84}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_helpers_map::preserveOrder()
|
void tst_helpers_map::preserveOrder()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::map(QVector<int>{500, 100, 250}, [](int v, ...) {
|
auto p = QtPromise::map(QVector<int>{500, 100, 250}, [](int v, ...) {
|
||||||
return QPromise<int>::resolve(v + 1).delay(v);
|
return QtPromise::QPromise<int>::resolve(v + 1).delay(v);
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{501, 101, 251}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{501, 101, 251}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_helpers_reduce : public QObject
|
class tst_helpers_reduce : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -57,8 +55,8 @@ struct SequenceTester
|
|||||||
},
|
},
|
||||||
QtPromise::resolve(2).delay(100));
|
QtPromise::resolve(2).delay(100));
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.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!
|
// NOTE(SB): reduce() on an empty sequence without an initial value is an error!
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p, -1), 42);
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
QCOMPARE(called, false);
|
QCOMPARE(called, false);
|
||||||
@ -109,8 +107,8 @@ void tst_helpers_reduce::regularValues()
|
|||||||
},
|
},
|
||||||
2);
|
2);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
@ -122,9 +120,9 @@ void tst_helpers_reduce::regularValues()
|
|||||||
|
|
||||||
void tst_helpers_reduce::promiseValues()
|
void tst_helpers_reduce::promiseValues()
|
||||||
{
|
{
|
||||||
QVector<QPromise<int>> inputs{QtPromise::resolve(4).delay(400),
|
QVector<QtPromise::QPromise<int>> inputs{QtPromise::resolve(4).delay(400),
|
||||||
QtPromise::resolve(6).delay(300),
|
QtPromise::resolve(6).delay(300),
|
||||||
QtPromise::resolve(8).delay(200)};
|
QtPromise::resolve(8).delay(200)};
|
||||||
QVector<int> v0;
|
QVector<int> v0;
|
||||||
QVector<int> v1;
|
QVector<int> v1;
|
||||||
|
|
||||||
@ -140,8 +138,8 @@ void tst_helpers_reduce::promiseValues()
|
|||||||
},
|
},
|
||||||
2);
|
2);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.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.
|
// NOTE(SB): when no initial value is given, the result type is the sequence type.
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QString>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QString{}), QString{"foo:4:0:6:1:8:2"});
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo:4:0:6:1:8:2"});
|
||||||
@ -182,7 +180,7 @@ void tst_helpers_reduce::delayedInitialValue()
|
|||||||
},
|
},
|
||||||
QtPromise::resolve(2).delay(100));
|
QtPromise::resolve(2).delay(100));
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), 23);
|
QCOMPARE(waitForValue(p, -1), 23);
|
||||||
@ -207,8 +205,8 @@ void tst_helpers_reduce::delayedFulfilled()
|
|||||||
},
|
},
|
||||||
2);
|
2);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.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) {
|
auto p0 = QtPromise::reduce(inputs, [&](int acc, int cur, int idx) {
|
||||||
v0 << acc << cur << idx;
|
v0 << acc << cur << idx;
|
||||||
if (cur == 6) {
|
if (cur == 6) {
|
||||||
return QPromise<int>::reject(QString{"foo"});
|
return QtPromise::QPromise<int>::reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
return QtPromise::resolve(acc + cur + idx);
|
return QtPromise::resolve(acc + cur + idx);
|
||||||
});
|
});
|
||||||
@ -236,14 +234,14 @@ void tst_helpers_reduce::delayedRejected()
|
|||||||
[&](int acc, int cur, int idx) {
|
[&](int acc, int cur, int idx) {
|
||||||
v1 << acc << cur << idx;
|
v1 << acc << cur << idx;
|
||||||
if (cur == 6) {
|
if (cur == 6) {
|
||||||
return QPromise<int>::reject(QString{"bar"});
|
return QtPromise::QPromise<int>::reject(QString{"bar"});
|
||||||
}
|
}
|
||||||
return QtPromise::resolve(acc + cur + idx);
|
return QtPromise::resolve(acc + cur + idx);
|
||||||
},
|
},
|
||||||
2);
|
2);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
@ -277,8 +275,8 @@ void tst_helpers_reduce::functorThrows()
|
|||||||
},
|
},
|
||||||
2);
|
2);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
@ -292,10 +290,10 @@ void tst_helpers_reduce::sequenceTypes()
|
|||||||
{
|
{
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||||
// QLinkedList is deprecated since Qt 5.15.
|
// QLinkedList is deprecated since Qt 5.15.
|
||||||
SequenceTester<QLinkedList<QPromise<int>>>::exec();
|
SequenceTester<QLinkedList<QtPromise::QPromise<int>>>::exec();
|
||||||
#endif
|
#endif
|
||||||
SequenceTester<QList<QPromise<int>>>::exec();
|
SequenceTester<QList<QtPromise::QPromise<int>>>::exec();
|
||||||
SequenceTester<QVector<QPromise<int>>>::exec();
|
SequenceTester<QVector<QtPromise::QPromise<int>>>::exec();
|
||||||
SequenceTester<std::list<QPromise<int>>>::exec();
|
SequenceTester<std::list<QtPromise::QPromise<int>>>::exec();
|
||||||
SequenceTester<std::vector<QPromise<int>>>::exec();
|
SequenceTester<std::vector<QtPromise::QPromise<int>>>::exec();
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_helpers_reject : public QObject
|
class tst_helpers_reject : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -29,7 +27,7 @@ QTEST_MAIN(tst_helpers_reject)
|
|||||||
|
|
||||||
void tst_helpers_reject::rejectWithValue()
|
void tst_helpers_reject::rejectWithValue()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::reject(42);
|
auto p = QtPromise::QPromise<int>::reject(42);
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForError(p, -1), 42);
|
QCOMPARE(waitForError(p, -1), 42);
|
||||||
@ -42,7 +40,7 @@ void tst_helpers_reject::rejectWithQSharedPtr()
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto sptr = QSharedPointer<int>::create(42);
|
auto sptr = QSharedPointer<int>::create(42);
|
||||||
auto p = QPromise<int>::reject(sptr);
|
auto p = QtPromise::QPromise<int>::reject(sptr);
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QSharedPointer<int>{}), sptr);
|
QCOMPARE(waitForError(p, QSharedPointer<int>{}), sptr);
|
||||||
|
|
||||||
@ -62,7 +60,7 @@ void tst_helpers_reject::rejectWithStdSharedPtr()
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto sptr = std::make_shared<int>(42);
|
auto sptr = std::make_shared<int>(42);
|
||||||
auto p = QPromise<int>::reject(sptr);
|
auto p = QtPromise::QPromise<int>::reject(sptr);
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, std::shared_ptr<int>{}), sptr);
|
QCOMPARE(waitForError(p, std::shared_ptr<int>{}), sptr);
|
||||||
|
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_helpers_resolve : public QObject
|
class tst_helpers_resolve : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -45,9 +43,9 @@ void tst_helpers_resolve::value()
|
|||||||
auto p1 = QtPromise::resolve(v0);
|
auto p1 = QtPromise::resolve(v0);
|
||||||
auto p2 = QtPromise::resolve(v1);
|
auto p2 = QtPromise::resolve(v1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
for (const auto& p : {p0, p1, p2}) {
|
for (const auto& p : {p0, p1, p2}) {
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
@ -61,7 +59,7 @@ void tst_helpers_resolve::noValue()
|
|||||||
{
|
{
|
||||||
auto p = QtPromise::resolve();
|
auto p = QtPromise::resolve();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
@ -74,7 +72,7 @@ void tst_helpers_resolve::moveRValue()
|
|||||||
{
|
{
|
||||||
auto p = QtPromise::resolve(Data{42}).wait();
|
auto p = QtPromise::resolve(Data{42}).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Data>>::value));
|
||||||
}
|
}
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 1);
|
QCOMPARE(Data::logs().ctor, 1);
|
||||||
@ -91,7 +89,7 @@ void tst_helpers_resolve::copyLValue()
|
|||||||
Data value{42};
|
Data value{42};
|
||||||
auto p = QtPromise::resolve(value).wait();
|
auto p = QtPromise::resolve(value).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Data>>::value));
|
||||||
}
|
}
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 1);
|
QCOMPARE(Data::logs().ctor, 1);
|
||||||
@ -103,24 +101,26 @@ void tst_helpers_resolve::copyLValue()
|
|||||||
// https://github.com/simonbrunel/qtpromise/issues/6
|
// https://github.com/simonbrunel/qtpromise/issues/6
|
||||||
void tst_helpers_resolve::qtSharedPtr()
|
void tst_helpers_resolve::qtSharedPtr()
|
||||||
{
|
{
|
||||||
|
using DataSPtr = QSharedPointer<Data>;
|
||||||
|
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
QWeakPointer<Data> wptr;
|
QWeakPointer<Data> wptr;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto sptr0 = QSharedPointer<Data>::create(42);
|
auto sptr0 = DataSPtr::create(42);
|
||||||
const QSharedPointer<Data> sptr1 = sptr0;
|
const DataSPtr sptr1 = sptr0;
|
||||||
|
|
||||||
auto p0 = QtPromise::resolve(QSharedPointer<Data>::create(42));
|
auto p0 = QtPromise::resolve(DataSPtr::create(42));
|
||||||
auto p1 = QtPromise::resolve(sptr0);
|
auto p1 = QtPromise::resolve(sptr0);
|
||||||
auto p2 = QtPromise::resolve(sptr1);
|
auto p2 = QtPromise::resolve(sptr1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p1, QSharedPointer<Data>{}), sptr0);
|
QCOMPARE(waitForValue(p1, DataSPtr{}), sptr0);
|
||||||
QCOMPARE(waitForValue(p2, QSharedPointer<Data>{}), sptr1);
|
QCOMPARE(waitForValue(p2, DataSPtr{}), sptr1);
|
||||||
|
|
||||||
wptr = sptr0;
|
wptr = sptr0;
|
||||||
|
|
||||||
@ -139,24 +139,26 @@ void tst_helpers_resolve::qtSharedPtr()
|
|||||||
// https://github.com/simonbrunel/qtpromise/issues/6
|
// https://github.com/simonbrunel/qtpromise/issues/6
|
||||||
void tst_helpers_resolve::stdSharedPtr()
|
void tst_helpers_resolve::stdSharedPtr()
|
||||||
{
|
{
|
||||||
|
using DataSPtr = std::shared_ptr<Data>;
|
||||||
|
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
std::weak_ptr<Data> wptr;
|
std::weak_ptr<Data> wptr;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto sptr0 = std::make_shared<Data>(42);
|
auto sptr0 = std::make_shared<Data>(42);
|
||||||
const std::shared_ptr<Data> sptr1 = sptr0;
|
const DataSPtr sptr1 = sptr0;
|
||||||
|
|
||||||
auto p0 = QtPromise::resolve(std::make_shared<Data>(42));
|
auto p0 = QtPromise::resolve(std::make_shared<Data>(42));
|
||||||
auto p1 = QtPromise::resolve(sptr0);
|
auto p1 = QtPromise::resolve(sptr0);
|
||||||
auto p2 = QtPromise::resolve(sptr1);
|
auto p2 = QtPromise::resolve(sptr1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p1, std::shared_ptr<Data>{}), sptr0);
|
QCOMPARE(waitForValue(p1, DataSPtr{}), sptr0);
|
||||||
QCOMPARE(waitForValue(p2, std::shared_ptr<Data>{}), sptr1);
|
QCOMPARE(waitForValue(p2, DataSPtr{}), sptr1);
|
||||||
|
|
||||||
wptr = sptr0;
|
wptr = sptr0;
|
||||||
|
|
||||||
@ -174,22 +176,22 @@ void tst_helpers_resolve::stdSharedPtr()
|
|||||||
|
|
||||||
void tst_helpers_resolve::typedPromise()
|
void tst_helpers_resolve::typedPromise()
|
||||||
{
|
{
|
||||||
auto resolver = [](const QPromiseResolve<int>& resolve) {
|
auto resolver = [](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
QPromise<int> v0{resolver};
|
QtPromise::QPromise<int> v0{resolver};
|
||||||
const QPromise<int> v1 = v0;
|
const QtPromise::QPromise<int> v1 = v0;
|
||||||
|
|
||||||
auto p0 = QtPromise::resolve(QPromise<int>{resolver});
|
auto p0 = QtPromise::resolve(QtPromise::QPromise<int>{resolver});
|
||||||
auto p1 = QtPromise::resolve(v0);
|
auto p1 = QtPromise::resolve(v0);
|
||||||
auto p2 = QtPromise::resolve(v1);
|
auto p2 = QtPromise::resolve(v1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
for (const auto& promise : {p0, p1, p2}) {
|
for (const auto& promise : {p0, p1, p2}) {
|
||||||
QCOMPARE(promise.isPending(), true);
|
QCOMPARE(promise.isPending(), true);
|
||||||
@ -201,22 +203,22 @@ void tst_helpers_resolve::typedPromise()
|
|||||||
|
|
||||||
void tst_helpers_resolve::voidPromise()
|
void tst_helpers_resolve::voidPromise()
|
||||||
{
|
{
|
||||||
auto resolver = [](const QPromiseResolve<void>& resolve) {
|
auto resolver = [](const QtPromise::QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
QPromise<void> v0{resolver};
|
QtPromise::QPromise<void> v0{resolver};
|
||||||
const QPromise<void> v1 = v0;
|
const QtPromise::QPromise<void> v1 = v0;
|
||||||
|
|
||||||
auto p0 = QtPromise::resolve(QPromise<void>{resolver});
|
auto p0 = QtPromise::resolve(QtPromise::QPromise<void>{resolver});
|
||||||
auto p1 = QtPromise::resolve(v0);
|
auto p1 = QtPromise::resolve(v0);
|
||||||
auto p2 = QtPromise::resolve(v1);
|
auto p2 = QtPromise::resolve(v1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<void>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<void>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
for (const auto& promise : {p0, p1, p2}) {
|
for (const auto& promise : {p0, p1, p2}) {
|
||||||
QCOMPARE(promise.isPending(), true);
|
QCOMPARE(promise.isPending(), true);
|
||||||
@ -238,9 +240,9 @@ void tst_helpers_resolve::typedFuture()
|
|||||||
auto p1 = QtPromise::resolve(v0);
|
auto p1 = QtPromise::resolve(v0);
|
||||||
auto p2 = QtPromise::resolve(v1);
|
auto p2 = QtPromise::resolve(v1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
for (const auto& promise : {p0, p1, p2}) {
|
for (const auto& promise : {p0, p1, p2}) {
|
||||||
QCOMPARE(promise.isPending(), true);
|
QCOMPARE(promise.isPending(), true);
|
||||||
@ -260,9 +262,9 @@ void tst_helpers_resolve::voidFuture()
|
|||||||
auto p1 = QtPromise::resolve(v0);
|
auto p1 = QtPromise::resolve(v0);
|
||||||
auto p2 = QtPromise::resolve(v1);
|
auto p2 = QtPromise::resolve(v1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<void>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<void>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
for (const auto& promise : {p0, p1, p2}) {
|
for (const auto& promise : {p0, p1, p2}) {
|
||||||
QCOMPARE(promise.isPending(), true);
|
QCOMPARE(promise.isPending(), true);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
qtpromise_add_tests(qpromise
|
qtpromise_add_tests(qpromise
|
||||||
SOURCES
|
SOURCES
|
||||||
tst_construct.cpp
|
tst_construct.cpp
|
||||||
|
tst_convert.cpp
|
||||||
tst_delay.cpp
|
tst_delay.cpp
|
||||||
tst_each.cpp
|
tst_each.cpp
|
||||||
tst_fail.cpp
|
tst_fail.cpp
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_construct : public QObject
|
class tst_qpromise_construct : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -46,7 +44,7 @@ QTEST_MAIN(tst_qpromise_construct)
|
|||||||
|
|
||||||
void tst_qpromise_construct::resolveSyncOneArg()
|
void tst_qpromise_construct::resolveSyncOneArg()
|
||||||
{
|
{
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>& resolve) {
|
QtPromise::QPromise<int> p{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
@ -57,7 +55,7 @@ void tst_qpromise_construct::resolveSyncOneArg()
|
|||||||
|
|
||||||
void tst_qpromise_construct::resolveSyncOneArg_void()
|
void tst_qpromise_construct::resolveSyncOneArg_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p{[](const QPromiseResolve<void>& resolve) {
|
QtPromise::QPromise<void> p{[](const QtPromise::QPromiseResolve<void>& resolve) {
|
||||||
resolve();
|
resolve();
|
||||||
}};
|
}};
|
||||||
|
|
||||||
@ -68,9 +66,10 @@ void tst_qpromise_construct::resolveSyncOneArg_void()
|
|||||||
|
|
||||||
void tst_qpromise_construct::resolveSyncTwoArgs()
|
void tst_qpromise_construct::resolveSyncTwoArgs()
|
||||||
{
|
{
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>& resolve, const QPromiseReject<int>&) {
|
QtPromise::QPromise<int> p{
|
||||||
resolve(42);
|
[](const QtPromise::QPromiseResolve<int>& resolve, const QtPromise::QPromiseReject<int>&) {
|
||||||
}};
|
resolve(42);
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{});
|
QCOMPARE(waitForError(p, QString{}), QString{});
|
||||||
@ -79,7 +78,8 @@ void tst_qpromise_construct::resolveSyncTwoArgs()
|
|||||||
|
|
||||||
void tst_qpromise_construct::resolveSyncTwoArgs_void()
|
void tst_qpromise_construct::resolveSyncTwoArgs_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p{[](const QPromiseResolve<void>& resolve, const QPromiseReject<void>&) {
|
QtPromise::QPromise<void> p{[](const QtPromise::QPromiseResolve<void>& resolve,
|
||||||
|
const QtPromise::QPromiseReject<void>&) {
|
||||||
resolve();
|
resolve();
|
||||||
}};
|
}};
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ void tst_qpromise_construct::resolveSyncTwoArgs_void()
|
|||||||
|
|
||||||
void tst_qpromise_construct::resolveAsyncOneArg()
|
void tst_qpromise_construct::resolveAsyncOneArg()
|
||||||
{
|
{
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>& resolve) {
|
QtPromise::QPromise<int> p{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
@ -104,7 +104,7 @@ void tst_qpromise_construct::resolveAsyncOneArg()
|
|||||||
|
|
||||||
void tst_qpromise_construct::resolveAsyncOneArg_void()
|
void tst_qpromise_construct::resolveAsyncOneArg_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p{[](const QPromiseResolve<void>& resolve) {
|
QtPromise::QPromise<void> p{[](const QtPromise::QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
@ -118,11 +118,12 @@ void tst_qpromise_construct::resolveAsyncOneArg_void()
|
|||||||
|
|
||||||
void tst_qpromise_construct::resolveAsyncTwoArgs()
|
void tst_qpromise_construct::resolveAsyncTwoArgs()
|
||||||
{
|
{
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>& resolve, const QPromiseReject<int>&) {
|
QtPromise::QPromise<int> p{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<int>& resolve, const QtPromise::QPromiseReject<int>&) {
|
||||||
resolve(42);
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
resolve(42);
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{});
|
QCOMPARE(waitForError(p, QString{}), QString{});
|
||||||
@ -132,7 +133,8 @@ void tst_qpromise_construct::resolveAsyncTwoArgs()
|
|||||||
|
|
||||||
void tst_qpromise_construct::resolveAsyncTwoArgs_void()
|
void tst_qpromise_construct::resolveAsyncTwoArgs_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p{[](const QPromiseResolve<void>& resolve, const QPromiseReject<void>&) {
|
QtPromise::QPromise<void> p{[](const QtPromise::QPromiseResolve<void>& resolve,
|
||||||
|
const QtPromise::QPromiseReject<void>&) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
@ -146,9 +148,10 @@ void tst_qpromise_construct::resolveAsyncTwoArgs_void()
|
|||||||
|
|
||||||
void tst_qpromise_construct::rejectSync()
|
void tst_qpromise_construct::rejectSync()
|
||||||
{
|
{
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QtPromise::QPromise<int> p{
|
||||||
reject(QString{"foo"});
|
[](const QtPromise::QPromiseResolve<int>&, const QtPromise::QPromiseReject<int>& reject) {
|
||||||
}};
|
reject(QString{"foo"});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), -1);
|
QCOMPARE(waitForValue(p, -1), -1);
|
||||||
@ -157,9 +160,10 @@ void tst_qpromise_construct::rejectSync()
|
|||||||
|
|
||||||
void tst_qpromise_construct::rejectSync_void()
|
void tst_qpromise_construct::rejectSync_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
QtPromise::QPromise<void> p{
|
||||||
reject(QString{"foo"});
|
[](const QtPromise::QPromiseResolve<void>&, const QtPromise::QPromiseReject<void>& reject) {
|
||||||
}};
|
reject(QString{"foo"});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), -1);
|
QCOMPARE(waitForValue(p, -1, 42), -1);
|
||||||
@ -168,11 +172,12 @@ void tst_qpromise_construct::rejectSync_void()
|
|||||||
|
|
||||||
void tst_qpromise_construct::rejectAsync()
|
void tst_qpromise_construct::rejectAsync()
|
||||||
{
|
{
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QtPromise::QPromise<int> p{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<int>&, const QtPromise::QPromiseReject<int>& reject) {
|
||||||
reject(QString{"foo"});
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), -1);
|
QCOMPARE(waitForValue(p, -1), -1);
|
||||||
@ -182,11 +187,12 @@ void tst_qpromise_construct::rejectAsync()
|
|||||||
|
|
||||||
void tst_qpromise_construct::rejectAsync_void()
|
void tst_qpromise_construct::rejectAsync_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
QtPromise::QPromise<void> p{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<void>&, const QtPromise::QPromiseReject<void>& reject) {
|
||||||
reject(QString{"foo"});
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), -1);
|
QCOMPARE(waitForValue(p, -1, 42), -1);
|
||||||
@ -196,7 +202,7 @@ void tst_qpromise_construct::rejectAsync_void()
|
|||||||
|
|
||||||
void tst_qpromise_construct::rejectThrowOneArg()
|
void tst_qpromise_construct::rejectThrowOneArg()
|
||||||
{
|
{
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>&) {
|
QtPromise::QPromise<int> p{[](const QtPromise::QPromiseResolve<int>&) {
|
||||||
throw QString{"foo"};
|
throw QString{"foo"};
|
||||||
}};
|
}};
|
||||||
|
|
||||||
@ -207,7 +213,7 @@ void tst_qpromise_construct::rejectThrowOneArg()
|
|||||||
|
|
||||||
void tst_qpromise_construct::rejectThrowOneArg_void()
|
void tst_qpromise_construct::rejectThrowOneArg_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p{[](const QPromiseResolve<void>&) {
|
QtPromise::QPromise<void> p{[](const QtPromise::QPromiseResolve<void>&) {
|
||||||
throw QString{"foo"};
|
throw QString{"foo"};
|
||||||
}};
|
}};
|
||||||
|
|
||||||
@ -218,9 +224,10 @@ void tst_qpromise_construct::rejectThrowOneArg_void()
|
|||||||
|
|
||||||
void tst_qpromise_construct::rejectThrowTwoArgs()
|
void tst_qpromise_construct::rejectThrowTwoArgs()
|
||||||
{
|
{
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>&, const QPromiseReject<int>&) {
|
QtPromise::QPromise<int> p{
|
||||||
throw QString{"foo"};
|
[](const QtPromise::QPromiseResolve<int>&, const QtPromise::QPromiseReject<int>&) {
|
||||||
}};
|
throw QString{"foo"};
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), -1);
|
QCOMPARE(waitForValue(p, -1), -1);
|
||||||
@ -229,9 +236,10 @@ void tst_qpromise_construct::rejectThrowTwoArgs()
|
|||||||
|
|
||||||
void tst_qpromise_construct::rejectThrowTwoArgs_void()
|
void tst_qpromise_construct::rejectThrowTwoArgs_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p{[](const QPromiseResolve<void>&, const QPromiseReject<void>&) {
|
QtPromise::QPromise<void> p{
|
||||||
throw QString{"foo"};
|
[](const QtPromise::QPromiseResolve<void>&, const QtPromise::QPromiseReject<void>&) {
|
||||||
}};
|
throw QString{"foo"};
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), -1);
|
QCOMPARE(waitForValue(p, -1, 42), -1);
|
||||||
@ -240,26 +248,28 @@ void tst_qpromise_construct::rejectThrowTwoArgs_void()
|
|||||||
|
|
||||||
void tst_qpromise_construct::rejectUndefined()
|
void tst_qpromise_construct::rejectUndefined()
|
||||||
{
|
{
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QtPromise::QPromise<int> p{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<int>&, const QtPromise::QPromiseReject<int>& reject) {
|
||||||
reject();
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject();
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForRejected<QPromiseUndefinedException>(p), true);
|
QCOMPARE(waitForRejected<QtPromise::QPromiseUndefinedException>(p), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_construct::rejectUndefined_void()
|
void tst_qpromise_construct::rejectUndefined_void()
|
||||||
{
|
{
|
||||||
QPromise<void> p{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
QtPromise::QPromise<void> p{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<void>&, const QtPromise::QPromiseReject<void>& reject) {
|
||||||
reject();
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject();
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForRejected<QPromiseUndefinedException>(p), true);
|
QCOMPARE(waitForRejected<QtPromise::QPromiseUndefinedException>(p), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/simonbrunel/qtpromise/issues/6
|
// https://github.com/simonbrunel/qtpromise/issues/6
|
||||||
@ -270,9 +280,9 @@ void tst_qpromise_construct::connectAndResolve()
|
|||||||
std::weak_ptr<int> wptr;
|
std::weak_ptr<int> wptr;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto p =
|
auto p = QtPromise::QPromise<std::shared_ptr<int>>{
|
||||||
QPromise<std::shared_ptr<int>>{[&](const QPromiseResolve<std::shared_ptr<int>>& resolve,
|
[&](const QtPromise::QPromiseResolve<std::shared_ptr<int>>& resolve,
|
||||||
const QPromiseReject<std::shared_ptr<int>>& reject) {
|
const QtPromise::QPromiseReject<std::shared_ptr<int>>& reject) {
|
||||||
connect(object.data(),
|
connect(object.data(),
|
||||||
&QObject::objectNameChanged,
|
&QObject::objectNameChanged,
|
||||||
[=, &wptr](const QString& name) {
|
[=, &wptr](const QString& name) {
|
||||||
@ -307,8 +317,8 @@ void tst_qpromise_construct::connectAndReject()
|
|||||||
std::weak_ptr<int> wptr;
|
std::weak_ptr<int> wptr;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>{[&](const QPromiseResolve<int>& resolve,
|
auto p = QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>& resolve,
|
||||||
const QPromiseReject<int>& reject) {
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
connect(object.data(), &QObject::objectNameChanged, [=, &wptr](const QString& name) {
|
connect(object.data(), &QObject::objectNameChanged, [=, &wptr](const QString& name) {
|
||||||
auto sptr = std::make_shared<int>(42);
|
auto sptr = std::make_shared<int>(42);
|
||||||
|
|
||||||
|
264
tests/auto/qtpromise/qpromise/tst_convert.cpp
Normal file
264
tests/auto/qtpromise/qpromise/tst_convert.cpp
Normal file
@ -0,0 +1,264 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Simon Brunel, https://github.com/simonbrunel
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in
|
||||||
|
* the LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../shared/utils.h"
|
||||||
|
|
||||||
|
#include <QtPromise>
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
class tst_qpromise_convert : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void initTestCase();
|
||||||
|
|
||||||
|
void fulfillTAsU();
|
||||||
|
void fulfillTAsVoid();
|
||||||
|
void fulfillTAsQVariant();
|
||||||
|
void fulfillQVariantAsU();
|
||||||
|
void fulfillQVariantAsVoid();
|
||||||
|
|
||||||
|
void rejectUnconvertibleTypes();
|
||||||
|
};
|
||||||
|
|
||||||
|
QTEST_MAIN(tst_qpromise_convert)
|
||||||
|
#include "tst_convert.moc"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct Foo
|
||||||
|
{
|
||||||
|
Foo() = default;
|
||||||
|
Foo(int foo) : m_foo{foo} { }
|
||||||
|
|
||||||
|
bool operator==(const Foo& rhs) const { return m_foo == rhs.m_foo; }
|
||||||
|
|
||||||
|
int m_foo{-1};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Bar
|
||||||
|
{
|
||||||
|
Bar() = default;
|
||||||
|
Bar(const Foo& other) : m_bar{other.m_foo} { }
|
||||||
|
|
||||||
|
bool operator==(const Bar& rhs) const { return m_bar == rhs.m_bar; }
|
||||||
|
|
||||||
|
int m_bar{-1};
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class Enum1 { Value0, Value1, Value2 };
|
||||||
|
enum class Enum2 { Value0, Value1, Value2 };
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(Foo)
|
||||||
|
Q_DECLARE_METATYPE(Bar)
|
||||||
|
|
||||||
|
void tst_qpromise_convert::initTestCase()
|
||||||
|
{
|
||||||
|
// Register converter used by QVariant.
|
||||||
|
// https://doc.qt.io/qt-5/qmetatype.html#registerConverter
|
||||||
|
QMetaType::registerConverter<Foo, QString>([](const Foo& foo) {
|
||||||
|
return QString{"Foo{%1}"}.arg(foo.m_foo);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_qpromise_convert::fulfillTAsU()
|
||||||
|
{
|
||||||
|
// Static cast between primitive types.
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(42.13).convert<int>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert enum class to int.
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(Enum1::Value1).convert<int>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, -1), 1);
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert int to enum class.
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(1).convert<Enum1>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Enum1>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, Enum1::Value0), Enum1::Value1);
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert between enums
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(Enum1::Value1).convert<Enum2>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Enum2>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, Enum2::Value0), Enum2::Value1);
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Converting constructor for Qt types.
|
||||||
|
// https://en.cppreference.com/w/cpp/language/converting_constructor
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(QByteArray{"foo"}).convert<QString>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QString>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo"});
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Converting constructor for non-Qt types.
|
||||||
|
// https://en.cppreference.com/w/cpp/language/converting_constructor
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(Foo{42}).convert<Bar>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Bar>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, Bar{}), Bar{42});
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Conversion of types Qt is aware of via QVariant.
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(42).convert<QString>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QString>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, QString{}), QString{"42"});
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Conversion of a non-Qt type via QVariant.
|
||||||
|
// https://doc.qt.io/qt-5/qmetatype.html#registerConverter
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(Foo{42}).convert<QString>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QString>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, QString{}), QString{"Foo{42}"});
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_qpromise_convert::fulfillTAsVoid()
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(42).convert<void>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_qpromise_convert::fulfillTAsQVariant()
|
||||||
|
{
|
||||||
|
// Primitive type to QVariant.
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(42).convert<QVariant>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVariant>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, QVariant{}), QVariant{42});
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-Qt user-defined type to QVariant.
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(Foo{42}).convert<QVariant>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVariant>>::value));
|
||||||
|
|
||||||
|
QVariant value = waitForValue(p, QVariant{});
|
||||||
|
QCOMPARE(value, QVariant::fromValue(Foo{42}));
|
||||||
|
QCOMPARE(value.value<Foo>().m_foo, 42);
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_qpromise_convert::fulfillQVariantAsU()
|
||||||
|
{
|
||||||
|
// Test whether a directly stored value can be extracted.
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(QVariant{42}).convert<int>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test automatic conversion from string performed by QVariant.
|
||||||
|
// https://doc.qt.io/qt-5/qvariant.html#toInt
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(QVariant{"42"}).convert<int>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-Qt user-defined type
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(QVariant::fromValue(Foo{42})).convert<Foo>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Foo>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, Foo{}), Foo{42});
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_qpromise_convert::fulfillQVariantAsVoid()
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(QVariant{42}).convert<void>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
|
QVERIFY(p.isFulfilled());
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_qpromise_convert::rejectUnconvertibleTypes()
|
||||||
|
{
|
||||||
|
// A string incompatible with int due to its value.
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(QString{"42foo"}).convert<int>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
|
QVERIFY(waitForRejected<QtPromise::QPromiseConversionException>(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
// A user-defined type unconvertible to string because there is no converter.
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(QVariant::fromValue(Bar{42})).convert<QString>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QString>>::value));
|
||||||
|
|
||||||
|
QVERIFY(waitForRejected<QtPromise::QPromiseConversionException>(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
// A standard library type unconvertible to a primitive type because there is no converter.
|
||||||
|
{
|
||||||
|
auto p = QtPromise::resolve(std::vector<int>{42, -42}).convert<int>();
|
||||||
|
|
||||||
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
|
QVERIFY(waitForRejected<QtPromise::QPromiseConversionException>(p));
|
||||||
|
}
|
||||||
|
}
|
@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_delay : public QObject
|
class tst_qpromise_delay : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -36,7 +34,7 @@ void tst_qpromise_delay::fulfilled()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>::resolve(42).delay(1000).finally([&]() {
|
auto p = QtPromise::QPromise<int>::resolve(42).delay(1000).finally([&]() {
|
||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -57,7 +55,7 @@ void tst_qpromise_delay::rejected()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>::reject(QString{"foo"}).delay(1000).finally([&]() {
|
auto p = QtPromise::QPromise<int>::reject(QString{"foo"}).delay(1000).finally([&]() {
|
||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -73,7 +71,7 @@ void tst_qpromise_delay::fulfilledStdChrono()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>::resolve(42).delay(std::chrono::seconds{1}).finally([&]() {
|
auto p = QtPromise::QPromise<int>::resolve(42).delay(std::chrono::seconds{1}).finally([&]() {
|
||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -94,9 +92,11 @@ void tst_qpromise_delay::rejectedStdChrono()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>::reject(QString{"foo"}).delay(std::chrono::seconds{1}).finally([&]() {
|
auto p = QtPromise::QPromise<int>::reject(QString{"foo"})
|
||||||
elapsed = timer.elapsed();
|
.delay(std::chrono::seconds{1})
|
||||||
});
|
.finally([&]() {
|
||||||
|
elapsed = timer.elapsed();
|
||||||
|
});
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_each : public QObject
|
class tst_qpromise_each : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -56,7 +54,7 @@ struct SequenceTester
|
|||||||
values << v + 2;
|
values << v + 2;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Sequence>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Sequence>>::value));
|
||||||
QCOMPARE(waitForValue(p, Sequence{}), (Sequence{42, 43, 44}));
|
QCOMPARE(waitForValue(p, Sequence{}), (Sequence{42, 43, 44}));
|
||||||
|
|
||||||
QVector<int> expected{0, 42, 1, 43, 2, 44, 42, 43, 44, 43, 44, 45, -1, -1, -1, 44, 45, 46};
|
QVector<int> 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()
|
void tst_qpromise_each::emptySequence()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<QVector<int>>::resolve({}).each([&](int v, ...) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({}).each([&](int v, ...) {
|
||||||
values << v;
|
values << v;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
QCOMPARE(values, (QVector<int>{}));
|
QCOMPARE(values, (QVector<int>{}));
|
||||||
}
|
}
|
||||||
@ -81,11 +79,11 @@ void tst_qpromise_each::emptySequence()
|
|||||||
void tst_qpromise_each::preserveValues()
|
void tst_qpromise_each::preserveValues()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).each([&](int v, ...) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({42, 43, 44}).each([&](int v, ...) {
|
||||||
values << v + 1;
|
values << v + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
@ -93,12 +91,12 @@ void tst_qpromise_each::preserveValues()
|
|||||||
void tst_qpromise_each::ignoreResult()
|
void tst_qpromise_each::ignoreResult()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).each([&](int v, ...) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({42, 43, 44}).each([&](int v, ...) {
|
||||||
values << v + 1;
|
values << v + 1;
|
||||||
return "Foo";
|
return "Foo";
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
@ -106,14 +104,14 @@ void tst_qpromise_each::ignoreResult()
|
|||||||
void tst_qpromise_each::delayedFulfilled()
|
void tst_qpromise_each::delayedFulfilled()
|
||||||
{
|
{
|
||||||
QMap<int, int> values;
|
QMap<int, int> values;
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).each([&](int v, int index) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({42, 43, 44}).each([&](int v, int index) {
|
||||||
return QPromise<void>::resolve().delay(250).then([=, &values]() {
|
return QtPromise::QPromise<void>::resolve().delay(250).then([=, &values]() {
|
||||||
values[v] = index;
|
values[v] = index;
|
||||||
return 42;
|
return 42;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
||||||
QCOMPARE(values, expected);
|
QCOMPARE(values, expected);
|
||||||
@ -121,42 +119,42 @@ void tst_qpromise_each::delayedFulfilled()
|
|||||||
|
|
||||||
void tst_qpromise_each::delayedRejected()
|
void tst_qpromise_each::delayedRejected()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).each([](int v, ...) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({42, 43, 44}).each([](int v, ...) {
|
||||||
return QPromise<int>{
|
return QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>& resolve,
|
||||||
[&](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
if (v == 44) {
|
if (v == 44) {
|
||||||
reject(QString{"foo"});
|
reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
resolve(v);
|
resolve(v);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_each::functorThrows()
|
void tst_qpromise_each::functorThrows()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).each([](int v, ...) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({42, 43, 44}).each([](int v, ...) {
|
||||||
if (v == 44) {
|
if (v == 44) {
|
||||||
throw QString{"foo"};
|
throw QString{"foo"};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_each::functorArguments()
|
void tst_qpromise_each::functorArguments()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).each([&](int v, int i) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({42, 43, 44}).each([&](int v, int i) {
|
||||||
values << i << v;
|
values << i << v;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 43, 44}));
|
||||||
QCOMPARE(values, (QVector<int>{0, 42, 1, 43, 2, 44}));
|
QCOMPARE(values, (QVector<int>{0, 42, 1, 43, 2, 44}));
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_fail : public QObject
|
class tst_qpromise_fail : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -72,7 +70,7 @@ private:
|
|||||||
void tst_qpromise_fail::sameType()
|
void tst_qpromise_fail::sameType()
|
||||||
{
|
{
|
||||||
// http://en.cppreference.com/w/cpp/error/exception
|
// http://en.cppreference.com/w/cpp/error/exception
|
||||||
auto p = QPromise<int>::reject(std::out_of_range("foo"));
|
auto p = QtPromise::QPromise<int>::reject(std::out_of_range("foo"));
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
p.fail([&](const std::domain_error& e) {
|
p.fail([&](const std::domain_error& e) {
|
||||||
@ -95,7 +93,7 @@ void tst_qpromise_fail::sameType()
|
|||||||
void tst_qpromise_fail::baseClass()
|
void tst_qpromise_fail::baseClass()
|
||||||
{
|
{
|
||||||
// http://en.cppreference.com/w/cpp/error/exception
|
// http://en.cppreference.com/w/cpp/error/exception
|
||||||
auto p = QPromise<int>::reject(std::out_of_range("foo"));
|
auto p = QtPromise::QPromise<int>::reject(std::out_of_range("foo"));
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
p.fail([&](const std::runtime_error& e) {
|
p.fail([&](const std::runtime_error& e) {
|
||||||
@ -117,7 +115,7 @@ void tst_qpromise_fail::baseClass()
|
|||||||
|
|
||||||
void tst_qpromise_fail::catchAll()
|
void tst_qpromise_fail::catchAll()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::reject(std::out_of_range("foo"));
|
auto p = QtPromise::QPromise<int>::reject(std::out_of_range("foo"));
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
p.fail([&](const std::runtime_error& e) {
|
p.fail([&](const std::runtime_error& e) {
|
||||||
@ -140,18 +138,18 @@ void tst_qpromise_fail::catchAll()
|
|||||||
void tst_qpromise_fail::functionPtrHandlers()
|
void tst_qpromise_fail::functionPtrHandlers()
|
||||||
{
|
{
|
||||||
{ // Global functions.
|
{ // Global functions.
|
||||||
auto p0 = QPromise<float>::reject(kErr).fail(&fnNoArg);
|
auto p0 = QtPromise::QPromise<float>::reject(kErr).fail(&fnNoArg);
|
||||||
auto p1 = QPromise<float>::reject(kErr).fail(&fnArgByVal);
|
auto p1 = QtPromise::QPromise<float>::reject(kErr).fail(&fnArgByVal);
|
||||||
auto p2 = QPromise<float>::reject(kErr).fail(&fnArgByRef);
|
auto p2 = QtPromise::QPromise<float>::reject(kErr).fail(&fnArgByRef);
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p0, kFail), kRes);
|
QCOMPARE(waitForValue(p0, kFail), kRes);
|
||||||
QCOMPARE(waitForValue(p1, kFail), kRes);
|
QCOMPARE(waitForValue(p1, kFail), kRes);
|
||||||
QCOMPARE(waitForValue(p2, kFail), kRes);
|
QCOMPARE(waitForValue(p2, kFail), kRes);
|
||||||
}
|
}
|
||||||
{ // Static member functions.
|
{ // Static member functions.
|
||||||
auto p0 = QPromise<float>::reject(kErr).fail(&Klass::kFnNoArg);
|
auto p0 = QtPromise::QPromise<float>::reject(kErr).fail(&Klass::kFnNoArg);
|
||||||
auto p1 = QPromise<float>::reject(kErr).fail(&Klass::kFnArgByVal);
|
auto p1 = QtPromise::QPromise<float>::reject(kErr).fail(&Klass::kFnArgByVal);
|
||||||
auto p2 = QPromise<float>::reject(kErr).fail(&Klass::kFnArgByRef);
|
auto p2 = QtPromise::QPromise<float>::reject(kErr).fail(&Klass::kFnArgByRef);
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p0, kFail), kRes);
|
QCOMPARE(waitForValue(p0, kFail), kRes);
|
||||||
QCOMPARE(waitForValue(p1, kFail), kRes);
|
QCOMPARE(waitForValue(p1, kFail), kRes);
|
||||||
@ -167,9 +165,9 @@ void tst_qpromise_fail::stdFunctionHandlers()
|
|||||||
std::function<float(QString)> stdFnArgByVal = fnArgByVal;
|
std::function<float(QString)> stdFnArgByVal = fnArgByVal;
|
||||||
std::function<float(const QString&)> stdFnArgByRef = fnArgByRef;
|
std::function<float(const QString&)> stdFnArgByRef = fnArgByRef;
|
||||||
|
|
||||||
auto p0 = QPromise<float>::reject(kErr).fail(stdFnNoArg);
|
auto p0 = QtPromise::QPromise<float>::reject(kErr).fail(stdFnNoArg);
|
||||||
auto p1 = QPromise<float>::reject(kErr).fail(stdFnArgByVal);
|
auto p1 = QtPromise::QPromise<float>::reject(kErr).fail(stdFnArgByVal);
|
||||||
auto p2 = QPromise<float>::reject(kErr).fail(stdFnArgByRef);
|
auto p2 = QtPromise::QPromise<float>::reject(kErr).fail(stdFnArgByRef);
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p0, kFail), kRes);
|
QCOMPARE(waitForValue(p0, kFail), kRes);
|
||||||
QCOMPARE(waitForValue(p1, kFail), kRes);
|
QCOMPARE(waitForValue(p1, kFail), kRes);
|
||||||
@ -180,19 +178,20 @@ void tst_qpromise_fail::stdFunctionHandlers()
|
|||||||
const std::function<float(QString)> stdFnArgByVal = fnArgByVal;
|
const std::function<float(QString)> stdFnArgByVal = fnArgByVal;
|
||||||
const std::function<float(const QString&)> stdFnArgByRef = fnArgByRef;
|
const std::function<float(const QString&)> stdFnArgByRef = fnArgByRef;
|
||||||
|
|
||||||
auto p0 = QPromise<float>::reject(kErr).fail(stdFnNoArg);
|
auto p0 = QtPromise::QPromise<float>::reject(kErr).fail(stdFnNoArg);
|
||||||
auto p1 = QPromise<float>::reject(kErr).fail(stdFnArgByVal);
|
auto p1 = QtPromise::QPromise<float>::reject(kErr).fail(stdFnArgByVal);
|
||||||
auto p2 = QPromise<float>::reject(kErr).fail(stdFnArgByRef);
|
auto p2 = QtPromise::QPromise<float>::reject(kErr).fail(stdFnArgByRef);
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p0, kFail), kRes);
|
QCOMPARE(waitForValue(p0, kFail), kRes);
|
||||||
QCOMPARE(waitForValue(p1, kFail), kRes);
|
QCOMPARE(waitForValue(p1, kFail), kRes);
|
||||||
QCOMPARE(waitForValue(p2, kFail), kRes);
|
QCOMPARE(waitForValue(p2, kFail), kRes);
|
||||||
}
|
}
|
||||||
{ // rvalue.
|
{ // rvalue.
|
||||||
auto p0 = QPromise<float>::reject(kErr).fail(std::function<float()>{fnNoArg});
|
auto p0 = QtPromise::QPromise<float>::reject(kErr).fail(std::function<float()>{fnNoArg});
|
||||||
auto p1 = QPromise<float>::reject(kErr).fail(std::function<float(QString)>{fnArgByVal});
|
auto p1 = QtPromise::QPromise<float>::reject(kErr).fail(
|
||||||
auto p2 =
|
std::function<float(QString)>{fnArgByVal});
|
||||||
QPromise<float>::reject(kErr).fail(std::function<float(const QString&)>{fnArgByRef});
|
auto p2 = QtPromise::QPromise<float>::reject(kErr).fail(
|
||||||
|
std::function<float(const QString&)>{fnArgByRef});
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p0, kFail), kRes);
|
QCOMPARE(waitForValue(p0, kFail), kRes);
|
||||||
QCOMPARE(waitForValue(p1, kFail), kRes);
|
QCOMPARE(waitForValue(p1, kFail), kRes);
|
||||||
@ -213,9 +212,9 @@ void tst_qpromise_fail::stdBindHandlers()
|
|||||||
const std::function<float(const QString&)> bindArgByRef =
|
const std::function<float(const QString&)> bindArgByRef =
|
||||||
std::bind(&Klass::fnArgByRef, &obj, _1);
|
std::bind(&Klass::fnArgByRef, &obj, _1);
|
||||||
|
|
||||||
auto p0 = QPromise<float>::reject(kErr).fail(bindNoArg);
|
auto p0 = QtPromise::QPromise<float>::reject(kErr).fail(bindNoArg);
|
||||||
auto p1 = QPromise<float>::reject(kErr).fail(bindArgByVal);
|
auto p1 = QtPromise::QPromise<float>::reject(kErr).fail(bindArgByVal);
|
||||||
auto p2 = QPromise<float>::reject(kErr).fail(bindArgByRef);
|
auto p2 = QtPromise::QPromise<float>::reject(kErr).fail(bindArgByRef);
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p0, kFail), val);
|
QCOMPARE(waitForValue(p0, kFail), val);
|
||||||
QCOMPARE(waitForValue(p1, kFail), val + kRes);
|
QCOMPARE(waitForValue(p1, kFail), val + kRes);
|
||||||
@ -235,9 +234,9 @@ void tst_qpromise_fail::lambdaHandlers()
|
|||||||
return v.toFloat();
|
return v.toFloat();
|
||||||
};
|
};
|
||||||
|
|
||||||
auto p0 = QPromise<float>::reject(kErr).fail(lambdaNoArg);
|
auto p0 = QtPromise::QPromise<float>::reject(kErr).fail(lambdaNoArg);
|
||||||
auto p1 = QPromise<float>::reject(kErr).fail(lambdaArgByVal);
|
auto p1 = QtPromise::QPromise<float>::reject(kErr).fail(lambdaArgByVal);
|
||||||
auto p2 = QPromise<float>::reject(kErr).fail(lambdaArgByRef);
|
auto p2 = QtPromise::QPromise<float>::reject(kErr).fail(lambdaArgByRef);
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p0, kFail), kRes);
|
QCOMPARE(waitForValue(p0, kFail), kRes);
|
||||||
QCOMPARE(waitForValue(p1, kFail), kRes);
|
QCOMPARE(waitForValue(p1, kFail), kRes);
|
||||||
@ -254,22 +253,22 @@ void tst_qpromise_fail::lambdaHandlers()
|
|||||||
return v.toFloat();
|
return v.toFloat();
|
||||||
};
|
};
|
||||||
|
|
||||||
auto p0 = QPromise<float>::reject(kErr).fail(lambdaNoArg);
|
auto p0 = QtPromise::QPromise<float>::reject(kErr).fail(lambdaNoArg);
|
||||||
auto p1 = QPromise<float>::reject(kErr).fail(lambdaArgByVal);
|
auto p1 = QtPromise::QPromise<float>::reject(kErr).fail(lambdaArgByVal);
|
||||||
auto p2 = QPromise<float>::reject(kErr).fail(lambdaArgByRef);
|
auto p2 = QtPromise::QPromise<float>::reject(kErr).fail(lambdaArgByRef);
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p0, kFail), kRes);
|
QCOMPARE(waitForValue(p0, kFail), kRes);
|
||||||
QCOMPARE(waitForValue(p1, kFail), kRes);
|
QCOMPARE(waitForValue(p1, kFail), kRes);
|
||||||
QCOMPARE(waitForValue(p2, kFail), kRes);
|
QCOMPARE(waitForValue(p2, kFail), kRes);
|
||||||
}
|
}
|
||||||
{ // rvalue.
|
{ // rvalue.
|
||||||
auto p0 = QPromise<float>::reject(kErr).fail([]() {
|
auto p0 = QtPromise::QPromise<float>::reject(kErr).fail([]() {
|
||||||
return kRes;
|
return kRes;
|
||||||
});
|
});
|
||||||
auto p1 = QPromise<float>::reject(kErr).fail([](QString v) {
|
auto p1 = QtPromise::QPromise<float>::reject(kErr).fail([](QString v) {
|
||||||
return v.toFloat();
|
return v.toFloat();
|
||||||
});
|
});
|
||||||
auto p2 = QPromise<float>::reject(kErr).fail([](const QString& v) {
|
auto p2 = QtPromise::QPromise<float>::reject(kErr).fail([](const QString& v) {
|
||||||
return v.toFloat();
|
return v.toFloat();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_filter : public QObject
|
class tst_qpromise_filter : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -43,13 +41,13 @@ struct SequenceTester
|
|||||||
return v > 42 && v < 51;
|
return v > 42 && v < 51;
|
||||||
})
|
})
|
||||||
.filter([](int, int i) {
|
.filter([](int, int i) {
|
||||||
return QPromise<bool>::resolve(i % 2 == 0);
|
return QtPromise::QPromise<bool>::resolve(i % 2 == 0);
|
||||||
})
|
})
|
||||||
.filter([](int v, ...) {
|
.filter([](int v, ...) {
|
||||||
return v != 45;
|
return v != 45;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Sequence>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Sequence>>::value));
|
||||||
QCOMPARE(waitForValue(p, Sequence{}), (Sequence{43, 47, 49}));
|
QCOMPARE(waitForValue(p, Sequence{}), (Sequence{43, 47, 49}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -58,78 +56,78 @@ struct SequenceTester
|
|||||||
|
|
||||||
void tst_qpromise_filter::emptySequence()
|
void tst_qpromise_filter::emptySequence()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({}).filter([](int v, ...) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({}).filter([](int v, ...) {
|
||||||
return v % 2 == 0;
|
return v % 2 == 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_filter::filterValues()
|
void tst_qpromise_filter::filterValues()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
||||||
return v % 2 == 0;
|
return v % 2 == 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_filter::delayedFulfilled()
|
void tst_qpromise_filter::delayedFulfilled()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
||||||
return QPromise<bool>{[&](const QPromiseResolve<bool>& resolve) {
|
return QtPromise::QPromise<bool>{[&](const QtPromise::QPromiseResolve<bool>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(v % 2 == 0);
|
resolve(v % 2 == 0);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_filter::delayedRejected()
|
void tst_qpromise_filter::delayedRejected()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
||||||
return QPromise<bool>{
|
return QtPromise::QPromise<bool>{[&](const QtPromise::QPromiseResolve<bool>& resolve,
|
||||||
[&](const QPromiseResolve<bool>& resolve, const QPromiseReject<bool>& reject) {
|
const QtPromise::QPromiseReject<bool>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
if (v == 43) {
|
if (v == 43) {
|
||||||
reject(QString{"foo"});
|
reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_filter::functorThrows()
|
void tst_qpromise_filter::functorThrows()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({42, 43, 44}).filter([](int v, ...) {
|
||||||
if (v == 43) {
|
if (v == 43) {
|
||||||
throw QString{"foo"};
|
throw QString{"foo"};
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_filter::functorArguments()
|
void tst_qpromise_filter::functorArguments()
|
||||||
{
|
{
|
||||||
QMap<int, int> args;
|
QMap<int, int> args;
|
||||||
auto p = QPromise<QVector<int>>::resolve({42, 43, 44}).filter([&](int v, int i) {
|
auto p = QtPromise::QPromise<QVector<int>>::resolve({42, 43, 44}).filter([&](int v, int i) {
|
||||||
args[v] = i;
|
args[v] = i;
|
||||||
return i % 2 == 0;
|
return i % 2 == 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{42, 44}));
|
||||||
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
QMap<int, int> expected{{42, 0}, {43, 1}, {44, 2}};
|
||||||
QCOMPARE(args, expected);
|
QCOMPARE(args, expected);
|
||||||
@ -137,11 +135,12 @@ void tst_qpromise_filter::functorArguments()
|
|||||||
|
|
||||||
void tst_qpromise_filter::preserveOrder()
|
void tst_qpromise_filter::preserveOrder()
|
||||||
{
|
{
|
||||||
auto p = QPromise<QVector<int>>::resolve({250, 50, 100, 400, 300}).filter([](int v, ...) {
|
auto p =
|
||||||
return QPromise<bool>::resolve(v > 200).delay(v);
|
QtPromise::QPromise<QVector<int>>::resolve({250, 50, 100, 400, 300}).filter([](int v, ...) {
|
||||||
});
|
return QtPromise::QPromise<bool>::resolve(v > 200).delay(v);
|
||||||
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{250, 400, 300}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{250, 400, 300}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_finally : public QObject
|
class tst_qpromise_finally : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -37,12 +35,12 @@ QTEST_MAIN(tst_qpromise_finally)
|
|||||||
void tst_qpromise_finally::fulfilledSync()
|
void tst_qpromise_finally::fulfilledSync()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<int>::resolve(42).finally([&]() {
|
auto p = QtPromise::QPromise<int>::resolve(42).finally([&]() {
|
||||||
value = 8;
|
value = 8;
|
||||||
return 16; // ignored!
|
return 16; // ignored!
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
QCOMPARE(waitForValue(p, -1), 42);
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(value, 8);
|
QCOMPARE(value, 8);
|
||||||
@ -51,12 +49,12 @@ void tst_qpromise_finally::fulfilledSync()
|
|||||||
void tst_qpromise_finally::fulfilledSync_void()
|
void tst_qpromise_finally::fulfilledSync_void()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<void>::resolve().finally([&]() {
|
auto p = QtPromise::QPromise<void>::resolve().finally([&]() {
|
||||||
value = 8;
|
value = 8;
|
||||||
return 16; // ignored!
|
return 16; // ignored!
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(value, 8);
|
QCOMPARE(value, 8);
|
||||||
@ -64,22 +62,22 @@ void tst_qpromise_finally::fulfilledSync_void()
|
|||||||
|
|
||||||
void tst_qpromise_finally::fulfilledThrows()
|
void tst_qpromise_finally::fulfilledThrows()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::resolve(42).finally([&]() {
|
auto p = QtPromise::QPromise<int>::resolve(42).finally([&]() {
|
||||||
throw QString{"bar"};
|
throw QString{"bar"};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_finally::fulfilledThrows_void()
|
void tst_qpromise_finally::fulfilledThrows_void()
|
||||||
{
|
{
|
||||||
auto p = QPromise<void>::resolve().finally([&]() {
|
auto p = QtPromise::QPromise<void>::resolve().finally([&]() {
|
||||||
throw QString{"bar"};
|
throw QString{"bar"};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
@ -87,8 +85,8 @@ void tst_qpromise_finally::fulfilledThrows_void()
|
|||||||
void tst_qpromise_finally::fulfilledAsyncResolve()
|
void tst_qpromise_finally::fulfilledAsyncResolve()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<int>::resolve(42).finally([&]() {
|
auto p = QtPromise::QPromise<int>::resolve(42).finally([&]() {
|
||||||
QPromise<int> p{[&](const QPromiseResolve<int>& resolve) {
|
QtPromise::QPromise<int> p{[&](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values << 64;
|
values << 64;
|
||||||
resolve(16); // ignored!
|
resolve(16); // ignored!
|
||||||
@ -106,8 +104,9 @@ void tst_qpromise_finally::fulfilledAsyncResolve()
|
|||||||
|
|
||||||
void tst_qpromise_finally::fulfilledAsyncReject()
|
void tst_qpromise_finally::fulfilledAsyncReject()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::resolve(42).finally([]() {
|
auto p = QtPromise::QPromise<int>::resolve(42).finally([]() {
|
||||||
return QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
return QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>&,
|
||||||
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString{"bar"});
|
reject(QString{"bar"});
|
||||||
});
|
});
|
||||||
@ -121,12 +120,12 @@ void tst_qpromise_finally::fulfilledAsyncReject()
|
|||||||
void tst_qpromise_finally::rejectedSync()
|
void tst_qpromise_finally::rejectedSync()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<int>::reject(QString{"foo"}).finally([&]() {
|
auto p = QtPromise::QPromise<int>::reject(QString{"foo"}).finally([&]() {
|
||||||
value = 8;
|
value = 8;
|
||||||
return 16; // ignored!
|
return 16; // ignored!
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(value, 8);
|
QCOMPARE(value, 8);
|
||||||
@ -135,12 +134,12 @@ void tst_qpromise_finally::rejectedSync()
|
|||||||
void tst_qpromise_finally::rejectedSync_void()
|
void tst_qpromise_finally::rejectedSync_void()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<void>::reject(QString{"foo"}).finally([&]() {
|
auto p = QtPromise::QPromise<void>::reject(QString{"foo"}).finally([&]() {
|
||||||
value = 8;
|
value = 8;
|
||||||
return 16; // ignored!
|
return 16; // ignored!
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
QCOMPARE(value, 8);
|
QCOMPARE(value, 8);
|
||||||
@ -148,22 +147,22 @@ void tst_qpromise_finally::rejectedSync_void()
|
|||||||
|
|
||||||
void tst_qpromise_finally::rejectedThrows()
|
void tst_qpromise_finally::rejectedThrows()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::reject(QString{"foo"}).finally([&]() {
|
auto p = QtPromise::QPromise<int>::reject(QString{"foo"}).finally([&]() {
|
||||||
throw QString{"bar"};
|
throw QString{"bar"};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_finally::rejectedThrows_void()
|
void tst_qpromise_finally::rejectedThrows_void()
|
||||||
{
|
{
|
||||||
auto p = QPromise<void>::reject(QString{"foo"}).finally([&]() {
|
auto p = QtPromise::QPromise<void>::reject(QString{"foo"}).finally([&]() {
|
||||||
throw QString{"bar"};
|
throw QString{"bar"};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
QCOMPARE(waitForError(p, QString{}), QString{"bar"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
@ -171,8 +170,8 @@ void tst_qpromise_finally::rejectedThrows_void()
|
|||||||
void tst_qpromise_finally::rejectedAsyncResolve()
|
void tst_qpromise_finally::rejectedAsyncResolve()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<int>::reject(QString{"foo"}).finally([&]() {
|
auto p = QtPromise::QPromise<int>::reject(QString{"foo"}).finally([&]() {
|
||||||
QPromise<int> p{[&](const QPromiseResolve<int>& resolve) {
|
QtPromise::QPromise<int> p{[&](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values << 64;
|
values << 64;
|
||||||
resolve(16); // ignored!
|
resolve(16); // ignored!
|
||||||
@ -194,8 +193,9 @@ void tst_qpromise_finally::rejectedAsyncResolve()
|
|||||||
|
|
||||||
void tst_qpromise_finally::rejectedAsyncReject()
|
void tst_qpromise_finally::rejectedAsyncReject()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::reject(QString{"foo"}).finally([]() {
|
auto p = QtPromise::QPromise<int>::reject(QString{"foo"}).finally([]() {
|
||||||
return QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
return QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>&,
|
||||||
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString{"bar"});
|
reject(QString{"bar"});
|
||||||
});
|
});
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_map : public QObject
|
class tst_qpromise_map : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -52,7 +50,7 @@ struct SequenceTester
|
|||||||
return QString::fromUtf8(v);
|
return QString::fromUtf8(v);
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<QString>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<QString>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<QString>{}),
|
QCOMPARE(waitForValue(p, QVector<QString>{}),
|
||||||
(QVector<QString>{"0:43!", "1:44!", "2:45!"}));
|
(QVector<QString>{"0:43!", "1:44!", "2:45!"}));
|
||||||
}
|
}
|
||||||
@ -66,7 +64,7 @@ void tst_qpromise_map::emptySequence()
|
|||||||
return v + 1;
|
return v + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
QCOMPARE(waitForValue(p, QVector<int>{}), QVector<int>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +74,7 @@ void tst_qpromise_map::modifyValues()
|
|||||||
return v + 1;
|
return v + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{43, 44, 45}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,39 +84,39 @@ void tst_qpromise_map::convertValues()
|
|||||||
return QString::number(v + 1);
|
return QString::number(v + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<QString>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<QString>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<QString>{}), (QVector<QString>{"43", "44", "45"}));
|
QCOMPARE(waitForValue(p, QVector<QString>{}), (QVector<QString>{"43", "44", "45"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_map::delayedFulfilled()
|
void tst_qpromise_map::delayedFulfilled()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::resolve(QVector<int>{42, 43, 44}).map([](int v, ...) {
|
auto p = QtPromise::resolve(QVector<int>{42, 43, 44}).map([](int v, ...) {
|
||||||
return QPromise<int>{[&](const QPromiseResolve<int>& resolve) {
|
return QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(v + 1);
|
resolve(v + 1);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{43, 44, 45}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{43, 44, 45}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_map::delayedRejected()
|
void tst_qpromise_map::delayedRejected()
|
||||||
{
|
{
|
||||||
auto p = QtPromise::resolve(QVector<int>{42, 43, 44}).map([](int v, ...) {
|
auto p = QtPromise::resolve(QVector<int>{42, 43, 44}).map([](int v, ...) {
|
||||||
return QPromise<int>{
|
return QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>& resolve,
|
||||||
[&](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
if (v == 43) {
|
if (v == 43) {
|
||||||
reject(QString{"foo"});
|
reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
resolve(v);
|
resolve(v);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +129,7 @@ void tst_qpromise_map::functorThrows()
|
|||||||
return v + 1;
|
return v + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +139,7 @@ void tst_qpromise_map::functorArguments()
|
|||||||
return v * i;
|
return v * i;
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p1, QVector<int>{}), (QVector<int>{0, 42, 84}));
|
QCOMPARE(waitForValue(p1, QVector<int>{}), (QVector<int>{0, 42, 84}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +149,7 @@ void tst_qpromise_map::preserveOrder()
|
|||||||
return QtPromise::resolve(v + 1).delay(v);
|
return QtPromise::resolve(v + 1).delay(v);
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QVector<int>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QVector<int>>>::value));
|
||||||
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{251, 501, 101}));
|
QCOMPARE(waitForValue(p, QVector<int>{}), (QVector<int>{251, 501, 101}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_operators : public QObject
|
class tst_qpromise_operators : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -34,21 +32,22 @@ QTEST_MAIN(tst_qpromise_operators)
|
|||||||
|
|
||||||
void tst_qpromise_operators::move()
|
void tst_qpromise_operators::move()
|
||||||
{
|
{
|
||||||
auto p0 = QPromise<int>::resolve(42);
|
auto p0 = QtPromise::QPromise<int>::resolve(42);
|
||||||
|
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1), 42);
|
QCOMPARE(waitForValue(p0, -1), 42);
|
||||||
|
|
||||||
p0 = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
p0 = QtPromise::QPromise<int>{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<int>&, const QtPromise::QPromiseReject<int>& reject) {
|
||||||
reject(QString{"foo"});
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(waitForError(p0, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p0, QString{}), QString{"foo"});
|
||||||
|
|
||||||
p0 = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
p0 = QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(43);
|
resolve(43);
|
||||||
});
|
});
|
||||||
@ -60,21 +59,22 @@ void tst_qpromise_operators::move()
|
|||||||
|
|
||||||
void tst_qpromise_operators::move_void()
|
void tst_qpromise_operators::move_void()
|
||||||
{
|
{
|
||||||
auto p0 = QPromise<void>::resolve();
|
auto p0 = QtPromise::QPromise<void>::resolve();
|
||||||
|
|
||||||
QCOMPARE(p0.isFulfilled(), true);
|
QCOMPARE(p0.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p0, -1, 42), 42);
|
QCOMPARE(waitForValue(p0, -1, 42), 42);
|
||||||
|
|
||||||
p0 = QPromise<void>{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
p0 = QtPromise::QPromise<void>{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<void>&, const QtPromise::QPromiseReject<void>& reject) {
|
||||||
reject(QString{"foo"});
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(waitForError(p0, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p0, QString{}), QString{"foo"});
|
||||||
|
|
||||||
p0 = QPromise<void>{[](const QPromiseResolve<void>& resolve) {
|
p0 = QtPromise::QPromise<void>{[](const QtPromise::QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
@ -86,13 +86,14 @@ void tst_qpromise_operators::move_void()
|
|||||||
|
|
||||||
void tst_qpromise_operators::copy()
|
void tst_qpromise_operators::copy()
|
||||||
{
|
{
|
||||||
auto p0 = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
auto p0 = QtPromise::QPromise<int>{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<int>&, const QtPromise::QPromiseReject<int>& reject) {
|
||||||
reject(QString{"foo"});
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p1 = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
auto p1 = QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
@ -113,13 +114,14 @@ void tst_qpromise_operators::copy()
|
|||||||
|
|
||||||
void tst_qpromise_operators::copy_void()
|
void tst_qpromise_operators::copy_void()
|
||||||
{
|
{
|
||||||
auto p0 = QPromise<void>{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
auto p0 = QtPromise::QPromise<void>{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<void>&, const QtPromise::QPromiseReject<void>& reject) {
|
||||||
reject(QString{"foo"});
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p1 = QPromise<void>{[](const QPromiseResolve<void>& resolve) {
|
auto p1 = QtPromise::QPromise<void>{[](const QtPromise::QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
@ -143,8 +145,8 @@ void tst_qpromise_operators::copy_void()
|
|||||||
|
|
||||||
void tst_qpromise_operators::equalTo()
|
void tst_qpromise_operators::equalTo()
|
||||||
{
|
{
|
||||||
auto p0 = QPromise<int>::resolve(42);
|
auto p0 = QtPromise::QPromise<int>::resolve(42);
|
||||||
auto p1 = QPromise<int>::resolve(42);
|
auto p1 = QtPromise::QPromise<int>::resolve(42);
|
||||||
auto p2 = p1;
|
auto p2 = p1;
|
||||||
auto p3(p2);
|
auto p3(p2);
|
||||||
|
|
||||||
@ -158,8 +160,8 @@ void tst_qpromise_operators::equalTo()
|
|||||||
|
|
||||||
void tst_qpromise_operators::equalTo_void()
|
void tst_qpromise_operators::equalTo_void()
|
||||||
{
|
{
|
||||||
auto p0 = QPromise<void>::resolve();
|
auto p0 = QtPromise::QPromise<void>::resolve();
|
||||||
auto p1 = QPromise<void>::resolve();
|
auto p1 = QtPromise::QPromise<void>::resolve();
|
||||||
auto p2 = p1;
|
auto p2 = p1;
|
||||||
auto p3(p2);
|
auto p3(p2);
|
||||||
|
|
||||||
@ -173,8 +175,8 @@ void tst_qpromise_operators::equalTo_void()
|
|||||||
|
|
||||||
void tst_qpromise_operators::notEqualTo()
|
void tst_qpromise_operators::notEqualTo()
|
||||||
{
|
{
|
||||||
auto p0 = QPromise<int>::resolve(42);
|
auto p0 = QtPromise::QPromise<int>::resolve(42);
|
||||||
auto p1 = QPromise<int>::resolve(42);
|
auto p1 = QtPromise::QPromise<int>::resolve(42);
|
||||||
auto p2 = p1;
|
auto p2 = p1;
|
||||||
auto p3(p2);
|
auto p3(p2);
|
||||||
|
|
||||||
@ -188,8 +190,8 @@ void tst_qpromise_operators::notEqualTo()
|
|||||||
|
|
||||||
void tst_qpromise_operators::notEqualTo_void()
|
void tst_qpromise_operators::notEqualTo_void()
|
||||||
{
|
{
|
||||||
auto p0 = QPromise<void>::resolve();
|
auto p0 = QtPromise::QPromise<void>::resolve();
|
||||||
auto p1 = QPromise<void>::resolve();
|
auto p1 = QtPromise::QPromise<void>::resolve();
|
||||||
auto p2 = p1;
|
auto p2 = p1;
|
||||||
auto p3(p2);
|
auto p3(p2);
|
||||||
|
|
||||||
@ -203,10 +205,10 @@ void tst_qpromise_operators::notEqualTo_void()
|
|||||||
|
|
||||||
void tst_qpromise_operators::chaining()
|
void tst_qpromise_operators::chaining()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::resolve(1);
|
auto p = QtPromise::QPromise<int>::resolve(1);
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
p = p.then([](int res) {
|
p = p.then([](int res) {
|
||||||
return QPromise<int>::resolve(res * 2);
|
return QtPromise::QPromise<int>::resolve(res * 2);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,12 +220,12 @@ void tst_qpromise_operators::chaining_void()
|
|||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
|
|
||||||
auto p = QPromise<void>::resolve();
|
auto p = QtPromise::QPromise<void>::resolve();
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
p = p.then([i, &values]() {
|
p = p.then([i, &values]() {
|
||||||
values.append(i * 2);
|
values.append(i * 2);
|
||||||
return QPromise<void>::resolve();
|
return QtPromise::QPromise<void>::resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_reduce : public QObject
|
class tst_qpromise_reduce : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -56,8 +54,8 @@ struct SequenceTester
|
|||||||
},
|
},
|
||||||
QtPromise::resolve(2).delay(100));
|
QtPromise::resolve(2).delay(100));
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.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!
|
// NOTE(SB): reduce() on an empty sequence without an initial value is an error!
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p, -1), 42);
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
QCOMPARE(called, false);
|
QCOMPARE(called, false);
|
||||||
@ -107,8 +105,8 @@ void tst_qpromise_reduce::regularValues()
|
|||||||
},
|
},
|
||||||
2);
|
2);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
@ -120,9 +118,9 @@ void tst_qpromise_reduce::regularValues()
|
|||||||
|
|
||||||
void tst_qpromise_reduce::promiseValues()
|
void tst_qpromise_reduce::promiseValues()
|
||||||
{
|
{
|
||||||
QVector<QPromise<int>> inputs{QtPromise::resolve(4).delay(400),
|
QVector<QtPromise::QPromise<int>> inputs{QtPromise::resolve(4).delay(400),
|
||||||
QtPromise::resolve(6).delay(300),
|
QtPromise::resolve(6).delay(300),
|
||||||
QtPromise::resolve(8).delay(200)};
|
QtPromise::resolve(8).delay(200)};
|
||||||
QVector<int> v0;
|
QVector<int> v0;
|
||||||
QVector<int> v1;
|
QVector<int> v1;
|
||||||
|
|
||||||
@ -137,8 +135,8 @@ void tst_qpromise_reduce::promiseValues()
|
|||||||
},
|
},
|
||||||
2);
|
2);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.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.
|
// NOTE(SB): when no initial value is given, the result type is the sequence type.
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QString>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, QString{}), QString{"foo:4:0:6:1:8:2"});
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo:4:0:6:1:8:2"});
|
||||||
@ -178,7 +176,7 @@ void tst_qpromise_reduce::delayedInitialValue()
|
|||||||
},
|
},
|
||||||
QtPromise::resolve(2).delay(100));
|
QtPromise::resolve(2).delay(100));
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isPending(), true);
|
QCOMPARE(p.isPending(), true);
|
||||||
QCOMPARE(waitForValue(p, -1), 23);
|
QCOMPARE(waitForValue(p, -1), 23);
|
||||||
@ -202,8 +200,8 @@ void tst_qpromise_reduce::delayedFulfilled()
|
|||||||
},
|
},
|
||||||
2);
|
2);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.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) {
|
auto p0 = QtPromise::resolve(inputs).reduce([&](int acc, int cur, int idx) {
|
||||||
v0 << acc << cur << idx;
|
v0 << acc << cur << idx;
|
||||||
if (cur == 6) {
|
if (cur == 6) {
|
||||||
return QPromise<int>::reject(QString{"foo"});
|
return QtPromise::QPromise<int>::reject(QString{"foo"});
|
||||||
}
|
}
|
||||||
return QtPromise::resolve(acc + cur + idx);
|
return QtPromise::resolve(acc + cur + idx);
|
||||||
});
|
});
|
||||||
@ -230,14 +228,14 @@ void tst_qpromise_reduce::delayedRejected()
|
|||||||
[&](int acc, int cur, int idx) {
|
[&](int acc, int cur, int idx) {
|
||||||
v1 << acc << cur << idx;
|
v1 << acc << cur << idx;
|
||||||
if (cur == 6) {
|
if (cur == 6) {
|
||||||
return QPromise<int>::reject(QString{"bar"});
|
return QtPromise::QPromise<int>::reject(QString{"bar"});
|
||||||
}
|
}
|
||||||
return QtPromise::resolve(acc + cur + idx);
|
return QtPromise::resolve(acc + cur + idx);
|
||||||
},
|
},
|
||||||
2);
|
2);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
@ -270,8 +268,8 @@ void tst_qpromise_reduce::functorThrows()
|
|||||||
},
|
},
|
||||||
2);
|
2);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
QCOMPARE(p0.isPending(), true);
|
QCOMPARE(p0.isPending(), true);
|
||||||
QCOMPARE(p1.isPending(), true);
|
QCOMPARE(p1.isPending(), true);
|
||||||
@ -285,10 +283,10 @@ void tst_qpromise_reduce::sequenceTypes()
|
|||||||
{
|
{
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||||
// QLinkedList is deprecated since Qt 5.15.
|
// QLinkedList is deprecated since Qt 5.15.
|
||||||
SequenceTester<QLinkedList<QPromise<int>>>::exec();
|
SequenceTester<QLinkedList<QtPromise::QPromise<int>>>::exec();
|
||||||
#endif
|
#endif
|
||||||
SequenceTester<QList<QPromise<int>>>::exec();
|
SequenceTester<QList<QtPromise::QPromise<int>>>::exec();
|
||||||
SequenceTester<QVector<QPromise<int>>>::exec();
|
SequenceTester<QVector<QtPromise::QPromise<int>>>::exec();
|
||||||
SequenceTester<std::list<QPromise<int>>>::exec();
|
SequenceTester<std::list<QtPromise::QPromise<int>>>::exec();
|
||||||
SequenceTester<std::vector<QPromise<int>>>::exec();
|
SequenceTester<std::vector<QtPromise::QPromise<int>>>::exec();
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_resolve : public QObject
|
class tst_qpromise_resolve : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -36,13 +34,13 @@ void tst_qpromise_resolve::value()
|
|||||||
int v0 = 42;
|
int v0 = 42;
|
||||||
const int v1 = 42;
|
const int v1 = 42;
|
||||||
|
|
||||||
auto p0 = QPromise<int>::resolve(42);
|
auto p0 = QtPromise::QPromise<int>::resolve(42);
|
||||||
auto p1 = QPromise<int>::resolve(v0);
|
auto p1 = QtPromise::QPromise<int>::resolve(v0);
|
||||||
auto p2 = QPromise<int>::resolve(v1);
|
auto p2 = QtPromise::QPromise<int>::resolve(v1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<int>>::value));
|
||||||
|
|
||||||
for (const auto& p : {p0, p1, p2}) {
|
for (const auto& p : {p0, p1, p2}) {
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
@ -54,9 +52,9 @@ void tst_qpromise_resolve::value()
|
|||||||
|
|
||||||
void tst_qpromise_resolve::noValue()
|
void tst_qpromise_resolve::noValue()
|
||||||
{
|
{
|
||||||
auto p = QPromise<void>::resolve();
|
auto p = QtPromise::QPromise<void>::resolve();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
|
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
QCOMPARE(waitForValue(p, -1, 42), 42);
|
QCOMPARE(waitForValue(p, -1, 42), 42);
|
||||||
@ -69,7 +67,7 @@ void tst_qpromise_resolve::moveRValue()
|
|||||||
{
|
{
|
||||||
auto p = QtPromise::resolve(Data{42}).wait();
|
auto p = QtPromise::resolve(Data{42}).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Data>>::value));
|
||||||
}
|
}
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 1);
|
QCOMPARE(Data::logs().ctor, 1);
|
||||||
@ -86,7 +84,7 @@ void tst_qpromise_resolve::copyLValue()
|
|||||||
Data value{42};
|
Data value{42};
|
||||||
auto p = QtPromise::resolve(value).wait();
|
auto p = QtPromise::resolve(value).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<Data>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<Data>>::value));
|
||||||
}
|
}
|
||||||
|
|
||||||
QCOMPARE(Data::logs().ctor, 1);
|
QCOMPARE(Data::logs().ctor, 1);
|
||||||
@ -98,24 +96,26 @@ void tst_qpromise_resolve::copyLValue()
|
|||||||
// https://github.com/simonbrunel/qtpromise/issues/6
|
// https://github.com/simonbrunel/qtpromise/issues/6
|
||||||
void tst_qpromise_resolve::qtSharedPtr()
|
void tst_qpromise_resolve::qtSharedPtr()
|
||||||
{
|
{
|
||||||
|
using DataSPtr = QSharedPointer<Data>;
|
||||||
|
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
QWeakPointer<Data> wptr;
|
QWeakPointer<Data> wptr;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto sptr0 = QSharedPointer<Data>::create(42);
|
auto sptr0 = DataSPtr::create(42);
|
||||||
const QSharedPointer<Data> sptr1 = sptr0;
|
const DataSPtr sptr1 = sptr0;
|
||||||
|
|
||||||
auto p0 = QPromise<QSharedPointer<Data>>::resolve(QSharedPointer<Data>::create(42));
|
auto p0 = QtPromise::QPromise<DataSPtr>::resolve(DataSPtr::create(42));
|
||||||
auto p1 = QPromise<QSharedPointer<Data>>::resolve(sptr0);
|
auto p1 = QtPromise::QPromise<DataSPtr>::resolve(sptr0);
|
||||||
auto p2 = QPromise<QSharedPointer<Data>>::resolve(sptr1);
|
auto p2 = QtPromise::QPromise<DataSPtr>::resolve(sptr1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<QSharedPointer<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p1, QSharedPointer<Data>{}), sptr0);
|
QCOMPARE(waitForValue(p1, DataSPtr{}), sptr0);
|
||||||
QCOMPARE(waitForValue(p2, QSharedPointer<Data>{}), sptr1);
|
QCOMPARE(waitForValue(p2, DataSPtr{}), sptr1);
|
||||||
|
|
||||||
wptr = sptr0;
|
wptr = sptr0;
|
||||||
|
|
||||||
@ -134,24 +134,26 @@ void tst_qpromise_resolve::qtSharedPtr()
|
|||||||
// https://github.com/simonbrunel/qtpromise/issues/6
|
// https://github.com/simonbrunel/qtpromise/issues/6
|
||||||
void tst_qpromise_resolve::stdSharedPtr()
|
void tst_qpromise_resolve::stdSharedPtr()
|
||||||
{
|
{
|
||||||
|
using DataSPtr = std::shared_ptr<Data>;
|
||||||
|
|
||||||
Data::logs().reset();
|
Data::logs().reset();
|
||||||
|
|
||||||
std::weak_ptr<Data> wptr;
|
std::weak_ptr<Data> wptr;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto sptr0 = std::make_shared<Data>(42);
|
auto sptr0 = std::make_shared<Data>(42);
|
||||||
const std::shared_ptr<Data> sptr1 = sptr0;
|
const DataSPtr sptr1 = sptr0;
|
||||||
|
|
||||||
auto p0 = QPromise<std::shared_ptr<Data>>::resolve(std::make_shared<Data>(42));
|
auto p0 = QtPromise::QPromise<DataSPtr>::resolve(std::make_shared<Data>(42));
|
||||||
auto p1 = QPromise<std::shared_ptr<Data>>::resolve(sptr0);
|
auto p1 = QtPromise::QPromise<DataSPtr>::resolve(sptr0);
|
||||||
auto p2 = QPromise<std::shared_ptr<Data>>::resolve(sptr1);
|
auto p2 = QtPromise::QPromise<DataSPtr>::resolve(sptr1);
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p0), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p0), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p1), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<std::shared_ptr<Data>>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<DataSPtr>>::value));
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p1, std::shared_ptr<Data>{}), sptr0);
|
QCOMPARE(waitForValue(p1, DataSPtr{}), sptr0);
|
||||||
QCOMPARE(waitForValue(p2, std::shared_ptr<Data>{}), sptr1);
|
QCOMPARE(waitForValue(p2, DataSPtr{}), sptr1);
|
||||||
|
|
||||||
wptr = sptr0;
|
wptr = sptr0;
|
||||||
|
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_tap : public QObject
|
class tst_qpromise_tap : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -33,7 +31,7 @@ QTEST_MAIN(tst_qpromise_tap)
|
|||||||
void tst_qpromise_tap::fulfilledSync()
|
void tst_qpromise_tap::fulfilledSync()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<int>::resolve(42).tap([&](int res) {
|
auto p = QtPromise::QPromise<int>::resolve(42).tap([&](int res) {
|
||||||
value = res + 1;
|
value = res + 1;
|
||||||
return 8;
|
return 8;
|
||||||
});
|
});
|
||||||
@ -46,7 +44,7 @@ void tst_qpromise_tap::fulfilledSync()
|
|||||||
void tst_qpromise_tap::fulfilledSync_void()
|
void tst_qpromise_tap::fulfilledSync_void()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<void>::resolve().tap([&]() {
|
auto p = QtPromise::QPromise<void>::resolve().tap([&]() {
|
||||||
value = 43;
|
value = 43;
|
||||||
return 8;
|
return 8;
|
||||||
});
|
});
|
||||||
@ -58,7 +56,7 @@ void tst_qpromise_tap::fulfilledSync_void()
|
|||||||
|
|
||||||
void tst_qpromise_tap::fulfilledThrows()
|
void tst_qpromise_tap::fulfilledThrows()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::resolve(42).tap([&](int) {
|
auto p = QtPromise::QPromise<int>::resolve(42).tap([&](int) {
|
||||||
throw QString{"foo"};
|
throw QString{"foo"};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -68,7 +66,7 @@ void tst_qpromise_tap::fulfilledThrows()
|
|||||||
|
|
||||||
void tst_qpromise_tap::fulfilledThrows_void()
|
void tst_qpromise_tap::fulfilledThrows_void()
|
||||||
{
|
{
|
||||||
auto p = QPromise<void>::resolve().tap([&]() {
|
auto p = QtPromise::QPromise<void>::resolve().tap([&]() {
|
||||||
throw QString{"foo"};
|
throw QString{"foo"};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -79,8 +77,8 @@ void tst_qpromise_tap::fulfilledThrows_void()
|
|||||||
void tst_qpromise_tap::fulfilledAsyncResolve()
|
void tst_qpromise_tap::fulfilledAsyncResolve()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<int>::resolve(1).tap([&](int) {
|
auto p = QtPromise::QPromise<int>::resolve(1).tap([&](int) {
|
||||||
QPromise<int> p{[&](const QPromiseResolve<int>& resolve) {
|
QtPromise::QPromise<int> p{[&](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values << 3;
|
values << 3;
|
||||||
resolve(4); // ignored!
|
resolve(4); // ignored!
|
||||||
@ -102,8 +100,9 @@ void tst_qpromise_tap::fulfilledAsyncResolve()
|
|||||||
void tst_qpromise_tap::fulfilledAsyncReject()
|
void tst_qpromise_tap::fulfilledAsyncReject()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<int>::resolve(1).tap([&](int) {
|
auto p = QtPromise::QPromise<int>::resolve(1).tap([&](int) {
|
||||||
QPromise<int> p{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QtPromise::QPromise<int> p{[&](const QtPromise::QPromiseResolve<int>&,
|
||||||
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values << 3;
|
values << 3;
|
||||||
reject(QString{"foo"});
|
reject(QString{"foo"});
|
||||||
@ -126,7 +125,7 @@ void tst_qpromise_tap::fulfilledAsyncReject()
|
|||||||
void tst_qpromise_tap::rejectedSync()
|
void tst_qpromise_tap::rejectedSync()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<int>::reject(QString{"foo"}).tap([&](int res) {
|
auto p = QtPromise::QPromise<int>::reject(QString{"foo"}).tap([&](int res) {
|
||||||
value = res + 1;
|
value = res + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -138,7 +137,7 @@ void tst_qpromise_tap::rejectedSync()
|
|||||||
void tst_qpromise_tap::rejectedSync_void()
|
void tst_qpromise_tap::rejectedSync_void()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<void>::reject(QString{"foo"}).tap([&]() {
|
auto p = QtPromise::QPromise<void>::reject(QString{"foo"}).tap([&]() {
|
||||||
value = 43;
|
value = 43;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_tapfail : public QObject
|
class tst_qpromise_tapfail : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -33,7 +31,7 @@ QTEST_MAIN(tst_qpromise_tapfail)
|
|||||||
void tst_qpromise_tapfail::fulfilled()
|
void tst_qpromise_tapfail::fulfilled()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<int>::resolve(42).tapFail([&]() {
|
auto p = QtPromise::QPromise<int>::resolve(42).tapFail([&]() {
|
||||||
value = 43;
|
value = 43;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -45,7 +43,7 @@ void tst_qpromise_tapfail::fulfilled()
|
|||||||
void tst_qpromise_tapfail::fulfilled_void()
|
void tst_qpromise_tapfail::fulfilled_void()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p = QPromise<void>::resolve().tapFail([&]() {
|
auto p = QtPromise::QPromise<void>::resolve().tapFail([&]() {
|
||||||
value = 43;
|
value = 43;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -58,7 +56,7 @@ void tst_qpromise_tapfail::rejected()
|
|||||||
{
|
{
|
||||||
QStringList errors;
|
QStringList errors;
|
||||||
|
|
||||||
auto p0 = QPromise<int>::reject(QString{"foo"}).tapFail([&](const QString& err) {
|
auto p0 = QtPromise::QPromise<int>::reject(QString{"foo"}).tapFail([&](const QString& err) {
|
||||||
errors << "1:" + err;
|
errors << "1:" + err;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -78,7 +76,7 @@ void tst_qpromise_tapfail::rejected_void()
|
|||||||
{
|
{
|
||||||
QStringList errors;
|
QStringList errors;
|
||||||
|
|
||||||
auto p0 = QPromise<void>::reject(QString{"foo"}).tapFail([&](const QString& err) {
|
auto p0 = QtPromise::QPromise<void>::reject(QString{"foo"}).tapFail([&](const QString& err) {
|
||||||
errors << "1:" + err;
|
errors << "1:" + err;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -95,7 +93,7 @@ void tst_qpromise_tapfail::rejected_void()
|
|||||||
|
|
||||||
void tst_qpromise_tapfail::throws()
|
void tst_qpromise_tapfail::throws()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::reject(QString{"foo"}).tapFail([&]() {
|
auto p = QtPromise::QPromise<int>::reject(QString{"foo"}).tapFail([&]() {
|
||||||
throw QString{"bar"};
|
throw QString{"bar"};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -105,7 +103,7 @@ void tst_qpromise_tapfail::throws()
|
|||||||
|
|
||||||
void tst_qpromise_tapfail::throws_void()
|
void tst_qpromise_tapfail::throws_void()
|
||||||
{
|
{
|
||||||
auto p = QPromise<void>::reject(QString{"foo"}).tapFail([&]() {
|
auto p = QtPromise::QPromise<void>::reject(QString{"foo"}).tapFail([&]() {
|
||||||
throw QString{"bar"};
|
throw QString{"bar"};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -116,8 +114,8 @@ void tst_qpromise_tapfail::throws_void()
|
|||||||
void tst_qpromise_tapfail::delayedResolved()
|
void tst_qpromise_tapfail::delayedResolved()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<int>::reject(QString{"foo"}).tapFail([&]() {
|
auto p = QtPromise::QPromise<int>::reject(QString{"foo"}).tapFail([&]() {
|
||||||
QPromise<void> p{[&](const QPromiseResolve<void>& resolve) {
|
QtPromise::QPromise<void> p{[&](const QtPromise::QPromiseResolve<void>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values << 3;
|
values << 3;
|
||||||
resolve(); // ignored!
|
resolve(); // ignored!
|
||||||
@ -135,8 +133,9 @@ void tst_qpromise_tapfail::delayedResolved()
|
|||||||
void tst_qpromise_tapfail::delayedRejected()
|
void tst_qpromise_tapfail::delayedRejected()
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
auto p = QPromise<int>::reject(QString{"foo"}).tapFail([&]() {
|
auto p = QtPromise::QPromise<int>::reject(QString{"foo"}).tapFail([&]() {
|
||||||
QPromise<void> p{[&](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
QtPromise::QPromise<void> p{[&](const QtPromise::QPromiseResolve<void>&,
|
||||||
|
const QtPromise::QPromiseReject<void>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
QtPromisePrivate::qtpromise_defer([=, &values]() {
|
||||||
values << 3;
|
values << 3;
|
||||||
reject(QString{"bar"});
|
reject(QString{"bar"});
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_then : public QObject
|
class tst_qpromise_then : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -76,7 +74,7 @@ void tst_qpromise_then::resolveSync()
|
|||||||
{
|
{
|
||||||
QVariantList values;
|
QVariantList values;
|
||||||
|
|
||||||
auto input = QPromise<int>::resolve(42);
|
auto input = QtPromise::QPromise<int>::resolve(42);
|
||||||
auto output = input.then([&](int res) {
|
auto output = input.then([&](int res) {
|
||||||
values << res;
|
values << res;
|
||||||
return QString::number(res + 1);
|
return QString::number(res + 1);
|
||||||
@ -98,22 +96,23 @@ void tst_qpromise_then::resolveSync()
|
|||||||
|
|
||||||
void tst_qpromise_then::resolveAsync()
|
void tst_qpromise_then::resolveAsync()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::resolve(42).then([](int res) {
|
auto p = QtPromise::QPromise<int>::resolve(42).then([](int res) {
|
||||||
return QPromise<QString>{[=](const QPromiseResolve<QString>& resolve) {
|
return QtPromise::QPromise<QString>{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[=](const QtPromise::QPromiseResolve<QString>& resolve) {
|
||||||
resolve(QString{"foo%1"}.arg(res));
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
});
|
resolve(QString{"foo%1"}.arg(res));
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<QString>>::value));
|
||||||
QCOMPARE(waitForValue(p, QString{}), QString{"foo42"});
|
QCOMPARE(waitForValue(p, QString{}), QString{"foo42"});
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_then::rejectSync()
|
void tst_qpromise_then::rejectSync()
|
||||||
{
|
{
|
||||||
auto input = QPromise<int>::resolve(42);
|
auto input = QtPromise::QPromise<int>::resolve(42);
|
||||||
auto output = input.then([](int res) {
|
auto output = input.then([](int res) {
|
||||||
throw QString{"foo%1"}.arg(res);
|
throw QString{"foo%1"}.arg(res);
|
||||||
return 42;
|
return 42;
|
||||||
@ -136,43 +135,43 @@ void tst_qpromise_then::rejectSync()
|
|||||||
|
|
||||||
void tst_qpromise_then::rejectAsync()
|
void tst_qpromise_then::rejectAsync()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::resolve(42).then([](int res) {
|
auto p = QtPromise::QPromise<int>::resolve(42).then([](int res) {
|
||||||
return QPromise<void>{
|
return QtPromise::QPromise<void>{[=](const QtPromise::QPromiseResolve<void>&,
|
||||||
[=](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
const QtPromise::QPromiseReject<void>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString{"foo%1"}.arg(res));
|
reject(QString{"foo%1"}.arg(res));
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<void>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<void>>::value));
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo42"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo42"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_then::skipResult()
|
void tst_qpromise_then::skipResult()
|
||||||
{
|
{
|
||||||
auto p = QPromise<int>::resolve(42);
|
auto p = QtPromise::QPromise<int>::resolve(42);
|
||||||
|
|
||||||
int value = -1;
|
int value = -1;
|
||||||
p.then([&]() {
|
p.then([&]() {
|
||||||
value = 43;
|
value = 43;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p), QPromise<int>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p), QtPromise::QPromise<int>>::value));
|
||||||
QCOMPARE(value, 43);
|
QCOMPARE(value, 43);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qpromise_then::nullHandler()
|
void tst_qpromise_then::nullHandler()
|
||||||
{
|
{
|
||||||
{ // resolved
|
{ // resolved
|
||||||
auto p = QPromise<int>::resolve(42).then(nullptr);
|
auto p = QtPromise::QPromise<int>::resolve(42).then(nullptr);
|
||||||
|
|
||||||
QCOMPARE(waitForValue(p, -1), 42);
|
QCOMPARE(waitForValue(p, -1), 42);
|
||||||
QCOMPARE(p.isFulfilled(), true);
|
QCOMPARE(p.isFulfilled(), true);
|
||||||
}
|
}
|
||||||
{ // rejected
|
{ // rejected
|
||||||
auto p = QPromise<int>::reject(QString{"foo"}).then(nullptr);
|
auto p = QtPromise::QPromise<int>::reject(QString{"foo"}).then(nullptr);
|
||||||
|
|
||||||
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
QCOMPARE(waitForError(p, QString{}), QString{"foo"});
|
||||||
QCOMPARE(p.isRejected(), true);
|
QCOMPARE(p.isRejected(), true);
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromise_timeout : public QObject
|
class tst_qpromise_timeout : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -38,7 +36,7 @@ void tst_qpromise_timeout::fulfilled()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
auto p = QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QTimer::singleShot(1000, [=]() {
|
QTimer::singleShot(1000, [=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
@ -59,7 +57,8 @@ void tst_qpromise_timeout::rejected()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
auto p = QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>&,
|
||||||
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QTimer::singleShot(1000, [=]() {
|
QTimer::singleShot(1000, [=]() {
|
||||||
reject(QString{"foo"});
|
reject(QString{"foo"});
|
||||||
});
|
});
|
||||||
@ -81,7 +80,7 @@ void tst_qpromise_timeout::timeout()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
auto p = QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QTimer::singleShot(4000, [=]() {
|
QTimer::singleShot(4000, [=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
@ -90,7 +89,7 @@ void tst_qpromise_timeout::timeout()
|
|||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
p.fail([&](const QPromiseTimeoutException&) {
|
p.fail([&](const QtPromise::QPromiseTimeoutException&) {
|
||||||
failed = true;
|
failed = true;
|
||||||
return -1;
|
return -1;
|
||||||
}).wait();
|
}).wait();
|
||||||
@ -113,7 +112,7 @@ void tst_qpromise_timeout::fulfilledStdChrono()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
auto p = QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QTimer::singleShot(1000, [=]() {
|
QTimer::singleShot(1000, [=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
@ -134,7 +133,8 @@ void tst_qpromise_timeout::rejectedStdChrono()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
auto p = QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>&,
|
||||||
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QTimer::singleShot(1000, [=]() {
|
QTimer::singleShot(1000, [=]() {
|
||||||
reject(QString{"foo"});
|
reject(QString{"foo"});
|
||||||
});
|
});
|
||||||
@ -156,7 +156,7 @@ void tst_qpromise_timeout::timeoutStdChrono()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
auto p = QPromise<int>{[](const QPromiseResolve<int>& resolve) {
|
auto p = QtPromise::QPromise<int>{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QTimer::singleShot(4000, [=]() {
|
QTimer::singleShot(4000, [=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
@ -165,7 +165,7 @@ void tst_qpromise_timeout::timeoutStdChrono()
|
|||||||
elapsed = timer.elapsed();
|
elapsed = timer.elapsed();
|
||||||
});
|
});
|
||||||
|
|
||||||
p.fail([&](const QPromiseTimeoutException&) {
|
p.fail([&](const QtPromise::QPromiseTimeoutException&) {
|
||||||
failed = true;
|
failed = true;
|
||||||
return -1;
|
return -1;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_qpromiseconnections : public QObject
|
class tst_qpromiseconnections : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -31,7 +29,7 @@ void tst_qpromiseconnections::connections()
|
|||||||
{
|
{
|
||||||
Object sender;
|
Object sender;
|
||||||
|
|
||||||
QPromiseConnections connections;
|
QtPromise::QPromiseConnections connections;
|
||||||
QCOMPARE(sender.hasConnections(), false);
|
QCOMPARE(sender.hasConnections(), false);
|
||||||
QCOMPARE(connections.count(), 0);
|
QCOMPARE(connections.count(), 0);
|
||||||
|
|
||||||
@ -53,7 +51,7 @@ void tst_qpromiseconnections::destruction()
|
|||||||
Object sender;
|
Object sender;
|
||||||
|
|
||||||
{
|
{
|
||||||
QPromiseConnections connections;
|
QtPromise::QPromiseConnections connections;
|
||||||
QCOMPARE(sender.hasConnections(), false);
|
QCOMPARE(sender.hasConnections(), false);
|
||||||
QCOMPARE(connections.count(), 0);
|
QCOMPARE(connections.count(), 0);
|
||||||
|
|
||||||
@ -67,7 +65,7 @@ void tst_qpromiseconnections::destruction()
|
|||||||
|
|
||||||
void tst_qpromiseconnections::senderDestroyed()
|
void tst_qpromiseconnections::senderDestroyed()
|
||||||
{
|
{
|
||||||
QPromiseConnections connections;
|
QtPromise::QPromiseConnections connections;
|
||||||
QCOMPARE(connections.count(), 0);
|
QCOMPARE(connections.count(), 0);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
// https://promisesaplus.com/#requirements
|
// https://promisesaplus.com/#requirements
|
||||||
class tst_requirements : public QObject
|
class tst_requirements : public QObject
|
||||||
{
|
{
|
||||||
@ -43,7 +41,7 @@ void tst_requirements::statePending()
|
|||||||
// 2.1.1. When pending, a promise:
|
// 2.1.1. When pending, a promise:
|
||||||
// 2.1.1.1. may transition to either the fulfilled state
|
// 2.1.1.1. may transition to either the fulfilled state
|
||||||
{
|
{
|
||||||
QPromise<int> p{[&](const QPromiseResolve<int>& resolve) {
|
QtPromise::QPromise<int> p{[&](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
@ -62,7 +60,8 @@ void tst_requirements::statePending()
|
|||||||
|
|
||||||
// 2.1.1.1. ... or the rejected state
|
// 2.1.1.1. ... or the rejected state
|
||||||
{
|
{
|
||||||
QPromise<int> p{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QtPromise::QPromise<int> p{[&](const QtPromise::QPromiseResolve<int>&,
|
||||||
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString{"foo"});
|
reject(QString{"foo"});
|
||||||
});
|
});
|
||||||
@ -86,7 +85,8 @@ void tst_requirements::stateFulfilled()
|
|||||||
int value = -1;
|
int value = -1;
|
||||||
|
|
||||||
// 2.1.2. When fulfilled, a promise:
|
// 2.1.2. When fulfilled, a promise:
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
|
QtPromise::QPromise<int> p{[](const QtPromise::QPromiseResolve<int>& resolve,
|
||||||
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
// 2.1.2.2. must have a value, which must not change.
|
// 2.1.2.2. must have a value, which must not change.
|
||||||
resolve(42);
|
resolve(42);
|
||||||
@ -120,7 +120,8 @@ void tst_requirements::stateRejected()
|
|||||||
int value = -1;
|
int value = -1;
|
||||||
|
|
||||||
// 2.1.3 When rejected, a promise:
|
// 2.1.3 When rejected, a promise:
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
|
QtPromise::QPromise<int> p{[](const QtPromise::QPromiseResolve<int>& resolve,
|
||||||
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
// 2.1.3.2. must have a reason, which must not change.
|
// 2.1.3.2. must have a reason, which must not change.
|
||||||
reject(QString{"foo"});
|
reject(QString{"foo"});
|
||||||
@ -154,7 +155,7 @@ void tst_requirements::thenArguments()
|
|||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
int value = -1;
|
int value = -1;
|
||||||
QPromise<int>::resolve(42)
|
QtPromise::QPromise<int>::resolve(42)
|
||||||
.then(
|
.then(
|
||||||
[&](int res) {
|
[&](int res) {
|
||||||
value = res;
|
value = res;
|
||||||
@ -170,7 +171,7 @@ void tst_requirements::thenArguments()
|
|||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
int value = -1;
|
int value = -1;
|
||||||
QPromise<int>::reject(QString{"foo"})
|
QtPromise::QPromise<int>::reject(QString{"foo"})
|
||||||
.then(
|
.then(
|
||||||
[&](int res) {
|
[&](int res) {
|
||||||
value = res;
|
value = res;
|
||||||
@ -187,7 +188,7 @@ void tst_requirements::thenArguments()
|
|||||||
// 2.2.1. onFulfilled is an optional arguments:
|
// 2.2.1. onFulfilled is an optional arguments:
|
||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
QPromise<int>::reject(QString{"foo"})
|
QtPromise::QPromise<int>::reject(QString{"foo"})
|
||||||
.then(nullptr,
|
.then(nullptr,
|
||||||
[&](const QString& err) {
|
[&](const QString& err) {
|
||||||
error = err;
|
error = err;
|
||||||
@ -201,7 +202,7 @@ void tst_requirements::thenArguments()
|
|||||||
// 2.2.1. onRejected is an optional arguments:
|
// 2.2.1. onRejected is an optional arguments:
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
QPromise<int>::resolve(42)
|
QtPromise::QPromise<int>::resolve(42)
|
||||||
.then([&value](int res) {
|
.then([&value](int res) {
|
||||||
value = res;
|
value = res;
|
||||||
})
|
})
|
||||||
@ -219,7 +220,7 @@ void tst_requirements::thenOnFulfilled()
|
|||||||
{
|
{
|
||||||
// 2.2.2. If onFulfilled is a function:
|
// 2.2.2. If onFulfilled is a function:
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
QPromise<int> p0{[](const QPromiseResolve<int>& resolve) {
|
QtPromise::QPromise<int> p0{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
// 2.2.2.3. it must not be called more than once
|
// 2.2.2.3. it must not be called more than once
|
||||||
resolve(42);
|
resolve(42);
|
||||||
@ -249,13 +250,14 @@ void tst_requirements::thenOnRejected()
|
|||||||
{
|
{
|
||||||
// 2.2.3. If onRejected is a function:
|
// 2.2.3. If onRejected is a function:
|
||||||
QStringList errors;
|
QStringList errors;
|
||||||
QPromise<void> p0{[](const QPromiseResolve<void>&, const QPromiseReject<void>& reject) {
|
QtPromise::QPromise<void> p0{
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
[](const QtPromise::QPromiseResolve<void>&, const QtPromise::QPromiseReject<void>& reject) {
|
||||||
// 2.2.3.3. it must not be called more than once.
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(QString{"foo"});
|
// 2.2.3.3. it must not be called more than once.
|
||||||
reject(QString{"bar"});
|
reject(QString{"foo"});
|
||||||
});
|
reject(QString{"bar"});
|
||||||
}};
|
});
|
||||||
|
}};
|
||||||
|
|
||||||
auto p1 = p0.then(nullptr, [&](const QString& err) {
|
auto p1 = p0.then(nullptr, [&](const QString& err) {
|
||||||
errors << err;
|
errors << err;
|
||||||
@ -282,7 +284,7 @@ void tst_requirements::thenAsynchronous()
|
|||||||
// loop turn in which then is called, and with a fresh stack).
|
// loop turn in which then is called, and with a fresh stack).
|
||||||
|
|
||||||
int value = -1;
|
int value = -1;
|
||||||
auto p0 = QPromise<int>::resolve(42);
|
auto p0 = QtPromise::QPromise<int>::resolve(42);
|
||||||
QVERIFY(p0.isFulfilled());
|
QVERIFY(p0.isFulfilled());
|
||||||
|
|
||||||
auto p1 = p0.then([&](int res) {
|
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:
|
// must execute in the order of their originating calls to then:
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>& resolve) {
|
QtPromise::QPromise<int> p{[](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
|
|
||||||
QtPromise::all(QVector<QPromise<void>>{p.then([&](int r) {
|
QtPromise::all(QVector<QtPromise::QPromise<void>>{p.then([&](int r) {
|
||||||
values << r + 1;
|
values << r + 1;
|
||||||
}),
|
}),
|
||||||
p.then([&](int r) {
|
p.then([&](int r) {
|
||||||
values << r + 2;
|
values << r + 2;
|
||||||
}),
|
}),
|
||||||
p.then([&](int r) {
|
p.then([&](int r) {
|
||||||
values << r + 3;
|
values << r + 3;
|
||||||
})})
|
})})
|
||||||
.wait();
|
.wait();
|
||||||
|
|
||||||
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
QCOMPARE(values, (QVector<int>{43, 44, 45}));
|
||||||
@ -328,27 +330,28 @@ void tst_requirements::thenMultipleCalls()
|
|||||||
// must execute in the order of their originating calls to then:
|
// must execute in the order of their originating calls to then:
|
||||||
{
|
{
|
||||||
QVector<int> values;
|
QVector<int> values;
|
||||||
QPromise<int> p{[](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QtPromise::QPromise<int> p{[](const QtPromise::QPromiseResolve<int>&,
|
||||||
|
const QtPromise::QPromiseReject<int>& reject) {
|
||||||
QtPromisePrivate::qtpromise_defer([=]() {
|
QtPromisePrivate::qtpromise_defer([=]() {
|
||||||
reject(8);
|
reject(8);
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
|
|
||||||
QtPromise::all(QVector<QPromise<int>>{p.then(nullptr,
|
QtPromise::all(QVector<QtPromise::QPromise<int>>{p.then(nullptr,
|
||||||
[&](int r) {
|
[&](int r) {
|
||||||
values << r + 1;
|
values << r + 1;
|
||||||
return r + 1;
|
return r + 1;
|
||||||
}),
|
}),
|
||||||
p.then(nullptr,
|
p.then(nullptr,
|
||||||
[&](int r) {
|
[&](int r) {
|
||||||
values << r + 2;
|
values << r + 2;
|
||||||
return r + 2;
|
return r + 2;
|
||||||
}),
|
}),
|
||||||
p.then(nullptr,
|
p.then(nullptr,
|
||||||
[&](int r) {
|
[&](int r) {
|
||||||
values << r + 3;
|
values << r + 3;
|
||||||
return r + 3;
|
return r + 3;
|
||||||
})})
|
})})
|
||||||
.wait();
|
.wait();
|
||||||
|
|
||||||
QCOMPARE(values, (QVector<int>{9, 10, 11}));
|
QCOMPARE(values, (QVector<int>{9, 10, 11}));
|
||||||
@ -362,10 +365,13 @@ void tst_requirements::thenHandlers()
|
|||||||
auto handler = []() {
|
auto handler = []() {
|
||||||
return 42;
|
return 42;
|
||||||
};
|
};
|
||||||
auto p1 = QPromise<int>::resolve(42);
|
auto p1 = QtPromise::QPromise<int>::resolve(42);
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1.then(handler, nullptr)), QPromise<int>>::value));
|
Q_STATIC_ASSERT(
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1.then(nullptr, handler)), QPromise<int>>::value));
|
(std::is_same<decltype(p1.then(handler, nullptr)), QtPromise::QPromise<int>>::value));
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p1.then(handler, handler)), QPromise<int>>::value));
|
Q_STATIC_ASSERT(
|
||||||
|
(std::is_same<decltype(p1.then(nullptr, handler)), QtPromise::QPromise<int>>::value));
|
||||||
|
Q_STATIC_ASSERT(
|
||||||
|
(std::is_same<decltype(p1.then(handler, handler)), QtPromise::QPromise<int>>::value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.2.7.1. If either onFulfilled or onRejected returns a value x, run the
|
// 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.
|
// p2 must be rejected with e as the reason.
|
||||||
{
|
{
|
||||||
QString reason;
|
QString reason;
|
||||||
auto p1 = QPromise<int>::resolve(42);
|
auto p1 = QtPromise::QPromise<int>::resolve(42);
|
||||||
auto p2 = p1.then([]() {
|
auto p2 = p1.then([]() {
|
||||||
throw QString{"foo"};
|
throw QString{"foo"};
|
||||||
});
|
});
|
||||||
@ -389,7 +395,7 @@ void tst_requirements::thenHandlers()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
QString reason;
|
QString reason;
|
||||||
auto p1 = QPromise<int>::reject(QString{"foo"});
|
auto p1 = QtPromise::QPromise<int>::reject(QString{"foo"});
|
||||||
auto p2 = p1.then(nullptr, []() {
|
auto p2 = p1.then(nullptr, []() {
|
||||||
throw QString{"bar"};
|
throw QString{"bar"};
|
||||||
return 42;
|
return 42;
|
||||||
@ -408,11 +414,11 @@ void tst_requirements::thenHandlers()
|
|||||||
// p2 must be fulfilled with the same value as promise1
|
// p2 must be fulfilled with the same value as promise1
|
||||||
{
|
{
|
||||||
QString value;
|
QString value;
|
||||||
auto p1 = QPromise<QString>::resolve("42");
|
auto p1 = QtPromise::QPromise<QString>::resolve("42");
|
||||||
auto p2 = p1.then(nullptr, []() {
|
auto p2 = p1.then(nullptr, []() {
|
||||||
return QString{};
|
return QString{};
|
||||||
});
|
});
|
||||||
Q_STATIC_ASSERT((std::is_same<decltype(p2), QPromise<QString>>::value));
|
Q_STATIC_ASSERT((std::is_same<decltype(p2), QtPromise::QPromise<QString>>::value));
|
||||||
p2.then([&](const QString& e) {
|
p2.then([&](const QString& e) {
|
||||||
value = e;
|
value = e;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
@ -7,6 +7,6 @@ add_library(${PROJECT_NAME} STATIC
|
|||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC
|
target_link_libraries(${PROJECT_NAME} PUBLIC
|
||||||
Qt5::Core
|
Qt${QT_VERSION_MAJOR}::Core
|
||||||
qtpromise
|
qtpromise
|
||||||
)
|
)
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
#include <QtPromise>
|
#include <QtPromise>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace QtPromise;
|
|
||||||
|
|
||||||
class tst_thread : public QObject
|
class tst_thread : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -35,8 +33,8 @@ void tst_thread::resolve()
|
|||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
|
|
||||||
QPromise<int>{[&](const QPromiseResolve<int>& resolve) {
|
QtPromise::QPromise<int>{[&](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
QtConcurrent::run([=, &source]() {
|
std::ignore = QtConcurrent::run([=, &source]() {
|
||||||
source = QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
@ -59,8 +57,8 @@ void tst_thread::resolve_void()
|
|||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
|
|
||||||
QPromise<void>{[&](const QPromiseResolve<void>& resolve) {
|
QtPromise::QPromise<void>{[&](const QtPromise::QPromiseResolve<void>& resolve) {
|
||||||
QtConcurrent::run([=, &source]() {
|
std::ignore = QtConcurrent::run([=, &source]() {
|
||||||
source = QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
@ -83,12 +81,13 @@ void tst_thread::reject()
|
|||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
|
|
||||||
QPromise<int>{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QtPromise::QPromise<int>{
|
||||||
QtConcurrent::run([=, &source]() {
|
[&](const QtPromise::QPromiseResolve<int>&, const QtPromise::QPromiseReject<int>& reject) {
|
||||||
source = QThread::currentThread();
|
std::ignore = QtConcurrent::run([=, &source]() {
|
||||||
reject(QString{"foo"});
|
source = QThread::currentThread();
|
||||||
});
|
reject(QString{"foo"});
|
||||||
}}
|
});
|
||||||
|
}}
|
||||||
.fail([&](const QString& err) {
|
.fail([&](const QString& err) {
|
||||||
target = QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
error = err;
|
error = err;
|
||||||
@ -105,7 +104,7 @@ void tst_thread::reject()
|
|||||||
void tst_thread::then()
|
void tst_thread::then()
|
||||||
{
|
{
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
QPromise<int> p{[&](const QPromiseResolve<int>& resolve) {
|
QtPromise::QPromise<int> p{[&](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
source = QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve(42);
|
resolve(42);
|
||||||
}};
|
}};
|
||||||
@ -113,7 +112,7 @@ void tst_thread::then()
|
|||||||
int value = -1;
|
int value = -1;
|
||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
QtPromise::resolve(QtConcurrent::run(
|
QtPromise::resolve(QtConcurrent::run(
|
||||||
[&](const QPromise<int>& p) {
|
[&](const QtPromise::QPromise<int>& p) {
|
||||||
p.then([&](int res) {
|
p.then([&](int res) {
|
||||||
target = QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
value = res;
|
value = res;
|
||||||
@ -131,7 +130,7 @@ void tst_thread::then()
|
|||||||
void tst_thread::then_void()
|
void tst_thread::then_void()
|
||||||
{
|
{
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
QPromise<void> p{[&](const QPromiseResolve<void>& resolve) {
|
QtPromise::QPromise<void> p{[&](const QtPromise::QPromiseResolve<void>& resolve) {
|
||||||
source = QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve();
|
resolve();
|
||||||
}};
|
}};
|
||||||
@ -139,7 +138,7 @@ void tst_thread::then_void()
|
|||||||
int value = -1;
|
int value = -1;
|
||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
QtPromise::resolve(QtConcurrent::run(
|
QtPromise::resolve(QtConcurrent::run(
|
||||||
[&](const QPromise<void>& p) {
|
[&](const QtPromise::QPromise<void>& p) {
|
||||||
p.then([&]() {
|
p.then([&]() {
|
||||||
target = QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
value = 43;
|
value = 43;
|
||||||
@ -157,15 +156,16 @@ void tst_thread::then_void()
|
|||||||
void tst_thread::fail()
|
void tst_thread::fail()
|
||||||
{
|
{
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
QPromise<int> p{[&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QtPromise::QPromise<int> p{
|
||||||
source = QThread::currentThread();
|
[&](const QtPromise::QPromiseResolve<int>&, const QtPromise::QPromiseReject<int>& reject) {
|
||||||
reject(QString{"foo"});
|
source = QThread::currentThread();
|
||||||
}};
|
reject(QString{"foo"});
|
||||||
|
}};
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
QtPromise::resolve(QtConcurrent::run(
|
QtPromise::resolve(QtConcurrent::run(
|
||||||
[&](const QPromise<int>& p) {
|
[&](const QtPromise::QPromise<int>& p) {
|
||||||
p.fail([&](const QString& err) {
|
p.fail([&](const QString& err) {
|
||||||
target = QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
error = err;
|
error = err;
|
||||||
@ -184,7 +184,7 @@ void tst_thread::fail()
|
|||||||
void tst_thread::finally()
|
void tst_thread::finally()
|
||||||
{
|
{
|
||||||
QThread* source = nullptr;
|
QThread* source = nullptr;
|
||||||
QPromise<int> p{[&](const QPromiseResolve<int>& resolve) {
|
QtPromise::QPromise<int> p{[&](const QtPromise::QPromiseResolve<int>& resolve) {
|
||||||
source = QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve(42);
|
resolve(42);
|
||||||
}};
|
}};
|
||||||
@ -192,7 +192,7 @@ void tst_thread::finally()
|
|||||||
int value = -1;
|
int value = -1;
|
||||||
QThread* target = nullptr;
|
QThread* target = nullptr;
|
||||||
QtPromise::resolve(QtConcurrent::run(
|
QtPromise::resolve(QtConcurrent::run(
|
||||||
[&](const QPromise<int>& p) {
|
[&](const QtPromise::QPromise<int>& p) {
|
||||||
p.finally([&]() {
|
p.finally([&]() {
|
||||||
target = QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
value = 43;
|
value = 43;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user