summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-24 19:04:40 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-24 19:04:40 (GMT)
commit445590f403c5cc456ac7d4dbd79bb6794b70d417 (patch)
tree71ee357b7ba1f83cbe36af94f7024d232d331a7c
parentc1d1b7fb6ebeb6c060b172567aa6df9104a6aeed (diff)
Add more autotests
-rw-r--r--messagecomposer/autotests/data/list_message.mbox11
-rw-r--r--messagecomposer/autotests/messagefactorytest.cpp61
-rw-r--r--messagecomposer/autotests/messagefactorytest.h1
3 files changed, 65 insertions, 8 deletions
diff --git a/messagecomposer/autotests/data/list_message.mbox b/messagecomposer/autotests/data/list_message.mbox
new file mode 100644
index 0000000..a4134db
--- /dev/null
+++ b/messagecomposer/autotests/data/list_message.mbox
@@ -0,0 +1,11 @@
+From: Sudhendu Kumar <dontspamme@yoohoo.com>
+To: I Dont Know<idontknow@yoohoo.com>
+Cc: Yes I Know<yesiknow@yoohoo.com>
+Subject: Plain Message Test
+List-Post: <mailto:list@list.org>
+Date: Tue, 16 Aug 2011 17:03:52 +0530
+MIME-Version: 1.0
+Content-Type: multipart/alternative; boundary="nextPart7970347.4U2bZv7Mgu"
+Content-Transfer-Encoding: 7Bit
+
+This is a mail from ML
diff --git a/messagecomposer/autotests/messagefactorytest.cpp b/messagecomposer/autotests/messagefactorytest.cpp
index 051395f..3a10e5a 100644
--- a/messagecomposer/autotests/messagefactorytest.cpp
+++ b/messagecomposer/autotests/messagefactorytest.cpp
@@ -133,9 +133,60 @@ void MessageFactoryTest::initTestCase()
QStandardPaths::setTestModeEnabled(true);
}
+KMime::Message::Ptr MessageFactoryTest::loadMessage(const QString &filename)
+{
+ QFile mailFile(filename);
+ if (!mailFile.open(QIODevice::ReadOnly)) {
+ return {};
+ }
+ const QByteArray mailData = KMime::CRLFtoLF(mailFile.readAll());
+ if (mailData.isEmpty()) {
+ return {};
+ }
+ KMime::Message::Ptr origMsg(new KMime::Message);
+ origMsg->setContent(mailData);
+ origMsg->parse();
+ return origMsg;
+}
+
+
void MessageFactoryTest::testCreateReplyToList()
{
- //TODO
+ const QString filename(QStringLiteral(MAIL_DATA_DIR) + QStringLiteral("/list_message.mbox"));
+ KMime::Message::Ptr msg = loadMessage(filename);
+ KIdentityManagement::IdentityManager *identMan = new KIdentityManagement::IdentityManager;
+ KIdentityManagement::Identity ident = identMan->newFromScratch(QStringLiteral("foo"));
+ ident.setPrimaryEmailAddress(QStringLiteral("foo@foo.foo"));
+ identMan->commit();
+
+ MessageFactory factory(msg, 0);
+ factory.setIdentityManager(identMan);
+ factory.setReplyStrategy(ReplyList);
+
+ MessageFactory::MessageReply reply = factory.createReply();
+ reply.replyAll = true;
+
+ QDateTime date = msg->date()->dateTime();
+ QString datetime = QLocale::system().toString(date.date(), QLocale::LongFormat);
+ datetime += QLatin1String(" ") + QLocale::system().toString(date.time(), QLocale::LongFormat);
+ QString replyStr = QString::fromLatin1(QByteArray("> This is a mail from ML"));
+ QCOMPARE(reply.msg->subject()->asUnicodeString(), QLatin1String("Re: Plain Message Test"));
+ QCOMPARE_OR_DIFF(reply.msg->body(), replyStr.toLatin1());
+ QString userAgent = reply.msg->userAgent()->asUnicodeString();
+ QString dateStr = reply.msg->date()->asUnicodeString();
+ QString ba = QString::fromLatin1("Date: %1\n"
+ "User-Agent: %2\n"
+ "To: list@list.org\n"
+ "Subject: Re: Plain Message Test\n"
+ "Content-Type: text/plain; charset=\"US-ASCII\"\n"
+ "Content-Transfer-Encoding: 8Bit\nMIME-Version: 1.0\n"
+ "X-KMail-Link-Message: 0\n"
+ "X-KMail-Link-Type: reply\n\n"
+ "%3")
+ .arg(dateStr).arg(userAgent).arg(replyStr);
+ QCOMPARE_OR_DIFF(reply.msg->encodedContent(), ba.toLatin1());
+
+ delete identMan;
}
void MessageFactoryTest::testCreateReplyToAuthor()
@@ -791,13 +842,7 @@ void MessageFactoryTest::test_multipartAlternative()
QFETCH(QString, selection);
QFETCH(QString, expected);
- QFile mailFile(mailFileName);
- QVERIFY(mailFile.open(QIODevice::ReadOnly));
- const QByteArray mailData = KMime::CRLFtoLF(mailFile.readAll());
- QVERIFY(!mailData.isEmpty());
- KMime::Message::Ptr origMsg(new KMime::Message);
- origMsg->setContent(mailData);
- origMsg->parse();
+ KMime::Message::Ptr origMsg = loadMessage(mailFileName);
KIdentityManagement::IdentityManager *identMan = new KIdentityManagement::IdentityManager;
KIdentityManagement::Identity ident = identMan->newFromScratch(QStringLiteral("foo"));
diff --git a/messagecomposer/autotests/messagefactorytest.h b/messagecomposer/autotests/messagefactorytest.h
index 6bc148d..586ab01 100644
--- a/messagecomposer/autotests/messagefactorytest.h
+++ b/messagecomposer/autotests/messagefactorytest.h
@@ -53,6 +53,7 @@ private:
KMime::Message::Ptr createPlainTestMessage();
KMime::Message::Ptr loadMessageFromFile(QString filename);
KMime::Message::Ptr createPlainTestMessageWithMultiEmails();
+ KMime::Message::Ptr loadMessage(const QString &filename);
};
#endif