Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

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

Add tests for showOnlyOneMimePart to not change the behaviour.

parent 7edbb2e3
......@@ -28,6 +28,12 @@ ecm_add_test(quotehtmltest.cpp setupenv.cpp ../plugins/quotehtml.cpp
LINK_LIBRARIES Qt5::Test KF5::MessageViewer KF5::IconThemes KF5::Mime
)
ecm_add_test(showonlymimeparttest.cpp setupenv.cpp util.cpp testcsshelper.cpp
TEST_NAME showonlymimeparttest
NAME_PREFIX "messageviewer-messageparttheme-"
LINK_LIBRARIES Qt5::Test KF5::MessageViewer KF5::IconThemes KF5::Mime KF5::GrantleeTheme
)
ecm_add_test(converthtmltoplaintexttest.cpp ../converthtmltoplaintext.cpp
TEST_NAME converthtmltoplaintexttest
NAME_PREFIX "messageviewer-messageparttheme-"
......
/*
Copyright (c) 2017 Sandro Knauß <sknauss@kde.org>
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
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
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. If not, see <http://www.gnu.org/licenses/>.
*/
#include "showonlymimeparttest.h"
#include "util.h"
#include "setupenv.h"
#include "testcsshelper.h"
#include <MimeTreeParser/FileHtmlWriter>
#include <MimeTreeParser/ObjectTreeParser>
#include <MimeTreeParser/MessagePart>
#include <QString>
#include <QTest>
using namespace MessageViewer;
void ShowOnlyMimePartTest::initTestCase()
{
Test::setupEnv();
}
void ShowOnlyMimePartTest::testDrawFrame_data()
{
QTest::addColumn<int>("content");
QTest::addColumn<bool>("showOnlyMimePart");
QTest::newRow("only first part") << 0 << true;
QTest::newRow("only first part - render complete") << 0 << false;
QTest::newRow("only second part") << 1 << true;
QTest::newRow("only second part - render complete") << 1 << false;
QTest::newRow("only third part") << 2 << true;
QTest::newRow("only third part - render complete") << 2 << false;
}
void ShowOnlyMimePartTest::testDrawFrame()
{
QFETCH(int, content);
QFETCH(bool, showOnlyMimePart);
QString commonName(QStringLiteral("frametest.mbox.html.content.") + QString::number(content)
+ ((showOnlyMimePart)?QStringLiteral(".single"):QStringLiteral(".full")));
QString outFileName(commonName);
QString referenceFileName(QStringLiteral(MAIL_DATA_DIR) + QLatin1Char('/') + commonName);
// load input mail
const KMime::Message::Ptr msg(Test::readAndParseMail(QStringLiteral("frametest.mbox")));
// render the mail
MimeTreeParser::FileHtmlWriter fileWriter(outFileName);
QImage paintDevice;
Test::TestCSSHelper cssHelper(&paintDevice);
MimeTreeParser::NodeHelper nodeHelper;
Test::ObjectTreeSource testSource(&fileWriter, &cssHelper);
MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper, showOnlyMimePart);
fileWriter.begin();
fileWriter.write(cssHelper.htmlHead(false));
QVERIFY(msg->contents().size() > content);
otp.parseObjectTree(msg->contents().at(content));
fileWriter.write(QStringLiteral("</body></html>"));
fileWriter.end();
Test::compareFile(outFileName, referenceFileName);
}
void ShowOnlyMimePartTest::testRelated_data()
{
QTest::addColumn<int>("content");
QTest::addColumn<bool>("showOnlyMimePart");
QTest::newRow("only html") << 0 << true;
QTest::newRow("only html - render complete") << 0 << false;
QTest::newRow("only image") << 1 << true;
QTest::newRow("only image - render complete") << 1 << false;
}
void ShowOnlyMimePartTest::testRelated()
{
QFETCH(int, content);
QFETCH(bool, showOnlyMimePart);
QString commonName(QStringLiteral("html-multipart-related.mbox.html.content.") + QString::number(content)
+ ((showOnlyMimePart)?QStringLiteral(".single"):QStringLiteral(".full")));
QString outFileName(commonName);
QString referenceFileName(QStringLiteral(MAIL_DATA_DIR) + QLatin1Char('/') + commonName);
// load input mail
const KMime::Message::Ptr msg(Test::readAndParseMail(QStringLiteral("html-multipart-related.mbox")));
// render the mail
MimeTreeParser::FileHtmlWriter fileWriter(outFileName);
QImage paintDevice;
Test::TestCSSHelper cssHelper(&paintDevice);
MimeTreeParser::NodeHelper nodeHelper;
Test::ObjectTreeSource testSource(&fileWriter, &cssHelper);
MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper, showOnlyMimePart);
fileWriter.begin();
fileWriter.write(cssHelper.htmlHead(false));
QVERIFY(msg->contents().size()> content);
otp.parseObjectTree(msg->contents().at(content));
fileWriter.write(QStringLiteral("</body></html>"));
fileWriter.end();
Test::compareFile(outFileName, referenceFileName);
}
QTEST_MAIN(ShowOnlyMimePartTest)
/*
Copyright (c) 2017 Sandro Knauß <sknauss@kde.org>
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
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
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. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MESSAGEVIEWER_TEST_SHOWONLYMIMEPARTTEST_H__
#define __MESSAGEVIEWER_TEST_SHOWONLYMIMEPARTTEST_H__
#include <QObject>
class ShowOnlyMimePartTest : public QObject
{
Q_OBJECT
public Q_SLOTS:
void initTestCase();
private Q_SLOTS:
void testDrawFrame_data();
void testDrawFrame();
void testRelated_data();
void testRelated();
};
#endif
From: Volker Krause <vkrause@kde.org>
To: vkrause@kde.org
Subject: text attachments trying to mess up escaping
Date: Tue, 03 Oct 2017 12:21:24 +0200
Message-ID: <1807613.y0QX81sLpY@vkpc5>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="nextPart2107984.jr9reY14Qx"
Content-Transfer-Encoding: 7Bit
This is a multi-part message in MIME format.
--nextPart2107984.jr9reY14Qx
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="us-ascii"
hello, this is the body
--nextPart2107984.jr9reY14Qx
Content-Disposition: inline; filename="messages.sh"
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="utf-8"; name="messages.sh"
#! /bin/sh
$XGETTEXT `find . -name '*.cpp' -o -name '*.h' | grep -v '/tests/' | grep -v '/autotests/'` -o $podir/libmimetreeparser.pot
--nextPart2107984.jr9reY14Qx
Content-Disposition: inline
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="utf-8"
maintainer:
description: MimeTreeParser Library
tier: 3
type: functional
platforms:
- name: All
portingAid: false
deprecated: false
release: false
libraries:
- qmake: MimeTreeParser
cmake: "KF5::MimeTreeParser"
cmakename: KF5MimeTreeParser
--nextPart2107984.jr9reY14Qx--
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<a name="att1"/>
<div id="attachmentDiv1">
<div class="noquote">
<div dir="ltr">hello, this is the body</div>
</div>
</div>
<a name="att2"/>
<div id="attachmentDiv2">
<table cellspacing="1" class="textAtm">
<tr class="textAtmH">
<td dir="ltr">
<a href="attachment:2?place=body">messages.sh</a>
</td>
</tr>
<tr class="textAtmB">
<td>
<div class="noquote">
<div dir="ltr">#! /bin/sh</div>
<div dir="ltr">$XGETTEXT `find . -name '*.cpp' -o -name '*.h' | grep -v '/tests/' | grep -v '/autotests/'` -o $podir/libmimetreeparser.pot</div>
</div>
</td>
</tr>
</table>
</div>
<a name="att3"/>
<div id="attachmentDiv3">
<div class="noquote">
<div dir="ltr">maintainer:</div>
<div dir="ltr">description: MimeTreeParser Library&nbsp;</div>
<div dir="ltr">tier: 3</div>
<div dir="ltr">type: functional</div>
<div dir="ltr">platforms:</div>
<div dir="ltr">&nbsp;&nbsp;&nbsp;&nbsp;- name: All</div>
<div dir="ltr">portingAid: false</div>
<div dir="ltr">deprecated: false</div>
<div dir="ltr">release: false</div>
<div dir="ltr">libraries:</div>
<div dir="ltr">&nbsp;- qmake: MimeTreeParser</div>
<div dir="ltr">&nbsp;&nbsp;&nbsp;cmake: "KF5::MimeTreeParser"</div>
<div dir="ltr">&nbsp;&nbsp;&nbsp;cmakename: KF5MimeTreeParser</div>
</div>
</div>
</body>
</html>
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<a name="att1"/>
<div id="attachmentDiv1">
<div class="noquote">
<div dir="ltr">hello, this is the body</div>
</div>
</div>
</body>
</html>
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<a name="att2"/>
<div id="attachmentDiv2">
<table cellspacing="1" class="textAtm">
<tr class="textAtmH">
<td dir="ltr">
<a href="attachment:2?place=body">messages.sh</a>
</td>
</tr>
<tr class="textAtmB">
<td>
<div class="noquote">
<div dir="ltr">#! /bin/sh</div>
<div dir="ltr">$XGETTEXT `find . -name '*.cpp' -o -name '*.h' | grep -v '/tests/' | grep -v '/autotests/'` -o $podir/libmimetreeparser.pot</div>
</div>
</td>
</tr>
</table>
</div>
<a name="att3"/>
<div id="attachmentDiv3">
<div class="noquote">
<div dir="ltr">maintainer:</div>
<div dir="ltr">description: MimeTreeParser Library&nbsp;</div>
<div dir="ltr">tier: 3</div>
<div dir="ltr">type: functional</div>
<div dir="ltr">platforms:</div>
<div dir="ltr">&nbsp;&nbsp;&nbsp;&nbsp;- name: All</div>
<div dir="ltr">portingAid: false</div>
<div dir="ltr">deprecated: false</div>
<div dir="ltr">release: false</div>
<div dir="ltr">libraries:</div>
<div dir="ltr">&nbsp;- qmake: MimeTreeParser</div>
<div dir="ltr">&nbsp;&nbsp;&nbsp;cmake: "KF5::MimeTreeParser"</div>
<div dir="ltr">&nbsp;&nbsp;&nbsp;cmakename: KF5MimeTreeParser</div>
</div>
</div>
</body>
</html>
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<a name="att2"/>
<div id="attachmentDiv2">
<div class="noquote">
<div dir="ltr">#! /bin/sh</div>
<div dir="ltr">$XGETTEXT `find . -name '*.cpp' -o -name '*.h' | grep -v '/tests/' | grep -v '/autotests/'` -o $podir/libmimetreeparser.pot</div>
</div>
</div>
</body>
</html>
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<a name="att3"/>
<div id="attachmentDiv3">
<div class="noquote">
<div dir="ltr">maintainer:</div>
<div dir="ltr">description: MimeTreeParser Library&nbsp;</div>
<div dir="ltr">tier: 3</div>
<div dir="ltr">type: functional</div>
<div dir="ltr">platforms:</div>
<div dir="ltr">&nbsp;&nbsp;&nbsp;&nbsp;- name: All</div>
<div dir="ltr">portingAid: false</div>
<div dir="ltr">deprecated: false</div>
<div dir="ltr">release: false</div>
<div dir="ltr">libraries:</div>
<div dir="ltr">&nbsp;- qmake: MimeTreeParser</div>
<div dir="ltr">&nbsp;&nbsp;&nbsp;cmake: "KF5::MimeTreeParser"</div>
<div dir="ltr">&nbsp;&nbsp;&nbsp;cmakename: KF5MimeTreeParser</div>
</div>
</div>
</body>
</html>
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<a name="att3"/>
<div id="attachmentDiv3">
<div class="noquote">
<div dir="ltr">maintainer:</div>
<div dir="ltr">description: MimeTreeParser Library&nbsp;</div>
<div dir="ltr">tier: 3</div>
<div dir="ltr">type: functional</div>
<div dir="ltr">platforms:</div>
<div dir="ltr">&nbsp;&nbsp;&nbsp;&nbsp;- name: All</div>
<div dir="ltr">portingAid: false</div>
<div dir="ltr">deprecated: false</div>
<div dir="ltr">release: false</div>
<div dir="ltr">libraries:</div>
<div dir="ltr">&nbsp;- qmake: MimeTreeParser</div>
<div dir="ltr">&nbsp;&nbsp;&nbsp;cmake: "KF5::MimeTreeParser"</div>
<div dir="ltr">&nbsp;&nbsp;&nbsp;cmakename: KF5MimeTreeParser</div>
</div>
</div>
</body>
</html>
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<!-- embedPart(contentID=uniqueid, url=file:///tmp/messageviewer.index.2/image.png) -->
<a name="att1"/>
<div id="attachmentDiv1">
<div style="position: relative">
<p> some random text :) <img src="cid:uniqueid"/> </p>
</div>
</div>
</body>
</html>
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<a name="att1"/>
<div id="attachmentDiv1">
<div style="position: relative">
<p> some random text :) <img src="cid:uniqueid"/> </p>
</div>
</div>
</body>
</html>
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<!-- embedPart(contentID=uniqueid, url=file:///tmp/messageviewer.index.2/image.png) -->
</body>
</html>
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<a name="att2"/>
<div id="attachmentDiv2">
<hr/>
<div>
<a href="attachment:2?place=body">
<img align="center" src="file:image.png" border="0" style="max-width: 100%"/>
</a>
</div>
<div>
<a href="attachment:2?place=body">image.png</a>
</div>
<div/>
</div>
</body>
</html>
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