File indexing completed on 2024-11-10 04:40:15
0001 /* 0002 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <QObject> 0008 #include <QStringList> 0009 0010 #include "agentinstancecreatejob.h" 0011 #include "agentmanager.h" 0012 #include "qtest_akonadi.h" 0013 0014 using namespace Akonadi; 0015 0016 class ResourceTest : public QObject 0017 { 0018 Q_OBJECT 0019 private Q_SLOTS: 0020 void initTestCase() 0021 { 0022 AkonadiTest::checkTestIsIsolated(); 0023 } 0024 void testResourceManagement() 0025 { 0026 qRegisterMetaType<Akonadi::AgentInstance>(); 0027 QSignalSpy spyAddInstance(AgentManager::self(), &AgentManager::instanceAdded); 0028 QVERIFY(spyAddInstance.isValid()); 0029 QSignalSpy spyRemoveInstance(AgentManager::self(), &AgentManager::instanceRemoved); 0030 QVERIFY(spyRemoveInstance.isValid()); 0031 0032 AgentType type = AgentManager::self()->type(QStringLiteral("akonadi_knut_resource")); 0033 QVERIFY(type.isValid()); 0034 0035 QStringList lst; 0036 lst << QStringLiteral("Resource"); 0037 QCOMPARE(type.capabilities(), lst); 0038 0039 auto job = new AgentInstanceCreateJob(type); 0040 AKVERIFYEXEC(job); 0041 0042 AgentInstance instance = job->instance(); 0043 QVERIFY(instance.isValid()); 0044 0045 QCOMPARE(spyAddInstance.count(), 1); 0046 QCOMPARE(spyAddInstance.first().at(0).value<AgentInstance>(), instance); 0047 QVERIFY(AgentManager::self()->instance(instance.identifier()).isValid()); 0048 0049 job = new AgentInstanceCreateJob(type); 0050 AKVERIFYEXEC(job); 0051 AgentInstance instance2 = job->instance(); 0052 QVERIFY(!(instance == instance2)); 0053 QCOMPARE(spyAddInstance.count(), 2); 0054 0055 AgentManager::self()->removeInstance(instance); 0056 AgentManager::self()->removeInstance(instance2); 0057 QTRY_COMPARE(spyRemoveInstance.count(), 2); 0058 QVERIFY(!AgentManager::self()->instances().contains(instance)); 0059 QVERIFY(!AgentManager::self()->instances().contains(instance2)); 0060 } 0061 0062 void testIllegalResourceManagement() 0063 { 0064 auto job = new AgentInstanceCreateJob(AgentManager::self()->type(QStringLiteral("non_existing_resource"))); 0065 QVERIFY(!job->exec()); 0066 0067 // unique agent 0068 // According to vkrause the mailthreader agent is no longer started by 0069 // default so this won't work. 0070 /* 0071 const AgentType type = AgentManager::self()->type( "akonadi_mailthreader_agent" ); 0072 QVERIFY( type.isValid() ); 0073 job = new AgentInstanceCreateJob( type ); 0074 AKVERIFYEXEC( job ); 0075 0076 job = new AgentInstanceCreateJob( type ); 0077 QVERIFY( !job->exec() ); 0078 */ 0079 } 0080 }; 0081 0082 QTEST_AKONADIMAIN(ResourceTest) 0083 0084 #include "resourcetest.moc"