Warning, file /frameworks/kservice/autotests/kautostarttest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2005 David Faure <faure@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 #include "kautostarttest.h" 0009 0010 #include <QStandardPaths> 0011 #include <QTest> 0012 0013 #include <QFile> 0014 0015 QTEST_MAIN(KAutostartTest) // Qt5 TODO: QTEST_GUILESS_MAIN 0016 0017 #include <kautostart.h> 0018 0019 void KAutostartTest::testStartDetection_data() 0020 { 0021 QTest::addColumn<QString>("service"); 0022 QTest::addColumn<bool>("doesAutostart"); 0023 if (KAutostart::isServiceRegistered(QStringLiteral("plasma-desktop"))) { 0024 QTest::newRow("plasma-desktop") << "plasma-desktop" << true; 0025 } 0026 if (KAutostart::isServiceRegistered(QStringLiteral("khotkeys"))) { 0027 QTest::newRow("khotkeys") << "khotkeys" << false; 0028 } 0029 QTest::newRow("does not exist") << "doesnotexist" << false; 0030 } 0031 0032 void KAutostartTest::testStartDetection() 0033 { 0034 QFETCH(QString, service); 0035 QFETCH(bool, doesAutostart); 0036 0037 KAutostart autostart(service); 0038 QCOMPARE(autostart.autostarts(), doesAutostart); 0039 } 0040 0041 void KAutostartTest::testStartInEnvDetection_data() 0042 { 0043 QTest::addColumn<QString>("env"); 0044 QTest::addColumn<bool>("doesAutostart"); 0045 QTest::newRow("kde") << "KDE" << true; 0046 QTest::newRow("xfce") << "XFCE" << false; 0047 } 0048 0049 void KAutostartTest::testStartInEnvDetection() 0050 { 0051 QFETCH(QString, env); 0052 QFETCH(bool, doesAutostart); 0053 0054 KAutostart autostart(QStringLiteral("plasma-desktop")); 0055 // Let's see if plasma.desktop actually exists 0056 if (QStandardPaths::locate(QStandardPaths::GenericConfigLocation, QStringLiteral("autostart/plasma-desktop.desktop")).isEmpty()) { 0057 QSKIP("plasma-desktop.desktop not found, kdebase not installed"); 0058 } else { 0059 QCOMPARE(autostart.autostarts(env), doesAutostart); 0060 } 0061 } 0062 0063 void KAutostartTest::testStartphase_data() 0064 { 0065 QTest::addColumn<QString>("service"); 0066 QTest::addColumn<int>("startPhase"); 0067 if (KAutostart::isServiceRegistered(QStringLiteral("plasma-desktop"))) { 0068 QTest::newRow("plasma-desktop") << "plasma-desktop" << int(KAutostart::BaseDesktop); 0069 } 0070 if (KAutostart::isServiceRegistered(QStringLiteral("klipper"))) { 0071 QTest::newRow("klipper") << "klipper" << int(KAutostart::Applications); 0072 } 0073 if (KAutostart::isServiceRegistered(QStringLiteral("khotkeys"))) { 0074 QTest::newRow("khotkeys") << "ktip" << int(KAutostart::Applications); 0075 } 0076 QTest::newRow("does not exist") << "doesnotexist" << int(KAutostart::Applications); 0077 } 0078 0079 void KAutostartTest::testStartphase() 0080 { 0081 QFETCH(QString, service); 0082 QFETCH(int, startPhase); 0083 0084 KAutostart autostart(service); 0085 QCOMPARE(int(autostart.startPhase()), startPhase); 0086 } 0087 0088 void KAutostartTest::testStartName() 0089 { 0090 if (!KAutostart::isServiceRegistered(QStringLiteral("plasma-desktop"))) { 0091 QSKIP("plasma-desktop.desktop not found, kdebase not installed"); 0092 } 0093 KAutostart autostart(QStringLiteral("plasma-desktop")); 0094 QCOMPARE(autostart.visibleName(), QStringLiteral("Plasma Desktop Workspace")); 0095 } 0096 0097 void KAutostartTest::testServiceRegistered() 0098 { 0099 KAutostart autostart; 0100 QCOMPARE(KAutostart::isServiceRegistered(QStringLiteral("doesnotexist")), false); 0101 0102 if (QStandardPaths::locate(QStandardPaths::GenericConfigLocation, QStringLiteral("autostart/plasma-desktop.desktop")).isEmpty()) { 0103 QSKIP("plasma-desktop.desktop not found, kdebase not installed"); 0104 } 0105 QCOMPARE(KAutostart::isServiceRegistered(QStringLiteral("plasma-desktop")), true); 0106 } 0107 0108 void KAutostartTest::testRegisteringAndManipulatingANewService() 0109 { 0110 QFile::remove(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1String{"/autostart/doesnotexist.desktop"}); 0111 { 0112 // need to clean up the KAutostart object before QFile can remove it 0113 KAutostart autostart(QStringLiteral("doesnotexist")); 0114 QCOMPARE(autostart.autostarts(), false); 0115 autostart.setCommand(QStringLiteral("aseigo")); 0116 #ifdef Q_OS_WIN 0117 autostart.setCommandToCheck(QStringLiteral("cmd")); 0118 #else 0119 autostart.setCommandToCheck(QStringLiteral("/bin/ls")); 0120 #endif 0121 autostart.setVisibleName(QStringLiteral("doesnotexisttest")); 0122 autostart.setStartPhase(KAutostart::BaseDesktop); 0123 autostart.setAllowedEnvironments(QStringList(QStringLiteral("KDE"))); 0124 autostart.addToAllowedEnvironments(QStringLiteral("XFCE")); 0125 autostart.addToAllowedEnvironments(QStringLiteral("GNOME")); 0126 autostart.removeFromAllowedEnvironments(QStringLiteral("GNOME")); 0127 autostart.setExcludedEnvironments(QStringList(QStringLiteral("GNOME"))); 0128 autostart.addToExcludedEnvironments(QStringLiteral("XFCE")); 0129 autostart.addToExcludedEnvironments(QStringLiteral("KDE")); 0130 autostart.removeFromExcludedEnvironments(QStringLiteral("KDE")); 0131 } 0132 0133 QVERIFY(QFile::exists(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1String{"/autostart/doesnotexist.desktop"})); 0134 0135 { 0136 QStringList allowedEnvs; 0137 allowedEnvs << QStringLiteral("KDE") << QStringLiteral("XFCE"); 0138 0139 QStringList excludedEnvs; 0140 excludedEnvs << QStringLiteral("GNOME") << QStringLiteral("XFCE"); 0141 0142 KAutostart autostart(QStringLiteral("doesnotexist")); 0143 QCOMPARE(autostart.command(), QStringLiteral("aseigo")); 0144 QCOMPARE(autostart.autostarts(), true); 0145 QCOMPARE(autostart.autostarts(QStringLiteral("KDE")), true); 0146 QCOMPARE(autostart.autostarts(QStringLiteral("GNOME")), false); 0147 QCOMPARE(autostart.autostarts(QStringLiteral("XFCE")), true); 0148 QCOMPARE(autostart.autostarts(QStringLiteral("XFCE"), KAutostart::CheckCommand), true); 0149 QCOMPARE(autostart.visibleName(), QStringLiteral("doesnotexisttest")); 0150 #ifdef Q_OS_WIN 0151 QCOMPARE(autostart.commandToCheck(), QStringLiteral("cmd")); 0152 #else 0153 QCOMPARE(autostart.commandToCheck(), QStringLiteral("/bin/ls")); 0154 #endif 0155 QCOMPARE(int(autostart.startPhase()), int(KAutostart::BaseDesktop)); 0156 QCOMPARE(autostart.allowedEnvironments(), allowedEnvs); 0157 QCOMPARE(autostart.excludedEnvironments(), excludedEnvs); 0158 0159 autostart.setCommandToCheck(QStringLiteral("/bin/whozitwhat")); 0160 } 0161 0162 { 0163 KAutostart autostart(QStringLiteral("doesnotexist")); 0164 QCOMPARE(autostart.autostarts(QStringLiteral("KDE"), KAutostart::CheckCommand), false); 0165 } 0166 } 0167 0168 void KAutostartTest::testRemovalOfNewServiceFile() 0169 { 0170 QVERIFY(QFile::remove(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1String{"/autostart/doesnotexist.desktop"})); 0171 }