diff --git a/messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp b/messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp index e6c02b50..d4e3ca25 100644 --- a/messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp +++ b/messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp @@ -1,358 +1,366 @@ /* 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 "setupenv.h" #include "testcsshelper.h" #include "util.h" #include #include #include #include #include #include #include using namespace MessageViewer; void RenderTest::initTestCase() { Test::setupEnv(); } +#ifndef Q_OS_WIN +void initLocale() +{ + setenv("LC_ALL", "en_US.utf-8", 1); + setenv("TZ", "UTC", 1); +} +Q_CONSTRUCTOR_FUNCTION(initLocale) +#endif void RenderTest::testRenderSmart_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); for (const QString &file : l) { if (!QFile::exists(dir.path() + QLatin1Char('/') + file + QStringLiteral(".html"))) { continue; } QTest::newRow(file.toLatin1().constData()) << file << QString(dir.path() + QLatin1Char( '/') + file + QStringLiteral(".html")) << QString(file + QStringLiteral(".out")) << QStringLiteral("smart") << false << QString(); } } void RenderTest::testRenderSmart() { testRender(); } void RenderTest::testRenderSmartAsync_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); for (const QString &file : l) { if (!QFile::exists(dir.path() + QLatin1Char('/') + file + QStringLiteral(".inProgress.html"))) { continue; } QTest::newRow(file.toLatin1().constData()) << file << QString(dir.path() + QLatin1Char( '/') + file + QStringLiteral(".html")) << QString(file + QStringLiteral(".out")) << QStringLiteral("smart") << false << QString( dir.path() + QLatin1Char( '/') + file + QStringLiteral(".inProgress.html")); } } void RenderTest::testRenderSmartAsync() { testRender(); } void RenderTest::testRenderSmartDetails_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); for (const QString &file : l) { QString fname = dir.path() + QLatin1String("/details/") + file + QLatin1String(".html"); if (!QFile::exists(fname)) { continue; } QTest::newRow(file.toLatin1().constData()) << file << fname << QString(file + QStringLiteral( ".out")) << QStringLiteral("smart") << true << QString(); } } void RenderTest::testRenderSmartDetails() { testRender(); } void RenderTest::testRenderInlined_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); for (const QString &file : l) { QString fname = dir.path() + QLatin1String("/inlined/") + file + QLatin1String(".html"); if (!QFile::exists(fname)) { fname = dir.path() + QLatin1Char('/') + file + QLatin1String(".html"); if (!QFile::exists(fname)) { continue; } } QTest::newRow(file.toLatin1().constData()) << file << fname << QString(file + QStringLiteral( ".out")) << QStringLiteral("inlined") << false << QString(); } } void RenderTest::testRenderInlined() { testRender(); } void RenderTest::testRenderIconic_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); for (const QString &file : l) { QString fname = dir.path() + QLatin1String("/iconic/") + file + QLatin1String(".html"); if (!QFile::exists(fname)) { fname = dir.path() + QLatin1Char('/') + file + QLatin1String(".html"); if (!QFile::exists(fname)) { continue; } } QTest::newRow(file.toLatin1().constData()) << file << fname << QString(file + QStringLiteral( ".out")) << QStringLiteral("iconic") << false << QString(); } } void RenderTest::testRenderIconic() { testRender(); } void RenderTest::testRenderHidden_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); for (const QString &file : l) { QString fname = dir.path() + QLatin1String("/hidden/") + file + QLatin1String(".html"); if (!QFile::exists(fname)) { fname = dir.path() + QLatin1Char('/') + file + QLatin1String(".html"); if (!QFile::exists(fname)) { continue; } } QTest::newRow(file.toLatin1().constData()) << file << fname << QString(file + QStringLiteral( ".out")) << QStringLiteral("hidden") << false << QString(); } } void RenderTest::testRenderHidden() { testRender(); } void RenderTest::testRenderHeaderOnly_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); for (const QString &file : l) { QString fname = dir.path() + QLatin1String("/headeronly/") + file + QStringLiteral(".html"); if (!QFile::exists(fname)) { fname = dir.path() + QLatin1Char('/') + file + QLatin1String(".html"); if (!QFile::exists(fname)) { continue; } } QTest::newRow(file.toLatin1().constData()) << file << fname << QString(file + QStringLiteral( ".out")) << QStringLiteral("headeronly") << false << QString(); } } void RenderTest::testRenderHeaderOnly() { testRender(); } QString renderTreeHelper(const MimeTreeParser::MessagePart::Ptr &messagePart, QString indent) { const QString line = QStringLiteral("%1 * %3\n").arg(indent, QString::fromUtf8(messagePart->metaObject()->className())); QString ret = line; indent += QLatin1Char(' '); foreach (const auto &subPart, messagePart->subParts()) { ret += renderTreeHelper(subPart, indent); } return ret; } void RenderTest::testRenderTree(const MimeTreeParser::MessagePart::Ptr &messagePart) { QString renderedTree = renderTreeHelper(messagePart, QString()); QFETCH(QString, mailFileName); QFETCH(QString, outFileName); const QString treeFileName = QLatin1String(MAIL_DATA_DIR) + QLatin1Char('/') + mailFileName + QStringLiteral(".tree"); const QString outTreeFileName = outFileName + QStringLiteral(".tree"); { QFile f(outTreeFileName); f.open(QIODevice::WriteOnly); f.write(renderedTree.toUtf8()); f.close(); } // compare to reference file const QStringList args = QStringList() << QStringLiteral("-u") << treeFileName << outTreeFileName; QProcess proc; proc.setProcessChannelMode(QProcess::ForwardedChannels); proc.start(QStringLiteral("diff"), args); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); } void RenderTest::testRender() { QFETCH(QString, mailFileName); QFETCH(QString, referenceFileName); QFETCH(QString, outFileName); QFETCH(QString, attachmentStrategy); QFETCH(bool, showSignatureDetails); QFETCH(QString, asyncFileName); const QString htmlFileName = outFileName + QStringLiteral(".html"); const bool bAsync = !asyncFileName.isEmpty(); // load input mail const KMime::Message::Ptr msg(Test::readAndParseMail(mailFileName)); // render the mail FileHtmlWriter fileWriter(outFileName); QImage paintDevice; Test::TestCSSHelper cssHelper(&paintDevice); MimeTreeParser::NodeHelper nodeHelper; Test::ObjectTreeSource testSource(&fileWriter, &cssHelper); testSource.setAllowDecryption(true); testSource.setAttachmentStrategy(attachmentStrategy); testSource.setShowSignatureDetails(showSignatureDetails); QEventLoop loop; MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper); connect(&nodeHelper, &MimeTreeParser::NodeHelper::update, &loop, &QEventLoop::quit); otp.setAllowAsync(bAsync); otp.parseObjectTree(msg.data()); fileWriter.begin(); fileWriter.write(cssHelper.htmlHead(false)); testSource.render(otp.parsedPart(), false); fileWriter.write(QStringLiteral("")); fileWriter.end(); if (!bAsync) { testRenderTree(otp.parsedPart()); } else { Test::compareFile(outFileName, asyncFileName); loop.exec(); MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper); otp.setAllowAsync(bAsync); otp.parseObjectTree(msg.data()); fileWriter.begin(); fileWriter.write(cssHelper.htmlHead(false)); testSource.render(otp.parsedPart(), false); fileWriter.write(QStringLiteral("")); fileWriter.end(); testRenderTree(otp.parsedPart()); } Test::compareFile(outFileName, referenceFileName); } QTEST_MAIN(RenderTest) diff --git a/mimetreeparser/autotests/data/alternative-notext.mbox.html b/mimetreeparser/autotests/data/alternative-notext.mbox.html index 41db4eab..6c3619b4 100644 --- a/mimetreeparser/autotests/data/alternative-notext.mbox.html +++ b/mimetreeparser/autotests/data/alternative-notext.mbox.html @@ -1,17 +1,20 @@ diff --git a/mimetreeparser/autotests/data/alternative.mbox.html b/mimetreeparser/autotests/data/alternative.mbox.html index 2fe886f1..0a83df46 100644 --- a/mimetreeparser/autotests/data/alternative.mbox.html +++ b/mimetreeparser/autotests/data/alternative.mbox.html @@ -1,17 +1,20 @@ diff --git a/mimetreeparser/autotests/data/headeronly/smime-signed-apple.mbox.html b/mimetreeparser/autotests/data/headeronly/smime-signed-apple.mbox.html index 27ebdaf5..5e8ff550 100644 --- a/mimetreeparser/autotests/data/headeronly/smime-signed-apple.mbox.html +++ b/mimetreeparser/autotests/data/headeronly/smime-signed-apple.mbox.html @@ -1,55 +1,61 @@ diff --git a/mimetreeparser/autotests/data/hidden/openpgp-signed-apple.mbox.html b/mimetreeparser/autotests/data/hidden/openpgp-signed-apple.mbox.html index 330b02a1..c17d3331 100644 --- a/mimetreeparser/autotests/data/hidden/openpgp-signed-apple.mbox.html +++ b/mimetreeparser/autotests/data/hidden/openpgp-signed-apple.mbox.html @@ -1,50 +1,56 @@ diff --git a/mimetreeparser/autotests/data/hidden/smime-signed-apple.mbox.html b/mimetreeparser/autotests/data/hidden/smime-signed-apple.mbox.html index 27ebdaf5..5e8ff550 100644 --- a/mimetreeparser/autotests/data/hidden/smime-signed-apple.mbox.html +++ b/mimetreeparser/autotests/data/hidden/smime-signed-apple.mbox.html @@ -1,55 +1,61 @@ diff --git a/mimetreeparser/autotests/data/html-multipart-related.mbox.html b/mimetreeparser/autotests/data/html-multipart-related.mbox.html index cac75276..084a5836 100644 --- a/mimetreeparser/autotests/data/html-multipart-related.mbox.html +++ b/mimetreeparser/autotests/data/html-multipart-related.mbox.html @@ -1,18 +1,21 @@ diff --git a/mimetreeparser/autotests/data/html.mbox.html b/mimetreeparser/autotests/data/html.mbox.html index 2fe886f1..0a83df46 100644 --- a/mimetreeparser/autotests/data/html.mbox.html +++ b/mimetreeparser/autotests/data/html.mbox.html @@ -1,17 +1,20 @@ diff --git a/mimetreeparser/autotests/data/htmlonly.mbox.html b/mimetreeparser/autotests/data/htmlonly.mbox.html index 1143f2cf..4a1db930 100644 --- a/mimetreeparser/autotests/data/htmlonly.mbox.html +++ b/mimetreeparser/autotests/data/htmlonly.mbox.html @@ -1,12 +1,15 @@ diff --git a/mimetreeparser/autotests/data/inlined/openpgp-signed-apple.mbox.html b/mimetreeparser/autotests/data/inlined/openpgp-signed-apple.mbox.html index 092d5e1c..c17d3331 100644 --- a/mimetreeparser/autotests/data/inlined/openpgp-signed-apple.mbox.html +++ b/mimetreeparser/autotests/data/inlined/openpgp-signed-apple.mbox.html @@ -1,63 +1,56 @@ diff --git a/mimetreeparser/autotests/data/inlined/smime-signed-apple.mbox.html b/mimetreeparser/autotests/data/inlined/smime-signed-apple.mbox.html index 2c209a4f..5e8ff550 100644 --- a/mimetreeparser/autotests/data/inlined/smime-signed-apple.mbox.html +++ b/mimetreeparser/autotests/data/inlined/smime-signed-apple.mbox.html @@ -1,68 +1,61 @@ diff --git a/mimetreeparser/autotests/data/openpgp-signed-apple.mbox.html b/mimetreeparser/autotests/data/openpgp-signed-apple.mbox.html index 234eaae4..c17d3331 100644 --- a/mimetreeparser/autotests/data/openpgp-signed-apple.mbox.html +++ b/mimetreeparser/autotests/data/openpgp-signed-apple.mbox.html @@ -1,58 +1,56 @@ diff --git a/mimetreeparser/autotests/data/smime-signed-apple.mbox.html b/mimetreeparser/autotests/data/smime-signed-apple.mbox.html index 2fbda399..5e8ff550 100644 --- a/mimetreeparser/autotests/data/smime-signed-apple.mbox.html +++ b/mimetreeparser/autotests/data/smime-signed-apple.mbox.html @@ -1,63 +1,61 @@ diff --git a/mimetreeparser/autotests/data/text+html-maillinglist.mbox.html b/mimetreeparser/autotests/data/text+html-maillinglist.mbox.html index 2b5af631..f19b5edf 100644 --- a/mimetreeparser/autotests/data/text+html-maillinglist.mbox.html +++ b/mimetreeparser/autotests/data/text+html-maillinglist.mbox.html @@ -1,38 +1,41 @@