diff options
Diffstat (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp')
-rw-r--r-- | framework/domain/mimetreeparser/tests/interfacetest.cpp | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index fd828960..88691539 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp | |||
@@ -18,6 +18,7 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include "interface.h" | 20 | #include "interface.h" |
21 | #include "interface_p.h" | ||
21 | 22 | ||
22 | #include <QTest> | 23 | #include <QTest> |
23 | 24 | ||
@@ -33,6 +34,15 @@ QByteArray readMailFromFile(const QString &mailFile) | |||
33 | class InterfaceTest : public QObject | 34 | class InterfaceTest : public QObject |
34 | { | 35 | { |
35 | Q_OBJECT | 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 | |||
36 | private slots: | 46 | private slots: |
37 | 47 | ||
38 | void testTextMail() | 48 | void testTextMail() |
@@ -43,10 +53,13 @@ private slots: | |||
43 | QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); | 53 | QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); |
44 | auto contentList = contentPart->content(ContentPart::PlainText); | 54 | auto contentList = contentPart->content(ContentPart::PlainText); |
45 | QCOMPARE(contentList.size(), 1); | 55 | QCOMPARE(contentList.size(), 1); |
46 | 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\n- GOG.com Team\n\n").toLocal8Bit()); | 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()); |
47 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | 57 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); |
48 | QCOMPARE(contentList[0]->encryptions().size(), 0); | 58 | QCOMPARE(contentList[0]->encryptions().size(), 0); |
49 | QCOMPARE(contentList[0]->signatures().size(), 0); | 59 | QCOMPARE(contentList[0]->signatures().size(), 0); |
60 | |||
61 | contentList = contentPart->content(ContentPart::Html); | ||
62 | QCOMPARE(contentList.size(), 0); | ||
50 | } | 63 | } |
51 | 64 | ||
52 | void testTextAlternative() | 65 | void testTextAlternative() |
@@ -55,6 +68,19 @@ private slots: | |||
55 | auto contentPart = parser.collectContentPart(); | 68 | auto contentPart = parser.collectContentPart(); |
56 | QVERIFY((bool)contentPart); | 69 | QVERIFY((bool)contentPart); |
57 | QCOMPARE(contentPart->availableContents(), ContentPart::PlainText | ContentPart::Html); | 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); | ||
58 | } | 84 | } |
59 | 85 | ||
60 | void testTextHtml() | 86 | void testTextHtml() |
@@ -63,6 +89,55 @@ private slots: | |||
63 | auto contentPart = parser.collectContentPart(); | 89 | auto contentPart = parser.collectContentPart(); |
64 | QVERIFY((bool)contentPart); | 90 | QVERIFY((bool)contentPart); |
65 | QCOMPARE(contentPart->availableContents(), ContentPart::Html); | 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()); | ||
66 | } | 141 | } |
67 | }; | 142 | }; |
68 | 143 | ||