diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-05-02 16:26:57 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-05-02 22:06:18 +0200 |
commit | 02cac26ef568355dbcab2fb204abdbac6c0580fb (patch) | |
tree | 61517c6a3457a220871c17701759312829d2e487 /tests/auto/corelib/kernel/qobject | |
parent | 106c2fd19dfbd6eeb741a2e8df684702a610f85b (diff) |
Small improvements to QObject unit test
Remove duplicate test and outdated comment about move-only functors,
and include return value in move-only functor test.
Change-Id: I58dffe0ccf3ec12e7e05e2c9588303da4a7e75ff
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/kernel/qobject')
-rw-r--r-- | tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index ede3bcccb2..c6db1a3a97 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -8376,7 +8376,7 @@ public: static void staticCallback0() {} static void staticCallback1(const QString &) {} - using Prototype0 = void(*)(); + using Prototype0 = int(*)(); using Prototype1 = void(*)(QString); template<typename Functor> @@ -8429,8 +8429,9 @@ inline constexpr bool compiles(Functor &&) { void tst_QObject::asyncCallbackHelper() { + int result = 0; QString arg1 = "Parameter"; - void *argv[] = { nullptr, &arg1 }; + void *argv[] = { &result, &arg1 }; auto lambda0 = []{}; auto lambda1 = [](const QString &) {}; @@ -8477,11 +8478,6 @@ void tst_QObject::asyncCallbackHelper() static_assert(!compiles<AsyncCaller::Prototype0>(freeFunction1)); static_assert(!compiles<AsyncCaller::Prototype0>(functor1)); - // move-only functor - should work, but doesn't because QFunctorSlotObject requires - // the functor to be of a copyable type! - static_assert(!compiles<AsyncCaller::Prototype0>(moveOnlyLambda)); - static_assert(!compiles<AsyncCaller::Prototype1>(moveOnlyLambda)); - // wrong parameter type static_assert(!compiles<AsyncCaller::Prototype1>(&AsyncCaller::callbackInt)); @@ -8520,19 +8516,25 @@ void tst_QObject::asyncCallbackHelper() QVERIFY(caller.callMe1(std::move(moveOnlyLambda1))); QVERIFY(caller.callMe1(freeFunction1)); + static const char *expectedPayload = "Hello World!"; { struct MoveOnlyFunctor { - MoveOnlyFunctor() : payload("Hello World!") {} + MoveOnlyFunctor() = default; MoveOnlyFunctor(MoveOnlyFunctor &&) = default; MoveOnlyFunctor(const MoveOnlyFunctor &) = delete; ~MoveOnlyFunctor() = default; - void operator()() const { qDebug() << payload; } - QString payload; + int operator()() const { + qDebug().noquote() << payload; + return int(payload.length()); + } + QString payload = expectedPayload; } moveOnlyFunctor; QVERIFY(caller.callMe0(std::move(moveOnlyFunctor))); } + QTest::ignoreMessage(QtDebugMsg, expectedPayload); caller.slotObject->call(nullptr, argv); + QCOMPARE(result, QLatin1String(expectedPayload).length()); // mutable lambda; same behavior as mutableFunctor - we copy the functor // in the QFunctorSlotObject, so the original is not modified |