-
Notifications
You must be signed in to change notification settings - Fork 60
/
utils.h
75 lines (67 loc) · 1.61 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* 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.
*/
#ifndef QTPROMISE_TESTS_AUTO_SHARED_UTILS_H
#define QTPROMISE_TESTS_AUTO_SHARED_UTILS_H
#include <QtPromise>
template<typename T>
static inline T waitForValue(const QtPromise::QPromise<T>& promise, const T& initial)
{
T value(initial);
promise
.then([&](const T& res) {
value = res;
})
.wait();
return value;
}
template<typename T>
static inline T
waitForValue(const QtPromise::QPromise<void>& promise, const T& initial, const T& expected)
{
T value(initial);
promise
.then([&]() {
value = expected;
})
.wait();
return value;
}
template<typename T, typename E>
static inline E waitForError(const QtPromise::QPromise<T>& promise, const E& initial)
{
E error(initial);
promise
.fail([&](const E& err) {
error = err;
return T();
})
.wait();
return error;
}
template<typename E>
static inline E waitForError(const QtPromise::QPromise<void>& promise, const E& initial)
{
E error(initial);
promise
.fail([&](const E& err) {
error = err;
})
.wait();
return error;
}
template<typename E, typename T>
static inline bool waitForRejected(const T& promise)
{
bool result = false;
promise
.tapFail([&](const E&) {
result = true;
})
.wait();
return result;
}
#endif // QTPROMISE_TESTS_AUTO_SHARED_UTILS_H