mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2024-11-21 18:24:29 +08:00
Reorganize exceptions and add unit tests
This commit is contained in:
parent
6110cd40d3
commit
700098ef7b
@ -2,7 +2,7 @@
|
||||
#define QTPROMISE_QPROMISE_H
|
||||
|
||||
#include "qpromise_p.h"
|
||||
#include "qpromiseerror.h"
|
||||
#include "qpromiseexceptions.h"
|
||||
#include "qpromiseglobal.h"
|
||||
#include "qpromiseresolver.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
|
@ -1,24 +1,12 @@
|
||||
#ifndef QTPROMISE_QPROMISEFUTURE_P_H
|
||||
#define QTPROMISE_QPROMISEFUTURE_P_H
|
||||
|
||||
#include "qpromiseexceptions.h"
|
||||
|
||||
// Qt
|
||||
#include <QFutureWatcher>
|
||||
#include <QFuture>
|
||||
|
||||
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 <typename T>
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef QTPROMISE_QPROMISERESOLVER_H
|
||||
#define QTPROMISE_QPROMISERESOLVER_H
|
||||
|
||||
#include "qpromiseerror.h"
|
||||
#include "qpromiseexceptions.h"
|
||||
|
||||
// Qt
|
||||
#include <QExplicitlySharedDataPointer>
|
||||
|
@ -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 \
|
||||
|
5
tests/auto/qtpromise/exceptions/exceptions.pro
Normal file
5
tests/auto/qtpromise/exceptions/exceptions.pro
Normal file
@ -0,0 +1,5 @@
|
||||
QT += concurrent
|
||||
TARGET = tst_exceptions
|
||||
SOURCES += $$PWD/tst_exceptions.cpp
|
||||
|
||||
include(../qtpromise.pri)
|
52
tests/auto/qtpromise/exceptions/tst_exceptions.cpp
Normal file
52
tests/auto/qtpromise/exceptions/tst_exceptions.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "../shared/utils.h"
|
||||
|
||||
// QtPromise
|
||||
#include <QtPromise>
|
||||
|
||||
// Qt
|
||||
#include <QtConcurrent>
|
||||
#include <QtTest>
|
||||
|
||||
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 <class E>
|
||||
void verify()
|
||||
{
|
||||
auto p = qPromise(QtConcurrent::run([]() { throw E(); }));
|
||||
QCOMPARE(p.isPending(), true);
|
||||
QCOMPARE(waitForRejected<E>(p), true);
|
||||
QCOMPARE(p.isRejected(), true);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
void tst_exceptions::canceled()
|
||||
{
|
||||
verify<QPromiseCanceledException>();
|
||||
}
|
||||
|
||||
void tst_exceptions::timeout()
|
||||
{
|
||||
verify<QPromiseTimeoutException>();
|
||||
}
|
||||
|
||||
void tst_exceptions::undefined()
|
||||
{
|
||||
verify<QPromiseUndefinedException>();
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
TEMPLATE = subdirs
|
||||
SUBDIRS += \
|
||||
benchmark \
|
||||
exceptions \
|
||||
future \
|
||||
helpers \
|
||||
qpromise \
|
||||
|
Loading…
Reference in New Issue
Block a user