Commit 40ca0828 authored by Laurent Montel's avatar Laurent Montel 😁

Improve expirecollectionattribute autotests

parent 7d74d7b3
...@@ -18,10 +18,14 @@ ...@@ -18,10 +18,14 @@
#include "expirecollectionattributetest.h" #include "expirecollectionattributetest.h"
#include "../expirecollectionattribute.h" #include "../expirecollectionattribute.h"
#include <qtest_kde.h> #include <qtest_kde.h>
Q_DECLARE_METATYPE(MailCommon::ExpireCollectionAttribute::ExpireUnits)
Q_DECLARE_METATYPE(MailCommon::ExpireCollectionAttribute::ExpireAction)
ExpireCollectionAttributeTest::ExpireCollectionAttributeTest(QObject *parent) ExpireCollectionAttributeTest::ExpireCollectionAttributeTest(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
qRegisterMetaType<MailCommon::ExpireCollectionAttribute::ExpireUnits>();
qRegisterMetaType<MailCommon::ExpireCollectionAttribute::ExpireAction>();
} }
ExpireCollectionAttributeTest::~ExpireCollectionAttributeTest() ExpireCollectionAttributeTest::~ExpireCollectionAttributeTest()
...@@ -43,12 +47,128 @@ void ExpireCollectionAttributeTest::shouldHaveDefaultValue() ...@@ -43,12 +47,128 @@ void ExpireCollectionAttributeTest::shouldHaveDefaultValue()
void ExpireCollectionAttributeTest::shouldAssignValue_data() void ExpireCollectionAttributeTest::shouldAssignValue_data()
{ {
//TODO QTest::addColumn<bool>("autoexpire");
QTest::addColumn<int>("unreadexpireage");
QTest::addColumn<int>("readexpireage");
QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireUnits>("unreadexpireunit");
QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireUnits>("readexpireunit");
QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireAction>("expireaction");
QTest::addColumn<Akonadi::Collection::Id>("akonadiid");
QTest::newRow("add autoexpire") << true << 28 << 14 << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireDelete << qint64(5);
QTest::newRow("change action") << true << 28 << 14 << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
QTest::newRow("change age") << true << 150 << 1 << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
QTest::newRow("change units") << true << 15 << 1 << MailCommon::ExpireCollectionAttribute::ExpireDays << MailCommon::ExpireCollectionAttribute::ExpireDays << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
QTest::newRow("change units2") << true << 150 << 18 << MailCommon::ExpireCollectionAttribute::ExpireMonths << MailCommon::ExpireCollectionAttribute::ExpireWeeks << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(6);
} }
void ExpireCollectionAttributeTest::shouldAssignValue() void ExpireCollectionAttributeTest::shouldAssignValue()
{ {
QFETCH(bool, autoexpire);
QFETCH(int, unreadexpireage);
QFETCH(int, readexpireage);
QFETCH(MailCommon::ExpireCollectionAttribute::ExpireUnits, unreadexpireunit);
QFETCH(MailCommon::ExpireCollectionAttribute::ExpireUnits, readexpireunit);
QFETCH(MailCommon::ExpireCollectionAttribute::ExpireAction, expireaction);
QFETCH(Akonadi::Collection::Id, akonadiid);
MailCommon::ExpireCollectionAttribute attr;
attr.setAutoExpire(autoexpire);
attr.setUnreadExpireAge(unreadexpireage);
attr.setReadExpireAge(readexpireage);
attr.setUnreadExpireUnits(unreadexpireunit);
attr.setReadExpireUnits(readexpireunit);
attr.setExpireAction(expireaction);
attr.setExpireToFolderId(akonadiid);
QCOMPARE(attr.isAutoExpire(), autoexpire);
QCOMPARE(attr.unreadExpireAge(), unreadexpireage);
QCOMPARE(attr.readExpireAge(), readexpireage);
QCOMPARE(attr.expireAction(), expireaction);
QCOMPARE(attr.unreadExpireUnits(), unreadexpireunit);
QCOMPARE(attr.readExpireUnits(), readexpireunit);
QCOMPARE(attr.expireToFolderId(), akonadiid);
}
void ExpireCollectionAttributeTest::shouldCloneAttr_data()
{
QTest::addColumn<bool>("autoexpire");
QTest::addColumn<int>("unreadexpireage");
QTest::addColumn<int>("readexpireage");
QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireUnits>("unreadexpireunit");
QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireUnits>("readexpireunit");
QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireAction>("expireaction");
QTest::addColumn<Akonadi::Collection::Id>("akonadiid");
QTest::newRow("add autoexpire") << true << 28 << 14 << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireDelete << qint64(5);
QTest::newRow("change action") << true << 28 << 14 << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
QTest::newRow("change age") << true << 150 << 1 << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
QTest::newRow("change units") << true << 15 << 1 << MailCommon::ExpireCollectionAttribute::ExpireDays << MailCommon::ExpireCollectionAttribute::ExpireDays << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
QTest::newRow("change units2") << true << 150 << 18 << MailCommon::ExpireCollectionAttribute::ExpireMonths << MailCommon::ExpireCollectionAttribute::ExpireWeeks << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(6);
}
void ExpireCollectionAttributeTest::shouldCloneAttr()
{
QFETCH(bool, autoexpire);
QFETCH(int, unreadexpireage);
QFETCH(int, readexpireage);
QFETCH(MailCommon::ExpireCollectionAttribute::ExpireUnits, unreadexpireunit);
QFETCH(MailCommon::ExpireCollectionAttribute::ExpireUnits, readexpireunit);
QFETCH(MailCommon::ExpireCollectionAttribute::ExpireAction, expireaction);
QFETCH(Akonadi::Collection::Id, akonadiid);
MailCommon::ExpireCollectionAttribute attr;
attr.setAutoExpire(autoexpire);
attr.setUnreadExpireAge(unreadexpireage);
attr.setReadExpireAge(readexpireage);
attr.setUnreadExpireUnits(unreadexpireunit);
attr.setReadExpireUnits(readexpireunit);
attr.setExpireAction(expireaction);
attr.setExpireToFolderId(akonadiid);
MailCommon::ExpireCollectionAttribute *result = attr.clone();
QVERIFY(attr == *result);
delete result;
}
void ExpireCollectionAttributeTest::shouldSerializedValue_data()
{
QTest::addColumn<bool>("autoexpire");
QTest::addColumn<int>("unreadexpireage");
QTest::addColumn<int>("readexpireage");
QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireUnits>("unreadexpireunit");
QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireUnits>("readexpireunit");
QTest::addColumn<MailCommon::ExpireCollectionAttribute::ExpireAction>("expireaction");
QTest::addColumn<Akonadi::Collection::Id>("akonadiid");
QTest::newRow("add autoexpire") << true << 28 << 14 << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireDelete << qint64(5);
QTest::newRow("change action") << true << 28 << 14 << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
QTest::newRow("change age") << true << 150 << 1 << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireNever << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
QTest::newRow("change units") << true << 15 << 1 << MailCommon::ExpireCollectionAttribute::ExpireDays << MailCommon::ExpireCollectionAttribute::ExpireDays << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(5);
QTest::newRow("change units2") << true << 150 << 18 << MailCommon::ExpireCollectionAttribute::ExpireMonths << MailCommon::ExpireCollectionAttribute::ExpireWeeks << MailCommon::ExpireCollectionAttribute::ExpireMove << qint64(6);
}
void ExpireCollectionAttributeTest::shouldSerializedValue()
{
QFETCH(bool, autoexpire);
QFETCH(int, unreadexpireage);
QFETCH(int, readexpireage);
QFETCH(MailCommon::ExpireCollectionAttribute::ExpireUnits, unreadexpireunit);
QFETCH(MailCommon::ExpireCollectionAttribute::ExpireUnits, readexpireunit);
QFETCH(MailCommon::ExpireCollectionAttribute::ExpireAction, expireaction);
QFETCH(Akonadi::Collection::Id, akonadiid);
MailCommon::ExpireCollectionAttribute attr; MailCommon::ExpireCollectionAttribute attr;
attr.setAutoExpire(autoexpire);
attr.setUnreadExpireAge(unreadexpireage);
attr.setReadExpireAge(readexpireage);
attr.setUnreadExpireUnits(unreadexpireunit);
attr.setReadExpireUnits(readexpireunit);
attr.setExpireAction(expireaction);
attr.setExpireToFolderId(akonadiid);
const QByteArray ba = attr.serialized();
MailCommon::ExpireCollectionAttribute result;
result.deserialize(ba);
QVERIFY(attr == result);
} }
QTEST_KDEMAIN(ExpireCollectionAttributeTest, NoGUI) QTEST_KDEMAIN(ExpireCollectionAttributeTest, NoGUI)
...@@ -30,6 +30,10 @@ private Q_SLOTS: ...@@ -30,6 +30,10 @@ private Q_SLOTS:
void shouldHaveDefaultValue(); void shouldHaveDefaultValue();
void shouldAssignValue_data(); void shouldAssignValue_data();
void shouldAssignValue(); void shouldAssignValue();
void shouldCloneAttr_data();
void shouldCloneAttr();
void shouldSerializedValue_data();
void shouldSerializedValue();
}; };
#endif // EXPIRECOLLECTIONATTRIBUTETEST_H #endif // EXPIRECOLLECTIONATTRIBUTETEST_H
...@@ -41,7 +41,7 @@ QByteArray ExpireCollectionAttribute::type() const ...@@ -41,7 +41,7 @@ QByteArray ExpireCollectionAttribute::type() const
return sType; return sType;
} }
Akonadi::Attribute *ExpireCollectionAttribute::clone() const ExpireCollectionAttribute *ExpireCollectionAttribute::clone() const
{ {
ExpireCollectionAttribute *expireAttr = new ExpireCollectionAttribute(); ExpireCollectionAttribute *expireAttr = new ExpireCollectionAttribute();
expireAttr->setAutoExpire(mExpireMessages); expireAttr->setAutoExpire(mExpireMessages);
......
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
}; };
QByteArray type() const; QByteArray type() const;
Attribute *clone() const; ExpireCollectionAttribute *clone() const;
QByteArray serialized() const; QByteArray serialized() const;
void deserialize( const QByteArray &data ); void deserialize( const QByteArray &data );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment