mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2024-11-21 18:24:29 +08:00
Fix GCC -Wold-style-cast warnings
Explicitly enable -Wold-style-cast and make all warnings into errors in tests (-Werror on GCC, -WX on MSVC).
This commit is contained in:
parent
fa987a5044
commit
26a2110a14
@ -197,7 +197,7 @@ template <typename T>
|
||||
template <template <typename, typename...> class Sequence, typename ...Args>
|
||||
inline QPromise<QVector<T>> QPromise<T>::all(const Sequence<QPromise<T>, Args...>& promises)
|
||||
{
|
||||
const int count = (int)promises.size();
|
||||
const int count = static_cast<int>(promises.size());
|
||||
if (count == 0) {
|
||||
return QPromise<QVector<T>>::resolve({});
|
||||
}
|
||||
@ -247,7 +247,7 @@ inline QPromise<T> QPromise<T>::resolve(T&& value)
|
||||
template <template <typename, typename...> class Sequence, typename ...Args>
|
||||
inline QPromise<void> QPromise<void>::all(const Sequence<QPromise<void>, Args...>& promises)
|
||||
{
|
||||
const int count = (int)promises.size();
|
||||
const int count = static_cast<int>(promises.size());
|
||||
if (count == 0) {
|
||||
return QPromise<void>::resolve();
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
TEMPLATE = app
|
||||
CONFIG += testcase
|
||||
CONFIG += testcase warn_on
|
||||
QT += testlib
|
||||
QT -= gui
|
||||
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# Additional warnings and make all warnings into errors
|
||||
# https://github.com/simonbrunel/qtpromise/issues/10
|
||||
gcc:QMAKE_CXXFLAGS += -Werror -Wold-style-cast
|
||||
msvc:QMAKE_CXXFLAGS -= -WX
|
||||
|
||||
coverage {
|
||||
gcc {
|
||||
message("Code coverage enabled (gcov)")
|
||||
|
@ -28,159 +28,159 @@ QTEST_MAIN(tst_thread)
|
||||
void tst_thread::resolve()
|
||||
{
|
||||
int value = -1;
|
||||
size_t target = 0;
|
||||
size_t source = 0;
|
||||
QThread* target = nullptr;
|
||||
QThread* source = nullptr;
|
||||
|
||||
QPromise<int>([&](const QPromiseResolve<int>& resolve) {
|
||||
QtConcurrent::run([=, &source]() {
|
||||
source = (size_t)QThread::currentThread();
|
||||
source = QThread::currentThread();
|
||||
resolve(42);
|
||||
});
|
||||
}).then([&](int res) {
|
||||
target = (size_t)QThread::currentThread();
|
||||
target = QThread::currentThread();
|
||||
value = res;
|
||||
}).wait();
|
||||
|
||||
QVERIFY(source != 0);
|
||||
QVERIFY(source != nullptr);
|
||||
QVERIFY(source != target);
|
||||
QCOMPARE(target, (size_t)QThread::currentThread());
|
||||
QCOMPARE(target, QThread::currentThread());
|
||||
QCOMPARE(value, 42);
|
||||
}
|
||||
|
||||
void tst_thread::resolve_void()
|
||||
{
|
||||
int value = -1;
|
||||
size_t target = 0;
|
||||
size_t source = 0;
|
||||
QThread* target = nullptr;
|
||||
QThread* source = nullptr;
|
||||
|
||||
QPromise<void>([&](const QPromiseResolve<void>& resolve) {
|
||||
QtConcurrent::run([=, &source]() {
|
||||
source = (size_t)QThread::currentThread();
|
||||
source = QThread::currentThread();
|
||||
resolve();
|
||||
});
|
||||
}).then([&]() {
|
||||
target = (size_t)QThread::currentThread();
|
||||
target = QThread::currentThread();
|
||||
value = 43;
|
||||
}).wait();
|
||||
|
||||
QVERIFY(source != 0);
|
||||
QVERIFY(source != nullptr);
|
||||
QVERIFY(source != target);
|
||||
QCOMPARE(target, (size_t)QThread::currentThread());
|
||||
QCOMPARE(target, QThread::currentThread());
|
||||
QCOMPARE(value, 43);
|
||||
}
|
||||
|
||||
void tst_thread::reject()
|
||||
{
|
||||
QString error;
|
||||
size_t target = 0;
|
||||
size_t source = 0;
|
||||
QThread* target = nullptr;
|
||||
QThread* source = nullptr;
|
||||
|
||||
QPromise<int>([&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||
QtConcurrent::run([=, &source]() {
|
||||
source = (size_t)QThread::currentThread();
|
||||
source = QThread::currentThread();
|
||||
reject(QString("foo"));
|
||||
});
|
||||
}).fail([&](const QString& err) {
|
||||
target = (size_t)QThread::currentThread();
|
||||
target = QThread::currentThread();
|
||||
error = err;
|
||||
return -1;
|
||||
}).wait();
|
||||
|
||||
QVERIFY(source != 0);
|
||||
QVERIFY(source != nullptr);
|
||||
QVERIFY(source != target);
|
||||
QCOMPARE(target, (size_t)QThread::currentThread());
|
||||
QCOMPARE(target, QThread::currentThread());
|
||||
QCOMPARE(error, QString("foo"));
|
||||
}
|
||||
|
||||
void tst_thread::then()
|
||||
{
|
||||
size_t source;
|
||||
QThread* source = nullptr;
|
||||
QPromise<int> p([&](const QPromiseResolve<int>& resolve) {
|
||||
source = (size_t)QThread::currentThread();
|
||||
source = QThread::currentThread();
|
||||
resolve(42);
|
||||
});
|
||||
|
||||
size_t target;
|
||||
int value = -1;
|
||||
QThread* target = nullptr;
|
||||
qPromise(QtConcurrent::run([&](const QPromise<int>& p) {
|
||||
p.then([&](int res) {
|
||||
target = (size_t)QThread::currentThread();
|
||||
target = QThread::currentThread();
|
||||
value = res;
|
||||
}).wait();
|
||||
}, p)).wait();
|
||||
|
||||
QVERIFY(target != 0);
|
||||
QVERIFY(target != nullptr);
|
||||
QVERIFY(source != target);
|
||||
QCOMPARE(source, (size_t)QThread::currentThread());
|
||||
QCOMPARE(source, QThread::currentThread());
|
||||
QCOMPARE(value, 42);
|
||||
}
|
||||
|
||||
void tst_thread::then_void()
|
||||
{
|
||||
size_t source;
|
||||
QThread* source = nullptr;
|
||||
QPromise<void> p([&](const QPromiseResolve<void>& resolve) {
|
||||
source = (size_t)QThread::currentThread();
|
||||
source = QThread::currentThread();
|
||||
resolve();
|
||||
});
|
||||
|
||||
size_t target;
|
||||
int value = -1;
|
||||
QThread* target = nullptr;
|
||||
qPromise(QtConcurrent::run([&](const QPromise<void>& p) {
|
||||
p.then([&]() {
|
||||
target = (size_t)QThread::currentThread();
|
||||
target = QThread::currentThread();
|
||||
value = 43;
|
||||
}).wait();
|
||||
}, p)).wait();
|
||||
|
||||
QVERIFY(target != 0);
|
||||
QVERIFY(target != nullptr);
|
||||
QVERIFY(source != target);
|
||||
QCOMPARE(source, (size_t)QThread::currentThread());
|
||||
QCOMPARE(source, QThread::currentThread());
|
||||
QCOMPARE(value, 43);
|
||||
}
|
||||
|
||||
void tst_thread::fail()
|
||||
{
|
||||
size_t source;
|
||||
QThread* source = nullptr;
|
||||
QPromise<int> p([&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||
source = (size_t)QThread::currentThread();
|
||||
source = QThread::currentThread();
|
||||
reject(QString("foo"));
|
||||
});
|
||||
|
||||
size_t target;
|
||||
QString error;
|
||||
QThread* target = nullptr;
|
||||
qPromise(QtConcurrent::run([&](const QPromise<int>& p) {
|
||||
p.fail([&](const QString& err) {
|
||||
target = (size_t)QThread::currentThread();
|
||||
target = QThread::currentThread();
|
||||
error = err;
|
||||
return -1;
|
||||
}).wait();
|
||||
}, p)).wait();
|
||||
|
||||
QVERIFY(target != 0);
|
||||
QVERIFY(target != nullptr);
|
||||
QVERIFY(source != target);
|
||||
QCOMPARE(source, (size_t)QThread::currentThread());
|
||||
QCOMPARE(source, QThread::currentThread());
|
||||
QCOMPARE(error, QString("foo"));
|
||||
}
|
||||
|
||||
void tst_thread::finally()
|
||||
{
|
||||
size_t source;
|
||||
QThread* source = nullptr;
|
||||
QPromise<int> p([&](const QPromiseResolve<int>& resolve) {
|
||||
source = (size_t)QThread::currentThread();
|
||||
source = QThread::currentThread();
|
||||
resolve(42);
|
||||
});
|
||||
|
||||
size_t target;
|
||||
int value = -1;
|
||||
QThread* target = nullptr;
|
||||
qPromise(QtConcurrent::run([&](const QPromise<int>& p) {
|
||||
p.finally([&]() {
|
||||
target = (size_t)QThread::currentThread();
|
||||
target = QThread::currentThread();
|
||||
value = 43;
|
||||
}).wait();
|
||||
}, p)).wait();
|
||||
|
||||
QVERIFY(target != 0);
|
||||
QVERIFY(target != nullptr);
|
||||
QVERIFY(source != target);
|
||||
QCOMPARE(source, (size_t)QThread::currentThread());
|
||||
QCOMPARE(source, QThread::currentThread());
|
||||
QCOMPARE(value, 43);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user