summaryrefslogtreecommitdiffstats
path: root/framework/domain/mimetreeparser/tests/interfacetest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp')
-rw-r--r--framework/domain/mimetreeparser/tests/interfacetest.cpp157
1 files changed, 157 insertions, 0 deletions
diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp
new file mode 100644
index 00000000..83de97f7
--- /dev/null
+++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp
@@ -0,0 +1,157 @@
1/*
2 Copyright (c) 2016 Sandro Knauß <knauss@kolabsystems.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "interface.h"
21#include "interface_p.h"
22
23#include <QTest>
24
25QByteArray readMailFromFile(const QString &mailFile)
26{
27 QFile file(QLatin1String(MAIL_DATA_DIR) + QLatin1Char('/') + mailFile);
28 file.open(QIODevice::ReadOnly);
29 Q_ASSERT(file.isOpen());
30 return file.readAll();
31}
32
33
34class InterfaceTest : public QObject
35{
36 Q_OBJECT
37private:
38 void printTree(const Part::Ptr &start, QString pre)
39 {
40 foreach (const auto &part, start->subParts()) {
41 qWarning() << QStringLiteral("%1* %2").arg(pre).arg(QString::fromLatin1(part->type()));
42 printTree(part,pre + QStringLiteral(" "));
43 }
44 }
45
46private slots:
47
48 void testTextMail()
49 {
50 Parser parser(readMailFromFile("plaintext.mbox"));
51 auto contentPartList = parser.collectContentParts();
52 QCOMPARE(contentPartList.size(), 1);
53 auto contentPart = contentPartList[0];
54 QVERIFY((bool)contentPart);
55 QCOMPARE(contentPart->availableContents(), QVector<QByteArray>() << "plaintext");
56 auto contentList = contentPart->content("plaintext");
57 QCOMPARE(contentList.size(), 1);
58 QCOMPARE(contentList[0]->content(), QStringLiteral("If you can see this text it means that your email client couldn't display our newsletter properly.\nPlease visit this link to view the newsletter on our website: http://www.gog.com/newsletter/").toLocal8Bit());
59 QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit());
60 QCOMPARE(contentList[0]->encryptions().size(), 0);
61 QCOMPARE(contentList[0]->signatures().size(), 0);
62
63 contentList = contentPart->content("html");
64 QCOMPARE(contentList.size(), 0);
65 }
66
67 void testTextAlternative()
68 {
69 Parser parser(readMailFromFile("alternative.mbox"));
70 auto contentPartList = parser.collectContentParts();
71 QCOMPARE(contentPartList.size(), 1);
72 auto contentPart = contentPartList[0];
73 QVERIFY((bool)contentPart);
74 QCOMPARE(contentPart->availableContents(), QVector<QByteArray>() << "html" << "plaintext");
75 auto contentList = contentPart->content("plaintext");
76 QCOMPARE(contentList.size(), 1);
77 QCOMPARE(contentList[0]->content(), QStringLiteral("If you can see this text it means that your email client couldn't display our newsletter properly.\nPlease visit this link to view the newsletter on our website: http://www.gog.com/newsletter/\n").toLocal8Bit());
78 QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit());
79 QCOMPARE(contentList[0]->encryptions().size(), 0);
80 QCOMPARE(contentList[0]->signatures().size(), 0);
81
82 contentList = contentPart->content("html");
83 QCOMPARE(contentList.size(), 1);
84 QCOMPARE(contentList[0]->content(), QStringLiteral("<html><body><p><span>HTML</span> text</p></body></html>\n\n").toLocal8Bit());
85 QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit());
86 QCOMPARE(contentList[0]->encryptions().size(), 0);
87 QCOMPARE(contentList[0]->signatures().size(), 0);
88 }
89
90 void testTextHtml()
91 {
92 Parser parser(readMailFromFile("html.mbox"));
93 auto contentPartList = parser.collectContentParts();
94 QCOMPARE(contentPartList.size(), 1);
95 auto contentPart = contentPartList[0];
96 QVERIFY((bool)contentPart);
97 QCOMPARE(contentPart->availableContents(), QVector<QByteArray>() << "html");
98
99 auto contentList = contentPart->content("plaintext");
100 QCOMPARE(contentList.size(), 0);
101
102 contentList = contentPart->content("html");
103 QCOMPARE(contentList.size(), 1);
104 QCOMPARE(contentList[0]->content(), QStringLiteral("<html><body><p><span>HTML</span> text</p></body></html>").toLocal8Bit());
105 QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit());
106 QCOMPARE(contentList[0]->encryptions().size(), 0);
107 QCOMPARE(contentList[0]->signatures().size(), 0);
108 }
109
110 void testSMimeEncrypted()
111 {
112 Parser parser(readMailFromFile("smime-encrypted.mbox"));
113 printTree(parser.d->mTree,QString());
114 auto contentPartList = parser.collectContentParts();
115 QCOMPARE(contentPartList.size(), 1);
116 auto contentPart = contentPartList[0];
117 QVERIFY((bool)contentPart);
118 QCOMPARE(contentPart->availableContents(), QVector<QByteArray>() << "plaintext");
119 auto contentList = contentPart->content("plaintext");
120 QCOMPARE(contentList.size(), 1);
121 QCOMPARE(contentList[0]->content(), QStringLiteral("The quick brown fox jumped over the lazy dog.").toLocal8Bit());
122 QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit());
123 }
124
125 void testOpenPGPEncryptedAttachment()
126 {
127 Parser parser(readMailFromFile("openpgp-encrypted-attachment-and-non-encrypted-attachment.mbox"));
128 printTree(parser.d->mTree,QString());
129 auto contentPartList = parser.collectContentParts();
130 QCOMPARE(contentPartList.size(), 1);
131 auto contentPart = contentPartList[0];
132 QVERIFY((bool)contentPart);
133 QCOMPARE(contentPart->availableContents(), QVector<QByteArray>() << "plaintext");
134 auto contentList = contentPart->content("plaintext");
135 QCOMPARE(contentList.size(), 1);
136 QCOMPARE(contentList[0]->content(), QStringLiteral("test text").toLocal8Bit());
137 QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit());
138 }
139
140 void testOpenPPGInline()
141 {
142 Parser parser(readMailFromFile("openpgp-inline-charset-encrypted.mbox"));
143 printTree(parser.d->mTree,QString());
144 auto contentPartList = parser.collectContentParts();
145 QCOMPARE(contentPartList.size(), 1);
146 auto contentPart = contentPartList[0];
147 QVERIFY((bool)contentPart);
148 QCOMPARE(contentPart->availableContents(), QVector<QByteArray>() << "plaintext");
149 auto contentList = contentPart->content("plaintext");
150 QCOMPARE(contentList.size(), 1);
151 QCOMPARE(contentList[0]->content(), QStringLiteral("asdasd asd asd asdf sadf sdaf sadf äöü").toLocal8Bit());
152 QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit());
153 }
154};
155
156QTEST_GUILESS_MAIN(InterfaceTest)
157#include "interfacetest.moc" \ No newline at end of file