Warning, file /pim/trojita/tests/Imap/test_Imap_Responses.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 <QTest> 0024 0025 #include "test_Imap_Responses.h" 0026 0027 Q_DECLARE_METATYPE(Imap::Responses::State) 0028 Q_DECLARE_METATYPE(respPtr) 0029 0030 /** @short Make sure equal Responses are recognized as equal */ 0031 void ImapResponsesTest::testCompareEq() 0032 { 0033 QFETCH( respPtr, first ); 0034 QFETCH( respPtr, second ); 0035 0036 QCOMPARE( *first, *second ); 0037 } 0038 0039 /** @short Make sure different kind of Responses are recognized as different */ 0040 void ImapResponsesTest::testCompareNe() 0041 { 0042 QFETCH( respPtr, first ); 0043 QFETCH( respPtr, second ); 0044 0045 QVERIFY2( *first != *second, "responses equal" ); 0046 } 0047 0048 void ImapResponsesTest::testCompareEq_data() 0049 { 0050 using namespace Imap::Responses; 0051 0052 QTest::addColumn<respPtr>("first"); 0053 QTest::addColumn<respPtr>("second"); 0054 0055 QSharedPointer<AbstractData> voidData( new RespData<void>() ); 0056 QSharedPointer<AbstractData> dumbList( new RespData<QStringList>( QStringList() << QStringLiteral("foo") << QStringLiteral("bar") ) ); 0057 0058 QTest::newRow( "tagged-OK-nothing" ) << 0059 respPtr( new State( "123", OK, QStringLiteral("foobar 333"), NONE, voidData ) ) << 0060 respPtr( new State( "123", OK, QStringLiteral("foobar 333"), NONE, voidData ) ); 0061 0062 QTest::newRow( "tagged-OK-ALERT-void" ) << 0063 respPtr( new State( "123", OK, QStringLiteral("foobar 666"), ALERT, voidData ) ) << 0064 respPtr( new State( "123", OK, QStringLiteral("foobar 666"), ALERT, voidData ) ); 0065 0066 QTest::newRow( "untagged-NO-CAPABILITY-void" ) << 0067 respPtr( new State( QByteArray(), NO, QStringLiteral("foobar 1337"), CAPABILITIES, dumbList ) ) << 0068 respPtr( new State( QByteArray(), NO, QStringLiteral("foobar 1337"), CAPABILITIES, dumbList ) ); 0069 0070 QTest::newRow( "capability-caps" ) << 0071 respPtr( new Capability( QStringList() << QStringLiteral("1337") << QStringLiteral("trojita") ) ) << 0072 respPtr( new Capability( QStringList() << QStringLiteral("1337") << QStringLiteral("trojita") ) ); 0073 0074 QTest::newRow( "number" ) << 0075 respPtr( new NumberResponse( EXISTS, 10 ) ) << 0076 respPtr( new NumberResponse( EXISTS, 10 ) ); 0077 0078 QTest::newRow( "list" ) << 0079 respPtr( new List( LIST, QStringList( QStringLiteral("\\Noselect") ), QStringLiteral("."), QStringLiteral("foOBar"), QMap<QByteArray,QVariant>() ) ) << 0080 respPtr( new List( LIST, QStringList( QStringLiteral("\\Noselect") ), QStringLiteral("."), QStringLiteral("foOBar"), QMap<QByteArray,QVariant>() ) ); 0081 0082 QTest::newRow( "flags" ) << 0083 respPtr( new Flags( QStringList( QStringLiteral("\\Seen") ) ) ) << 0084 respPtr( new Flags( QStringList( QStringLiteral("\\Seen") ) ) ); 0085 0086 QTest::newRow( "search" ) << 0087 respPtr( new Search(Imap::Uids() << 333)) << 0088 respPtr( new Search(Imap::Uids() << 333)); 0089 0090 ESearch::ListData_t emptyEsearchList; 0091 QTest::newRow("esearch") << 0092 respPtr(new ESearch("t1", ESearch::UIDS, emptyEsearchList)) << 0093 respPtr(new ESearch("t1", ESearch::UIDS, emptyEsearchList)); 0094 0095 Status::stateDataType stateMap; 0096 QTest::newRow( "status-1" ) << 0097 respPtr( new Status( QStringLiteral("ahoj"), stateMap ) ) << 0098 respPtr( new Status( QStringLiteral("ahoj"), stateMap ) ); 0099 0100 stateMap[Status::MESSAGES] = 12; 0101 QTest::newRow( "status-2" ) << 0102 respPtr( new Status( QStringLiteral("ahoj"), stateMap ) ) << 0103 respPtr( new Status( QStringLiteral("ahoj"), stateMap ) ); 0104 0105 stateMap[Status::RECENT] = 0; 0106 QTest::newRow( "status-3" ) << 0107 respPtr( new Status( QStringLiteral("ahoj"), stateMap ) ) << 0108 respPtr( new Status( QStringLiteral("ahoj"), stateMap ) ); 0109 0110 QTest::newRow( "namespace-1" ) << 0111 respPtr( new Namespace( QList<NamespaceData>() << NamespaceData( QStringLiteral("foo"), QStringLiteral("bar")), QList<NamespaceData>(), 0112 QList<NamespaceData>() ) ) << 0113 respPtr( new Namespace( QList<NamespaceData>() << NamespaceData( QStringLiteral("foo"), QStringLiteral("bar")), QList<NamespaceData>(), 0114 QList<NamespaceData>() ) ); 0115 0116 QTest::newRow( "sort-empty" ) << respPtr(new Sort(Imap::Uids())) << respPtr(new Sort(Imap::Uids())); 0117 QTest::newRow( "sort-1" ) << respPtr(new Sort(Imap::Uids() << 3 << 6)) << respPtr(new Sort(Imap::Uids() << 3 << 6)); 0118 0119 ThreadingNode node; 0120 node.num = 666; 0121 QTest::newRow( "thread-1" ) << 0122 respPtr( new Thread( QVector<ThreadingNode>() << node ) ) << 0123 respPtr( new Thread( QVector<ThreadingNode>() << node ) ); 0124 ThreadingNode node2; 0125 node.children += QVector<ThreadingNode>() << node2; 0126 QTest::newRow( "thread-2" ) << 0127 respPtr( new Thread( QVector<ThreadingNode>() << node ) ) << 0128 respPtr( new Thread( QVector<ThreadingNode>() << node ) ); 0129 0130 QTest::newRow("id-empty") << 0131 respPtr(new Id(QMap<QByteArray,QByteArray>())) << 0132 respPtr(new Id(QMap<QByteArray,QByteArray>())); 0133 0134 QTest::newRow("enable") << 0135 respPtr(new Enabled(QList<QByteArray>() << "foo")) << 0136 respPtr(new Enabled(QList<QByteArray>() << "foo")); 0137 } 0138 0139 void ImapResponsesTest::testCompareNe_data() 0140 { 0141 using namespace Imap::Responses; 0142 0143 QTest::addColumn<respPtr>("first"); 0144 QTest::addColumn<respPtr>("second"); 0145 0146 QSharedPointer<AbstractData> voidData( new RespData<void>() ); 0147 QSharedPointer<AbstractData> dumbList( new RespData<QStringList>( QStringList() << QStringLiteral("foo") << QStringLiteral("bar") ) ); 0148 QSharedPointer<AbstractData> anotherList( new RespData<QStringList>( QStringList() << QStringLiteral("bar") << QStringLiteral("baz") ) ); 0149 0150 QTest::newRow( "status-tag" ) << 0151 respPtr( new State( "123", OK, QStringLiteral("foobar 333"), NONE, voidData ) ) << 0152 respPtr( new State( "321", OK, QStringLiteral("foobar 333"), NONE, voidData ) ); 0153 0154 QTest::newRow( "status-tagged-untagged" ) << 0155 respPtr( new State( "123", OK, QStringLiteral("foobar 333"), NONE, voidData ) ) << 0156 respPtr( new State( QByteArray(), OK, QStringLiteral("foobar 333"), NONE, voidData ) ); 0157 0158 QTest::newRow( "status-kind" ) << 0159 respPtr( new State( QByteArray(), OK, QStringLiteral("foobar 333"), NONE, voidData ) ) << 0160 respPtr( new State( QByteArray(), NO, QStringLiteral("foobar 333"), NONE, voidData ) ); 0161 0162 QTest::newRow( "status-response-code" ) << 0163 respPtr( new State( QByteArray(), OK, QStringLiteral("foobar 333"), NONE, voidData ) ) << 0164 respPtr( new State( QByteArray(), OK, QStringLiteral("foobar 333"), ALERT, voidData ) ); 0165 0166 QTest::newRow( "status-response-data-type" ) << 0167 respPtr( new State( QByteArray(), OK, QStringLiteral("foobar 333"), CAPABILITIES, dumbList ) ) << 0168 respPtr( new State( QByteArray(), OK, QStringLiteral("foobar 333"), CAPABILITIES, voidData ) ); 0169 0170 QTest::newRow( "status-response-data-data" ) << 0171 respPtr( new State( QByteArray(), OK, QStringLiteral("foobar 333"), CAPABILITIES, dumbList ) ) << 0172 respPtr( new State( QByteArray(), OK, QStringLiteral("foobar 333"), CAPABILITIES, anotherList ) ); 0173 0174 QTest::newRow( "status-message" ) << 0175 respPtr( new State( QByteArray(), OK, QStringLiteral("foobar 333"), NONE, voidData ) ) << 0176 respPtr( new State( QByteArray(), OK, QStringLiteral("foobar 666"), NONE, voidData ) ); 0177 0178 QTest::newRow( "kind-status-capability" ) << 0179 respPtr( new State( QByteArray(), OK, QStringLiteral("foobar 333"), NONE, voidData ) ) << 0180 respPtr( new Capability( QStringList() ) ); 0181 0182 QTest::newRow( "capability-caps" ) << 0183 respPtr( new Capability( QStringList(QStringLiteral("333")) ) ) << 0184 respPtr( new Capability( QStringList(QStringLiteral("666")) ) ); 0185 0186 QTest::newRow( "number-kind" ) << 0187 respPtr( new NumberResponse( EXISTS, 10 ) ) << 0188 respPtr( new NumberResponse( EXPUNGE, 10 ) ); 0189 0190 QTest::newRow( "number-number" ) << 0191 respPtr( new NumberResponse( RECENT, 10 ) ) << 0192 respPtr( new NumberResponse( RECENT, 11 ) ); 0193 0194 QTest::newRow( "list-kind" ) << 0195 respPtr( new List( LIST, QStringList(), QStringLiteral("."), QStringLiteral("blesmrt"), QMap<QByteArray,QVariant>() ) ) << 0196 respPtr( new List( LSUB, QStringList(), QStringLiteral("."), QStringLiteral("blesmrt"), QMap<QByteArray,QVariant>() ) ); 0197 0198 QTest::newRow( "list-flags" ) << 0199 respPtr( new List( LIST, QStringList(), QStringLiteral("."), QStringLiteral("blesmrt"), QMap<QByteArray,QVariant>() ) ) << 0200 respPtr( new List( LIST, QStringList(QStringLiteral("333")), QStringLiteral("."), QStringLiteral("blesmrt"), QMap<QByteArray,QVariant>() ) ); 0201 0202 QTest::newRow( "list-separator" ) << 0203 respPtr( new List( LIST, QStringList(), QStringLiteral("."), QStringLiteral("blesmrt"), QMap<QByteArray,QVariant>() ) ) << 0204 respPtr( new List( LIST, QStringList(), QStringLiteral("/"), QStringLiteral("blesmrt"), QMap<QByteArray,QVariant>() ) ); 0205 0206 QTest::newRow( "list-mailbox" ) << 0207 respPtr( new List( LIST, QStringList(), QStringLiteral("."), QStringLiteral("blesmrt"), QMap<QByteArray,QVariant>() ) ) << 0208 respPtr( new List( LIST, QStringList(), QStringLiteral("."), QStringLiteral("trojita"), QMap<QByteArray,QVariant>() ) ); 0209 0210 QTest::newRow( "list-mailbox-case" ) << 0211 respPtr( new List( LIST, QStringList(), QStringLiteral("."), QStringLiteral("blesmrt"), QMap<QByteArray,QVariant>() ) ) << 0212 respPtr( new List( LIST, QStringList(), QStringLiteral("."), QStringLiteral("blEsmrt"), QMap<QByteArray,QVariant>() ) ); 0213 0214 QMap<QByteArray,QVariant> listExtendedData; 0215 listExtendedData["blah"] = 10; 0216 QTest::newRow("list-extended-data") << 0217 respPtr(new List(LIST, QStringList(), QStringLiteral("."), QStringLiteral("ble"), QMap<QByteArray,QVariant>())) << 0218 respPtr(new List(LIST, QStringList(), QStringLiteral("."), QStringLiteral("ble"), listExtendedData)); 0219 0220 QTest::newRow( "flags" ) << 0221 respPtr( new Flags( QStringList(QStringLiteral("333")) ) ) << 0222 respPtr( new Flags( QStringList(QStringLiteral("666")) ) ); 0223 0224 QTest::newRow( "search" ) << 0225 respPtr( new Search(Imap::Uids() << 333)) << 0226 respPtr( new Search(Imap::Uids() << 666)); 0227 0228 ESearch::ListData_t emptyEsearchResp; 0229 QTest::newRow("esearch-tag") << 0230 respPtr(new ESearch("t1", ESearch::UIDS, emptyEsearchResp)) << 0231 respPtr(new ESearch(QByteArray(), ESearch::UIDS, emptyEsearchResp)); 0232 0233 QTest::newRow("esearch-uid-seq") << 0234 respPtr(new ESearch("t1", ESearch::UIDS, emptyEsearchResp)) << 0235 respPtr(new ESearch("t1", ESearch::SEQUENCE, emptyEsearchResp)); 0236 0237 ESearch::ListData_t dummyESearch1; 0238 dummyESearch1.push_back(qMakePair<>(QByteArray("foo"), Imap::Uids() << 666)); 0239 0240 QTest::newRow("esearch-listdata") << 0241 respPtr(new ESearch("t1", ESearch::UIDS, dummyESearch1)) << 0242 respPtr(new ESearch("t1", ESearch::UIDS, emptyEsearchResp)); 0243 0244 QTest::newRow( "status-mailbox" ) << 0245 respPtr( new Status( QStringLiteral("ahoj"), Status::stateDataType() ) ) << 0246 respPtr( new Status( QStringLiteral("ahOj"), Status::stateDataType() ) ); 0247 0248 Status::stateDataType stateMap1, stateMap2, stateMap3; 0249 stateMap1[Status::MESSAGES] = 12; 0250 stateMap1[Status::RECENT] = 0; 0251 0252 stateMap2 = stateMap1; 0253 stateMap2[Status::UIDNEXT] = 1; 0254 0255 stateMap3 = stateMap1; 0256 stateMap1[Status::RECENT] = 1; 0257 0258 QTest::newRow( "status-mailbox-nonempty" ) << 0259 respPtr( new Status( QStringLiteral("ahoj"), stateMap1 ) ) << 0260 respPtr( new Status( QStringLiteral("ahOj"), stateMap1 ) ); 0261 0262 QTest::newRow( "status-1" ) << 0263 respPtr( new Status( QStringLiteral("ahoj"), stateMap1 ) ) << 0264 respPtr( new Status( QStringLiteral("ahoj"), stateMap2 ) ); 0265 0266 QTest::newRow( "status-2" ) << 0267 respPtr( new Status( QStringLiteral("ahoj"), stateMap1 ) ) << 0268 respPtr( new Status( QStringLiteral("ahoj"), stateMap3 ) ); 0269 0270 QTest::newRow( "namespace-1" ) << 0271 respPtr( new Namespace( QList<NamespaceData>(), QList<NamespaceData>() << NamespaceData( QStringLiteral("foo"), QStringLiteral("bar") ), 0272 QList<NamespaceData>() ) ) << 0273 respPtr( new Namespace( QList<NamespaceData>() << NamespaceData( QStringLiteral("foo"), QStringLiteral("bar")), QList<NamespaceData>(), 0274 QList<NamespaceData>() ) ); 0275 0276 QTest::newRow( "sort-empty-1" ) << respPtr(new Sort(Imap::Uids())) << respPtr(new Sort(Imap::Uids() << 3)); 0277 QTest::newRow( "sort-empty-2" ) << respPtr(new Sort(Imap::Uids() << 6)) << respPtr(new Sort(Imap::Uids())); 0278 QTest::newRow( "sort-1" ) << respPtr(new Sort(Imap::Uids() << 33 << 6)) << respPtr(new Sort(Imap::Uids() << 3 << 6)); 0279 0280 ThreadingNode node( 666 ); 0281 ThreadingNode node2( 333 ); 0282 QTest::newRow( "thread-1" ) << 0283 respPtr( new Thread( QVector<ThreadingNode>() ) ) << 0284 respPtr( new Thread( QVector<ThreadingNode>() << node ) ); 0285 QTest::newRow( "thread-2" ) << 0286 respPtr( new Thread( QVector<ThreadingNode>() << node2 ) ) << 0287 respPtr( new Thread( QVector<ThreadingNode>() << node ) ); 0288 ThreadingNode node3; 0289 node.children += QVector<ThreadingNode>() << node3; 0290 QTest::newRow( "thread-3" ) << 0291 respPtr( new Thread( QVector<ThreadingNode>() << node ) ) << 0292 respPtr( new Thread( QVector<ThreadingNode>() << node << node3 ) ); 0293 0294 0295 QMap<QByteArray,QByteArray> sampleId; 0296 sampleId["foo"] = "bar"; 0297 0298 QTest::newRow("id") << 0299 respPtr(new Id(QMap<QByteArray,QByteArray>())) << 0300 respPtr(new Id(sampleId)); 0301 0302 QTest::newRow("enable") << 0303 respPtr(new Enabled(QList<QByteArray>())) << 0304 respPtr(new Enabled(QList<QByteArray>() << "blah")); 0305 } 0306 0307 QTEST_GUILESS_MAIN( ImapResponsesTest ) 0308 0309 namespace QTest { 0310 0311 template<> char * toString( const Imap::Responses::AbstractResponse& resp ) 0312 { 0313 QByteArray buf; 0314 QTextStream stream( &buf ); 0315 stream << resp; 0316 stream.flush(); 0317 return qstrdup( buf.data() ); 0318 } 0319 0320 }