2
Copyright (c) 2007 Volker Krause <vkrause@kde.org>
3
Copyright (c) 2013 Daniel Vrátil <dvratil@redhat.com>
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.
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.
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
21
#include "notificationmessagev2test.h"
22
#include <notificationmessagev2_p.h>
25
#include <QtTest/QTest>
27
QTEST_APPLESS_MAIN( NotificationMessageV2Test )
29
using namespace Akonadi;
31
Q_DECLARE_METATYPE( NotificationMessageV2::Type )
33
void NotificationMessageV2Test::testCompress()
35
NotificationMessageV2::List list;
36
NotificationMessageV2 msg;
37
msg.setType( NotificationMessageV2::Items );
38
msg.setOperation( NotificationMessageV2::Add );
40
NotificationMessageV2::appendAndCompress( list, msg );
41
QCOMPARE( list.count(), 1 );
43
msg.setOperation( NotificationMessageV2::Modify );
44
NotificationMessageV2::appendAndCompress( list, msg );
45
QCOMPARE( list.count(), 1 );
46
QCOMPARE( list.first().operation(), NotificationMessageV2::Add );
48
msg.setOperation( NotificationMessageV2::Remove );
49
NotificationMessageV2::appendAndCompress( list, msg );
50
QCOMPARE( list.count(), 2 ); // should be 2 for collections, 0 for items?
53
void NotificationMessageV2Test::testCompress2()
55
NotificationMessageV2::List list;
56
NotificationMessageV2 msg;
57
msg.setType( NotificationMessageV2::Items );
58
msg.setOperation( NotificationMessageV2::Modify );
60
NotificationMessageV2::appendAndCompress( list, msg );
61
QCOMPARE( list.count(), 1 );
63
msg.setOperation( NotificationMessageV2::Remove );
64
NotificationMessageV2::appendAndCompress( list, msg );
65
QCOMPARE( list.count(), 1 );
66
QCOMPARE( list.first().operation(), NotificationMessageV2::Remove );
69
void NotificationMessageV2Test::testCompress3()
71
NotificationMessageV2::List list;
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 );
80
NotificationMessageV2 msg2;
81
msg2.setType( NotificationMessageV2::Items );
82
msg2.setOperation( NotificationMessageV2::Modify );
83
msg2.setItemParts( QSet<QByteArray>() << "PART2" );
84
NotificationMessageV2::appendAndCompress( list, msg2 );
86
QCOMPARE( list.count(), 1 );
87
QCOMPARE( list.first().itemParts(), QSet<QByteArray>() << "PART1" << "PART2" );
90
void NotificationMessageV2Test::testCompress4()
92
NotificationMessageV2::List list;
93
NotificationMessageV2 msg;
94
msg.setType( NotificationMessageV2::Items );
95
msg.setOperation( NotificationMessageV2::ModifyFlags );
99
msg.setAddedFlags( set );
100
NotificationMessageV2::appendAndCompress( list, msg );
101
QCOMPARE( list.count(), 1 );
104
msg.setAddedFlags( set );
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") );
113
void NotificationMessageV2Test::testCompress5()
115
NotificationMessageV2::List list;
116
NotificationMessageV2 msg;
117
msg.setType( NotificationMessageV2::Items );
118
msg.setOperation( NotificationMessageV2::ModifyFlags );
120
msg.setAddedFlags( QSet<QByteArray>() << "FLAG1" << "FLAG2" );
121
NotificationMessageV2::appendAndCompress( list, msg );
122
QCOMPARE( list.count(), 1 );
124
NotificationMessageV2 msg2;
125
msg2.setType( NotificationMessageV2::Items );
126
msg2.setOperation( NotificationMessageV2::Add );
127
msg2.setAddedFlags( QSet<QByteArray>() );
128
NotificationMessageV2::appendAndCompress( list, msg2 );
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 );
137
void NotificationMessageV2Test::testCompress6()
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 );
147
NotificationMessageV2 msg2;
148
msg2.setType( NotificationMessageV2::Items );
149
msg2.setOperation( NotificationMessageV2::ModifyFlags );
150
msg2.setAddedFlags( QSet<QByteArray>() << "FLAG2" );
151
NotificationMessageV2::appendAndCompress( list, msg2 );
153
QCOMPARE( list.count(), 1 );
154
QCOMPARE( list.first().operation(), NotificationMessageV2::ModifyFlags );
155
QCOMPARE( list.first().addedFlags(), QSet<QByteArray>() << "FLAG1" << "FLAG2" );
158
void NotificationMessageV2Test::testCompress7()
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 );
168
NotificationMessageV2 msg2;
169
msg2.setType( NotificationMessageV2::Items );
170
msg2.setOperation( NotificationMessageV2::ModifyFlags );
171
msg2.setAddedFlags( QSet<QByteArray>() << "FLAG1" );
172
NotificationMessageV2::appendAndCompress( list, msg2 );
174
QCOMPARE( list.count(), 2 );
177
void NotificationMessageV2Test::testCompressWithItemParts()
179
NotificationMessageV2::List list;
180
NotificationMessageV2 msg;
181
msg.setType( NotificationMessageV2::Items );
182
msg.setOperation( NotificationMessageV2::Add );
184
NotificationMessageV2::appendAndCompress( list, msg );
185
QCOMPARE( list.count(), 1 );
187
msg.setOperation( NotificationMessageV2::Modify );
188
QSet<QByteArray> parts;
190
msg.setAddedFlags( parts );
191
NotificationMessageV2::appendAndCompress( list, msg );
192
NotificationMessageV2::appendAndCompress( list, msg );
194
QCOMPARE( list.count(), 1 );
195
QCOMPARE( list.first().operation(), NotificationMessageV2::Add );
196
QCOMPARE( list.first().itemParts(), QSet<QByteArray>() );
199
NotificationMessageV2::appendAndCompress( list, msg );
200
QCOMPARE( list.count(), 1 );
202
msg.setOperation( NotificationMessageV2::Remove );
203
msg.setItemParts( QSet<QByteArray>() );
204
NotificationMessageV2::appendAndCompress( list, msg );
206
QCOMPARE( list.count(), 1 );
207
QCOMPARE( list.first().operation(), NotificationMessageV2::Remove );
208
QCOMPARE( list.first().itemParts(), QSet<QByteArray>() );
211
void NotificationMessageV2Test::testNoCompress()
213
NotificationMessageV2::List list;
214
NotificationMessageV2 msg;
215
msg.setType( NotificationMessageV2::Items );
216
msg.setOperation( NotificationMessageV2::Modify );
218
NotificationMessageV2::appendAndCompress( list, msg );
219
QCOMPARE( list.count(), 1 );
221
msg.setType( NotificationMessageV2::Collections );
222
NotificationMessageV2::appendAndCompress( list, msg );
223
QCOMPARE( list.count(), 2 );
226
void NotificationMessageV2Test::testPartModificationMerge_data()
228
QTest::addColumn<NotificationMessageV2::Type>( "type" );
229
QTest::newRow( "item" ) << NotificationMessageV2::Items;
230
QTest::newRow( "collection" ) << NotificationMessageV2::Collections;
233
void NotificationMessageV2Test::testPartModificationMerge()
235
QFETCH( NotificationMessageV2::Type, type );
237
NotificationMessageV2::List list;
238
NotificationMessageV2 msg;
240
msg.setOperation( NotificationMessageV2::Modify );
241
msg.setItemParts( QSet<QByteArray>() << "PART1" );
243
NotificationMessageV2::appendAndCompress( list, msg );
244
QCOMPARE( list.count(), 1 );
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") );