diff options
| author | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:28 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:28 +0200 |
| commit | 69344560ea394c06ca94acac46a2e4c3e8b7b229 (patch) | |
| tree | ebc98370a697a9bbd6b973a14fa5113c475c6db7 /tests/unit/qmap/test_decode_click_coalescer.cpp | |
| parent | 3e9d10a67671d0bd5c7b8c3ca8088f1818322eff (diff) | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (diff) | |
Update upstream source from tag 'upstream/3.2.0_rc1+dfsg'
Update to upstream version '3.2.0~rc1+dfsg'
with Debian dir dbff457fd2c3616d5c77b863c7bfb2186ed86047
Diffstat (limited to 'tests/unit/qmap/test_decode_click_coalescer.cpp')
| -rw-r--r-- | tests/unit/qmap/test_decode_click_coalescer.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/unit/qmap/test_decode_click_coalescer.cpp b/tests/unit/qmap/test_decode_click_coalescer.cpp new file mode 100644 index 00000000..284aa5e5 --- /dev/null +++ b/tests/unit/qmap/test_decode_click_coalescer.cpp @@ -0,0 +1,95 @@ +#include <QtTest> + +#include "qmap/decode_click_coalescer.h" +#include "qmap/qmap_click_policy.h" + +class TestDecodeClickCoalescer final : public QObject +{ + Q_OBJECT + +private slots: + void disarmsBeforeSingleClick(); + void coalescesUpdatedRecordByIdentity(); + void keepsDifferentRecordsSeparate(); + void protectsDoubleClickWhenDisarmIsOverwritten(); +}; + +namespace +{ + struct DispatchEvent + { + QByteArray row; + DecodeClickGesture gesture; + }; +} + +void TestDecodeClickCoalescer::disarmsBeforeSingleClick() +{ + QList<DispatchEvent> dispatched; + DecodeClickCoalescer coalescer {this, [&dispatched] (QByteArray const& row, + DecodeClickGesture gesture) { + dispatched.append ({row, gesture}); + }, 20}; + + coalescer.press ("K1ABC", "first"); + QCOMPARE (dispatched.size (), 1); + QVERIFY (dispatched.first ().gesture == DecodeClickGesture::Press); + QTRY_COMPARE_WITH_TIMEOUT (dispatched.size (), 2, 100); + QCOMPARE (dispatched.last ().row, QByteArray {"first"}); + QVERIFY (dispatched.last ().gesture == DecodeClickGesture::SingleClick); +} + +void TestDecodeClickCoalescer::coalescesUpdatedRecordByIdentity() +{ + QList<DispatchEvent> dispatched; + DecodeClickCoalescer coalescer {this, [&dispatched] (QByteArray const& row, + DecodeClickGesture gesture) { + dispatched.append ({row, gesture}); + }, 20}; + + coalescer.press ("K1ABC", "old record"); + coalescer.doubleClick ("K1ABC", "new record"); + QCOMPARE (dispatched.size (), 2); + QCOMPARE (dispatched.last ().row, QByteArray {"new record"}); + QVERIFY (dispatched.last ().gesture == DecodeClickGesture::DoubleClick); + QTest::qWait (30); + QCOMPARE (dispatched.size (), 2); +} + +void TestDecodeClickCoalescer::keepsDifferentRecordsSeparate() +{ + QList<DispatchEvent> dispatched; + DecodeClickCoalescer coalescer {this, [&dispatched] (QByteArray const& row, + DecodeClickGesture gesture) { + dispatched.append ({row, gesture}); + }, 20}; + + coalescer.press ("K1ABC", "first"); + coalescer.press ("K2XYZ", "second"); + QCOMPARE (dispatched.size (), 3); + QCOMPARE (dispatched.at (1).row, QByteArray {"first"}); + QVERIFY (dispatched.at (1).gesture == DecodeClickGesture::SingleClick); + QVERIFY (dispatched.last ().gesture == DecodeClickGesture::Press); + QTRY_COMPARE_WITH_TIMEOUT (dispatched.size (), 4, 100); + QCOMPARE (dispatched.last ().row, QByteArray {"second"}); + QVERIFY (dispatched.last ().gesture == DecodeClickGesture::SingleClick); +} + +void TestDecodeClickCoalescer::protectsDoubleClickWhenDisarmIsOverwritten() +{ + auto const failedDoubleClick = qmapClickPolicy (true, false, true, true); + QVERIFY (failedDoubleClick.disarmBeforeQsy); + QVERIFY (!failedDoubleClick.enableAutoTx); + QVERIFY (!failedDoubleClick.restartTransmission); + + auto const acceptedDoubleClick = qmapClickPolicy (true, true, false, true); + QVERIFY (acceptedDoubleClick.enableAutoTx); + QVERIFY (acceptedDoubleClick.restartTransmission); + + auto const failedSingleClick = qmapClickPolicy (false, false, true, false); + QVERIFY (failedSingleClick.disableAutoTx); +} + +QTEST_GUILESS_MAIN (TestDecodeClickCoalescer) + +#include "test_decode_click_coalescer.moc" |
