Warning, file /plasma/plasma-workspace/libtaskmanager/autotests/waylandtasksmodeltest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2023 Fushan Wen <qydwhotmail@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #define QT_FORCE_ASSERTS 1
0008 
0009 #include <qpa/qplatformnativeinterface.h>
0010 
0011 #include <wayland-client-core.h>
0012 
0013 #include "common.h"
0014 #include "waylandtasksmodel.h"
0015 
0016 using namespace TaskManager;
0017 
0018 class WaylandTasksModelTest : public QObject
0019 {
0020     Q_OBJECT
0021 
0022 private Q_SLOTS:
0023     void initTestCase();
0024     void cleanupTestCase();
0025 
0026     void test_openCloseWindow();
0027     void test_modelData();
0028     void test_fullscreen();
0029     void test_geometry();
0030     void test_stackingOrder();
0031     void test_modelDataFromDesktopFile();
0032 
0033     void test_request();
0034 
0035 private:
0036     WaylandTasksModel m_model;
0037 };
0038 
0039 void WaylandTasksModelTest::initTestCase()
0040 {
0041     if (!KWindowSystem::isPlatformWayland()) {
0042         QSKIP("Test is not running on Wayland.");
0043     }
0044 
0045     QGuiApplication::setQuitOnLastWindowClosed(false);
0046 
0047     QStandardPaths::setTestModeEnabled(true);
0048 
0049     const QString applicationDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QDir::separator() + QStringLiteral("applications");
0050     QDir dir;
0051     if (!dir.exists(applicationDir)) {
0052         dir.mkpath(applicationDir);
0053     }
0054 
0055     QPlatformNativeInterface *const native = qGuiApp->platformNativeInterface();
0056     wl_display_roundtrip(static_cast<struct wl_display *>(native->nativeResourceForIntegration("wl_display")));
0057 }
0058 
0059 void WaylandTasksModelTest::cleanupTestCase()
0060 {
0061     TestUtils::cleanupTestCase();
0062 }
0063 
0064 void WaylandTasksModelTest::test_openCloseWindow()
0065 {
0066     TestUtils::testOpenCloseWindow(m_model);
0067 }
0068 
0069 void WaylandTasksModelTest::test_modelData()
0070 {
0071     const QString title = QStringLiteral("__testwindow__%1").arg(QDateTime::currentDateTime().toString());
0072     QModelIndex index;
0073     auto window = TestUtils::createSingleWindow(m_model, title, index);
0074 
0075     // See WaylandTasksModel::data for available roles
0076     // Icon is unavailable on Wayland
0077 
0078     QTRY_COMPARE(index.data(AbstractTasksModel::WinIdList).toList().size(), 1);
0079     QVERIFY(index.data(AbstractTasksModel::MimeType).toString().startsWith(QLatin1String("windowsystem/winid")));
0080 
0081     QTRY_VERIFY(index.data(AbstractTasksModel::IsWindow).toBool());
0082     QTRY_VERIFY(index.data(AbstractTasksModel::IsActive).toBool());
0083 
0084     QTRY_VERIFY(index.data(AbstractTasksModel::IsClosable).toBool());
0085     QTRY_VERIFY(index.data(AbstractTasksModel::IsMovable).toBool());
0086     QTRY_VERIFY(index.data(AbstractTasksModel::IsResizable).toBool());
0087     QTRY_VERIFY(index.data(AbstractTasksModel::IsMaximizable).toBool());
0088     QTRY_VERIFY(!index.data(AbstractTasksModel::IsMaximized).toBool());
0089     QTRY_VERIFY(index.data(AbstractTasksModel::IsMinimizable).toBool());
0090     QTRY_VERIFY(!index.data(AbstractTasksModel::IsKeepAbove).toBool());
0091     QTRY_VERIFY(!index.data(AbstractTasksModel::IsKeepBelow).toBool());
0092     QTRY_VERIFY(index.data(AbstractTasksModel::IsFullScreenable).toBool());
0093     QTRY_VERIFY(!index.data(AbstractTasksModel::IsFullScreen).toBool());
0094     QTRY_VERIFY(!index.data(AbstractTasksModel::IsShadeable).toBool()); // It's intentionally not implemented on wayland
0095     QTRY_VERIFY(!index.data(AbstractTasksModel::IsShaded).toBool());
0096     QTRY_VERIFY(index.data(AbstractTasksModel::IsVirtualDesktopsChangeable).toBool());
0097     QTRY_VERIFY(!index.data(AbstractTasksModel::IsOnAllVirtualDesktops).toBool());
0098 
0099     // Due to window decoration, the size of a window can't be determined accurately
0100     const QRect screenGeometry = index.data(AbstractTasksModel::ScreenGeometry).toRect();
0101     QVERIFY(screenGeometry.width() > 0 && screenGeometry.height() > 0);
0102 
0103     QTRY_VERIFY(!index.data(AbstractTasksModel::IsDemandingAttention).toBool());
0104     QTRY_VERIFY(!index.data(AbstractTasksModel::SkipTaskbar).toBool());
0105     QTRY_VERIFY(!index.data(AbstractTasksModel::SkipPager).toBool());
0106     // AbstractTasksModel::AppPid
0107 
0108     QVERIFY(index.data(AbstractTasksModel::CanLaunchNewInstance).toBool());
0109 }
0110 
0111 void WaylandTasksModelTest::test_fullscreen()
0112 {
0113     TestUtils::testFullscreen(m_model);
0114 }
0115 
0116 void WaylandTasksModelTest::test_geometry()
0117 {
0118     TestUtils::testGeometry(m_model);
0119 }
0120 
0121 void WaylandTasksModelTest::test_stackingOrder()
0122 {
0123     TestUtils::testStackingOrder(m_model);
0124 }
0125 
0126 void WaylandTasksModelTest::test_modelDataFromDesktopFile()
0127 {
0128     TestUtils::testModelDataFromDesktopFile(m_model);
0129 }
0130 
0131 void WaylandTasksModelTest::test_request()
0132 {
0133     TestUtils::testRequest(m_model);
0134 }
0135 
0136 QTEST_MAIN(WaylandTasksModelTest)
0137 
0138 #include "waylandtasksmodeltest.moc"