File indexing completed on 2024-11-10 04:56:22
0001 /* 0002 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 // Qt 0007 #include <QSignalSpy> 0008 #include <QTest> 0009 // WaylandServer 0010 #include "wayland/display.h" 0011 #include "wayland/keyboard.h" 0012 #include "wayland/pointer.h" 0013 #include "wayland/seat.h" 0014 0015 using namespace KWin; 0016 0017 class TestWaylandServerSeat : public QObject 0018 { 0019 Q_OBJECT 0020 private Q_SLOTS: 0021 void testCapabilities(); 0022 void testName(); 0023 void testPointerButton(); 0024 void testPointerPos(); 0025 void testRepeatInfo(); 0026 void testMultiple(); 0027 }; 0028 0029 static const QString s_socketName = QStringLiteral("kwin-wayland-server-seat-test-0"); 0030 0031 void TestWaylandServerSeat::testCapabilities() 0032 { 0033 KWin::Display display; 0034 display.addSocketName(s_socketName); 0035 display.start(); 0036 SeatInterface *seat = new SeatInterface(&display, &display); 0037 QVERIFY(!seat->hasKeyboard()); 0038 QVERIFY(!seat->hasPointer()); 0039 QVERIFY(!seat->hasTouch()); 0040 0041 QSignalSpy keyboardSpy(seat, &SeatInterface::hasKeyboardChanged); 0042 seat->setHasKeyboard(true); 0043 QCOMPARE(keyboardSpy.count(), 1); 0044 QVERIFY(keyboardSpy.last().first().toBool()); 0045 QVERIFY(seat->hasKeyboard()); 0046 seat->setHasKeyboard(false); 0047 QCOMPARE(keyboardSpy.count(), 2); 0048 QVERIFY(!keyboardSpy.last().first().toBool()); 0049 QVERIFY(!seat->hasKeyboard()); 0050 seat->setHasKeyboard(false); 0051 QCOMPARE(keyboardSpy.count(), 2); 0052 0053 QSignalSpy pointerSpy(seat, &SeatInterface::hasPointerChanged); 0054 seat->setHasPointer(true); 0055 QCOMPARE(pointerSpy.count(), 1); 0056 QVERIFY(pointerSpy.last().first().toBool()); 0057 QVERIFY(seat->hasPointer()); 0058 seat->setHasPointer(false); 0059 QCOMPARE(pointerSpy.count(), 2); 0060 QVERIFY(!pointerSpy.last().first().toBool()); 0061 QVERIFY(!seat->hasPointer()); 0062 seat->setHasPointer(false); 0063 QCOMPARE(pointerSpy.count(), 2); 0064 0065 QSignalSpy touchSpy(seat, &SeatInterface::hasTouchChanged); 0066 seat->setHasTouch(true); 0067 QCOMPARE(touchSpy.count(), 1); 0068 QVERIFY(touchSpy.last().first().toBool()); 0069 QVERIFY(seat->hasTouch()); 0070 seat->setHasTouch(false); 0071 QCOMPARE(touchSpy.count(), 2); 0072 QVERIFY(!touchSpy.last().first().toBool()); 0073 QVERIFY(!seat->hasTouch()); 0074 seat->setHasTouch(false); 0075 QCOMPARE(touchSpy.count(), 2); 0076 } 0077 0078 void TestWaylandServerSeat::testName() 0079 { 0080 KWin::Display display; 0081 display.addSocketName(s_socketName); 0082 display.start(); 0083 SeatInterface *seat = new SeatInterface(&display, &display); 0084 QCOMPARE(seat->name(), QString()); 0085 0086 QSignalSpy nameSpy(seat, &SeatInterface::nameChanged); 0087 const QString name = QStringLiteral("foobar"); 0088 seat->setName(name); 0089 QCOMPARE(seat->name(), name); 0090 QCOMPARE(nameSpy.count(), 1); 0091 QCOMPARE(nameSpy.first().first().toString(), name); 0092 seat->setName(name); 0093 QCOMPARE(nameSpy.count(), 1); 0094 } 0095 0096 void TestWaylandServerSeat::testPointerButton() 0097 { 0098 KWin::Display display; 0099 display.addSocketName(s_socketName); 0100 display.start(); 0101 SeatInterface *seat = new SeatInterface(&display, &display); 0102 seat->setHasPointer(true); 0103 0104 // no button pressed yet, should be released and no serial 0105 QVERIFY(!seat->isPointerButtonPressed(0)); 0106 QVERIFY(!seat->isPointerButtonPressed(1)); 0107 QCOMPARE(seat->pointerButtonSerial(0), quint32(0)); 0108 QCOMPARE(seat->pointerButtonSerial(1), quint32(0)); 0109 0110 // mark the button as pressed 0111 seat->notifyPointerButton(0, PointerButtonState::Pressed); 0112 seat->notifyPointerFrame(); 0113 QVERIFY(seat->isPointerButtonPressed(0)); 0114 QCOMPARE(seat->pointerButtonSerial(0), display.serial()); 0115 0116 // other button should still be unpressed 0117 QVERIFY(!seat->isPointerButtonPressed(1)); 0118 QCOMPARE(seat->pointerButtonSerial(1), quint32(0)); 0119 0120 // release it again 0121 seat->notifyPointerButton(0, PointerButtonState::Released); 0122 seat->notifyPointerFrame(); 0123 QVERIFY(!seat->isPointerButtonPressed(0)); 0124 QCOMPARE(seat->pointerButtonSerial(0), display.serial()); 0125 } 0126 0127 void TestWaylandServerSeat::testPointerPos() 0128 { 0129 KWin::Display display; 0130 display.addSocketName(s_socketName); 0131 display.start(); 0132 SeatInterface *seat = new SeatInterface(&display, &display); 0133 seat->setHasPointer(true); 0134 QSignalSpy seatPosSpy(seat, &SeatInterface::pointerPosChanged); 0135 0136 QCOMPARE(seat->pointerPos(), QPointF()); 0137 0138 seat->notifyPointerMotion(QPointF(10, 15)); 0139 seat->notifyPointerFrame(); 0140 QCOMPARE(seat->pointerPos(), QPointF(10, 15)); 0141 QCOMPARE(seatPosSpy.count(), 1); 0142 QCOMPARE(seatPosSpy.first().first().toPointF(), QPointF(10, 15)); 0143 0144 seat->notifyPointerMotion(QPointF(10, 15)); 0145 seat->notifyPointerFrame(); 0146 QCOMPARE(seatPosSpy.count(), 1); 0147 0148 seat->notifyPointerMotion(QPointF(5, 7)); 0149 seat->notifyPointerFrame(); 0150 QCOMPARE(seat->pointerPos(), QPointF(5, 7)); 0151 QCOMPARE(seatPosSpy.count(), 2); 0152 QCOMPARE(seatPosSpy.first().first().toPointF(), QPointF(10, 15)); 0153 QCOMPARE(seatPosSpy.last().first().toPointF(), QPointF(5, 7)); 0154 } 0155 0156 void TestWaylandServerSeat::testRepeatInfo() 0157 { 0158 KWin::Display display; 0159 display.addSocketName(s_socketName); 0160 display.start(); 0161 SeatInterface *seat = new SeatInterface(&display, &display); 0162 seat->setHasKeyboard(true); 0163 QCOMPARE(seat->keyboard()->keyRepeatRate(), 0); 0164 QCOMPARE(seat->keyboard()->keyRepeatDelay(), 0); 0165 seat->keyboard()->setRepeatInfo(25, 660); 0166 QCOMPARE(seat->keyboard()->keyRepeatRate(), 25); 0167 QCOMPARE(seat->keyboard()->keyRepeatDelay(), 660); 0168 // setting negative values should result in 0 0169 seat->keyboard()->setRepeatInfo(-25, -660); 0170 QCOMPARE(seat->keyboard()->keyRepeatRate(), 0); 0171 QCOMPARE(seat->keyboard()->keyRepeatDelay(), 0); 0172 } 0173 0174 void TestWaylandServerSeat::testMultiple() 0175 { 0176 KWin::Display display; 0177 display.addSocketName(s_socketName); 0178 display.start(); 0179 QVERIFY(display.seats().isEmpty()); 0180 SeatInterface *seat1 = new SeatInterface(&display, &display); 0181 QCOMPARE(display.seats().count(), 1); 0182 QCOMPARE(display.seats().at(0), seat1); 0183 SeatInterface *seat2 = new SeatInterface(&display, &display); 0184 QCOMPARE(display.seats().count(), 2); 0185 QCOMPARE(display.seats().at(0), seat1); 0186 QCOMPARE(display.seats().at(1), seat2); 0187 SeatInterface *seat3 = new SeatInterface(&display, &display); 0188 QCOMPARE(display.seats().count(), 3); 0189 QCOMPARE(display.seats().at(0), seat1); 0190 QCOMPARE(display.seats().at(1), seat2); 0191 QCOMPARE(display.seats().at(2), seat3); 0192 0193 delete seat3; 0194 QCOMPARE(display.seats().count(), 2); 0195 QCOMPARE(display.seats().at(0), seat1); 0196 QCOMPARE(display.seats().at(1), seat2); 0197 0198 delete seat2; 0199 QCOMPARE(display.seats().count(), 1); 0200 QCOMPARE(display.seats().at(0), seat1); 0201 0202 delete seat1; 0203 QCOMPARE(display.seats().count(), 0); 0204 } 0205 0206 QTEST_GUILESS_MAIN(TestWaylandServerSeat) 0207 #include "test_seat.moc"