File indexing completed on 2024-09-22 04:49:58

0001 /*
0002   SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #include "filterimporterpathcachetest.h"
0008 #include "../filterimporterpathcache.h"
0009 #include <Akonadi/Collection>
0010 #include <QTest>
0011 
0012 QTEST_MAIN(FilterImporterPathCacheTest)
0013 
0014 FilterImporterPathCacheTest::FilterImporterPathCacheTest(QObject *parent)
0015     : QObject(parent)
0016 {
0017 }
0018 
0019 FilterImporterPathCacheTest::~FilterImporterPathCacheTest() = default;
0020 
0021 void FilterImporterPathCacheTest::shouldReturnEmptyStringWhenListIsEmpty()
0022 {
0023     MailCommon::FilterImporterPathCache cache;
0024     QCOMPARE(cache.count(), 0);
0025     QVERIFY(!cache.convertedFilterPath(QStringLiteral("foo")).isValid());
0026     QCOMPARE(cache.count(), 0);
0027 }
0028 
0029 void FilterImporterPathCacheTest::shouldNotStoreEmptyValue()
0030 {
0031     MailCommon::FilterImporterPathCache cache;
0032     cache.insert(QString(), Akonadi::Collection(3));
0033     QCOMPARE(cache.count(), 0);
0034 
0035     cache.insert(QStringLiteral("foo"), Akonadi::Collection(-1));
0036     QCOMPARE(cache.count(), 0);
0037 
0038     cache.insert(QStringLiteral("foo1"), Akonadi::Collection(3));
0039     QCOMPARE(cache.count(), 1);
0040 }
0041 
0042 void FilterImporterPathCacheTest::shouldNotDuplicateEntries()
0043 {
0044     MailCommon::FilterImporterPathCache cache;
0045     cache.insert(QStringLiteral("foo1"), Akonadi::Collection(3));
0046     QCOMPARE(cache.count(), 1);
0047 
0048     cache.insert(QStringLiteral("foo1"), Akonadi::Collection(3));
0049     QCOMPARE(cache.count(), 1);
0050 
0051     cache.insert(QStringLiteral("foo1"), Akonadi::Collection(3));
0052     QCOMPARE(cache.count(), 1);
0053 
0054     cache.insert(QStringLiteral("foo1"), Akonadi::Collection(4));
0055     QCOMPARE(cache.count(), 1);
0056 
0057     cache.insert(QStringLiteral("foo1"), Akonadi::Collection(4));
0058     QCOMPARE(cache.count(), 1);
0059 
0060     // Add new one
0061     cache.insert(QStringLiteral("foo2"), Akonadi::Collection(4));
0062     QCOMPARE(cache.count(), 2);
0063 }
0064 
0065 void FilterImporterPathCacheTest::shouldReturnValues()
0066 {
0067     MailCommon::FilterImporterPathCache cache;
0068     QString key = QStringLiteral("foo1");
0069     Akonadi::Collection cached = Akonadi::Collection(3);
0070     cache.insert(key, cached);
0071     QCOMPARE(cache.convertedFilterPath(key), cached);
0072 
0073     // Use value in same key
0074     cached = Akonadi::Collection(5);
0075     cache.insert(key, cached);
0076     QCOMPARE(cache.convertedFilterPath(key), cached);
0077 }
0078 
0079 #include "moc_filterimporterpathcachetest.cpp"