diff --git a/mimetreeparser/autotests/attachmenttest.cpp b/mimetreeparser/autotests/attachmenttest.cpp index 98e6d18a..ba7b802d 100644 --- a/mimetreeparser/autotests/attachmenttest.cpp +++ b/mimetreeparser/autotests/attachmenttest.cpp @@ -1,68 +1,69 @@ /* Copyright (c) 2015 Volker Krause 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 "objecttreeparser.h" #include "util.h" #include "setupenv.h" +#include "testobjecttreesource.h" #include using namespace MimeTreeParser; class AttachmentTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void testEncryptedAttachment_data(); void testEncryptedAttachment(); }; QTEST_MAIN(AttachmentTest) void AttachmentTest::initTestCase() { MimeTreeParser::Test::setupEnv(); } void AttachmentTest::testEncryptedAttachment_data() { QTest::addColumn("mbox"); QTest::newRow("encrypted") << "openpgp-encrypted-two-attachments.mbox"; QTest::newRow("signed") << "openpgp-signed-two-attachments.mbox"; QTest::newRow("signed+encrypted") << "openpgp-signed-encrypted-two-attachments.mbox"; QTest::newRow("encrypted+partial signed") << "openpgp-encrypted-partially-signed-attachments.mbox"; } void AttachmentTest::testEncryptedAttachment() { QFETCH(QString, mbox); auto msg = readAndParseMail(mbox); NodeHelper nodeHelper; Test::TestObjectTreeSource testSource; - testSource.setAllowDecryption(true); + testSource.mDecryptMessage = true; ObjectTreeParser otp(&testSource, &nodeHelper); otp.parseObjectTree(msg.data()); auto attachments = msg->attachments(); auto encAtts = nodeHelper.attachmentsOfExtraContents(); QCOMPARE(attachments.size() + encAtts.size(), 2); } #include "attachmenttest.moc" diff --git a/mimetreeparser/autotests/setupenv.h b/mimetreeparser/autotests/setupenv.h index 6675b831..148fa02c 100644 --- a/mimetreeparser/autotests/setupenv.h +++ b/mimetreeparser/autotests/setupenv.h @@ -1,105 +1,36 @@ /* Copyright (C) 2010 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Copyright (c) 2010 Leo Franchi 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. */ -#ifndef MESSAGECORE_TESTS_UTIL_H -#define MESSAGECORE_TESTS_UTIL_H - -#include -#include -#include -#include -#include +#ifndef MIMETREEPARSER_TESTS_SETUPENV_H +#define MIMETREEPARSER_TESTS_SETUPENV_H namespace MimeTreeParser { namespace Test { /** * setup a environment variables for tests: * * set LC_ALL to C * * set KDEHOME */ 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 MimeTreeParser::Interface::ObjectTreeSource -{ -public: - TestObjectTreeSource() - : mPreferredMode(Util::Html) - , mDecryptMessage(false) - { - } - - bool autoImportKeys() const override - { - return true; - } - - const BodyPartFormatterFactory *bodyPartFormatterFactory() override - { - return &mBodyPartFormatterFactory; - } - - bool decryptMessage() const override - { - return mDecryptMessage; - } - - void setAllowDecryption(bool allowDecryption) - { - mDecryptMessage = allowDecryption; - } - - void setHtmlMode(MimeTreeParser::Util::HtmlMode mode, const QList &availableModes) override - { - Q_UNUSED(mode); - Q_UNUSED(availableModes); - } - - MimeTreeParser::Util::HtmlMode preferredMode() const override - { - return mPreferredMode; - } - - void setPreferredMode(MimeTreeParser::Util::HtmlMode mode) - { - mPreferredMode = mode; - } - - const QTextCodec *overrideCodec() override - { - return nullptr; - } - - void render(const MessagePart::Ptr &msgPart, bool showOnlyOneMimePart) override - { - Q_UNUSED(msgPart); - Q_UNUSED(showOnlyOneMimePart); - } - -private: - BodyPartFormatterFactory mBodyPartFormatterFactory; - MimeTreeParser::Util::HtmlMode mPreferredMode; - bool mDecryptMessage = false; -}; } } #endif diff --git a/mimetreeparser/autotests/setupenv.h b/mimetreeparser/autotests/testobjecttreesource.h similarity index 68% copy from mimetreeparser/autotests/setupenv.h copy to mimetreeparser/autotests/testobjecttreesource.h index 6675b831..04ac02ef 100644 --- a/mimetreeparser/autotests/setupenv.h +++ b/mimetreeparser/autotests/testobjecttreesource.h @@ -1,105 +1,82 @@ /* - Copyright (C) 2010 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Copyright (c) 2010 Leo Franchi + Copyright (C) 2017 Sandro Kanuß 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. */ -#ifndef MESSAGECORE_TESTS_UTIL_H -#define MESSAGECORE_TESTS_UTIL_H +#ifndef MIMETREEPARSER_TESTS_TESTOBJECTTREESOURCE_H +#define MIMETREEPARSER_TESTS_TESTOBJECTTREESOURCE_H -#include -#include #include #include #include namespace MimeTreeParser { namespace Test { -/** -* setup a environment variables for tests: -* * set LC_ALL to C -* * set KDEHOME -*/ -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 MimeTreeParser::Interface::ObjectTreeSource { public: TestObjectTreeSource() - : mPreferredMode(Util::Html) + : mBodyPartFormatterFactory(MimeTreeParser::BodyPartFormatterFactory::instance()) + , mPreferredMode(Util::Html) , mDecryptMessage(false) { } bool autoImportKeys() const override { return true; } const BodyPartFormatterFactory *bodyPartFormatterFactory() override { - return &mBodyPartFormatterFactory; + return mBodyPartFormatterFactory; } bool decryptMessage() const override { return mDecryptMessage; } - void setAllowDecryption(bool allowDecryption) - { - mDecryptMessage = allowDecryption; - } - void setHtmlMode(MimeTreeParser::Util::HtmlMode mode, const QList &availableModes) override { Q_UNUSED(mode); Q_UNUSED(availableModes); } MimeTreeParser::Util::HtmlMode preferredMode() const override { return mPreferredMode; } - void setPreferredMode(MimeTreeParser::Util::HtmlMode mode) - { - mPreferredMode = mode; - } - const QTextCodec *overrideCodec() override { return nullptr; } void render(const MessagePart::Ptr &msgPart, bool showOnlyOneMimePart) override { Q_UNUSED(msgPart); Q_UNUSED(showOnlyOneMimePart); } -private: - BodyPartFormatterFactory mBodyPartFormatterFactory; + BodyPartFormatterFactory *mBodyPartFormatterFactory; MimeTreeParser::Util::HtmlMode mPreferredMode; - bool mDecryptMessage = false; + bool mDecryptMessage; }; } } - #endif