/* ============================================================ * The rekonq project * ============================================================ * SPDX-License-Identifier: GPL-3.0-only * Copyright (C) 2022 aqua * ============================================================ */ #include #include #include #include #include // 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, settingsPath) { const auto path = QDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)).filePath("rekonqrc"); EXPECT_FALSE(path.isEmpty()); EXPECT_TRUE(path.endsWith("rekonqrc")); } 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 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(); }