File indexing completed on 2024-11-24 04:43:56

0001 /*
0002    SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "folderarchiveaccountinfotest.h"
0008 #include "folderarchiveaccountinfo.h"
0009 #include <Akonadi/Collection>
0010 #include <KSharedConfig>
0011 #include <QStandardPaths>
0012 #include <QTest>
0013 QTEST_MAIN(FolderArchiveAccountInfoTest)
0014 
0015 FolderArchiveAccountInfoTest::FolderArchiveAccountInfoTest(QObject *parent)
0016     : QObject(parent)
0017 {
0018     QStandardPaths::setTestModeEnabled(true);
0019 }
0020 
0021 FolderArchiveAccountInfoTest::~FolderArchiveAccountInfoTest() = default;
0022 
0023 void FolderArchiveAccountInfoTest::shouldHaveDefaultValue()
0024 {
0025     FolderArchiveAccountInfo info;
0026     QVERIFY(info.instanceName().isEmpty());
0027     QCOMPARE(info.archiveTopLevel(), Akonadi::Collection(-1).id());
0028     QCOMPARE(info.folderArchiveType(), FolderArchiveAccountInfo::UniqueFolder);
0029     QVERIFY(!info.enabled());
0030     QVERIFY(!info.keepExistingStructure());
0031     QVERIFY(!info.isValid());
0032     QVERIFY(!info.useDateFromMessage());
0033 }
0034 
0035 void FolderArchiveAccountInfoTest::shouldBeValid()
0036 {
0037     FolderArchiveAccountInfo info;
0038     QVERIFY(!info.isValid());
0039     info.setArchiveTopLevel(Akonadi::Collection(42).id());
0040     QVERIFY(!info.isValid());
0041     info.setInstanceName(QStringLiteral("FOO"));
0042     QVERIFY(info.isValid());
0043 }
0044 
0045 void FolderArchiveAccountInfoTest::shouldRestoreFromSettings()
0046 {
0047     FolderArchiveAccountInfo info;
0048     info.setInstanceName(QStringLiteral("FOO1"));
0049     info.setArchiveTopLevel(Akonadi::Collection(42).id());
0050     info.setFolderArchiveType(FolderArchiveAccountInfo::FolderByMonths);
0051     info.setEnabled(true);
0052     info.setKeepExistingStructure(true);
0053 
0054     KConfigGroup grp(KSharedConfig::openConfig(), QStringLiteral("testsettings"));
0055     info.writeConfig(grp);
0056 
0057     FolderArchiveAccountInfo restoreInfo(grp);
0058     QCOMPARE(info, restoreInfo);
0059 }
0060 
0061 #include "moc_folderarchiveaccountinfotest.cpp"