summaryrefslogtreecommitdiff
path: root/src/settings/test/test_settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings/test/test_settings.cpp')
-rw-r--r--src/settings/test/test_settings.cpp40
1 files changed, 27 insertions, 13 deletions
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