mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2025-07-01 23:11:47 +08:00
Reorganize exceptions and add unit tests
This commit is contained in:
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 \
|
||||
|
Reference in New Issue
Block a user