File indexing completed on 2024-05-12 16:25:28

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "retentioninfotest.h"
0008 #include "retentioninfo.h"
0009 #include "ruqola_autotest_helper.h"
0010 #include <QJsonObject>
0011 
0012 QTEST_GUILESS_MAIN(RetentionInfoTest)
0013 RetentionInfoTest::RetentionInfoTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void RetentionInfoTest::shouldHaveDefaultValues()
0019 {
0020     RetentionInfo info;
0021     QVERIFY(!info.enabled());
0022     QVERIFY(!info.overrideGlobal());
0023     QVERIFY(!info.excludePinned());
0024     QVERIFY(!info.filesOnly());
0025     QCOMPARE(info.maxAge(), -1);
0026 }
0027 
0028 void RetentionInfoTest::shouldLoadRetention_data()
0029 {
0030     QTest::addColumn<QString>("name");
0031     QTest::addColumn<RetentionInfo>("retentionInfo");
0032     RetentionInfo info;
0033     info.setMaxAge(32);
0034     info.setEnabled(true);
0035     info.setExcludePinned(false);
0036     info.setFilesOnly(true);
0037     info.setOverrideGlobal(true);
0038     QTest::addRow("retention") << QStringLiteral("retention") << info;
0039 }
0040 
0041 void RetentionInfoTest::shouldLoadRetention()
0042 {
0043     QFETCH(QString, name);
0044     QFETCH(RetentionInfo, retentionInfo);
0045     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/retention/") + name + QLatin1String(".json");
0046     const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile);
0047 
0048     RetentionInfo r;
0049     r.parseRetentionInfo(obj);
0050     const bool equalOwner = (r == retentionInfo);
0051     if (!equalOwner) {
0052         qDebug() << "ACTUAL " << r;
0053         qDebug() << "EXPECTED " << retentionInfo;
0054     }
0055     QVERIFY(equalOwner);
0056 }
0057 
0058 #include "moc_retentioninfotest.cpp"