2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2014-09-02 07:34:31 +00:00
|
|
|
// Qt
|
2018-11-06 06:22:36 +00:00
|
|
|
#include <QtTest>
|
2014-09-02 07:34:31 +00:00
|
|
|
// WaylandServer
|
2014-09-17 12:35:33 +00:00
|
|
|
#include "../../src/server/display.h"
|
2014-11-25 12:52:40 +00:00
|
|
|
#include "../../src/server/pointer_interface.h"
|
2014-09-17 12:35:33 +00:00
|
|
|
#include "../../src/server/seat_interface.h"
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestWaylandServerSeat : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void testCapabilities();
|
|
|
|
void testName();
|
|
|
|
void testPointerButton();
|
|
|
|
void testPointerPos();
|
2014-09-03 18:02:42 +00:00
|
|
|
void testDestroyThroughTerminate();
|
2015-09-02 14:00:11 +00:00
|
|
|
void testRepeatInfo();
|
2015-12-15 14:47:19 +00:00
|
|
|
void testMultiple();
|
2014-09-02 07:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwin-wayland-server-seat-test-0");
|
|
|
|
|
|
|
|
void TestWaylandServerSeat::testCapabilities()
|
|
|
|
{
|
|
|
|
Display display;
|
|
|
|
display.setSocketName(s_socketName);
|
|
|
|
display.start();
|
|
|
|
SeatInterface *seat = display.createSeat();
|
|
|
|
QVERIFY(!seat->hasKeyboard());
|
|
|
|
QVERIFY(!seat->hasPointer());
|
|
|
|
QVERIFY(!seat->hasTouch());
|
|
|
|
|
|
|
|
QSignalSpy keyboardSpy(seat, SIGNAL(hasKeyboardChanged(bool)));
|
|
|
|
QVERIFY(keyboardSpy.isValid());
|
|
|
|
seat->setHasKeyboard(true);
|
|
|
|
QCOMPARE(keyboardSpy.count(), 1);
|
|
|
|
QVERIFY(keyboardSpy.last().first().toBool());
|
|
|
|
QVERIFY(seat->hasKeyboard());
|
|
|
|
seat->setHasKeyboard(false);
|
|
|
|
QCOMPARE(keyboardSpy.count(), 2);
|
|
|
|
QVERIFY(!keyboardSpy.last().first().toBool());
|
|
|
|
QVERIFY(!seat->hasKeyboard());
|
|
|
|
seat->setHasKeyboard(false);
|
|
|
|
QCOMPARE(keyboardSpy.count(), 2);
|
|
|
|
|
|
|
|
QSignalSpy pointerSpy(seat, SIGNAL(hasPointerChanged(bool)));
|
|
|
|
QVERIFY(pointerSpy.isValid());
|
|
|
|
seat->setHasPointer(true);
|
|
|
|
QCOMPARE(pointerSpy.count(), 1);
|
|
|
|
QVERIFY(pointerSpy.last().first().toBool());
|
|
|
|
QVERIFY(seat->hasPointer());
|
|
|
|
seat->setHasPointer(false);
|
|
|
|
QCOMPARE(pointerSpy.count(), 2);
|
|
|
|
QVERIFY(!pointerSpy.last().first().toBool());
|
|
|
|
QVERIFY(!seat->hasPointer());
|
|
|
|
seat->setHasPointer(false);
|
|
|
|
QCOMPARE(pointerSpy.count(), 2);
|
|
|
|
|
|
|
|
QSignalSpy touchSpy(seat, SIGNAL(hasTouchChanged(bool)));
|
|
|
|
QVERIFY(touchSpy.isValid());
|
|
|
|
seat->setHasTouch(true);
|
|
|
|
QCOMPARE(touchSpy.count(), 1);
|
|
|
|
QVERIFY(touchSpy.last().first().toBool());
|
|
|
|
QVERIFY(seat->hasTouch());
|
|
|
|
seat->setHasTouch(false);
|
|
|
|
QCOMPARE(touchSpy.count(), 2);
|
|
|
|
QVERIFY(!touchSpy.last().first().toBool());
|
|
|
|
QVERIFY(!seat->hasTouch());
|
|
|
|
seat->setHasTouch(false);
|
|
|
|
QCOMPARE(touchSpy.count(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandServerSeat::testName()
|
|
|
|
{
|
|
|
|
Display display;
|
|
|
|
display.setSocketName(s_socketName);
|
|
|
|
display.start();
|
|
|
|
SeatInterface *seat = display.createSeat();
|
|
|
|
QCOMPARE(seat->name(), QString());
|
|
|
|
|
|
|
|
QSignalSpy nameSpy(seat, SIGNAL(nameChanged(QString)));
|
|
|
|
QVERIFY(nameSpy.isValid());
|
|
|
|
const QString name = QStringLiteral("foobar");
|
|
|
|
seat->setName(name);
|
|
|
|
QCOMPARE(seat->name(), name);
|
|
|
|
QCOMPARE(nameSpy.count(), 1);
|
|
|
|
QCOMPARE(nameSpy.first().first().toString(), name);
|
|
|
|
seat->setName(name);
|
|
|
|
QCOMPARE(nameSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandServerSeat::testPointerButton()
|
|
|
|
{
|
|
|
|
Display display;
|
|
|
|
display.setSocketName(s_socketName);
|
|
|
|
display.start();
|
|
|
|
SeatInterface *seat = display.createSeat();
|
2014-11-25 15:04:07 +00:00
|
|
|
PointerInterface *pointer = seat->focusedPointer();
|
2014-11-26 09:34:23 +00:00
|
|
|
QVERIFY(!pointer);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
// no button pressed yet, should be released and no serial
|
2014-11-26 10:50:52 +00:00
|
|
|
QVERIFY(!seat->isPointerButtonPressed(0));
|
|
|
|
QVERIFY(!seat->isPointerButtonPressed(1));
|
|
|
|
QCOMPARE(seat->pointerButtonSerial(0), quint32(0));
|
|
|
|
QCOMPARE(seat->pointerButtonSerial(1), quint32(0));
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
// mark the button as pressed
|
2014-11-26 10:50:52 +00:00
|
|
|
seat->pointerButtonPressed(0);
|
|
|
|
QVERIFY(seat->isPointerButtonPressed(0));
|
|
|
|
QCOMPARE(seat->pointerButtonSerial(0), display.serial());
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
// other button should still be unpressed
|
2014-11-26 10:50:52 +00:00
|
|
|
QVERIFY(!seat->isPointerButtonPressed(1));
|
|
|
|
QCOMPARE(seat->pointerButtonSerial(1), quint32(0));
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
// release it again
|
2014-11-26 10:50:52 +00:00
|
|
|
seat->pointerButtonReleased(0);
|
|
|
|
QVERIFY(!seat->isPointerButtonPressed(0));
|
|
|
|
QCOMPARE(seat->pointerButtonSerial(0), display.serial());
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandServerSeat::testPointerPos()
|
|
|
|
{
|
|
|
|
Display display;
|
|
|
|
display.setSocketName(s_socketName);
|
|
|
|
display.start();
|
|
|
|
SeatInterface *seat = display.createSeat();
|
2014-11-25 13:24:52 +00:00
|
|
|
QSignalSpy seatPosSpy(seat, SIGNAL(pointerPosChanged(QPointF)));
|
|
|
|
QVERIFY(seatPosSpy.isValid());
|
2014-11-25 15:04:07 +00:00
|
|
|
PointerInterface *pointer = seat->focusedPointer();
|
2014-11-26 09:34:23 +00:00
|
|
|
QVERIFY(!pointer);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2014-11-25 13:24:52 +00:00
|
|
|
QCOMPARE(seat->pointerPos(), QPointF());
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2014-11-26 10:50:52 +00:00
|
|
|
seat->setPointerPos(QPointF(10, 15));
|
2014-11-25 13:24:52 +00:00
|
|
|
QCOMPARE(seat->pointerPos(), QPointF(10, 15));
|
|
|
|
QCOMPARE(seatPosSpy.count(), 1);
|
|
|
|
QCOMPARE(seatPosSpy.first().first().toPointF(), QPointF(10, 15));
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2014-11-26 10:50:52 +00:00
|
|
|
seat->setPointerPos(QPointF(10, 15));
|
2014-11-25 13:24:52 +00:00
|
|
|
QCOMPARE(seatPosSpy.count(), 1);
|
|
|
|
|
|
|
|
seat->setPointerPos(QPointF(5, 7));
|
|
|
|
QCOMPARE(seat->pointerPos(), QPointF(5, 7));
|
|
|
|
QCOMPARE(seatPosSpy.count(), 2);
|
|
|
|
QCOMPARE(seatPosSpy.first().first().toPointF(), QPointF(10, 15));
|
|
|
|
QCOMPARE(seatPosSpy.last().first().toPointF(), QPointF(5, 7));
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-03 18:02:42 +00:00
|
|
|
void TestWaylandServerSeat::testDestroyThroughTerminate()
|
|
|
|
{
|
2020-07-06 09:36:25 +00:00
|
|
|
QScopedPointer<Display> display(new Display());
|
|
|
|
display->setSocketName(s_socketName);
|
|
|
|
display->start();
|
|
|
|
SeatInterface *seat = display->createSeat();
|
2014-09-03 18:02:42 +00:00
|
|
|
QSignalSpy destroyedSpy(seat, SIGNAL(destroyed(QObject*)));
|
|
|
|
QVERIFY(destroyedSpy.isValid());
|
2020-07-06 09:36:25 +00:00
|
|
|
display.reset();
|
2014-09-03 18:02:42 +00:00
|
|
|
QVERIFY(!destroyedSpy.isEmpty());
|
|
|
|
}
|
|
|
|
|
2015-09-02 14:00:11 +00:00
|
|
|
void TestWaylandServerSeat::testRepeatInfo()
|
|
|
|
{
|
|
|
|
Display display;
|
|
|
|
display.setSocketName(s_socketName);
|
|
|
|
display.start();
|
|
|
|
SeatInterface *seat = display.createSeat();
|
|
|
|
QCOMPARE(seat->keyRepeatRate(), 0);
|
|
|
|
QCOMPARE(seat->keyRepeatDelay(), 0);
|
|
|
|
seat->setKeyRepeatInfo(25, 660);
|
|
|
|
QCOMPARE(seat->keyRepeatRate(), 25);
|
|
|
|
QCOMPARE(seat->keyRepeatDelay(), 660);
|
|
|
|
// setting negative values should result in 0
|
|
|
|
seat->setKeyRepeatInfo(-25, -660);
|
|
|
|
QCOMPARE(seat->keyRepeatRate(), 0);
|
|
|
|
QCOMPARE(seat->keyRepeatDelay(), 0);
|
|
|
|
}
|
|
|
|
|
2015-12-15 14:47:19 +00:00
|
|
|
void TestWaylandServerSeat::testMultiple()
|
|
|
|
{
|
|
|
|
Display display;
|
|
|
|
display.setSocketName(s_socketName);
|
|
|
|
display.start();
|
|
|
|
QVERIFY(display.seats().isEmpty());
|
|
|
|
SeatInterface *seat1 = display.createSeat();
|
|
|
|
QCOMPARE(display.seats().count(), 1);
|
|
|
|
QCOMPARE(display.seats().at(0), seat1);
|
|
|
|
SeatInterface *seat2 = display.createSeat();
|
|
|
|
QCOMPARE(display.seats().count(), 2);
|
|
|
|
QCOMPARE(display.seats().at(0), seat1);
|
|
|
|
QCOMPARE(display.seats().at(1), seat2);
|
|
|
|
SeatInterface *seat3 = display.createSeat();
|
|
|
|
QCOMPARE(display.seats().count(), 3);
|
|
|
|
QCOMPARE(display.seats().at(0), seat1);
|
|
|
|
QCOMPARE(display.seats().at(1), seat2);
|
|
|
|
QCOMPARE(display.seats().at(2), seat3);
|
|
|
|
|
|
|
|
delete seat3;
|
|
|
|
QCOMPARE(display.seats().count(), 2);
|
|
|
|
QCOMPARE(display.seats().at(0), seat1);
|
|
|
|
QCOMPARE(display.seats().at(1), seat2);
|
|
|
|
|
|
|
|
delete seat2;
|
|
|
|
QCOMPARE(display.seats().count(), 1);
|
|
|
|
QCOMPARE(display.seats().at(0), seat1);
|
|
|
|
|
|
|
|
delete seat1;
|
|
|
|
QCOMPARE(display.seats().count(), 0);
|
|
|
|
}
|
|
|
|
|
2014-09-23 10:00:17 +00:00
|
|
|
QTEST_GUILESS_MAIN(TestWaylandServerSeat)
|
2014-09-02 07:34:31 +00:00
|
|
|
#include "test_seat.moc"
|