Warning, file /pim/trojita/tests/Misc/test_Rfc5322.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 0002 0003 This file is part of the Trojita Qt IMAP e-mail client, 0004 http://trojita.flaska.net/ 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License or (at your option) version 3 or any later version 0010 accepted by the membership of KDE e.V. (or its successor approved 0011 by the membership of KDE e.V.), which shall act as a proxy 0012 defined in Section 14 of version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #include <QDebug> 0024 #include <QTest> 0025 #include "test_Rfc5322.h" 0026 #include "Common/MetaTypes.h" 0027 #include "Imap/Model/ItemRoles.h" 0028 #include "Imap/Parser/Rfc5322HeaderParser.h" 0029 0030 namespace QTest { 0031 0032 /** @short Debug data dumper for QList<uint> */ 0033 template<> 0034 char *toString(const QList<QByteArray> &list) 0035 { 0036 QString buf; 0037 QDebug d(&buf); 0038 d << list; 0039 return qstrdup(buf.toUtf8().constData()); 0040 } 0041 0042 } 0043 0044 0045 void Rfc5322Test::initTestCase() 0046 { 0047 Common::registerMetaTypes(); 0048 } 0049 0050 void Rfc5322Test::testHeaders() 0051 { 0052 QFETCH(QByteArray, input); 0053 QFETCH(bool, ok); 0054 QFETCH(QList<QByteArray>, references); 0055 QFETCH(QList<QByteArray>, listPost); 0056 QFETCH(bool, listPostNo); 0057 QFETCH(QList<QByteArray>, messageId); 0058 QFETCH(QList<QByteArray>, inReplyTo); 0059 0060 Imap::LowLevelParser::Rfc5322HeaderParser parser; 0061 bool res = parser.parse(input); 0062 QCOMPARE(res, ok); 0063 0064 QCOMPARE(parser.references, references); 0065 QCOMPARE(parser.listPost, listPost); 0066 QCOMPARE(parser.listPostNo, listPostNo); 0067 QCOMPARE(parser.messageId, messageId); 0068 QCOMPARE(parser.inReplyTo, inReplyTo); 0069 } 0070 0071 void Rfc5322Test::testHeaders_data() 0072 { 0073 QTest::addColumn<QByteArray>("input"); 0074 QTest::addColumn<bool>("ok"); 0075 QTest::addColumn<QList<QByteArray> >("references"); 0076 QTest::addColumn<QList<QByteArray> >("listPost"); 0077 QTest::addColumn<bool>("listPostNo"); 0078 QTest::addColumn<QList<QByteArray> >("messageId"); 0079 QTest::addColumn<QList<QByteArray> >("inReplyTo"); 0080 0081 QList<QByteArray> refs; 0082 QList<QByteArray> lp; 0083 QList<QByteArray> mi; 0084 QList<QByteArray> irt; 0085 0086 QTest::newRow("empty-1") << QByteArray() << true << refs << lp << false << mi << irt; 0087 QTest::newRow("empty-2") << QByteArray(" ") << true << refs << lp << false << mi << irt; 0088 QTest::newRow("empty-3") << QByteArray("\r\n \r\n") << true << refs << lp << false << mi << irt; 0089 0090 refs << "foo@bar"; 0091 QTest::newRow("trivial") << QByteArray("reFerences: <foo@bar>\r\n") << true << refs << lp << false << mi << irt; 0092 0093 refs.clear(); 0094 refs << "a@b" << "x@[aaaa]" << "bar@baz"; 0095 QTest::newRow("folding-squares-phrases-other-headers-etc") 0096 << QByteArray("references: <a@b> <x@[aaaa]> foo <bar@\r\n baz>\r\nfail: foo\r\n\r\nsmrt") 0097 << true << refs << lp << false << mi << irt; 0098 0099 QTest::newRow("broken-following-headers") 0100 << QByteArray("references: <a@b> <x@[aaaa]> foo <bar@\r\n baz>\r\nfail: foo\r") 0101 << false << refs << lp << false << mi << irt; 0102 0103 refs.clear(); 0104 lp << "mailto:list@host.com"; 0105 QTest::newRow("list-post-1") 0106 << QByteArray("List-Post: <mailto:list@host.com>\r\n") 0107 << true << refs << lp << false << mi << irt; 0108 0109 lp.clear(); 0110 lp << "mailto:moderator@host.com"; 0111 QTest::newRow("list-post-2") 0112 << QByteArray("List-Post: <mailto:moderator@host.com> (Postings are Moderated)\r\n") 0113 << true << refs << lp << false << mi << irt; 0114 0115 lp.clear(); 0116 lp << "mailto:moderator@host.com?subject=list%20posting"; 0117 QTest::newRow("list-post-3") 0118 << QByteArray("List-Post: <mailto:moderator@host.com?subject=list%20posting>\r\n") 0119 << true << refs << lp << false << mi << irt; 0120 0121 lp.clear(); 0122 QTest::newRow("list-post-no") 0123 << QByteArray("List-Post: NO (posting not allowed on this list)\r\n") 0124 << true << refs << lp << true << mi << irt; 0125 0126 lp << "ftp://ftp.host.com/list.txt" << "mailto:list@host.com?subject=help"; 0127 QTest::newRow("list-post-4") 0128 << QByteArray("List-Post: <ftp://ftp.host.com/list.txt> (FTP),\r\n <mailto:list@host.com?subject=help>\r\n") 0129 << true << refs << lp << false << mi << irt; 0130 0131 refs.clear(); 0132 lp.clear(); 0133 refs << "20121031120002.5C37D5807C@linuxized.com" << "CAKmKYaDZtfZ9wzKML8WgJ=evVhteyOG0RVfsASpBGViwncsaiQ@mail.gmail.com" 0134 << "50911AE6.8060402@gmail.com"; 0135 lp << "mailto:gentoo-dev@lists.gentoo.org"; 0136 QTest::newRow("realworld-1") 0137 << QByteArray("List-Post: <mailto:gentoo-dev@lists.gentoo.org>\r\n" 0138 "References: <20121031120002.5C37D5807C@linuxized.com> " 0139 "<CAKmKYaDZtfZ9wzKML8WgJ=evVhteyOG0RVfsASpBGViwncsaiQ@mail.gmail.com>\r\n" 0140 " <50911AE6.8060402@gmail.com>\r\n" 0141 "\r\n") 0142 << true << refs << lp << false << mi << irt; 0143 0144 refs.clear(); 0145 lp.clear(); 0146 mi << "ea758af6-e6ff-44d3-964d-cb61289d1d3a@flaska.net"; 0147 QTest::newRow("message-id-1") 0148 << QByteArray("Message-ID: <ea758af6-e6ff-44d3-964d-cb61289d1d3a@flaska.net>\r\n") 0149 << true << refs << lp << false << mi << irt; 0150 0151 mi.clear(); 0152 mi << "a@b"; 0153 irt << "x@y" << "foo@[666]"; 0154 QTest::newRow("message-id-and-in-reply-to") 0155 << QByteArray("MESSAGE-id: <a@b>\r\n" 0156 "In-REPLY-to: <x@y > <foo@[666]>\r\n") 0157 << true << refs << lp << false << mi << irt; 0158 0159 refs.clear(); 0160 lp.clear(); 0161 lp << "http://groups.google.com/group/MEH/post?hl=cs_US" << "mailto:CENSORED@googlegroups.com"; 0162 mi.clear(); 0163 irt.clear(); 0164 QTest::newRow("list-post-http-and-mailto") 0165 << QByteArray("List-Post: <http://groups.google.com/group/MEH/post?hl=cs_US>, <mailto:CENSORED@googlegroups.com>\r\n") 0166 << true << refs << lp << false << mi << irt; 0167 } 0168 0169 0170 QTEST_GUILESS_MAIN(Rfc5322Test)