2
Copyright (C) 2008 Omat Holding B.V. <info@omat.nl>
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include <qtest_kde.h>
21
#include "imaplibtest.h"
22
#include "imaplibtest.moc"
23
#include "fakeserver.h"
24
#include "../imaplib.h"
29
QTEST_KDEMAIN( ImaplibTest, NoGUI )
31
void ImaplibTest::initTestCase()
33
qRegisterMetaType<Imaplib*>( "Imaplib*" );
35
m_fake = new FakeServer( this );
36
m_fake->setResponse( QStringList( "* CAPABILITY IMAP4 IMAP4rev1 ACL QUOTA LITERAL+ MAILBOX-REFERRALS NAMESPACE UIDPLUS ID NO_ATOMIC_RENAME UNSELECT CHILDREN MULTIAPPEND BINARY SORT THREAD=ORDEREDSUBJECT THREAD=REFERENCES ANNOTATEMORE IDLE STARTTLS" ) );
39
m_imap = new Imaplib( 0, "testconnection" );
40
m_imap->startConnection( "127.0.0.1", 5989, 1 );
43
connect( m_imap, SIGNAL( login( Imaplib* ) ), &loop, SLOT( quit() ) );
47
void ImaplibTest::testCapabilities()
49
QCOMPARE( m_imap->capable( "acl" ), true );
50
QCOMPARE( m_imap->capable( "starttls" ), true );
51
QCOMPARE( m_imap->capable( "uidnext" ), false );
52
QCOMPARE( m_imap->capable( "uidplus" ), true );
53
QCOMPARE( m_imap->capable( "CHILDREN" ), true );
56
void ImaplibTest::testLogin()
58
QSignalSpy spy1( m_imap, SIGNAL( loginFailed( Imaplib* ) ) );
59
QSignalSpy spy2( m_imap, SIGNAL( loginOk( Imaplib* ) ) );
62
list << "a02 NO Login failed: authentication failure" << "a02 OK User logged in";
63
m_fake->setResponse( list );
64
m_imap->login( "toma", "imaplib" );
67
connect( m_imap, SIGNAL( loginFailed( Imaplib* ) ), &loop, SLOT( quit() ) );
68
connect( m_imap, SIGNAL( loginOk( Imaplib* ) ), &loop, SLOT( quit() ) );
71
QCOMPARE( spy1.count(), 1 );
72
QCOMPARE( spy2.count(), 0 );
74
m_imap->login( "toma", "imaplib" );
78
QCOMPARE( spy1.count(), 1 );
79
QCOMPARE( spy2.count(), 1 );
82
void ImaplibTest::testMailboxList()
84
QSignalSpy spy1( m_imap, SIGNAL( currentFolders( const QStringList&, const QStringList& ) ) );
87
list << "* LIST (\\HasChildren) \".\" \"TestCases\"\n" // simple test
88
"* LIST (\\HasNoChildren) \".\" \"TestCases.Cl&AOE-udio\"\n" // encoding test
89
"* LIST (\\HasNoChildren) \".\" \"TestCases.Frode R&APg-nning\"\n" // encoding test
90
"* LIST (\\HasNoChildren \\Noselect) \".\" \"TestCases.a02 in body\"\n" // a02 & noselect
91
"* LIST (\\HasNoChildren) \".\" \"TestCases.tom &- jerry\"\n" // & encoding
92
"* LIST (\\HasNoChildren) \".\" TestCases.tom\n" // no quotes around the bane
94
m_fake->setResponse( list );
95
m_imap->getMailBoxList();
98
connect( m_imap, SIGNAL( currentFolders( const QStringList&, const QStringList& ) ), &loop, SLOT( quit() ) );
101
QCOMPARE( spy1.count(), 1 );
103
QList<QVariant> arguments = spy1.takeFirst();
104
QStringList folders = arguments.at(0).toStringList();
105
QStringList noselectfolders = arguments.at(1).toStringList();
107
QCOMPARE( folders.count(), 6);
108
QCOMPARE( noselectfolders.count(), 1);
111
list1 << "TestCases" << QString::fromUtf8("TestCases.Cláudio") << QString::fromUtf8("TestCases.Frode Rønning")
112
<< "TestCases.a02 in body" << "TestCases.tom & jerry" << "TestCases.tom";
114
QCOMPARE( folders, list1 );
117
list1 << "TestCases.a02 in body";
119
QCOMPARE( noselectfolders, list1 );
122
void ImaplibTest::testMailboxCreateAndDelete()
124
QSignalSpy spy1( m_imap, SIGNAL( mailBoxAdded( bool ) ) );
125
QSignalSpy spy2( m_imap, SIGNAL( mailBoxDeleted( bool, QString ) ) );
128
list << "a02 OK" << "a02 NO" << "a02 OK" << "a02 BAD";
129
m_fake->setResponse( list );
130
m_imap->createMailBox( "tom" );
133
connect( m_imap, SIGNAL( mailBoxAdded( bool ) ), &loop, SLOT( quit() ) );
134
connect( m_imap, SIGNAL( mailBoxDeleted( bool, QString ) ), &loop, SLOT( quit() ) );
137
QCOMPARE( spy1.count(), 1 );
138
QCOMPARE( spy2.count(), 0 );
139
QCOMPARE( spy1.takeFirst().at(0).toBool(), true );
141
m_imap->createMailBox( "tom" );
144
QCOMPARE( spy1.count(), 1 );
145
QCOMPARE( spy2.count(), 0 );
146
QCOMPARE( spy1.takeFirst().at(0).toBool(), false );
148
m_imap->deleteMailBox( "tom &" );
151
QCOMPARE( spy1.count(), 0 );
152
QCOMPARE( spy2.count(), 1 );
153
QCOMPARE( spy2.at(0).at(0).toBool(), true );
154
QCOMPARE( spy2.takeFirst().at(1).toString(), QString("tom &") );
156
m_imap->deleteMailBox( QString::fromUtf8("tøm") );
159
QCOMPARE( spy1.count(), 0 );
160
QCOMPARE( spy2.count(), 1 );
161
QCOMPARE( spy2.at(0).at(0).toBool(), false );
162
QCOMPARE( spy2.takeFirst().at(1).toString(), QString::fromUtf8("tøm") );
165
void ImaplibTest::testGetHeaders()
167
QSignalSpy spy1( m_imap, SIGNAL( headersInFolder( Imaplib*, const QString&, const QStringList& ) ) );
171
<< "* 1 FETCH (UID 1 RFC822.SIZE 5083 "
172
"BODY[HEADER.FIELDS (\"FROM\" \"TO\" \"CC\" \"SUBJECT\" \"DATE\" \"IN-REPLY-TO\" \"MESSAGE-ID\")] {185}\n"
173
"Message-Id: <E2HJ2E2-22222c-B2@somat.nl>\n"
174
"From: \"Tom Albers\" <noreply@omat.nl>\n"
175
"Subject: [tracker] [ Bugs-1660 ] Nice test case?\n"
176
"To: noreply@omat.nl\n"
177
"Date: Mon, 19 Feb 2007 02:58:45 -0800\n"
178
"* 2 FETCH (UID 2 RFC822.SIZE 64100 "
179
"BODY[HEADER.FIELDS (\"FROM\" \"TO\" \"CC\" \"SUBJECT\" \"DATE\" \"IN-REPLY-TO\" \"MESSAGE-ID\")] {142}\n"
180
"Message-Id: <E2HJ2Kj-2222P2-VI@omat.nl>\n"
181
"From: info@omat.nl\n"
182
"Subject: [patch] Not really!\n"
184
"Date: Mon, 19 Feb 2007 03:05:25 -0800\r\n"
185
"a02 OK FETCH completed.";
186
m_fake->setResponse( list );
189
list << QString::number(0) << QString::number(1);
190
m_imap->getHeaders( "Tom", list );
193
connect( m_imap, SIGNAL( headersInFolder( Imaplib*, const QString&, const QStringList& ) ),
194
&loop, SLOT( quit() ) );
199
<< "Message-Id: <E2HJ2E2-22222c-B2@somat.nl>\n"
200
"From: \"Tom Albers\" <noreply@omat.nl>\n"
201
"Subject: [tracker] [ Bugs-1660 ] Nice test case?\n"
202
"To: noreply@omat.nl\n"
203
"Date: Mon, 19 Feb 2007 02:58:45 -0800" << "5083"
205
<< "Message-Id: <E2HJ2Kj-2222P2-VI@omat.nl>\n"
206
"From: info@omat.nl\n"
207
"Subject: [patch] Not really!\n"
209
"Date: Mon, 19 Feb 2007 03:05:25 -0800" << "64100";
212
QCOMPARE( spy1.count(), 1 );
213
QCOMPARE( spy1.at(0).at(1).toString(), QString( "Tom" ) );
214
QCOMPARE( spy1.takeFirst().at(2).toStringList(), list );