Commit a87632f1 authored by Sandro Knauß's avatar Sandro Knauß

Replace EmptySource with Test::TestObjectTreeSource

parent 25e14d06
......@@ -19,8 +19,6 @@
#include "viewer/objecttreeparser.h"
#include "util.h"
#include "viewer/objecttreeemptysource.h"
#include "setupenv.h"
#include <qtest.h>
......@@ -57,9 +55,9 @@ void AttachmentTest::testEncryptedAttachment()
QFETCH(QString, mbox);
auto msg = readAndParseMail(mbox);
NodeHelper nodeHelper;
EmptySource emptySource;
emptySource.setAllowDecryption(true);
ObjectTreeParser otp(&emptySource, &nodeHelper);
Test::TestObjectTreeSource testSource(Q_NULLPTR, Q_NULLPTR);
testSource.setAllowDecryption(true);
ObjectTreeParser otp(&testSource, &nodeHelper);
otp.parseObjectTree(msg.data());
auto attachments = msg->attachments();
......
......@@ -20,7 +20,6 @@
#include "util.h"
#include "viewer/objecttreeparser.h"
#include "viewer/objecttreeemptysource.h"
#include "interfaces/htmlwriter.h"
#include "viewer/csshelperbase.h"
......@@ -56,7 +55,7 @@ void ObjectTreeParserTester::test_parsePlainMessage()
QCOMPARE(msg->contents().size(), 0);
// Parse the message
EmptySource emptySource;
Test::TestObjectTreeSource emptySource(Q_NULLPTR, Q_NULLPTR);
ObjectTreeParser otp(&emptySource);
otp.parseObjectTree(msg.data());
......@@ -190,7 +189,7 @@ void ObjectTreeParserTester::test_HTML()
QCOMPARE(msg->subject()->as7BitString(false).constData(), "HTML test");
QCOMPARE(msg->contents().size(), 2);
EmptySource emptySource;
Test::TestObjectTreeSource emptySource(Q_NULLPTR, Q_NULLPTR);
ObjectTreeParser otp(&emptySource);
otp.parseObjectTree(msg.data());
......@@ -227,7 +226,7 @@ void ObjectTreeParserTester::test_HTMLOnly()
QCOMPARE(msg->subject()->as7BitString(false).constData(), "HTML test");
QCOMPARE(msg->contents().size(), 0);
EmptySource emptySource;
Test::TestObjectTreeSource emptySource(Q_NULLPTR, Q_NULLPTR);
ObjectTreeParser otp(&emptySource);
otp.parseObjectTree(msg.data());
......
......@@ -22,8 +22,9 @@
#define MESSAGECORE_TESTS_UTIL_H
#include <gpgme++/key.h>
#include <viewer/objecttreeemptysource.h>
#include "objecttreesourceif.h"
#include <viewer/attachmentstrategy.h>
#include "viewer/bodypartformatterbasefactory.h"
namespace MessageViewer
{
......@@ -40,7 +41,7 @@ void setupEnv();
// We can't use EmptySource, since we need to control some emelnets of the source for tests to also test
// loadExternal and htmlMail.
class TestObjectTreeSource : public MessageViewer::EmptySource
class TestObjectTreeSource : public MessageViewer::ObjectTreeSourceIf
{
public:
TestObjectTreeSource(MessageViewer::HtmlWriter *writer,
......@@ -50,6 +51,7 @@ public:
, mAttachmentStrategy(QStringLiteral("smart"))
, mHtmlLoadExternal(false)
, mHtmlMail(true)
, mDecryptMessage(false)
{
}
......@@ -104,12 +106,60 @@ public:
return false;
}
const BodyPartFormatterBaseFactory *bodyPartFormatterFactory() Q_DECL_OVERRIDE
{
return &mBodyPartFormatterBaseFactory;
}
bool decryptMessage() const Q_DECL_OVERRIDE
{
return mDecryptMessage;
}
void setAllowDecryption(bool allowDecryption)
{
mDecryptMessage = allowDecryption;
}
bool showSignatureDetails() const Q_DECL_OVERRIDE
{
return false;
}
void setHtmlMode(MessageViewer::Util::HtmlMode mode) Q_DECL_OVERRIDE
{
Q_UNUSED(mode);
}
int levelQuote() const Q_DECL_OVERRIDE
{
return 1;
}
const QTextCodec *overrideCodec() Q_DECL_OVERRIDE
{
return Q_NULLPTR;
}
QString createMessageHeader(KMime::Message *message) Q_DECL_OVERRIDE
{
Q_UNUSED(message);
return QString(); //do nothing
}
QObject *sourceObject() Q_DECL_OVERRIDE
{
return Q_NULLPTR;
}
private:
MessageViewer::HtmlWriter *mWriter;
MessageViewer::CSSHelperBase *mCSSHelper;
QString mAttachmentStrategy;
BodyPartFormatterBaseFactory mBodyPartFormatterBaseFactory;
bool mHtmlLoadExternal;
bool mHtmlMail;
bool mDecryptMessage;
};
}
......
......@@ -19,8 +19,6 @@
#include "viewer/objecttreeparser.h"
#include "util.h"
#include "viewer/objecttreeemptysource.h"
#include <setupenv.h>
#include <qtest.h>
......@@ -50,14 +48,14 @@ QTEST_MAIN(UnencryptedMessageTest)
void UnencryptedMessageTest::initTestCase()
{
MessageViewer::Test::setupEnv();
Test::setupEnv();
}
void UnencryptedMessageTest::testMailWithoutEncryption()
{
KMime::Message::Ptr originalMessage = readAndParseMail(QStringLiteral("encapsulated-with-attachment.mbox"));
NodeHelper nodeHelper;
EmptySource emptySource;
Test::TestObjectTreeSource emptySource(Q_NULLPTR, Q_NULLPTR);
ObjectTreeParser otp(&emptySource, &nodeHelper);
otp.parseObjectTree(originalMessage.data());
QVERIFY(!nodeHelper.unencryptedMessage(originalMessage));
......@@ -70,7 +68,7 @@ void UnencryptedMessageTest::testSignedForwardedOpenPGPSignedEncrypted()
NodeHelper nodeHelper;
TestHtmlWriter testWriter;
TestCSSHelper testCSSHelper;
MessageViewer::Test::TestObjectTreeSource emptySource(&testWriter, &testCSSHelper);
Test::TestObjectTreeSource emptySource(&testWriter, &testCSSHelper);
ObjectTreeParser otp(&emptySource, &nodeHelper);
otp.parseObjectTree(originalMessage.data());
......@@ -89,7 +87,7 @@ void UnencryptedMessageTest::testForwardedOpenPGPSignedEncrypted()
NodeHelper nodeHelper;
TestHtmlWriter testWriter;
TestCSSHelper testCSSHelper;
MessageViewer::Test::TestObjectTreeSource emptySource(&testWriter, &testCSSHelper);
Test::TestObjectTreeSource emptySource(&testWriter, &testCSSHelper);
emptySource.setAllowDecryption(true);
ObjectTreeParser otp(&emptySource, &nodeHelper);
otp.parseObjectTree(originalMessage.data());
......@@ -125,7 +123,7 @@ void UnencryptedMessageTest::testSMIMESignedEncrypted()
KMime::Message::Ptr originalMessage = readAndParseMail(QStringLiteral("smime-signed-encrypted.mbox"));
NodeHelper nodeHelper;
EmptySource emptySource;
Test::TestObjectTreeSource emptySource(Q_NULLPTR, Q_NULLPTR);
emptySource.setAllowDecryption(true);
ObjectTreeParser otp(&emptySource, &nodeHelper);
otp.parseObjectTree(originalMessage.data());
......@@ -154,7 +152,7 @@ void UnencryptedMessageTest::testOpenPGPSignedEncrypted()
KMime::Message::Ptr originalMessage = readAndParseMail(QStringLiteral("openpgp-signed-encrypted.mbox"));
NodeHelper nodeHelper;
EmptySource emptySource;
Test::TestObjectTreeSource emptySource(Q_NULLPTR, Q_NULLPTR);
emptySource.setAllowDecryption(true);
ObjectTreeParser otp(&emptySource, &nodeHelper);
otp.parseObjectTree(originalMessage.data());
......@@ -183,7 +181,7 @@ void UnencryptedMessageTest::testOpenPGPEncrypted()
KMime::Message::Ptr originalMessage = readAndParseMail(QStringLiteral("openpgp-encrypted.mbox"));
NodeHelper nodeHelper;
EmptySource emptySource;
Test::TestObjectTreeSource emptySource(Q_NULLPTR, Q_NULLPTR);
emptySource.setAllowDecryption(true);
ObjectTreeParser otp(&emptySource, &nodeHelper);
otp.parseObjectTree(originalMessage.data());
......@@ -203,7 +201,7 @@ void UnencryptedMessageTest::testOpenPGPEncryptedNotDecrypted()
KMime::Message::Ptr originalMessage = readAndParseMail(QStringLiteral("openpgp-encrypted.mbox"));
NodeHelper nodeHelper;
EmptySource emptySource;
Test::TestObjectTreeSource emptySource(Q_NULLPTR, Q_NULLPTR);
emptySource.setAllowDecryption(false);
ObjectTreeParser otp(&emptySource, &nodeHelper);
otp.parseObjectTree(originalMessage.data());
......@@ -233,7 +231,7 @@ void UnencryptedMessageTest::testAsync()
KMime::Message::Ptr originalMessage = readAndParseMail(mailFileName);
NodeHelper nodeHelper;
EmptySource emptySource;
Test::TestObjectTreeSource emptySource(Q_NULLPTR, Q_NULLPTR);
emptySource.setAllowDecryption(true);
{
QEventLoop loop;
......@@ -276,7 +274,7 @@ void UnencryptedMessageTest::testNotDecrypted()
NodeHelper nodeHelper;
TestHtmlWriter testWriter;
TestCSSHelper testCSSHelper;
MessageViewer::Test::TestObjectTreeSource emptySource(&testWriter, &testCSSHelper);
Test::TestObjectTreeSource emptySource(&testWriter, &testCSSHelper);
emptySource.setAllowDecryption(false);
ObjectTreeParser otp(&emptySource, &nodeHelper);
otp.parseObjectTree(originalMessage.data());
......@@ -299,7 +297,7 @@ void UnencryptedMessageTest::testSMimeAutoCertImport()
NodeHelper nodeHelper;
TestHtmlWriter testWriter;
TestCSSHelper testCSSHelper;
MessageViewer::Test::TestObjectTreeSource emptySource(&testWriter, &testCSSHelper);
Test::TestObjectTreeSource emptySource(&testWriter, &testCSSHelper);
ObjectTreeParser otp(&emptySource, &nodeHelper);
otp.parseObjectTree(originalMessage.data());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment