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/test_settings.cpp | |
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/test_settings.cpp')
-rw-r--r-- | src/settings/test/test_settings.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
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(); +} |