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

« back to all changes in this revision

Viewing changes to kimap/tests/idlejobtest.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:
29
29
#include <KDebug>
30
30
 
31
31
Q_DECLARE_METATYPE( QList<int> )
 
32
Q_DECLARE_METATYPE( QList<qint64> )
32
33
Q_DECLARE_METATYPE( KIMAP::IdleJob* )
33
34
 
34
35
class IdleJobTest: public QObject {
48
49
  QTest::addColumn<QString>( "expectedMailBox" );
49
50
  QTest::addColumn< QList<int> >( "expectedMessageCounts" );
50
51
  QTest::addColumn< QList<int> >( "expectedRecentCounts" );
 
52
  QTest::addColumn< QList<qint64> >( "expectedFlagsNotifications" );
51
53
 
52
54
  QList<QByteArray> scenario;
53
55
  QString expectedMailBox;
54
56
  QList<int> expectedMessageCounts;
55
57
  QList<int> expectedRecentCounts;
 
58
  QList<qint64> expectedFlagsNotifications;
56
59
 
57
60
  scenario.clear();
58
61
  scenario << FakeServer::preauth()
74
77
  expectedMessageCounts << 1 << 2;
75
78
  expectedRecentCounts << 0 << 1;
76
79
 
77
 
  QTest::newRow( "normal" ) << scenario << expectedMailBox << expectedMessageCounts << expectedRecentCounts;
 
80
  QTest::newRow( "normal" ) << scenario << expectedMailBox << expectedMessageCounts << expectedRecentCounts << expectedFlagsNotifications;
78
81
 
79
82
  scenario.clear();
80
83
  scenario << FakeServer::preauth()
94
97
  expectedMessageCounts << -1 << -1;
95
98
  expectedRecentCounts << 0 << 1;
96
99
 
97
 
  QTest::newRow( "only RECENT" ) << scenario << expectedMailBox << expectedMessageCounts << expectedRecentCounts;
 
100
  QTest::newRow( "only RECENT" ) << scenario << expectedMailBox << expectedMessageCounts << expectedRecentCounts << expectedFlagsNotifications;
98
101
 
99
102
  scenario.clear();
100
103
  scenario << FakeServer::preauth()
114
117
  expectedMessageCounts << 1 << 2;
115
118
  expectedRecentCounts << -1 << -1;
116
119
 
117
 
  QTest::newRow( "only EXISTS" ) << scenario << expectedMailBox << expectedMessageCounts << expectedRecentCounts;
 
120
  QTest::newRow( "only EXISTS" ) << scenario << expectedMailBox << expectedMessageCounts << expectedRecentCounts << expectedFlagsNotifications;
118
121
 
119
122
  scenario.clear();
120
123
  scenario << FakeServer::preauth()
135
138
  expectedMessageCounts << 2;
136
139
  expectedRecentCounts << 1;
137
140
 
138
 
  QTest::newRow( "under 200ms, same notification" ) << scenario << expectedMailBox << expectedMessageCounts << expectedRecentCounts;
 
141
  QTest::newRow( "under 200ms, same notification" ) << scenario << expectedMailBox << expectedMessageCounts << expectedRecentCounts << expectedFlagsNotifications;
139
142
 
140
143
  scenario.clear();
141
144
  scenario << FakeServer::preauth()
156
159
  expectedMessageCounts << 2 << -1;
157
160
  expectedRecentCounts << -1 << 1;
158
161
 
159
 
