From 8260ad6fd639925e28f9d062dc5d1770b6db0dc5 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Thu, 26 Dec 2024 11:28:09 +0100 Subject: [PATCH] Enhance TestSettings Test both "normal" MXIDs and MXIDs with slashes; actually test reading into AccountSettings from the settings storage. --- autotests/testsettings.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/autotests/testsettings.cpp b/autotests/testsettings.cpp index 85c91864c..8b84555a5 100644 --- a/autotests/testsettings.cpp +++ b/autotests/testsettings.cpp @@ -13,6 +13,7 @@ class TestSettings : public QObject { private slots: void initTestCase(); + void accountSettings_data() const; void accountSettings(); private: @@ -25,22 +26,28 @@ void TestSettings::initTestCase() qSettings.remove(AccountsGroupName); } +void TestSettings::accountSettings_data() const +{ + QTest::addColumn("mxId"); + + QTest::newRow("normal MXID") << u"@user:example.org"_s; + QTest::newRow("MXID with slashes") << u"@user/with\\slashes:example.org"_s; // Test #842 +} + void TestSettings::accountSettings() { - const auto mxId = u"@user/with\\slashes:example.org"_s; // Test #842 + QFETCH(QString, mxId); const auto escapedMxId = Settings::escapedForSettings(mxId); const auto homeserverUrl = QUrl(u"https://example.org"_s); + QVERIFY(SettingsGroup(AccountsGroupName).childGroups().empty()); // Pre-requisite qSettings.beginGroup(AccountsGroupName); - { + { // Test writing to account settings AccountSettings accSettings(mxId); + QCOMPARE(accSettings.userId(), mxId); + QCOMPARE(accSettings.group(), AccountsGroupName % u'/' % escapedMxId); accSettings.setHomeserver(homeserverUrl); - QVERIFY(accSettings.homeserver() == homeserverUrl); - // Bypass SettingsGroup::get() that prepends the group name and check that the group name - // has actually been prepended. - QVERIFY(accSettings.Settings::get(AccountsGroupName % u'/' % escapedMxId % u'/' - % u"homeserver"_s) - == homeserverUrl); + QCOMPARE(accSettings.homeserver(), homeserverUrl); } qSettings.sync(); @@ -48,6 +55,13 @@ void TestSettings::accountSettings() auto childGroups = qSettings.childGroups(); QVERIFY(childGroups.contains(escapedMxId)); QVERIFY(SettingsGroup(AccountsGroupName).childGroups().contains(mxId)); + { // Test reading what was previously written + SettingsGroup allAccountNames(AccountsGroupName); + QCOMPARE(allAccountNames.childGroups().size(), 1); + AccountSettings accSettings(allAccountNames.childGroups().back()); + QCOMPARE(accSettings.userId(), mxId); + QCOMPARE(accSettings.homeserver(), homeserverUrl); + } SettingsGroup(AccountsGroupName).remove(mxId); qSettings.sync(); childGroups = qSettings.childGroups();