File indexing completed on 2024-12-22 05:00:49

0001 /*
0002    SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "archivemailinfotest.h"
0008 #include "../archivemailinfo.h"
0009 #include <Akonadi/Collection>
0010 #include <KConfigGroup>
0011 #include <KSharedConfig>
0012 #include <QStandardPaths>
0013 #include <QTest>
0014 
0015 ArchiveMailInfoTest::ArchiveMailInfoTest(QObject *parent)
0016     : QObject(parent)
0017 {
0018     QStandardPaths::setTestModeEnabled(true);
0019 }
0020 
0021 ArchiveMailInfoTest::~ArchiveMailInfoTest() = default;
0022 
0023 void ArchiveMailInfoTest::shouldHaveDefaultValue()
0024 {
0025     ArchiveMailInfo info;
0026     QCOMPARE(info.saveCollectionId(), Akonadi::Collection::Id(-1));
0027     QCOMPARE(info.saveSubCollection(), false);
0028     QCOMPARE(info.url(), QUrl());
0029     QCOMPARE(info.archiveType(), MailCommon::BackupJob::Zip);
0030     QCOMPARE(info.archiveUnit(), ArchiveMailInfo::ArchiveDays);
0031     QCOMPARE(info.archiveAge(), 1);
0032     QCOMPARE(info.lastDateSaved(), QDate());
0033     QCOMPARE(info.maximumArchiveCount(), 0);
0034     QCOMPARE(info.isEnabled(), true);
0035     QCOMPARE(info.useRange(), false);
0036     QVERIFY(info.range().isEmpty());
0037 }
0038 
0039 void ArchiveMailInfoTest::shouldRestoreFromSettings()
0040 {
0041     ArchiveMailInfo info;
0042     info.setSaveCollectionId(Akonadi::Collection::Id(42));
0043     info.setUrl(QUrl::fromLocalFile(QStringLiteral("/foo/foo")));
0044     info.setArchiveType(MailCommon::BackupJob::TarBz2);
0045     info.setArchiveUnit(ArchiveMailInfo::ArchiveMonths);
0046     info.setArchiveAge(5);
0047     info.setLastDateSaved(QDate::currentDate());
0048     info.setMaximumArchiveCount(5);
0049     info.setEnabled(false);
0050     info.setUseRange(true);
0051     info.setRange({8, 7});
0052 
0053     KConfigGroup grp(KSharedConfig::openConfig(), QStringLiteral("testsettings"));
0054     info.writeConfig(grp);
0055 
0056     const ArchiveMailInfo restoreInfo(grp);
0057     QCOMPARE(info, restoreInfo);
0058 }
0059 
0060 void ArchiveMailInfoTest::shouldCopyArchiveInfo()
0061 {
0062     ArchiveMailInfo info;
0063     info.setSaveCollectionId(Akonadi::Collection::Id(42));
0064     info.setUrl(QUrl::fromLocalFile(QStringLiteral("/foo/foo")));
0065     info.setArchiveType(MailCommon::BackupJob::TarBz2);
0066     info.setArchiveUnit(ArchiveMailInfo::ArchiveMonths);
0067     info.setArchiveAge(5);
0068     info.setLastDateSaved(QDate::currentDate());
0069     info.setMaximumArchiveCount(5);
0070     info.setEnabled(false);
0071     info.setUseRange(true);
0072     info.setRange({8, 7});
0073 
0074     const ArchiveMailInfo copyInfo(info);
0075     QCOMPARE(info, copyInfo);
0076 }
0077 
0078 QTEST_MAIN(ArchiveMailInfoTest)
0079 
0080 #include "moc_archivemailinfotest.cpp"