Changeset View
Changeset View
Standalone View
Standalone View
autotests/unit/file/pendingfilequeuetest.cpp
Show All 33 Lines | |||||
34 | 34 | | |||
35 | public: | 35 | public: | ||
36 | PendingFileQueueTest(); | 36 | PendingFileQueueTest(); | ||
37 | 37 | | |||
38 | private Q_SLOTS: | 38 | private Q_SLOTS: | ||
39 | void testTimers(); | 39 | void testTimers(); | ||
40 | void testTimeout(); | 40 | void testTimeout(); | ||
41 | void testRequeue(); | 41 | void testRequeue(); | ||
42 | void testDeleteCreate(); | ||||
42 | }; | 43 | }; | ||
43 | 44 | | |||
44 | PendingFileQueueTest::PendingFileQueueTest() | 45 | PendingFileQueueTest::PendingFileQueueTest() | ||
45 | { | 46 | { | ||
46 | } | 47 | } | ||
47 | 48 | | |||
48 | class TimerEventEater : public QObject | 49 | class TimerEventEater : public QObject | ||
49 | { | 50 | { | ||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Line(s) | 197 | while (true) { | |||
202 | QVERIFY2(elapsed10thSeconds <= 50, "Signal emitted late"); | 203 | QVERIFY2(elapsed10thSeconds <= 50, "Signal emitted late"); | ||
203 | elapsed10thSeconds++; | 204 | elapsed10thSeconds++; | ||
204 | } | 205 | } | ||
205 | QVERIFY2(elapsed10thSeconds > 40, "Signal emitted early"); | 206 | QVERIFY2(elapsed10thSeconds > 40, "Signal emitted early"); | ||
206 | 207 | | |||
207 | QCOMPARE(spy.count(), 1); | 208 | QCOMPARE(spy.count(), 1); | ||
208 | QCOMPARE(spy.takeFirst().constFirst().toString(), myUrl); | 209 | QCOMPARE(spy.takeFirst().constFirst().toString(), myUrl); | ||
209 | } | 210 | } | ||
211 | | ||||
212 | void PendingFileQueueTest::testDeleteCreate() | ||||
213 | { | ||||
214 | QString myUrl(QStringLiteral("/dir/testfile")); | ||||
215 | | ||||
216 | QTime currentTime = QTime::currentTime(); | ||||
217 | | ||||
218 | PendingFileQueue queue; | ||||
219 | | ||||
220 | auto eventEater = new TimerEventEater(this); | ||||
221 | queue.m_cacheTimer.installEventFilter(eventEater); | ||||
222 | queue.m_clearRecentlyEmittedTimer.installEventFilter(eventEater); | ||||
223 | queue.m_pendingFilesTimer.installEventFilter(eventEater); | ||||
224 | | ||||
225 | QSignalSpy spyModified(&queue, SIGNAL(indexModifiedFile(QString))); | ||||
226 | QSignalSpy spyRemoved(&queue, SIGNAL(removeFileIndex(QString))); | ||||
227 | QVERIFY(spyModified.isValid()); | ||||
228 | QVERIFY(spyRemoved.isValid()); | ||||
229 | | ||||
230 | PendingFile file1(myUrl); | ||||
231 | PendingFile file2(myUrl); | ||||
232 | file1.setDeleted(); | ||||
233 | file2.setModified(); | ||||
234 | | ||||
235 | queue.enqueue(file1); | ||||
236 | queue.enqueue(file2); | ||||
237 | QTimer::singleShot(0, [&queue, currentTime] { queue.processCache(currentTime); }); | ||||
238 | | ||||
239 | // The signals should be emitted immediately | ||||
240 | QVERIFY(spyModified.wait()); | ||||
241 | | ||||
242 | QCOMPARE(spyRemoved.count(), 1); | ||||
243 | QCOMPARE(spyRemoved.takeFirst().constFirst().toString(), myUrl); | ||||
244 | | ||||
245 | QCOMPARE(spyModified.count(), 1); | ||||
246 | QCOMPARE(spyModified.takeFirst().constFirst().toString(), myUrl); | ||||
247 | } | ||||
248 | | ||||
210 | } // namespace | 249 | } // namespace | ||
211 | 250 | | |||
212 | QTEST_GUILESS_MAIN(Baloo::PendingFileQueueTest) | 251 | QTEST_GUILESS_MAIN(Baloo::PendingFileQueueTest) | ||
213 | 252 | | |||
214 | #include "pendingfilequeuetest.moc" | 253 | #include "pendingfilequeuetest.moc" |