From 396bc0c1721af8d3ee970228e7df457f6b2c73d5 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 13 Apr 2020 15:44:09 +0300 Subject: Rewrite Session backend Add session.hpp, containing structs that describe session data MainWindow, SubWindow and WebView can be created from Session::structs Opening new window will automatically open a default subwindow and tab if none were specified Add lib/session_formats Add JsonSession, to serialize/deserialize Session structs into JSON - add some tests clang-tidy: - fix various warnings - disable modernize-use-trailing-return-type check --- lib/session_formats/test/json.cpp | 103 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 lib/session_formats/test/json.cpp (limited to 'lib/session_formats/test/json.cpp') diff --git a/lib/session_formats/test/json.cpp b/lib/session_formats/test/json.cpp new file mode 100644 index 0000000..4c6b683 --- /dev/null +++ b/lib/session_formats/test/json.cpp @@ -0,0 +1,103 @@ +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file +#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); +} -- cgit v1.2.1