~ubuntu-branches/ubuntu/vivid/akonadi/vivid

« back to all changes in this revision

Viewing changes to libs/tests/notificationmessagev2test.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg, Rohan Garg, Philip Muškovac
  • Date: 2013-06-13 08:46:15 UTC
  • mfrom: (1.1.42)
  • Revision ID: package-import@ubuntu.com-20130613084615-e37v5pdoe2p2xu9d
Tags: 1.9.80-0ubuntu1
[ Rohan Garg ]
* New upstream release
  - Update symbols
  - Install asapcat with akonadi-server for now
  - Install notificationmessagev2_p.h with -dev package
  - Refresh disable_dbus_requiring_tests.diff

[ Philip Muškovac ]
* libkonadi-dev needs to depend on akonadi-server for the dbus service 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2007 Volker Krause <vkrause@kde.org>
 
3
    Copyright (c) 2013 Daniel Vrátil <dvratil@redhat.com>
 
4
 
 
5
    This library is free software; you can redistribute it and/or modify it
 
6
    under the terms of the GNU Library General Public License as published by
 
7
    the Free Software Foundation; either version 2 of the License, or (at your
 
8
    option) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful, but WITHOUT
 
11
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 
13
    License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Library General Public License
 
16
    along with this library; see the file COPYING.LIB.  If not, write to the
 
17
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
18
    02110-1301, USA.
 
19
*/
 
20
 
 
21
#include "notificationmessagev2test.h"
 
22
#include <notificationmessagev2_p.h>
 
23
 
 
24
#include <QSet>
 
25
#include <QtTest/QTest>
 
26
 
 
27
QTEST_APPLESS_MAIN( NotificationMessageV2Test )
 
28
 
 
29
using namespace Akonadi;
 
30
 
 
31
Q_DECLARE_METATYPE( NotificationMessageV2::Type )
 
32
 
 
33
void NotificationMessageV2Test::testCompress()
 
34
{
 
35
  NotificationMessageV2::List list;
 
36
  NotificationMessageV2 msg;
 
37
  msg.setType( NotificationMessageV2::Items );
 
38
  msg.setOperation( NotificationMessageV2::Add );
 
39
 
 
40
  NotificationMessageV2::appendAndCompress( list, msg );
 
41
  QCOMPARE( list.count(), 1 );
 
42
 
 
43
  msg.setOperation( NotificationMessageV2::Modify );
 
44
  NotificationMessageV2::appendAndCompress( list, msg );
 
45
  QCOMPARE( list.count(), 1 );
 
46
  QCOMPARE( list.first().operation(), NotificationMessageV2::Add );
 
47
 
 
48
  msg.setOperation( NotificationMessageV2::Remove );
 
49
  NotificationMessageV2::appendAndCompress( list, msg );
 
50
  QCOMPARE( list.count(), 2 ); // should be 2 for collections, 0 for items?
 
51
}
 
52
 
 
53
void NotificationMessageV2Test::testCompress2()
 
54
{
 
55
  NotificationMessageV2::List list;
 
56
  NotificationMessageV2 msg;
 
57
  msg.setType( NotificationMessageV2::Items );
 
58
  msg.setOperation( NotificationMessageV2::Modify );
 
59
 
 
60
  NotificationMessageV2::appendAndCompress( list, msg );
 
61
  QCOMPARE( list.count(), 1 );
 
62
 
 
63
  msg.setOperation( NotificationMessageV2::Remove );
 
64
  NotificationMessageV2::appendAndCompress( list, msg );
 
65
  QCOMPARE( list.count(), 1 );
 
66
  QCOMPARE( list.first().operation(), NotificationMessageV2::Remove );
 
67
}
 
68
 
 
69
void NotificationMessageV2Test::testCompress3()
 
70
{
 
71
  NotificationMessageV2::List list;
 
72
 
 
73
  NotificationMessageV2 msg;
 
74
  msg.setType( NotificationMessageV2::Items );
 
75
  msg.setOperation( NotificationMessageV2::Modify );
 
76
  msg.setItemParts( QSet<QByteArray>() << "PART1" );
 
77
  NotificationMessageV2::appendAndCompress( list, msg );
 
78
  QCOMPARE( list.count(), 1 );
 
79
 
 
80
  NotificationMessageV2 msg2;
 
81
  msg2.setType( NotificationMessageV2::Items );
 
82
  msg2.setOperation( NotificationMessageV2::Modify );
 
83
  msg2.setItemParts( QSet<QByteArray>() << "PART2" );
 
84
  NotificationMessageV2::appendAndCompress( list, msg2 );
 
85
 
 
86
  QCOMPARE( list.count(), 1 );
 
87
  QCOMPARE( list.first().itemParts(), QSet<QByteArray>() << "PART1" << "PART2" );
 
88
}
 
