#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file // clazy:excludeall=non-pod-global-static #include #include TEST_CASE("JsonSession default constructor") { JsonSession session; REQUIRE(session.serialize() == "{}"); const auto tree = session.get(); REQUIRE(tree.count() == 0); } TEST_CASE("JsonSession command line constructor, single URL") { const QString profile = ""; const QString url = "https://some.url"; JsonSession session(profile, QStringList(url)); const auto tree = session.get(); REQUIRE(tree.count() == 1); const auto window = tree.at(0); REQUIRE(window.subwindows.count() == 1); const auto subwindow = window.subwindows.at(0); REQUIRE(subwindow.profile == profile); REQUIRE(subwindow.tabs.count() == 1); const auto tab = subwindow.tabs.at(0); REQUIRE(tab.profile == profile); REQUIRE(tab.url == url); REQUIRE(tab.history.isEmpty()); } TEST_CASE("JsonSession command line constructor, multiple URLs") { const QString profile = "default"; const QStringList urls{ "https://some.url", "http://other.url", "a random string" }; JsonSession session(profile, urls); const auto tree = session.get(); REQUIRE(tree.count() == 1); const auto window = tree.at(0); REQUIRE(window.subwindows.count() == 1); const auto subwindow = window.subwindows.at(0); REQUIRE(subwindow.profile == profile); REQUIRE(subwindow.tabs.count() == 3); for(int i = 0; i < urls.size(); ++i) { const auto tab = subwindow.tabs.at(i); REQUIRE(tab.profile == profile); REQUIRE(tab.url == urls.at(i)); REQUIRE(tab.history.isEmpty()); } } TEST_CASE("JsonSession QByteArray constuctor") { const QString profile = ""; const QString url = "about:blank"; JsonSession donor(profile, { url }); JsonSession session(donor.serialize()); const auto tree = session.get(); REQUIRE(tree.count() == 1); const auto window = tree.at(0); REQUIRE(window.subwindows.count() == 1); const auto subwindow = window.subwindows.at(0); REQUIRE(subwindow.profile == profile); REQUIRE(subwindow.tabs.count() == 1); const auto tab = subwindow.tabs.at(0); REQUIRE(tab.profile == profile); REQUIRE(tab.url == url); REQUIRE(tab.history.isEmpty()); } TEST_CASE("JsonSession MainWindowVector constructor") { const Session::WebView cview{ "profile", "url", "history" }; const Session::SubWindow csubwindow{ "profile", { cview } }; const Session::MainWindow cwindow{ { csubwindow } }; const JsonSession session{ { cwindow } }; const auto tree = session.get(); REQUIRE(tree.count() == 1); const auto window = tree.at(0); REQUIRE(window.subwindows.count() == 1); const auto subwindow = window.subwindows.at(0); REQUIRE(subwindow.profile == csubwindow.profile); REQUIRE(subwindow.tabs.count() == 1); const auto tab = subwindow.tabs.at(0); REQUIRE(tab.profile == cview.profile); REQUIRE(tab.url == cview.url); REQUIRE(tab.history == cview.history); }