summaryrefslogtreecommitdiffstats
path: root/tests/auto/qfilesystemwatcher
diff options
context:
space:
mode:
authorJason Barron <jbarron@trolltech.com>2009-07-28 12:58:46 +0200
committerJason Barron <jbarron@trolltech.com>2009-07-28 13:45:59 +0200
commit7eba68adc4a7862d9474179592e5c8393a7acdbb (patch)
tree73014cabc8b10f46203844aeb40de574d97032dc /tests/auto/qfilesystemwatcher
parenta20f8dcbeafa34b50ef69d1c5db0f17b09731d2a (diff)
parent3bf3981c7026de9017887d08312391b54fe8afc6 (diff)
Merge commit 'qt/master-stable'
Conflicts: configure.exe src/corelib/io/io.pri src/corelib/io/qfilesystemwatcher.cpp tests/auto/qfileinfo/tst_qfileinfo.cpp tools/configure/configureapp.cpp
Diffstat (limited to 'tests/auto/qfilesystemwatcher')
-rw-r--r--tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
index 6fa49b4980..a93a645e29 100644
--- a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
+++ b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
@@ -73,6 +73,8 @@ private slots:
void removePath();
void addPaths();
void removePaths();
+ void watchFileAndItsDirectory();
+ void watchFileAndItsDirectory_data() { basicTest_data(); }
private:
QStringList do_force_engines;
@@ -400,5 +402,83 @@ void tst_QFileSystemWatcher::removePaths()
watcher.removePaths(paths);
}
+void tst_QFileSystemWatcher::watchFileAndItsDirectory()
+{
+ QFETCH(QString, backend);
+ QDir().mkdir("testDir");
+ QDir testDir("testDir");
+
+ QString testFileName = testDir.filePath("testFile.txt");
+ QString secondFileName = testDir.filePath("testFile2.txt");
+ QFile::remove(secondFileName);
+
+ QFile testFile(testFileName);
+ testFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner);
+ testFile.remove();
+
+ QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Truncate));
+ testFile.write(QByteArray("hello"));
+ testFile.close();
+
+ QFileSystemWatcher watcher;
+ watcher.setObjectName(QLatin1String("_qt_autotest_force_engine_") + backend);
+
+ watcher.addPath(testDir.dirName());
+ watcher.addPath(testFileName);
+
+ QSignalSpy fileChangedSpy(&watcher, SIGNAL(fileChanged(const QString &)));
+ QSignalSpy dirChangedSpy(&watcher, SIGNAL(directoryChanged(const QString &)));
+ QEventLoop eventLoop;
+ QTimer timer;
+ connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
+
+ // resolution of the modification time is system dependent, but it's at most 1 second when using
+ // the polling engine. From what I know, FAT32 has a 2 second resolution. So we have to
+ // wait before modifying the directory...
+ QTest::qWait(2000);
+
+ QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Truncate));
+ testFile.write(QByteArray("hello again"));
+ testFile.close();
+
+ timer.start(3000);
+ eventLoop.exec();
+ QCOMPARE(fileChangedSpy.count(), 1);
+ QCOMPARE(dirChangedSpy.count(), 0);
+
+ fileChangedSpy.clear();
+ QFile secondFile(secondFileName);
+ secondFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
+ secondFile.write("Foo");
+ secondFile.close();
+
+ timer.start(3000);
+ eventLoop.exec();
+ QCOMPARE(fileChangedSpy.count(), 0);
+ QCOMPARE(dirChangedSpy.count(), 1);
+
+ dirChangedSpy.clear();
+
+ QFile::remove(testFileName);
+
+ timer.start(3000);
+ eventLoop.exec();
+ QCOMPARE(fileChangedSpy.count(), 1);
+ QCOMPARE(dirChangedSpy.count(), 1);
+
+ fileChangedSpy.clear();
+ dirChangedSpy.clear();
+
+ watcher.removePath(testFileName);
+ QFile::remove(secondFileName);
+
+ timer.start(3000);
+ eventLoop.exec();
+ QCOMPARE(fileChangedSpy.count(), 0);
+ QCOMPARE(dirChangedSpy.count(), 1);
+
+ QVERIFY(QDir().rmdir("testDir"));
+}
+
QTEST_MAIN(tst_QFileSystemWatcher)
#include "tst_qfilesystemwatcher.moc"