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.cpp37
1 files changed, 29 insertions, 8 deletions
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 <QApplication>
#include <QDir>
+#include <QLineEdit>
#include <QStandardPaths>
#include <gtest/gtest.h>
-#include <iostream>
-
// 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<QLineEdit *>("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)