File indexing completed on 2024-11-17 04:50:59

0001 /*
0002   SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #include "expirecollectionattributetest.h"
0008 #include "../attributes/expirecollectionattribute.h"
0009 #include <QTest>
0010 
0011 Q_DECLARE_METATYPE(MailCommon::ExpireCollectionAttribute::ExpireUnits)
0012 Q_DECLARE_METATYPE(MailCommon::ExpireCollectionAttribute::ExpireAction)
0013 ExpireCollectionAttributeTest::ExpireCollectionAttributeTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016     qRegisterMetaType<MailCommon::ExpireCollectionAttribute::ExpireUnits>();
0017     qRegisterMetaType<MailCommon::ExpireCollectionAttribute::ExpireAction>();
0018 }
0019 
0020 ExpireCollectionAttributeTest::~ExpireCollectionAttributeTest() = default;
0021 
0022 void ExpireCollectionAttributeTest::shouldHaveDefaultValue()
0023 {
0024     MailCommon::ExpireCollectionAttribute attr;
0025     QVERIFY(!attr.isAutoExpire());
0026     QCOMPARE(attr.unreadExpireAge(), 28);
0027     QCOMPARE(attr.readExpireAge(), 14);
0028     QCOMPARE(attr.expireAction(), MailCommon::ExpireCollectionAttribute::ExpireDelete);
0029     QCOMPARE(attr.unreadExpireUnits(), MailCommon::ExpireCollectionAttribute::ExpireNever);
0030     QCOMPARE(attr.readExpireUnits(), MailCommon::ExpireCollectionAttribute::ExpireNever);
0031     QCOMPARE(attr.expireToFolderId(), (qint64)-1);
0032 }
0033 
0034 void ExpireCollectionAttributeTest::shouldAssignValue_data()
0035 {
0036     QTest::addColumn<bool>("autoexpire");
0037     QTest::addColumn<int>("unreadexpireage");
0038     QTest::addColumn<int>("readexpireage");
0039     QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireUnits>("unreadexpireunit");
0040     QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireUnits>("readexpireunit");
0041     QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireAction>("expireaction");
0042     QTest::addColumn<Akonadi::Collection::Id>("akonadiid");
0043 
0044     QTest::newRow("add autoexpire") << true << 28 << 14 << MailCommon::ExpireCollectionAttribute::ExpireNever
0045                                     << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireDelete << qint64(5);
0046     QTest::newRow("change action") << true << 28 << 14 << MailCommon::ExpireCollectionAttribute::ExpireNever
0047                                    << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
0048     QTest::newRow("change age") << true << 150 << 1 << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireNever
0049                                 << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
0050     QTest::newRow("change units") << true << 15 << 1 << MailCommon::ExpireCollectionAttribute::ExpireDays << MailCommon::ExpireCollectionAttribute::ExpireDays
0051                                   << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
0052     QTest::newRow("change units2") << true << 150 << 18 << MailCommon::ExpireCollectionAttribute::ExpireMonths
0053                                    << MailCommon::ExpireCollectionAttribute::ExpireWeeks << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(6);
0054 }
0055 
0056 void ExpireCollectionAttributeTest::shouldAssignValue()
0057 {
0058     QFETCH(bool, autoexpire);
0059     QFETCH(int, unreadexpireage);
0060     QFETCH(int, readexpireage);
0061     QFETCH(MailCommon::ExpireCollectionAttribute::ExpireUnits, unreadexpireunit);
0062     QFETCH(MailCommon::ExpireCollectionAttribute::ExpireUnits, readexpireunit);
0063     QFETCH(MailCommon::ExpireCollectionAttribute::ExpireAction, expireaction);
0064     QFETCH(Akonadi::Collection::Id, akonadiid);
0065     MailCommon::ExpireCollectionAttribute attr;
0066     attr.setAutoExpire(autoexpire);
0067     attr.setUnreadExpireAge(unreadexpireage);
0068     attr.setReadExpireAge(readexpireage);
0069     attr.setUnreadExpireUnits(unreadexpireunit);
0070     attr.setReadExpireUnits(readexpireunit);
0071     attr.setExpireAction(expireaction);
0072     attr.setExpireToFolderId(akonadiid);
0073 
0074     QCOMPARE(attr.isAutoExpire(), autoexpire);
0075     QCOMPARE(attr.unreadExpireAge(), unreadexpireage);
0076     QCOMPARE(attr.readExpireAge(), readexpireage);
0077     QCOMPARE(attr.expireAction(), expireaction);
0078     QCOMPARE(attr.unreadExpireUnits(), unreadexpireunit);
0079     QCOMPARE(attr.readExpireUnits(), readexpireunit);
0080     QCOMPARE(attr.expireToFolderId(), akonadiid);
0081 }
0082 
0083 void ExpireCollectionAttributeTest::shouldCloneAttr_data()
0084 {
0085     QTest::addColumn<bool>("autoexpire");
0086     QTest::addColumn<int>("unreadexpireage");
0087     QTest::addColumn<int>("readexpireage");
0088     QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireUnits>("unreadexpireunit");
0089     QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireUnits>("readexpireunit");
0090     QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireAction>("expireaction");
0091     QTest::addColumn<Akonadi::Collection::Id>("akonadiid");
0092 
0093     QTest::newRow("add autoexpire") << true << 28 << 14 << MailCommon::ExpireCollectionAttribute::ExpireNever
0094                                     << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireDelete << qint64(5);
0095     QTest::newRow("change action") << true << 28 << 14 << MailCommon::ExpireCollectionAttribute::ExpireNever
0096                                    << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
0097     QTest::newRow("change age") << true << 150 << 1 << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireNever
0098                                 << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
0099     QTest::newRow("change units") << true << 15 << 1 << MailCommon::ExpireCollectionAttribute::ExpireDays << MailCommon::ExpireCollectionAttribute::ExpireDays
0100                                   << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
0101     QTest::newRow("change units2") << true << 150 << 18 << MailCommon::ExpireCollectionAttribute::ExpireMonths
0102                                    << MailCommon::ExpireCollectionAttribute::ExpireWeeks << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(6);
0103 }
0104 
0105 void ExpireCollectionAttributeTest::shouldCloneAttr()
0106 {
0107     QFETCH(bool, autoexpire);
0108     QFETCH(int, unreadexpireage);
0109     QFETCH(int, readexpireage);
0110     QFETCH(MailCommon::ExpireCollectionAttribute::ExpireUnits, unreadexpireunit);
0111     QFETCH(MailCommon::ExpireCollectionAttribute::ExpireUnits, readexpireunit);
0112     QFETCH(MailCommon::ExpireCollectionAttribute::ExpireAction, expireaction);
0113     QFETCH(Akonadi::Collection::Id, akonadiid);
0114     MailCommon::ExpireCollectionAttribute attr;
0115     attr.setAutoExpire(autoexpire);
0116     attr.setUnreadExpireAge(unreadexpireage);
0117     attr.setReadExpireAge(readexpireage);
0118     attr.setUnreadExpireUnits(unreadexpireunit);
0119     attr.setReadExpireUnits(readexpireunit);
0120     attr.setExpireAction(expireaction);
0121     attr.setExpireToFolderId(akonadiid);
0122     MailCommon::ExpireCollectionAttribute *result = attr.clone();
0123     QVERIFY(attr == *result);
0124     delete result;
0125 }
0126 
0127 void ExpireCollectionAttributeTest::shouldSerializedValue_data()
0128 {
0129     QTest::addColumn<bool>("autoexpire");
0130     QTest::addColumn<int>("unreadexpireage");
0131     QTest::addColumn<int>("readexpireage");
0132     QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireUnits>("unreadexpireunit");
0133     QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireUnits>("readexpireunit");
0134     QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireAction>("expireaction");
0135     QTest::addColumn<Akonadi::Collection::Id>("akonadiid");
0136 
0137     QTest::newRow("add autoexpire") << true << 28 << 14 << MailCommon::ExpireCollectionAttribute::ExpireNever
0138                                     << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireDelete << qint64(5);
0139     QTest::newRow("change action") << true << 28 << 14 << MailCommon::ExpireCollectionAttribute::ExpireNever
0140                                    << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
0141     QTest::newRow("change age") << true << 150 << 1 << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireNever
0142                                 << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
0143     QTest::newRow("change units") << true << 15 << 1 << MailCommon::ExpireCollectionAttribute::ExpireDays << MailCommon::ExpireCollectionAttribute::ExpireDays
0144                                   << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
0145     QTest::newRow("change units2") << true << 150 << 18 << MailCommon::ExpireCollectionAttribute::ExpireMonths
0146                                    << MailCommon::ExpireCollectionAttribute::ExpireWeeks << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(6);
0147 }
0148 
0149 void ExpireCollectionAttributeTest::shouldSerializedValue()
0150 {
0151     QFETCH(bool, autoexpire);
0152     QFETCH(int, unreadexpireage);
0153     QFETCH(int, readexpireage);
0154     QFETCH(MailCommon::ExpireCollectionAttribute::ExpireUnits, unreadexpireunit);
0155     QFETCH(MailCommon::ExpireCollectionAttribute::ExpireUnits, readexpireunit);
0156     QFETCH(MailCommon::ExpireCollectionAttribute::ExpireAction, expireaction);
0157     QFETCH(Akonadi::Collection::Id, akonadiid);
0158     MailCommon::ExpireCollectionAttribute attr;
0159     attr.setAutoExpire(autoexpire);
0160     attr.setUnreadExpireAge(unreadexpireage);
0161     attr.setReadExpireAge(readexpireage);
0162     attr.setUnreadExpireUnits(unreadexpireunit);
0163     attr.setReadExpireUnits(readexpireunit);
0164     attr.setExpireAction(expireaction);
0165     attr.setExpireToFolderId(akonadiid);
0166     const QByteArray ba = attr.serialized();
0167     MailCommon::ExpireCollectionAttribute result;
0168     result.deserialize(ba);
0169     QVERIFY(attr == result);
0170 }
0171 
0172 void ExpireCollectionAttributeTest::shouldHaveType()
0173 {
0174     MailCommon::ExpireCollectionAttribute attr;
0175     QCOMPARE(attr.type(), QByteArray("expirationcollectionattribute"));
0176 }
0177 
0178 QTEST_MAIN(ExpireCollectionAttributeTest)
0179 
0180 #include "moc_expirecollectionattributetest.cpp"