forked from qt-creator/qt-creator
runAsync: Add test for move-only types
Excludes MSVC2013 which doesn't really support moving. Change-Id: I2bffa546f2c90946b4d99e0eee292741b900a386 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -27,6 +27,10 @@
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#if !defined(Q_CC_MSVC) || _MSC_VER >= 1900 // MSVC2015
|
||||
#define SUPPORTS_MOVE
|
||||
#endif
|
||||
|
||||
class tst_RunExtensions : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -34,6 +38,9 @@ class tst_RunExtensions : public QObject
|
||||
private slots:
|
||||
void runAsync();
|
||||
void runInThreadPool();
|
||||
#ifdef SUPPORTS_MOVE
|
||||
void moveOnlyType();
|
||||
#endif
|
||||
};
|
||||
|
||||
void report3(QFutureInterface<int> &fi)
|
||||
@@ -268,6 +275,35 @@ void tst_RunExtensions::runInThreadPool()
|
||||
QList<QString>({QString(QLatin1String("rvalue"))}));
|
||||
}
|
||||
|
||||
#ifdef SUPPORTS_MOVE
|
||||
|
||||
class MoveOnlyType
|
||||
{
|
||||
public:
|
||||
MoveOnlyType() = default;
|
||||
MoveOnlyType(const MoveOnlyType &) = delete;
|
||||
MoveOnlyType(MoveOnlyType &&) = default;
|
||||
MoveOnlyType &operator=(const MoveOnlyType &) = delete;
|
||||
MoveOnlyType &operator=(MoveOnlyType &&) = default;
|
||||
};
|
||||
|
||||
class MoveOnlyCallable : public MoveOnlyType
|
||||
{
|
||||
public:
|
||||
void operator()(QFutureInterface<int> &fi, const MoveOnlyType &)
|
||||
{
|
||||
fi.reportResult(1);
|
||||
}
|
||||
};
|
||||
|
||||
void tst_RunExtensions::moveOnlyType()
|
||||
{
|
||||
QCOMPARE(Utils::runAsync<int>(MoveOnlyCallable(), MoveOnlyType()).results(),
|
||||
QList<int>({1}));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
QTEST_MAIN(tst_RunExtensions)
|
||||
|
||||
#include "tst_runextensions.moc"
|
||||
|
||||
Reference in New Issue
Block a user