~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/resources/imap/tests/imaplibtest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2008 Omat Holding B.V. <info@omat.nl>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
17
*/
 
18
 
 
19
#include <qtest_kde.h>
 
20
 
 
21
#include "imaplibtest.h"
 
22
#include "imaplibtest.moc"
 
23
#include "fakeserver.h"
 
24
#include "../imaplib.h"
 
25
 
 
26
#include <QTcpSocket>
 
27
#include <QtTest>
 
28
 
 
29
QTEST_KDEMAIN( ImaplibTest, NoGUI )
 
30
 
 
31
void ImaplibTest::initTestCase()
 
32
{
 
33
    qRegisterMetaType<Imaplib*>( "Imaplib*" );
 
34
 
 
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" ) );
 
37
    m_fake->start();
 
38
 
 
39
    m_imap = new Imaplib( 0, "testconnection" );
 
40
    m_imap->startConnection( "127.0.0.1", 5989, 1 );
 
41
 
 
42
    QEventLoop loop;
 
43
    connect( m_imap, SIGNAL( login( Imaplib* ) ), &loop, SLOT( quit() ) );
 
44
    loop.exec();
 
45
}
 
46
 
 
47
void ImaplibTest::testCapabilities()
 
48
{
 
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 );
 
54
}
 
55
 
 
56
void ImaplibTest::testLogin()
 
57
{
 
58
    QSignalSpy spy1( m_imap, SIGNAL( loginFailed( Imaplib* ) ) );
 
59
    QSignalSpy spy2( m_imap, SIGNAL( loginOk( Imaplib* ) ) );
 
60
 
 
61
    QStringList list;
 
62
    list << "a02 NO Login failed: authentication failure" << "a02 OK User logged in";
 
63
    m_fake->setResponse( list );
 
64
    m_imap->login( "toma", "imaplib" );
 
65
 
 
66
    QEventLoop loop;
 
67
    connect( m_imap, SIGNAL( loginFailed( Imaplib* ) ), &loop, SLOT( quit() ) );
 
68
    connect( m_imap, SIGNAL( loginOk( Imaplib* ) ), &loop, SLOT( quit() ) );
 
69
    loop.exec();
 
70
 
 
71
    QCOMPARE( spy1.count(), 1 );
 
72
    QCOMPARE( spy2.count(), 0 );
 
73
 
 
74
    m_imap->login( "toma", "imaplib" );
 
75
 
 
76
    loop.exec();
 
77
 
 
78
    QCOMPARE( spy1.count(), 1 );
 
79
    QCOMPARE( spy2.count(), 1 );
 
80
}
 
81
 
 
82
void ImaplibTest::testMailboxList()
 
83
{
 
84
    QSignalSpy spy1( m_imap, SIGNAL( currentFolders( const QStringList&, const QStringList& ) ) );
 
85
 
 
86
    QStringList list;
 
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
 
93
            "a02 OK Completed";
 
94
    m_fake->setResponse( list );
 
95
    m_imap->getMailBoxList();
 
96
 
 
97
    QEventLoop loop;
 
98
    connect( m_imap, SIGNAL( currentFolders( const QStringList&, const QStringList& ) ), &loop, SLOT( quit() ) );
 
99
    loop.exec();
 
100
 
 
101
    QCOMPARE( spy1.count(), 1 );
 
102
 
 
103
    QList<QVariant> arguments = spy1.takeFirst();
 
104
    QStringList folders = arguments.at(0).toStringList();
 
105
    QStringList noselectfolders = arguments.at(1).toStringList();
 
106
 
 
107
    QCOMPARE( folders.count(), 6);
 
108
    QCOMPARE( noselectfolders.count(), 1);
 
109
 
 
110
    QStringList list1;
 
111
    list1 << "TestCases" << QString::fromUtf8("TestCases.Cláudio") << QString::fromUtf8("TestCases.Frode Rønning")
 
112
         << "TestCases.a02 in body" << "TestCases.tom & jerry" << "TestCases.tom";
 
113
    
 
114
    QCOMPARE( folders, list1 );
 
115
 
 
116
    list1.clear();
 
117
    list1 << "TestCases.a02 in body";
 
118
 
 
119
    QCOMPARE( noselectfolders, list1 );
 
120
}
 