  QTest::newRow( "above 200ms, two notifications" ) << scenario << expectedMailBox << expectedMessageCounts << expectedRecentCounts;
 
162
  QTest::newRow( "above 200ms, two notifications" ) << scenario << expectedMailBox << expectedMessageCounts << expectedRecentCounts << expectedFlagsNotifications;
 
163
 
 
164
  scenario.clear();
 
165
  scenario << FakeServer::preauth()
 
166
           << "C: A000001 SELECT \"INBOX/Foo\""
 
167
           << "S: A000001 OK SELECT done"
 
168
           << "C: A000002 IDLE"
 
169
           << "S: + OK"
 
170
           << "S: * 1 FETCH (FLAGS ())"
 
171
           << "W: 200"
 
172
           << "S: * 2 FETCH (FLAGS (\\Seen))"
 
173
           << "S: A000002 OK done idling";
 
174
 
 
175
  expectedMailBox = "INBOX/Foo";
 
176
 
 
177
  expectedMessageCounts.clear();
 
178
  expectedRecentCounts.clear();
 
179
  expectedFlagsNotifications << 1 << 2;
 
180
 
 
181
  QTest::newRow("2 flags change notifications") << scenario << expectedMailBox << expectedMessageCounts << expectedRecentCounts << expectedFlagsNotifications;
160
182
}
161
183
 
162
184
void shouldReactToIdle()
165
187
    QFETCH( QString, expectedMailBox );
166
188
    QFETCH( QList<int>, expectedMessageCounts );
167
189
    QFETCH( QList<int>, expectedRecentCounts );
 
190
    QFETCH( QList<qint64>, expectedFlagsNotifications );
168
191
 
169
192
    QVERIFY( expectedMessageCounts.size() == expectedRecentCounts.size() );
170
193
 
180
203
 
181
204
    KIMAP::IdleJob *idle = new KIMAP::IdleJob( &session );
182
205
 
183
 
    QSignalSpy spy( idle, SIGNAL(mailBoxStats(KIMAP::IdleJob*,QString,int,int)) );
 
206
    QSignalSpy statsSpy( idle, SIGNAL(mailBoxStats(KIMAP::IdleJob*,QString,int,int)) );
 
207
    QSignalSpy flagsSpy( idle, SIGNAL(mailBoxMessageFlagsChanged(KIMAP::IdleJob*,qint64)) );
184
208
 
185
209
    bool result = idle->exec();
186
210
 
187
211
    if ( result ) {
188
 
      QCOMPARE( spy.count(), expectedMessageCounts.size() );
 
212
      QCOMPARE( statsSpy.count(), expectedMessageCounts.size() );
 
213
      QCOMPARE( flagsSpy.count(), expectedFlagsNotifications.size() );
189
214
 
190
 
      for ( int i=0; i<spy.count(); i++ ) {
191
 
        const KIMAP::IdleJob *job = spy.at( i ).at( 0 ).value<KIMAP::IdleJob*>();
192
 
        const QString mailBox = spy.at( i ).at( 1 ).toString();
193
 
        const int messageCount = spy.at( i ).at( 2 ).toInt();
194
 
        const int recentCount = spy.at( i ).at( 3 ).toInt();
 
215
      for ( int i = 0 ; i < statsSpy.count(); i++ ) {
 
216
        const KIMAP::IdleJob *job = statsSpy.at( i ).at( 0 ).value<KIMAP::IdleJob*>();
 
217
        const QString mailBox = statsSpy.at( i ).at( 1 ).toString();
 
218
        const int messageCount = statsSpy.at( i ).at( 2 ).toInt();
 
219
        const int recentCount = statsSpy.at( i ).at( 3 ).toInt();
195
220
 
196
221
        QCOMPARE( job, idle );
197
222
        QCOMPARE( mailBox, expectedMailBox );
198
223
        QCOMPARE( messageCount, expectedMessageCounts.at( i ) );
199
224
        QCOMPARE( recentCount, expectedRecentCounts.at( i ) );
200
225
      }
 
226
 
 
227
      for ( int i = 0; i < flagsSpy.count(); i++ ) {
 
228
        const KIMAP::IdleJob *job = flagsSpy.at( i ).at( 0 ).value<KIMAP::IdleJob*>();
 
229
        const qint64 uid = flagsSpy.at( i ).at( 1 ).toLongLong();
 
230
 
 
231
        QCOMPARE( job, idle );
 
232
        QCOMPARE( uid, expectedFlagsNotifications.at( i ) );
 
233
      }
201
234
    }
202
235
 
203
236
    fakeServer.quit();