Reorganize exceptions and add unit tests

This commit is contained in:
Simon Brunel
2019-02-23 11:42:02 +01:00
parent 6110cd40d3
commit 700098ef7b
8 changed files with 76 additions and 20 deletions

View File

@ -0,0 +1,5 @@
QT += concurrent
TARGET = tst_exceptions
SOURCES += $$PWD/tst_exceptions.cpp
include(../qtpromise.pri)

View 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>();
}

View File

@ -1,6 +1,7 @@
TEMPLATE = subdirs
SUBDIRS += \
benchmark \
exceptions \
future \
helpers \
qpromise \