Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Fix unstable timers in KisInputManagerTest

Dmitry Kazakov0e0c06a4c83c
diff --git a/libs/ui/input/KisTouchHoldEventsPostponer.cpp b/libs/ui/input/KisTouchHoldEventsPostponer.cpp
index c22cc83af7..a62a088379 100644
--- a/libs/ui/input/KisTouchHoldEventsPostponer.cpp
+++ b/libs/ui/input/KisTouchHoldEventsPostponer.cpp
@@ -16,6 +16,11 @@
#include <KoPointerEvent.h>
#endif
+#ifdef Q_OS_WIN
+// to detect if we are running in a unittest mode
+#include <QStandardPaths>
+#endif
+
KisTouchHoldEventsPostponer::KisTouchHoldEventsPostponer(qreal maxHoldDistance, int holdTimeout)
: m_maxHoldDistance(maxHoldDistance)
@@ -23,7 +28,14 @@ KisTouchHoldEventsPostponer::KisTouchHoldEventsPostponer(qreal maxHoldDistance,
connect(&m_timer, &QTimer::timeout, this, &KisTouchHoldEventsPostponer::slotHoldCompletionTimeout);
m_timer.setSingleShot(true);
+#ifdef Q_OS_WIN
+ // on Windows, the coarse timers are too coarse for running is a unitest, so we should
+ // switch to a precise one inside unittests; for normal user-facing runs the precision
+ // is not necessary
+ m_timer.setTimerType(QStandardPaths::isTestModeEnabled() ? Qt::PreciseTimer : Qt::CoarseTimer);
+#else
m_timer.setTimerType(Qt::CoarseTimer);
+#endif
m_timer.setInterval(holdTimeout);
m_timer.start();
}
diff --git a/libs/ui/tests/kis_input_manager_test.cpp b/libs/ui/tests/kis_input_manager_test.cpp
index 8bcfbd7d7d..cd4b38416b 100644
--- a/libs/ui/tests/kis_input_manager_test.cpp
+++ b/libs/ui/tests/kis_input_manager_test.cpp
@@ -1144,7 +1144,7 @@ void KisInputManagerTest::testTouchHoldPostponer()
if (postponer.state() == KisTouchHoldEventsPostponer::HoldCompleted || holdHasBeenCompleted) {
QVERIFY(holdHasBeenCompleted);
QCOMPARE(postponer.state(), KisTouchHoldEventsPostponer::HoldCompleted);
- QCOMPARE(completeOnIndex, eventIndex);
+ QCOMPARE(eventIndex, completeOnIndex);
// the last event has not yet been pushed, so no "+1"
QCOMPARE(postponer.postponedEvents().size(), eventIndex);
diff --git a/sdk/tests/kistest.h b/sdk/tests/kistest.h
index 2c813ac93d..a7bb1c7eef 100644
--- a/sdk/tests/kistest.h
+++ b/sdk/tests/kistest.h
@@ -255,6 +255,7 @@ int main(int argc, char *argv[]) \
QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); \
qputenv("QT_LOGGING_RULES", ""); \
QStandardPaths::setTestModeEnabled(true); \
+ KisSynchronizedConnectionBase::setAutoModeForUnittestsEnabled(true); \
qputenv("EXTRA_RESOURCE_DIRS", QByteArray(KRITA_RESOURCE_DIRS_FOR_TESTS)); \
qputenv("KRITA_PLUGIN_PATH", QByteArray(KRITA_PLUGINS_DIR_FOR_TESTS)); \
QApplication app(argc, argv); \