2
Copyright (C) 2013 Christian Mollekopf <mollekopf@kolabsys.com>
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 "kimaptest/fakeserver.h"
22
#include "kimap/session.h"
23
#include "kimap/getmetadatajob.h"
29
typedef QMap<QByteArray,QByteArray> MAP;
30
Q_DECLARE_METATYPE(MAP)
32
class GetMetadataJobTest: public QObject {
39
QTest::addColumn<QList<QByteArray> >( "scenario" );
40
QTest::addColumn<QString>( "mailbox" );
41
QTest::addColumn<QMap<QByteArray, QByteArray> >( "expectedAnnotations" );
44
QList<QByteArray> scenario;
45
scenario << FakeServer::preauth()
46
<< "C: A000001 GETMETADATA \"Folder1\" (DEPTH infinity) (/shared)"
47
<< "S: * METADATA \"Folder1\" (/shared/comment \"Shared comment\")"
48
<< "S: * METADATA \"Folder1\" (/private/comment \"My own comment\")"
49
<< "S: A000001 OK GETMETADATA complete";
50
QMap<QByteArray, QByteArray> expected;
51
expected.insert("/shared/comment", "Shared comment");
52
expected.insert("/private/comment", "My own comment");
53
QTest::newRow( "normal" ) << scenario << "Folder1" << expected;
56
QList<QByteArray> scenario;
57
scenario << FakeServer::preauth()
58
<< "C: A000001 GETMETADATA \"Folder1\" (DEPTH infinity) (/shared)"
59
<< "S: * METADATA \"Folder1\" (/shared/comment \"Shared comment\" /private/comment \"My own comment\")"
60
<< "S: A000001 OK GETMETADATA complete";
61
QMap<QByteArray, QByteArray> expected;
62
expected.insert("/shared/comment", "Shared comment");
63
expected.insert("/private/comment", "My own comment");
64
QTest::newRow( "combined response" ) << scenario << "Folder1" << expected;
70
QFETCH( QList<QByteArray>, scenario );
71
QFETCH( QString, mailbox );
72
QFETCH( MAP, expectedAnnotations );
74
FakeServer fakeServer;
75
fakeServer.setScenario( scenario );
76
fakeServer.startAndWait();
78
KIMAP::Session session( "127.0.0.1", 5989 );
80
KIMAP::GetMetaDataJob *getMetadataJob = new KIMAP::GetMetaDataJob( &session );
81
getMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Metadata );
82
getMetadataJob->setMailBox( mailbox );
83
getMetadataJob->setDepth( KIMAP::GetMetaDataJob::AllLevels );
84
getMetadataJob->addEntry( "/shared" );
86
QVERIFY( getMetadataJob->exec() );
87
QCOMPARE( getMetadataJob->allMetaData( mailbox ).size(), expectedAnnotations.size() );
88
foreach ( const QByteArray &entry, expectedAnnotations.keys() ) {
89
QCOMPARE( getMetadataJob->metaData(mailbox, entry), expectedAnnotations.value(entry) );
97
QTEST_KDEMAIN_CORE( GetMetadataJobTest )
99
#include "getmetadatajobtest.moc"