diff options
author | aqua <aqua@iserlohn-fortress.net> | 2022-08-20 16:37:42 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2022-08-28 09:48:45 +0300 |
commit | f7ccea7bca79f1dc21e497872a419446f20d211e (patch) | |
tree | 87ad85a6e402908ce5c7f3439e0e25b889333c1c /src/settings/test | |
parent | Add rekonf script to generate SettingsWidgets (diff) | |
download | rekonq-f7ccea7bca79f1dc21e497872a419446f20d211e.tar.xz |
Add Setting and MockSettings
- rename Settings to RekonqSettings
Diffstat (limited to 'src/settings/test')
-rw-r--r-- | src/settings/test/dialog.cpp | 12 | ||||
-rw-r--r-- | src/settings/test/fonts.cpp | 31 | ||||
-rw-r--r-- | src/settings/test/settings_mock.hpp | 18 | ||||
-rw-r--r-- | src/settings/test/test_settings.cpp | 71 | ||||
-rw-r--r-- | src/settings/test/test_settingsdialog.cpp | 20 |
5 files changed, 109 insertions, 43 deletions
diff --git a/src/settings/test/dialog.cpp b/src/settings/test/dialog.cpp deleted file mode 100644 index 2bc9ffe0..00000000 --- a/src/settings/test/dialog.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "../settingsdialog.h" -#include <QApplication> - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - - SettingsDialog dlg; - dlg.show(); - - return QApplication::exec(); -}
\ No newline at end of file diff --git a/src/settings/test/fonts.cpp b/src/settings/test/fonts.cpp deleted file mode 100644 index 65cc7229..00000000 --- a/src/settings/test/fonts.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "../helpers.hpp" -#include <QFontInfo> -#include <QGuiApplication> -#include <gtest/gtest.h> -#include <vector> - -TEST(Settings, getFont) -{ - const auto serif = getFont(QFont::Serif); - EXPECT_EQ(serif.styleHint(), QFont::Serif) << qUtf8Printable(serif.toString()); - - const auto fixed = getFont(QFont::Monospace); - EXPECT_EQ(fixed.styleHint(), QFont::Monospace) << qUtf8Printable(fixed.toString()); -} - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - - // handling fonts requires a QGuiApplication - // The proper platform name needs to be added to the argument list before the QGuiApplication constructor is called - // This needs to be done here for gtest_discover_tests to work - QList<char *> args; - for (int i = 0; i < argc; ++i) args.append(argv[i]); - args.append({"-platform", "offscreen"}); - int args_count = args.count(); - - QGuiApplication app(args_count, args.data()); - - return RUN_ALL_TESTS(); -} diff --git a/src/settings/test/settings_mock.hpp b/src/settings/test/settings_mock.hpp new file mode 100644 index 00000000..ec792ff5 --- /dev/null +++ b/src/settings/test/settings_mock.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include <gmock/gmock.h> +#include <rsettings.hpp> + +class MockSettings : public RekonqSettings { + Q_OBJECT + +public: + explicit MockSettings() : RekonqSettings(nullptr) {} + ~MockSettings() = default; + + MOCK_METHOD(void, beginGroup, (const QString &), (override)); + MOCK_METHOD(void, endGroup, (), (override)); + + MOCK_METHOD(void, setValue, (const QString &, const QVariant &), (override)); + MOCK_METHOD(QVariant, value, (const QString &, const QVariant &), (const, override)); +}; diff --git a/src/settings/test/test_settings.cpp b/src/settings/test/test_settings.cpp new file mode 100644 index 00000000..72582bc7 --- /dev/null +++ b/src/settings/test/test_settings.cpp @@ -0,0 +1,71 @@ +#include <QApplication> +#include <gtest/gtest.h> + +#include <iostream> + +// Software under Test +#include "../helpers.hpp" +#include "../settings.hpp" +#include "../settingsdialog.h" +#include "settings_mock.hpp" + +using ::testing::AtLeast; +using ::testing::ReturnArg; + +const char *settingsFile = nullptr; + +TEST(settings, getFont) +{ + const auto serif = getFont(QFont::Serif); + EXPECT_EQ(serif.styleHint(), QFont::Serif) << qUtf8Printable(serif.toString()); + + const auto fixed = getFont(QFont::Monospace); + EXPECT_EQ(fixed.styleHint(), QFont::Monospace) << qUtf8Printable(fixed.toString()); +} + +TEST(settings, Settings) +{ + Settings settings(settingsFile); + + const auto FirstRun = settings.value("FirstRun"); + EXPECT_TRUE(FirstRun.isValid()); + EXPECT_TRUE(FirstRun.toBool()); + + settings.beginGroup("Network"); + const auto downloadPathAsk = settings.value("downloadPathAsk"); + EXPECT_TRUE(downloadPathAsk.isValid()); + EXPECT_TRUE(downloadPathAsk.toBool()); + settings.endGroup(); + + const auto searchUrl = settings.value("searchUrl"); + EXPECT_TRUE(searchUrl.isValid()); + EXPECT_EQ(searchUrl.toString(), QString("https://duckduckgo.com/?q=%1")); +} + +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); +} + +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 + // This needs to be done here for gtest_discover_tests to work + QList<char *> args; + for (int i = 0; i < argc; ++i) args.append(argv[i]); + args.append({"-platform", "offscreen"}); + int args_count = args.count(); + + QApplication app(args_count, args.data()); + + return RUN_ALL_TESTS(); +} diff --git a/src/settings/test/test_settingsdialog.cpp b/src/settings/test/test_settingsdialog.cpp new file mode 100644 index 00000000..b70c6dda --- /dev/null +++ b/src/settings/test/test_settingsdialog.cpp @@ -0,0 +1,20 @@ +#include "../settingsdialog.h" +#include "settings_mock.hpp" +#include <QApplication> + +using ::testing::AtLeast; +using ::testing::NiceMock; +using ::testing::ReturnArg; + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + NiceMock<MockSettings> settings; + EXPECT_CALL(settings, value).WillRepeatedly(ReturnArg<1>()); + + SettingsDialog dlg(&settings); + dlg.show(); + + return QApplication::exec(); +} |