[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdepim/KDE/4.14] mailcommon/filter: Add more unittest
From:       Montel Laurent <montel () kde ! org>
Date:       2015-04-01 7:47:42
Message-ID: E1YdDNG-0005nB-IL () scm ! kde ! org
[Download RAW message or body]

Git commit 8a4d31d3611708d2eb3b59157f9d79c02fdc1c41 by Montel Laurent.
Committed on 01/04/2015 at 07:47.
Pushed by mlaurent into branch 'KDE/4.14'.

Add more unittest

M  +92   -0    mailcommon/filter/autotests/filteractionaddheadertest.cpp
M  +5    -0    mailcommon/filter/autotests/filteractionaddheadertest.h
M  +1    -1    mailcommon/filter/filteractions/filteractionaddheader.cpp

http://commits.kde.org/kdepim/8a4d31d3611708d2eb3b59157f9d79c02fdc1c41

diff --git a/mailcommon/filter/autotests/filteractionaddheadertest.cpp \
b/mailcommon/filter/autotests/filteractionaddheadertest.cpp index bffdb84..66bcb89 \
                100644
--- a/mailcommon/filter/autotests/filteractionaddheadertest.cpp
+++ b/mailcommon/filter/autotests/filteractionaddheadertest.cpp
@@ -19,6 +19,7 @@
 #include "../filteractions/filteractionaddheader.h"
 #include <KLineEdit>
 #include <QLabel>
+#include <itemcontext.h>
 #include <qtest_kde.h>
 #include <widgets/minimumcombobox.h>
 
@@ -85,6 +86,97 @@ void FilterActionAddHeaderTest::shouldBeEmpty()
     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<KMime::Message::Ptr>(msgPtr);
+    MailCommon::ItemContext context(item, true);
+
+    filter.argsFromString("");
+    QCOMPARE(filter.process(context, false), \
MailCommon::FilterAction::ErrorButGoOn); +    QCOMPARE(context.needsPayloadStore(), \
false); +}
+
+void FilterActionAddHeaderTest::shouldNotExecuteActionWhenValueIsEmpty()
+{
+    MailCommon::FilterActionAddHeader filter(this);
+    KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
+    Akonadi::Item item;
+    item.setPayload<KMime::Message::Ptr>(msgPtr);
+    MailCommon::ItemContext context(item, true);
+
+    filter.argsFromString("foo");
+    QCOMPARE(filter.process(context, false), \
MailCommon::FilterAction::ErrorButGoOn); +    QCOMPARE(context.needsPayloadStore(), \
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<KMime::Message::Ptr>(msgPtr);
+    MailCommon::ItemContext context(item, true);
+
+    filter.argsFromString("testheader\tfoo");
+    QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn);
+    QCOMPARE(context.needsPayloadStore(), true);
+    QCOMPARE(msgPtr->encodedContent(), output);
+}
+
+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<KMime::Message::Ptr>(msgPtr);
+    MailCommon::ItemContext context(item, true);
+
+    filter.argsFromString("testheader\tfoo");
+    QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn);
+    QCOMPARE(context.needsPayloadStore(), true);
+    QCOMPARE(msgPtr->encodedContent(), output);
+}
+
 void FilterActionAddHeaderTest::shouldAddValue()
 {
     QFETCH( QString, argsinput );
diff --git a/mailcommon/filter/autotests/filteractionaddheadertest.h \
b/mailcommon/filter/autotests/filteractionaddheadertest.h index 50e8d47..4f031cf \
                100644
--- a/mailcommon/filter/autotests/filteractionaddheadertest.h
+++ b/mailcommon/filter/autotests/filteractionaddheadertest.h
@@ -34,6 +34,11 @@ private Q_SLOTS:
     void shouldClearWidget();
     void shouldReturnSieveCode();
     void shouldBeEmpty();
+
+    void shouldNotExecuteActionWhenParameterIsEmpty();
+    void shouldNotExecuteActionWhenValueIsEmpty();
+    void shouldAddNewHeaderWhenNotExistingHeader();
+    void shouldReplaceHeaderWhenExistingHeader();
 };
 
 #endif // FILTERACTIONADDHEADERTEST_H
diff --git a/mailcommon/filter/filteractions/filteractionaddheader.cpp \
b/mailcommon/filter/filteractions/filteractionaddheader.cpp index 5f35f2a..3627eb5 \
                100644
--- a/mailcommon/filter/filteractions/filteractionaddheader.cpp
+++ b/mailcommon/filter/filteractions/filteractionaddheader.cpp
@@ -51,7 +51,7 @@ bool FilterActionAddHeader::isEmpty() const
 
 FilterAction::ReturnCode FilterActionAddHeader::process(ItemContext &context , bool) \
const  {
-    if ( mParameter.isEmpty() )
+    if ( mParameter.isEmpty() || mValue.isEmpty())
         return ErrorButGoOn;
 
     KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic