Changeset View
Changeset View
Standalone View
Standalone View
autotests/unit/file/kinotifytest.cpp
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 68 | { | |||
---|---|---|---|---|---|
85 | QCOMPARE(spy.takeFirst().at(0).toString(), f1); | 85 | QCOMPARE(spy.takeFirst().at(0).toString(), f1); | ||
86 | } | 86 | } | ||
87 | 87 | | |||
88 | 88 | | |||
89 | void KInotifyTest::testDeleteFolder() | 89 | void KInotifyTest::testDeleteFolder() | ||
90 | { | 90 | { | ||
91 | // create some test files | 91 | // create some test files | ||
92 | QTemporaryDir dir; | 92 | QTemporaryDir dir; | ||
93 | const QString d1(QStringLiteral("%1/randomJunk4").arg(dir.path())); | 93 | const QString d1(QStringLiteral("%1/randomJunk4/").arg(dir.path())); | ||
94 | mkdir(d1); | 94 | mkdir(d1); | ||
95 | 95 | | |||
96 | // start the inotify watcher | 96 | // start the inotify watcher | ||
97 | KInotify kn(nullptr /*no config*/); | 97 | KInotify kn(nullptr /*no config*/); | ||
98 | kn.addWatch(dir.path(), KInotify::EventAll); | 98 | kn.addWatch(dir.path(), KInotify::EventAll); | ||
99 | 99 | | |||
100 | // listen to the desired signal | 100 | // listen to the desired signal | ||
101 | QSignalSpy spy(&kn, SIGNAL(deleted(QString,bool))); | 101 | QSignalSpy spy(&kn, SIGNAL(deleted(QString,bool))); | ||
Show All 16 Lines | 115 | { | |||
118 | // start the inotify watcher | 118 | // start the inotify watcher | ||
119 | KInotify kn(nullptr /*no config*/); | 119 | KInotify kn(nullptr /*no config*/); | ||
120 | kn.addWatch(dir.path(), KInotify::EventAll); | 120 | kn.addWatch(dir.path(), KInotify::EventAll); | ||
121 | 121 | | |||
122 | // listen to the desired signal | 122 | // listen to the desired signal | ||
123 | QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool))); | 123 | QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool))); | ||
124 | 124 | | |||
125 | // create the subdir | 125 | // create the subdir | ||
126 | const QString d1(QStringLiteral("%1/randomJunk1").arg(dir.path())); | 126 | const QString d1(QStringLiteral("%1/randomJunk1/").arg(dir.path())); | ||
127 | mkdir(d1); | 127 | mkdir(d1); | ||
128 | QVERIFY(createdSpy.wait()); | 128 | QVERIFY(createdSpy.wait()); | ||
129 | QCOMPARE(createdSpy.count(), 1); | 129 | QCOMPARE(createdSpy.count(), 1); | ||
130 | QCOMPARE(createdSpy.takeFirst().at(0).toString(), d1); | 130 | QCOMPARE(createdSpy.takeFirst().at(0).toString(), d1); | ||
131 | QVERIFY(kn.watchingPath(d1)); | 131 | QVERIFY(kn.watchingPath(d1)); | ||
132 | 132 | | |||
133 | // lets go one level deeper | 133 | // lets go one level deeper | ||
134 | const QString d2 = QStringLiteral("%1/subdir1").arg(d1); | 134 | const QString d2 = QStringLiteral("%1subdir1/").arg(d1); | ||
135 | mkdir(d2); | 135 | mkdir(d2); | ||
136 | QVERIFY(createdSpy.wait()); | 136 | QVERIFY(createdSpy.wait()); | ||
137 | QCOMPARE(createdSpy.count(), 1); | 137 | QCOMPARE(createdSpy.count(), 1); | ||
138 | QCOMPARE(createdSpy.takeFirst().at(0).toString(), d2); | 138 | QCOMPARE(createdSpy.takeFirst().at(0).toString(), d2); | ||
139 | QVERIFY(kn.watchingPath(d2)); | 139 | QVERIFY(kn.watchingPath(d2)); | ||
140 | 140 | | |||
141 | // although we are in the folder test lets try creating a file | 141 | // although we are in the folder test lets try creating a file | ||
142 | const QString f1 = QStringLiteral("%1/somefile1").arg(d2); | 142 | const QString f1 = QStringLiteral("%1somefile1").arg(d2); | ||
143 | touchFile(f1); | 143 | touchFile(f1); | ||
144 | QVERIFY(createdSpy.wait()); | 144 | QVERIFY(createdSpy.wait()); | ||
145 | QCOMPARE(createdSpy.count(), 1); | 145 | QCOMPARE(createdSpy.count(), 1); | ||
146 | QCOMPARE(createdSpy.takeFirst().at(0).toString(), f1); | 146 | QCOMPARE(createdSpy.takeFirst().at(0).toString(), f1); | ||
147 | } | 147 | } | ||
148 | 148 | | |||
149 | 149 | | |||
150 | void KInotifyTest::testRenameFile() | 150 | void KInotifyTest::testRenameFile() | ||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 189 | { | |||
224 | QCOMPARE(args.at(1).toString(), dest2); | 224 | QCOMPARE(args.at(1).toString(), dest2); | ||
225 | } | 225 | } | ||
226 | 226 | | |||
227 | 227 | | |||
228 | void KInotifyTest::testRenameFolder() | 228 | void KInotifyTest::testRenameFolder() | ||
229 | { | 229 | { | ||
230 | // create some test files | 230 | // create some test files | ||
231 | QTemporaryDir dir; | 231 | QTemporaryDir dir; | ||
232 | const QString f1(QStringLiteral("%1/randomJunk1").arg(dir.path())); | 232 | const QString d1(QStringLiteral("%1/randomJunk1/").arg(dir.path())); | ||
233 | mkdir(f1); | 233 | mkdir(d1); | ||
234 | 234 | | |||
235 | // start the inotify watcher | 235 | // start the inotify watcher | ||
236 | KInotify kn(nullptr /*no config*/); | 236 | KInotify kn(nullptr /*no config*/); | ||
237 | kn.addWatch(dir.path(), KInotify::EventAll); | 237 | kn.addWatch(dir.path(), KInotify::EventAll); | ||
238 | 238 | | |||
239 | // listen to the desired signal | 239 | // listen to the desired signal | ||
240 | QSignalSpy spy(&kn, SIGNAL(moved(QString,QString))); | 240 | QSignalSpy spy(&kn, SIGNAL(moved(QString,QString))); | ||
241 | 241 | | |||
242 | // actually move the file | 242 | // actually rename the folder | ||
243 | const QString f2(QStringLiteral("%1/randomJunk2").arg(dir.path())); | 243 | const QString d2(QStringLiteral("%1/randomJunk2/").arg(dir.path())); | ||
244 | QFile::rename(f1, f2); | 244 | QFile::rename(d1, d2); | ||
245 | 245 | | |||
246 | // check the desired signal | 246 | // check the desired signal | ||
247 | QVERIFY(spy.wait()); | 247 | QVERIFY(spy.wait()); | ||
248 | QCOMPARE(spy.count(), 1); | 248 | QCOMPARE(spy.count(), 1); | ||
249 | QList<QVariant> args = spy.takeFirst(); | 249 | QList<QVariant> args = spy.takeFirst(); | ||
250 | QCOMPARE(args.at(0).toString(), f1); | 250 | QCOMPARE(args.at(0).toString(), d1); | ||
251 | QCOMPARE(args.at(1).toString(), f2); | 251 | QCOMPARE(args.at(1).toString(), d2); | ||
252 | 252 | | |||
253 | // check the path cache | 253 | // check the path cache | ||
254 | QVERIFY(!kn.watchingPath(f1)); | 254 | QVERIFY(!kn.watchingPath(d1)); | ||
255 | QVERIFY(kn.watchingPath(f2)); | 255 | QVERIFY(kn.watchingPath(d2)); | ||
256 | 256 | | |||
257 | // test a subsequent rename | 257 | // test a subsequent rename | ||
258 | const QString f3(QStringLiteral("%1/randomJunk3").arg(dir.path())); | 258 | const QString d3(QStringLiteral("%1/randomJunk3/").arg(dir.path())); | ||
259 | QFile::rename(f2, f3); | 259 | QFile::rename(d2, d3); | ||
260 | 260 | | |||
261 | // check the desired signal | 261 | // check the desired signal | ||
262 | QVERIFY(spy.wait()); | 262 | QVERIFY(spy.wait()); | ||
263 | QCOMPARE(spy.count(), 1); | 263 | QCOMPARE(spy.count(), 1); | ||
264 | args = spy.takeFirst(); | 264 | args = spy.takeFirst(); | ||
265 | QCOMPARE(args.at(0).toString(), f2); | 265 | QCOMPARE(args.at(0).toString(), d2); | ||
266 | QCOMPARE(args.at(1).toString(), f3); | 266 | QCOMPARE(args.at(1).toString(), d3); | ||
267 | 267 | | |||
268 | // check the path cache | 268 | // check the path cache | ||
269 | QVERIFY(!kn.watchingPath(f1)); | 269 | QVERIFY(!kn.watchingPath(d1)); | ||
270 | QVERIFY(!kn.watchingPath(f2)); | 270 | QVERIFY(!kn.watchingPath(d2)); | ||
271 | QVERIFY(kn.watchingPath(f3)); | 271 | QVERIFY(kn.watchingPath(d3)); | ||
272 | 272 | | |||
273 | 273 | | |||
274 | // KInotify claims it has updated its data structures, lets see if that is true | 274 | // KInotify claims it has updated its data structures, lets see if that is true | ||
275 | // by creating a file in the new folder | 275 | // by creating a file in the new folder | ||
276 | // listen to the desired signal | 276 | // listen to the desired signal | ||
277 | const QString f4(QStringLiteral("%1/somefile").arg(f3)); | 277 | const QString f4(QStringLiteral("%1somefile").arg(d3)); | ||
278 | 278 | | |||
279 | QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool))); | 279 | QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool))); | ||
280 | 280 | | |||
281 | // test creating a file | 281 | // test creating a file | ||
282 | touchFile(f4); | 282 | touchFile(f4); | ||
283 | 283 | | |||
284 | QVERIFY(createdSpy.wait()); | 284 | QVERIFY(createdSpy.wait()); | ||
285 | QCOMPARE(createdSpy.count(), 1); | 285 | QCOMPARE(createdSpy.count(), 1); | ||
286 | QCOMPARE(createdSpy.takeFirst().at(0).toString(), f4); | 286 | QCOMPARE(createdSpy.takeFirst().at(0).toString(), f4); | ||
287 | } | 287 | } | ||
288 | 288 | | |||
289 | 289 | | |||
290 | void KInotifyTest::testMoveFolder() | 290 | void KInotifyTest::testMoveFolder() | ||
291 | { | 291 | { | ||
292 | // create some test files | 292 | // create some test files | ||
293 | QTemporaryDir dir1; | 293 | QTemporaryDir dir1; | ||
294 | QTemporaryDir dir2; | 294 | QTemporaryDir dir2; | ||
295 | const QString src(QStringLiteral("%1/randomJunk1").arg(dir1.path())); | 295 | const QString src(QStringLiteral("%1/randomJunk1/").arg(dir1.path())); | ||
296 | const QString dest(QStringLiteral("%1/randomJunk2").arg(dir2.path())); | 296 | const QString dest(QStringLiteral("%1/randomJunk2/").arg(dir2.path())); | ||
297 | mkdir(src); | 297 | mkdir(src); | ||
298 | 298 | | |||
299 | // start the inotify watcher | 299 | // start the inotify watcher | ||
300 | KInotify kn(nullptr /*no config*/); | 300 | KInotify kn(nullptr /*no config*/); | ||
301 | kn.addWatch(dir1.path(), KInotify::EventAll); | 301 | kn.addWatch(dir1.path(), KInotify::EventAll); | ||
302 | kn.addWatch(dir2.path(), KInotify::EventAll); | 302 | kn.addWatch(dir2.path(), KInotify::EventAll); | ||
303 | 303 | | |||
304 | // listen to the desired signal | 304 | // listen to the desired signal | ||
Show All 9 Lines | |||||
314 | QCOMPARE(args.at(0).toString(), src); | 314 | QCOMPARE(args.at(0).toString(), src); | ||
315 | QCOMPARE(args.at(1).toString(), dest); | 315 | QCOMPARE(args.at(1).toString(), dest); | ||
316 | 316 | | |||
317 | // check the path cache | 317 | // check the path cache | ||
318 | QVERIFY(!kn.watchingPath(src)); | 318 | QVERIFY(!kn.watchingPath(src)); | ||
319 | QVERIFY(kn.watchingPath(dest)); | 319 | QVERIFY(kn.watchingPath(dest)); | ||
320 | 320 | | |||
321 | // test a subsequent move | 321 | // test a subsequent move | ||
322 | const QString dest2(QStringLiteral("%1/randomJunk3").arg(dir1.path())); | 322 | const QString dest2(QStringLiteral("%1/randomJunk3/").arg(dir1.path())); | ||
323 | QFile::rename(dest, dest2); | 323 | QFile::rename(dest, dest2); | ||
324 | 324 | | |||
325 | // check the desired signal | 325 | // check the desired signal | ||
326 | QVERIFY(spy.wait()); | 326 | QVERIFY(spy.wait()); | ||
327 | QCOMPARE(spy.count(), 1); | 327 | QCOMPARE(spy.count(), 1); | ||
328 | args = spy.takeFirst(); | 328 | args = spy.takeFirst(); | ||
329 | QCOMPARE(args.at(0).toString(), dest); | 329 | QCOMPARE(args.at(0).toString(), dest); | ||
330 | QCOMPARE(args.at(1).toString(), dest2); | 330 | QCOMPARE(args.at(1).toString(), dest2); | ||
331 | 331 | | |||
332 | // check the path cache | 332 | // check the path cache | ||
333 | QVERIFY(!kn.watchingPath(src)); | 333 | QVERIFY(!kn.watchingPath(src)); | ||
334 | QVERIFY(!kn.watchingPath(dest)); | 334 | QVERIFY(!kn.watchingPath(dest)); | ||
335 | QVERIFY(kn.watchingPath(dest2)); | 335 | QVERIFY(kn.watchingPath(dest2)); | ||
336 | 336 | | |||
337 | 337 | | |||
338 | // KInotify claims it has updated its data structures, lets see if that is true | 338 | // KInotify claims it has updated its data structures, lets see if that is true | ||
339 | // by creating a file in the new folder | 339 | // by creating a file in the new folder | ||
340 | // listen to the desired signal | 340 | // listen to the desired signal | ||
341 | const QString f4(QStringLiteral("%1/somefile").arg(dest2)); | 341 | const QString f4(QStringLiteral("%1somefile").arg(dest2)); | ||
342 | 342 | | |||
343 | QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool))); | 343 | QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool))); | ||
344 | 344 | | |||
345 | // test creating a file | 345 | // test creating a file | ||
346 | touchFile(f4); | 346 | touchFile(f4); | ||
347 | 347 | | |||
348 | QVERIFY(createdSpy.wait()); | 348 | QVERIFY(createdSpy.wait()); | ||
349 | QCOMPARE(createdSpy.count(), 1); | 349 | QCOMPARE(createdSpy.count(), 1); | ||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |