diff --git a/src/qtpromise/qpromise.h b/src/qtpromise/qpromise.h index e2c1475..3da218b 100644 --- a/src/qtpromise/qpromise.h +++ b/src/qtpromise/qpromise.h @@ -2,7 +2,7 @@ #define QTPROMISE_QPROMISE_H #include "qpromise_p.h" -#include "qpromiseerror.h" +#include "qpromiseexceptions.h" #include "qpromiseglobal.h" #include "qpromiseresolver.h" diff --git a/src/qtpromise/qpromiseerror.h b/src/qtpromise/qpromiseexceptions.h similarity index 71% rename from src/qtpromise/qpromiseerror.h rename to src/qtpromise/qpromiseexceptions.h index 831a30e..bbfaf5b 100644 --- a/src/qtpromise/qpromiseerror.h +++ b/src/qtpromise/qpromiseexceptions.h @@ -1,5 +1,5 @@ -#ifndef QTPROMISE_QPROMISEERROR_H -#define QTPROMISE_QPROMISEERROR_H +#ifndef QTPROMISE_QPROMISEEXCEPTIONS_H +#define QTPROMISE_QPROMISEEXCEPTIONS_H #include "qpromise_p.h" #include "qpromiseglobal.h" @@ -9,6 +9,16 @@ namespace QtPromise { +class QPromiseCanceledException : public QException +{ +public: + void raise() const Q_DECL_OVERRIDE { throw *this; } + QPromiseCanceledException* clone() const Q_DECL_OVERRIDE + { + return new QPromiseCanceledException(*this); + } +}; + class QPromiseTimeoutException : public QException { public: @@ -37,4 +47,4 @@ using QPromiseError = QtPromisePrivate::PromiseError; } // namespace QtPromise -#endif // QTPROMISE_QPROMISEERROR_H +#endif // QTPROMISE_QPROMISEEXCEPTIONS_H diff --git a/src/qtpromise/qpromisefuture.h b/src/qtpromise/qpromisefuture.h index 5cc41ce..833c8d6 100644 --- a/src/qtpromise/qpromisefuture.h +++ b/src/qtpromise/qpromisefuture.h @@ -1,24 +1,12 @@ #ifndef QTPROMISE_QPROMISEFUTURE_P_H #define QTPROMISE_QPROMISEFUTURE_P_H +#include "qpromiseexceptions.h" + // Qt #include #include -namespace QtPromise { - -class QPromiseCanceledException : public QException -{ -public: - void raise() const Q_DECL_OVERRIDE { throw *this; } - QPromiseCanceledException* clone() const Q_DECL_OVERRIDE - { - return new QPromiseCanceledException(*this); - } -}; - -} // namespace QtPromise - namespace QtPromisePrivate { template diff --git a/src/qtpromise/qpromiseresolver.h b/src/qtpromise/qpromiseresolver.h index f48b5d1..39c1034 100644 --- a/src/qtpromise/qpromiseresolver.h +++ b/src/qtpromise/qpromiseresolver.h @@ -1,7 +1,7 @@ #ifndef QTPROMISE_QPROMISERESOLVER_H #define QTPROMISE_QPROMISERESOLVER_H -#include "qpromiseerror.h" +#include "qpromiseexceptions.h" // Qt #include diff --git a/src/qtpromise/qtpromise.pri b/src/qtpromise/qtpromise.pri index 4815e64..1d53240 100644 --- a/src/qtpromise/qtpromise.pri +++ b/src/qtpromise/qtpromise.pri @@ -2,7 +2,7 @@ HEADERS += \ $$PWD/qpromise.h \ $$PWD/qpromise.inl \ $$PWD/qpromise_p.h \ - $$PWD/qpromiseerror.h \ + $$PWD/qpromiseexceptions.h \ $$PWD/qpromisefuture.h \ $$PWD/qpromiseglobal.h \ $$PWD/qpromisehelpers.h \ diff --git a/tests/auto/qtpromise/exceptions/exceptions.pro b/tests/auto/qtpromise/exceptions/exceptions.pro new file mode 100644 index 0000000..47c54b2 --- /dev/null +++ b/tests/auto/qtpromise/exceptions/exceptions.pro @@ -0,0 +1,5 @@ +QT += concurrent +TARGET = tst_exceptions +SOURCES += $$PWD/tst_exceptions.cpp + +include(../qtpromise.pri) diff --git a/tests/auto/qtpromise/exceptions/tst_exceptions.cpp b/tests/auto/qtpromise/exceptions/tst_exceptions.cpp new file mode 100644 index 0000000..3fde13b --- /dev/null +++ b/tests/auto/qtpromise/exceptions/tst_exceptions.cpp @@ -0,0 +1,52 @@ +#include "../shared/utils.h" + +// QtPromise +#include + +// Qt +#include +#include + +using namespace QtPromise; + +class tst_exceptions : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void canceled(); + void timeout(); + void undefined(); + +}; // class tst_exceptions + +QTEST_MAIN(tst_exceptions) +#include "tst_exceptions.moc" + +namespace { + +template +void verify() +{ + auto p = qPromise(QtConcurrent::run([]() { throw E(); })); + QCOMPARE(p.isPending(), true); + QCOMPARE(waitForRejected(p), true); + QCOMPARE(p.isRejected(), true); +} + +} // anonymous namespace + +void tst_exceptions::canceled() +{ + verify(); +} + +void tst_exceptions::timeout() +{ + verify(); +} + +void tst_exceptions::undefined() +{ + verify(); +} diff --git a/tests/auto/qtpromise/qtpromise.pro b/tests/auto/qtpromise/qtpromise.pro index ff9600d..24d7c89 100644 --- a/tests/auto/qtpromise/qtpromise.pro +++ b/tests/auto/qtpromise/qtpromise.pro @@ -1,6 +1,7 @@ TEMPLATE = subdirs SUBDIRS += \ benchmark \ + exceptions \ future \ helpers \ qpromise \