Changeset View
Changeset View
Standalone View
Standalone View
autotests/unit/file/pendingfilequeuetest.cpp
Show All 20 Lines | |||||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "pendingfilequeue.h" | 23 | #include "pendingfilequeue.h" | ||
24 | 24 | | |||
25 | #include <qtest.h> | 25 | #include <qtest.h> | ||
26 | #include <qsignalspy.h> | 26 | #include <qsignalspy.h> | ||
27 | #include <qtimer.h> | 27 | #include <qtimer.h> | ||
28 | 28 | | |||
29 | using namespace Baloo; | 29 | namespace Baloo { | ||
30 | 30 | | |||
31 | class PendingFileQueueTest : public QObject | 31 | class PendingFileQueueTest : public QObject | ||
32 | { | 32 | { | ||
33 | Q_OBJECT | 33 | Q_OBJECT | ||
34 | 34 | | |||
35 | public: | 35 | public: | ||
36 | PendingFileQueueTest(); | 36 | PendingFileQueueTest(); | ||
37 | 37 | | |||
38 | private Q_SLOTS: | 38 | private Q_SLOTS: | ||
39 | void testTimeout(); | 39 | void testTimeout(); | ||
40 | void testRequeue(); | 40 | void testRequeue(); | ||
41 | }; | 41 | }; | ||
42 | 42 | | |||
43 | PendingFileQueueTest::PendingFileQueueTest() | 43 | PendingFileQueueTest::PendingFileQueueTest() | ||
44 | { | 44 | { | ||
45 | } | 45 | } | ||
46 | 46 | | |||
47 | void PendingFileQueueTest::testTimeout() | 47 | void PendingFileQueueTest::testTimeout() | ||
48 | { | 48 | { | ||
49 | QString myUrl(QStringLiteral("/tmp")); | 49 | QString myUrl(QStringLiteral("/tmp")); | ||
50 | 50 | | |||
51 | PendingFileQueue queue; | 51 | PendingFileQueue queue; | ||
52 | queue.setMinimumTimeout(2); | 52 | queue.setMinimumTimeout(1); | ||
53 | queue.setTrackingTime(1); | ||||
53 | 54 | | |||
54 | QSignalSpy spy(&queue, SIGNAL(indexModifiedFile(QString))); | 55 | QSignalSpy spy(&queue, SIGNAL(indexModifiedFile(QString))); | ||
55 | QVERIFY(spy.isValid()); | 56 | QVERIFY(spy.isValid()); | ||
56 | 57 | | |||
57 | PendingFile file(myUrl); | 58 | PendingFile file(myUrl); | ||
58 | file.setModified(); | 59 | file.setModified(); | ||
59 | queue.enqueue(file); | 60 | queue.enqueue(file); | ||
60 | 61 | | |||
61 | // The signal should be emitted immediately | 62 | // The signal should be emitted immediately | ||
62 | QVERIFY(spy.wait()); | 63 | QVERIFY(spy.wait(50)); | ||
63 | QCOMPARE(spy.count(), 1); | 64 | QCOMPARE(spy.count(), 1); | ||
64 | QCOMPARE(spy.takeFirst().constFirst().toString(), myUrl); | 65 | QCOMPARE(spy.takeFirst().constFirst().toString(), myUrl); | ||
66 | QCOMPARE(queue.m_recentlyEmitted.count(), 1); | ||||
65 | 67 | | |||
66 | // Enqueue the url again. This time it should wait for should wait for the | 68 | // Enqueue the url again. This time it should wait for should wait for the | ||
67 | // minimumTimeout | 69 | // minimumTimeout | ||
68 | queue.enqueue(file); | 70 | queue.enqueue(file); | ||
69 | 71 | | |||
70 | QTest::qWait(1000); | 72 | QTest::qWait(100); | ||
73 | QCOMPARE(queue.m_pendingFiles.count(), 1); | ||||
74 | QCOMPARE(queue.m_recentlyEmitted.count(), 1); | ||||
71 | QVERIFY(spy.isEmpty()); | 75 | QVERIFY(spy.isEmpty()); | ||
72 | 76 | | |||
73 | QVERIFY(spy.wait(2000)); | 77 | QVERIFY(spy.wait(1500)); | ||
74 | QCOMPARE(spy.count(), 1); | 78 | QCOMPARE(spy.count(), 1); | ||
75 | QCOMPARE(spy.takeFirst().constFirst().toString(), myUrl); | 79 | QCOMPARE(spy.takeFirst().constFirst().toString(), myUrl); | ||
80 | QCOMPARE(queue.m_pendingFiles.count(), 0); | ||||
81 | QCOMPARE(queue.m_recentlyEmitted.count(), 1); | ||||
82 | | ||||
83 | // Wait for Tracking Time | ||||
84 | QTest::qWait(1500); | ||||
85 | QCOMPARE(queue.m_recentlyEmitted.count(), 0); | ||||
76 | } | 86 | } | ||
77 | 87 | | |||
78 | void PendingFileQueueTest::testRequeue() | 88 | void PendingFileQueueTest::testRequeue() | ||
79 | { | 89 | { | ||
80 | QString myUrl(QStringLiteral("/tmp")); | 90 | QString myUrl(QStringLiteral("/tmp")); | ||
81 | 91 | | |||
82 | PendingFileQueue queue; | 92 | PendingFileQueue queue; | ||
83 | queue.setMinimumTimeout(2); | 93 | queue.setMinimumTimeout(2); | ||
Show All 21 Lines | |||||
105 | 115 | | |||
106 | QTest::qWait(3500); | 116 | QTest::qWait(3500); | ||
107 | QVERIFY(spy.isEmpty()); | 117 | QVERIFY(spy.isEmpty()); | ||
108 | 118 | | |||
109 | QVERIFY(spy.wait(2500)); | 119 | QVERIFY(spy.wait(2500)); | ||
110 | QCOMPARE(spy.count(), 1); | 120 | QCOMPARE(spy.count(), 1); | ||
111 | QCOMPARE(spy.takeFirst().constFirst().toString(), myUrl); | 121 | QCOMPARE(spy.takeFirst().constFirst().toString(), myUrl); | ||
112 | } | 122 | } | ||
123 | } // namespace | ||||
113 | 124 | | |||
114 | QTEST_GUILESS_MAIN(PendingFileQueueTest) | 125 | QTEST_GUILESS_MAIN(Baloo::PendingFileQueueTest) | ||
115 | 126 | | |||
116 | #include "pendingfilequeuetest.moc" | 127 | #include "pendingfilequeuetest.moc" |