File indexing completed on 2024-11-10 04:56:03

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #include "kwin_wayland_test.h"
0010 
0011 #include "cursor.h"
0012 #include "wayland_server.h"
0013 
0014 #include <QSignalSpy>
0015 
0016 namespace KWin
0017 {
0018 
0019 static const QString s_socketName = QStringLiteral("wayland_test_kwin_platform_cursor-0");
0020 
0021 class PlatformCursorTest : public QObject
0022 {
0023     Q_OBJECT
0024 private Q_SLOTS:
0025     void initTestCase();
0026     void testPos();
0027 };
0028 
0029 void PlatformCursorTest::initTestCase()
0030 {
0031     QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
0032     QVERIFY(waylandServer()->init(s_socketName));
0033     Test::setOutputConfig({
0034         QRect(0, 0, 1280, 1024),
0035         QRect(1280, 0, 1280, 1024),
0036     });
0037 
0038     kwinApp()->start();
0039     QVERIFY(applicationStartedSpy.wait());
0040 }
0041 
0042 void PlatformCursorTest::testPos()
0043 {
0044     // this test verifies that the PlatformCursor of the QPA plugin forwards ::pos and ::setPos correctly
0045     // that is QCursor should work just like KWin::Cursor
0046 
0047     // cursor should be centered on screen
0048     QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(639, 511));
0049     QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(639, 511));
0050 
0051     // let's set the pos through QCursor API
0052     QCursor::setPos(QPoint(10, 10));
0053     QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(10, 10));
0054     QCOMPARE(QCursor::pos(), QPoint(10, 10));
0055 
0056     // and let's set the pos through Cursor API
0057     QCursor::setPos(QPoint(20, 20));
0058     QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(20, 20));
0059     QCOMPARE(QCursor::pos(), QPoint(20, 20));
0060 }
0061 
0062 }
0063 
0064 WAYLANDTEST_MAIN(KWin::PlatformCursorTest)
0065 #include "platformcursor.moc"