Changeset View
Changeset View
Standalone View
Standalone View
framework/domain/mimetreeparser/tests/interfacetest.cpp
- This file was added.
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 | | ||||
25 | QByteArray 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 | | ||||
34 | class InterfaceTest : public QObject | ||||
35 | { | ||||
36 | Q_OBJECT | ||||
37 | private: | ||||
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 | | ||||
46 | private slots: | ||||
47 | | ||||
48 | void testTextMail() | ||||
49 | { | ||||
50 | Parser parser(readMailFromFile("plaintext.mbox")); | ||||
51 | auto contentPart = parser.collectContentPart(); | ||||
52 | QVERIFY((bool)contentPart); | ||||
53 | QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); | ||||
54 | auto contentList = contentPart->content(ContentPart::PlainText); | ||||
55 | QCOMPARE(contentList.size(), 1); | ||||
56 | 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()); | ||||
57 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | ||||
58 | QCOMPARE(contentList[0]->encryptions().size(), 0); | ||||
59 | QCOMPARE(contentList[0]->signatures().size(), 0); | ||||
60 | | ||||
61 | contentList = contentPart->content(ContentPart::Html); | ||||
62 | QCOMPARE(contentList.size(), 0); | ||||
63 | } | ||||
64 | | ||||
65 | void testTextAlternative() | ||||
66 | { | ||||
67 | Parser parser(readMailFromFile("alternative.mbox")); | ||||
68 | auto contentPart = parser.collectContentPart(); | ||||
69 | QVERIFY((bool)contentPart); | ||||
70 | QCOMPARE(contentPart->availableContents(), ContentPart::PlainText | ContentPart::Html); | ||||
71 | auto contentList = contentPart->content(ContentPart::PlainText); | ||||
72 | QCOMPARE(contentList.size(), 1); | ||||
73 | 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()); | ||||
74 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | ||||
75 | QCOMPARE(contentList[0]->encryptions().size(), 0); | ||||
76 | QCOMPARE(contentList[0]->signatures().size(), 0); | ||||
77 | | ||||
78 | contentList = contentPart->content(ContentPart::Html); | ||||
79 | QCOMPARE(contentList.size(), 1); | ||||
80 | QCOMPARE(contentList[0]->content(), QStringLiteral("<html><body><p><span>HTML</span> text</p></body></html>\n\n").toLocal8Bit()); | ||||
81 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | ||||
82 | QCOMPARE(contentList[0]->encryptions().size(), 0); | ||||
83 | QCOMPARE(contentList[0]->signatures().size(), 0); | ||||
84 | } | ||||
85 | | ||||
86 | void testTextHtml() | ||||
87 | { | ||||
88 | Parser parser(readMailFromFile("html.mbox")); | ||||
89 | auto contentPart = parser.collectContentPart(); | ||||
90 | QVERIFY((bool)contentPart); | ||||
91 | QCOMPARE(contentPart->availableContents(), ContentPart::Html); | ||||
92 | | ||||
93 | auto contentList = contentPart->content(ContentPart::PlainText); | ||||
94 | QCOMPARE(contentList.size(), 0); | ||||
95 | | ||||
96 | contentList = contentPart->content(ContentPart::Html); | ||||
97 | QCOMPARE(contentList.size(), 1); | ||||
98 | QCOMPARE(contentList[0]->content(), QStringLiteral("<html><body><p><span>HTML</span> text</p></body></html>").toLocal8Bit()); | ||||
99 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | ||||
100 | QCOMPARE(contentList[0]->encryptions().size(), 0); | ||||
101 | QCOMPARE(contentList[0]->signatures().size(), 0); | ||||
102 | } | ||||
103 | | ||||
104 | void testSMimeEncrypted() | ||||
105 | { | ||||
106 | Parser parser(readMailFromFile("smime-encrypted.mbox")); | ||||
107 | printTree(parser.d->mTree,QString()); | ||||
108 | auto contentPart = parser.collectContentPart(); | ||||
109 | QVERIFY((bool)contentPart); | ||||
110 | QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); | ||||
111 | auto contentList = contentPart->content(ContentPart::PlainText); | ||||
112 | QCOMPARE(contentList.size(), 1); | ||||
113 | QCOMPARE(contentList[0]->content(), QStringLiteral("The quick brown fox jumped over the lazy dog.").toLocal8Bit()); | ||||
114 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | ||||
115 | } | ||||
116 | | ||||
117 | void testOpenPGPEncryptedAttachment() | ||||
118 | { | ||||
119 | Parser parser(readMailFromFile("openpgp-encrypted-attachment-and-non-encrypted-attachment.mbox")); | ||||
120 | printTree(parser.d->mTree,QString()); | ||||
121 | auto contentPart = parser.collectContentPart(); | ||||
122 | QVERIFY((bool)contentPart); | ||||
123 | QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); | ||||
124 | auto contentList = contentPart->content(ContentPart::PlainText); | ||||
125 | QCOMPARE(contentList.size(), 1); | ||||
126 | QCOMPARE(contentList[0]->content(), QStringLiteral("test text").toLocal8Bit()); | ||||
127 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | ||||
128 | } | ||||
129 | | ||||
130 | void testOpenPPGInline() | ||||
131 | { | ||||
132 | Parser parser(readMailFromFile("openpgp-inline-charset-encrypted.mbox")); | ||||
133 | printTree(parser.d->mTree,QString()); | ||||
134 | auto contentPart = parser.collectContentPart(); | ||||
135 | QVERIFY((bool)contentPart); | ||||
136 | QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); | ||||
137 | auto contentList = contentPart->content(ContentPart::PlainText); | ||||
138 | QCOMPARE(contentList.size(), 1); | ||||
139 | QCOMPARE(contentList[0]->content(), QStringLiteral("asdasd asd asd asdf sadf sdaf sadf äöü").toLocal8Bit()); | ||||
140 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | ||||
141 | } | ||||
142 | }; | ||||
143 | | ||||
144 | QTEST_GUILESS_MAIN(InterfaceTest) | ||||
145 | #include "interfacetest.moc" | ||||
146 | No newline at end of file |