on xenial help sign in
use real timers in TouchRegistry when running "make tryFoo" tests (uqmlscene)

And simplify TestUtil::ensureTouchRegistryInstalled()

commit1bb1d440ce0bd1e44d2351cb9b7eb913418de15b authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateFri 17 Oct 2014, 11:22 (12 years ago) parent1ff2631
3 files changed+15−28
tests/uqmlscene/main.cpp+5−5 tests/utils/modules/Unity/Test/testutil.cpp+10−22 tests/utils/modules/Unity/Test/testutil.h−1
tests/uqmlscene/main.cpp+5−5
@@ -428,6 +428,10 @@ int main(int argc, char ** argv)
428428
429429 MouseTouchAdaptor mouseTouchAdaptor;
430430 app.installNativeEventFilter(&mouseTouchAdaptor);
431+ // Create it before loading the module, so that TestUtil
432+ // doesn't create one with a fake timer factory.
433+ // When interacting manually with a test we want the real deal.
434+ new TouchRegistry;
431435
432436#ifndef QT_NO_TRANSLATION
433437 QTranslator translator;
@@ -499,11 +503,7 @@ int main(int argc, char ** argv)
499503 QQuickItem *contentItem = qobject_cast<QQuickItem *>(topLevel);
500504 if (contentItem) {
501505 qxView = new QQuickView(&engine, nullptr);
502− if (TouchRegistry::instance() == nullptr) {
503− new TouchRegistry(qxView);
504− } else {
505− TouchRegistry::instance()->setParent(qxView);
506− }
506+ TouchRegistry::instance()->setParent(qxView);
507507 qxView->installEventFilter(TouchRegistry::instance());
508508 window = qxView;
509509 // Set window default properties; the qml can still override them
tests/utils/modules/Unity/Test/testutil.cpp+10−22
@@ -31,7 +31,6 @@ TestUtil::TestUtil(QObject *parent)
3131 : QObject(parent)
3232 , m_targetWindow(0)
3333 , m_touchDevice(0)
34− , m_installedTouchRegistry(false)
3534{
3635}
3736
@@ -83,30 +82,19 @@ void TestUtil::ensureTouchDevice()
8382
8483void TestUtil::ensureTouchRegistryInstalled()
8584{
86− if (m_installedTouchRegistry)
85+ if (TouchRegistry::instance())
8786 return;
8887
89− TouchRegistry *touchRegistry;
90− if (TouchRegistry::instance() == nullptr) {
91− // Tests can be *very* slow to run and we don't want things timing out because
92− // of that. So give it fake timers to use (they will never time out)
93− touchRegistry = new TouchRegistry(this, new FakeTimerFactory);
94− } else {
95− touchRegistry = TouchRegistry::instance();
96− if (touchRegistry->parent() != this) {
97− // someone else created it. leave it alone
98− m_installedTouchRegistry = true;
99− }
100− }
88+ if (!m_targetWindow)
89+ return;
10190
102− ensureTargetWindow();
91+ // Tests can be *very* slow to run and we don't want things timing out because
92+ // of that. So give it fake timers to use (they will never time out)
93+ TouchRegistry *touchRegistry = new TouchRegistry(this, new FakeTimerFactory);
10394
104− if (m_targetWindow) {
105− QQuickView *view = qobject_cast<QQuickView*>(m_targetWindow);
106− if (view) {
107− view->installEventFilter(touchRegistry);
108− touchRegistry->setParent(view);
109− m_installedTouchRegistry = true;
110− }
95+ QQuickView *view = qobject_cast<QQuickView*>(m_targetWindow);
96+ if (view) {
97+ view->installEventFilter(touchRegistry);
98+ touchRegistry->setParent(view);
11199 }
112100}
tests/utils/modules/Unity/Test/testutil.h−1
@@ -42,7 +42,6 @@ private:
4242
4343 QWindow *m_targetWindow;
4444 QTouchDevice *m_touchDevice;
45− bool m_installedTouchRegistry;
4645};
4746
4847QML_DECLARE_TYPE(TestUtil)