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

0001 /*
0002     SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "servermanager.h"
0008 #include "control.h"
0009 #include "qtest_akonadi.h"
0010 
0011 #include <QObject>
0012 
0013 using namespace Akonadi;
0014 
0015 class ServerManagerTest : public QObject
0016 {
0017     Q_OBJECT
0018 private Q_SLOTS:
0019     void initTestCase()
0020     {
0021         AkonadiTest::checkTestIsIsolated();
0022         QVERIFY(Control::start());
0023         trackAkonadiProcess(false);
0024     }
0025 
0026     void cleanupTestCase()
0027     {
0028         trackAkonadiProcess(true);
0029     }
0030 
0031     void testStartStop()
0032     {
0033         QSignalSpy startSpy(ServerManager::self(), SIGNAL(started()));
0034         QVERIFY(startSpy.isValid());
0035         QSignalSpy stopSpy(ServerManager::self(), SIGNAL(stopped()));
0036         QVERIFY(stopSpy.isValid());
0037 
0038         QVERIFY(ServerManager::isRunning());
0039         QVERIFY(Control::start());
0040 
0041         QVERIFY(startSpy.isEmpty());
0042         QVERIFY(stopSpy.isEmpty());
0043 
0044         {
0045             QSignalSpy spy(ServerManager::self(), SIGNAL(stopped()));
0046             QVERIFY(ServerManager::stop());
0047             QTRY_VERIFY(spy.count() >= 1);
0048         }
0049         QVERIFY(!ServerManager::isRunning());
0050         QVERIFY(startSpy.isEmpty());
0051         QCOMPARE(stopSpy.count(), 1);
0052 
0053         QVERIFY(!ServerManager::stop());
0054         {
0055             QSignalSpy spy(ServerManager::self(), SIGNAL(started()));
0056             QVERIFY(ServerManager::start());
0057             QTRY_VERIFY(spy.count() >= 1);
0058         }
0059         QVERIFY(ServerManager::isRunning());
0060         QCOMPARE(startSpy.count(), 1);
0061         QCOMPARE(stopSpy.count(), 1);
0062     }
0063 
0064     void testRestart()
0065     {
0066         QVERIFY(ServerManager::isRunning());
0067         QSignalSpy startSpy(ServerManager::self(), SIGNAL(started()));
0068         QVERIFY(startSpy.isValid());
0069 
0070         QVERIFY(Control::restart());
0071 
0072         QVERIFY(ServerManager::isRunning());
0073         QCOMPARE(startSpy.count(), 1);
0074     }
0075 };
0076 
0077 QTEST_AKONADIMAIN(ServerManagerTest)
0078 
0079 #include "servermanagertest.moc"