From f42795551235568ecf4c82514c2175164d24c64a Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Wed, 30 Mar 2016 17:58:15 +0200 Subject: Simplify the build of auto tests Remove all configure_files: - Move all tests to cpp files - Use the QTEST_MAIN macro instead of a generated main.cpp - Include test*.moc in the cpp to let CMAKE_AUTOMOC call moc - Pass info through add_definitions instead of generating oc_bin.h with them This makes sure that build errors points to the original test source file instead of the generated one in the build directory to be able to jump and fix errors directly from the IDE's error pane. --- test/testfolderman.cpp | 122 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 test/testfolderman.cpp (limited to 'test/testfolderman.cpp') diff --git a/test/testfolderman.cpp b/test/testfolderman.cpp new file mode 100644 index 000000000..47e115da0 --- /dev/null +++ b/test/testfolderman.cpp @@ -0,0 +1,122 @@ +/* + * 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 +#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) +#include +#endif +#include + +#include "utility.h" +#include "folderman.h" +#include "account.h" +#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() + { +#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) + 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")); + { + QFile f(dir.path() + "/sub/file.txt"); + f.open(QFile::WriteOnly); + f.write("hello"); + } + + AccountStatePtr newAccountState(new AccountState(Account::create())); + FolderMan *folderman = FolderMan::instance(); + QCOMPARE(folderman, &_fm); + QVERIFY(folderman->addFolder(newAccountState.data(), folderDefinition(dir.path() + "/sub/ownCloud1"))); + QVERIFY(folderman->addFolder(newAccountState.data(), folderDefinition(dir.path() + "/ownCloud2"))); + + + // those should be allowed + 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()); + + // A file -> Error + QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/file.txt").isNull()); + + // 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()); + + + // 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()); +#else + QSKIP("Test not supported with Qt4", SkipSingle); +#endif + } +}; + +QTEST_MAIN(TestFolderMan) +#include "testfolderman.moc" -- cgit v1.2.3