Warning, file /pim/mailcommon/src/search/autotests/searchruledatetest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only 0005 */ 0006 0007 #include "searchruledatetest.h" 0008 #include "../searchrule/searchruledate.h" 0009 #include <KMime/Message> 0010 #include <QTest> 0011 Q_DECLARE_METATYPE(MailCommon::SearchRule::Function) 0012 SearchRuleDateTest::SearchRuleDateTest(QObject *parent) 0013 : QObject(parent) 0014 { 0015 } 0016 0017 void SearchRuleDateTest::shouldHaveDefaultValue() 0018 { 0019 MailCommon::SearchRuleDate searchrule; 0020 QCOMPARE(searchrule.field(), QByteArray()); 0021 QCOMPARE(searchrule.function(), MailCommon::SearchRule::FuncContains); 0022 QVERIFY(searchrule.contents().isEmpty()); 0023 QVERIFY(searchrule.isEmpty()); 0024 } 0025 0026 void SearchRuleDateTest::shouldRequiresPart() 0027 { 0028 MailCommon::SearchRuleDate searchrule; 0029 QCOMPARE(searchrule.requiredPart(), MailCommon::SearchRule::Envelope); 0030 } 0031 0032 void SearchRuleDateTest::shouldBeEmpty() 0033 { 0034 MailCommon::SearchRuleDate searchrule("<date>", MailCommon::SearchRule::FuncEquals, QString()); 0035 QVERIFY(searchrule.isEmpty()); 0036 0037 MailCommon::SearchRuleDate searchrule2("<date>", MailCommon::SearchRule::FuncEquals, QDate(2015, 5, 5).toString(Qt::ISODate)); 0038 QVERIFY(!searchrule2.isEmpty()); 0039 } 0040 0041 void SearchRuleDateTest::shouldMatchDate_data() 0042 { 0043 QTest::addColumn<MailCommon::SearchRule::Function>("function"); 0044 QTest::addColumn<QDate>("maildate"); 0045 QTest::addColumn<QDate>("matchdate"); 0046 QTest::addColumn<bool>("match"); 0047 QTest::newRow("equaldontmatch") << MailCommon::SearchRule::FuncEquals << QDate(2015, 5, 5) << QDate(2015, 5, 6) << false; 0048 QTest::newRow("equalmatch") << MailCommon::SearchRule::FuncEquals << QDate(2015, 5, 5) << QDate(2015, 5, 5) << true; 0049 QTest::newRow("notequalnotmatch") << MailCommon::SearchRule::FuncNotEqual << QDate(2015, 5, 5) << QDate(2015, 5, 5) << false; 0050 QTest::newRow("notequalmatch") << MailCommon::SearchRule::FuncNotEqual << QDate(2015, 5, 5) << QDate(2015, 5, 6) << true; 0051 0052 QTest::newRow("isgreatermatch") << MailCommon::SearchRule::FuncIsGreater << QDate(2015, 5, 5) << QDate(2015, 5, 4) << true; 0053 QTest::newRow("isgreaternotmatch") << MailCommon::SearchRule::FuncIsGreater << QDate(2015, 5, 5) << QDate(2015, 5, 6) << false; 0054 QTest::newRow("isgreaternotmatchequalvalue") << MailCommon::SearchRule::FuncIsGreater << QDate(2015, 5, 5) << QDate(2015, 5, 5) << false; 0055 0056 QTest::newRow("islessorequalmatch") << MailCommon::SearchRule::FuncIsLessOrEqual << QDate(2015, 5, 5) << QDate(2015, 5, 6) << true; 0057 QTest::newRow("islessorequalmatch equal") << MailCommon::SearchRule::FuncIsLessOrEqual << QDate(2015, 5, 5) << QDate(2015, 5, 5) << true; 0058 QTest::newRow("islessorequalnotmatch") << MailCommon::SearchRule::FuncIsLessOrEqual << QDate(2015, 5, 7) << QDate(2015, 5, 5) << false; 0059 0060 QTest::newRow("islessmatch") << MailCommon::SearchRule::FuncIsLess << QDate(2015, 5, 4) << QDate(2015, 5, 5) << true; 0061 QTest::newRow("islessnotmatch") << MailCommon::SearchRule::FuncIsLess << QDate(2015, 5, 5) << QDate(2015, 5, 4) << false; 0062 QTest::newRow("islessnotmatchequalvalue") << MailCommon::SearchRule::FuncIsLess << QDate(2015, 5, 5) << QDate(2015, 5, 5) << false; 0063 0064 QTest::newRow("isgreaterorequalmatch") << MailCommon::SearchRule::FuncIsGreaterOrEqual << QDate(2015, 5, 6) << QDate(2015, 5, 5) << true; 0065 QTest::newRow("isgreaterorequalmatch equal") << MailCommon::SearchRule::FuncIsGreaterOrEqual << QDate(2015, 5, 5) << QDate(2015, 5, 5) << true; 0066 QTest::newRow("isgreaterorequalnotmatch") << MailCommon::SearchRule::FuncIsGreaterOrEqual << QDate(2015, 5, 5) << QDate(2015, 5, 7) << false; 0067 } 0068 0069 void SearchRuleDateTest::shouldMatchDate() 0070 { 0071 QFETCH(MailCommon::SearchRule::Function, function); 0072 QFETCH(QDate, maildate); 0073 QFETCH(QDate, matchdate); 0074 QFETCH(bool, match); 0075 MailCommon::SearchRuleDate searchrule("<date>", function, matchdate.toString(Qt::ISODate)); 0076 0077 KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); 0078 msgPtr->date(true)->setDateTime(QDateTime(maildate.startOfDay())); 0079 0080 Akonadi::Item item; 0081 item.setPayload<KMime::Message::Ptr>(msgPtr); 0082 QCOMPARE(searchrule.matches(item), match); 0083 } 0084 0085 QTEST_MAIN(SearchRuleDateTest) 0086 0087 #include "moc_searchruledatetest.cpp"