Skip to content

Commit 1a0bd15

Browse files
committed
test(folderman): add test function to unload and delete folders.
Signed-off-by: Camila Ayres <hello@camilasan.com>
1 parent 8ae3a97 commit 1a0bd15

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

test/testfolderman.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "accountstate.h"
2020
#include <accountmanager.h>
2121
#include "configfile.h"
22+
#include "socketapi/socketapi.h"
2223
#include "syncenginetestutils.h"
2324
#include "testhelper.h"
2425

@@ -554,6 +555,39 @@ private slots:
554555
verifyFolderSyncChangesOnReceivedFileIdNotification(user2, {50}, {"2"});
555556
verifyFolderSyncChangesOnReceivedFileIdNotification(user2, {10, 11, 17, 18, 404}, {});
556557
}
558+
559+
void testUnloadAndDeleteAllFolders()
560+
{
561+
_fm.reset({});
562+
_fm.reset(new FolderMan{});
563+
564+
QTemporaryDir dir;
565+
ConfigFile::setConfDir(dir.path());
566+
QVERIFY(dir.isValid());
567+
QVERIFY(QDir(dir.path()).mkpath(QStringLiteral("folder1")));
568+
QVERIFY(QDir(dir.path()).mkpath(QStringLiteral("folder2")));
569+
570+
auto account = Account::create();
571+
account->setCredentials(new FakeCredentials{new FakeQNAM({})});
572+
account->setUrl(QUrl(QStringLiteral("http://example.de")));
573+
auto accountState = new FakeAccountState(account);
574+
575+
const auto folder1 = FolderMan::instance()->addFolder(accountState, folderDefinition(dir.path() + QStringLiteral("/folder1")));
576+
const auto folder2 = FolderMan::instance()->addFolder(accountState, folderDefinition(dir.path() + QStringLiteral("/folder2")));
577+
QVERIFY(folder1);
578+
QVERIFY(folder2);
579+
QCOMPARE(FolderMan::instance()->map().count(), 2);
580+
581+
auto socketApi = FolderMan::instance()->socketApi();
582+
583+
// verifies that calling slotUnregisterPath twice on the same alias doesn't crash
584+
socketApi->slotUnregisterPath(folder1->alias());
585+
socketApi->slotUnregisterPath(folder1->alias());
586+
587+
FolderMan::instance()->unloadAndDeleteAllFolders();
588+
589+
QCOMPARE(FolderMan::instance()->map().count(), 0);
590+
}
557591
};
558592

559593
QTEST_GUILESS_MAIN(TestFolderMan)

0 commit comments

Comments
 (0)