summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorRiccardo Ferrazzo <rferrazz@develer.com>2013-08-29 12:36:34 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-19 09:13:57 +0200
commit31db8728cf038f0a38c42d64c375403fde8598c9 (patch)
treed90706ae06b54e08f18313962f2ac6f2803e65f6 /tests/auto
parent73b88fccedfe3912649d119bedf8490ab6c41812 (diff)
Fix QFileSystemWatcher inotify
On linux using QFileSystemWatcher with inotify backend when a watched file is moved and added again to the watched files its path is not replaced with the new one. This behavior prevents the emission of the fileChanged signal with the wrong file path. Task-number: QTBUG-33211 Change-Id: Ib45d8efdf5afbf8b8f6b4b26e43f3d6ee740aca6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
index 4105a43735..20ef7b5a76 100644
--- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
+++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
@@ -79,6 +79,8 @@ private slots:
void QTBUG2331();
void QTBUG2331_data() { basicTest_data(); }
+ void signalsEmittedAfterFileMoved();
+
private:
QString m_tempDirPattern;
};
@@ -596,5 +598,84 @@ void tst_QFileSystemWatcher::QTBUG2331()
QCOMPARE(watcher.directories(), QStringList());
}
+class SignalReceiver : public QObject
+{
+ Q_OBJECT
+public:
+ SignalReceiver(const QDir &moveSrcDir,
+ const QString &moveDestination,
+ QFileSystemWatcher *watcher,
+ QObject *parent = 0)
+ : QObject(parent),
+ added(false),
+ moveSrcDir(moveSrcDir),
+ moveDestination(QDir(moveDestination)),
+ watcher(watcher)
+ {}
+
+public slots:
+ void fileChanged(const QString &path)
+ {
+ QFileInfo finfo(path);
+
+ QCOMPARE(finfo.absolutePath(), moveSrcDir.absolutePath());
+
+ if (!added) {
+ foreach (const QFileInfo &fi, moveDestination.entryInfoList(QDir::Files | QDir::NoSymLinks))
+ watcher->addPath(fi.absoluteFilePath());
+ added = true;
+ }
+ }
+
+private:
+ bool added;
+ QDir moveSrcDir;
+ QDir moveDestination;
+ QFileSystemWatcher *watcher;
+};
+
+// regression test for QTBUG-33211.
+// using inotify backend if a file is moved and then added to the watcher
+// before all the fileChanged signals are emitted the remaining signals are
+// emitted with the destination path instead of the starting path
+void tst_QFileSystemWatcher::signalsEmittedAfterFileMoved()
+{
+ QTemporaryDir temporaryDirectory(m_tempDirPattern);
+ QVERIFY(temporaryDirectory.isValid());
+ QDir testDir(temporaryDirectory.path());
+ QVERIFY(testDir.mkdir("movehere"));
+ QString movePath = testDir.filePath("movehere");
+
+ for (int i = 0; i < 10; i++) {
+ QFile f(testDir.filePath(QString("test%1.txt").arg(i)));
+ QVERIFY(f.open(QIODevice::WriteOnly));
+ f.write(QByteArray("i am " + i));
+ f.close();
+ }
+
+ QFileSystemWatcher watcher;
+ QVERIFY(watcher.addPath(testDir.path()));
+ QVERIFY(watcher.addPath(movePath));
+
+ // add files to watcher
+ QFileInfoList files = testDir.entryInfoList(QDir::Files | QDir::NoSymLinks);
+ foreach (const QFileInfo &finfo, files)
+ QVERIFY(watcher.addPath(finfo.absoluteFilePath()));
+
+ // create the signal receiver
+ SignalReceiver signalReceiver(testDir, movePath, &watcher);
+ connect(&watcher, SIGNAL(fileChanged(QString)), &signalReceiver, SLOT(fileChanged(QString)));
+
+ // watch signals
+ QSignalSpy changedSpy(&watcher, SIGNAL(fileChanged(QString)));
+ QVERIFY(changedSpy.isValid());
+
+ // move files to second directory
+ foreach (const QFileInfo &finfo, files)
+ QVERIFY(testDir.rename(finfo.fileName(), QString("movehere/%2").arg(finfo.fileName())));
+
+ QTRY_COMPARE(changedSpy.count(), 10);
+}
+
QTEST_MAIN(tst_QFileSystemWatcher)
#include "tst_qfilesystemwatcher.moc"