1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-06-07 14:37:45 +00:00

Begin testing AccountManager

This commit is contained in:
Joshua Goins 2024-08-22 18:57:25 -04:00
parent 51d9551667
commit 33441f06d0
3 changed files with 40 additions and 1 deletions

View file

@ -1,6 +1,12 @@
# SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
# SPDX-License-Identifier: CC0-1.0
ecm_add_test(accountmanagertest.cpp
TEST_NAME accountmanagertest
LINK_LIBRARIES astra_static Qt::Test
NAME_PREFIX "astra-"
)
ecm_add_test(patchlisttest.cpp
TEST_NAME patchlisttest
LINK_LIBRARIES astra_static Qt::Test

View file

@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#include <QtTest/QtTest>
#include "accountmanager.h"
class AccountManagerTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testNothing()
{
AccountManager profileManager;
QAbstractItemModelTester modelTester(&profileManager);
QCOMPARE(profileManager.rowCount({}), 0);
profileManager.load();
// There should be no profiles, not even a dummy one
QCOMPARE(profileManager.rowCount({}), 0);
QCOMPARE(profileManager.numAccounts(), 0);
QVERIFY(!profileManager.hasAnyAccounts());
// These functions shouldn't crash and return empty when there's no acccounts
QCOMPARE(profileManager.getByUuid(QString{}), nullptr);
QVERIFY(!profileManager.canDelete(nullptr));
}
};
QTEST_MAIN(AccountManagerTest)
#include "accountmanagertest.moc"

View file

@ -92,7 +92,7 @@ Account *AccountManager::getByUuid(const QString &uuid) const
bool AccountManager::canDelete(const Account *account) const
{
Q_UNUSED(account)
return m_accounts.size() != 1;
return m_accounts.size() > 1;
}
void AccountManager::deleteAccount(Account *account)