File: testinotifywatcher.cpp

package info (click to toggle)
nextcloud-desktop 4.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,404 kB
  • sloc: cpp: 118,401; objc: 752; python: 606; sh: 395; ansic: 391; ruby: 174; makefile: 44; javascript: 32; xml: 6
file content (75 lines) | stat: -rw-r--r-- 2,347 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2016 ownCloud GmbH
 * SPDX-License-Identifier: CC0-1.0
 *
 * This software is in the public domain, furnished "as is", without technical
 * support, and with no warranty, express or implied, as to its usefulness for
 * any purpose.
 */

#include <QtTest>

#include "folderwatcher_linux.h"
#include "common/utility.h"

using namespace OCC;

class TestInotifyWatcher: public FolderWatcherPrivate
{
    Q_OBJECT

private:
    QString _root;

private slots:
    void initTestCase()
    {
        _root = QDir::tempPath() + "/" + "test_" + QString::number(OCC::Utility::rand());
        qDebug() << "creating test directory tree in " << _root;
        QDir rootDir(_root);

        rootDir.mkpath(_root + "/a1/b1/c1");
        rootDir.mkpath(_root + "/a1/b1/c2");
        rootDir.mkpath(_root + "/a1/b2/c1");
        rootDir.mkpath(_root + "/a1/b3/c3");
        rootDir.mkpath(_root + "/a2/b3/c3");
    }

    // Test the recursive path listing function findFoldersBelow
    void testDirsBelowPath() {
        QStringList dirs;

        bool ok = findFoldersBelow(QDir(_root), dirs);
        QVERIFY( dirs.indexOf(_root + "/a1")>-1);
        QVERIFY( dirs.indexOf(_root + "/a1/b1")>-1);
        QVERIFY( dirs.indexOf(_root + "/a1/b1/c1")>-1);
        QVERIFY( dirs.indexOf(_root + "/a1/b1/c2")>-1);

        QVERIFY(Utility::writeRandomFile(_root+"/a1/rand1.dat"));
        QVERIFY(Utility::writeRandomFile(_root+"/a1/b1/rand2.dat"));
        QVERIFY(Utility::writeRandomFile(_root+"/a1/b1/c1/rand3.dat"));

        QVERIFY( dirs.indexOf(_root + "/a1/b2")>-1);
        QVERIFY( dirs.indexOf(_root + "/a1/b2/c1")>-1);
        QVERIFY( dirs.indexOf(_root + "/a1/b3")>-1);
        QVERIFY( dirs.indexOf(_root + "/a1/b3/c3")>-1);

        QVERIFY( dirs.indexOf(_root + "/a2"));
        QVERIFY( dirs.indexOf(_root + "/a2/b3"));
        QVERIFY( dirs.indexOf(_root + "/a2/b3/c3"));

        QVERIFY2(dirs.count() == 11, "Directory count wrong.");

        QVERIFY2(ok, "findFoldersBelow failed.");
    }

    void cleanupTestCase() {
        if( _root.startsWith(QDir::tempPath() )) {
           system( QStringLiteral("rm -rf %1").arg(_root).toLocal8Bit() );
        }
    }
};

QTEST_APPLESS_MAIN(TestInotifyWatcher)
#include "testinotifywatcher.moc"