diff --git a/plugins/messageviewer/bodypartformatter/autotests/data/wks-confirmation-request-decrypted.mbox.html b/plugins/messageviewer/bodypartformatter/autotests/data/wks-confirmation-request-decrypted.mbox.html
index e731559f..5a2c2212 100644
--- a/plugins/messageviewer/bodypartformatter/autotests/data/wks-confirmation-request-decrypted.mbox.html
+++ b/plugins/messageviewer/bodypartformatter/autotests/data/wks-confirmation-request-decrypted.mbox.html
@@ -1,43 +1,43 @@
Register your OpenPGP key with your email provider.
When you register your key with your email provider other people will then be able to retrieve the key and send you encrypted emails and verify authenticity of emails you send them.
diff --git a/plugins/messageviewer/bodypartformatter/autotests/data/wks-confirmation-request-multipart-decrypted.mbox.html b/plugins/messageviewer/bodypartformatter/autotests/data/wks-confirmation-request-multipart-decrypted.mbox.html
index 56eb6696..f52b06f7 100644
--- a/plugins/messageviewer/bodypartformatter/autotests/data/wks-confirmation-request-multipart-decrypted.mbox.html
+++ b/plugins/messageviewer/bodypartformatter/autotests/data/wks-confirmation-request-multipart-decrypted.mbox.html
@@ -1,43 +1,43 @@
Register your OpenPGP key with your email provider.
When you register your key with your email provider other people will then be able to retrieve the key and send you encrypted emails and verify authenticity of emails you send them.
diff --git a/plugins/messageviewer/bodypartformatter/autotests/data/wks-confirmation-response-decrypted.mbox.html b/plugins/messageviewer/bodypartformatter/autotests/data/wks-confirmation-response-decrypted.mbox.html
index 3f1d1ea4..f6c52977 100644
--- a/plugins/messageviewer/bodypartformatter/autotests/data/wks-confirmation-response-decrypted.mbox.html
+++ b/plugins/messageviewer/bodypartformatter/autotests/data/wks-confirmation-response-decrypted.mbox.html
@@ -1,39 +1,39 @@
This is an automatically generated email. The purpose of this email is to register your OpenPGP key with your email provider.
Your OpenPGP key will be published on your email provider's key server. Other users will be able to retrieve the key and send you encrypted emails and verify authenticity of emails you send them.
Show key details
diff --git a/plugins/messageviewer/bodypartformatter/autotests/rendertest.cpp b/plugins/messageviewer/bodypartformatter/autotests/rendertest.cpp
index 738d1712..7453dbca 100644
--- a/plugins/messageviewer/bodypartformatter/autotests/rendertest.cpp
+++ b/plugins/messageviewer/bodypartformatter/autotests/rendertest.cpp
@@ -1,230 +1,238 @@
/*
Copyright (c) 2010 Volker Krause
Copyright (c) 2016 Sandro Knauß
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 "rendertest.h"
#include "testobjecttreesource.h"
#include
#include
#include
#include
-#include
#include
#include
#include
#include
+#include
+#include
+#include
#ifndef Q_OS_WIN
void initLocale()
{
setenv("KDEHOME", QFile::encodeName(QDir::homePath() + QString::fromLatin1(
"/.qttest")).constData(), 1);
setenv("LC_ALL", "en_US.utf-8", 1);
setenv("TZ", "UTC", 1);
QStandardPaths::setTestModeEnabled(true);
QIcon::setThemeName(QStringLiteral("breeze"));
QLocale::setDefault(QLocale(QStringLiteral("en_US")));
}
Q_CONSTRUCTOR_FUNCTION(initLocale)
#endif
+void RenderTest::initTestCase()
+{
+ QApplication::setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
+ QApplication::setPalette(QApplication::style()->standardPalette());
+}
+
void RenderTest::testRender_data()
{
QTest::addColumn("mailFileName");
QTest::addColumn("referenceFileName");
QTest::addColumn("outFileName");
QDir dir(QStringLiteral(MAIL_DATA_DIR));
const QStringList lst = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks);
for (const QString &file : lst) {
if (!QFile::exists(dir.path() + QLatin1Char('/') + file + QStringLiteral(".html"))) {
continue;
}
QTest::newRow(file.toLatin1()) << QString(dir.path() + QLatin1Char('/') + file) << QString(dir.path() + QLatin1Char('/') + file + QStringLiteral(".html"))
<< QString(file + QStringLiteral(".out"));
}
}
void RenderTest::testRender()
{
QFETCH(QString, mailFileName);
QFETCH(QString, referenceFileName);
QFETCH(QString, outFileName);
// load input mail
QFile mailFile(mailFileName);
QVERIFY(mailFile.open(QIODevice::ReadOnly));
const QByteArray mailData = KMime::CRLFtoLF(mailFile.readAll());
QVERIFY(!mailData.isEmpty());
KMime::Message::Ptr msg(new KMime::Message);
msg->setContent(mailData);
msg->parse();
// render the mail
MimeTreeParser::FileHtmlWriter fileWriter(outFileName);
fileWriter.begin();
QImage paintDevice;
MessageViewer::CSSHelperBase cssHelper(&paintDevice);
MimeTreeParser::NodeHelper nodeHelper;
TestObjectTreeSource testSource(&fileWriter, &cssHelper);
MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper);
fileWriter.write(QStringLiteral("\n"
"\n"
"\n"));
otp.parseObjectTree(msg.data());
fileWriter.write(QStringLiteral(""));
fileWriter.end();
compareFile(outFileName, referenceFileName);
}
void RenderTest::testRenderKeyDetails_data()
{
QTest::addColumn("basename");
QTest::newRow("message-with-openpgp-key.mbox") << QStringLiteral("message-with-openpgp-key.mbox");
QTest::newRow("message-with-two-openpgp-key.mbox") << QStringLiteral("message-with-two-openpgp-key.mbox");
}
void RenderTest::testRenderKeyDetails()
{
QFETCH(QString, basename);
QString mailFileName = QStringLiteral(MAIL_DATA_DIR) + QLatin1Char('/') + basename;
QString referenceFileName = QStringLiteral(MAIL_DATA_DIR) + QLatin1Char('/') + basename + QStringLiteral(".html");
QString outFileName = basename + QStringLiteral(".out");
// load input mail
QFile mailFile(mailFileName);
QVERIFY(mailFile.open(QIODevice::ReadOnly));
const QByteArray mailData = KMime::CRLFtoLF(mailFile.readAll());
QVERIFY(!mailData.isEmpty());
KMime::Message::Ptr msg(new KMime::Message);
msg->setContent(mailData);
msg->parse();
// render the mail
QEventLoop loop;
MimeTreeParser::FileHtmlWriter fileWriter(outFileName);
fileWriter.begin();
QImage paintDevice;
MessageViewer::CSSHelperBase cssHelper(&paintDevice);
MimeTreeParser::NodeHelper nodeHelper;
TestObjectTreeSource testSource(&fileWriter, &cssHelper);
testSource.setShowSignatureDetails(true);
MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper);
fileWriter.write(QStringLiteral("\n"
"\n"
"\n"));
connect(&nodeHelper, &MimeTreeParser::NodeHelper::update, &loop, &QEventLoop::quit);
otp.parseObjectTree(msg.data());
fileWriter.write(QStringLiteral(""));
fileWriter.end();
compareFile(outFileName, referenceFileName + QStringLiteral(".running"));
loop.exec();
{
MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper);
fileWriter.begin();
fileWriter.write(QStringLiteral("\n"
"\n"
"\n"));
otp.parseObjectTree(msg.data());
fileWriter.write(QStringLiteral(""));
fileWriter.end();
compareFile(outFileName, referenceFileName + QStringLiteral(".details"));
}
}
void RenderTest::compareFile(const QString &outFile, const QString &referenceFile)
{
QVERIFY(QFile::exists(outFile));
const QString htmlFile = outFile + QStringLiteral(".html");
// remove tailing newlines and spaces and make htmlmore uniform (breaks pre tags)
{
QFile f(outFile);
QVERIFY(f.open(QIODevice::ReadOnly));
QString content = QString::fromUtf8(f.readAll());
f.close();
content.replace(QRegExp(QStringLiteral("[\t ]+")), QStringLiteral(" "));
content.replace(QRegExp(QStringLiteral("[\t ]*\n+[\t ]*")), QStringLiteral("\n"));
content.replace(QRegExp(QStringLiteral("([\n\t ])\\1+")), QStringLiteral("\\1"));
content.replace(QRegExp(QStringLiteral(">\n+[\t ]*")), QStringLiteral(">"));
content.replace(QRegExp(QStringLiteral("[\t ]*\n+[\t ]*<")), QStringLiteral("<"));
content.replace(QLatin1String(" "), QLatin1String("NBSP_ENTITY_PLACEHOLDER")); // xmlling chokes on
QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate));
f.write(content.toUtf8());
f.close();
}
// validate xml and pretty-print for comparisson
// TODO add proper cmake check for xmllint and diff
QStringList args = QStringList()
<< QStringLiteral("--format")
<< QStringLiteral("--encode")
<< QStringLiteral("UTF8")
<< QStringLiteral("--output")
<< htmlFile
<< outFile;
QCOMPARE(QProcess::execute(QStringLiteral("xmllint"), args), 0);
// get rid of system dependent or random paths
{
QFile f(htmlFile);
QVERIFY(f.open(QIODevice::ReadOnly));
QString content = QString::fromUtf8(f.readAll());
f.close();
content.replace(QRegExp(QStringLiteral(
"\"file:[^\"]*[/(?:%2F)]([^\"/(?:%2F)]*)\"")),
QStringLiteral("\"file:\\1\""));
content.replace(QLatin1String("NBSP_ENTITY_PLACEHOLDER"), QLatin1String(" ")); // undo above transformation for xmllint
content.replace(QRegExp(QStringLiteral("/bodypart/\\d+/")), QStringLiteral("/bodypart/0/"));
QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate));
f.write(content.toUtf8());
f.close();
}
// compare to reference file
args = QStringList()
<< QStringLiteral("-u")
<< referenceFile
<< htmlFile;
QProcess proc;
proc.setProcessChannelMode(QProcess::ForwardedChannels);
proc.start(QStringLiteral("diff"), args);
QVERIFY(proc.waitForFinished());
QCOMPARE(proc.exitCode(), 0);
}
QTEST_MAIN(RenderTest)
diff --git a/plugins/messageviewer/bodypartformatter/autotests/rendertest.h b/plugins/messageviewer/bodypartformatter/autotests/rendertest.h
index 6d5268e4..23674e13 100644
--- a/plugins/messageviewer/bodypartformatter/autotests/rendertest.h
+++ b/plugins/messageviewer/bodypartformatter/autotests/rendertest.h
@@ -1,39 +1,42 @@
/*
Copyright (c) 2010 Volker Krause
Copyright (c) 2016 Sandro Knauß
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 RENDERTEST_H
#define RENDERTEST_H
#include
class RenderTest : public QObject
{
Q_OBJECT
+public Q_SLOTS:
+ void initTestCase();
+
private Q_SLOTS:
void testRender_data();
void testRender();
void testRenderKeyDetails_data();
void testRenderKeyDetails();
private:
void compareFile(const QString &outFile, const QString &referenceFile);
};
#endif