aboutsummaryrefslogtreecommitdiff
path: root/lib/session_formats/test/json.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-04-13 15:44:09 +0300
committerAqua-sama <aqua@iserlohn-fortress.net>2020-04-13 15:44:09 +0300
commit396bc0c1721af8d3ee970228e7df457f6b2c73d5 (patch)
tree5aee4f0faec3fdfe616e1684dcb1736be9126bc1 /lib/session_formats/test/json.cpp
parentAdd singleapplication.wrap (diff)
downloadsmolbote-396bc0c1721af8d3ee970228e7df457f6b2c73d5.tar.xz
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
Diffstat (limited to 'lib/session_formats/test/json.cpp')
-rw-r--r--lib/session_formats/test/json.cpp103
1 files changed, 103 insertions, 0 deletions
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 <catch2/catch.hpp>
+#include <session_json.hpp>
+
+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);
+}