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

« back to all changes in this revision

Viewing changes to akonadi/xml/tests/collection.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) Igor Trindade Oliveira <igor_trindade@yahoo.com.br>
 
3
 
 
4
    This library is free software; you can redistribute it and/or modify it
 
5
    under the terms of the GNU Library General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or (at your
 
7
    option) any later version.
 
8
 
 
9
    This library is distributed in the hope that it will be useful, but WITHOUT
 
10
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
11
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 
12
    License for more details.
 
13
 
 
14
    You should have received a copy of the GNU Library General Public License
 
15
    along with this library; see the file COPYING.LIB.  If not, write to the
 
16
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
17
    02110-1301, USA.
 
18
*/
 
19
 
 
20
#include "collection.h"
 
21
#include <xml/xmlreader.h>
 
22
#include <xml/xmlwriter.h>
 
23
 
 
24
#include <akonadi/entitydisplayattribute.h>
 
25
 
 
26
#include <qtest_kde.h>
 
27
#include <kdebug.h>
 
28
 
 
29
QTEST_KDEMAIN(CollectionTest, NoGUI)
 
30
 
 
31
QByteArray collection1(
 
32
"<test>\n"
 
33
" <collection content=\"inode/directory,message/rfc822\" rid=\"c11\" name=\"Inbox\">\n"
 
34
"  <attribute type=\"ENTITYDISPLAY\">(\"Posteingang\" \"mail-folder-inbox\" \"\" ())</attribute>\n"
 
35
" </collection>\n"
 
36
"</test>\n");
 
37
 
 
38
QByteArray collection2(
 
39
"<test> \
 
40
  <collection rid=\"c11\" name=\"Inbox\" content=\"inode/directory,message/rfc822\">           \
 
41
      <attribute type=\"ENTITYDISPLAY\" >(\"Posteingang\" \"mail-folder-inbox\" false)</attribute>  \
 
42
      <collection rid=\"c111\" name=\"KDE PIM\" content=\"inode/directory,message/rfc822\">   \
 
43
      </collection>                                                                                  \
 
44
      <collection rid=\"c112\" name=\"Akonadi\" content=\"inode/directory,message/rfc822\">   \
 
45
        <attribute type=\"AccessRights\">wcW</attribute>                                       \
 
46
      </collection>                                                                              \
 
47
    </collection>                                                                              \
 
48
<test>");
 
49
 
 
50
void CollectionTest::testBuildCollection()
 
51
{
 
52
  QDomDocument mDocument;
 
53
 
 
54
  mDocument.setContent( collection1, true, 0 );
 
55
  Collection::List colist = XmlReader::readCollections( mDocument.documentElement() );
 
56
 
 
57
  QStringList mimeType;
 
58
 
 
59
  mimeType << QLatin1String( "inode/directory" ) << QLatin1String( "message/rfc822" );
 
60
  QCOMPARE( colist.size(), 1 );
 
61
  verifyCollection( colist, 0, QLatin1String( "c11" ), QLatin1String( "Inbox" ), mimeType );
 
62
 
 
63
  mDocument.setContent( collection2, true, 0 );
 
64
  colist = XmlReader::readCollections( mDocument.documentElement() );
 
65
 
 
66
  QCOMPARE( colist.size(), 3 );
 
67
  verifyCollection( colist, 0, QLatin1String( "c11" ), QLatin1String( "Inbox" ), mimeType );
 
68
  verifyCollection( colist, 1, QLatin1String( "c111" ), QLatin1String( "KDE PIM" ), mimeType );
 
69
  verifyCollection( colist, 2, QLatin1String( "c112" ), QLatin1String( "Akonadi" ), mimeType );
 
70
 
 
71
  QVERIFY( colist.at( 0 ).hasAttribute<EntityDisplayAttribute>() );
 
72
  EntityDisplayAttribute *attr = colist.at( 0 ).attribute<EntityDisplayAttribute>();
 
73
  QCOMPARE( attr->displayName(), QString::fromLatin1( "Posteingang" ) );
 
74
}
 
75
 
 
76
void CollectionTest::serializeCollection()
 
77
{
 
78
  Collection c;
 
79
  c.setRemoteId( QLatin1String( "c11" ) );
 
80
  c.setName( QLatin1String( "Inbox" ) );
 
81
  c.setContentMimeTypes( QStringList() << Collection::mimeType() << QLatin1String( "message/rfc822" ) );
 
82
  c.attribute<EntityDisplayAttribute>( Collection::AddIfMissing )->setDisplayName( QLatin1String( "Posteingang" ) );
 
83
  c.attribute<EntityDisplayAttribute>()->setIconName( QLatin1String( "mail-folder-inbox" ) );
 
84
 
 
85
  QDomDocument doc;
 
86
  QDomElement root = doc.createElement( QLatin1String( "test" ) );
 
87
  doc.appendChild( root );
 
88
  XmlWriter::writeCollection( c, root );
 
89
 
 
90
  QCOMPARE( doc.toString(), QString::fromUtf8( collection1 ) );
 
91
}
 
92
 
 
93
void CollectionTest::verifyCollection( const Collection::List &colist, int listPosition,
 
94
                                       const QString &remoteId, const QString &name,
 
95
                                       const QStringList &mimeType )
 
96
{
 
97
  QVERIFY( colist.at( listPosition ).name() == name );
 
98
  QVERIFY( colist.at( listPosition ).remoteId() == remoteId );
 
99
  QVERIFY( colist.at( listPosition ).contentMimeTypes() == mimeType );
 
100
}