summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-08-12 11:15:48 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-08-12 18:32:50 +0000
commitd90e38740d20f1a81fa39eeeb74b97197bb84718 (patch)
tree5acc4915ced9fdc040ae826da7c252d4ae7f95b0 /tests
parent660014156d33d6c1635e22016d20506494e8878b (diff)
Fix DeferredFlag implementation for QTestEventLoop
As discovered in the expanded testing of QTRY_COMPARE() using the same class, the timer needs a context object and a slot to call. This amends commit 35ad157d88c7bfcb9b90b01111b0f43dd2e012d9 Task-number: QTBUG-104441 Change-Id: I41fc23de84ce8c7d6608db0005276a2071974494 Reviewed-by: Jason McDonald <macadder1@gmail.com> (cherry picked from commit 45cbb1e31efab23294cd1a5e475986bd3ea9bb10) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/testlib/selftests/eventloop/tst_eventloop.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/tests/auto/testlib/selftests/eventloop/tst_eventloop.cpp b/tests/auto/testlib/selftests/eventloop/tst_eventloop.cpp
index b5e8efce82..202a8b77f1 100644
--- a/tests/auto/testlib/selftests/eventloop/tst_eventloop.cpp
+++ b/tests/auto/testlib/selftests/eventloop/tst_eventloop.cpp
@@ -18,21 +18,29 @@ private slots:
void pass();
};
-class DeferredFlag
+class DeferredFlag : public QObject // Can't be const.
{
+ Q_OBJECT
bool m_flag;
public:
+ // A boolean that either starts out true or decays to true after 50 ms.
+ // However, that decay will only happen when the event loop is run.
explicit DeferredFlag(bool initial = false) : m_flag(initial)
{
if (!initial)
- QTimer::singleShot(50, [this] { m_flag = true; });
+ QTimer::singleShot(50, this, &DeferredFlag::onTimeOut);
}
explicit operator bool() const { return m_flag; }
bool operator!() const { return !m_flag; }
- friend bool operator==(DeferredFlag a, DeferredFlag b) { return bool(a) == bool(b); }
+ friend bool operator==(const DeferredFlag &a, const DeferredFlag &b)
+ {
+ return bool(a) == bool(b);
+ }
+public slots:
+ void onTimeOut() { m_flag = true; }
};
-char *toString(DeferredFlag val)
+char *toString(const DeferredFlag &val)
{
return qstrdup(bool(val) ? "DeferredFlag(true)" : "DeferredFlag(false)");
}