2015-07-13 15:35:19 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-07-15 10:47:42 +03:00
|
|
|
#include <qglobal.h>
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
2015-07-13 15:35:19 +03:00
|
|
|
#include <QTemporaryDir>
|
2015-07-14 16:06:42 +03:00
|
|
|
#endif
|
2015-07-13 15:35:19 +03:00
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
#include "utility.h"
|
|
|
|
#include "folderman.h"
|
2016-03-16 21:07:40 +03:00
|
|
|
#include "account.h"
|
2015-07-13 15:35:19 +03:00
|
|
|
#include "accountstate.h"
|
|
|
|
|
|
|
|
using namespace OCC;
|
|
|
|
|
|
|
|
|
|
|
|
static FolderDefinition folderDefinition(const QString &path) {
|
|
|
|
FolderDefinition d;
|
|
|
|
d.localPath = path;
|
|
|
|
d.targetPath = path;
|
|
|
|
d.alias = path;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class TestFolderMan: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
FolderMan _fm;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void testCheckPathValidityForNewFolder()
|
|
|
|
{
|
2015-07-15 10:47:42 +03:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
2015-07-13 15:35:19 +03:00
|
|
|
QTemporaryDir dir;
|
|
|
|
QVERIFY(dir.isValid());
|
|
|
|
QDir dir2(dir.path());
|
|
|
|
QVERIFY(dir2.mkpath("sub/ownCloud1/folder/f"));
|
|
|
|
QVERIFY(dir2.mkpath("ownCloud2"));
|
|
|
|
QVERIFY(dir2.mkpath("sub/free"));
|
|
|
|
QVERIFY(dir2.mkpath("free2/sub"));
|
2015-07-28 13:14:52 +03:00
|
|
|
{
|
|
|
|
QFile f(dir.path() + "/sub/file.txt");
|
|
|
|
f.open(QFile::WriteOnly);
|
|
|
|
f.write("hello");
|
|
|
|
}
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2016-03-16 21:07:40 +03:00
|
|
|
AccountStatePtr newAccountState(new AccountState(Account::create()));
|
2015-07-13 15:35:19 +03:00
|
|
|
FolderMan *folderman = FolderMan::instance();
|
|
|
|
QCOMPARE(folderman, &_fm);
|
2016-03-16 21:07:40 +03:00
|
|
|
QVERIFY(folderman->addFolder(newAccountState.data(), folderDefinition(dir.path() + "/sub/ownCloud1")));
|
|
|
|
QVERIFY(folderman->addFolder(newAccountState.data(), folderDefinition(dir.path() + "/ownCloud2")));
|
2015-07-13 15:35:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
// those should be allowed
|
2015-07-28 13:14:52 +03:00
|
|
|
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/free"), QString());
|
|
|
|
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/free2/"), QString());
|
|
|
|
// Not an existing directory -> Ok
|
|
|
|
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/bliblablu"), QString());
|
|
|
|
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/free/bliblablu"), QString());
|
|
|
|
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/bliblablu/some/more"), QString());
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2015-07-28 13:14:52 +03:00
|
|
|
// A file -> Error
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/file.txt").isNull());
|
2015-07-13 15:35:19 +03:00
|
|
|
|
|
|
|
// There are folders configured in those folders: -> ERROR
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1").isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/ownCloud2/").isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub").isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/").isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path()).isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1/folder").isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1/folder/f").isNull());
|
|
|
|
|
|
|
|
|
|
|
|
// make a bunch of links
|
|
|
|
QVERIFY(QFile::link(dir.path() + "/sub/free", dir.path() + "/link1"));
|
|
|
|
QVERIFY(QFile::link(dir.path() + "/sub", dir.path() + "/link2"));
|
|
|
|
QVERIFY(QFile::link(dir.path() + "/sub/ownCloud1", dir.path() + "/link3"));
|
|
|
|
QVERIFY(QFile::link(dir.path() + "/sub/ownCloud1/folder", dir.path() + "/link4"));
|
|
|
|
|
|
|
|
// Ok
|
|
|
|
QVERIFY(folderman->checkPathValidityForNewFolder(dir.path() + "/link1").isNull());
|
|
|
|
QVERIFY(folderman->checkPathValidityForNewFolder(dir.path() + "/link2/free").isNull());
|
|
|
|
|
|
|
|
// Not Ok
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link2").isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link3").isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link4").isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link3/folder").isNull());
|
2015-07-28 13:14:52 +03:00
|
|
|
|
|
|
|
|
|
|
|
// test some non existing sub path (error)
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1/some/sub/path").isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/ownCloud2/blublu").isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1/folder/g/h").isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link3/folder/neu_folder").isNull());
|
|
|
|
|
|
|
|
// Subfolder of links
|
|
|
|
QVERIFY(folderman->checkPathValidityForNewFolder(dir.path() + "/link1/subfolder").isNull());
|
|
|
|
QVERIFY(folderman->checkPathValidityForNewFolder(dir.path() + "/link2/free/subfolder").isNull());
|
|
|
|
|
|
|
|
// Invalid paths
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder("").isNull());
|
|
|
|
|
|
|
|
// Should not have the rights
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder("/").isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder("/usr/bin/somefolder").isNull());
|
2015-07-14 16:06:42 +03:00
|
|
|
#else
|
|
|
|
QSKIP("Test not supported with Qt4", SkipSingle);
|
|
|
|
#endif
|
2015-07-13 15:35:19 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-11 02:17:16 +03:00
|
|
|
QTEST_APPLESS_MAIN(TestFolderMan)
|
2016-03-30 18:58:15 +03:00
|
|
|
#include "testfolderman.moc"
|