2011-03-18 03:14:45 +03:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cerrno>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDir>
|
|
|
|
|
|
|
|
#include "mirall/inotify.h"
|
|
|
|
#include "mirall/temporarydir.h"
|
|
|
|
#include "testfolderwatcher.h"
|
|
|
|
|
|
|
|
void TestFolderWatcher::initTestCase()
|
|
|
|
{
|
2011-04-07 00:35:08 +04:00
|
|
|
|
2011-03-18 03:14:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestFolderWatcher::cleanupTestCase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestFolderWatcher::testFilesAdded()
|
|
|
|
{
|
2011-04-07 00:35:08 +04:00
|
|
|
Mirall::INotify::initialize();
|
2011-03-18 03:14:45 +03:00
|
|
|
Mirall::TemporaryDir tmp;
|
|
|
|
Mirall::FolderWatcher watcher(tmp.path());
|
|
|
|
|
2011-04-07 00:35:08 +04:00
|
|
|
// lower the event interval
|
|
|
|
watcher.setEventInterval(1);
|
|
|
|
|
2011-03-18 03:14:45 +03:00
|
|
|
qDebug() << "Monitored: " << watcher.folders();
|
|
|
|
|
2011-03-18 15:54:32 +03:00
|
|
|
QDir subdir = QDir(tmp.path());
|
2011-04-07 00:35:08 +04:00
|
|
|
QSignalSpy spy(&watcher, SIGNAL(folderChanged(const QStringList &)));
|
2011-03-18 15:54:32 +03:00
|
|
|
|
2011-03-18 03:14:45 +03:00
|
|
|
QVERIFY(subdir.mkpath(tmp.path() + "/sub1/sub2"));
|
2011-03-18 15:54:32 +03:00
|
|
|
QVERIFY(subdir.mkpath(tmp.path() + "/sub2"));
|
|
|
|
|
|
|
|
while (spy.count() == 0)
|
2011-04-07 00:35:08 +04:00
|
|
|
QTest::qWait(1010);
|
2011-03-18 03:14:45 +03:00
|
|
|
|
2011-04-07 00:35:08 +04:00
|
|
|
// 1 directory changes
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
QList<QVariant> arguments = spy.takeFirst();
|
|
|
|
QStringList paths = arguments.at(0).toStringList();
|
|
|
|
qDebug() << paths;
|
|
|
|
QCOMPARE(paths.size(), 2);
|
2011-03-18 15:54:32 +03:00
|
|
|
|
|
|
|
qDebug() << "Monitored: " << watcher.folders();
|
2011-04-07 00:35:08 +04:00
|
|
|
|
|
|
|
// the new sub2 directory should be now also bee in the list of watches
|
|
|
|
QFile file(tmp.path() + "/sub1/sub2/foo.txt");
|
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write("hello", 5);
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
//while (spy.count() == )
|
|
|
|
QTest::qWait(1010);
|
|
|
|
|
|
|
|
// 1 file changes
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
|
|
|
|
|
|
|
Mirall::INotify::cleanup();
|
2011-03-18 03:14:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_MAIN(TestFolderWatcher)
|
|
|
|
#include "testfolderwatcher.moc"
|