1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*
* Copyright 2015 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "GestureTest.h"
#include <QtGui/qpa/qwindowsysteminterface.h>
#include <QtQml/QQmlEngine>
#include <QtQuick/QQuickView>
#include <QtTest/QtTest>
#include <LomiriGestures/private/timer_p.h>
#include <LomiriGestures/private/touchregistry_p.h>
#include "uctestcase.h"
#include "uctestextras.h"
UG_USE_NAMESPACE
GestureTest::GestureTest(const QString &qmlFilename)
: QObject(), m_device(nullptr), m_view(nullptr), m_qmlFilename(qmlFilename)
{
}
void GestureTest::initTestCase()
{
if (!m_device) {
m_device = new QTouchDevice;
m_device->setType(QTouchDevice::TouchScreen);
QWindowSystemInterface::registerTouchDevice(m_device);
}
}
void GestureTest::init()
{
m_view = new LomiriTestCase(m_qmlFilename, QQuickView::SizeRootObjectToView, true);
m_fakeTimerFactory = new FakeTimerFactory;
m_touchRegistry = TouchRegistry::instance();
m_touchRegistry->setTimerFactory(m_fakeTimerFactory);
m_view->installEventFilter(m_touchRegistry);
qApp->processEvents();
}
void GestureTest::cleanup()
{
m_view->removeEventFilter(m_touchRegistry);
delete m_touchRegistry;
m_touchRegistry = nullptr;
// TouchRegistry will take down the timer factory along with him
// delete m_fakeTimerFactory;
m_fakeTimerFactory = nullptr;
delete m_view;
m_view = nullptr;
// add a small timeout after each run to have a proper cleanup
QTest::qWait(400);
}
////////////////////////// TouchMemento /////////////////////////////
TouchMemento::TouchMemento(const QTouchEvent *touchEvent)
: touchPointStates(touchEvent->touchPointStates()), touchPoints(touchEvent->touchPoints())
{
}
bool TouchMemento::containsTouchWithId(int touchId) const
{
for (int i = 0; i < touchPoints.count(); ++i) {
if (touchPoints.at(i).id() == touchId) {
return true;
}
}
return false;
}
////////////////////////// DummyItem /////////////////////////////
DummyItem::DummyItem(QQuickItem *parent)
: QQuickItem(parent)
{
touchEventHandler = defaultTouchEventHandler;
mousePressEventHandler = defaultMouseEventHandler;
mouseMoveEventHandler = defaultMouseEventHandler;
mouseReleaseEventHandler = defaultMouseEventHandler;
mouseDoubleClickEventHandler = defaultMouseEventHandler;
}
void DummyItem::touchEvent(QTouchEvent *event)
{
touchEvents.append(TouchMemento(event));
touchEventHandler(event);
}
void DummyItem::mousePressEvent(QMouseEvent *event)
{
mousePressEventHandler(event);
}
void DummyItem::mouseMoveEvent(QMouseEvent *event)
{
mouseMoveEventHandler(event);
}
void DummyItem::mouseReleaseEvent(QMouseEvent *event)
{
mouseReleaseEventHandler(event);
}
void DummyItem::mouseDoubleClickEvent(QMouseEvent *event)
{
mouseDoubleClickEventHandler(event);
}
void DummyItem::defaultTouchEventHandler(QTouchEvent *event)
{
event->accept();
}
void DummyItem::defaultMouseEventHandler(QMouseEvent *event)
{
event->accept();
}
|