mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2024-11-22 10:40:08 +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>
|
template <template <typename, typename...> class Sequence, typename ...Args>
|
||||||
inline QPromise<QVector<T>> QPromise<T>::all(const Sequence<QPromise<T>, Args...>& promises)
|
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) {
|
if (count == 0) {
|
||||||
return QPromise<QVector<T>>::resolve({});
|
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>
|
template <template <typename, typename...> class Sequence, typename ...Args>
|
||||||
inline QPromise<void> QPromise<void>::all(const Sequence<QPromise<void>, Args...>& promises)
|
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) {
|
if (count == 0) {
|
||||||
return QPromise<void>::resolve();
|
return QPromise<void>::resolve();
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
CONFIG += testcase
|
CONFIG += testcase warn_on
|
||||||
QT += testlib
|
QT += testlib
|
||||||
QT -= gui
|
QT -= gui
|
||||||
|
|
||||||
DEFINES += QT_DEPRECATED_WARNINGS
|
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 {
|
coverage {
|
||||||
gcc {
|
gcc {
|
||||||
message("Code coverage enabled (gcov)")
|
message("Code coverage enabled (gcov)")
|
||||||
|
@ -28,159 +28,159 @@ QTEST_MAIN(tst_thread)
|
|||||||
void tst_thread::resolve()
|
void tst_thread::resolve()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
size_t target = 0;
|
QThread* target = nullptr;
|
||||||
size_t source = 0;
|
QThread* source = nullptr;
|
||||||
|
|
||||||
QPromise<int>([&](const QPromiseResolve<int>& resolve) {
|
QPromise<int>([&](const QPromiseResolve<int>& resolve) {
|
||||||
QtConcurrent::run([=, &source]() {
|
QtConcurrent::run([=, &source]() {
|
||||||
source = (size_t)QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
}).then([&](int res) {
|
}).then([&](int res) {
|
||||||
target = (size_t)QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
value = res;
|
value = res;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QVERIFY(source != 0);
|
QVERIFY(source != nullptr);
|
||||||
QVERIFY(source != target);
|
QVERIFY(source != target);
|
||||||
QCOMPARE(target, (size_t)QThread::currentThread());
|
QCOMPARE(target, QThread::currentThread());
|
||||||
QCOMPARE(value, 42);
|
QCOMPARE(value, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_thread::resolve_void()
|
void tst_thread::resolve_void()
|
||||||
{
|
{
|
||||||
int value = -1;
|
int value = -1;
|
||||||
size_t target = 0;
|
QThread* target = nullptr;
|
||||||
size_t source = 0;
|
QThread* source = nullptr;
|
||||||
|
|
||||||
QPromise<void>([&](const QPromiseResolve<void>& resolve) {
|
QPromise<void>([&](const QPromiseResolve<void>& resolve) {
|
||||||
QtConcurrent::run([=, &source]() {
|
QtConcurrent::run([=, &source]() {
|
||||||
source = (size_t)QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}).then([&]() {
|
}).then([&]() {
|
||||||
target = (size_t)QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
value = 43;
|
value = 43;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QVERIFY(source != 0);
|
QVERIFY(source != nullptr);
|
||||||
QVERIFY(source != target);
|
QVERIFY(source != target);
|
||||||
QCOMPARE(target, (size_t)QThread::currentThread());
|
QCOMPARE(target, QThread::currentThread());
|
||||||
QCOMPARE(value, 43);
|
QCOMPARE(value, 43);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_thread::reject()
|
void tst_thread::reject()
|
||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
size_t target = 0;
|
QThread* target = nullptr;
|
||||||
size_t source = 0;
|
QThread* source = nullptr;
|
||||||
|
|
||||||
QPromise<int>([&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QPromise<int>([&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
QtConcurrent::run([=, &source]() {
|
QtConcurrent::run([=, &source]() {
|
||||||
source = (size_t)QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
reject(QString("foo"));
|
reject(QString("foo"));
|
||||||
});
|
});
|
||||||
}).fail([&](const QString& err) {
|
}).fail([&](const QString& err) {
|
||||||
target = (size_t)QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
error = err;
|
error = err;
|
||||||
return -1;
|
return -1;
|
||||||
}).wait();
|
}).wait();
|
||||||
|
|
||||||
QVERIFY(source != 0);
|
QVERIFY(source != nullptr);
|
||||||
QVERIFY(source != target);
|
QVERIFY(source != target);
|
||||||
QCOMPARE(target, (size_t)QThread::currentThread());
|
QCOMPARE(target, QThread::currentThread());
|
||||||
QCOMPARE(error, QString("foo"));
|
QCOMPARE(error, QString("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_thread::then()
|
void tst_thread::then()
|
||||||
{
|
{
|
||||||
size_t source;
|
QThread* source = nullptr;
|
||||||
QPromise<int> p([&](const QPromiseResolve<int>& resolve) {
|
QPromise<int> p([&](const QPromiseResolve<int>& resolve) {
|
||||||
source = (size_t)QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
|
|
||||||
size_t target;
|
|
||||||
int value = -1;
|
int value = -1;
|
||||||
|
QThread* target = nullptr;
|
||||||
qPromise(QtConcurrent::run([&](const QPromise<int>& p) {
|
qPromise(QtConcurrent::run([&](const QPromise<int>& p) {
|
||||||
p.then([&](int res) {
|
p.then([&](int res) {
|
||||||
target = (size_t)QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
value = res;
|
value = res;
|
||||||
}).wait();
|
}).wait();
|
||||||
}, p)).wait();
|
}, p)).wait();
|
||||||
|
|
||||||
QVERIFY(target != 0);
|
QVERIFY(target != nullptr);
|
||||||
QVERIFY(source != target);
|
QVERIFY(source != target);
|
||||||
QCOMPARE(source, (size_t)QThread::currentThread());
|
QCOMPARE(source, QThread::currentThread());
|
||||||
QCOMPARE(value, 42);
|
QCOMPARE(value, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_thread::then_void()
|
void tst_thread::then_void()
|
||||||
{
|
{
|
||||||
size_t source;
|
QThread* source = nullptr;
|
||||||
QPromise<void> p([&](const QPromiseResolve<void>& resolve) {
|
QPromise<void> p([&](const QPromiseResolve<void>& resolve) {
|
||||||
source = (size_t)QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
size_t target;
|
|
||||||
int value = -1;
|
int value = -1;
|
||||||
|
QThread* target = nullptr;
|
||||||
qPromise(QtConcurrent::run([&](const QPromise<void>& p) {
|
qPromise(QtConcurrent::run([&](const QPromise<void>& p) {
|
||||||
p.then([&]() {
|
p.then([&]() {
|
||||||
target = (size_t)QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
value = 43;
|
value = 43;
|
||||||
}).wait();
|
}).wait();
|
||||||
}, p)).wait();
|
}, p)).wait();
|
||||||
|
|
||||||
QVERIFY(target != 0);
|
QVERIFY(target != nullptr);
|
||||||
QVERIFY(source != target);
|
QVERIFY(source != target);
|
||||||
QCOMPARE(source, (size_t)QThread::currentThread());
|
QCOMPARE(source, QThread::currentThread());
|
||||||
QCOMPARE(value, 43);
|
QCOMPARE(value, 43);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_thread::fail()
|
void tst_thread::fail()
|
||||||
{
|
{
|
||||||
size_t source;
|
QThread* source = nullptr;
|
||||||
QPromise<int> p([&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
QPromise<int> p([&](const QPromiseResolve<int>&, const QPromiseReject<int>& reject) {
|
||||||
source = (size_t)QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
reject(QString("foo"));
|
reject(QString("foo"));
|
||||||
});
|
});
|
||||||
|
|
||||||
size_t target;
|
|
||||||
QString error;
|
QString error;
|
||||||
|
QThread* target = nullptr;
|
||||||
qPromise(QtConcurrent::run([&](const QPromise<int>& p) {
|
qPromise(QtConcurrent::run([&](const QPromise<int>& p) {
|
||||||
p.fail([&](const QString& err) {
|
p.fail([&](const QString& err) {
|
||||||
target = (size_t)QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
error = err;
|
error = err;
|
||||||
return -1;
|
return -1;
|
||||||
}).wait();
|
}).wait();
|
||||||
}, p)).wait();
|
}, p)).wait();
|
||||||
|
|
||||||
QVERIFY(target != 0);
|
QVERIFY(target != nullptr);
|
||||||
QVERIFY(source != target);
|
QVERIFY(source != target);
|
||||||
QCOMPARE(source, (size_t)QThread::currentThread());
|
QCOMPARE(source, QThread::currentThread());
|
||||||
QCOMPARE(error, QString("foo"));
|
QCOMPARE(error, QString("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_thread::finally()
|
void tst_thread::finally()
|
||||||
{
|
{
|
||||||
size_t source;
|
QThread* source = nullptr;
|
||||||
QPromise<int> p([&](const QPromiseResolve<int>& resolve) {
|
QPromise<int> p([&](const QPromiseResolve<int>& resolve) {
|
||||||
source = (size_t)QThread::currentThread();
|
source = QThread::currentThread();
|
||||||
resolve(42);
|
resolve(42);
|
||||||
});
|
});
|
||||||
|
|
||||||
size_t target;
|
|
||||||
int value = -1;
|
int value = -1;
|
||||||
|
QThread* target = nullptr;
|
||||||
qPromise(QtConcurrent::run([&](const QPromise<int>& p) {
|
qPromise(QtConcurrent::run([&](const QPromise<int>& p) {
|
||||||
p.finally([&]() {
|
p.finally([&]() {
|
||||||
target = (size_t)QThread::currentThread();
|
target = QThread::currentThread();
|
||||||
value = 43;
|
value = 43;
|
||||||
}).wait();
|
}).wait();
|
||||||
}, p)).wait();
|
}, p)).wait();
|
||||||
|
|
||||||
QVERIFY(target != 0);
|
QVERIFY(target != nullptr);
|
||||||
QVERIFY(source != target);
|
QVERIFY(source != target);
|
||||||
QCOMPARE(source, (size_t)QThread::currentThread());
|
QCOMPARE(source, QThread::currentThread());
|
||||||
QCOMPARE(value, 43);
|
QCOMPARE(value, 43);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user