summaryrefslogtreecommitdiff
path: root/src/settings
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-08-25 21:30:08 +0300
committeraqua <aqua@iserlohn-fortress.net>2022-08-28 10:56:22 +0300
commit0ba34ee50bc3d58de44bdaef2e4fdfd7b2fc5907 (patch)
tree498c4e2275008564b43f32a4bb24505ffe4dfc84 /src/settings
parentSettingsDialog: save settings when changed (diff)
downloadrekonq-0ba34ee50bc3d58de44bdaef2e4fdfd7b2fc5907.tar.xz
Improve test coverage
Diffstat (limited to 'src/settings')
-rw-r--r--src/settings/CMakeLists.txt11
-rw-r--r--src/settings/settings.hpp1
-rw-r--r--src/settings/settingswidgets.hpp5
-rw-r--r--src/settings/test/rekonqrc36
-rw-r--r--src/settings/test/test_settings.cpp40
-rw-r--r--src/settings/test/test_settings.qrc5
6 files changed, 77 insertions, 21 deletions
diff --git a/src/settings/CMakeLists.txt b/src/settings/CMakeLists.txt
index 29a011c1..712fd57a 100644
--- a/src/settings/CMakeLists.txt
+++ b/src/settings/CMakeLists.txt
@@ -23,16 +23,11 @@ add_library(settings STATIC
)
target_link_libraries(settings PUBLIC Qt6::Widgets)
-IF(TESTING)
+IF(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
add_executable(test_settingsdialog test/test_settingsdialog.cpp test/settings_mock.hpp)
target_link_libraries(test_settingsdialog GTest::gmock settings)
- # test config file
- add_custom_command(OUTPUT rekonqrc DEPENDS ${PROJECT_SOURCE_DIR}/src/rekonq.kcfg
- COMMAND python3 ${PROJECT_SOURCE_DIR}/scripts/rekonf.py
- --group=all --output=rekonqrc ${PROJECT_SOURCE_DIR}/src/rekonq.kcfg)
-
- add_executable(test_settings test/test_settings.cpp test/settings_mock.hpp rekonqrc)
- target_link_libraries(test_settings GTest::gtest GTest::gmock settings)
+ add_executable(test_settings test/test_settings.cpp test/test_settings.qrc test/settings_mock.hpp)
+ target_link_libraries(test_settings PRIVATE GTest::gtest GTest::gmock settings)
gtest_discover_tests(test_settings EXTRA_ARGS rekonqrc)
endif()
diff --git a/src/settings/settings.hpp b/src/settings/settings.hpp
index ec654f17..713ce38d 100644
--- a/src/settings/settings.hpp
+++ b/src/settings/settings.hpp
@@ -28,5 +28,6 @@ public:
[[nodiscard]] QString filePath() const override;
private:
+ Q_DISABLE_COPY_MOVE(Settings)
QSettings *d;
};
diff --git a/src/settings/settingswidgets.hpp b/src/settings/settingswidgets.hpp
index 25fbe0a4..cb08b591 100644
--- a/src/settings/settingswidgets.hpp
+++ b/src/settings/settingswidgets.hpp
@@ -20,6 +20,7 @@ public:
{
m_settings = settings;
}
+ virtual ~SettingsWidget() = default;
signals:
void changed();
@@ -36,22 +37,26 @@ class GeneralSettingsWidget final : public SettingsWidget {
Q_OBJECT
public:
explicit GeneralSettingsWidget(RekonqSettings *, QWidget *parent = nullptr);
+ ~GeneralSettingsWidget() override = default;
};
class AppearanceSettingsWidget final : public SettingsWidget {
Q_OBJECT
public:
explicit AppearanceSettingsWidget(RekonqSettings *, QWidget *parent = nullptr);
+ ~AppearanceSettingsWidget() override = default;
};
class NetworkSettingsWidget final : public SettingsWidget {
Q_OBJECT
public:
explicit NetworkSettingsWidget(RekonqSettings *, QWidget *parent = nullptr);
+ ~NetworkSettingsWidget() override = default;
};
class ShortcutsSettingsWidget final : public SettingsWidget {
Q_OBJECT
public:
explicit ShortcutsSettingsWidget(RekonqSettings *, QWidget *parent = nullptr);
+ ~ShortcutsSettingsWidget() override = default;
};
diff --git a/src/settings/test/rekonqrc b/src/settings/test/rekonqrc
new file mode 100644
index 00000000..97329a6d
--- /dev/null
+++ b/src/settings/test/rekonqrc
@@ -0,0 +1,36 @@
+[General]
+FirstRun=true
+lang=TODO: change type to StringList
+homepage=http://www.kde.org/
+newtab=http://www.kde.org/
+searchUrl=https://duckduckgo.com/?q=%1
+pluginPath=TODO: change type to Path
+
+[Network]
+downloadPath=TODO: change type to Path
+downloadPathAsk=true
+userAgent=TODO
+
+[Appearance]
+defaultFontSize=16
+minFontSize=7
+defaultEncoding=ISO 8859-1
+defaultZoom=10
+
+[Shortcuts]
+actionShowSidebar=Ctrl+B
+actionShowSearchBar=Ctrl+F
+actionSettings=Ctrl+S
+actionQuit=Ctrl+Q
+actionNewTab=Ctrl+T
+actionCloseTab=Ctrl+W
+actionSwitchTabLeft=Ctrl+Left
+actionSwitchTabRight=Ctrl+Right
+actionFocusAddressBar=F6
+actionBack=Alt+Left
+actionForward=Alt+Right
+actionRefresh=F5
+actionReload=Ctrl+F5
+actionOpen=Ctrl+O
+actionBookmark=Ctrl+D
+
diff --git a/src/settings/test/test_settings.cpp b/src/settings/test/test_settings.cpp
index fdb976f6..babbcdb6 100644
--- a/src/settings/test/test_settings.cpp
+++ b/src/settings/test/test_settings.cpp
@@ -6,8 +6,10 @@
* ============================================================ */
#include <QApplication>
+#include <QDialogButtonBox>
#include <QDir>
#include <QLineEdit>
+#include <QPushButton>
#include <QStandardPaths>
#include <gtest/gtest.h>
@@ -22,8 +24,6 @@ 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);
@@ -53,12 +53,16 @@ TEST(settings, settingsPath)
TEST(settings, Settings)
{
- Settings settings(settingsFile);
+ Settings settings(":rekonqrc");
+ EXPECT_THAT(settings.filePath(), QStringEq(":rekonqrc"));
const auto FirstRun = settings.value("FirstRun");
EXPECT_TRUE(FirstRun.isValid());
EXPECT_TRUE(FirstRun.toBool());
+ settings.setValue("FirstRun", false);
+ EXPECT_FALSE(settings.value("FirstRun").toBool());
+
settings.beginGroup("Network");
const auto downloadPathAsk = settings.value("downloadPathAsk");
EXPECT_TRUE(downloadPathAsk.isValid());
@@ -75,24 +79,34 @@ TEST(settings, SettingsDialog)
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);
+ EXPECT_CALL(mockSettings, beginGroup).Times(3 * 4);
+ EXPECT_CALL(mockSettings, endGroup).Times(3 * 4);
// 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, value).Times(35 * 2).WillRepeatedly(ReturnArg<1>());
+ EXPECT_CALL(mockSettings, setValue(_, _)).Times(33 + 34);
EXPECT_CALL(mockSettings, setValue(QStringEq("homepage"), QVariantEq("about:blank")));
- SettingsDialog dlg(&mockSettings);
- auto *homepage = dlg.findChild<QLineEdit *>("homepage");
- EXPECT_TRUE(homepage->text() == QLatin1String("http://www.kde.org/")) << qUtf8Printable(homepage->text());
- homepage->setText("about:blank");
- dlg.accept();
+ // change setting
+ {
+ SettingsDialog dlg(&mockSettings);
+ auto *homepage = dlg.findChild<QLineEdit *>("homepage");
+ EXPECT_TRUE(homepage->text() == QLatin1String("http://www.kde.org/")) << qUtf8Printable(homepage->text());
+ homepage->setText("about:blank");
+ dlg.accept();
+ }
+
+ // reset setting
+ {
+ SettingsDialog dlg(&mockSettings);
+ auto *resetBtn = dlg.findChild<QDialogButtonBox *>()->button(QDialogButtonBox::RestoreDefaults);
+ EXPECT_FALSE(resetBtn == nullptr);
+ resetBtn->click();
+ }
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
- if (argc > 1) settingsFile = argv[argc - 1];
// handling fonts requires a QGuiApplication
// The proper platform name needs to be added to the argument list before the QGuiApplication constructor is called
diff --git a/src/settings/test/test_settings.qrc b/src/settings/test/test_settings.qrc
new file mode 100644
index 00000000..deaf088f
--- /dev/null
+++ b/src/settings/test/test_settings.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>rekonqrc</file>
+ </qresource>
+</RCC>