89
 
 
90
void NotificationMessageV2Test::testCompress4()
 
91
{
 
92
  NotificationMessageV2::List list;
 
93
  NotificationMessageV2 msg;
 
94
  msg.setType( NotificationMessageV2::Items );
 
95
  msg.setOperation( NotificationMessageV2::ModifyFlags );
 
96
 
 
97
  QSet<QByteArray> set;
 
98
  set << "FLAG1";
 
99
  msg.setAddedFlags( set );
 
100
  NotificationMessageV2::appendAndCompress( list, msg );
 
101
  QCOMPARE( list.count(), 1 );
 
102
 
 
103
  set.clear();
 
104
  msg.setAddedFlags( set );
 
105
  set << "FLAG2";
 
106
  msg.setRemovedFlags( set );
 
107
  NotificationMessageV2::appendAndCompress( list, msg );
 
108
  QCOMPARE( list.count(), 1 );
 
109
  QCOMPARE( list.first().addedFlags(), (QSet<QByteArray>() << "FLAG1") );
 
110
  QCOMPARE( list.first().removedFlags(), (QSet<QByteArray>() << "FLAG2") );
 
111
}
 
112
 
 
113
void NotificationMessageV2Test::testCompress5()
 
114
{
 
115
  NotificationMessageV2::List list;
 
116
  NotificationMessageV2 msg;
 
117
  msg.setType( NotificationMessageV2::Items );
 
118
  msg.setOperation( NotificationMessageV2::ModifyFlags );
 
119
 
 
120
  msg.setAddedFlags( QSet<QByteArray>() << "FLAG1" << "FLAG2" );
 
121
  NotificationMessageV2::appendAndCompress( list, msg );
 
122
  QCOMPARE( list.count(), 1 );
 
123
 
 
124
  NotificationMessageV2 msg2;
 
125
  msg2.setType( NotificationMessageV2::Items );
 
126
  msg2.setOperation( NotificationMessageV2::Add );
 
127
  msg2.setAddedFlags( QSet<QByteArray>() );
 
128
  NotificationMessageV2::appendAndCompress( list, msg2 );
 
129
 
 
130
  msg.setAddedFlags( QSet<QByteArray>() );
 
131
  msg.setRemovedFlags( QSet<QByteArray>() << "FLAG2" << "FLAG1" );
 
132
  NotificationMessageV2::appendAndCompress( list, msg );
 
133
  QCOMPARE( list.count(), 1 );
 
134
  QCOMPARE( list.first().operation(), NotificationMessageV2::Add );
 
135
}
 
136
 
 
137
void NotificationMessageV2Test::testCompress6()
 
138
{
 
139
  NotificationMessageV2::List list;
 
140
  NotificationMessageV2 msg;
 
141
  msg.setType( NotificationMessageV2::Items );
 
142
  msg.setOperation( NotificationMessageV2::ModifyFlags );
 
143
  msg.setAddedFlags( QSet<QByteArray>() << "FLAG1" );
 
144
  NotificationMessageV2::appendAndCompress( list, msg );
 
145
  QCOMPARE( list.count(), 1 );
 
146
 
 
147
  NotificationMessageV2 msg2;
 
148
  msg2.setType( NotificationMessageV2::Items );
 
149
  msg2.setOperation( NotificationMessageV2::ModifyFlags );
 
150
  msg2.setAddedFlags( QSet<QByteArray>() << "FLAG2" );
 
151
  NotificationMessageV2::appendAndCompress( list, msg2 );
 
152
 
 
153
  QCOMPARE( list.count(), 1 );
 
154
  QCOMPARE( list.first().operation(), NotificationMessageV2::ModifyFlags );
 
155
  QCOMPARE( list.first().addedFlags(), QSet<QByteArray>() << "FLAG1" << "FLAG2" );
 
156
}
 
157
 
 
158
void NotificationMessageV2Test::testCompress7()
 
