diff --git a/messageviewer/src/messagepartthemes/default/autotests/CMakeLists.txt b/messageviewer/src/messagepartthemes/default/autotests/CMakeLists.txt index 3923558a..62c006a3 100644 --- a/messageviewer/src/messagepartthemes/default/autotests/CMakeLists.txt +++ b/messageviewer/src/messagepartthemes/default/autotests/CMakeLists.txt @@ -1,35 +1,41 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) add_definitions( -DMAIL_DATA_DIR="${CMAKE_SOURCE_DIR}/mimetreeparser/autotests/data" ) include(${CMAKE_SOURCE_DIR}/cmake/modules/kdepim_add_gpg_crypto_test.cmake) macro(add_messageviewer_crypto_unittest _source) set(_test ${_source} util.cpp) get_filename_component(_name ${_source} NAME_WE) add_executable( ${_name} ${_test} setupenv.cpp testcsshelper.cpp ) ecm_mark_as_test(messageviewer-messageparttheme-${_name}) target_link_libraries( ${_name} KF5::MessageViewer Qt5::Test KF5::IconThemes KF5::Mime KF5::GrantleeTheme ) add_gpg_crypto_test(${_name} messageviewer-messageparttheme-${_name}) endmacro () add_messageviewer_crypto_unittest(objecttreeparsertest.cpp) add_messageviewer_crypto_unittest(rendertest.cpp) add_messageviewer_crypto_unittest(unencryptedmessagetest.cpp) ecm_add_test(quotehtmltest.cpp setupenv.cpp ../plugins/quotehtml.cpp TEST_NAME quotehtmltest NAME_PREFIX "messageviewer-messageparttheme-" 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-" LINK_LIBRARIES Qt5::Test Grantlee5::TextDocument ) diff --git a/messageviewer/src/messagepartthemes/default/autotests/showonlymimeparttest.cpp b/messageviewer/src/messagepartthemes/default/autotests/showonlymimeparttest.cpp new file mode 100644 index 00000000..aeba9a41 --- /dev/null +++ b/messageviewer/src/messagepartthemes/default/autotests/showonlymimeparttest.cpp @@ -0,0 +1,137 @@ +/* + Copyright (c) 2017 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 + 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 . +*/ + +#include "showonlymimeparttest.h" + +#include "util.h" +#include "setupenv.h" +#include "testcsshelper.h" + +#include +#include +#include + +#include +#include + +using namespace MessageViewer; + +void ShowOnlyMimePartTest::initTestCase() +{ + Test::setupEnv(); +} + +void ShowOnlyMimePartTest::testDrawFrame_data() +{ + QTest::addColumn("content"); + QTest::addColumn("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("")); + fileWriter.end(); + + Test::compareFile(outFileName, referenceFileName); +} + +void ShowOnlyMimePartTest::testRelated_data() +{ + QTest::addColumn("content"); + QTest::addColumn("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("")); + fileWriter.end(); + + Test::compareFile(outFileName, referenceFileName); +} + +QTEST_MAIN(ShowOnlyMimePartTest) diff --git a/messageviewer/src/messagepartthemes/default/autotests/showonlymimeparttest.h b/messageviewer/src/messagepartthemes/default/autotests/showonlymimeparttest.h new file mode 100644 index 00000000..e92f3bef --- /dev/null +++ b/messageviewer/src/messagepartthemes/default/autotests/showonlymimeparttest.h @@ -0,0 +1,41 @@ +/* + Copyright (c) 2017 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 + 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 . +*/ + +#ifndef __MESSAGEVIEWER_TEST_SHOWONLYMIMEPARTTEST_H__ +#define __MESSAGEVIEWER_TEST_SHOWONLYMIMEPARTTEST_H__ + +#include + +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 diff --git a/mimetreeparser/autotests/data/frametest.mbox b/mimetreeparser/autotests/data/frametest.mbox new file mode 100644 index 00000000..5169032d --- /dev/null +++ b/mimetreeparser/autotests/data/frametest.mbox @@ -0,0 +1,43 @@ +From: Volker Krause +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-- diff --git a/mimetreeparser/autotests/data/frametest.mbox.html.content.0.full b/mimetreeparser/autotests/data/frametest.mbox.html.content.0.full new file mode 100644 index 00000000..ef7abb7b --- /dev/null +++ b/mimetreeparser/autotests/data/frametest.mbox.html.content.0.full @@ -0,0 +1,48 @@ + + + + + +
+
+
hello, this is the body
+
+
+
+
+ + + + + + + +
+ messages.sh +
+
+
#! /bin/sh
+
$XGETTEXT `find . -name '*.cpp' -o -name '*.h' | grep -v '/tests/' | grep -v '/autotests/'` -o $podir/libmimetreeparser.pot
+
+
+
+
+
+
+
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
+
+
+ + diff --git a/mimetreeparser/autotests/data/frametest.mbox.html.content.0.single b/mimetreeparser/autotests/data/frametest.mbox.html.content.0.single new file mode 100644 index 00000000..f8415f82 --- /dev/null +++ b/mimetreeparser/autotests/data/frametest.mbox.html.content.0.single @@ -0,0 +1,12 @@ + + + + +
+
+
+
hello, this is the body
+
+
+ + diff --git a/mimetreeparser/autotests/data/frametest.mbox.html.content.1.full b/mimetreeparser/autotests/data/frametest.mbox.html.content.1.full new file mode 100644 index 00000000..be9c9710 --- /dev/null +++ b/mimetreeparser/autotests/data/frametest.mbox.html.content.1.full @@ -0,0 +1,42 @@ + + + + +
+
+ + + + + + + +
+ messages.sh +
+
+
#! /bin/sh
+
$XGETTEXT `find . -name '*.cpp' -o -name '*.h' | grep -v '/tests/' | grep -v '/autotests/'` -o $podir/libmimetreeparser.pot
+
+
+
+
+
+
+
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
+
+
+ + diff --git a/mimetreeparser/autotests/data/frametest.mbox.html.content.1.single b/mimetreeparser/autotests/data/frametest.mbox.html.content.1.single new file mode 100644 index 00000000..e04d9f25 --- /dev/null +++ b/mimetreeparser/autotests/data/frametest.mbox.html.content.1.single @@ -0,0 +1,13 @@ + + + + +
+
+
+
#! /bin/sh
+
$XGETTEXT `find . -name '*.cpp' -o -name '*.h' | grep -v '/tests/' | grep -v '/autotests/'` -o $podir/libmimetreeparser.pot
+
+
+ + diff --git a/mimetreeparser/autotests/data/frametest.mbox.html.content.2.full b/mimetreeparser/autotests/data/frametest.mbox.html.content.2.full new file mode 100644 index 00000000..47bdcdc5 --- /dev/null +++ b/mimetreeparser/autotests/data/frametest.mbox.html.content.2.full @@ -0,0 +1,24 @@ + + + + +
+
+
+
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
+
+
+ + diff --git a/mimetreeparser/autotests/data/frametest.mbox.html.content.2.single b/mimetreeparser/autotests/data/frametest.mbox.html.content.2.single new file mode 100644 index 00000000..47bdcdc5 --- /dev/null +++ b/mimetreeparser/autotests/data/frametest.mbox.html.content.2.single @@ -0,0 +1,24 @@ + + + + +
+
+
+
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
+
+
+ + diff --git a/mimetreeparser/autotests/data/html-multipart-related.mbox.html.content.0.full b/mimetreeparser/autotests/data/html-multipart-related.mbox.html.content.0.full new file mode 100644 index 00000000..888a9a4d --- /dev/null +++ b/mimetreeparser/autotests/data/html-multipart-related.mbox.html.content.0.full @@ -0,0 +1,13 @@ + + + + + +
+
+
+

some random text :)

+
+
+ + diff --git a/mimetreeparser/autotests/data/html-multipart-related.mbox.html.content.0.single b/mimetreeparser/autotests/data/html-multipart-related.mbox.html.content.0.single new file mode 100644 index 00000000..cdd90c6a --- /dev/null +++ b/mimetreeparser/autotests/data/html-multipart-related.mbox.html.content.0.single @@ -0,0 +1,12 @@ + + + + +
+
+
+

some random text :)

+
+
+ + diff --git a/mimetreeparser/autotests/data/html-multipart-related.mbox.html.content.1.full b/mimetreeparser/autotests/data/html-multipart-related.mbox.html.content.1.full new file mode 100644 index 00000000..78358ffc --- /dev/null +++ b/mimetreeparser/autotests/data/html-multipart-related.mbox.html.content.1.full @@ -0,0 +1,7 @@ + + + + + + + diff --git a/mimetreeparser/autotests/data/html-multipart-related.mbox.html.content.1.single b/mimetreeparser/autotests/data/html-multipart-related.mbox.html.content.1.single new file mode 100644 index 00000000..61ed7017 --- /dev/null +++ b/mimetreeparser/autotests/data/html-multipart-related.mbox.html.content.1.single @@ -0,0 +1,19 @@ + + + + +
+
+
+
+
+ image.png +
+
+
+ +