Add autotest

wilder
Montel Laurent 9 years ago
parent 4e17be8b8a
commit 70175cff1d
  1. 5
      src/filter/autotests/CMakeLists.txt
  2. 61
      src/filter/autotests/filterimporterpathcachetest.cpp
  3. 9
      src/filter/autotests/filterimporterpathcachetest.h
  4. 9
      src/filter/filterimporterpathcache.cpp
  5. 1
      src/filter/filterimporterpathcache.h

@ -269,3 +269,8 @@ add_mailcommon_filter_test(filteractionmissingidentitydialogtest
../dialog/filteractionmissingidentitydialog.cpp
../../../autotests/dummykernel.cpp
)
add_mailcommon_filter_test(filterimporterpathcachetest
filterimporterpathcachetest.cpp
../filterimporterpathcache.cpp
)

@ -16,6 +16,7 @@
*/
#include "filterimporterpathcachetest.h"
#include "../filterimporterpathcache.h"
#include <QTest>
QTEST_MAIN(FilterImporterPathCacheTest)
@ -30,3 +31,63 @@ FilterImporterPathCacheTest::~FilterImporterPathCacheTest()
{
}
void FilterImporterPathCacheTest::shouldReturnEmptyStringWhenListIsEmpty()
{
MailCommon::FilterImporterPathCache cache;
QCOMPARE(cache.count(), 0);
QVERIFY(cache.convertedFilterPath(QStringLiteral("dd")).isEmpty());
QCOMPARE(cache.count(), 0);
}
void FilterImporterPathCacheTest::shouldNotStoreEmptyValue()
{
MailCommon::FilterImporterPathCache cache;
cache.insert(QString(), QStringLiteral("foo"));
QCOMPARE(cache.count(), 0);
cache.insert(QStringLiteral("foo"), QString());
QCOMPARE(cache.count(), 0);
cache.insert(QStringLiteral("foo1"), QStringLiteral("foo"));
QCOMPARE(cache.count(), 1);
}
void FilterImporterPathCacheTest::shouldNotDuplicateEntries()
{
MailCommon::FilterImporterPathCache cache;
cache.insert(QStringLiteral("foo1"), QStringLiteral("foo"));
QCOMPARE(cache.count(), 1);
cache.insert(QStringLiteral("foo1"), QStringLiteral("foo"));
QCOMPARE(cache.count(), 1);
cache.insert(QStringLiteral("foo1"), QStringLiteral("foo"));
QCOMPARE(cache.count(), 1);
cache.insert(QStringLiteral("foo1"), QStringLiteral("foo2"));
QCOMPARE(cache.count(), 1);
cache.insert(QStringLiteral("foo1"), QStringLiteral("foo3"));
QCOMPARE(cache.count(), 1);
//Add new one
cache.insert(QStringLiteral("foo2"), QStringLiteral("foo3"));
QCOMPARE(cache.count(), 2);
}
void FilterImporterPathCacheTest::shouldReturnValues()
{
MailCommon::FilterImporterPathCache cache;
QString key = QStringLiteral("foo1");
QString cached = QStringLiteral("foo");
cache.insert(key, cached);
QCOMPARE(cache.convertedFilterPath(key), cached);
//Use value in same key
cached = QStringLiteral("foo5");
cache.insert(key, cached);
QCOMPARE(cache.convertedFilterPath(key), cached);
}

@ -26,10 +26,11 @@ class FilterImporterPathCacheTest : public QObject
public:
explicit FilterImporterPathCacheTest(QObject *parent = nullptr);
~FilterImporterPathCacheTest();
signals:
public slots:
private Q_SLOTS:
void shouldReturnEmptyStringWhenListIsEmpty();
void shouldNotStoreEmptyValue();
void shouldNotDuplicateEntries();
void shouldReturnValues();
};
#endif // FILTERIMPORTERPATHCACHETEST_H

@ -35,8 +35,17 @@ FilterImporterPathCache *FilterImporterPathCache::self()
return &s_self;
}
int FilterImporterPathCache::count() const
{
return mFilterCache.count();
}
void FilterImporterPathCache::insert(const QString &original, const QString &newValue)
{
if (original.isEmpty() || newValue.isEmpty()) {
return;
}
mFilterCache.insert(original, newValue);
}

@ -34,6 +34,7 @@ public:
void insert(const QString &original, const QString &newValue);
QString convertedFilterPath(const QString &original);
void clear();
int count() const;
private:
QHash<QString, QString> mFilterCache;
};

Loading…
Cancel
Save