on xenial help sign in
make the FakeElapsedTimer more realistic; adapt the test
commit7d3977100bdb9d13d5fae3fb07082ae8ad8a33a5 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateTue 29 Nov 2016, 16:37 (10 years ago) parenta1679d2
1 file changed+25−10
tests/plugins/Utils/WindowInputMonitorTest.cpp+25−10
tests/plugins/Utils/WindowInputMonitorTest.cpp+25−10
@@ -25,14 +25,15 @@ class FakeElapsedTimer : public AbstractElapsedTimer {
2525public:
2626 static qint64 msecsSinceEpoch;
2727
28− FakeElapsedTimer() { start(); }
28+ FakeElapsedTimer() {}
2929
30− void start() override { m_msecsSinceReference = msecsSinceEpoch; }
30+ void start() override { m_msecsSinceReference = msecsSinceEpoch; m_valid = true; }
3131 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(); }
3333
3434private:
3535 qint64 m_msecsSinceReference;
36+ bool m_valid{false};
3637};
3738qint64 FakeElapsedTimer::msecsSinceEpoch = 0;
3839
@@ -48,7 +49,7 @@ public:
4849 int interval() const override;
4950 void setInterval(int msecs) override;
5051 void start() override;
51− void stop() override;
52+ void stop() override;
5253 bool isRunning() const override;
5354 bool isSingleShot() const override;
5455 void setSingleShot(bool value) override;
@@ -103,11 +104,10 @@ void WindowInputMonitorTest::init()
103104
104105void WindowInputMonitorTest::cleanup()
105106{
106− delete m_fakeTimerFactory;
107+ delete m_fakeTimerFactory;
107108 m_fakeTimerFactory = nullptr;
108109}
109110
110−
111111void WindowInputMonitorTest::passTime(qint64 timeSpanMs)
112112{
113113 qint64 finalTime = FakeElapsedTimer::msecsSinceEpoch + timeSpanMs;
@@ -138,7 +138,7 @@ void WindowInputMonitorTest::touchTapTouch()
138138 QFETCH(int, silenceAfterTap);
139139 QFETCH(int, expectedActivatedCount);
140140 QFETCH(Qt::Key, key);
141− WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
141+ WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(this), new FakeElapsedTimer);
142142 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
143143 QVERIFY(activatedSpy.isValid());
144144
@@ -199,7 +199,7 @@ void WindowInputMonitorTest::touchTapTouch()
199199
200200void WindowInputMonitorTest::tapWhileTouching()
201201{
202− WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
202+ WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(this), new FakeElapsedTimer);
203203 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
204204 QVERIFY(activatedSpy.isValid());
205205
@@ -234,7 +234,7 @@ void WindowInputMonitorTest::tapWhileTouching()
234234 */
235235void WindowInputMonitorTest::multipleHomeKeys()
236236{
237− WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
237+ WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(this), new FakeElapsedTimer);
238238 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
239239 QVERIFY(activatedSpy.isValid());
240240
@@ -266,7 +266,7 @@ void WindowInputMonitorTest::multipleHomeKeys()
266266// regression test for lp:1607427
267267void WindowInputMonitorTest::repeatedSuperPress()
268268{
269− WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
269+ WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(this), new FakeElapsedTimer);
270270 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
271271 QVERIFY(activatedSpy.isValid());
272272
@@ -284,6 +284,21 @@ void WindowInputMonitorTest::repeatedSuperPress()
284284 passTime(1000);
285285 QCOMPARE(activatedSpy.count(), 1);
286286
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);
287302 // 2nd try
288303 activatedSpy.clear();
289304 {