Differential D18758 Diff 58398 kdevplatform/3rdparty/qtpromise/qtpromise-0.5.0/tests/auto/qtpromise/exceptions/tst_exceptions.cpp
Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/3rdparty/qtpromise/qtpromise-0.5.0/tests/auto/qtpromise/exceptions/tst_exceptions.cpp
- This file was added.
1 | #include "../shared/utils.h" | ||||
---|---|---|---|---|---|
2 | | ||||
3 | // QtPromise | ||||
4 | #include <QtPromise> | ||||
5 | | ||||
6 | // Qt | ||||
7 | #include <QtConcurrent> | ||||
8 | #include <QtTest> | ||||
9 | | ||||
10 | using namespace QtPromise; | ||||
11 | | ||||
12 | class tst_exceptions : public QObject | ||||
13 | { | ||||
14 | Q_OBJECT | ||||
15 | | ||||
16 | private Q_SLOTS: | ||||
17 | void canceled(); | ||||
18 | void context(); | ||||
19 | void timeout(); | ||||
20 | void undefined(); | ||||
21 | | ||||
22 | }; // class tst_exceptions | ||||
23 | | ||||
24 | QTEST_MAIN(tst_exceptions) | ||||
25 | #include "tst_exceptions.moc" | ||||
26 | | ||||
27 | namespace { | ||||
28 | | ||||
29 | template <class E> | ||||
30 | void verify() | ||||
31 | { | ||||
32 | auto p = QtPromise::resolve(QtConcurrent::run([]() { throw E(); })); | ||||
33 | QCOMPARE(p.isPending(), true); | ||||
34 | QCOMPARE(waitForRejected<E>(p), true); | ||||
35 | QCOMPARE(p.isRejected(), true); | ||||
36 | } | ||||
37 | | ||||
38 | } // anonymous namespace | ||||
39 | | ||||
40 | void tst_exceptions::canceled() | ||||
41 | { | ||||
42 | verify<QPromiseCanceledException>(); | ||||
43 | } | ||||
44 | | ||||
45 | void tst_exceptions::context() | ||||
46 | { | ||||
47 | verify<QPromiseContextException>(); | ||||
48 | } | ||||
49 | | ||||
50 | void tst_exceptions::timeout() | ||||
51 | { | ||||
52 | verify<QPromiseTimeoutException>(); | ||||
53 | } | ||||
54 | | ||||
55 | void tst_exceptions::undefined() | ||||
56 | { | ||||
57 | verify<QPromiseUndefinedException>(); | ||||
58 | } |