mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2025-04-01 22:08:39 +08:00
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.
65 lines
1.1 KiB
C++
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>();
|
|
}
|