diff --git a/src/collectionpage/autotests/expirecollectionattributetest.cpp b/src/collectionpage/autotests/expirecollectionattributetest.cpp index 61a911b..dbbaaf0 100644 --- a/src/collectionpage/autotests/expirecollectionattributetest.cpp +++ b/src/collectionpage/autotests/expirecollectionattributetest.cpp @@ -1,191 +1,191 @@ /* Copyright (c) 2014-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "expirecollectionattributetest.h" -#include +#include #include "../attributes/expirecollectionattribute.h" Q_DECLARE_METATYPE(MailCommon::ExpireCollectionAttribute::ExpireUnits) Q_DECLARE_METATYPE(MailCommon::ExpireCollectionAttribute::ExpireAction) ExpireCollectionAttributeTest::ExpireCollectionAttributeTest(QObject *parent) : QObject(parent) { qRegisterMetaType(); qRegisterMetaType(); } ExpireCollectionAttributeTest::~ExpireCollectionAttributeTest() { } void ExpireCollectionAttributeTest::shouldHaveDefaultValue() { MailCommon::ExpireCollectionAttribute attr; QVERIFY(!attr.isAutoExpire()); QCOMPARE(attr.unreadExpireAge(), 28); QCOMPARE(attr.readExpireAge(), 14); QCOMPARE(attr.expireAction(), MailCommon::ExpireCollectionAttribute::ExpireDelete); QCOMPARE(attr.unreadExpireUnits(), MailCommon::ExpireCollectionAttribute::ExpireNever); QCOMPARE(attr.readExpireUnits(), MailCommon::ExpireCollectionAttribute::ExpireNever); QCOMPARE(attr.expireToFolderId(), (qint64) - 1); } void ExpireCollectionAttributeTest::shouldAssignValue_data() { QTest::addColumn("autoexpire"); QTest::addColumn("unreadexpireage"); QTest::addColumn("readexpireage"); QTest::addColumn("unreadexpireunit"); QTest::addColumn("readexpireunit"); QTest::addColumn("expireaction"); QTest::addColumn("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() { 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("autoexpire"); QTest::addColumn("unreadexpireage"); QTest::addColumn("readexpireage"); QTest::addColumn("unreadexpireunit"); QTest::addColumn("readexpireunit"); QTest::addColumn("expireaction"); QTest::addColumn("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("autoexpire"); QTest::addColumn("unreadexpireage"); QTest::addColumn("readexpireage"); QTest::addColumn("unreadexpireunit"); QTest::addColumn("readexpireunit"); QTest::addColumn("expireaction"); QTest::addColumn("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; 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); } void ExpireCollectionAttributeTest::shouldHaveType() { MailCommon::ExpireCollectionAttribute attr; QCOMPARE(attr.type(), QByteArray("expirationcollectionattribute")); } QTEST_MAIN(ExpireCollectionAttributeTest) diff --git a/src/filter/autotests/filteractionaddheadertest.cpp b/src/filter/autotests/filteractionaddheadertest.cpp index 5987d0b..19a661b 100644 --- a/src/filter/autotests/filteractionaddheadertest.cpp +++ b/src/filter/autotests/filteractionaddheadertest.cpp @@ -1,213 +1,213 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionaddheadertest.h" #include "../filteractions/filteractionaddheader.h" #include "filter/itemcontext.h" #include #include -#include +#include #include FilterActionAddHeaderTest::FilterActionAddHeaderTest(QObject *parent) : QObject(parent) { } FilterActionAddHeaderTest::~FilterActionAddHeaderTest() { } void FilterActionAddHeaderTest::shouldCreateWidget() { MailCommon::FilterActionAddHeader filter; QWidget *widget = filter.createParamWidget(nullptr); QVERIFY(widget); PimCommon::MinimumComboBox *comboBox = widget->findChild(QStringLiteral("combo")); QVERIFY(comboBox); QVERIFY(comboBox->isEditable()); QLabel *label = widget->findChild(QStringLiteral("label_value")); QVERIFY(label); KLineEdit *lineEdit = widget->findChild(QStringLiteral("ledit")); QVERIFY(lineEdit); QVERIFY(lineEdit->text().isEmpty()); } void FilterActionAddHeaderTest::shouldAddValue_data() { QTest::addColumn("argsinput"); QTest::addColumn("resultheader"); QTest::addColumn("resultvalue"); QTest::newRow("empty") << QString() << QString() << QString(); QString val = QStringLiteral("bla") + QLatin1Char('\t') + QStringLiteral("blo"); QTest::newRow("real value") << val << QStringLiteral("bla") << QStringLiteral("blo"); } void FilterActionAddHeaderTest::shouldClearWidget() { MailCommon::FilterActionAddHeader filter; QWidget *widget = filter.createParamWidget(nullptr); PimCommon::MinimumComboBox *comboBox = widget->findChild(QStringLiteral("combo")); KLineEdit *lineEdit = widget->findChild(QStringLiteral("ledit")); comboBox->lineEdit()->setText(QStringLiteral("test")); lineEdit->setText(QStringLiteral("blo")); filter.clearParamWidget(widget); QVERIFY(comboBox->lineEdit()->text().isEmpty()); QVERIFY(lineEdit->text().isEmpty()); } void FilterActionAddHeaderTest::shouldReturnSieveCode() { MailCommon::FilterActionAddHeader filter; QCOMPARE(filter.sieveRequires().join(QLatin1Char(',')), QStringLiteral("editheader")); } void FilterActionAddHeaderTest::shouldBeEmpty() { MailCommon::FilterActionAddHeader filter; QVERIFY(filter.isEmpty()); filter.argsFromString(QString()); QVERIFY(filter.isEmpty()); filter.argsFromString(QStringLiteral("foo\tbla")); QVERIFY(!filter.isEmpty()); } void FilterActionAddHeaderTest::shouldNotExecuteActionWhenParameterIsEmpty() { MailCommon::FilterActionAddHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QStringLiteral("")); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn); QCOMPARE(context.needsPayloadStore(), false); QCOMPARE(context.deleteItem(), false); QCOMPARE(context.needsFlagStore(), false); } void FilterActionAddHeaderTest::shouldNotExecuteActionWhenValueIsEmpty() { MailCommon::FilterActionAddHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QStringLiteral("foo")); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn); QCOMPARE(context.needsPayloadStore(), false); QCOMPARE(context.deleteItem(), false); QCOMPARE(context.needsFlagStore(), false); } void FilterActionAddHeaderTest::shouldAddNewHeaderWhenNotExistingHeader() { const QByteArray data = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "\n" "test"; const QByteArray output = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "testheader: foo\n" "\n" "test"; MailCommon::FilterActionAddHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->setContent(data); msgPtr->parse(); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QStringLiteral("testheader\tfoo")); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), true); QCOMPARE(msgPtr->encodedContent(), output); QCOMPARE(context.deleteItem(), false); QCOMPARE(context.needsFlagStore(), false); } void FilterActionAddHeaderTest::shouldReplaceHeaderWhenExistingHeader() { const QByteArray data = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "testheader: bla\n" "\n" "test"; const QByteArray output = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "testheader: foo\n" "\n" "test"; MailCommon::FilterActionAddHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->setContent(data); msgPtr->parse(); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QStringLiteral("testheader\tfoo")); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), true); QCOMPARE(msgPtr->encodedContent(), output); QCOMPARE(context.deleteItem(), false); QCOMPARE(context.needsFlagStore(), false); } void FilterActionAddHeaderTest::shouldAddValue() { QFETCH(QString, argsinput); QFETCH(QString, resultheader); QFETCH(QString, resultvalue); MailCommon::FilterActionAddHeader filter; QWidget *widget = filter.createParamWidget(nullptr); filter.argsFromString(argsinput); filter.setParamWidgetValue(widget); PimCommon::MinimumComboBox *comboBox = widget->findChild(QStringLiteral("combo")); KLineEdit *lineEdit = widget->findChild(QStringLiteral("ledit")); QCOMPARE(comboBox->lineEdit()->text(), resultheader); QCOMPARE(lineEdit->text(), resultvalue); } void FilterActionAddHeaderTest::shouldRequiresSieve() { MailCommon::FilterActionAddHeader filter; QCOMPARE(filter.sieveRequires(), QStringList() << QStringLiteral("editheader")); } QTEST_MAIN(FilterActionAddHeaderTest) diff --git a/src/filter/autotests/filteractionaddtoaddressbooktest.cpp b/src/filter/autotests/filteractionaddtoaddressbooktest.cpp index 50d5470..d7f7f1a 100644 --- a/src/filter/autotests/filteractionaddtoaddressbooktest.cpp +++ b/src/filter/autotests/filteractionaddtoaddressbooktest.cpp @@ -1,96 +1,96 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionaddtoaddressbooktest.h" #include "../filteractions/filteractionaddtoaddressbook.h" -#include +#include #include #include #include #include #include #include FilterActionAddToAddressBookTest::FilterActionAddToAddressBookTest(QObject *parent) : QObject(parent) { } FilterActionAddToAddressBookTest::~FilterActionAddToAddressBookTest() { } void FilterActionAddToAddressBookTest::shouldHaveDefaultValue() { MailCommon::FilterActionAddToAddressBook filter; QWidget *w = filter.createParamWidget(nullptr); PimCommon::MinimumComboBox *headerCombo = w->findChild(QStringLiteral("HeaderComboBox")); QVERIFY(headerCombo); QLabel *label = w->findChild(QStringLiteral("label_with_category")); QVERIFY(label); KPIM::TagWidget *categoryEdit = w->findChild(QStringLiteral("CategoryEdit")); QVERIFY(categoryEdit); label = w->findChild(QStringLiteral("label_in_addressbook")); QVERIFY(label); Akonadi::CollectionComboBox *collectionComboBox = w->findChild(QStringLiteral("AddressBookComboBox")); QVERIFY(collectionComboBox); } void FilterActionAddToAddressBookTest::shouldReportErrorWhenArgumentIsEmpty() { MailCommon::FilterActionAddToAddressBook filter; KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, false); filter.argsFromString(QString()); QVERIFY(filter.isEmpty()); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn); QCOMPARE(context.needsPayloadStore(), false); QCOMPARE(context.needsFlagStore(), false); QCOMPARE(context.needsFullPayload(), false); } void FilterActionAddToAddressBookTest::shouldReportErrorWhenCollectionIsInvalid() { MailCommon::FilterActionAddToAddressBook filter; KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, false); filter.argsFromString(QStringLiteral("foo\t-1\tddd")); QVERIFY(filter.isEmpty()); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn); QCOMPARE(context.needsPayloadStore(), false); QCOMPARE(context.needsFlagStore(), false); QCOMPARE(context.needsFullPayload(), false); } void FilterActionAddToAddressBookTest::shouldRequiresPart() { MailCommon::FilterActionAddToAddressBook filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::Envelope); } QTEST_MAIN(FilterActionAddToAddressBookTest) diff --git a/src/filter/autotests/filteractioncopytest.cpp b/src/filter/autotests/filteractioncopytest.cpp index bfc0e15..5540a57 100644 --- a/src/filter/autotests/filteractioncopytest.cpp +++ b/src/filter/autotests/filteractioncopytest.cpp @@ -1,49 +1,49 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractioncopytest.h" #include "../filteractions/filteractioncopy.h" -#include +#include FilterActionCopyTest::FilterActionCopyTest(QObject *parent) : QObject(parent) { } FilterActionCopyTest::~FilterActionCopyTest() { } void FilterActionCopyTest::shouldBeEmpty() { MailCommon::FilterActionCopy filter; QVERIFY(filter.isEmpty()); } void FilterActionCopyTest::shouldHaveSieveRequires() { MailCommon::FilterActionCopy filter; QCOMPARE(filter.sieveRequires(), QStringList() << QStringLiteral("fileinto") << QStringLiteral("copy")); } void FilterActionCopyTest::shouldHaveRequiresPart() { MailCommon::FilterActionCopy filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::Envelope); } QTEST_MAIN(FilterActionCopyTest) diff --git a/src/filter/autotests/filteractiondeletetest.cpp b/src/filter/autotests/filteractiondeletetest.cpp index 7b4c72b..2859c1c 100644 --- a/src/filter/autotests/filteractiondeletetest.cpp +++ b/src/filter/autotests/filteractiondeletetest.cpp @@ -1,76 +1,76 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractiondeletetest.h" #include "../filteractions/filteractiondelete.h" -#include +#include #include FilterActionDeleteTest::FilterActionDeleteTest(QObject *parent) : QObject(parent) { } FilterActionDeleteTest::~FilterActionDeleteTest() { } void FilterActionDeleteTest::shouldHaveDefaultValue() { MailCommon::FilterActionDelete filter(nullptr); QWidget *w = filter.createParamWidget(nullptr); QVERIFY(w); QLabel *lab = dynamic_cast(w); QVERIFY(lab); QCOMPARE(lab->objectName(), QStringLiteral("label_delete")); } void FilterActionDeleteTest::shouldReturnSieveValue() { MailCommon::FilterActionDelete filter(nullptr); QCOMPARE(filter.sieveCode(), QStringLiteral("discard;")); } void FilterActionDeleteTest::shouldBeNotEmpty() { MailCommon::FilterActionDelete filter; QVERIFY(!filter.isEmpty()); } void FilterActionDeleteTest::shouldRequiresPart() { MailCommon::FilterActionDelete filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::Envelope); } void FilterActionDeleteTest::shouldDeleteItem() { MailCommon::FilterActionDelete filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, false); filter.argsFromString(QString()); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), false); QCOMPARE(context.deleteItem(), true); QCOMPARE(context.needsFlagStore(), false); QCOMPARE(context.needsFullPayload(), false); } QTEST_MAIN(FilterActionDeleteTest) diff --git a/src/filter/autotests/filteractionexectest.cpp b/src/filter/autotests/filteractionexectest.cpp index 2bf20b3..741e03c 100644 --- a/src/filter/autotests/filteractionexectest.cpp +++ b/src/filter/autotests/filteractionexectest.cpp @@ -1,51 +1,51 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionexectest.h" -#include +#include #include "../filteractions/filteractionexec.h" #include "../filteractions/filteractionwithurl.h" #include FilterActionExecTest::FilterActionExecTest(QObject *parent) : QObject(parent) { } FilterActionExecTest::~FilterActionExecTest() { } void FilterActionExecTest::shouldHaveDefaultValue() { MailCommon::FilterActionExec filter; QWidget *w = filter.createParamWidget(nullptr); KUrlRequester *requester = w->findChild(QStringLiteral("requester")); QVERIFY(requester); MailCommon::FilterActionWithUrlHelpButton *helpButton = w->findChild(QStringLiteral("helpbutton")); QVERIFY(helpButton); } void FilterActionExecTest::shouldHaveRequirePart() { MailCommon::FilterActionExec filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage); } QTEST_MAIN(FilterActionExecTest) diff --git a/src/filter/autotests/filteractionforwardtest.cpp b/src/filter/autotests/filteractionforwardtest.cpp index f03f732..2f57627 100644 --- a/src/filter/autotests/filteractionforwardtest.cpp +++ b/src/filter/autotests/filteractionforwardtest.cpp @@ -1,45 +1,45 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionforwardtest.h" -#include +#include #include "../filteractions/filteractionforward.h" FilterActionForwardTest::FilterActionForwardTest(QObject *parent) : QObject(parent) { } FilterActionForwardTest::~FilterActionForwardTest() { } void FilterActionForwardTest::shouldBeEmpty() { MailCommon::FilterActionForward filter; QVERIFY(filter.isEmpty()); filter.argsFromString(QStringLiteral("foo")); QVERIFY(!filter.isEmpty()); } void FilterActionForwardTest::shouldRequiresPart() { MailCommon::FilterActionForward filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage); } QTEST_MAIN(FilterActionForwardTest) diff --git a/src/filter/autotests/filteractionmovetest.cpp b/src/filter/autotests/filteractionmovetest.cpp index 09c0553..effad7c 100644 --- a/src/filter/autotests/filteractionmovetest.cpp +++ b/src/filter/autotests/filteractionmovetest.cpp @@ -1,54 +1,54 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionmovetest.h" -#include +#include #include "../filteractions/filteractionmove.h" #include "folder/folderrequester.h" FilterActionMoveTest::FilterActionMoveTest(QObject *parent) : QObject(parent) { } FilterActionMoveTest::~FilterActionMoveTest() { } void FilterActionMoveTest::shouldHaveSieveRequires() { MailCommon::FilterActionMove filter; QCOMPARE(filter.sieveRequires(), QStringList() << QStringLiteral("fileinto")); } void FilterActionMoveTest::shouldHaveRequiresPart() { MailCommon::FilterActionMove filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::Envelope); } void FilterActionMoveTest::shouldHaveDefaultValue() { MailCommon::FilterActionMove filter; QWidget *w = filter.createParamWidget(nullptr); QVERIFY(w); MailCommon::FolderRequester *requester = dynamic_cast(w); QVERIFY(requester); QCOMPARE(requester->objectName(), QStringLiteral("folderrequester")); } QTEST_MAIN(FilterActionMoveTest) diff --git a/src/filter/autotests/filteractionpipethroughtest.cpp b/src/filter/autotests/filteractionpipethroughtest.cpp index 844c822..0121967 100644 --- a/src/filter/autotests/filteractionpipethroughtest.cpp +++ b/src/filter/autotests/filteractionpipethroughtest.cpp @@ -1,379 +1,379 @@ /* * Copyright (c) 2015 Sandro Knauß * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public * License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ #include "filteractionpipethroughtest.h" #include "../filteractions/filteractionpipethrough.h" -#include +#include using namespace MailCommon; FilterActionPipeThroughTest::FilterActionPipeThroughTest() { } void FilterActionPipeThroughTest::setOutput(FilterAction *filter, const QByteArray &output) { QByteArray sendData = output; filter->argsFromString(QLatin1String("echo \"") + QString::fromUtf8(sendData.replace('"', "\\\"")) + QStringLiteral("\"")); } void FilterActionPipeThroughTest::testWithNoCommand() { /* No command to exceute -> no output -> error */ FilterActionPipeThrough filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; item.setPayload(msgPtr); ItemContext context(item, true); filter.argsFromString(QStringLiteral("")); QCOMPARE(filter.process(context, false), FilterAction::ErrorButGoOn); QCOMPARE(context.needsPayloadStore(), false); } void FilterActionPipeThroughTest::testWithInvalidCommandPath() { /* put a mail in the pipe and make sure we get the same output */ QByteArray data = "From: Konqui \n" "To: Friends \n" "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n" "Subject: Sample message\n" "MIME-Version: 1.0\n" "Content-type: multipart/mixed; boundary=\"simple boundary\"\n" "\n" "\n" "--simple boundary\n" "Content-type: text/plain; charset=us-ascii\n" "\n" "This is explicitly typed plain US-ASCII text.\n" "It DOES end with a linebreak.\n" "\n" "--simple boundary--\n"; FilterActionPipeThrough filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; msgPtr->setContent(data); item.setPayload(msgPtr); ItemContext context(item, true); filter.argsFromString(QStringLiteral("/home/cat ")); QCOMPARE(filter.process(context, false), FilterAction::ErrorButGoOn); QCOMPARE(context.needsPayloadStore(), false); QCOMPARE(msgPtr->encodedContent(), data); } void FilterActionPipeThroughTest::testCommandWithoutOutput() { /* Valid command but no output -> error */ FilterActionPipeThrough filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; item.setPayload(msgPtr); ItemContext context(item, true); filter.argsFromString(QStringLiteral("echo ''")); QCOMPARE(filter.process(context, false), FilterAction::ErrorButGoOn); QCOMPARE(context.needsPayloadStore(), false); } void FilterActionPipeThroughTest::testWithMailOutput() { /* Make sure that mail is not changed from output to KMIME::Message * and also no assemble changes the mail * * Very important for not breake signatures from mails. */ QByteArray data = "From: Konqui \n" "To: Friends \n" "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n" "Subject: Sample message\n" "MIME-Version: 1.0\n" "Content-type: multipart/mixed;\n" " boundary=\"simple boundary\"\n" "\n" "\n" "--simple boundary\n" "Content-type: text/plain;\n" " charset=us-ascii\n" "\n" "This is explicitly typed plain US-ASCII text.\n" "It DOES end with a linebreak.\n" "\n" "--simple boundary--\n"; FilterActionPipeThrough filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; item.setPayload(msgPtr); ItemContext context(item, true); setOutput(&filter, data); QCOMPARE(filter.process(context, false), FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), true); QByteArray expected = data + '\n'; QCOMPARE(msgPtr->encodedContent(), expected); msgPtr->assemble(); //Make sure that the message isFrozen so no submimes do not change QCOMPARE(msgPtr->encodedContent(), expected); } void FilterActionPipeThroughTest::testCopyMail() { /* put a mail in the pipe and make sure we get the same output */ QByteArray data = "From: Konqui \n" "To: Friends \n" "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n" "Subject: Sample message\n" "MIME-Version: 1.0\n" "Content-type: multipart/mixed; boundary=\"simple boundary\"\n" "\n" "\n" "--simple boundary\n" "Content-type: text/plain; charset=us-ascii\n" "\n" "This is explicitly typed plain US-ASCII text.\n" "It DOES end with a linebreak.\n" "\n" "--simple boundary--\n"; FilterActionPipeThrough filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; msgPtr->setContent(data); item.setPayload(msgPtr); ItemContext context(item, true); filter.argsFromString(QStringLiteral("cat ")); QCOMPARE(filter.process(context, false), FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), true); QCOMPARE(msgPtr->encodedContent(), data); } void FilterActionPipeThroughTest::testXUidUnchange() { // the X-UID header isn't changed -> mail isn't changed anyhow QByteArray data = "From: Konqui \n" "To: Friends \n" "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n" "Subject: Sample message\n" "MIME-Version: 1.0\n" "X-UID: XXXX1\n" "Content-type: multipart/mixed;\n" " boundary=\"simple boundary\"\n" "\n" "\n" "--simple boundary\n" "Content-type: text/plain;\n" " charset=us-ascii\n" "\n" "This is explicitly typed plain US-ASCII text.\n" "It DOES end with a linebreak.\n" "\n" "--simple boundary--\n"; FilterActionPipeThrough filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; msgPtr->setContent(data); msgPtr->parse(); item.setPayload(msgPtr); ItemContext context(item, true); filter.argsFromString(QStringLiteral("cat ")); QCOMPARE(filter.process(context, false), FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), true); QCOMPARE(QString::fromLatin1(msgPtr->encodedContent()), QString::fromLatin1(data)); } void FilterActionPipeThroughTest::testXUidRemoved() { /* Make sure if the X-Uid is removed from pipe through, that we add it again * but we have to assemble the mail, so we create some changes in the header. * More important is, that the body isn't changed. */ QByteArray data = "From: Konqui \n" "To: Friends \n" "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n" "Subject: Sample message\n" "MIME-Version: 1.0\n" "X-UID: XXXX1\n" "Content-type: multipart/mixed;\n" " boundary=\"simple boundary\"\n" "\n" "\n" "--simple boundary\n" "Content-type: text/plain;\n" " charset=us-ascii\n" "\n" "This is explicitly typed plain US-ASCII text.\n" "It DOES end with a linebreak.\n" "\n" "--simple boundary--\n"; QByteArray send = "From: Konqui \n" "To: Friends \n" "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n" "Subject: Sample message\n" "MIME-Version: 1.0\n" "Content-type: multipart/mixed;\n" " boundary=\"simple boundary\"\n" "\n" "\n" "--simple boundary\n" "Content-type: text/plain;\n" " charset=us-ascii\n" "\n" "This is explicitly typed plain US-ASCII text.\n" "It DOES end with a linebreak.\n" "\n" "--simple boundary--\n"; QByteArray output = "From: Konqui \n" "To: Friends \n" "Date: Sun, 21 Mar 1993 23:56:48 -0800\n" // <- this is removed, because we assemble "Subject: Sample message\n" "MIME-Version: 1.0\n" "Content-Type: multipart/mixed; boundary=\"simple boundary\"\n" // <- this nweline is removed, because we assemble "X-UID: XXXX1\n" "\n" "\n" "--simple boundary\n" // <- body isn't changed "Content-type: text/plain;\n" " charset=us-ascii\n" "\n" "This is explicitly typed plain US-ASCII text.\n" "It DOES end with a linebreak.\n" "\n" "--simple boundary--\n" "\n"; FilterActionPipeThrough filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; msgPtr->setContent(data); msgPtr->parse(); item.setPayload(msgPtr); ItemContext context(item, true); setOutput(&filter, send); QCOMPARE(filter.process(context, false), FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), true); QCOMPARE(msgPtr->encodedContent(), output); } void FilterActionPipeThroughTest::shouldRequiresPart() { FilterActionPipeThrough filter(this); QCOMPARE(filter.requiredPart(), SearchRule::CompleteMessage); } void FilterActionPipeThroughTest::testXUidChange() { /* Make sure if the X-Uid is changed from pipe through, that we put is to the original value again. * The mail is assembled again, so we create some changes in the header. * More important is, that the body isn't changed. */ QByteArray data = "From: Konqui \n" "To: Friends \n" "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n" "Subject: Sample message\n" "MIME-Version: 1.0\n" "X-UID: XXXX1\n" "Content-type: multipart/mixed;\n" " boundary=\"simple boundary\"\n" "\n" "\n" "--simple boundary\n" "Content-type: text/plain;\n" " charset=us-ascii\n" "\n" "This is explicitly typed plain US-ASCII text.\n" "It DOES end with a linebreak.\n" "\n" "--simple boundary--\n"; QByteArray send = "From: Konqui \n" "To: Friends \n" "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n" "Subject: Sample message\n" "MIME-Version: 1.0\n" "X-UID: XXXX2\n" "Content-type: multipart/mixed;\n" " boundary=\"simple boundary\"\n" "\n" "\n" "--simple boundary\n" "Content-type: text/plain;\n" " charset=us-ascii\n" "\n" "This is explicitly typed plain US-ASCII text.\n" "It DOES end with a linebreak.\n" "\n" "--simple boundary--\n"; QByteArray output = "From: Konqui \n" "To: Friends \n" "Date: Sun, 21 Mar 1993 23:56:48 -0800\n" // <- this is removed, because we assemble "Subject: Sample message\n" "MIME-Version: 1.0\n" "Content-Type: multipart/mixed; boundary=\"simple boundary\"\n" // <- this nweline is removed, because we assemble "X-UID: XXXX1\n" "\n" "\n" "--simple boundary\n" // <- body isn't changed "Content-type: text/plain;\n" " charset=us-ascii\n" "\n" "This is explicitly typed plain US-ASCII text.\n" "It DOES end with a linebreak.\n" "\n" "--simple boundary--\n" "\n"; FilterActionPipeThrough filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; msgPtr->setContent(data); msgPtr->parse(); item.setPayload(msgPtr); ItemContext context(item, true); setOutput(&filter, send); QCOMPARE(filter.process(context, false), FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), true); QCOMPARE(msgPtr->encodedContent(), output); } QTEST_MAIN(FilterActionPipeThroughTest) diff --git a/src/filter/autotests/filteractionplaysoundtest.cpp b/src/filter/autotests/filteractionplaysoundtest.cpp index 7196dbf..3329ca8 100644 --- a/src/filter/autotests/filteractionplaysoundtest.cpp +++ b/src/filter/autotests/filteractionplaysoundtest.cpp @@ -1,63 +1,63 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionplaysoundtest.h" #include "../filteractions/filteractionplaysound.h" -#include +#include #include "filter/soundtestwidget.h" FilterActionPlaySoundTest::FilterActionPlaySoundTest(QObject *parent) : QObject(parent) { } FilterActionPlaySoundTest::~FilterActionPlaySoundTest() { } void FilterActionPlaySoundTest::shouldBeValid() { MailCommon::FilterActionPlaySound filter; QVERIFY(filter.isEmpty()); filter.argsFromString(QStringLiteral("foo")); QVERIFY(!filter.isEmpty()); } void FilterActionPlaySoundTest::shouldHaveDefaultValue() { MailCommon::FilterActionPlaySound filter; QWidget *w = filter.createParamWidget(nullptr); QVERIFY(w); QCOMPARE(w->objectName(), QStringLiteral("soundwidget")); MailCommon::SoundTestWidget *soundTest = dynamic_cast(w); QVERIFY(soundTest); QVERIFY(soundTest->url().isEmpty()); } void FilterActionPlaySoundTest::shouldHaveRequiredPart() { MailCommon::FilterActionPlaySound filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::Envelope); } void FilterActionPlaySoundTest::shouldSieveRequres() { MailCommon::FilterActionPlaySound w; QCOMPARE(w.sieveRequires(), QStringList()); } QTEST_MAIN(FilterActionPlaySoundTest) diff --git a/src/filter/autotests/filteractionredirecttest.cpp b/src/filter/autotests/filteractionredirecttest.cpp index 3e0ae7c..e849ded 100644 --- a/src/filter/autotests/filteractionredirecttest.cpp +++ b/src/filter/autotests/filteractionredirecttest.cpp @@ -1,43 +1,43 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionredirecttest.h" #include "../filteractions/filteractionredirect.h" -#include +#include FilterActionRedirectTest::FilterActionRedirectTest(QObject *parent) : QObject(parent) { } FilterActionRedirectTest::~FilterActionRedirectTest() { } void FilterActionRedirectTest::shouldBeEmpty() { MailCommon::FilterActionRedirect filter; QVERIFY(filter.isEmpty()); } void FilterActionRedirectTest::shouldHaveRequiredPart() { MailCommon::FilterActionRedirect filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage); } QTEST_MAIN(FilterActionRedirectTest) diff --git a/src/filter/autotests/filteractionremoveheadertest.cpp b/src/filter/autotests/filteractionremoveheadertest.cpp index 06b55ac..9d2fe43 100644 --- a/src/filter/autotests/filteractionremoveheadertest.cpp +++ b/src/filter/autotests/filteractionremoveheadertest.cpp @@ -1,166 +1,166 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionremoveheadertest.h" #include "../filteractions/filteractionremoveheader.h" -#include +#include #include FilterActionRemoveHeaderTest::FilterActionRemoveHeaderTest(QObject *parent) : QObject(parent) { } FilterActionRemoveHeaderTest::~FilterActionRemoveHeaderTest() { } void FilterActionRemoveHeaderTest::shouldHaveDefaultValue() { MailCommon::FilterActionRemoveHeader filter; QWidget *w = filter.createParamWidget(nullptr); PimCommon::MinimumComboBox *comboBox = dynamic_cast(w); QVERIFY(comboBox); QVERIFY(comboBox->isEditable()); QVERIFY(comboBox->count() > 0); } void FilterActionRemoveHeaderTest::shouldHaveSieveRequires() { MailCommon::FilterActionRemoveHeader filter; QCOMPARE(filter.sieveRequires(), QStringList() << QStringLiteral("editheader")); } void FilterActionRemoveHeaderTest::shouldBeEmpty() { MailCommon::FilterActionRemoveHeader filter; QVERIFY(filter.isEmpty()); filter.argsFromString(QStringLiteral("bla")); QVERIFY(!filter.isEmpty()); } void FilterActionRemoveHeaderTest::shouldNotExecuteActionWhenParameterIsEmpty() { MailCommon::FilterActionRemoveHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QString()); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn); QCOMPARE(context.needsPayloadStore(), false); } void FilterActionRemoveHeaderTest::shouldRemoveHeader() { const QByteArray data = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "testheader: foo\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "\n" "test"; const QByteArray output = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "\n" "test"; MailCommon::FilterActionRemoveHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->setContent(data); msgPtr->parse(); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QStringLiteral("testheader")); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), true); QCOMPARE(msgPtr->encodedContent(), output); } void FilterActionRemoveHeaderTest::shouldNotTryToRemoveHeaderWhenItDoesntExist() { const QByteArray data = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "testheader2: foo\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "\n" "test"; MailCommon::FilterActionRemoveHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->setContent(data); msgPtr->parse(); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QStringLiteral("testheader")); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), false); QCOMPARE(msgPtr->encodedContent(), data); } void FilterActionRemoveHeaderTest::shouldRemoveMultiHeader() { const QByteArray data = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "testheader: foo\n" "testheader: foo\n" "testheader: bla\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "\n" "test"; const QByteArray output = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "\n" "test"; MailCommon::FilterActionRemoveHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->setContent(data); msgPtr->parse(); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QStringLiteral("testheader")); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), true); QCOMPARE(msgPtr->encodedContent(), output); } void FilterActionRemoveHeaderTest::shouldHaveRequiredPart() { MailCommon::FilterActionRemoveHeader filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage); } QTEST_MAIN(FilterActionRemoveHeaderTest) diff --git a/src/filter/autotests/filteractionreplytotest.cpp b/src/filter/autotests/filteractionreplytotest.cpp index 36bef9c..9e4d0a7 100644 --- a/src/filter/autotests/filteractionreplytotest.cpp +++ b/src/filter/autotests/filteractionreplytotest.cpp @@ -1,144 +1,144 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionreplytotest.h" #include "../filteractions/filteractionreplyto.h" -#include +#include #include FilterActionReplyToTest::FilterActionReplyToTest(QObject *parent) : QObject(parent) { } FilterActionReplyToTest::~FilterActionReplyToTest() { } void FilterActionReplyToTest::shouldHaveDefaultValue() { MailCommon::FilterActionReplyTo filter; QWidget *w = filter.createParamWidget(nullptr); QCOMPARE(w->objectName(), QStringLiteral("emailaddressrequester")); } void FilterActionReplyToTest::shouldBeEmpty() { MailCommon::FilterActionReplyTo filter; QVERIFY(filter.isEmpty()); } void FilterActionReplyToTest::shouldHadReplyToHeader() { const QString replyTo = QStringLiteral("fooreply@kde.org"); const QByteArray data = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "\n" "test"; const QByteArray output = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "Reply-To: fooreply@kde.org\n" "\n" "test"; MailCommon::FilterActionReplyTo filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->setContent(data); msgPtr->parse(); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(replyTo); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), true); QCOMPARE(msgPtr->encodedContent(), output); } void FilterActionReplyToTest::shouldReplaceReplyToHeader() { const QString replyTo = QStringLiteral("fooreply@kde.org"); const QByteArray data = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "Reply-To: oldfooreply@kde.org\n" "\n" "test"; const QByteArray output = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "Reply-To: fooreply@kde.org\n" "\n" "test"; MailCommon::FilterActionReplyTo filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->setContent(data); msgPtr->parse(); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(replyTo); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), true); QCOMPARE(msgPtr->encodedContent(), output); } void FilterActionReplyToTest::shouldHaveRequiredPart() { MailCommon::FilterActionReplyTo filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage); } void FilterActionReplyToTest::shouldNotCreateReplyToWhenAddressIsEmpty() { const QByteArray data = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "Reply-To: oldfooreply@kde.org\n" "\n" "test"; MailCommon::FilterActionReplyTo filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->setContent(data); msgPtr->parse(); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QString()); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn); QCOMPARE(context.needsPayloadStore(), false); QCOMPARE(msgPtr->encodedContent(), data); } QTEST_MAIN(FilterActionReplyToTest) diff --git a/src/filter/autotests/filteractionrewriteheadertest.cpp b/src/filter/autotests/filteractionrewriteheadertest.cpp index 2227045..1c28952 100644 --- a/src/filter/autotests/filteractionrewriteheadertest.cpp +++ b/src/filter/autotests/filteractionrewriteheadertest.cpp @@ -1,185 +1,185 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionrewriteheadertest.h" -#include +#include #include "../filteractions/filteractionrewriteheader.h" #include #include #include #include FilterActionRewriteHeaderTest::FilterActionRewriteHeaderTest(QObject *parent) : QObject(parent) { } FilterActionRewriteHeaderTest::~FilterActionRewriteHeaderTest() { } void FilterActionRewriteHeaderTest::shouldHaveDefaultValue() { MailCommon::FilterActionRewriteHeader filter; QWidget *w = filter.createParamWidget(nullptr); PimCommon::MinimumComboBox *combo = w->findChild(QStringLiteral("combo")); QVERIFY(combo); QVERIFY(combo->count() > 0); QLabel *label = w->findChild(QStringLiteral("label_replace")); QVERIFY(label); KLineEdit *regExpLineEdit = w->findChild(QStringLiteral("search")); QVERIFY(regExpLineEdit); QVERIFY(regExpLineEdit->text().isEmpty()); label = w->findChild(QStringLiteral("label_with")); QVERIFY(label); KLineEdit *lineEdit = w->findChild(QStringLiteral("replace")); QVERIFY(lineEdit); QVERIFY(lineEdit->text().isEmpty()); } void FilterActionRewriteHeaderTest::shouldBeEmpty() { MailCommon::FilterActionRewriteHeader filter; QVERIFY(filter.isEmpty()); filter.argsFromString(QStringLiteral("foo\tbla")); QVERIFY(filter.isEmpty()); filter.argsFromString(QStringLiteral("foo\tbla\tkde")); QVERIFY(!filter.isEmpty()); } void FilterActionRewriteHeaderTest::shouldNotExecuteActionWhenParameterIsEmpty() { MailCommon::FilterActionRewriteHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QString()); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn); QCOMPARE(context.needsPayloadStore(), false); } void FilterActionRewriteHeaderTest::shouldNotExecuteActionWhenValueIsEmpty() { MailCommon::FilterActionRewriteHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QStringLiteral("foo")); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn); QCOMPARE(context.needsPayloadStore(), false); filter.argsFromString(QStringLiteral("foo\tbla")); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn); QCOMPARE(context.needsPayloadStore(), false); } void FilterActionRewriteHeaderTest::shouldRewriteHeader() { const QByteArray data = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "testheader: foo\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "\n" "test"; const QByteArray output = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "testheader: bla\n" "\n" "test"; MailCommon::FilterActionRewriteHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->setContent(data); msgPtr->parse(); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QStringLiteral("testheader\tfoo\tbla")); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), true); QCOMPARE(msgPtr->encodedContent(), output); } void FilterActionRewriteHeaderTest::shouldNotRewriteHeaderWhenHeaderNotFound() { const QByteArray data = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "\n" "test"; MailCommon::FilterActionRewriteHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->setContent(data); msgPtr->parse(); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QStringLiteral("testheader\tfoo\tbla")); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), false); QCOMPARE(msgPtr->encodedContent(), data); } void FilterActionRewriteHeaderTest::shouldNotRewriteHeaderWhenRegexpNotFound() { const QByteArray data = "From: foo@kde.org\n" "To: foo@kde.org\n" "Subject: test\n" "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" "MIME-Version: 1.0\n" "testheader: bla\n" "\n" "test"; MailCommon::FilterActionRewriteHeader filter(this); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->setContent(data); msgPtr->parse(); Akonadi::Item item; item.setPayload(msgPtr); MailCommon::ItemContext context(item, true); filter.argsFromString(QStringLiteral("testheader\tfoo\tbla")); QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); QCOMPARE(context.needsPayloadStore(), false); QCOMPARE(msgPtr->encodedContent(), data); } void FilterActionRewriteHeaderTest::shouldHaveRequiredPart() { MailCommon::FilterActionRewriteHeader filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage); } QTEST_MAIN(FilterActionRewriteHeaderTest) diff --git a/src/filter/autotests/filteractionsendfakedispositiontest.cpp b/src/filter/autotests/filteractionsendfakedispositiontest.cpp index 05f5e76..2d4b029 100644 --- a/src/filter/autotests/filteractionsendfakedispositiontest.cpp +++ b/src/filter/autotests/filteractionsendfakedispositiontest.cpp @@ -1,56 +1,56 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionsendfakedispositiontest.h" #include "../filteractions/filteractionsendfakedisposition.h" -#include +#include #include FilterActionSendFakeDispositionTest::FilterActionSendFakeDispositionTest(QObject *parent) : QObject(parent) { } FilterActionSendFakeDispositionTest::~FilterActionSendFakeDispositionTest() { } void FilterActionSendFakeDispositionTest::shouldHaveDefaultValue() { MailCommon::FilterActionSendFakeDisposition filter; QWidget *w = filter.createParamWidget(nullptr); QCOMPARE(w->objectName(), QStringLiteral("combobox")); PimCommon::MinimumComboBox *comboBox = dynamic_cast(w); QVERIFY(comboBox); QVERIFY(!comboBox->isEditable()); QVERIFY(comboBox->count() > 0); } void FilterActionSendFakeDispositionTest::shouldBeEmpty() { MailCommon::FilterActionSendFakeDisposition filter; QVERIFY(filter.isEmpty()); } void FilterActionSendFakeDispositionTest::shouldHaveRequiredPart() { MailCommon::FilterActionSendFakeDisposition filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage); } QTEST_MAIN(FilterActionSendFakeDispositionTest) diff --git a/src/filter/autotests/filteractionsendreceipttest.cpp b/src/filter/autotests/filteractionsendreceipttest.cpp index ac77b9c..2f8c304 100644 --- a/src/filter/autotests/filteractionsendreceipttest.cpp +++ b/src/filter/autotests/filteractionsendreceipttest.cpp @@ -1,44 +1,44 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionsendreceipttest.h" #include "../filteractions/filteractionsendreceipt.h" -#include +#include FilterActionSendReceiptTest::FilterActionSendReceiptTest(QObject *parent) : QObject(parent) { } void FilterActionSendReceiptTest::shouldBeNotEmpty() { MailCommon::FilterActionSendReceipt filter; QVERIFY(!filter.isEmpty()); } void FilterActionSendReceiptTest::shouldRequiresPart() { MailCommon::FilterActionSendReceipt filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage); } void FilterActionSendReceiptTest::shouldSieveRequires() { MailCommon::FilterActionSendReceipt filter; QCOMPARE(filter.sieveRequires(), QStringList()); } QTEST_MAIN(FilterActionSendReceiptTest) diff --git a/src/filter/autotests/filteractionsetstatustest.cpp b/src/filter/autotests/filteractionsetstatustest.cpp index 9d6a478..22b9218 100644 --- a/src/filter/autotests/filteractionsetstatustest.cpp +++ b/src/filter/autotests/filteractionsetstatustest.cpp @@ -1,62 +1,62 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionsetstatustest.h" #include "../filteractions/filteractionsetstatus.h" -#include +#include #include #include FilterActionSetStatusTest::FilterActionSetStatusTest(QObject *parent) : QObject(parent) { } FilterActionSetStatusTest::~FilterActionSetStatusTest() { } void FilterActionSetStatusTest::shouldHaveDefaultValue() { MailCommon::FilterActionSetStatus filter; QWidget *w = filter.createParamWidget(nullptr); QCOMPARE(w->objectName(), QStringLiteral("combobox")); PimCommon::MinimumComboBox *comboBox = dynamic_cast(w); QVERIFY(comboBox); QVERIFY(!comboBox->isEditable()); QVERIFY(comboBox->count() > 0); } void FilterActionSetStatusTest::shouldHaveSieveRequires() { MailCommon::FilterActionSetStatus filter; QCOMPARE(filter.sieveRequires(), QStringList() << QStringLiteral("imap4flags")); } void FilterActionSetStatusTest::shouldBeEmpty() { MailCommon::FilterActionSetStatus filter; QVERIFY(filter.isEmpty()); } void FilterActionSetStatusTest::shouldRequiresPart() { MailCommon::FilterActionSetStatus filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::Envelope); } QTEST_MAIN(FilterActionSetStatusTest) diff --git a/src/filter/autotests/filteractionsettransporttest.cpp b/src/filter/autotests/filteractionsettransporttest.cpp index cae5ff0..c87ba26 100644 --- a/src/filter/autotests/filteractionsettransporttest.cpp +++ b/src/filter/autotests/filteractionsettransporttest.cpp @@ -1,43 +1,43 @@ #include "filteractionsettransporttest.h" #include "../filteractions/filteractionsettransport.h" -#include +#include #include FilterActionSetTransportTest::FilterActionSetTransportTest(QObject *parent) : QObject(parent) { } FilterActionSetTransportTest::~FilterActionSetTransportTest() { } void FilterActionSetTransportTest::shouldBeEmpty() { MailCommon::FilterActionSetTransport filter; QVERIFY(filter.isEmpty()); } void FilterActionSetTransportTest::shouldHaveDefaultValue() { MailCommon::FilterActionSetTransport filter; QWidget *w = filter.createParamWidget(nullptr); QCOMPARE(w->objectName(), QStringLiteral("transportcombobox")); MailTransport::TransportComboBox *transportCombobox = dynamic_cast(w); QVERIFY(transportCombobox); } void FilterActionSetTransportTest::shouldHaveRequiredPart() { MailCommon::FilterActionSetTransport filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage); } void FilterActionSetTransportTest::shouldHaveSieveRequires() { MailCommon::FilterActionSetTransport filter; QCOMPARE(filter.sieveRequires(), QStringList()); } QTEST_MAIN(FilterActionSetTransportTest) diff --git a/src/filter/autotests/filteractionunsetstatustest.cpp b/src/filter/autotests/filteractionunsetstatustest.cpp index dfa59e6..ee8615b 100644 --- a/src/filter/autotests/filteractionunsetstatustest.cpp +++ b/src/filter/autotests/filteractionunsetstatustest.cpp @@ -1,43 +1,43 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionunsetstatustest.h" #include "../filteractions/filteractionunsetstatus.h" -#include +#include FilterActionUnsetStatusTest::FilterActionUnsetStatusTest(QObject *parent) : QObject(parent) { } FilterActionUnsetStatusTest::~FilterActionUnsetStatusTest() { } void FilterActionUnsetStatusTest::shouldHaveSieveRequires() { MailCommon::FilterActionUnsetStatus filter; QCOMPARE(filter.sieveRequires(), QStringList() << QStringLiteral("imap4flags")); } void FilterActionUnsetStatusTest::shouldRequiresPart() { MailCommon::FilterActionUnsetStatus filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::Envelope); } QTEST_MAIN(FilterActionUnsetStatusTest) diff --git a/src/filter/autotests/filteractionwithaddresstest.cpp b/src/filter/autotests/filteractionwithaddresstest.cpp index 55f116e..3333f39 100644 --- a/src/filter/autotests/filteractionwithaddresstest.cpp +++ b/src/filter/autotests/filteractionwithaddresstest.cpp @@ -1,78 +1,78 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionwithaddresstest.h" #include "../filteractions/filteractionwithaddress.h" -#include +#include #include #include class TestFilterActionWithAddress : public MailCommon::FilterActionWithAddress { public: TestFilterActionWithAddress() : MailCommon::FilterActionWithAddress(QStringLiteral("foo"), QStringLiteral("bla")) { } FilterAction::ReturnCode process(MailCommon::ItemContext &, bool) const override { return GoOn; } MailCommon::SearchRule::RequiredPart requiredPart() const override { return MailCommon::SearchRule::CompleteMessage; } }; FilterActionWithAddressTest::FilterActionWithAddressTest(QObject *parent) : QObject(parent) { } FilterActionWithAddressTest::~FilterActionWithAddressTest() { } void FilterActionWithAddressTest::shouldHaveDefaultValue() { TestFilterActionWithAddress filter; QWidget *w = filter.createParamWidget(nullptr); QCOMPARE(w->objectName(), QStringLiteral("emailaddressrequester")); Akonadi::EmailAddressRequester *requester = dynamic_cast(w); QVERIFY(requester); QVERIFY(filter.isEmpty()); } void FilterActionWithAddressTest::shouldAssignValue() { TestFilterActionWithAddress filter; QWidget *w = filter.createParamWidget(nullptr); Akonadi::EmailAddressRequester *requester = dynamic_cast(w); filter.argsFromString(QStringLiteral("foo")); filter.setParamWidgetValue(w); QVERIFY(!filter.isEmpty()); QVERIFY(!requester->text().isEmpty()); } void FilterActionWithAddressTest::shouldRequiresPart() { TestFilterActionWithAddress filter; QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage); } QTEST_MAIN(FilterActionWithAddressTest) diff --git a/src/filter/autotests/filteractionwithurltest.cpp b/src/filter/autotests/filteractionwithurltest.cpp index d641925..636c4c8 100644 --- a/src/filter/autotests/filteractionwithurltest.cpp +++ b/src/filter/autotests/filteractionwithurltest.cpp @@ -1,117 +1,117 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filteractionwithurltest.h" #include "../filteractions/filteractionwithurl.h" #include #include -#include +#include class TestFilterActionWithUrl : public MailCommon::FilterActionWithUrl { public: TestFilterActionWithUrl() : MailCommon::FilterActionWithUrl(QStringLiteral("test"), QStringLiteral("label")) { } FilterAction::ReturnCode process(MailCommon::ItemContext &, bool) const override { return GoOn; } MailCommon::SearchRule::RequiredPart requiredPart() const override { return MailCommon::SearchRule::CompleteMessage; } }; FilterActionWithUrlTest::FilterActionWithUrlTest(QObject *parent) : QObject(parent) { } FilterActionWithUrlTest::~FilterActionWithUrlTest() { } void FilterActionWithUrlTest::shouldHaveDefaultValue() { TestFilterActionWithUrl filter; QWidget *w = filter.createParamWidget(nullptr); KUrlRequester *requester = w->findChild(QStringLiteral("requester")); QVERIFY(requester); QToolButton *toolButton = w->findChild(QStringLiteral("helpbutton")); QVERIFY(toolButton); } void FilterActionWithUrlTest::shouldClearWidget() { TestFilterActionWithUrl filter; QWidget *w = filter.createParamWidget(nullptr); KUrlRequester *requester = w->findChild(QStringLiteral("requester")); requester->setUrl(QUrl::fromLocalFile(QStringLiteral("/foo/bla"))); QVERIFY(!requester->url().isEmpty()); filter.clearParamWidget(w); QVERIFY(requester->url().isEmpty()); } void FilterActionWithUrlTest::shouldAddValue() { TestFilterActionWithUrl filter; QWidget *w = filter.createParamWidget(nullptr); KUrlRequester *requester = w->findChild(QStringLiteral("requester")); filter.argsFromString(QStringLiteral("/foo")); filter.setParamWidgetValue(w); QCOMPARE(requester->lineEdit()->text(), QStringLiteral("/foo")); } void FilterActionWithUrlTest::shouldApplyValue() { TestFilterActionWithUrl filter; QWidget *w = filter.createParamWidget(nullptr); filter.argsFromString(QStringLiteral("foo")); filter.setParamWidgetValue(w); filter.applyParamWidgetValue(w); QCOMPARE(filter.argsAsString(), QStringLiteral("foo")); } void FilterActionWithUrlTest::shouldTestUrl_data() { QTest::addColumn("urlstr"); QTest::addColumn("output"); QTest::newRow("fullpath") << QStringLiteral("/usr/bin/ls") << QStringLiteral("/usr/bin/ls"); QTest::newRow("local") << QStringLiteral("ls") << QStringLiteral("ls"); QTest::newRow("localwithargument") << QStringLiteral("ls -l") << QStringLiteral("ls -l"); QTest::newRow("fullpathwithargument") << QStringLiteral("/usr/bin/ls -l") << QStringLiteral("/usr/bin/ls -l"); QTest::newRow("url") << QStringLiteral("file:///usr/bin/ls -l") << QStringLiteral("/usr/bin/ls -l"); QTest::newRow("url2") << QStringLiteral("/usr/bin/ls -l") << QStringLiteral("/usr/bin/ls -l"); } void FilterActionWithUrlTest::shouldTestUrl() { QFETCH(QString, urlstr); QFETCH(QString, output); TestFilterActionWithUrl filter; QWidget *w = filter.createParamWidget(nullptr); filter.argsFromString(urlstr); filter.setParamWidgetValue(w); filter.applyParamWidgetValue(w); QCOMPARE(filter.argsAsString(), output); } QTEST_MAIN(FilterActionWithUrlTest) diff --git a/src/filter/autotests/filterconverttosieveresultdialogtest.cpp b/src/filter/autotests/filterconverttosieveresultdialogtest.cpp index 0a15731..0db1444 100644 --- a/src/filter/autotests/filterconverttosieveresultdialogtest.cpp +++ b/src/filter/autotests/filterconverttosieveresultdialogtest.cpp @@ -1,60 +1,60 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filterconverttosieveresultdialogtest.h" #include "../filterconverter/filterconverttosieveresultdialog.h" #include -#include +#include #include #include #include FilterConvertToSieveResultDialogTest::FilterConvertToSieveResultDialogTest(QObject *parent) : QObject(parent) { QStandardPaths::setTestModeEnabled(true); } FilterConvertToSieveResultDialogTest::~FilterConvertToSieveResultDialogTest() { } void FilterConvertToSieveResultDialogTest::shouldHaveDefaultValue() { MailCommon::FilterConvertToSieveResultDialog dlg; QDialogButtonBox *buttonBox = dlg.findChild(QStringLiteral("buttonbox")); QVERIFY(buttonBox); QPushButton *saveButton = dlg.findChild(QStringLiteral("savebutton")); QVERIFY(saveButton); KPIMTextEdit::PlainTextEditorWidget *editor = dlg.findChild(QStringLiteral("editor")); QVERIFY(editor); QVERIFY(editor->toPlainText().isEmpty()); } void FilterConvertToSieveResultDialogTest::shouldAddCode() { MailCommon::FilterConvertToSieveResultDialog dlg; KPIMTextEdit::PlainTextEditorWidget *editor = dlg.findChild(QStringLiteral("editor")); QVERIFY(editor->toPlainText().isEmpty()); const QString code = QStringLiteral("foo"); dlg.setCode(code); QCOMPARE(editor->toPlainText(), code); } QTEST_MAIN(FilterConvertToSieveResultDialogTest) diff --git a/src/filter/autotests/invalidfilterdialogtest.cpp b/src/filter/autotests/invalidfilterdialogtest.cpp index bf1cab9..c48ff01 100644 --- a/src/filter/autotests/invalidfilterdialogtest.cpp +++ b/src/filter/autotests/invalidfilterdialogtest.cpp @@ -1,47 +1,47 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "invalidfilterdialogtest.h" #include "../filter/invalidfilters/invalidfilterdialog.h" -#include +#include #include "../filter/invalidfilters/invalidfilterwidget.h" #include "../filter/invalidfilters/invalidfilterinfowidget.h" #include InvalidFilterDialogTest::InvalidFilterDialogTest(QObject *parent) : QObject(parent) { QStandardPaths::setTestModeEnabled(true); } InvalidFilterDialogTest::~InvalidFilterDialogTest() { } void InvalidFilterDialogTest::shouldHaveDefaultValue() { MailCommon::InvalidFilterDialog dlg; MailCommon::InvalidFilterWidget *widget = dlg.findChild(QStringLiteral("invalid_filter_widget")); QVERIFY(widget); MailCommon::InvalidFilterInfoWidget *infoWidget = dlg.findChild(QStringLiteral("invalid_filter_infowidget")); QVERIFY(infoWidget); QVERIFY(!infoWidget->isVisible()); QVERIFY(!dlg.windowTitle().isEmpty()); } QTEST_MAIN(InvalidFilterDialogTest) diff --git a/src/filter/autotests/invalidfilterinfotest.cpp b/src/filter/autotests/invalidfilterinfotest.cpp index bf36b7c..a682478 100644 --- a/src/filter/autotests/invalidfilterinfotest.cpp +++ b/src/filter/autotests/invalidfilterinfotest.cpp @@ -1,71 +1,71 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "invalidfilterinfotest.h" #include "../filter/invalidfilters/invalidfilterinfo.h" -#include +#include InvalidFilterInfoTest::InvalidFilterInfoTest(QObject *parent) : QObject(parent) { } InvalidFilterInfoTest::~InvalidFilterInfoTest() { } void InvalidFilterInfoTest::shouldAddEmptyValue() { MailCommon::InvalidFilterInfo info; QVERIFY(info.name().isEmpty()); QVERIFY(info.information().isEmpty()); } void InvalidFilterInfoTest::shouldAssignValueFromConstructor() { const QString name = QStringLiteral("foo"); const QString information = QStringLiteral("bla"); MailCommon::InvalidFilterInfo info(name, information); QCOMPARE(info.name(), name); QCOMPARE(info.information(), information); } void InvalidFilterInfoTest::shouldAssignValue() { MailCommon::InvalidFilterInfo info; const QString name = QStringLiteral("foo"); const QString information = QStringLiteral("bla"); info.setName(name); info.setInformation(information); QCOMPARE(info.name(), name); QCOMPARE(info.information(), information); } void InvalidFilterInfoTest::shouldBeEqual() { MailCommon::InvalidFilterInfo info; const QString name = QStringLiteral("foo"); const QString information = QStringLiteral("bla"); info.setName(name); info.setInformation(information); MailCommon::InvalidFilterInfo copyInfo; copyInfo = info; QVERIFY(copyInfo == info); } QTEST_MAIN(InvalidFilterInfoTest) diff --git a/src/filter/autotests/invalidfilterinfowidgettest.cpp b/src/filter/autotests/invalidfilterinfowidgettest.cpp index 439702d..cb0c731 100644 --- a/src/filter/autotests/invalidfilterinfowidgettest.cpp +++ b/src/filter/autotests/invalidfilterinfowidgettest.cpp @@ -1,38 +1,38 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "invalidfilterinfowidgettest.h" #include "../invalidfilters/invalidfilterinfowidget.h" -#include +#include InvalidFilterInfoWidgetTest::InvalidFilterInfoWidgetTest(QObject *parent) : QObject(parent) { } InvalidFilterInfoWidgetTest::~InvalidFilterInfoWidgetTest() { } void InvalidFilterInfoWidgetTest::shouldHaveDefaultValue() { MailCommon::InvalidFilterInfoWidget w; QVERIFY(!w.isVisible()); QVERIFY(!w.isCloseButtonVisible()); } QTEST_MAIN(InvalidFilterInfoWidgetTest) diff --git a/src/filter/autotests/invalidfilterlistwidgettest.cpp b/src/filter/autotests/invalidfilterlistwidgettest.cpp index 078970e..f3b85e8 100644 --- a/src/filter/autotests/invalidfilterlistwidgettest.cpp +++ b/src/filter/autotests/invalidfilterlistwidgettest.cpp @@ -1,49 +1,49 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "invalidfilterlistwidgettest.h" -#include +#include #include "../filter/invalidfilters/invalidfilterlistview.h" #include "../filter/invalidfilters/invalidfilterinfo.h" InvalidFilterListWidgetTest::InvalidFilterListWidgetTest(QObject *parent) : QObject(parent) { } InvalidFilterListWidgetTest::~InvalidFilterListWidgetTest() { } void InvalidFilterListWidgetTest::shouldHaveDefaultValue() { MailCommon::InvalidFilterListView w; QCOMPARE(w.model()->rowCount(), 0); } void InvalidFilterListWidgetTest::shouldAddInvalidFilters() { MailCommon::InvalidFilterListView w; QVector lst; lst.append(MailCommon::InvalidFilterInfo(QStringLiteral("foo"), QStringLiteral("bla"))); lst.append(MailCommon::InvalidFilterInfo(QStringLiteral("foo1"), QStringLiteral("bla1"))); lst.append(MailCommon::InvalidFilterInfo(QStringLiteral("foo2"), QStringLiteral("bla2"))); w.setInvalidFilters(lst); QCOMPARE(w.model()->rowCount(), 3); } QTEST_MAIN(InvalidFilterListWidgetTest) diff --git a/src/filter/autotests/invalidfilterwidgettest.cpp b/src/filter/autotests/invalidfilterwidgettest.cpp index f5c0c70..debffb0 100644 --- a/src/filter/autotests/invalidfilterwidgettest.cpp +++ b/src/filter/autotests/invalidfilterwidgettest.cpp @@ -1,42 +1,42 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "invalidfilterwidgettest.h" #include "../filter/invalidfilters/invalidfilterwidget.h" #include "../filter/invalidfilters/invalidfilterlistview.h" #include -#include +#include InvalidFilterWidgetTest::InvalidFilterWidgetTest(QObject *parent) : QObject(parent) { } InvalidFilterWidgetTest::~InvalidFilterWidgetTest() { } void InvalidFilterWidgetTest::shouldHaveDefaultValue() { MailCommon::InvalidFilterWidget w; QLabel *lab = w.findChild(QStringLiteral("label")); QVERIFY(lab); MailCommon::InvalidFilterListView *list = w.findChild(QStringLiteral("invalidfilterlist")); QVERIFY(list); } QTEST_MAIN(InvalidFilterWidgetTest) diff --git a/src/filter/autotests/itemcontexttest.cpp b/src/filter/autotests/itemcontexttest.cpp index 53da765..32db66a 100644 --- a/src/filter/autotests/itemcontexttest.cpp +++ b/src/filter/autotests/itemcontexttest.cpp @@ -1,113 +1,113 @@ /* Copyright (c) 2014-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "itemcontexttest.h" #include "../itemcontext.h" -#include +#include #include ItemContextTest::ItemContextTest(QObject *parent) : QObject(parent) { } ItemContextTest::~ItemContextTest() { } void ItemContextTest::shouldHaveDefaultValue() { Akonadi::Item item(42); MailCommon::ItemContext itemContext(item, true); QCOMPARE(itemContext.item(), item); QVERIFY(!itemContext.moveTargetCollection().isValid()); QVERIFY(!itemContext.needsPayloadStore()); QVERIFY(!itemContext.needsFlagStore()); QVERIFY(itemContext.needsFullPayload()); QVERIFY(!itemContext.deleteItem()); MailCommon::ItemContext itemContext2(item, false); QCOMPARE(itemContext2.item(), item); QVERIFY(!itemContext2.moveTargetCollection().isValid()); QVERIFY(!itemContext2.needsPayloadStore()); QVERIFY(!itemContext2.needsFlagStore()); QVERIFY(!itemContext2.needsFullPayload()); QVERIFY(!itemContext2.deleteItem()); } void ItemContextTest::shouldAssignContext_data() { QTest::addColumn("needspayloadstore"); QTest::addColumn("needsflagstore"); QTest::addColumn("needsfullpayload"); QTest::addColumn("deleteitem"); QTest::newRow("no boolean") << false << false << false << false; QTest::newRow("needspayloadstore") << true << false << false << false; QTest::newRow("needsflagstore") << false << true << false << false; QTest::newRow("needsfullpayload") << false << false << true << false; QTest::newRow("deleteitem") << false << false << false << true; QTest::newRow("all") << true << true << true << true; QTest::newRow("T T F F") << true << true << false << false; QTest::newRow("T T T F") << true << true << true << false; QTest::newRow("F T F F") << false << true << false << false; QTest::newRow("F F T F") << false << false << true << false; QTest::newRow("F T T F") << false << true << true << false; QTest::newRow("F T T T") << false << true << true << true; QTest::newRow("F F F T") << false << false << false << true; QTest::newRow("F T F T") << false << true << false << true; QTest::newRow("F F F T") << false << false << false << true; } void ItemContextTest::shouldAssignContext() { QFETCH(bool, needspayloadstore); QFETCH(bool, needsflagstore); QFETCH(bool, needsfullpayload); QFETCH(bool, deleteitem); Akonadi::Item item(42); MailCommon::ItemContext itemContext(item, needsfullpayload); if (needspayloadstore) { itemContext.setNeedsPayloadStore(); } if (needsflagstore) { itemContext.setNeedsFlagStore(); } if (deleteitem) { itemContext.setDeleteItem(); } QCOMPARE(itemContext.item(), item); QCOMPARE(itemContext.needsFlagStore(), needsflagstore); QCOMPARE(itemContext.needsFullPayload(), needsfullpayload); QCOMPARE(itemContext.needsPayloadStore(), needspayloadstore); QCOMPARE(itemContext.deleteItem(), deleteitem); } void ItemContextTest::shouldAssignCollection() { Akonadi::Item item(42); Akonadi::Collection col(12); MailCommon::ItemContext itemContext(item, true); itemContext.setMoveTargetCollection(col); QCOMPARE(itemContext.item(), item); QCOMPARE(itemContext.moveTargetCollection(), col); } QTEST_MAIN(ItemContextTest) diff --git a/src/filter/autotests/mailfiltertest.cpp b/src/filter/autotests/mailfiltertest.cpp index b86478f..18d8549 100644 --- a/src/filter/autotests/mailfiltertest.cpp +++ b/src/filter/autotests/mailfiltertest.cpp @@ -1,59 +1,59 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mailfiltertest.h" #include "../mailfilter.h" -#include +#include MailFilterTest::MailFilterTest(QObject *parent) : QObject(parent) { } MailFilterTest::~MailFilterTest() { } void MailFilterTest::shouldHaveDefaultValue() { MailCommon::MailFilter mailfilter; QVERIFY(mailfilter.isEmpty()); QVERIFY(mailfilter.isEnabled()); QVERIFY(mailfilter.applyOnInbound()); QVERIFY(!mailfilter.applyBeforeOutbound()); QVERIFY(mailfilter.applyOnExplicit()); QVERIFY(mailfilter.stopProcessingHere()); QVERIFY(!mailfilter.configureShortcut()); QVERIFY(!mailfilter.configureToolbar()); QVERIFY(mailfilter.isAutoNaming()); QCOMPARE(mailfilter.applicability(), MailCommon::MailFilter::All); QVERIFY(mailfilter.actions()->isEmpty()); QVERIFY(mailfilter.icon().isEmpty()); } void MailFilterTest::shouldApplySettings() { MailCommon::MailFilter mailfilter; bool value = true; mailfilter.setApplyBeforeOutbound(value); QCOMPARE(mailfilter.applyBeforeOutbound(), value); value = false; mailfilter.setApplyBeforeOutbound(value); QCOMPARE(mailfilter.applyBeforeOutbound(), value); } QTEST_MAIN(MailFilterTest) diff --git a/src/filter/invalidfilters/invalidfilterlistitemdelegate.cpp b/src/filter/invalidfilters/invalidfilterlistitemdelegate.cpp index bf4d06e..1e9135c 100644 --- a/src/filter/invalidfilters/invalidfilterlistitemdelegate.cpp +++ b/src/filter/invalidfilters/invalidfilterlistitemdelegate.cpp @@ -1,101 +1,101 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "invalidfilterlistitemdelegate.h" #include "invalidfilterlistmodel.h" #include #include #include #include #include -#include +#include using namespace MailCommon; InvalidFilterListItemDelegate::InvalidFilterListItemDelegate(QAbstractItemView *itemView, QObject *parent) : KWidgetItemDelegate(itemView, parent) { } InvalidFilterListItemDelegate::~InvalidFilterListItemDelegate() { } QSize InvalidFilterListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(index); const QStyle *style = itemView()->style(); const int buttonHeight = style->pixelMetric(QStyle::PM_ButtonMargin) * 2 +style->pixelMetric(QStyle::PM_ButtonIconSize); const int fontHeight = option.fontMetrics.height(); return QSize(100, qMax(buttonHeight, fontHeight)); } void InvalidFilterListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(index); painter->save(); itemView()->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter); if (option.state & QStyle::State_Selected) { painter->setPen(option.palette.highlightedText().color()); } painter->restore(); } QList InvalidFilterListItemDelegate::createItemWidgets(const QModelIndex &) const { QLabel *label = new QLabel(); QToolButton *showInformationToolButton = new QToolButton(); connect(showInformationToolButton, &QAbstractButton::clicked, this, &InvalidFilterListItemDelegate::slotShowDetails); return QList() << label << showInformationToolButton; } void InvalidFilterListItemDelegate::updateItemWidgets(const QList widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const { QLabel *label = static_cast(widgets[0]); const QAbstractItemModel *model = index.model(); label->setText(model->data(index).toString()); const QString details = model->data(index, InvalidFilterListModel::InformationRole).toString(); QToolButton *showInformationToolButton = static_cast(widgets[1]); showInformationToolButton->setEnabled(!details.isEmpty()); const int itemHeight = sizeHint(option, index).height(); showInformationToolButton->setIcon(QIcon::fromTheme(QStringLiteral("help-hint"))); showInformationToolButton->resize(showInformationToolButton->sizeHint()); showInformationToolButton->move(option.rect.right() - showInformationToolButton->width(), (itemHeight - showInformationToolButton->height()) / 2); int labelWidth = option.rect.width(); labelWidth -= showInformationToolButton->sizeHint().width(); label->resize(labelWidth, label->sizeHint().height()); label->move(0, (itemHeight - label->height()) / 2); } void InvalidFilterListItemDelegate::slotShowDetails() { const QAbstractItemModel *model = focusedIndex().model(); const QString information = model->data(focusedIndex(), InvalidFilterListModel::InformationRole).toString(); if (!information.isEmpty()) { Q_EMIT showDetails(information); } } diff --git a/src/filter/kmfilterlistbox.cpp b/src/filter/kmfilterlistbox.cpp index b44df34..21439b4 100644 --- a/src/filter/kmfilterlistbox.cpp +++ b/src/filter/kmfilterlistbox.cpp @@ -1,887 +1,887 @@ /* Copyright (c) 2014-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "kmfilterlistbox.h" #include "mailfilter.h" #include "filtermanager.h" #include "filteractions/filteractiondict.h" #include #include "invalidfilters/invalidfilterinfo.h" #include "invalidfilters/invalidfilterdialog.h" #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include "mailcommon_debug.h" #include #include // What's this help texts const char _wt_filterlist[] = I18N_NOOP("