121
 
 
122
void ImaplibTest::testMailboxCreateAndDelete()
 
123
{
 
124
    QSignalSpy spy1( m_imap, SIGNAL( mailBoxAdded( bool ) ) );
 
125
    QSignalSpy spy2( m_imap, SIGNAL( mailBoxDeleted( bool, QString ) ) );
 
126
 
 
127
    QStringList list;
 
128
    list << "a02 OK" << "a02 NO" << "a02 OK" << "a02 BAD";
 
129
    m_fake->setResponse( list );
 
130
    m_imap->createMailBox( "tom" );
 
131
 
 
132
    QEventLoop loop;
 
133
    connect( m_imap, SIGNAL( mailBoxAdded( bool ) ), &loop, SLOT( quit() ) );
 
134
    connect( m_imap, SIGNAL( mailBoxDeleted( bool, QString ) ), &loop, SLOT( quit() ) );
 
135
    loop.exec();
 
136
 
 
137
    QCOMPARE( spy1.count(), 1 );
 
138
    QCOMPARE( spy2.count(), 0 );
 
139
    QCOMPARE( spy1.takeFirst().at(0).toBool(), true );
 
140
 
 
141
    m_imap->createMailBox( "tom" );
 
142
    loop.exec();
 
143
 
 
144
    QCOMPARE( spy1.count(), 1 );
 
145
    QCOMPARE( spy2.count(), 0 );
 
146
    QCOMPARE( spy1.takeFirst().at(0).toBool(), false );
 
147
 
 
148
    m_imap->deleteMailBox( "tom &" );
 
149
    loop.exec();
 
150
 
 
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 &") );
 
155
 
 
156
    m_imap->deleteMailBox( QString::fromUtf8("tøm") );
 
157
    loop.exec();
 
158
 
 
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") );
 
163
}
 
164
 
 
165
void ImaplibTest::testGetHeaders()
 
166
{
 
167
    QSignalSpy spy1( m_imap, SIGNAL( headersInFolder( Imaplib*, const QString&, const QStringList& ) ) );
 
168
 
 
169
    QStringList list;
 
170
    list << "a02 OK" 
 
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"
 
183
            "To: info@omat.nl\n"
 
184
            "Date: Mon, 19 Feb 2007 03:05:25 -0800\r\n"
 
185
            "a02 OK FETCH completed.";
 
186
    m_fake->setResponse( list );
 
187
 
 
188
    list.clear();
 
189
    list << QString::number(0) << QString::number(1);
 
190
    m_imap->getHeaders( "Tom", list ); 
 
191
 
 
192
    QEventLoop loop;
 
193
    connect( m_imap, SIGNAL( headersInFolder( Imaplib*, const QString&, const QStringList& ) ), 
 
194
             &loop, SLOT( quit() ) );
 
195
    loop.exec();
 
196
    
 
197
    list.clear();
 
198
    list << "1" << "Tom" 
 
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"
 
204
         << "2" << "Tom" 
 
205
         << "Message-Id: <E2HJ2Kj-2222P2-VI@omat.nl>\n"
 
206
            "From: info@omat.nl\n"
 
207
            "Subject: [patch] Not really!\n"
 
208
            "To: info@omat.nl\n"
 
209
            "Date: Mon, 19 Feb 2007 03:05:25 -0800" << "64100";
 
210
 
 
211
 
 
212
    QCOMPARE( spy1.count(), 1 );
 
213
    QCOMPARE( spy1.at(0).at(1).toString(), QString( "Tom" ) );
 
214
    QCOMPARE( spy1.takeFirst().at(2).toStringList(), list );
 
215
}
 
216
 
 
217