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 "collection.h"
0008 #include "collectionfetchjob.h"
0009 #include "collectionfetchscope.h"
0010 #include "control.h"
0011 #include "qtest_akonadi.h"
0012 #include "subscriptionjob_p.h"
0013 
0014 #include <QObject>
0015 
0016 using namespace Akonadi;
0017 
0018 class SubscriptionTest : public QObject
0019 {
0020     Q_OBJECT
0021 private Q_SLOTS:
0022     void initTestCase()
0023     {
0024         AkonadiTest::checkTestIsIsolated();
0025         Control::start();
0026     }
0027 
0028     void testSubscribe()
0029     {
0030         Collection::List l;
0031         l << Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res2/foo2")));
0032         QVERIFY(l.first().isValid());
0033         auto sjob = new SubscriptionJob(this);
0034         sjob->unsubscribe(l);
0035         AKVERIFYEXEC(sjob);
0036 
0037         const Collection res2Col = Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res2")));
0038         QVERIFY(res2Col.isValid());
0039         auto ljob = new CollectionFetchJob(res2Col, CollectionFetchJob::FirstLevel, this);
0040         AKVERIFYEXEC(ljob);
0041         QCOMPARE(ljob->collections().count(), 1);
0042 
0043         ljob = new CollectionFetchJob(res2Col, CollectionFetchJob::FirstLevel, this);
0044         ljob->fetchScope().setListFilter(CollectionFetchScope::NoFilter);
0045         AKVERIFYEXEC(ljob);
0046         QCOMPARE(ljob->collections().count(), 2);
0047 
0048         sjob = new SubscriptionJob(this);
0049         sjob->subscribe(l);
0050         AKVERIFYEXEC(sjob);
0051 
0052         ljob = new CollectionFetchJob(res2Col, CollectionFetchJob::FirstLevel, this);
0053         AKVERIFYEXEC(ljob);
0054         QCOMPARE(ljob->collections().count(), 2);
0055     }
0056 
0057     void testEmptySubscribe()
0058     {
0059         Collection::List l;
0060         auto sjob = new SubscriptionJob(this);
0061         AKVERIFYEXEC(sjob);
0062     }
0063 
0064     void testInvalidSubscribe()
0065     {
0066         Collection::List l;
0067         l << Collection(1);
0068         auto sjob = new SubscriptionJob(this);
0069         sjob->subscribe(l);
0070         l << Collection(INT_MAX);
0071         sjob->unsubscribe(l);
0072         QVERIFY(!sjob->exec());
0073     }
0074 };
0075 
0076 QTEST_AKONADIMAIN(SubscriptionTest)
0077 
0078 #include "subscriptiontest.moc"