qtpromise/tests/auto/qtpromise/exceptions/tst_exceptions.cpp
Simon Brunel d43657fbd5 Use clang-format for code style consistency
Based on the WebKit preset and following 'most' of the Qt guidelines, except a few rules that work better for promise continuation lambdas. Requires clang-format 11.
2020-03-22 17:50:16 +01:00

65 lines
1.1 KiB
C++

/*
* Copyright (c) Simon Brunel, https://github.com/simonbrunel
*
* This source code is licensed under the MIT license found in
* the LICENSE file in the root directory of this source tree.
*/
#include "../shared/utils.h"
#include <QtConcurrent>
#include <QtPromise>
#include <QtTest>
using namespace QtPromise;
class tst_exceptions : public QObject
{
Q_OBJECT
private Q_SLOTS:
void canceled();
void context();
void timeout();
void undefined();
}; // class tst_exceptions
QTEST_MAIN(tst_exceptions)
#include "tst_exceptions.moc"
namespace {
template<class E>
void verify()
{
auto p = QtPromise::resolve(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::context()
{
verify<QPromiseContextException>();
}
void tst_exceptions::timeout()
{
verify<QPromiseTimeoutException>();
}
void tst_exceptions::undefined()
{
verify<QPromiseUndefinedException>();
}