Fix "Key sequence 'Ctrl+F' is ambiguous" error message
[trojita.git] / tests / Misc / test_Rfc5322.cpp
blobd0d0820e32fda479fecbddafc8a5b215af17054c
1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <QDebug>
24 #include <QTest>
25 #include "test_Rfc5322.h"
26 #include "Common/MetaTypes.h"
27 #include "Imap/Model/ItemRoles.h"
28 #include "Imap/Parser/Rfc5322HeaderParser.h"
30 namespace QTest {
32 /** @short Debug data dumper for QList<uint> */
33 template<>
34 char *toString(const QList<QByteArray> &list)
36 QString buf;
37 QDebug d(&buf);
38 d << list;
39 return qstrdup(buf.toUtf8().constData());
45 void Rfc5322Test::initTestCase()
47 Common::registerMetaTypes();
50 void Rfc5322Test::testHeaders()
52 QFETCH(QByteArray, input);
53 QFETCH(bool, ok);
54 QFETCH(QList<QByteArray>, references);
55 QFETCH(QList<QByteArray>, listPost);
56 QFETCH(bool, listPostNo);
57 QFETCH(QList<QByteArray>, messageId);
58 QFETCH(QList<QByteArray>, inReplyTo);
60 Imap::LowLevelParser::Rfc5322HeaderParser parser;
61 bool res = parser.parse(input);
62 QCOMPARE(res, ok);
64 QCOMPARE(parser.references, references);
65 QCOMPARE(parser.listPost, listPost);
66 QCOMPARE(parser.listPostNo, listPostNo);
67 QCOMPARE(parser.messageId, messageId);
68 QCOMPARE(parser.inReplyTo, inReplyTo);
71 void Rfc5322Test::testHeaders_data()
73 QTest::addColumn<QByteArray>("input");
74 QTest::addColumn<bool>("ok");
75 QTest::addColumn<QList<QByteArray> >("references");
76 QTest::addColumn<QList<QByteArray> >("listPost");
77 QTest::addColumn<bool>("listPostNo");
78 QTest::addColumn<QList<QByteArray> >("messageId");
79 QTest::addColumn<QList<QByteArray> >("inReplyTo");
81 QList<QByteArray> refs;
82 QList<QByteArray> lp;
83 QList<QByteArray> mi;
84 QList<QByteArray> irt;
86 QTest::newRow("empty-1") << QByteArray() << true << refs << lp << false << mi << irt;
87 QTest::newRow("empty-2") << QByteArray(" ") << true << refs << lp << false << mi << irt;
88 QTest::newRow("empty-3") << QByteArray("\r\n \r\n") << true << refs << lp << false << mi << irt;
90 refs << "foo@bar";
91 QTest::newRow("trivial") << QByteArray("reFerences: <foo@bar>\r\n") << true << refs << lp << false << mi << irt;
93 refs.clear();
94 refs << "a@b" << "x@[aaaa]" << "bar@baz";
95 QTest::newRow("folding-squares-phrases-other-headers-etc")
96 << QByteArray("references: <a@b> <x@[aaaa]> foo <bar@\r\n baz>\r\nfail: foo\r\n\r\nsmrt")
97 << true << refs << lp << false << mi << irt;
99 QTest::newRow("broken-following-headers")
100 << QByteArray("references: <a@b> <x@[aaaa]> foo <bar@\r\n baz>\r\nfail: foo\r")
101 << false << refs << lp << false << mi << irt;
103 refs.clear();
104 lp << "mailto:list@host.com";
105 QTest::newRow("list-post-1")
106 << QByteArray("List-Post: <mailto:list@host.com>\r\n")
107 << true << refs << lp << false << mi << irt;
109 lp.clear();
110 lp << "mailto:moderator@host.com";
111 QTest::newRow("list-post-2")
112 << QByteArray("List-Post: <mailto:moderator@host.com> (Postings are Moderated)\r\n")
113 << true << refs << lp << false << mi << irt;
115 lp.clear();
116 lp << "mailto:moderator@host.com?subject=list%20posting";
117 QTest::newRow("list-post-3")
118 << QByteArray("List-Post: <mailto:moderator@host.com?subject=list%20posting>\r\n")
119 << true << refs << lp << false << mi << irt;
121 lp.clear();
122 QTest::newRow("list-post-no")
123 << QByteArray("List-Post: NO (posting not allowed on this list)\r\n")
124 << true << refs << lp << true << mi << irt;
126 lp << "ftp://ftp.host.com/list.txt" << "mailto:list@host.com?subject=help";
127 QTest::newRow("list-post-4")
128 << QByteArray("List-Post: <ftp://ftp.host.com/list.txt> (FTP),\r\n <mailto:list@host.com?subject=help>\r\n")
129 << true << refs << lp << false << mi << irt;
131 refs.clear();
132 lp.clear();
133 refs << "20121031120002.5C37D5807C@linuxized.com" << "CAKmKYaDZtfZ9wzKML8WgJ=evVhteyOG0RVfsASpBGViwncsaiQ@mail.gmail.com"
134 << "50911AE6.8060402@gmail.com";
135 lp << "mailto:gentoo-dev@lists.gentoo.org";
136 QTest::newRow("realworld-1")
137 << QByteArray("List-Post: <mailto:gentoo-dev@lists.gentoo.org>\r\n"
138 "References: <20121031120002.5C37D5807C@linuxized.com> "
139 "<CAKmKYaDZtfZ9wzKML8WgJ=evVhteyOG0RVfsASpBGViwncsaiQ@mail.gmail.com>\r\n"
140 " <50911AE6.8060402@gmail.com>\r\n"
141 "\r\n")
142 << true << refs << lp << false << mi << irt;
144 refs.clear();
145 lp.clear();
146 mi << "ea758af6-e6ff-44d3-964d-cb61289d1d3a@flaska.net";
147 QTest::newRow("message-id-1")
148 << QByteArray("Message-ID: <ea758af6-e6ff-44d3-964d-cb61289d1d3a@flaska.net>\r\n")
149 << true << refs << lp << false << mi << irt;
151 mi.clear();
152 mi << "a@b";
153 irt << "x@y" << "foo@[666]";
154 QTest::newRow("message-id-and-in-reply-to")
155 << QByteArray("MESSAGE-id: <a@b>\r\n"
156 "In-REPLY-to: <x@y > <foo@[666]>\r\n")
157 << true << refs << lp << false << mi << irt;
159 refs.clear();
160 lp.clear();
161 lp << "http://groups.google.com/group/MEH/post?hl=cs_US" << "mailto:CENSORED@googlegroups.com";
162 mi.clear();
163 irt.clear();
164 QTest::newRow("list-post-http-and-mailto")
165 << QByteArray("List-Post: <http://groups.google.com/group/MEH/post?hl=cs_US>, <mailto:CENSORED@googlegroups.com>\r\n")
166 << true << refs << lp << false << mi << irt;
170 QTEST_GUILESS_MAIN(Rfc5322Test)