From c5ed279da0e74adb79c6c2a3e485cb9668b1c130 Mon Sep 17 00:00:00 2001 From: aqua Date: Wed, 24 Aug 2022 16:38:49 +0300 Subject: SettingsDialog: save settings when changed - connect Restore Defaults button --- src/settings/test/test_settings.cpp | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'src/settings/test') diff --git a/src/settings/test/test_settings.cpp b/src/settings/test/test_settings.cpp index 2ca5ba1a..fdb976f6 100644 --- a/src/settings/test/test_settings.cpp +++ b/src/settings/test/test_settings.cpp @@ -7,22 +7,34 @@ #include #include +#include #include #include -#include - // Software under Test #include "../helpers.hpp" #include "../settings.hpp" #include "../settingsdialog.h" #include "settings_mock.hpp" +using ::testing::_; using ::testing::AtLeast; +using ::testing::ContainerEq; using ::testing::ReturnArg; const char *settingsFile = nullptr; +MATCHER_P(QStringEq, a, "") +{ + *result_listener << "where the arg is " << qUtf8Printable(arg); + return arg.compare(a) == 0; +} +MATCHER_P(QVariantEq, a, "") +{ + *result_listener << "where the arg is " << qUtf8Printable(arg.toString()); + return arg.toString().compare(a) == 0; +} + TEST(settings, getFont) { const auto serif = getFont(QFont::Serif); @@ -60,12 +72,21 @@ TEST(settings, Settings) TEST(settings, SettingsDialog) { - MockSettings settings; - EXPECT_CALL(settings, beginGroup).Times(4); - EXPECT_CALL(settings, endGroup).Times(4); - EXPECT_CALL(settings, value).Times(AtLeast(4)).WillRepeatedly(ReturnArg<1>()); - - SettingsDialog dlg(&settings); + MockSettings mockSettings; + // There are 4 groups in total, but General should not be calling beginGroup/endGroup + // beginGroup/endGroup are called twice: during the ctor and when accepted + EXPECT_CALL(mockSettings, beginGroup).Times(3 * 2); + EXPECT_CALL(mockSettings, endGroup).Times(3 * 2); + // There are 35 settings in total, one of which is hidden and won't be set by the dialog + EXPECT_CALL(mockSettings, value).Times(35).WillRepeatedly(ReturnArg<1>()); + EXPECT_CALL(mockSettings, setValue(_, _)).Times(33); + EXPECT_CALL(mockSettings, setValue(QStringEq("homepage"), QVariantEq("about:blank"))); + + SettingsDialog dlg(&mockSettings); + auto *homepage = dlg.findChild("homepage"); + EXPECT_TRUE(homepage->text() == QLatin1String("http://www.kde.org/")) << qUtf8Printable(homepage->text()); + homepage->setText("about:blank"); + dlg.accept(); } int main(int argc, char **argv) -- cgit v1.2.1