20 #include <qpa/qwindowsysteminterface.h> 21 #include <QtGui/QGuiApplication> 23 #include <private/qquickbehavior_p.h> 24 #include <private/qquickanimation_p.h> 27 #include <TouchRegistry> 32 TestUtil::TestUtil(QObject *parent)
36 , m_putFakeTimerFactoryInTouchRegistry(false)
45 TestUtil::isInstanceOf(QObject *obj, QString name)
47 if (!obj)
return false;
48 bool result = obj->inherits(name.toUtf8());
50 const QMetaObject *metaObject = obj->metaObject();
51 while (!result && metaObject) {
52 const QString className = metaObject->className();
53 const QString qmlName = className.left(className.indexOf(
"_QMLTYPE_"));
54 result = qmlName == name;
55 metaObject = metaObject->superClass();
62 TestUtil::waitForBehaviors(QObject *obj)
66 Q_FOREACH(
auto c, obj->children()) {
67 if (
auto *b = dynamic_cast<QQuickBehavior*>(c)) {
69 QTRY_COMPARE(b->animation()->isRunning(),
false);
76 TouchEventSequenceWrapper *TestUtil::touchEvent(QQuickItem *item)
83 if (!m_putFakeTimerFactoryInTouchRegistry) {
84 TouchRegistry::instance()->setTimerFactory(
new FakeTimerFactory);
85 m_putFakeTimerFactoryInTouchRegistry =
true;
88 return new TouchEventSequenceWrapper(
89 QTest::touchEvent(m_targetWindow, m_touchDevice,
false), item);
92 void TestUtil::ensureTargetWindow()
94 if (!m_targetWindow && !QGuiApplication::topLevelWindows().isEmpty())
95 m_targetWindow = QGuiApplication::topLevelWindows()[0];
98 void TestUtil::ensureTouchDevice()
100 if (!m_touchDevice) {
101 m_touchDevice =
new QTouchDevice;
102 m_touchDevice->setType(QTouchDevice::TouchScreen);
103 QWindowSystemInterface::registerTouchDevice(m_touchDevice);