From b19cac022ee4e80aefe04f66d58673fb174f6533 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 2 Feb 2016 09:17:13 +0100 Subject: [PATCH] runAsync: Add test for move-only types Excludes MSVC2013 which doesn't really support moving. Change-Id: I2bffa546f2c90946b4d99e0eee292741b900a386 Reviewed-by: Orgad Shaneh --- .../auto/runextensions/tst_runextensions.cpp | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/auto/runextensions/tst_runextensions.cpp b/tests/auto/runextensions/tst_runextensions.cpp index 9237d8f5ac6..554ac6a7dd8 100644 --- a/tests/auto/runextensions/tst_runextensions.cpp +++ b/tests/auto/runextensions/tst_runextensions.cpp @@ -27,6 +27,10 @@ #include +#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 &fi) @@ -268,6 +275,35 @@ void tst_RunExtensions::runInThreadPool() QList({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 &fi, const MoveOnlyType &) + { + fi.reportResult(1); + } +}; + +void tst_RunExtensions::moveOnlyType() +{ + QCOMPARE(Utils::runAsync(MoveOnlyCallable(), MoveOnlyType()).results(), + QList({1})); +} + +#endif + QTEST_MAIN(tst_RunExtensions) #include "tst_runextensions.moc"