diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index ece3d1e..cfbd4e9 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,6 +1,12 @@ # SPDX-FileCopyrightText: 2023 Joshua Goins # 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 diff --git a/autotests/accountmanagertest.cpp b/autotests/accountmanagertest.cpp new file mode 100644 index 0000000..155e0fc --- /dev/null +++ b/autotests/accountmanagertest.cpp @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: 2024 Joshua Goins +// SPDX-License-Identifier: GPL-3.0-or-later + +#include + +#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" diff --git a/launcher/src/accountmanager.cpp b/launcher/src/accountmanager.cpp index b431ee0..78351aa 100644 --- a/launcher/src/accountmanager.cpp +++ b/launcher/src/accountmanager.cpp @@ -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)