~ubuntu-branches/ubuntu/trusty/kdepimlibs/trusty

« back to all changes in this revision

Viewing changes to kimap/tests/getmetadatajobtest.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg, Rohan Garg, Philip Muškovac
  • Date: 2013-11-23 17:36:44 UTC
  • mfrom: (1.1.102)
  • Revision ID: package-import@ubuntu.com-20131123173644-p5ow94192ezsny8g
Tags: 4:4.11.80-0ubuntu1
[ Rohan Garg ]
* New upstream beta release
  - Bump akonadi requirement to 1.10.45
  - Update install files
  - Update symbols

[ Philip Muškovac ]
* kdepimlibs-dev/-dbg breaks/replaces kdepim-runtime/-dbg (<< 4:4.11.80)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2013 Christian Mollekopf <mollekopf@kolabsys.com>
 
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 "kimaptest/fakeserver.h"
 
22
#include "kimap/session.h"
 
23
#include "kimap/getmetadatajob.h"
 
24
 
 
25
#include <QTcpSocket>
 
26
#include <QtTest>
 
27
#include <KDebug>
 
28
 
 
29
typedef QMap<QByteArray,QByteArray> MAP;
 
30
Q_DECLARE_METATYPE(MAP)
 
31
 
 
32
class GetMetadataJobTest: public QObject {
 
33
  Q_OBJECT
 
34
 
 
35
private Q_SLOTS:
 
36
 
 
37
void metadata_data()
 
38
{
 
39
  QTest::addColumn<QList<QByteArray> >( "scenario" );
 
40
  QTest::addColumn<QString>( "mailbox" );
 
41
  QTest::addColumn<QMap<QByteArray, QByteArray> >( "expectedAnnotations" );
 
42
 
 
43
  {
 
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;
 
54
  }
 
55
  {
 
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;
 
65
  }
 
66
}
 
67
 
 
68
void metadata()
 
69
{
 
70
  QFETCH( QList<QByteArray>, scenario );
 
71
  QFETCH( QString, mailbox );
 
72
  QFETCH( MAP, expectedAnnotations );
 
73
 
 
74
  FakeServer fakeServer;
 
75
  fakeServer.setScenario( scenario );
 
76
  fakeServer.startAndWait();
 
77
 
 
78
  KIMAP::Session session( "127.0.0.1", 5989 );
 
79
 
 
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" );
 
85
 
 
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) );
 
90
  }
 
91
 
 
92
  fakeServer.quit();
 
93
}
 
94
 
 
95
};
 
96
 
 
97
QTEST_KDEMAIN_CORE( GetMetadataJobTest )
 
98
 
 
99
#include "getmetadatajobtest.moc"