on xenial help sign in
make the FakeElapsedTimer more realistic; adapt the test
7d39771Lukáš Tinkl
tests/plugins/Utils/WindowInputMonitorTest.cpp+25−10
@@ -25,14 +25,15 @@ class FakeElapsedTimer : public AbstractElapsedTimer {
25public:
25public:
26 static qint64 msecsSinceEpoch;
26 static qint64 msecsSinceEpoch;
27
27
28− FakeElapsedTimer() { start(); }
28+ FakeElapsedTimer() {}
29
29
30− void start() override { m_msecsSinceReference = msecsSinceEpoch; }
30+ void start() override { m_msecsSinceReference = msecsSinceEpoch; m_valid = true; }
31 qint64 msecsSinceReference() const override { return m_msecsSinceReference; }
31 qint64 msecsSinceReference() const override { return m_msecsSinceReference; }
32− qint64 elapsed() const override { return msecsSinceEpoch - m_msecsSinceReference; }
32+ qint64 elapsed() const override { return m_valid ? msecsSinceEpoch - m_msecsSinceReference : qrand(); }
33
33
34private:
34private:
35 qint64 m_msecsSinceReference;
35 qint64 m_msecsSinceReference;
36+ bool m_valid{false};
36};
37};
37qint64 FakeElapsedTimer::msecsSinceEpoch = 0;
38qint64 FakeElapsedTimer::msecsSinceEpoch = 0;
38
39
@@ -48,7 +49,7 @@ public:
48 int interval() const override;
49 int interval() const override;
49 void setInterval(int msecs) override;
50 void setInterval(int msecs) override;
50 void start() override;
51 void start() override;
51− void stop() override;
52+ void stop() override;
52 bool isRunning() const override;
53 bool isRunning() const override;
53 bool isSingleShot() const override;
54 bool isSingleShot() const override;
54 void setSingleShot(bool value) override;
55 void setSingleShot(bool value) override;
@@ -103,11 +104,10 @@ void WindowInputMonitorTest::init()
103
104
104void WindowInputMonitorTest::cleanup()
105void WindowInputMonitorTest::cleanup()
105{
106{
106− delete m_fakeTimerFactory;
107+ delete m_fakeTimerFactory;
107 m_fakeTimerFactory = nullptr;
108 m_fakeTimerFactory = nullptr;
108}
109}
109
110
110−
111void WindowInputMonitorTest::passTime(qint64 timeSpanMs)
111void WindowInputMonitorTest::passTime(qint64 timeSpanMs)
112{
112{
113 qint64 finalTime = FakeElapsedTimer::msecsSinceEpoch + timeSpanMs;
113 qint64 finalTime = FakeElapsedTimer::msecsSinceEpoch + timeSpanMs;
@@ -138,7 +138,7 @@ void WindowInputMonitorTest::touchTapTouch()
138 QFETCH(int, silenceAfterTap);
138 QFETCH(int, silenceAfterTap);
139 QFETCH(int, expectedActivatedCount);
139 QFETCH(int, expectedActivatedCount);
140 QFETCH(Qt::Key, key);
140 QFETCH(Qt::Key, key);
141− WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
141+ WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(this), new FakeElapsedTimer);
142 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
142 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
143 QVERIFY(activatedSpy.isValid());
143 QVERIFY(activatedSpy.isValid());
144
144
@@ -199,7 +199,7 @@ void WindowInputMonitorTest::touchTapTouch()
199
199
200void WindowInputMonitorTest::tapWhileTouching()
200void WindowInputMonitorTest::tapWhileTouching()
201{
201{
202− WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
202+ WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(this), new FakeElapsedTimer);
203 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
203 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
204 QVERIFY(activatedSpy.isValid());
204 QVERIFY(activatedSpy.isValid());
205
205
@@ -234,7 +234,7 @@ void WindowInputMonitorTest::tapWhileTouching()
234 */
234 */
235void WindowInputMonitorTest::multipleHomeKeys()
235void WindowInputMonitorTest::multipleHomeKeys()
236{
236{
237− WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
237+ WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(this), new FakeElapsedTimer);
238 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
238 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
239 QVERIFY(activatedSpy.isValid());
239 QVERIFY(activatedSpy.isValid());
240
240
@@ -266,7 +266,7 @@ void WindowInputMonitorTest::multipleHomeKeys()
266// regression test for lp:1607427
266// regression test for lp:1607427
267void WindowInputMonitorTest::repeatedSuperPress()
267void WindowInputMonitorTest::repeatedSuperPress()
268{
268{
269− WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
269+ WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(this), new FakeElapsedTimer);
270 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
270 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
271 QVERIFY(activatedSpy.isValid());
271 QVERIFY(activatedSpy.isValid());
272
272
@@ -284,6 +284,21 @@ void WindowInputMonitorTest::repeatedSuperPress()
284 passTime(1000);
284 passTime(1000);
285 QCOMPARE(activatedSpy.count(), 1);
285 QCOMPARE(activatedSpy.count(), 1);
286
286
287+ // a touch event in between
288+ {
289+ QTouchEvent touchEvent(QEvent::TouchBegin);
290+ homeKeyWatcher.update(&touchEvent);
291+ }
292+ {
293+ QTouchEvent touchEvent(QEvent::TouchUpdate);
294+ homeKeyWatcher.update(&touchEvent);
295+ }
296+ {
297+ QTouchEvent touchEvent(QEvent::TouchEnd);
298+ homeKeyWatcher.update(&touchEvent);
299+ }
300+
301+ passTime(1000);
287 // 2nd try
302 // 2nd try
288 activatedSpy.clear();
303 activatedSpy.clear();
289 {
304 {