159
{
 
160
  NotificationMessageV2::List list;
 
161
  NotificationMessageV2 msg;
 
162
  msg.setType( NotificationMessageV2::Items );
 
163
  msg.setOperation( NotificationMessageV2::Modify );
 
164
  msg.setItemParts( QSet<QByteArray>() << "PART1" );
 
165
  NotificationMessageV2::appendAndCompress( list, msg );
 
166
  QCOMPARE( list.count(), 1 );
 
167
 
 
168
  NotificationMessageV2 msg2;
 
169
  msg2.setType( NotificationMessageV2::Items );
 
170
  msg2.setOperation( NotificationMessageV2::ModifyFlags );
 
171
  msg2.setAddedFlags( QSet<QByteArray>() << "FLAG1" );
 
172
  NotificationMessageV2::appendAndCompress( list, msg2 );
 
173
 
 
174
  QCOMPARE( list.count(), 2 );
 
175
}
 
176
 
 
177
void NotificationMessageV2Test::testCompressWithItemParts()
 
178
{
 
179
  NotificationMessageV2::List list;
 
180
  NotificationMessageV2 msg;
 
181
  msg.setType( NotificationMessageV2::Items );
 
182
  msg.setOperation( NotificationMessageV2::Add );
 
183
 
 
184
  NotificationMessageV2::appendAndCompress( list, msg );
 
185
  QCOMPARE( list.count(), 1 );
 
186
 
 
187
  msg.setOperation( NotificationMessageV2::Modify );
 
188
  QSet<QByteArray> parts;
 
189
  parts << "SomePart";
 
190
  msg.setAddedFlags( parts );
 
191
  NotificationMessageV2::appendAndCompress( list, msg );
 
192
  NotificationMessageV2::appendAndCompress( list, msg );
 
193
 
 
194
  QCOMPARE( list.count(), 1 );
 
195
  QCOMPARE( list.first().operation(), NotificationMessageV2::Add );
 
196
  QCOMPARE( list.first().itemParts(), QSet<QByteArray>() );
 
197
 
 
198
  list.clear();
 
199
  NotificationMessageV2::appendAndCompress( list, msg );
 
200
  QCOMPARE( list.count(), 1 );
 
201
 
 
202
  msg.setOperation( NotificationMessageV2::Remove );
 
203
  msg.setItemParts( QSet<QByteArray>() );
 
204
  NotificationMessageV2::appendAndCompress( list, msg );
 
205
 
 
206
  QCOMPARE( list.count(), 1 );
 
207
  QCOMPARE( list.first().operation(), NotificationMessageV2::Remove );
 
208
  QCOMPARE( list.first().itemParts(), QSet<QByteArray>() );
 
209
}
 
210
 
 
211
void NotificationMessageV2Test::testNoCompress()
 
212
{
 
213
  NotificationMessageV2::List list;
 
214
  NotificationMessageV2 msg;
 
215
  msg.setType( NotificationMessageV2::Items );
 
216
  msg.setOperation( NotificationMessageV2::Modify );
 
217
 
 
218
  NotificationMessageV2::appendAndCompress( list, msg );
 
219
  QCOMPARE( list.count(), 1 );
 
220
 
 
221
  msg.setType( NotificationMessageV2::Collections );
 
222
  NotificationMessageV2::appendAndCompress( list, msg );
 
223
  QCOMPARE( list.count(), 2 );
 
224
}
 
225
 
 
226
void NotificationMessageV2Test::testPartModificationMerge_data()
 
227
{
 
228
  QTest::addColumn<NotificationMessageV2::Type>( "type" );
 
229
  QTest::newRow( "item" ) << NotificationMessageV2::Items;
 
230
  QTest::newRow( "collection" ) << NotificationMessageV2::Collections;
 
231
}
 
232
 
 
233
void NotificationMessageV2Test::testPartModificationMerge()
 
234
{
 
235
  QFETCH( NotificationMessageV2::Type, type );
 
236
 
 
237
  NotificationMessageV2::List list;
 
238
  NotificationMessageV2 msg;
 
239
  msg.setType( type );
 
240
  msg.setOperation( NotificationMessageV2::Modify );
 
241
  msg.setItemParts( QSet<QByteArray>() << "PART1" );
 
242
 
 
243
  NotificationMessageV2::appendAndCompress( list, msg );
 
244
  QCOMPARE( list.count(), 1 );
 
245
 
 
246
  msg.setItemParts( QSet<QByteArray>() << "PART2" );
 
247
  NotificationMessageV2::appendAndCompress( list, msg );
 
248
  QCOMPARE( list.count(), 1 );
 
249
  QCOMPARE( list.first().itemParts(), (QSet<QByteArray>() << "PART1" << "PART2") );
 
250
}