File indexing completed on 2024-11-10 04:40:07

0001 /*
0002  * SPDX-FileCopyrightText: 2016 Elvis Angelaccio <elvis.angelaccio@kdemail.net>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  *
0006  */
0007 
0008 #include "akonadicontrol/agenttype.h"
0009 #include "shared/aktest.h"
0010 
0011 #include <QTest>
0012 
0013 Q_DECLARE_METATYPE(AgentType)
0014 
0015 class AgentTypeTest : public QObject
0016 {
0017     Q_OBJECT
0018 
0019 private Q_SLOTS:
0020 
0021     void testLoad_data();
0022     void testLoad();
0023 };
0024 
0025 void AgentTypeTest::testLoad_data()
0026 {
0027     AgentType googleContactsResource;
0028     googleContactsResource.exec = QStringLiteral("akonadi_googlecontacts_resource");
0029     googleContactsResource.mimeTypes = QStringList{QStringLiteral("text/directory"), QString()};
0030     googleContactsResource.capabilities = QStringList{AgentType::CapabilityResource};
0031     googleContactsResource.instanceCounter = 0;
0032     googleContactsResource.identifier = QStringLiteral("akonadi_googlecontacts_resource");
0033     googleContactsResource.custom =
0034         QVariantMap{{QStringLiteral("KAccounts"), QStringList{QStringLiteral("google-contacts"), QStringLiteral("google-calendar")}},
0035                     {QStringLiteral("HasLocalStorage"), true}};
0036     googleContactsResource.launchMethod = AgentType::Process;
0037     // We test an UTF-8 name within quotes.
0038     googleContactsResource.name = QStringLiteral("\"Контакти Google\"");
0039     // We also check whether an unquoted string with a comma is not parsed as a QStringList. See bug #330010
0040     googleContactsResource.comment = QStringLiteral("Доступ до ваших записів контактів, Google з KDE");
0041     googleContactsResource.icon = QStringLiteral("im-google");
0042 
0043     QTest::addColumn<QString>("fileName");
0044     QTest::addColumn<AgentType>("expectedAgentType");
0045 
0046     QTest::newRow("google contacts resource") << QFINDTESTDATA("data/akonaditestresource.desktop") << googleContactsResource;
0047 }
0048 
0049 void AgentTypeTest::testLoad()
0050 {
0051     QFETCH(QString, fileName);
0052     QFETCH(AgentType, expectedAgentType);
0053 
0054     AgentType agentType;
0055     QLocale::setDefault(QLocale::Ukrainian);
0056     QVERIFY(agentType.load(fileName, nullptr));
0057 
0058     QCOMPARE(agentType.exec, expectedAgentType.exec);
0059     QCOMPARE(agentType.mimeTypes, expectedAgentType.mimeTypes);
0060     QCOMPARE(agentType.capabilities, expectedAgentType.capabilities);
0061     QCOMPARE(agentType.instanceCounter, expectedAgentType.instanceCounter);
0062     QCOMPARE(agentType.identifier, expectedAgentType.identifier);
0063     QCOMPARE(agentType.custom, expectedAgentType.custom);
0064     QCOMPARE(agentType.launchMethod, expectedAgentType.launchMethod);
0065     QCOMPARE(agentType.name, expectedAgentType.name);
0066     QCOMPARE(agentType.comment, expectedAgentType.comment);
0067     QCOMPARE(agentType.icon, expectedAgentType.icon);
0068 }
0069 
0070 AKTEST_MAIN(AgentTypeTest)
0071 
0072 #include "agenttypetest.moc"