#define CATCH_CONFIG_RUNNER // clazy:excludeall=non-pod-global-static #include "webprofilemanager.h" #include #include SCENARIO("WebProfileManager") { const QString search{ "https://search.url/t=%1" }; const QUrl homepage{ "https://homepage.net" }; const QUrl newtab{ "https://newtab.net" }; const QString default_id{ "default" }; GIVEN("an empty profile list") { WebProfileManager profiles({}, default_id, search, homepage, newtab); REQUIRE(profiles.idList().count() == 1); REQUIRE(profiles.profile(default_id) == WebProfile::defaultProfile()); REQUIRE(profiles.profile("not-in-list") == nullptr); WHEN("adding a new profile") { const QString id{ "id" }; auto *settings = WebProfile::load(QString(), search, homepage, newtab); auto *profile = WebProfile::load(id, settings, true); THEN("doesn't add profile without settings") { profiles.add(id, profile, nullptr); REQUIRE(profiles.idList().count() == 1); } THEN("doesn't add settings without profile") { profiles.add(id, nullptr, settings); REQUIRE(profiles.idList().count() == 1); } THEN("adds new profile with settings") { profiles.add(id, profile, settings); REQUIRE(profiles.idList().count() == 2); } } WHEN("moving") { WebProfileManager other(std::move(profiles)); THEN("moved has the same number of profiles") { REQUIRE(other.idList().count() == 1); REQUIRE(other.profile(default_id) == WebProfile::defaultProfile()); REQUIRE(other.profile("not-in-list") == nullptr); } } } GIVEN("a number of profiles, default undefined") { REQUIRE(qEnvironmentVariableIsSet("PROFILES")); WebProfileManager profiles(QString::fromLatin1(qgetenv("PROFILES")).split(';'), default_id, search, homepage, newtab); REQUIRE(profiles.idList().count() == 2); REQUIRE(profiles.profile(default_id) == WebProfile::defaultProfile()); REQUIRE(profiles.profile("testing") != nullptr); REQUIRE(profiles.profile("not-in-list") == nullptr); WHEN("making global") { profiles.make_global(); WebProfileManager other; THEN("global has the same number of profiles") { REQUIRE(other.idList().count() == 2); REQUIRE(other.profile(default_id) == WebProfile::defaultProfile()); REQUIRE(other.profile("testing") != nullptr); REQUIRE(other.profile("not-in-list") == nullptr); } THEN("walking has no nullptrs") { other.walk([](const QString &, WebProfile *profile, const QSettings *settings) { REQUIRE(profile != nullptr); REQUIRE(settings != nullptr); }); } } } GIVEN("a number of profiles, default defined") { REQUIRE(qEnvironmentVariableIsSet("PROFILES")); WebProfileManager profiles(QString::fromLatin1(qgetenv("PROFILES")).split(';'), "testing", search, homepage, newtab); REQUIRE(profiles.idList().count() == 1); REQUIRE(profiles.profile("testing") == WebProfile::defaultProfile()); REQUIRE(profiles.profile("not-in-list") == nullptr); WHEN("walking") { profiles.walk([](const QString &, WebProfile *profile, const QSettings *settings) { REQUIRE(profile != nullptr); REQUIRE(settings != nullptr); }); } } } int main(int argc, char **argv) { QApplication app(argc, argv); const auto r = Catch::Session().run(argc, argv); return r; }