testinotifywatcher.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * This software is in the public domain, furnished "as is", without technical
  3. * support, and with no warranty, express or implied, as to its usefulness for
  4. * any purpose.
  5. * */
  6. #ifndef MIRALL_INOTIFYWATCHER_H
  7. #define MIRALL_INOTIFYWATCHER_H
  8. #include <QtTest>
  9. #include "folderwatcher_linux.h"
  10. #include "utility.h"
  11. using namespace OCC;
  12. class TestInotifyWatcher: public FolderWatcherPrivate
  13. {
  14. Q_OBJECT
  15. private:
  16. QString _root;
  17. private slots:
  18. void initTestCase() {
  19. qsrand(QTime::currentTime().msec());
  20. _root = QDir::tempPath() + "/" + "test_" + QString::number(qrand());
  21. qDebug() << "creating test directory tree in " << _root;
  22. QDir rootDir(_root);
  23. rootDir.mkpath(_root + "/a1/b1/c1");
  24. rootDir.mkpath(_root + "/a1/b1/c2");
  25. rootDir.mkpath(_root + "/a1/b2/c1");
  26. rootDir.mkpath(_root + "/a1/b3/c3");
  27. rootDir.mkpath(_root + "/a2/b3/c3");
  28. }
  29. // Test the recursive path listing function findFoldersBelow
  30. void testDirsBelowPath() {
  31. QStringList dirs;
  32. bool ok = findFoldersBelow(QDir(_root), dirs);
  33. QVERIFY( dirs.indexOf(_root + "/a1")>-1);
  34. QVERIFY( dirs.indexOf(_root + "/a1/b1")>-1);
  35. QVERIFY( dirs.indexOf(_root + "/a1/b1/c1")>-1);
  36. QVERIFY( dirs.indexOf(_root + "/a1/b1/c2")>-1);
  37. QVERIFY(Utility::writeRandomFile(_root+"/a1/rand1.dat"));
  38. QVERIFY(Utility::writeRandomFile(_root+"/a1/b1/rand2.dat"));
  39. QVERIFY(Utility::writeRandomFile(_root+"/a1/b1/c1/rand3.dat"));
  40. QVERIFY( dirs.indexOf(_root + "/a1/b2")>-1);
  41. QVERIFY( dirs.indexOf(_root + "/a1/b2/c1")>-1);
  42. QVERIFY( dirs.indexOf(_root + "/a1/b3")>-1);
  43. QVERIFY( dirs.indexOf(_root + "/a1/b3/c3")>-1);
  44. QVERIFY( dirs.indexOf(_root + "/a2"));
  45. QVERIFY( dirs.indexOf(_root + "/a2/b3"));
  46. QVERIFY( dirs.indexOf(_root + "/a2/b3/c3"));
  47. QVERIFY2(dirs.count() == 11, "Directory count wrong.");
  48. QVERIFY2(ok, "findFoldersBelow failed.");
  49. }
  50. void cleanupTestCase() {
  51. if( _root.startsWith(QDir::tempPath() )) {
  52. system( QString("rm -rf %1").arg(_root).toLocal8Bit() );
  53. }
  54. }
  55. };
  56. #endif