File indexing completed on 2024-05-12 05:10:04
0001 /*************************************************************************** 0002 Copyright (C) 2021 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #include "newstufftest.h" 0026 #include "../newstuff/manager.h" 0027 #include "../utils/tellico_utils.h" 0028 0029 #include <QTest> 0030 #include <QStandardPaths> 0031 #include <QDBusConnection> 0032 #include <QDBusReply> 0033 #include <QDBusInterface> 0034 0035 QTEST_MAIN( NewStuffTest ) 0036 0037 void NewStuffTest::initTestCase() { 0038 QStandardPaths::setTestModeEnabled(true); 0039 // start with a clean test directory 0040 QDir dir(Tellico::saveLocation(QStringLiteral("entry-templates/"))); 0041 QVERIFY(dir.removeRecursively()); 0042 dir.setPath(Tellico::saveLocation(QStringLiteral("data-sources/"))); 0043 QVERIFY(dir.removeRecursively()); 0044 Tellico::NewStuff::Manager::self(); 0045 } 0046 0047 void NewStuffTest::testConnection() { 0048 auto conn = QDBusConnection::sessionBus(); 0049 QVERIFY(conn.isConnected()); 0050 auto obj = conn.objectRegisteredAt(QStringLiteral("/NewStuff")); 0051 QVERIFY(obj); 0052 0053 auto msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.tellico"), // Service 0054 QStringLiteral("/NewStuff"), // Path 0055 QStringLiteral("org.kde.tellico.newstuff"), // Interface 0056 QStringLiteral("installTemplate") // Method 0057 ); 0058 msg.setArguments(QVariantList() << QString()); // one arg, file to install 0059 QDBusReply<bool> reply = conn.call(msg); 0060 QVERIFY(reply.isValid()); 0061 QCOMPARE(reply.value(), false); // false because of empty installation file 0062 } 0063 0064 void NewStuffTest::testNewStuff() { 0065 auto list = Tellico::NewStuff::Manager::self()->userTemplates(); 0066 QVERIFY(list.isEmpty()); 0067 } 0068 0069 void NewStuffTest::testInstallTemplate() { 0070 auto startList = Tellico::NewStuff::Manager::self()->userTemplates(); 0071 0072 const QString templateFile = QFINDTESTDATA("../../xslt/entry-templates/Compact.xsl"); 0073 QVERIFY(Tellico::NewStuff::Manager::self()->installTemplate(templateFile)); 0074 auto listAfterInstall = Tellico::NewStuff::Manager::self()->userTemplates(); 0075 QCOMPARE(startList.count(), listAfterInstall.count()-1); // one more file got installed 0076 QVERIFY(listAfterInstall.contains(QStringLiteral("Compact"))); 0077 0078 QVERIFY(Tellico::NewStuff::Manager::self()->removeTemplate(templateFile)); 0079 auto listAfterDelete = Tellico::NewStuff::Manager::self()->userTemplates(); 0080 QCOMPARE(startList.count(), listAfterDelete.count()); // one more file got installed 0081 QVERIFY(!listAfterDelete.contains(QStringLiteral("Compact"))); 0082 0083 QVERIFY(Tellico::NewStuff::Manager::self()->installTemplate(templateFile)); 0084 listAfterInstall = Tellico::NewStuff::Manager::self()->userTemplates(); 0085 QVERIFY(Tellico::NewStuff::Manager::self()->removeTemplateByName(QStringLiteral("Compact"))); 0086 0087 QDBusInterface iface(QStringLiteral("org.kde.tellico"), QStringLiteral("/NewStuff"), QStringLiteral("org.kde.tellico.newstuff")); 0088 QDBusReply<bool> reply = iface.call(QStringLiteral("installTemplate"), templateFile); 0089 QVERIFY(reply.isValid()); 0090 QCOMPARE(reply.value(), true); 0091 listAfterInstall = Tellico::NewStuff::Manager::self()->userTemplates(); 0092 QVERIFY(listAfterInstall.contains(QStringLiteral("Compact"))); 0093 0094 reply = iface.call(QStringLiteral("removeTemplate"), templateFile); 0095 QVERIFY(reply.isValid()); 0096 QCOMPARE(reply.value(), true); 0097 listAfterDelete = Tellico::NewStuff::Manager::self()->userTemplates(); 0098 QVERIFY(!listAfterDelete.contains(QStringLiteral("Compact"))); 0099 } 0100 0101 void NewStuffTest::testInstallScript() { 0102 QDir dir(Tellico::saveLocation(QStringLiteral("data-sources/dark_horse_comics/"))); 0103 QVERIFY(!dir.exists(QStringLiteral("dark_horse_comics.py"))); 0104 0105 const QString scriptFile = QFINDTESTDATA("../fetch/scripts/dark_horse_comics.py"); 0106 QVERIFY(Tellico::NewStuff::Manager::self()->installScript(scriptFile)); 0107 QVERIFY(dir.exists(QStringLiteral("dark_horse_comics.py"))); 0108 0109 QVERIFY(Tellico::NewStuff::Manager::self()->removeScriptByName(QStringLiteral("dark_horse_comics"))); 0110 QVERIFY(!dir.exists()); // complete directory should not exist 0111 0112 QDBusInterface iface(QStringLiteral("org.kde.tellico"), QStringLiteral("/NewStuff"), QStringLiteral("org.kde.tellico.newstuff")); 0113 QDBusReply<bool> reply = iface.call(QStringLiteral("installScript"), scriptFile); 0114 QVERIFY(reply.isValid()); 0115 QCOMPARE(reply.value(), true); 0116 QVERIFY(dir.exists(QStringLiteral("dark_horse_comics.py"))); 0117 0118 reply = iface.call(QStringLiteral("removeScript"), scriptFile); 0119 QVERIFY(reply.isValid()); 0120 QCOMPARE(reply.value(), true); 0121 QVERIFY(!dir.exists()); // complete directory should not exist 0122 }