diff --git a/examples/messageviewergrantleetheme/themes/example/header.html b/examples/messageviewergrantleetheme/themes/example/header.html index 1bcccf72..a3c6d7b5 100644 --- a/examples/messageviewergrantleetheme/themes/example/header.html +++ b/examples/messageviewergrantleetheme/themes/example/header.html @@ -1,49 +1,48 @@
{% if header.subject %} {% with header.subjecti18n as title %} {% with header.subject|safe as value %} {% include "header_row.html" %} {% endwith %} {% endwith %} {% endif %} - {% if header.from %} + {% if header.from.isSet %} {% with header.fromi18n as title %} - {% with header.from|safe as value %} + {% with header.from.fullAddress|safe as value %} {% include "header_row.html" %} {% endwith %} {% endwith %} {% endif %} {% if header.to.isSet %} {% with header.toi18n as title %} {% with header.to.fullAddress|safe as value %} {% include "header_row.html" %} {% endwith %} {% endwith %} {% endif %} {% if header.cc.isSet %} {% with header.cci18n as title %} {% with header.cc.fullAddress|safe as value %} {% include "header_row.html" %} {% endwith %} {% endwith %} {% endif %} {% if header.bcc.isSet %} {% with header.bcci18n as title %} {% with header.bcc.fullAddress|safe as value %} {% include "header_row.html" %} {% endwith %} {% endwith %} {% endif %} - {% if header.date %} - {% with header.datei18n as title %} - {% with header.dateshort|safe as value %} - {% include "header_row.html" %} - {% endwith %} - {% endwith %} - {% endif %} + + {% with header.datei18n as title %} + {% with header.date.short as value %} + {% include "header_row.html" %} + {% endwith %} + {% endwith %} {% if header.spamHTML %} {{ spamHTML|safe }} {% endif %}
diff --git a/examples/messageviewergrantleetheme/themes/example_fancy/header.html b/examples/messageviewergrantleetheme/themes/example_fancy/header.html index cc0e32e8..ab28a629 100644 --- a/examples/messageviewergrantleetheme/themes/example_fancy/header.html +++ b/examples/messageviewergrantleetheme/themes/example_fancy/header.html @@ -1,103 +1,103 @@
{{ header.subject|safe }}
{% if header.photourl %} {% endif %} {% if header.spamHTML %}
- {% if header.cc.isSet %} {% endif %} {% if header.bcc.isSet %} {% endif %} {% if header.Sender %} - + {% endif %} {% if header.ListId %} {% endif %} - +
{{ header.fromi18n }}{{ header.from|safe }} + {{ header.from.str}} {% if header.resentfrom %} -   {{ header.resentfromi18n }}: {{ header.resentfrom|safe }} +   {{ header.resentfromi18n }}: {{ header.resentfrom }} {% endif %} {% if vCardName %}   {{ header.vcardi18n }} {% endif %} {% if header.organization %} -   ("{{ header.organization|safe }}") +   ("{{ header.organization}}") {% endif %}
{{ header.toi18n }} {{ header.to.expandableTo|safe }}
{{ header.cci18n }} {{ header.cc.expandableCc|safe }}
{{ header.bcci18n }} {{ header.bcc.expandableBCC|safe }}
Sender: {{ header.Sender|safe }}{{ header.Sender }}
List-Id: {{ header.ListId }}
{{ header.datei18n }} {{ header.dateshort }}{{ header.date.short }}
- +
{{ header.spamstatusi18n }}  {{ header.spamHTML|safe }}
{% endif %}
diff --git a/plugins/messageviewerheaderplugins/autotests/CMakeLists.txt b/plugins/messageviewerheaderplugins/autotests/CMakeLists.txt index 2882013d..45ee126e 100644 --- a/plugins/messageviewerheaderplugins/autotests/CMakeLists.txt +++ b/plugins/messageviewerheaderplugins/autotests/CMakeLists.txt @@ -1,43 +1,44 @@ # convenience macro to add qtest unit tests add_definitions( -DHEADER_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" ) +add_definitions( -DGRANTLEETHEME_DATA_DIR="${CMAKE_SOURCE_DIR}/examples/messageviewergrantleetheme/themes" ) macro(add_messageviewer_header_unittest _source _additional) set( _test ${_source} utils.cpp ${_additional}) get_filename_component(_name ${_source} NAME_WE) add_executable( ${_name} ${_test} ) add_test(NAME ${_name} COMMAND ${_name} ) ecm_mark_as_test(messageviewer-header-${_name}) target_link_libraries( ${_name} KF5::MessageViewer KF5::Libkleo Qt5::Test KF5::KIOCore KF5::Mime KF5::AkonadiCore KF5::AkonadiNotes KF5::CalendarCore KF5::GrantleeTheme KF5::XmlGui KF5::I18n) endmacro () macro(add_messageviewer_header_class_unittest _source ) set( _test ${_source}) get_filename_component(_name ${_source} NAME_WE) add_executable( ${_name} ${_test} ) add_test(NAME ${_name} COMMAND ${_name} ) ecm_mark_as_test(messageviewer-header-${_name}) target_link_libraries( ${_name} KF5::MessageViewer KF5::Libkleo Qt5::Test KF5::KIOCore KF5::Mime KF5::AkonadiCore KF5::AkonadiNotes KF5::CalendarCore KF5::GrantleeTheme KF5::XmlGui) endmacro () configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/../enterpriseheaderstyleplugin/messageviewer_enterpriseheaderstyleplugin.json.cmake ${CMAKE_CURRENT_BINARY_DIR}/messageviewer_enterpriseheaderstyleplugin.json) add_messageviewer_header_unittest( briefheaderstyleplugintest.cpp "../briefheaderstyleplugin/briefheaderstrategy.cpp;../briefheaderstyleplugin/briefheaderstyle.cpp;../briefheaderstyleplugin/briefheaderstyleplugin.cpp;../briefheaderstyleplugin/briefheaderstyleinterface.cpp") add_messageviewer_header_unittest( enterpriseheaderstyleplugintest.cpp "../enterpriseheaderstyleplugin/enterpriseheaderstyle.cpp;../enterpriseheaderstyleplugin/enterpriseheaderstyleplugin.cpp;../enterpriseheaderstyleplugin/enterpriseheaderstyleinterface.cpp") add_messageviewer_header_unittest( fancyheaderstyleplugintest.cpp "../fancyheaderstyleplugin/fancyheaderstyle.cpp;../fancyheaderstyleplugin/fancyheaderstyleplugin.cpp;../fancyheaderstyleplugin/fancyheaderstyleinterface.cpp") add_messageviewer_header_unittest( grantleeheaderstyleplugintest.cpp "../grantleeheaderstyleplugin/grantleeheaderstrategy.cpp;../grantleeheaderstyleplugin/grantleeheaderstyleplugin.cpp;../grantleeheaderstyleplugin/grantleeheaderstyleinterface.cpp") add_messageviewer_header_unittest( longheaderstyleplugintest.cpp "../longheaderstyleplugin/longheaderstyleplugin.cpp;../longheaderstyleplugin/longheaderstyleinterface.cpp") add_messageviewer_header_unittest( standardsheaderstyleplugintest.cpp "../standardsheaderstyleplugin/standardheaderstrategy.cpp;../standardsheaderstyleplugin/standardsheaderstyleplugin.cpp;../standardsheaderstyleplugin/standardsheaderstyleinterface.cpp") add_messageviewer_header_class_unittest( headerstylepluginmanagertest.cpp) diff --git a/plugins/messageviewerheaderplugins/autotests/data/example/allheaders.mbox.html b/plugins/messageviewerheaderplugins/autotests/data/example/allheaders.mbox.html new file mode 100644 index 00000000..9ff5a153 --- /dev/null +++ b/plugins/messageviewerheaderplugins/autotests/data/example/allheaders.mbox.html @@ -0,0 +1,29 @@ + + + + +
+
Subject:ssr/vpn超低价促销
+
+ + From: + + admin <admin@ssrr.link> +
+
To:spam1 <spam1@example.org>, spam2 <spam2@example.org>, spam3 <spam3@example.org>, spam4 <spam4@example.org>, spam5 <spam5@example.org>, spam6 <spam6@example.org>
+
+ + CC: + + foo@exampleorg +
+
+ + BCC: + + bcc@example.org +
+
Date:21 May 2018 16:52:43
+
+ + diff --git a/plugins/messageviewerheaderplugins/autotests/data/example/headertest.mbox.html b/plugins/messageviewerheaderplugins/autotests/data/example/headertest.mbox.html new file mode 100644 index 00000000..5e814d37 --- /dev/null +++ b/plugins/messageviewerheaderplugins/autotests/data/example/headertest.mbox.html @@ -0,0 +1,14 @@ + + + + +
+
Subject:No Subject
+
From:admin <admin@ssrr.link>, from2 <from2@example.org>, from3 <from3@example.org>, from4 <from4@example.org>, from5 <from5@example.org>, from6 <from6@example.org>
+
To:direct recipient1 <tospam1@example.org>, direct recipient2 <tospam2@example.org>, direct recipient3 <tospam3@example.org>, direct recipient4 <tospam4@example.org>, direct recipient5 <tospam5@example.org>, direct recipient6 <tospam6@example.org>
+
CC:copy recipient1 <ccspam1@example.org>, copy recipient2 <ccspam2@example.org>, copy recipient3 <ccspam3@example.org>, copy recipient4 <ccspam4@example.org>, copy recipient5 <ccspam5@example.org>, copy recipient6 <ccspam6@example.org>
+
BCC:blind copy recipient1 <bccspam1@example.org>, blind copy recipient2 <bccspam2@example.org>, blind copy recipient3 <bccspam3@example.org>, blind copy recipient4 <bccspam4@example.org>, blind copy recipient5 <bccspam5@example.org>, blind copy recipient6 <bccspam6@example.org>
+
Date:21 May 2018 16:52:43
+
+ + diff --git a/plugins/messageviewerheaderplugins/autotests/data/example_fancy/allheaders.mbox.html b/plugins/messageviewerheaderplugins/autotests/data/example_fancy/allheaders.mbox.html new file mode 100644 index 00000000..f63f4d46 --- /dev/null +++ b/plugins/messageviewerheaderplugins/autotests/data/example_fancy/allheaders.mbox.html @@ -0,0 +1,77 @@ + + + + +
+
ssr/vpn超低价促销
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
From:admin <admin@ssrr.link> +NBSP_ENTITY_PLACEHOLDERNBSP_ENTITY_PLACEHOLDER("Universität KDE")
To: + + + spam1 <spam1@example.org>, spam2 <spam2@example.org>, spam3 <spam3@example.org>, spam4 <spam4@example.org> + spam1 <spam1@example.org>, spam2 <spam2@example.org>, spam3 <spam3@example.org>, spam4 <spam4@example.org>, spam5 <spam5@example.org>, spam6 <spam6@example.org> + +
CC: + foo@exampleorg +
BCC: + bcc@example.org +
Sender: sender <sender@example.org>
List-Id: testlist <testlist@listi.example.org>
Date: 21 May 2018 16:52:43
+
+
+
+
+ +
+
+ + + + + +
+
Spam Status:NBSP_ENTITY_PLACEHOLDERSpamassassin NBSP_ENTITY_PLACEHOLDER
+
+ + +
+ + diff --git a/plugins/messageviewerheaderplugins/autotests/data/example_fancy/headertest.mbox.html b/plugins/messageviewerheaderplugins/autotests/data/example_fancy/headertest.mbox.html new file mode 100644 index 00000000..d486e09f --- /dev/null +++ b/plugins/messageviewerheaderplugins/autotests/data/example_fancy/headertest.mbox.html @@ -0,0 +1,62 @@ + + + + +
+
No Subject
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
From:admin <admin@ssrr.link>, from2 <from2@example.org>, from3 <from3@example.org>, from4 <from4@example.org>, from5 <from5@example.org>, from6 <from6@example.org>
To: + + + direct recipient1 <tospam1@example.org>, direct recipient2 <tospam2@example.org>, direct recipient3 <tospam3@example.org>, direct recipient4 <tospam4@example.org> + direct recipient1 <tospam1@example.org>, direct recipient2 <tospam2@example.org>, direct recipient3 <tospam3@example.org>, direct recipient4 <tospam4@example.org>, direct recipient5 <tospam5@example.org>, direct recipient6 <tospam6@example.org> + +
CC: + + + copy recipient1 <ccspam1@example.org>, copy recipient2 <ccspam2@example.org>, copy recipient3 <ccspam3@example.org>, copy recipient4 <ccspam4@example.org> + copy recipient1 <ccspam1@example.org>, copy recipient2 <ccspam2@example.org>, copy recipient3 <ccspam3@example.org>, copy recipient4 <ccspam4@example.org>, copy recipient5 <ccspam5@example.org>, copy recipient6 <ccspam6@example.org> + +
BCC: + + + blind copy recipient1 <bccspam1@example.org>, blind copy recipient2 <bccspam2@example.org>, blind copy recipient3 <bccspam3@example.org>, blind copy recipient4 <bccspam4@example.org> + blind copy recipient1 <bccspam1@example.org>, blind copy recipient2 <bccspam2@example.org>, blind copy recipient3 <bccspam3@example.org>, blind copy recipient4 <bccspam4@example.org>, blind copy recipient5 <bccspam5@example.org>, blind copy recipient6 <bccspam6@example.org> + +
Date: 21 May 2018 16:52:43
+
+
+
+
+ + diff --git a/plugins/messageviewerheaderplugins/autotests/grantleeheaderstyleplugintest.cpp b/plugins/messageviewerheaderplugins/autotests/grantleeheaderstyleplugintest.cpp index 4857aaab..bcb6a040 100644 --- a/plugins/messageviewerheaderplugins/autotests/grantleeheaderstyleplugintest.cpp +++ b/plugins/messageviewerheaderplugins/autotests/grantleeheaderstyleplugintest.cpp @@ -1,53 +1,187 @@ /* Copyright (C) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "grantleeheaderstyleplugintest.h" +#include "utils.h" #include "../grantleeheaderstyleplugin/grantleeheaderstyleplugin.h" #include "../grantleeheaderstyleplugin/grantleeheaderstyleinterface.h" + +#include +#include + #include +#include + #include #include + GrantleeHeaderStylePluginTest::GrantleeHeaderStylePluginTest(QObject *parent) : QObject(parent) { } GrantleeHeaderStylePluginTest::~GrantleeHeaderStylePluginTest() { } +void GrantleeHeaderStylePluginTest::initTestCase() +{ + QStandardPaths::setTestModeEnabled(true); + qputenv("LC_ALL", "C"); + expectedDataLocation = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); + expectedDataLocation += QDir::separator() + QStringLiteral("messageviewer/themes"); + QDir targetDir(expectedDataLocation); + QDir sourceDir(QStringLiteral(GRANTLEETHEME_DATA_DIR)); + const auto themeDirs = sourceDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); + + if (targetDir.exists()) { + QVERIFY(targetDir.removeRecursively()); // Start with a fresh copy + } + + for (const auto &themeDir : themeDirs) { + const QString &dirName = targetDir.filePath(themeDir.fileName()); + QVERIFY(targetDir.mkpath(themeDir.fileName())); + const auto files = QDir(themeDir.absoluteFilePath()).entryInfoList(QDir::Files | QDir::Readable | QDir::NoSymLinks); + qDebug() << dirName << files; + for (const auto &file : files) { + const QString &newPath = dirName + QDir::separator() + file.fileName(); + qDebug() << file << newPath; + QVERIFY(QFile(file.absoluteFilePath()).copy(newPath)); + } + + } +} + +void GrantleeHeaderStylePluginTest::cleanupTestCase() +{ + QDir targetDir(expectedDataLocation); + + if (targetDir.exists()) { + QVERIFY(targetDir.removeRecursively()); // Start with a fresh copy + } +} + void GrantleeHeaderStylePluginTest::shouldHaveDefaultValue() { MessageViewer::GrantleeHeaderStylePlugin plugin; QVERIFY(plugin.headerStyle()); QVERIFY(plugin.headerStrategy()); } void GrantleeHeaderStylePluginTest::shouldCreateInterface() { MessageViewer::GrantleeHeaderStylePlugin plugin; KActionMenu *menu = new KActionMenu(this); QActionGroup *act = new QActionGroup(this); MessageViewer::HeaderStyleInterface *interface = plugin.createView(menu, act, new KActionCollection(this)); QVERIFY(interface); //QVERIFY(!interface->action().isEmpty()); } +void GrantleeHeaderStylePluginTest::testThemeActivation_data() +{ + QTest::addColumn("themeName"); + + QDir dir(QStringLiteral(GRANTLEETHEME_DATA_DIR)); + const auto themeDirs = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); + + for (const QFileInfo &t : themeDirs) { + QTest::newRow(t.fileName().toLatin1().constData()) << t.fileName(); + } +} + +void GrantleeHeaderStylePluginTest::testThemeActivation() +{ + QFETCH(QString, themeName); + + MessageViewer::GrantleeHeaderStylePlugin plugin; + KActionMenu *menu = new KActionMenu(this); + QActionGroup *act = new QActionGroup(this); + + MessageViewer::GrantleeHeaderStyleInterface *interface = static_cast(plugin.createView(menu, act, new KActionCollection(this))); + QVERIFY(interface); + + QVERIFY(interface->mThemeManager->themes().contains(themeName)); + + for (const auto &action : act->actions()) { + if (action->data() == themeName) { + action->trigger(); + break; + } + } + + QCOMPARE(plugin.headerStyle()->theme().dirName(), themeName); +} + +void GrantleeHeaderStylePluginTest::testThemeRender_data() +{ + QTest::addColumn("themeName"); + QTest::addColumn("mailFileName"); + + QDir dir(QStringLiteral(HEADER_DATA_DIR)); + const auto themeDirs = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); + const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); + + for (const QFileInfo &t : themeDirs) { + const QDir themeDir(t.absoluteFilePath()); + for (const QString &file : l) { + if (!themeDir.exists(file + QStringLiteral(".html"))) { + continue; + } + QTest::newRow(QString(themeDir.dirName() + QStringLiteral("-") + file).toLatin1().constData()) << themeDir.dirName() << file; + } + } +} + +void GrantleeHeaderStylePluginTest::testThemeRender() +{ + QFETCH(QString, themeName); + QFETCH(QString, mailFileName); + + auto aMsg = readAndParseMail(mailFileName); + MessageViewer::GrantleeHeaderStylePlugin plugin; + auto *style = plugin.headerStyle(); + KActionMenu *menu = new KActionMenu(this); + QActionGroup *act = new QActionGroup(this); + + MessageViewer::GrantleeHeaderStyleInterface *interface = static_cast(plugin.createView(menu, act, new KActionCollection(this))); + QVERIFY(interface); + + QVERIFY(interface->mThemeManager->themes().contains(themeName)); + + for (const auto &theme : interface->mThemeManager->themes()) { + if (theme.dirName() != themeName) { + continue; + } + if (theme.absolutePath().startsWith(expectedDataLocation)) { + style->setTheme(theme); + break; + } + } + + QCOMPARE(style->theme().dirName(), themeName); + // Make sure, that we do not load the same file from a different location. + QVERIFY(style->theme().absolutePath().startsWith(expectedDataLocation)); + + const QString data = style->format(aMsg.data()); + testHeaderFile(data, mailFileName, themeName); +} + QTEST_MAIN(GrantleeHeaderStylePluginTest) diff --git a/plugins/messageviewerheaderplugins/autotests/grantleeheaderstyleplugintest.h b/plugins/messageviewerheaderplugins/autotests/grantleeheaderstyleplugintest.h index e80143a1..bb6c9fbb 100644 --- a/plugins/messageviewerheaderplugins/autotests/grantleeheaderstyleplugintest.h +++ b/plugins/messageviewerheaderplugins/autotests/grantleeheaderstyleplugintest.h @@ -1,37 +1,48 @@ /* Copyright (C) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef GRANTLEEHEADERSTYLEPLUGINTEST_H #define GRANTLEEHEADERSTYLEPLUGINTEST_H #include class GrantleeHeaderStylePluginTest : public QObject { Q_OBJECT public: explicit GrantleeHeaderStylePluginTest(QObject *parent = nullptr); ~GrantleeHeaderStylePluginTest(); +public Q_SLOTS: + void initTestCase(); + void cleanupTestCase(); + private Q_SLOTS: void shouldHaveDefaultValue(); void shouldCreateInterface(); + void testThemeActivation_data(); + void testThemeActivation(); + void testThemeRender_data(); + void testThemeRender(); + +private: + QString expectedDataLocation; }; #endif // GRANTLEEHEADERSTYLEPLUGINTEST_H diff --git a/plugins/messageviewerheaderplugins/autotests/utils.cpp b/plugins/messageviewerheaderplugins/autotests/utils.cpp index 6fee067c..670a9e2a 100644 --- a/plugins/messageviewerheaderplugins/autotests/utils.cpp +++ b/plugins/messageviewerheaderplugins/autotests/utils.cpp @@ -1,93 +1,99 @@ /* Copyright (C) 2018 Sandro Knauß This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "utils.h" #include #include #include #include #include #include -void testHeaderFile(const QString &data, const QString &name) +void testHeaderFile(const QString &data, const QString &name, const QString &dir) { QString header = QStringLiteral("\n" "\n" "\n"); header += data; header += QStringLiteral("\n\n\n"); QString imagePath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("libmessageviewer/pics"), QStandardPaths::LocateDirectory)); header.replace(QStringLiteral("file://") + imagePath, QStringLiteral("file://PATHTOIMAGES")); header.replace(QRegExp(QStringLiteral("[\t ]+")), QStringLiteral(" ")); header.replace(QRegExp(QStringLiteral("[\t ]*\n+[\t ]*")), QStringLiteral("\n")); header.replace(QRegExp(QStringLiteral("([\n\t ])\\1+")), QStringLiteral("\\1")); header.replace(QRegExp(QStringLiteral(">\n+[\t ]*")), QStringLiteral(">")); header.replace(QRegExp(QStringLiteral("[\t ]*\n+[\t ]*<")), QStringLiteral("<")); header.replace(QLatin1String(" "), QLatin1String("NBSP_ENTITY_PLACEHOLDER")); // xmlling chokes on   QString outName = name + QStringLiteral(".out.html"); QString fName = name + QStringLiteral(".html"); - QVERIFY(QFile(QStringLiteral(HEADER_DATA_DIR "/") + fName).exists()); + QString referenceFile = QStringLiteral(HEADER_DATA_DIR "/"); + if (!dir.isEmpty()) { + referenceFile += dir + QStringLiteral("/"); + } + referenceFile += fName; + + QVERIFY(QFile(referenceFile).exists()); { QFile f(outName); f.open(QIODevice::WriteOnly); f.write(header.toUtf8()); f.close(); } // TODO add proper cmake check for xmllint and diff { const QStringList args = QStringList() << QStringLiteral("--format") << QStringLiteral("--encode") << QStringLiteral("UTF8") << QStringLiteral("--output") << fName << outName; QCOMPARE(QProcess::execute(QStringLiteral("xmllint"), args), 0); } { // compare to reference file const QStringList args = QStringList() << QStringLiteral("-u") << fName - << QStringLiteral(HEADER_DATA_DIR "/") + fName; + << referenceFile; QProcess proc; proc.setProcessChannelMode(QProcess::ForwardedChannels); proc.start(QStringLiteral("diff"), args); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); } } KMime::Message::Ptr readAndParseMail(const QString &mailFile) { QFile file(QStringLiteral(HEADER_DATA_DIR) + QLatin1Char('/') + mailFile); bool openFile = file.open(QIODevice::ReadOnly); Q_ASSERT(openFile); const QByteArray data = KMime::CRLFtoLF(file.readAll()); Q_ASSERT(!data.isEmpty()); KMime::Message::Ptr msg(new KMime::Message); msg->setContent(data); msg->parse(); return msg; } diff --git a/plugins/messageviewerheaderplugins/autotests/utils.h b/plugins/messageviewerheaderplugins/autotests/utils.h index 0745b9ac..795d8d41 100644 --- a/plugins/messageviewerheaderplugins/autotests/utils.h +++ b/plugins/messageviewerheaderplugins/autotests/utils.h @@ -1,29 +1,29 @@ /* Copyright (C) 2018 Sandro Knauß This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef HEADERSTYLEPLUGINTESTUTILS_H #define HEADERSTYLEPLUGINTESTUTILS_H #include #include -void testHeaderFile(const QString &data, const QString &name); +void testHeaderFile(const QString &data, const QString &name, const QString &dir = QString()); KMime::Message::Ptr readAndParseMail(const QString &mailFile); #endif // HEADERSTYLEPLUGINTESTUTILS_H diff --git a/plugins/messageviewerheaderplugins/grantleeheaderstyleplugin/grantleeheaderstyleinterface.h b/plugins/messageviewerheaderplugins/grantleeheaderstyleplugin/grantleeheaderstyleinterface.h index bf1182e7..dcfcfbdf 100644 --- a/plugins/messageviewerheaderplugins/grantleeheaderstyleplugin/grantleeheaderstyleinterface.h +++ b/plugins/messageviewerheaderplugins/grantleeheaderstyleplugin/grantleeheaderstyleinterface.h @@ -1,45 +1,49 @@ /* Copyright (C) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef GRANTLEEHEADERSTYLEINTERFACE_H #define GRANTLEEHEADERSTYLEINTERFACE_H #include namespace GrantleeTheme { class ThemeManager; } +class GrantleeHeaderStylePluginTest; + namespace MessageViewer { class GrantleeHeaderStyleInterface : public MessageViewer::HeaderStyleInterface { Q_OBJECT public: explicit GrantleeHeaderStyleInterface(HeaderStylePlugin *plugin, QObject *parent = nullptr); ~GrantleeHeaderStyleInterface() override; void createAction(KActionMenu *menu, QActionGroup *actionGroup, KActionCollection *ac) override; void activateAction() override; private: void slotGrantleeHeaders(); + + friend ::GrantleeHeaderStylePluginTest; GrantleeTheme::ThemeManager *mThemeManager = nullptr; }; } #endif // GRANTLEEHEADERSTYLEINTERFACE_H