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/>.
25 #include "test_Imap_Responses.h"
27 Q_DECLARE_METATYPE(Imap::Responses::State
)
28 Q_DECLARE_METATYPE(respPtr
)
30 /** @short Make sure equal Responses are recognized as equal */
31 void ImapResponsesTest::testCompareEq()
33 QFETCH( respPtr
, first
);
34 QFETCH( respPtr
, second
);
36 QCOMPARE( *first
, *second
);
39 /** @short Make sure different kind of Responses are recognized as different */
40 void ImapResponsesTest::testCompareNe()
42 QFETCH( respPtr
, first
);
43 QFETCH( respPtr
, second
);
45 QVERIFY2( *first
!= *second
, "responses equal" );
48 void ImapResponsesTest::testCompareEq_data()
50 using namespace Imap::Responses
;
52 QTest::addColumn
<respPtr
>("first");
53 QTest::addColumn
<respPtr
>("second");
55 QSharedPointer
<AbstractData
> voidData( new RespData
<void>() );
56 QSharedPointer
<AbstractData
> dumbList( new RespData
<QStringList
>( QStringList() << QStringLiteral("foo") << QStringLiteral("bar") ) );
58 QTest::newRow( "tagged-OK-nothing" ) <<
59 respPtr( new State( "123", OK
, QStringLiteral("foobar 333"), NONE
, voidData
) ) <<
60 respPtr( new State( "123", OK
, QStringLiteral("foobar 333"), NONE
, voidData
) );
62 QTest::newRow( "tagged-OK-ALERT-void" ) <<
63 respPtr( new State( "123", OK
, QStringLiteral("foobar 666"), ALERT
, voidData
) ) <<
64 respPtr( new State( "123", OK
, QStringLiteral("foobar 666"), ALERT
, voidData
) );
66 QTest::newRow( "untagged-NO-CAPABILITY-void" ) <<
67 respPtr( new State( QByteArray(), NO
, QStringLiteral("foobar 1337"), CAPABILITIES
, dumbList
) ) <<
68 respPtr( new State( QByteArray(), NO
, QStringLiteral("foobar 1337"), CAPABILITIES
, dumbList
) );
70 QTest::newRow( "capability-caps" ) <<
71 respPtr( new Capability( QStringList() << QStringLiteral("1337") << QStringLiteral("trojita") ) ) <<
72 respPtr( new Capability( QStringList() << QStringLiteral("1337") << QStringLiteral("trojita") ) );
74 QTest::newRow( "number" ) <<
75 respPtr( new NumberResponse( EXISTS
, 10 ) ) <<
76 respPtr( new NumberResponse( EXISTS
, 10 ) );
78 QTest::newRow( "list" ) <<
79 respPtr( new List( LIST
, QStringList( QStringLiteral("\\Noselect") ), QStringLiteral("."), QStringLiteral("foOBar"), QMap
<QByteArray
,QVariant
>() ) ) <<
80 respPtr( new List( LIST
, QStringList( QStringLiteral("\\Noselect") ), QStringLiteral("."), QStringLiteral("foOBar"), QMap
<QByteArray
,QVariant
>() ) );
82 QTest::newRow( "flags" ) <<
83 respPtr( new Flags( QStringList( QStringLiteral("\\Seen") ) ) ) <<
84 respPtr( new Flags( QStringList( QStringLiteral("\\Seen") ) ) );
86 QTest::newRow( "search" ) <<
87 respPtr( new Search(Imap::Uids() << 333)) <<
88 respPtr( new Search(Imap::Uids() << 333));
90 ESearch::ListData_t emptyEsearchList
;
91 QTest::newRow("esearch") <<
92 respPtr(new ESearch("t1", ESearch::UIDS
, emptyEsearchList
)) <<
93 respPtr(new ESearch("t1", ESearch::UIDS
, emptyEsearchList
));
95 Status::stateDataType stateMap
;
96 QTest::newRow( "status-1" ) <<
97 respPtr( new Status( QStringLiteral("ahoj"), stateMap
) ) <<
98 respPtr( new Status( QStringLiteral("ahoj"), stateMap
) );
100 stateMap
[Status::MESSAGES
] = 12;
101 QTest::newRow( "status-2" ) <<
102 respPtr( new Status( QStringLiteral("ahoj"), stateMap
) ) <<
103 respPtr( new Status( QStringLiteral("ahoj"), stateMap
) );
105 stateMap
[Status::RECENT
] = 0;
106 QTest::newRow( "status-3" ) <<
107 respPtr( new Status( QStringLiteral("ahoj"), stateMap
) ) <<
108 respPtr( new Status( QStringLiteral("ahoj"), stateMap
) );
110 QTest::newRow( "namespace-1" ) <<
111 respPtr( new Namespace( QList
<NamespaceData
>() << NamespaceData( QStringLiteral("foo"), QStringLiteral("bar")), QList
<NamespaceData
>(),
112 QList
<NamespaceData
>() ) ) <<
113 respPtr( new Namespace( QList
<NamespaceData
>() << NamespaceData( QStringLiteral("foo"), QStringLiteral("bar")), QList
<NamespaceData
>(),
114 QList
<NamespaceData
>() ) );
116 QTest::newRow( "sort-empty" ) << respPtr(new Sort(Imap::Uids())) << respPtr(new Sort(Imap::Uids()));
117 QTest::newRow( "sort-1" ) << respPtr(new Sort(Imap::Uids() << 3 << 6)) << respPtr(new Sort(Imap::Uids() << 3 << 6));
121 QTest::newRow( "thread-1" ) <<
122 respPtr( new Thread( QVector
<ThreadingNode
>() << node
) ) <<
123 respPtr( new Thread( QVector
<ThreadingNode
>() << node
) );
125 node
.children
+= QVector
<ThreadingNode
>() << node2
;
126 QTest::newRow( "thread-2" ) <<
127 respPtr( new Thread( QVector
<ThreadingNode
>() << node
) ) <<
128 respPtr( new Thread( QVector
<ThreadingNode
>() << node
) );
130 QTest::newRow("id-empty") <<
131 respPtr(new Id(QMap
<QByteArray
,QByteArray
>())) <<
132 respPtr(new Id(QMap
<QByteArray
,QByteArray
>()));
134 QTest::newRow("enable") <<
135 respPtr(new Enabled(QList
<QByteArray
>() << "foo")) <<
136 respPtr(new Enabled(QList
<QByteArray
>() << "foo"));
139 void ImapResponsesTest::testCompareNe_data()
141 using namespace Imap::Responses
;
143 QTest::addColumn
<respPtr
>("first");
144 QTest::addColumn
<respPtr
>("second");
146 QSharedPointer
<AbstractData
> voidData( new RespData
<void>() );
147 QSharedPointer
<AbstractData
> dumbList( new RespData
<QStringList
>( QStringList() << QStringLiteral("foo") << QStringLiteral("bar") ) );
148 QSharedPointer
<AbstractData
> anotherList( new RespData
<QStringList
>( QStringList() << QStringLiteral("bar") << QStringLiteral("baz") ) );
150 QTest::newRow( "status-tag" ) <<
151 respPtr( new State( "123", OK
, QStringLiteral("foobar 333"), NONE
, voidData
) ) <<
152 respPtr( new State( "321", OK
, QStringLiteral("foobar 333"), NONE
, voidData
) );
154 QTest::newRow( "status-tagged-untagged" ) <<
155 respPtr( new State( "123", OK
, QStringLiteral("foobar 333"), NONE
, voidData
) ) <<
156 respPtr( new State( QByteArray(), OK
, QStringLiteral("foobar 333"), NONE
, voidData
) );
158 QTest::newRow( "status-kind" ) <<
159 respPtr( new State( QByteArray(), OK
, QStringLiteral("foobar 333"), NONE
, voidData
) ) <<
160 respPtr( new State( QByteArray(), NO
, QStringLiteral("foobar 333"), NONE
, voidData
) );
162 QTest::newRow( "status-response-code" ) <<
163 respPtr( new State( QByteArray(), OK
, QStringLiteral("foobar 333"), NONE
, voidData
) ) <<
164 respPtr( new State( QByteArray(), OK
, QStringLiteral("foobar 333"), ALERT
, voidData
) );
166 QTest::newRow( "status-response-data-type" ) <<
167 respPtr( new State( QByteArray(), OK
, QStringLiteral("foobar 333"), CAPABILITIES
, dumbList
) ) <<
168 respPtr( new State( QByteArray(), OK
, QStringLiteral("foobar 333"), CAPABILITIES
, voidData
) );
170 QTest::newRow( "status-response-data-data" ) <<
171 respPtr( new State( QByteArray(), OK
, QStringLiteral("foobar 333"), CAPABILITIES
, dumbList
) ) <<
172 respPtr( new State( QByteArray(), OK
, QStringLiteral("foobar 333"), CAPABILITIES
, anotherList
) );
174 QTest::newRow( "status-message" ) <<
175 respPtr( new State( QByteArray(), OK
, QStringLiteral("foobar 333"), NONE
, voidData
) ) <<
176 respPtr( new State( QByteArray(), OK
, QStringLiteral("foobar 666"), NONE
, voidData
) );
178 QTest::newRow( "kind-status-capability" ) <<
179 respPtr( new State( QByteArray(), OK
, QStringLiteral("foobar 333"), NONE
, voidData
) ) <<
180 respPtr( new Capability( QStringList() ) );
182 QTest::newRow( "capability-caps" ) <<
183 respPtr( new Capability( QStringList(QStringLiteral("333")) ) ) <<
184 respPtr( new Capability( QStringList(QStringLiteral("666")) ) );
186 QTest::newRow( "number-kind" ) <<
187 respPtr( new NumberResponse( EXISTS
, 10 ) ) <<
188 respPtr( new NumberResponse( EXPUNGE
, 10 ) );
190 QTest::newRow( "number-number" ) <<
191 respPtr( new NumberResponse( RECENT
, 10 ) ) <<
192 respPtr( new NumberResponse( RECENT
, 11 ) );
194 QTest::newRow( "list-kind" ) <<
195 respPtr( new List( LIST
, QStringList(), QStringLiteral("."), QStringLiteral("blesmrt"), QMap
<QByteArray
,QVariant
>() ) ) <<
196 respPtr( new List( LSUB
, QStringList(), QStringLiteral("."), QStringLiteral("blesmrt"), QMap
<QByteArray
,QVariant
>() ) );
198 QTest::newRow( "list-flags" ) <<
199 respPtr( new List( LIST
, QStringList(), QStringLiteral("."), QStringLiteral("blesmrt"), QMap
<QByteArray
,QVariant
>() ) ) <<
200 respPtr( new List( LIST
, QStringList(QStringLiteral("333")), QStringLiteral("."), QStringLiteral("blesmrt"), QMap
<QByteArray
,QVariant
>() ) );
202 QTest::newRow( "list-separator" ) <<
203 respPtr( new List( LIST
, QStringList(), QStringLiteral("."), QStringLiteral("blesmrt"), QMap
<QByteArray
,QVariant
>() ) ) <<
204 respPtr( new List( LIST
, QStringList(), QStringLiteral("/"), QStringLiteral("blesmrt"), QMap
<QByteArray
,QVariant
>() ) );
206 QTest::newRow( "list-mailbox" ) <<
207 respPtr( new List( LIST
, QStringList(), QStringLiteral("."), QStringLiteral("blesmrt"), QMap
<QByteArray
,QVariant
>() ) ) <<
208 respPtr( new List( LIST
, QStringList(), QStringLiteral("."), QStringLiteral("trojita"), QMap
<QByteArray
,QVariant
>() ) );
210 QTest::newRow( "list-mailbox-case" ) <<
211 respPtr( new List( LIST
, QStringList(), QStringLiteral("."), QStringLiteral("blesmrt"), QMap
<QByteArray
,QVariant
>() ) ) <<
212 respPtr( new List( LIST
, QStringList(), QStringLiteral("."), QStringLiteral("blEsmrt"), QMap
<QByteArray
,QVariant
>() ) );
214 QMap
<QByteArray
,QVariant
> listExtendedData
;
215 listExtendedData
["blah"] = 10;
216 QTest::newRow("list-extended-data") <<
217 respPtr(new List(LIST
, QStringList(), QStringLiteral("."), QStringLiteral("ble"), QMap
<QByteArray
,QVariant
>())) <<
218 respPtr(new List(LIST
, QStringList(), QStringLiteral("."), QStringLiteral("ble"), listExtendedData
));
220 QTest::newRow( "flags" ) <<
221 respPtr( new Flags( QStringList(QStringLiteral("333")) ) ) <<
222 respPtr( new Flags( QStringList(QStringLiteral("666")) ) );
224 QTest::newRow( "search" ) <<
225 respPtr( new Search(Imap::Uids() << 333)) <<
226 respPtr( new Search(Imap::Uids() << 666));
228 ESearch::ListData_t emptyEsearchResp
;
229 QTest::newRow("esearch-tag") <<
230 respPtr(new ESearch("t1", ESearch::UIDS
, emptyEsearchResp
)) <<
231 respPtr(new ESearch(QByteArray(), ESearch::UIDS
, emptyEsearchResp
));
233 QTest::newRow("esearch-uid-seq") <<
234 respPtr(new ESearch("t1", ESearch::UIDS
, emptyEsearchResp
)) <<
235 respPtr(new ESearch("t1", ESearch::SEQUENCE
, emptyEsearchResp
));
237 ESearch::ListData_t dummyESearch1
;
238 dummyESearch1
.push_back(qMakePair
<>(QByteArray("foo"), Imap::Uids() << 666));
240 QTest::newRow("esearch-listdata") <<
241 respPtr(new ESearch("t1", ESearch::UIDS
, dummyESearch1
)) <<
242 respPtr(new ESearch("t1", ESearch::UIDS
, emptyEsearchResp
));
244 QTest::newRow( "status-mailbox" ) <<
245 respPtr( new Status( QStringLiteral("ahoj"), Status::stateDataType() ) ) <<
246 respPtr( new Status( QStringLiteral("ahOj"), Status::stateDataType() ) );
248 Status::stateDataType stateMap1
, stateMap2
, stateMap3
;
249 stateMap1
[Status::MESSAGES
] = 12;
250 stateMap1
[Status::RECENT
] = 0;
252 stateMap2
= stateMap1
;
253 stateMap2
[Status::UIDNEXT
] = 1;
255 stateMap3
= stateMap1
;
256 stateMap1
[Status::RECENT
] = 1;
258 QTest::newRow( "status-mailbox-nonempty" ) <<
259 respPtr( new Status( QStringLiteral("ahoj"), stateMap1
) ) <<
260 respPtr( new Status( QStringLiteral("ahOj"), stateMap1
) );
262 QTest::newRow( "status-1" ) <<
263 respPtr( new Status( QStringLiteral("ahoj"), stateMap1
) ) <<
264 respPtr( new Status( QStringLiteral("ahoj"), stateMap2
) );
266 QTest::newRow( "status-2" ) <<
267 respPtr( new Status( QStringLiteral("ahoj"), stateMap1
) ) <<
268 respPtr( new Status( QStringLiteral("ahoj"), stateMap3
) );
270 QTest::newRow( "namespace-1" ) <<
271 respPtr( new Namespace( QList
<NamespaceData
>(), QList
<NamespaceData
>() << NamespaceData( QStringLiteral("foo"), QStringLiteral("bar") ),
272 QList
<NamespaceData
>() ) ) <<
273 respPtr( new Namespace( QList
<NamespaceData
>() << NamespaceData( QStringLiteral("foo"), QStringLiteral("bar")), QList
<NamespaceData
>(),
274 QList
<NamespaceData
>() ) );
276 QTest::newRow( "sort-empty-1" ) << respPtr(new Sort(Imap::Uids())) << respPtr(new Sort(Imap::Uids() << 3));
277 QTest::newRow( "sort-empty-2" ) << respPtr(new Sort(Imap::Uids() << 6)) << respPtr(new Sort(Imap::Uids()));
278 QTest::newRow( "sort-1" ) << respPtr(new Sort(Imap::Uids() << 33 << 6)) << respPtr(new Sort(Imap::Uids() << 3 << 6));
280 ThreadingNode
node( 666 );
281 ThreadingNode
node2( 333 );
282 QTest::newRow( "thread-1" ) <<
283 respPtr( new Thread( QVector
<ThreadingNode
>() ) ) <<
284 respPtr( new Thread( QVector
<ThreadingNode
>() << node
) );
285 QTest::newRow( "thread-2" ) <<
286 respPtr( new Thread( QVector
<ThreadingNode
>() << node2
) ) <<
287 respPtr( new Thread( QVector
<ThreadingNode
>() << node
) );
289 node
.children
+= QVector
<ThreadingNode
>() << node3
;
290 QTest::newRow( "thread-3" ) <<
291 respPtr( new Thread( QVector
<ThreadingNode
>() << node
) ) <<
292 respPtr( new Thread( QVector
<ThreadingNode
>() << node
<< node3
) );
295 QMap
<QByteArray
,QByteArray
> sampleId
;
296 sampleId
["foo"] = "bar";
298 QTest::newRow("id") <<
299 respPtr(new Id(QMap
<QByteArray
,QByteArray
>())) <<
300 respPtr(new Id(sampleId
));
302 QTest::newRow("enable") <<
303 respPtr(new Enabled(QList
<QByteArray
>())) <<
304 respPtr(new Enabled(QList
<QByteArray
>() << "blah"));
307 QTEST_GUILESS_MAIN( ImapResponsesTest
)
311 template<> char * toString( const Imap::Responses::AbstractResponse
& resp
)
314 QTextStream
stream( &buf
);
317 return qstrdup( buf
.data() );