This is the list of defined filters. " "They are processed top-to-bottom.

" "

Click on any filter to edit it " "using the controls in the right-hand half " "of the dialog.

"); const char _wt_filterlist_new[] = I18N_NOOP("

Click this button to create a new filter.

" "

The filter will be inserted just before the currently-" "selected one, but you can always change that " "later on.

" "

If you have clicked this button accidentally, you can undo this " "by clicking on the Delete button.

"); const char _wt_filterlist_copy[] = I18N_NOOP("

Click this button to copy a filter.

" "

If you have clicked this button accidentally, you can undo this " "by clicking on the Delete button.

"); const char _wt_filterlist_delete[] = I18N_NOOP("

Click this button to delete the currently-" "selected filter from the list above.

" "

There is no way to get the filter back once " "it is deleted, but you can always leave the " "dialog by clicking Cancel to discard the " "changes made.

"); const char _wt_filterlist_up[] = I18N_NOOP("

Click this button to move the currently-" "selected filter up one in the list above.

" "

This is useful since the order of the filters in the list " "determines the order in which they are tried on messages: " "The topmost filter gets tried first.

" "

If you have clicked this button accidentally, you can undo this " "by clicking on the Down button.

"); const char _wt_filterlist_down[] = I18N_NOOP("

Click this button to move the currently-" "selected filter down one in the list above.

