Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChristian Kamm <kamm@incasoftware.de>2014-11-20 14:41:06 +0300
committerChristian Kamm <kamm@incasoftware.de>2014-11-20 14:41:06 +0300
commitf275002ebed7210019a319fc1f26805cd929e4b3 (patch)
tree53d887995dbad1595a2891b0821e4d2eb2fe974f /test
parent4d7b8bdb25b51128ab0a339ff946a9a5804b3a0a (diff)
parentd4e0941c2732508b2d944f19115c2c76c7eb593b (diff)
Merge branch '1.7'
Diffstat (limited to 'test')
-rw-r--r--test/testfolderwatcher.h96
1 files changed, 70 insertions, 26 deletions
diff --git a/test/testfolderwatcher.h b/test/testfolderwatcher.h
index d2da060e3..6bbe48671 100644
--- a/test/testfolderwatcher.h
+++ b/test/testfolderwatcher.h
@@ -15,15 +15,23 @@
using namespace Mirall;
+class FriendlyThread : public QThread
+{
+ friend class TestFolderWatcher;
+};
+
class TestFolderWatcher : public QObject
{
Q_OBJECT
public slots:
void slotFolderChanged( const QString& path ) {
- qDebug() << "COMPARE: " << path << _checkMark;
- QVERIFY(_checkMark == path);
- _checkMark.clear();
+ if (_skipNotifications.contains(path)) {
+ return;
+ }
+ if (_requiredNotifications.contains(path)) {
+ _receivedNotifications.insert(path);
+ }
}
void slotEnd() { // in case something goes wrong...
@@ -36,7 +44,16 @@ private:
FolderWatcher *_watcher;
QEventLoop _loop;
QTimer _timer;
- QString _checkMark;
+ QSet<QString> _requiredNotifications;
+ QSet<QString> _receivedNotifications;
+ QSet<QString> _skipNotifications;
+
+ void processAndWait()
+ {
+ _loop.processEvents();
+ FriendlyThread::msleep(200);
+ _loop.processEvents();
+ }
private slots:
void initTestCase() {
@@ -52,68 +69,95 @@ private slots:
rootDir.mkpath(_root + "/a2/b3/c3");
Utility::writeRandomFile( _root+"/a1/random.bin");
Utility::writeRandomFile( _root+"/a1/b2/todelete.bin");
- Utility::writeRandomFile( _root+"/a2/movefile");
+ Utility::writeRandomFile( _root+"/a2/renamefile");
+ Utility::writeRandomFile( _root+"/a1/movefile");
_watcher = new FolderWatcher(_root);
QObject::connect(_watcher, SIGNAL(folderChanged(QString)), this, SLOT(slotFolderChanged(QString)));
- _timer.singleShot(3000, this, SLOT(slotEnd()));
+ _timer.singleShot(5000, this, SLOT(slotEnd()));
+ }
+
+ void init()
+ {
+ _receivedNotifications.clear();
+ _requiredNotifications.clear();
+ _skipNotifications.clear();
+ }
+
+ void checkNotifications()
+ {
+ processAndWait();
+ QCOMPARE(_receivedNotifications, _requiredNotifications);
}
void testACreate() { // create a new file
QString cmd;
- _checkMark = _root;
+ _requiredNotifications.insert(_root);
cmd = QString("echo \"xyz\" > %1/foo.txt").arg(_root);
qDebug() << "Command: " << cmd;
system(cmd.toLocal8Bit());
- _loop.processEvents();
- QVERIFY(_checkMark.isEmpty()); // the slot clears the checkmark.
+ checkNotifications();
}
void testATouch() { // touch an existing file.
+ _requiredNotifications.insert(_root+"/a1");
+#ifdef Q_OS_WIN
+ Utility::writeRandomFile(QString("%1/a1/random.bin").arg(_root));
+#else
QString cmd;
cmd = QString("/usr/bin/touch %1/a1/random.bin").arg(_root);
- _checkMark = _root+"/a1";
qDebug() << "Command: " << cmd;
system(cmd.toLocal8Bit());
+#endif
- _loop.processEvents();
- QVERIFY(_checkMark.isEmpty()); // the slot clears the checkmark.
+ checkNotifications();
}
void testCreateADir() {
- _checkMark = _root+"/a1/b1";
+ _requiredNotifications.insert(_root+"/a1/b1");
+ _skipNotifications.insert(_root + "/a1/b1/new_dir");
QDir dir;
dir.mkdir( _root + "/a1/b1/new_dir");
QVERIFY(QFile::exists(_root + "/a1/b1/new_dir"));
- _loop.processEvents();
- QVERIFY(_checkMark.isEmpty()); // the slot clears the checkmark.
+
+ checkNotifications();
}
void testRemoveADir() {
- _checkMark = _root+"/a1/b3";
+ _requiredNotifications.insert(_root+"/a1/b3");
QDir dir;
QVERIFY(dir.rmdir(_root+"/a1/b3/c3"));
- _loop.processEvents();
- QVERIFY(_checkMark.isEmpty()); // the slot clears the checkmark.
+
+ checkNotifications();
}
void testRemoveAFile() {
- _checkMark = _root+"/a1/b2";
+ _requiredNotifications.insert(_root+"/a1/b2");
QVERIFY(QFile::exists(_root+"/a1/b2/todelete.bin"));
QFile::remove(_root+"/a1/b2/todelete.bin");
QVERIFY(!QFile::exists(_root+"/a1/b2/todelete.bin"));
- _loop.processEvents();
- QVERIFY(_checkMark.isEmpty()); // the slot clears the checkmark.
+
+ checkNotifications();
+ }
+
+ void testRenameAFile() {
+ _requiredNotifications.insert(_root+"/a2");
+ QVERIFY(QFile::exists(_root+"/a2/renamefile"));
+ QFile::rename(_root+"/a2/renamefile", _root+"/a2/renamefile.renamed" );
+ QVERIFY(QFile::exists(_root+"/a2/renamefile.renamed"));
+
+ checkNotifications();
}
void testMoveAFile() {
- _checkMark = _root+"/a2";
- QVERIFY(QFile::exists(_root+"/a2/movefile"));
- QFile::rename(_root+"/a2/movefile", _root+"/a2/movefile.renamed" );
+ _requiredNotifications.insert(_root+"/a1");
+ _requiredNotifications.insert(_root+"/a2");
+ QVERIFY(QFile::exists(_root+"/a1/movefile"));
+ QFile::rename(_root+"/a1/movefile", _root+"/a2/movefile.renamed" );
QVERIFY(QFile::exists(_root+"/a2/movefile.renamed"));
- _loop.processEvents();
- QVERIFY(_checkMark.isEmpty()); // the slot clears the checkmark.
+
+ checkNotifications();
}
void cleanupTestCase() {