Changeset View
Changeset View
Standalone View
Standalone View
autotests/unit/file/pendingfilequeuetest.cpp
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 48 | { | |||
---|---|---|---|---|---|
56 | 56 | | |||
57 | PendingFile file(myUrl); | 57 | PendingFile file(myUrl); | ||
58 | file.setModified(); | 58 | file.setModified(); | ||
59 | queue.enqueue(file); | 59 | queue.enqueue(file); | ||
60 | 60 | | |||
61 | // The signal should be emitted immediately | 61 | // The signal should be emitted immediately | ||
62 | QVERIFY(spy.wait()); | 62 | QVERIFY(spy.wait()); | ||
63 | QCOMPARE(spy.count(), 1); | 63 | QCOMPARE(spy.count(), 1); | ||
64 | QCOMPARE(spy.takeFirst().first().toString(), myUrl); | 64 | QCOMPARE(spy.takeFirst().constFirst().toString(), myUrl); | ||
65 | 65 | | |||
66 | // Enqueue the url again. This time it should wait for should wait for the | 66 | // Enqueue the url again. This time it should wait for should wait for the | ||
67 | // minimumTimeout | 67 | // minimumTimeout | ||
68 | queue.enqueue(file); | 68 | queue.enqueue(file); | ||
69 | 69 | | |||
70 | QTest::qWait(1000); | 70 | QTest::qWait(1000); | ||
71 | QVERIFY(spy.isEmpty()); | 71 | QVERIFY(spy.isEmpty()); | ||
72 | 72 | | |||
73 | QVERIFY(spy.wait(2000)); | 73 | QVERIFY(spy.wait(2000)); | ||
74 | QCOMPARE(spy.count(), 1); | 74 | QCOMPARE(spy.count(), 1); | ||
75 | QCOMPARE(spy.takeFirst().first().toString(), myUrl); | 75 | QCOMPARE(spy.takeFirst().constFirst().toString(), myUrl); | ||
76 | } | 76 | } | ||
77 | 77 | | |||
78 | void PendingFileQueueTest::testRequeue() | 78 | void PendingFileQueueTest::testRequeue() | ||
79 | { | 79 | { | ||
80 | QString myUrl(QStringLiteral("/tmp")); | 80 | QString myUrl(QStringLiteral("/tmp")); | ||
81 | 81 | | |||
82 | PendingFileQueue queue; | 82 | PendingFileQueue queue; | ||
83 | queue.setMinimumTimeout(2); | 83 | queue.setMinimumTimeout(2); | ||
84 | queue.setMaximumTimeout(5); | 84 | queue.setMaximumTimeout(5); | ||
85 | 85 | | |||
86 | QSignalSpy spy(&queue, SIGNAL(indexModifiedFile(QString))); | 86 | QSignalSpy spy(&queue, SIGNAL(indexModifiedFile(QString))); | ||
87 | QVERIFY(spy.isValid()); | 87 | QVERIFY(spy.isValid()); | ||
88 | 88 | | |||
89 | PendingFile file(myUrl); | 89 | PendingFile file(myUrl); | ||
90 | file.setModified(); | 90 | file.setModified(); | ||
91 | queue.enqueue(file); | 91 | queue.enqueue(file); | ||
92 | 92 | | |||
93 | // The signal should be emitted immediately | 93 | // The signal should be emitted immediately | ||
94 | QTest::qWait(20); | 94 | QTest::qWait(20); | ||
95 | QCOMPARE(spy.count(), 1); | 95 | QCOMPARE(spy.count(), 1); | ||
96 | QCOMPARE(spy.takeFirst().first().toString(), myUrl); | 96 | QCOMPARE(spy.takeFirst().constFirst().toString(), myUrl); | ||
97 | 97 | | |||
98 | // Send many events | 98 | // Send many events | ||
99 | queue.enqueue(file); | 99 | queue.enqueue(file); | ||
100 | QTest::qWait(20); | 100 | QTest::qWait(20); | ||
101 | queue.enqueue(file); | 101 | queue.enqueue(file); | ||
102 | QTest::qWait(20); | 102 | QTest::qWait(20); | ||
103 | queue.enqueue(file); | 103 | queue.enqueue(file); | ||
104 | QTest::qWait(20); | 104 | QTest::qWait(20); | ||
105 | 105 | | |||
106 | QTest::qWait(3500); | 106 | QTest::qWait(3500); | ||
107 | QVERIFY(spy.isEmpty()); | 107 | QVERIFY(spy.isEmpty()); | ||
108 | 108 | | |||
109 | QVERIFY(spy.wait(2500)); | 109 | QVERIFY(spy.wait(2500)); | ||
110 | QCOMPARE(spy.count(), 1); | 110 | QCOMPARE(spy.count(), 1); | ||
111 | QCOMPARE(spy.takeFirst().first().toString(), myUrl); | 111 | QCOMPARE(spy.takeFirst().constFirst().toString(), myUrl); | ||
112 | } | 112 | } | ||
113 | 113 | | |||
114 | QTEST_GUILESS_MAIN(PendingFileQueueTest) | 114 | QTEST_GUILESS_MAIN(PendingFileQueueTest) | ||
115 | 115 | | |||
116 | #include "pendingfilequeuetest.moc" | 116 | #include "pendingfilequeuetest.moc" |