" "

This is useful since the order of the filters in the list " "determines the order in which they are tried on messages: " "The topmost filter gets tried first.

" "

If you have clicked this button accidentally, you can undo this " "by clicking on the Up button.

"); const char _wt_filterlist_top[] = I18N_NOOP("

Click this button to move the currently-" "selected filter to top of list.

" "

This is useful since the order of the filters in the list " "determines the order in which they are tried on messages: " "The topmost filter gets tried first.

"); const char _wt_filterlist_bottom[] = I18N_NOOP("

Click this button to move the currently-" "selected filter to bottom of list.

" "

This is useful since the order of the filters in the list " "determines the order in which they are tried on messages: " "The topmost filter gets tried first.

"); const char _wt_filterlist_rename[] = I18N_NOOP("

Click this button to rename the currently-selected filter.

" "

Filters are named automatically, as long as they start with " "\"<\".

" "

If you have renamed a filter accidentally and want automatic " "naming back, click this button and select Clear followed " "by OK in the appearing dialog.

"); //============================================================================= // // class KMFilterListBox (the filter list manipulator) // //============================================================================= using namespace MailCommon; KMFilterListBox::KMFilterListBox(const QString &title, QWidget *parent) : QGroupBox(title, parent) { QVBoxLayout *layout = new QVBoxLayout(); //----------- the list box mListWidget = new QListWidget(this); mListWidget->setMinimumWidth(150); mListWidget->setWhatsThis(i18n(_wt_filterlist)); mListWidget->setDragDropMode(QAbstractItemView::InternalMove); mListWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); connect(mListWidget->model(), &QAbstractItemModel::rowsMoved, this, &KMFilterListBox::slotRowsMoved); mSearchListWidget = new KListWidgetSearchLine(this, mListWidget); mSearchListWidget->setPlaceholderText( i18nc("@info Displayed grayed-out inside the textbox, verb to search", "Search")); mSearchListWidget->installEventFilter(this); layout->addWidget(mSearchListWidget); layout->addWidget(mListWidget); //----------- the first row of buttons QWidget *hb = new QWidget(this); QHBoxLayout *hbHBoxLayout = new QHBoxLayout(hb); hbHBoxLayout->setContentsMargins(0, 0, 0, 0); hbHBoxLayout->setSpacing(4); mBtnTop = new QPushButton(QString(), hb); hbHBoxLayout->addWidget(mBtnTop); mBtnTop->setIcon(QIcon::fromTheme(QStringLiteral("go-top"))); mBtnTop->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall)); mBtnTop->setMinimumSize(mBtnTop->sizeHint() * 1.2); mBtnUp = new QPushButton(QString(), hb); hbHBoxLayout->addWidget(mBtnUp); mBtnUp->setAutoRepeat(true); mBtnUp->setIcon(QIcon::fromTheme(QStringLiteral("go-up"))); mBtnUp->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall)); mBtnUp->setMinimumSize(mBtnUp->sizeHint() * 1.2); mBtnDown = new QPushButton(QString(), hb); hbHBoxLayout->addWidget(mBtnDown); mBtnDown->setAutoRepeat(true); mBtnDown->setIcon(QIcon::fromTheme(QStringLiteral("go-down"))); mBtnDown->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall)); mBtnDown->setMinimumSize(mBtnDown->sizeHint() * 1.2); mBtnBottom = new QPushButton(QString(), hb); hbHBoxLayout->addWidget(mBtnBottom); mBtnBottom->setIcon(QIcon::fromTheme(QStringLiteral("go-bottom"))); mBtnBottom->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall)); mBtnBottom->setMinimumSize(mBtnBottom->sizeHint() * 1.2); mBtnUp->setToolTip(i18nc("Move selected filter up.", "Up")); mBtnDown->setToolTip(i18nc("Move selected filter down.", "Down")); mBtnTop->setToolTip(i18nc("Move selected filter to the top.", "Top")); mBtnBottom->setToolTip(i18nc("Move selected filter to the bottom.", "Bottom")); mBtnUp->setWhatsThis(i18n(_wt_filterlist_up)); mBtnDown->setWhatsThis(i18n(_wt_filterlist_down)); mBtnBottom->setWhatsThis(i18n(_wt_filterlist_bottom)); mBtnTop->setWhatsThis(i18n(_wt_filterlist_top)); layout->addWidget(hb); //----------- the second row of buttons hb = new QWidget(this); hbHBoxLayout = new QHBoxLayout(hb); hbHBoxLayout->setContentsMargins(0, 0, 0, 0); hbHBoxLayout->setSpacing(4); mBtnNew = new QPushButton(hb); hbHBoxLayout->addWidget(mBtnNew); mBtnNew->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); mBtnNew->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall)); mBtnNew->setMinimumSize(mBtnNew->sizeHint() * 1.2); mBtnCopy = new QPushButton(hb); hbHBoxLayout->addWidget(mBtnCopy); mBtnCopy->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy"))); mBtnCopy->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall)); mBtnCopy->setMinimumSize(mBtnCopy->sizeHint() * 1.2); mBtnDelete = new QPushButton(hb); hbHBoxLayout->addWidget(mBtnDelete); mBtnDelete->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete"))); mBtnDelete->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall)); mBtnDelete->setMinimumSize(mBtnDelete->sizeHint() * 1.2); mBtnRename = new QPushButton(hb); mBtnRename->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); mBtnRename->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall)); mBtnRename->setMinimumSize(mBtnDelete->sizeHint() * 1.2); hbHBoxLayout->addWidget(mBtnRename); mBtnNew->setToolTip(i18nc("@action:button in filter list manipulator", "New")); mBtnCopy->setToolTip(i18n("Copy")); mBtnDelete->setToolTip(i18n("Delete")); mBtnRename->setToolTip(i18n("Rename")); mBtnNew->setWhatsThis(i18n(_wt_filterlist_new)); mBtnCopy->setWhatsThis(i18n(_wt_filterlist_copy)); mBtnDelete->setWhatsThis(i18n(_wt_filterlist_delete)); mBtnRename->setWhatsThis(i18n(_wt_filterlist_rename)); layout->addWidget(hb); setLayout(layout); QShortcut *shortcut = new QShortcut(this); shortcut->setKey(Qt::Key_Delete); connect(shortcut, &QShortcut::activated, this, &KMFilterListBox::slotDelete); //----------- now connect everything connect(mListWidget, &QListWidget::currentRowChanged, this, &KMFilterListBox::slotSelected); connect(mListWidget, &QListWidget::itemDoubleClicked, this, &KMFilterListBox::slotRename); connect(mListWidget, &QListWidget::itemChanged, this, &KMFilterListBox::slotFilterEnabledChanged); connect(mListWidget, &QListWidget::itemSelectionChanged, this, &KMFilterListBox::slotSelectionChanged); connect(mBtnUp, &QPushButton::clicked, this, &KMFilterListBox::slotUp); connect(mBtnDown, &QPushButton::clicked, this, &KMFilterListBox::slotDown); connect(mBtnTop, &QPushButton::clicked, this, &KMFilterListBox::slotTop); connect(mBtnBottom, &QPushButton::clicked, this, &KMFilterListBox::slotBottom); connect(mBtnNew, &QPushButton::clicked, this, &KMFilterListBox::slotNew); connect(mBtnCopy, &QPushButton::clicked, this, &KMFilterListBox::slotCopy); connect(mBtnDelete, &QPushButton::clicked, this, &KMFilterListBox::slotDelete); connect(mBtnRename, &QPushButton::clicked, this, &KMFilterListBox::slotRename); // the dialog should call loadFilterList() // when all signals are connected. enableControls(); } KMFilterListBox::~KMFilterListBox() { } bool KMFilterListBox::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::KeyPress && obj == mSearchListWidget) { QKeyEvent *key = static_cast(event); if ((key->key() == Qt::Key_Enter) || (key->key() == Qt::Key_Return)) { event->accept(); return true; } } return QGroupBox::eventFilter(obj, event); } bool KMFilterListBox::itemIsValid(QListWidgetItem *item) const { if (!item) { qCDebug(MAILCOMMON_LOG) << "Called while no filter is selected, ignoring."; return false; } if (item->isHidden()) { return false; } return true; } void KMFilterListBox::slotFilterEnabledChanged(QListWidgetItem *item) { if (!item) { qCDebug(MAILCOMMON_LOG) << "Called while no filter is selected, ignoring."; return; } QListWidgetFilterItem *itemFilter = static_cast(item); MailCommon::MailFilter *filter = itemFilter->filter(); filter->setEnabled((item->checkState() == Qt::Checked)); Q_EMIT filterUpdated(filter); } void KMFilterListBox::slotRowsMoved(const QModelIndex &, int sourcestart, int sourceEnd, const QModelIndex &, int destinationRow) { Q_UNUSED(sourceEnd); Q_UNUSED(sourcestart); Q_UNUSED(destinationRow); enableControls(); Q_EMIT filterOrderAltered(); } void KMFilterListBox::createFilter(const QByteArray &field, const QString &value) { SearchRule::Ptr newRule = SearchRule::createInstance(field, SearchRule::FuncContains, value); MailFilter *newFilter = new MailFilter(); newFilter->pattern()->append(newRule); newFilter->pattern()->setName(QStringLiteral("<%1>: %2"). arg(QString::fromLatin1(field)). arg(value)); FilterActionDesc *desc = MailCommon::FilterManager::filterActionDict()->value(QStringLiteral("transfer")); if (desc) { newFilter->actions()->append(desc->create()); } insertFilter(newFilter); enableControls(); } void KMFilterListBox::slotUpdateFilterName() { QListWidgetItem *item = mListWidget->currentItem(); if (!item) { qCDebug(MAILCOMMON_LOG) << "Called while no filter is selected, ignoring."; return; } QListWidgetFilterItem *itemFilter = static_cast(item); MailCommon::MailFilter *filter = itemFilter->filter(); SearchPattern *p = filter->pattern(); if (!p) { return; } QString shouldBeName = p->name(); QString displayedName = itemFilter->text(); if (shouldBeName.trimmed().isEmpty()) { filter->setAutoNaming(true); } if (filter->isAutoNaming()) { // auto-naming of patterns if (!p->isEmpty() && p->first() && !p->first()->field().trimmed().isEmpty()) { shouldBeName = QStringLiteral("<%1>: %2"). arg(QString::fromLatin1(p->first()->field())). arg(p->first()->contents()); } else { shouldBeName = QLatin1Char('<') + i18n("unnamed") + QLatin1Char('>'); } p->setName(shouldBeName); } if (displayedName == shouldBeName) { return; } filter->setToolbarName(shouldBeName); mListWidget->blockSignals(true); itemFilter->setText(shouldBeName); mListWidget->blockSignals(false); } void KMFilterListBox::slotAccepted() { applyFilterChanged(true); } void KMFilterListBox::slotApplied() { applyFilterChanged(false); } void KMFilterListBox::applyFilterChanged(bool closeAfterSaving) { if (mListWidget->currentItem()) { Q_EMIT applyWidgets(); slotSelected(mListWidget->currentRow()); } // by now all edit widgets should have written back // their widget's data into our filter list. bool wasCanceled = false; const QList newFilters = filtersForSaving(closeAfterSaving, wasCanceled); if (!wasCanceled) { MailCommon::FilterManager::instance()->setFilters(newFilters); } } QList KMFilterListBox::filtersForSaving(bool closeAfterSaving, bool &wasCanceled) const { Q_EMIT const_cast(this)->applyWidgets(); // signals aren't const QList filters; QStringList emptyFilters; QVector listInvalidFilters; const int numberOfFilter(mListWidget->count()); for (int i = 0; i < numberOfFilter; ++i) { QListWidgetFilterItem *itemFilter = static_cast(mListWidget->item(i)); MailFilter *f = new MailFilter(*itemFilter->filter()); // deep copy const QString information = f->purify(); if (!f->isEmpty() && information.isEmpty()) { // the filter is valid: filters.append(f); } else { // the filter is invalid: emptyFilters << f->name(); listInvalidFilters.append(MailCommon::InvalidFilterInfo(f->name(), information)); delete f; } } // report on invalid filters: if (!emptyFilters.empty()) { QPointer dlg = new MailCommon::InvalidFilterDialog(nullptr); dlg->setInvalidFilters(listInvalidFilters); if (!dlg->exec()) { if (closeAfterSaving) { Q_EMIT abortClosing(); } wasCanceled = true; } delete dlg; } return filters; } void KMFilterListBox::slotSelectionChanged() { if (mListWidget->selectedItems().count() > 1) { Q_EMIT resetWidgets(); } enableControls(); } void KMFilterListBox::slotSelected(int aIdx) { if (aIdx >= 0 && aIdx < mListWidget->count()) { QListWidgetFilterItem *itemFilter = static_cast(mListWidget->item(aIdx)); MailFilter *f = itemFilter->filter(); if (f) { Q_EMIT filterSelected(f); } else { Q_EMIT resetWidgets(); } } else { Q_EMIT resetWidgets(); } enableControls(); } void KMFilterListBox::slotNew() { QListWidgetItem *item = mListWidget->currentItem(); if (item && item->isHidden()) { return; } // just insert a new filter. insertFilter(new MailFilter()); enableControls(); } void KMFilterListBox::slotCopy() { QListWidgetItem *item = mListWidget->currentItem(); if (!itemIsValid(item)) { return; } // make sure that all changes are written to the filter before we copy it Q_EMIT applyWidgets(); QListWidgetFilterItem *itemFilter = static_cast(item); MailFilter *filter = itemFilter->filter(); // enableControls should make sure this method is // never called when no filter is selected. Q_ASSERT(filter); // inserts a copy of the current filter. MailFilter *copyFilter = new MailFilter(*filter); copyFilter->generateRandomIdentifier(); copyFilter->setShortcut(QKeySequence()); insertFilter(copyFilter); enableControls(); } void KMFilterListBox::slotDelete() { QListWidgetItem *itemFirst = mListWidget->currentItem(); if (!itemIsValid(itemFirst)) { return; } const bool uniqFilterSelected = (mListWidget->selectedItems().count() == 1); QListWidgetFilterItem *itemFilter = static_cast(itemFirst); MailCommon::MailFilter *filter = itemFilter->filter(); const QString filterName = filter->pattern()->name(); if (uniqFilterSelected) { if (KMessageBox::questionYesNo( this, i18n("Do you want to remove the filter \"%1\"?", filterName), i18n("Remove Filter")) == KMessageBox::No) { return; } } else { if (KMessageBox::questionYesNo( this, i18n("Do you want to remove selected filters?"), i18n("Remove Filters")) == KMessageBox::No) { return; } } const int oIdxSelItem = mListWidget->currentRow(); QList lst; Q_EMIT resetWidgets(); const QList lstItems = mListWidget->selectedItems(); for (QListWidgetItem *item : lstItems) { QListWidgetFilterItem *itemFilter = static_cast(item); MailCommon::MailFilter *filter = itemFilter->filter(); lst << filter; // remove the filter from both the listbox QListWidgetItem *item2 = mListWidget->takeItem(mListWidget->row(item)); delete item2; } const int count = mListWidget->count(); // and set the new current item. if (count > oIdxSelItem) { // oIdxItem is still a valid index mListWidget->setCurrentRow(oIdxSelItem); } else if (count) { // oIdxSelIdx is no longer valid, but the // list box isn't empty mListWidget->setCurrentRow(count - 1); } // work around a problem when deleting the first item in a QListWidget: // after takeItem, slotSelectionChanged is emitted with 1, but the row 0 // remains selected and another selectCurrentRow(0) does not trigger the // selectionChanged signal // (qt-copy as of 2006-12-22 / gungl) if (oIdxSelItem == 0) { slotSelected(0); } enableControls(); Q_EMIT filterRemoved(lst); } void KMFilterListBox::slotTop() { QList listWidgetItem = selectedFilter(); if (listWidgetItem.isEmpty()) { return; } const int numberOfItem(listWidgetItem.count()); if ((numberOfItem == 1) && (mListWidget->currentRow() == 0)) { qCDebug(MAILCOMMON_LOG) << "Called while the _topmost_ filter is selected, ignoring."; return; } QListWidgetItem *item = nullptr; bool wasMoved = false; for (int i = 0; i < numberOfItem; ++i) { const int posItem = mListWidget->row(listWidgetItem.at(i)); if (posItem == i) { continue; } item = mListWidget->takeItem(mListWidget->row(listWidgetItem.at(i))); mListWidget->insertItem(i, item); wasMoved = true; } if (wasMoved) { enableControls(); Q_EMIT filterOrderAltered(); } } QList KMFilterListBox::selectedFilter() { QList listWidgetItem; const int numberOfFilters = mListWidget->count(); for (int i = 0; i < numberOfFilters; ++i) { if (mListWidget->item(i)->isSelected() && !mListWidget->item(i)->isHidden()) { listWidgetItem << mListWidget->item(i); } } return listWidgetItem; } QStringList KMFilterListBox::selectedFilterId(SearchRule::RequiredPart &requiredPart, const QString &resource) const { QStringList listFilterId; requiredPart = SearchRule::Envelope; const int numberOfFilters = mListWidget->count(); for (int i = 0; i < numberOfFilters; ++i) { if (mListWidget->item(i)->isSelected() && !mListWidget->item(i)->isHidden()) { MailFilter *filter = static_cast(mListWidget->item(i))->filter(); if (!filter->isEmpty()) { const QString id = filter->identifier(); listFilterId << id; requiredPart = qMax(requiredPart, static_cast(mListWidget->item(i))->filter()->requiredPart(resource)); } } } return listFilterId; } void KMFilterListBox::slotBottom() { const QList listWidgetItem = selectedFilter(); if (listWidgetItem.isEmpty()) { return; } const int numberOfElement(mListWidget->count()); const int numberOfItem(listWidgetItem.count()); if ((numberOfItem == 1) && (mListWidget->currentRow() == numberOfElement - 1)) { qCDebug(MAILCOMMON_LOG) << "Called while the _last_ filter is selected, ignoring."; return; } QListWidgetItem *item = nullptr; int j = 0; bool wasMoved = false; for (int i = numberOfItem - 1; i >= 0; --i, j++) { const int posItem = mListWidget->row(listWidgetItem.at(i)); if (posItem == (numberOfElement - 1 - j)) { continue; } item = mListWidget->takeItem(mListWidget->row(listWidgetItem.at(i))); mListWidget->insertItem(numberOfElement - j, item); wasMoved = true; } if (wasMoved) { enableControls(); Q_EMIT filterOrderAltered(); } } void KMFilterListBox::slotUp() { const QList listWidgetItem = selectedFilter(); if (listWidgetItem.isEmpty()) { return; } const int numberOfItem(listWidgetItem.count()); if ((numberOfItem == 1) && (mListWidget->currentRow() == 0)) { qCDebug(MAILCOMMON_LOG) << "Called while the _topmost_ filter is selected, ignoring."; return; } bool wasMoved = false; for (int i = 0; i < numberOfItem; ++i) { const int posItem = mListWidget->row(listWidgetItem.at(i)); if (posItem == i) { continue; } swapNeighbouringFilters(posItem, posItem - 1); wasMoved = true; } if (wasMoved) { enableControls(); Q_EMIT filterOrderAltered(); } } void KMFilterListBox::slotDown() { const QList listWidgetItem = selectedFilter(); if (listWidgetItem.isEmpty()) { return; } const int numberOfElement(mListWidget->count()); const int numberOfItem(listWidgetItem.count()); if ((numberOfItem == 1) && (mListWidget->currentRow() == numberOfElement - 1)) { qCDebug(MAILCOMMON_LOG) << "Called while the _last_ filter is selected, ignoring."; return; } int j = 0; bool wasMoved = false; for (int i = numberOfItem - 1; i >= 0; --i, j++) { const int posItem = mListWidget->row(listWidgetItem.at(i)); if (posItem == (numberOfElement - 1 - j)) { continue; } swapNeighbouringFilters(posItem, posItem + 1); wasMoved = true; } if (wasMoved) { enableControls(); Q_EMIT filterOrderAltered(); } } void KMFilterListBox::slotRename() { QListWidgetItem *item = mListWidget->currentItem(); if (!itemIsValid(item)) { return; } QListWidgetFilterItem *itemFilter = static_cast(item); bool okPressed = false; MailFilter *filter = itemFilter->filter(); // enableControls should make sure this method is // never called when no filter is selected. Q_ASSERT(filter); // allow empty names - those will turn auto-naming on again QString newName = QInputDialog::getText(window(), i18n("Rename Filter"), i18n("Rename filter \"%1\" to:\n(leave the field empty for automatic naming)", filter->pattern()->name()), /*label*/ QLineEdit::Normal, filter->pattern()->name(), /* initial value */ &okPressed); if (!okPressed) { return; } if (newName.isEmpty()) { // bait for slotUpdateFilterName to // use automatic naming again. filter->pattern()->setName(QStringLiteral("<>")); filter->setAutoNaming(true); } else { filter->pattern()->setName(newName); filter->setAutoNaming(false); } slotUpdateFilterName(); Q_EMIT filterUpdated(filter); } void KMFilterListBox::enableControls() { const int currentIndex = mListWidget->currentRow(); const bool theFirst = (currentIndex == 0); const int numberOfElement(mListWidget->count()); const bool theLast = (currentIndex >= numberOfElement - 1); const bool aFilterIsSelected = (currentIndex >= 0); const int numberOfSelectedItem(mListWidget->selectedItems().count()); const bool uniqFilterSelected = (numberOfSelectedItem == 1); const bool allItemSelected = (numberOfSelectedItem == numberOfElement); mBtnUp->setEnabled(aFilterIsSelected && ((uniqFilterSelected && !theFirst) || (!uniqFilterSelected)) && !allItemSelected); mBtnDown->setEnabled(aFilterIsSelected && ((uniqFilterSelected && !theLast) || (!uniqFilterSelected)) && !allItemSelected); mBtnCopy->setEnabled(aFilterIsSelected && uniqFilterSelected); mBtnDelete->setEnabled(aFilterIsSelected); mBtnRename->setEnabled(aFilterIsSelected && uniqFilterSelected); mBtnTop->setEnabled(aFilterIsSelected && ((uniqFilterSelected && !theFirst) || (!uniqFilterSelected)) && !allItemSelected); mBtnBottom->setEnabled(aFilterIsSelected && ((uniqFilterSelected && !theLast) || (!uniqFilterSelected)) && !allItemSelected); if (aFilterIsSelected) { mListWidget->scrollToItem(mListWidget->currentItem()); } } void KMFilterListBox::loadFilterList(bool createDummyFilter) { Q_ASSERT(mListWidget); setEnabled(false); Q_EMIT resetWidgets(); // we don't want the insertion to // cause flicker in the edit widgets. blockSignals(true); // clear both lists mListWidget->clear(); const QList filters = MailCommon::FilterManager::instance()->filters(); for (MailFilter *filter : filters) { QListWidgetFilterItem *item = new QListWidgetFilterItem(filter->pattern()->name(), mListWidget); item->setFilter(new MailFilter(*filter)); mListWidget->addItem(item); } blockSignals(false); setEnabled(true); // create an empty filter when there's none, to avoid a completely // disabled dialog (usability tests indicated that the new-filter // button is too hard to find that way): const int numberOfItem(mListWidget->count()); if (numberOfItem == 0) { if (createDummyFilter) { slotNew(); } } else { mListWidget->setCurrentRow(0); } enableControls(); } void KMFilterListBox::insertFilter(MailFilter *aFilter) { // must be really a filter... Q_ASSERT(aFilter); const int currentIndex = mListWidget->currentRow(); // if mIdxSelItem < 0, QListBox::insertItem will append. QListWidgetFilterItem *item = new QListWidgetFilterItem(aFilter->pattern()->name()); item->setFilter(aFilter); mListWidget->insertItem(currentIndex, item); mListWidget->clearSelection(); if (currentIndex < 0) { mListWidget->setCurrentRow(mListWidget->count() - 1); } else { // insert just before selected mListWidget->setCurrentRow(currentIndex); } Q_EMIT filterCreated(); Q_EMIT filterOrderAltered(); } void KMFilterListBox::appendFilter(MailFilter *aFilter) { QListWidgetFilterItem *item = new QListWidgetFilterItem(aFilter->pattern()->name(), mListWidget); item->setFilter(aFilter); mListWidget->addItem(item); Q_EMIT filterCreated(); } void KMFilterListBox::swapNeighbouringFilters(int untouchedOne, int movedOne) { // must be neighbours... Q_ASSERT(untouchedOne - movedOne == 1 || movedOne - untouchedOne == 1); // untouchedOne is at idx. to move it down(up), // remove item at idx+(-)1 w/o deleting it. QListWidgetItem *item = mListWidget->takeItem(movedOne); // now selected item is at idx(idx-1), so // insert the other item at idx, ie. above(below). mListWidget->insertItem(untouchedOne, item); } QListWidgetFilterItem::QListWidgetFilterItem(const QString &text, QListWidget *parent) : QListWidgetItem(text, parent) , mFilter(nullptr) { } QListWidgetFilterItem::~QListWidgetFilterItem() { delete mFilter; } void QListWidgetFilterItem::setFilter(MailCommon::MailFilter *filter) { mFilter = filter; setCheckState(filter->isEnabled() ? Qt::Checked : Qt::Unchecked); } MailCommon::MailFilter *QListWidgetFilterItem::filter() { return mFilter; } diff --git a/src/filter/tests/filterimporterexportergui.cpp b/src/filter/tests/filterimporterexportergui.cpp index f9d58f1..49dd788 100644 --- a/src/filter/tests/filterimporterexportergui.cpp +++ b/src/filter/tests/filterimporterexportergui.cpp @@ -1,118 +1,118 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filterimporterexportergui.h" #include "filter/filterimporterexporter.h" #include "filter/mailfilter.h" -#include +#include #include #include -#include +#include #include Q_DECLARE_METATYPE(MailCommon::FilterImporterExporter::FilterType) FilterImporterExporterGui::FilterImporterExporterGui(QWidget *parent) : QWidget(parent) { QVBoxLayout *mainLayout = new QVBoxLayout(this); QMenuBar *menuBar = new QMenuBar(this); mainLayout->addWidget(menuBar); QMenu *menuFilter = menuBar->addMenu(QStringLiteral("filter")); QAction *act = new QAction(QStringLiteral("KMail filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::KMailFilter)); menuFilter->addAction(act); act = new QAction(QStringLiteral("Thunderbird filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::ThunderBirdFilter)); menuFilter->addAction(act); act = new QAction(QStringLiteral("Evolution filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::EvolutionFilter)); menuFilter->addAction(act); act = new QAction(QStringLiteral("Sylpheed filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::SylpheedFilter)); menuFilter->addAction(act); act = new QAction(QStringLiteral("Procmail filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::ProcmailFilter)); menuFilter->addAction(act); act = new QAction(QStringLiteral("Balsa filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::BalsaFilter)); menuFilter->addAction(act); act = new QAction(QStringLiteral("Claws Mail filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::ClawsMailFilter)); menuFilter->addAction(act); act = new QAction(QStringLiteral("Icedove Mail filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::IcedoveFilter)); menuFilter->addAction(act); act = new QAction(QStringLiteral("GMail filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::GmailFilter)); menuFilter->addAction(act); connect(menuFilter, QOverload::of(&QMenu::triggered), this, &FilterImporterExporterGui::slotImportFilter); mTextEdit = new QTextEdit; mTextEdit->setReadOnly(true); mainLayout->addWidget(mTextEdit); } FilterImporterExporterGui::~FilterImporterExporterGui() { } void FilterImporterExporterGui::slotImportFilter(QAction *act) { if (act) { importFilters(act->data().value()); } } void FilterImporterExporterGui::importFilters(MailCommon::FilterImporterExporter::FilterType type) { MailCommon::FilterImporterExporter importer(this); bool canceled = false; const QList filters = importer.importFilters(canceled, type); if (canceled) { mTextEdit->setText(QStringLiteral("Canceled")); return; } QString result; for (MailCommon::MailFilter *filter : filters) { if (!result.isEmpty()) { result += QLatin1Char('\n'); } result += filter->asString(); } mTextEdit->setText(result); } int main(int argc, char **argv) { QApplication app(argc, argv); FilterImporterExporterGui *w = new FilterImporterExporterGui(); w->resize(800, 600); w->show(); app.exec(); delete w; return 0; } diff --git a/src/mdn/autotests/mdnstateattributetest.cpp b/src/mdn/autotests/mdnstateattributetest.cpp index c506457..7014990 100644 --- a/src/mdn/autotests/mdnstateattributetest.cpp +++ b/src/mdn/autotests/mdnstateattributetest.cpp @@ -1,65 +1,65 @@ /* Copyright (c) 2014-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mdnstateattributetest.h" #include "../mdnstateattribute.h" -#include +#include MDNStateAttributeTest::MDNStateAttributeTest(QObject *parent) : QObject(parent) { } MDNStateAttributeTest::~MDNStateAttributeTest() { } void MDNStateAttributeTest::shouldHaveDefaultValue() { MailCommon::MDNStateAttribute attr; QCOMPARE(attr.mdnState(), MailCommon::MDNStateAttribute::MDNStateUnknown); } void MDNStateAttributeTest::shouldHaveType() { MailCommon::MDNStateAttribute attr; QCOMPARE(attr.type(), QByteArray("MDNStateAttribute")); } void MDNStateAttributeTest::shouldSerializedAttribute() { MailCommon::MDNStateAttribute attr; attr.setMDNState(MailCommon::MDNStateAttribute::MDNDenied); QCOMPARE(attr.mdnState(), MailCommon::MDNStateAttribute::MDNDenied); const QByteArray ba = attr.serialized(); MailCommon::MDNStateAttribute result; result.deserialize(ba); QVERIFY(attr == result); } void MDNStateAttributeTest::shouldCloneAttribute() { MailCommon::MDNStateAttribute attr; attr.setMDNState(MailCommon::MDNStateAttribute::MDNDenied); MailCommon::MDNStateAttribute *result = attr.clone(); QVERIFY(attr == *result); delete result; } QTEST_MAIN(MDNStateAttributeTest) diff --git a/src/search/autotests/searchpatterntest.cpp b/src/search/autotests/searchpatterntest.cpp index ee0233b..e574374 100644 --- a/src/search/autotests/searchpatterntest.cpp +++ b/src/search/autotests/searchpatterntest.cpp @@ -1,82 +1,82 @@ /* Copyright (c) 2015 Tomas Trnka This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "searchpatterntest.h" #include "../searchpattern.h" -#include +#include SearchPatternTest::SearchPatternTest(QObject *parent) : QObject(parent) { } SearchPatternTest::~SearchPatternTest() { } void SearchPatternTest::shouldRuleRequirePart_data() { QTest::addColumn("field"); QTest::addColumn("part"); // SearchRuleStatus QTest::newRow("status") << QByteArray("") << MailCommon::SearchRule::Envelope; // SearchRuleNumerical QTest::newRow("numerical") << QByteArray("") << MailCommon::SearchRule::Envelope; // SearchRuleDate QTest::newRow("date") << QByteArray("") << MailCommon::SearchRule::Envelope; // SearchRuleString QTest::newRow("recipients") << QByteArray("") << MailCommon::SearchRule::Envelope; QTest::newRow("tag") << QByteArray("") << MailCommon::SearchRule::Envelope; QTest::newRow("subject") << QByteArray("subject") << MailCommon::SearchRule::Envelope; QTest::newRow("from") << QByteArray("from") << MailCommon::SearchRule::Envelope; QTest::newRow("sender") << QByteArray("sender") << MailCommon::SearchRule::Envelope; QTest::newRow("reply-to") << QByteArray("reply-to") << MailCommon::SearchRule::Envelope; QTest::newRow("to") << QByteArray("to") << MailCommon::SearchRule::Envelope; QTest::newRow("cc") << QByteArray("cc") << MailCommon::SearchRule::Envelope; QTest::newRow("bcc") << QByteArray("bcc") << MailCommon::SearchRule::Envelope; QTest::newRow("in-reply-to") << QByteArray("in-reply-to") << MailCommon::SearchRule::Envelope; QTest::newRow("message-id") << QByteArray("message-id") << MailCommon::SearchRule::Envelope; QTest::newRow("references") << QByteArray("references") << MailCommon::SearchRule::Envelope; QTest::newRow("any header") << QByteArray("") << MailCommon::SearchRule::Header; QTest::newRow("custom header") << QByteArray("X-DummyHeaderName") << MailCommon::SearchRule::Header; QTest::newRow("Organization") << QByteArray("Organization") << MailCommon::SearchRule::Header; QTest::newRow("List-Id") << QByteArray("List-Id") << MailCommon::SearchRule::Header; QTest::newRow("Resent-From") << QByteArray("Resent-From") << MailCommon::SearchRule::Header; QTest::newRow("X-Loop") << QByteArray("X-Loop") << MailCommon::SearchRule::Header; QTest::newRow("X-Mailing-List") << QByteArray("X-Mailing-List") << MailCommon::SearchRule::Header; QTest::newRow("X-Spam-Flag") << QByteArray("X-Spam-Flag") << MailCommon::SearchRule::Header; QTest::newRow("") << QByteArray("") << MailCommon::SearchRule::CompleteMessage; QTest::newRow("") << QByteArray("") << MailCommon::SearchRule::CompleteMessage; } void SearchPatternTest::shouldRuleRequirePart() { QFETCH(QByteArray, field); QFETCH(MailCommon::SearchRule::RequiredPart, part); const MailCommon::SearchRule::Ptr rule = MailCommon::SearchRule::createInstance(field, MailCommon::SearchRule::FuncNone, QString()); QCOMPARE(rule->requiredPart(), part); } QTEST_MAIN(SearchPatternTest) diff --git a/src/search/autotests/searchruledatetest.cpp b/src/search/autotests/searchruledatetest.cpp index c23e34f..09a4f59 100644 --- a/src/search/autotests/searchruledatetest.cpp +++ b/src/search/autotests/searchruledatetest.cpp @@ -1,95 +1,95 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "searchruledatetest.h" -#include +#include #include "../searchrule/searchruledate.h" #include Q_DECLARE_METATYPE(MailCommon::SearchRule::Function) SearchRuleDateTest::SearchRuleDateTest(QObject *parent) : QObject(parent) { } void SearchRuleDateTest::shouldHaveDefaultValue() { MailCommon::SearchRuleDate searchrule; QCOMPARE(searchrule.field(), QByteArray()); QCOMPARE(searchrule.function(), MailCommon::SearchRule::FuncContains); QVERIFY(searchrule.contents().isEmpty()); QVERIFY(searchrule.isEmpty()); } void SearchRuleDateTest::shouldRequiresPart() { MailCommon::SearchRuleDate searchrule; QCOMPARE(searchrule.requiredPart(), MailCommon::SearchRule::Envelope); } void SearchRuleDateTest::shouldBeEmpty() { MailCommon::SearchRuleDate searchrule("", MailCommon::SearchRule::FuncEquals, QString()); QVERIFY(searchrule.isEmpty()); MailCommon::SearchRuleDate searchrule2("", MailCommon::SearchRule::FuncEquals, QDate(2015, 5, 5).toString(Qt::ISODate)); QVERIFY(!searchrule2.isEmpty()); } void SearchRuleDateTest::shouldMatchDate_data() { QTest::addColumn("function"); QTest::addColumn("maildate"); QTest::addColumn("matchdate"); QTest::addColumn("match"); QTest::newRow("equaldontmatch") << MailCommon::SearchRule::FuncEquals << QDate(2015, 5, 5) << QDate(2015, 5, 6) << false; QTest::newRow("equalmatch") << MailCommon::SearchRule::FuncEquals << QDate(2015, 5, 5) << QDate(2015, 5, 5) << true; QTest::newRow("notequalnotmatch") << MailCommon::SearchRule::FuncNotEqual << QDate(2015, 5, 5) << QDate(2015, 5, 5) << false; QTest::newRow("notequalmatch") << MailCommon::SearchRule::FuncNotEqual << QDate(2015, 5, 5) << QDate(2015, 5, 6) << true; QTest::newRow("isgreatermatch") << MailCommon::SearchRule::FuncIsGreater << QDate(2015, 5, 5) << QDate(2015, 5, 4) << true; QTest::newRow("isgreaternotmatch") << MailCommon::SearchRule::FuncIsGreater << QDate(2015, 5, 5) << QDate(2015, 5, 6) << false; QTest::newRow("isgreaternotmatchequalvalue") << MailCommon::SearchRule::FuncIsGreater << QDate(2015, 5, 5) << QDate(2015, 5, 5) << false; QTest::newRow("islessorequalmatch") << MailCommon::SearchRule::FuncIsLessOrEqual << QDate(2015, 5, 5) << QDate(2015, 5, 6) << true; QTest::newRow("islessorequalmatch equal") << MailCommon::SearchRule::FuncIsLessOrEqual << QDate(2015, 5, 5) << QDate(2015, 5, 5) << true; QTest::newRow("islessorequalnotmatch") << MailCommon::SearchRule::FuncIsLessOrEqual << QDate(2015, 5, 7) << QDate(2015, 5, 5) << false; QTest::newRow("islessmatch") << MailCommon::SearchRule::FuncIsLess << QDate(2015, 5, 4) << QDate(2015, 5, 5) << true; QTest::newRow("islessnotmatch") << MailCommon::SearchRule::FuncIsLess << QDate(2015, 5, 5) << QDate(2015, 5, 4) << false; QTest::newRow("islessnotmatchequalvalue") << MailCommon::SearchRule::FuncIsLess << QDate(2015, 5, 5) << QDate(2015, 5, 5) << false; QTest::newRow("isgreaterorequalmatch") << MailCommon::SearchRule::FuncIsGreaterOrEqual << QDate(2015, 5, 6) << QDate(2015, 5, 5) << true; QTest::newRow("isgreaterorequalmatch equal") << MailCommon::SearchRule::FuncIsGreaterOrEqual << QDate(2015, 5, 5) << QDate(2015, 5, 5) << true; QTest::newRow("isgreaterorequalnotmatch") << MailCommon::SearchRule::FuncIsGreaterOrEqual << QDate(2015, 5, 5) << QDate(2015, 5, 7) << false; } void SearchRuleDateTest::shouldMatchDate() { QFETCH(MailCommon::SearchRule::Function, function); QFETCH(QDate, maildate); QFETCH(QDate, matchdate); QFETCH(bool, match); MailCommon::SearchRuleDate searchrule("", function, matchdate.toString(Qt::ISODate)); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->date(true)->setDateTime(QDateTime(maildate)); Akonadi::Item item; item.setPayload(msgPtr); QCOMPARE(searchrule.matches(item), match); } QTEST_MAIN(SearchRuleDateTest) diff --git a/src/search/autotests/searchrulenumericaltest.cpp b/src/search/autotests/searchrulenumericaltest.cpp index 922f9b2..41b022d 100644 --- a/src/search/autotests/searchrulenumericaltest.cpp +++ b/src/search/autotests/searchrulenumericaltest.cpp @@ -1,75 +1,75 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "searchrulenumericaltest.h" -#include +#include #include "../searchrule/searchrulenumerical.h" SearchRuleNumericalTest::SearchRuleNumericalTest(QObject *parent) : QObject(parent) { } void SearchRuleNumericalTest::shouldHaveDefaultValue() { MailCommon::SearchRuleNumerical ruleStatus; QVERIFY(ruleStatus.contents().isEmpty()); QVERIFY(ruleStatus.field().isEmpty()); QCOMPARE(ruleStatus.function(), MailCommon::SearchRule::FuncContains); QVERIFY(ruleStatus.isEmpty()); } void SearchRuleNumericalTest::shouldBeEmpty() { MailCommon::SearchRuleNumerical ruleStatus(QByteArray(), MailCommon::SearchRule::FuncContains, QStringLiteral("foo")); QVERIFY(ruleStatus.isEmpty()); ruleStatus = MailCommon::SearchRuleNumerical(QByteArray(), MailCommon::SearchRule::FuncContains, QStringLiteral("0")); QVERIFY(!ruleStatus.isEmpty()); } void SearchRuleNumericalTest::shouldHaveRequirePart() { MailCommon::SearchRuleNumerical ruleStatus; QCOMPARE(ruleStatus.requiredPart(), MailCommon::SearchRule::Envelope); } void SearchRuleNumericalTest::shouldMatchNumericalsize_data() { #if 0 QTest::addColumn("function"); QTest::addColumn("value"); QTest::addColumn("matchvalue"); QTest::addColumn("match"); #endif } void SearchRuleNumericalTest::shouldMatchNumericalsize() { #if 0 QFETCH(MailCommon::SearchRule::Function, function); QFETCH(long, value); QFETCH(long, matchvalue); QFETCH(bool, match); MailCommon::SearchRuleNumerical searchrule("", function, QString::number(value)); KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); msgPtr->date(true)->setDateTime(maildate); Akonadi::Item item; item.setPayload(msgPtr); QCOMPARE(searchrule.matches(item), match); #endif } QTEST_MAIN(SearchRuleNumericalTest) diff --git a/src/search/autotests/searchrulestatustest.cpp b/src/search/autotests/searchrulestatustest.cpp index dc9d4c3..527a755 100644 --- a/src/search/autotests/searchrulestatustest.cpp +++ b/src/search/autotests/searchrulestatustest.cpp @@ -1,63 +1,63 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "searchrulestatustest.h" -#include +#include #include "../searchrule/searchrulestatus.h" SearchRuleStatusTest::SearchRuleStatusTest(QObject *parent) : QObject(parent) { } void SearchRuleStatusTest::shouldHaveDefaultValue() { MailCommon::SearchRuleStatus ruleStatus; QVERIFY(ruleStatus.contents().isEmpty()); QVERIFY(ruleStatus.field().isEmpty()); QCOMPARE(ruleStatus.function(), MailCommon::SearchRule::FuncContains); QVERIFY(ruleStatus.isEmpty()); } void SearchRuleStatusTest::shouldHaveRequirePart() { MailCommon::SearchRuleStatus ruleStatus; QCOMPARE(ruleStatus.requiredPart(), MailCommon::SearchRule::Envelope); } void SearchRuleStatusTest::shouldMatchStatus() { } void SearchRuleStatusTest::shouldMatchStatus_data() { } void SearchRuleStatusTest::shouldBeEmpty() { MailCommon::SearchRuleStatus searchrule; QVERIFY(searchrule.isEmpty()); searchrule = MailCommon::SearchRuleStatus(QByteArray(), MailCommon::SearchRule::FuncContains, QStringLiteral("foo")); QVERIFY(searchrule.isEmpty()); searchrule = MailCommon::SearchRuleStatus(QByteArray(""), MailCommon::SearchRule::FuncContains, QString()); QVERIFY(searchrule.isEmpty()); searchrule = MailCommon::SearchRuleStatus(QByteArray(""), MailCommon::SearchRule::FuncContains, QStringLiteral("foo")); QVERIFY(!searchrule.isEmpty()); } QTEST_MAIN(SearchRuleStatusTest) diff --git a/src/search/autotests/searchrulestringtest.cpp b/src/search/autotests/searchrulestringtest.cpp index 13d6e23..80ee319 100644 --- a/src/search/autotests/searchrulestringtest.cpp +++ b/src/search/autotests/searchrulestringtest.cpp @@ -1,87 +1,87 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "searchrulestringtest.h" -#include +#include #include "../searchrule/searchrulestring.h" SearchRuleStringTest::SearchRuleStringTest(QObject *parent) : QObject(parent) { } void SearchRuleStringTest::shouldHaveDefaultValue() { MailCommon::SearchRuleString searchrule; QCOMPARE(searchrule.function(), MailCommon::SearchRule::FuncContains); QVERIFY(searchrule.isEmpty()); } void SearchRuleStringTest::shouldHaveRequirePart() { QFETCH(QByteArray, field); QFETCH(MailCommon::SearchRule::RequiredPart, requiredpart); MailCommon::SearchRuleString ruleStatus(field); QCOMPARE(ruleStatus.requiredPart(), requiredpart); } void SearchRuleStringTest::shouldHaveRequirePart_data() { QTest::addColumn("field"); QTest::addColumn("requiredpart"); QTest::newRow("recipient") << QByteArray("") << MailCommon::SearchRule::Envelope; QTest::newRow("status") << QByteArray("") << MailCommon::SearchRule::Envelope; QTest::newRow("tag") << QByteArray("") << MailCommon::SearchRule::Envelope; QTest::newRow("subject") << QByteArray("subject") << MailCommon::SearchRule::Envelope; QTest::newRow("from") << QByteArray("from") << MailCommon::SearchRule::Envelope; QTest::newRow("sender") << QByteArray("sender") << MailCommon::SearchRule::Envelope; QTest::newRow("reply-to") << QByteArray("reply-to") << MailCommon::SearchRule::Envelope; QTest::newRow("to") << QByteArray("to") << MailCommon::SearchRule::Envelope; QTest::newRow("cc") << QByteArray("cc") << MailCommon::SearchRule::Envelope; QTest::newRow("in-reply-to") << QByteArray("in-reply-to") << MailCommon::SearchRule::Envelope; QTest::newRow("message-id") << QByteArray("message-id") << MailCommon::SearchRule::Envelope; QTest::newRow("references") << QByteArray("references") << MailCommon::SearchRule::Envelope; QTest::newRow("messages") << QByteArray("") << MailCommon::SearchRule::CompleteMessage; QTest::newRow("body") << QByteArray("") << MailCommon::SearchRule::CompleteMessage; QTest::newRow("unknown") << QByteArray("unknown") << MailCommon::SearchRule::Header; } void SearchRuleStringTest::shouldMatchString() { } void SearchRuleStringTest::shouldMatchString_data() { } void SearchRuleStringTest::shouldBeEmpty() { MailCommon::SearchRuleString searchrule; QVERIFY(searchrule.isEmpty()); searchrule = MailCommon::SearchRuleString(QByteArray(), MailCommon::SearchRule::FuncContains, QStringLiteral("foo")); QVERIFY(searchrule.isEmpty()); searchrule = MailCommon::SearchRuleString(QByteArray(""), MailCommon::SearchRule::FuncContains, QString()); QVERIFY(searchrule.isEmpty()); searchrule = MailCommon::SearchRuleString(QByteArray(""), MailCommon::SearchRule::FuncContains, QStringLiteral("foo")); QVERIFY(!searchrule.isEmpty()); } QTEST_MAIN(SearchRuleStringTest) diff --git a/src/search/autotests/searchruletest.cpp b/src/search/autotests/searchruletest.cpp index 3765d54..334152b 100644 --- a/src/search/autotests/searchruletest.cpp +++ b/src/search/autotests/searchruletest.cpp @@ -1,67 +1,67 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "searchruletest.h" #include "../search/searchrule/searchrule.h" -#include +#include class TestSearchRule : public MailCommon::SearchRule { public: TestSearchRule(const QByteArray &field = QByteArray(), Function function = FuncContains, const QString &contents = QString()) : MailCommon::SearchRule(field, function, contents) { } bool matches(const Akonadi::Item &item) const override { Q_UNUSED(item); return false; } bool isEmpty() const override { return false; } MailCommon::SearchRule::RequiredPart requiredPart() const override { return MailCommon::SearchRule::CompleteMessage; } }; SearchRuleTest::SearchRuleTest(QObject *parent) : QObject(parent) { } void SearchRuleTest::shouldHaveDefaultValue() { TestSearchRule searchrule; QCOMPARE(searchrule.field(), QByteArray()); QCOMPARE(searchrule.function(), MailCommon::SearchRule::FuncContains); QVERIFY(searchrule.contents().isEmpty()); } void SearchRuleTest::shouldAssignValue() { TestSearchRule searchrule; //TODO } QTEST_MAIN(SearchRuleTest) diff --git a/src/snippets/autotests/snippetsmanagertest.cpp b/src/snippets/autotests/snippetsmanagertest.cpp index 731a5fc..a2bc622 100644 --- a/src/snippets/autotests/snippetsmanagertest.cpp +++ b/src/snippets/autotests/snippetsmanagertest.cpp @@ -1,49 +1,49 @@ /* Copyright (c) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "snippetsmanagertest.h" #include "../snippetsmanager.h" #include -#include +#include SnippetsManagerTest::SnippetsManagerTest(QObject *parent) : QObject(parent) { } SnippetsManagerTest::~SnippetsManagerTest() { } void SnippetsManagerTest::shouldHaveDefaultValue() { KActionCollection *collection = new KActionCollection(this); MailCommon::SnippetsManager snippetManager(collection, this); QVERIFY(snippetManager.deleteSnippetAction()); QVERIFY(snippetManager.model()); QVERIFY(snippetManager.selectionModel()); QVERIFY(snippetManager.addSnippetAction()); QVERIFY(snippetManager.editSnippetAction()); QVERIFY(snippetManager.deleteSnippetAction()); QVERIFY(snippetManager.addSnippetGroupAction()); QVERIFY(snippetManager.editSnippetGroupAction()); QVERIFY(snippetManager.deleteSnippetGroupAction()); QVERIFY(snippetManager.insertSnippetAction()); QVERIFY(snippetManager.selectedName().isEmpty()); } QTEST_MAIN(SnippetsManagerTest)