[autotest/libinput] Add a mocked test for Libinput::TouchEvent
This commit is contained in:
parent
8851bb8daa
commit
1e564989c9
4 changed files with 168 additions and 15 deletions
|
@ -36,6 +36,20 @@ target_link_libraries( testLibinputPointerEvent Qt5::Test Qt5::Widgets KF5::Conf
|
|||
add_test(kwin-testLibinputPointerEvent testLibinputPointerEvent)
|
||||
ecm_mark_as_test(testLibinputPointerEvent)
|
||||
|
||||
########################################################
|
||||
# Test Touch Event
|
||||
########################################################
|
||||
set( testLibinputTouchEvent_SRCS
|
||||
touch_event_test.cpp
|
||||
mock_libinput.cpp
|
||||
../../libinput/device.cpp
|
||||
../../libinput/events.cpp
|
||||
)
|
||||
add_executable(testLibinputTouchEvent ${testLibinputTouchEvent_SRCS})
|
||||
target_link_libraries( testLibinputTouchEvent Qt5::Test Qt5::Widgets KF5::ConfigCore)
|
||||
add_test(kwin-testLibinputTouchEvent testLibinputTouchEvent)
|
||||
ecm_mark_as_test(testLibinputTouchEvent)
|
||||
|
||||
########################################################
|
||||
# Test Input Events
|
||||
########################################################
|
||||
|
|
|
@ -251,7 +251,13 @@ struct libinput_event_pointer *libinput_event_get_pointer_event(struct libinput_
|
|||
|
||||
struct libinput_event_touch *libinput_event_get_touch_event(struct libinput_event *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
if (event->type == LIBINPUT_EVENT_TOUCH_DOWN ||
|
||||
event->type == LIBINPUT_EVENT_TOUCH_UP ||
|
||||
event->type == LIBINPUT_EVENT_TOUCH_MOTION ||
|
||||
event->type == LIBINPUT_EVENT_TOUCH_CANCEL ||
|
||||
event->type == LIBINPUT_EVENT_TOUCH_FRAME) {
|
||||
return reinterpret_cast<libinput_event_touch *>(event);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -341,38 +347,36 @@ double libinput_event_pointer_get_axis_value(struct libinput_event_pointer *even
|
|||
|
||||
uint32_t libinput_event_touch_get_time(struct libinput_event_touch *event)
|
||||
{
|
||||
Q_UNUSED(time)
|
||||
return 0;
|
||||
return event->time;
|
||||
}
|
||||
|
||||
double libinput_event_touch_get_x(struct libinput_event_touch *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
return 0.0;
|
||||
return event->absolutePos.x();
|
||||
}
|
||||
|
||||
double libinput_event_touch_get_y(struct libinput_event_touch *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
return 0.0;
|
||||
return event->absolutePos.y();
|
||||
}
|
||||
|
||||
double libinput_event_touch_get_x_transformed(struct libinput_event_touch *event, uint32_t width)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
Q_UNUSED(width)
|
||||
return 0.0;
|
||||
double deviceWidth = 0.0;
|
||||
double deviceHeight = 0.0;
|
||||
libinput_device_get_size(event->device, &deviceWidth, &deviceHeight);
|
||||
return event->absolutePos.x() / deviceWidth * width;
|
||||
}
|
||||
|
||||
double libinput_event_touch_get_y_transformed(struct libinput_event_touch *event, uint32_t height)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
Q_UNUSED(height)
|
||||
return 0.0;
|
||||
double deviceWidth = 0.0;
|
||||
double deviceHeight = 0.0;
|
||||
libinput_device_get_size(event->device, &deviceWidth, &deviceHeight);
|
||||
return event->absolutePos.y() / deviceHeight * height;
|
||||
}
|
||||
|
||||
int32_t libinput_event_touch_get_slot(struct libinput_event_touch *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
return 0;
|
||||
return event->slot;
|
||||
}
|
||||
|
|
|
@ -81,4 +81,9 @@ struct libinput_event_pointer : libinput_event {
|
|||
QPointF absolutePos;
|
||||
};
|
||||
|
||||
struct libinput_event_touch : libinput_event {
|
||||
qint32 slot = -1;
|
||||
QPointF absolutePos;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
130
autotests/libinput/touch_event_test.cpp
Normal file
130
autotests/libinput/touch_event_test.cpp
Normal file
|
@ -0,0 +1,130 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
#include "mock_libinput.h"
|
||||
#include "../../libinput/device.h"
|
||||
#include "../../libinput/events.h"
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include <linux/input.h>
|
||||
|
||||
Q_DECLARE_METATYPE(libinput_event_type)
|
||||
|
||||
using namespace KWin::LibInput;
|
||||
|
||||
class TestLibinputTouchEvent : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
void testType_data();
|
||||
void testType();
|
||||
void testAbsoluteMotion_data();
|
||||
void testAbsoluteMotion();
|
||||
|
||||
private:
|
||||
libinput_device *m_nativeDevice = nullptr;
|
||||
Device *m_device = nullptr;
|
||||
};
|
||||
|
||||
void TestLibinputTouchEvent::init()
|
||||
{
|
||||
m_nativeDevice = new libinput_device;
|
||||
m_nativeDevice->touch = true;
|
||||
m_nativeDevice->deviceSize = QSizeF(12.5, 13.8);
|
||||
m_device = new Device(m_nativeDevice);
|
||||
}
|
||||
|
||||
void TestLibinputTouchEvent::cleanup()
|
||||
{
|
||||
delete m_device;
|
||||
m_device = nullptr;
|
||||
|
||||
delete m_nativeDevice;
|
||||
m_nativeDevice = nullptr;
|
||||
}
|
||||
|
||||
void TestLibinputTouchEvent::testType_data()
|
||||
{
|
||||
QTest::addColumn<libinput_event_type>("type");
|
||||
QTest::addColumn<bool>("hasId");
|
||||
|
||||
QTest::newRow("down") << LIBINPUT_EVENT_TOUCH_DOWN << true;
|
||||
QTest::newRow("up") << LIBINPUT_EVENT_TOUCH_UP << true;
|
||||
QTest::newRow("motion") << LIBINPUT_EVENT_TOUCH_MOTION << true;
|
||||
QTest::newRow("cancel") << LIBINPUT_EVENT_TOUCH_CANCEL << false;
|
||||
QTest::newRow("frame") << LIBINPUT_EVENT_TOUCH_FRAME << false;
|
||||
}
|
||||
|
||||
void TestLibinputTouchEvent::testType()
|
||||
{
|
||||
// this test verifies the initialization of a PointerEvent and the parent Event class
|
||||
libinput_event_touch *touchEvent = new libinput_event_touch;
|
||||
QFETCH(libinput_event_type, type);
|
||||
touchEvent->type = type;
|
||||
touchEvent->device = m_nativeDevice;
|
||||
touchEvent->slot = 0;
|
||||
|
||||
QScopedPointer<Event> event(Event::create(touchEvent));
|
||||
// API of event
|
||||
QCOMPARE(event->type(), type);
|
||||
QCOMPARE(event->device(), m_device);
|
||||
QCOMPARE(event->nativeDevice(), m_nativeDevice);
|
||||
QCOMPARE((libinput_event*)(*event.data()), touchEvent);
|
||||
// verify it's a pointer event
|
||||
QVERIFY(dynamic_cast<TouchEvent*>(event.data()));
|
||||
QCOMPARE((libinput_event_touch*)(*dynamic_cast<TouchEvent*>(event.data())), touchEvent);
|
||||
QFETCH(bool, hasId);
|
||||
if (hasId) {
|
||||
QCOMPARE(dynamic_cast<TouchEvent*>(event.data())->id(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void TestLibinputTouchEvent::testAbsoluteMotion_data()
|
||||
{
|
||||
QTest::addColumn<libinput_event_type>("type");
|
||||
QTest::newRow("down") << LIBINPUT_EVENT_TOUCH_DOWN;
|
||||
QTest::newRow("motion") << LIBINPUT_EVENT_TOUCH_MOTION;
|
||||
}
|
||||
|
||||
void TestLibinputTouchEvent::testAbsoluteMotion()
|
||||
{
|
||||
// this test verifies absolute touch points (either down or motion)
|
||||
libinput_event_touch *touchEvent = new libinput_event_touch;
|
||||
touchEvent->device = m_nativeDevice;
|
||||
QFETCH(libinput_event_type, type);
|
||||
touchEvent->type = type;
|
||||
touchEvent->absolutePos = QPointF(6.25, 6.9);
|
||||
touchEvent->time = 500u;
|
||||
touchEvent->slot = 1;
|
||||
|
||||
QScopedPointer<Event> event(Event::create(touchEvent));
|
||||
auto te = dynamic_cast<TouchEvent*>(event.data());
|
||||
QVERIFY(te);
|
||||
QCOMPARE(te->type(), type);
|
||||
QCOMPARE(te->time(), 500u);
|
||||
QCOMPARE(te->absolutePos(), QPointF(6.25, 6.9));
|
||||
QCOMPARE(te->absolutePos(QSize(1280, 1024)), QPointF(640, 512));
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestLibinputTouchEvent)
|
||||
#include "touch_event_test.moc"
|
Loading…
Reference in a new issue