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

0001 /*
0002     SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "notificationmessagetest.h"
0008 #include "private/protocol_p.h"
0009 
0010 #include <QSet>
0011 #include <QTest>
0012 
0013 QTEST_APPLESS_MAIN(NotificationMessageTest)
0014 
0015 using namespace Akonadi;
0016 using namespace Akonadi::Protocol;
0017 
0018 void NotificationMessageTest::testCompress()
0019 {
0020     ChangeNotificationList list;
0021     FetchCollectionsResponse collection(1);
0022     CollectionChangeNotification msg;
0023     msg.setCollection(std::move(collection));
0024     msg.setOperation(CollectionChangeNotification::Add);
0025 
0026     QVERIFY(CollectionChangeNotification::appendAndCompress(list, CollectionChangeNotificationPtr::create(msg)));
0027     QCOMPARE(list.count(), 1);
0028 
0029     msg.setOperation(CollectionChangeNotification::Modify);
0030     QVERIFY(!CollectionChangeNotification::appendAndCompress(list, CollectionChangeNotificationPtr::create(msg)));
0031     QCOMPARE(list.count(), 1);
0032     QCOMPARE(list.first().staticCast<CollectionChangeNotification>()->operation(), CollectionChangeNotification::Add);
0033 
0034     msg.setOperation(CollectionChangeNotification::Remove);
0035     QVERIFY(CollectionChangeNotification::appendAndCompress(list, CollectionChangeNotificationPtr::create(msg)));
0036     QCOMPARE(list.count(), 2);
0037 }
0038 
0039 void NotificationMessageTest::testCompress2()
0040 {
0041     ChangeNotificationList list;
0042     FetchCollectionsResponse collection(1);
0043     CollectionChangeNotification msg;
0044     msg.setCollection(std::move(collection));
0045     msg.setOperation(CollectionChangeNotification::Modify);
0046 
0047     QVERIFY(CollectionChangeNotification::appendAndCompress(list, CollectionChangeNotificationPtr::create(msg)));
0048     QCOMPARE(list.count(), 1);
0049 
0050     msg.setOperation(CollectionChangeNotification::Remove);
0051     QVERIFY(CollectionChangeNotification::appendAndCompress(list, CollectionChangeNotificationPtr::create(msg)));
0052     QCOMPARE(list.count(), 2);
0053     QCOMPARE(list.first().staticCast<CollectionChangeNotification>()->operation(), CollectionChangeNotification::Modify);
0054     QCOMPARE(list.last().staticCast<CollectionChangeNotification>()->operation(), CollectionChangeNotification::Remove);
0055 }
0056 
0057 void NotificationMessageTest::testCompress3()
0058 {
0059     ChangeNotificationList list;
0060     FetchCollectionsResponse collection(1);
0061     CollectionChangeNotification msg;
0062     msg.setCollection(std::move(collection));
0063     msg.setOperation(CollectionChangeNotification::Modify);
0064 
0065     QVERIFY(CollectionChangeNotification::appendAndCompress(list, CollectionChangeNotificationPtr::create(msg)));
0066     QCOMPARE(list.count(), 1);
0067 
0068     QVERIFY(!CollectionChangeNotification::appendAndCompress(list, CollectionChangeNotificationPtr::create(msg)));
0069     QCOMPARE(list.count(), 1);
0070 }
0071 
0072 void NotificationMessageTest::testPartModificationMerge()
0073 {
0074     ChangeNotificationList list;
0075     FetchCollectionsResponse collection(1);
0076     CollectionChangeNotification msg;
0077     msg.setCollection(std::move(collection));
0078     msg.setOperation(CollectionChangeNotification::Modify);
0079     msg.setChangedParts(QSet<QByteArray>() << "PART1");
0080 
0081     QVERIFY(CollectionChangeNotification::appendAndCompress(list, CollectionChangeNotificationPtr::create(msg)));
0082     QCOMPARE(list.count(), 1);
0083 
0084     msg.setChangedParts(QSet<QByteArray>() << "PART2");
0085     QVERIFY(!CollectionChangeNotification::appendAndCompress(list, CollectionChangeNotificationPtr::create(msg)));
0086     QCOMPARE(list.count(), 1);
0087     QCOMPARE(list.first().staticCast<CollectionChangeNotification>()->changedParts(),
0088              (QSet<QByteArray>() << "PART1"
0089                                  << "PART2"));
0090 }
0091 
0092 #include "moc_notificationmessagetest.cpp"