summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2025-06-08 14:53:13 +0200
committerFelix Morgner <felix.morgner@gmail.com>2025-06-08 14:53:13 +0200
commit63aa6b86c211828c47027145ff405fd7e3fc5c3a (patch)
treeff77a5279b845b0fa2d5d5ef7c11de97a71c5c96
parent0c5b0e03345d31406963e8ed8348a8c77ebe6352 (diff)
downloadturns-63aa6b86c211828c47027145ff405fd7e3fc5c3a.tar.xz
turns-63aa6b86c211828c47027145ff405fd7e3fc5c3a.zip
gui: wrap tests in application
-rw-r--r--gui/CMakeLists.txt4
-rw-r--r--gui/tests/gtk-test.cpp39
-rw-r--r--gui/tests/gtk-test.hpp33
-rw-r--r--gui/tests/main.cpp60
-rw-r--r--gui/tests/main.hpp19
-rw-r--r--gui/tests/participant_editor.cpp25
6 files changed, 94 insertions, 86 deletions
diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
index 111a870..7e3edf7 100644
--- a/gui/CMakeLists.txt
+++ b/gui/CMakeLists.txt
@@ -157,7 +157,7 @@ install(TARGETS "gui")
# Tests
add_executable("gui-tests"
- "tests/gtk-test.cpp"
+ "tests/main.cpp"
"tests/messages.cpp"
"tests/participant_editor.cpp"
"tests/participant_row.cpp"
@@ -166,7 +166,7 @@ add_executable("gui-tests"
target_link_libraries("gui-tests" PRIVATE
"gui_impl"
- "Catch2::Catch2WithMain"
+ "Catch2::Catch2"
"$<$<CXX_COMPILER_ID:GNU,Clang>:-Wl,--whole-archive>"
"resources"
diff --git a/gui/tests/gtk-test.cpp b/gui/tests/gtk-test.cpp
deleted file mode 100644
index 385f772..0000000
--- a/gui/tests/gtk-test.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com>
- * SPDX-License-Identifier: LGPL-2.1-only
- */
-
-#include "gtk-test.hpp"
-
-#include <turnsmm/init.hpp>
-
-#include <libintl.h>
-
-#include <clocale>
-
-namespace Turns::gui::tests
-{
-
- auto gtk_test::testRunStarting(Catch::TestRunInfo const &) -> void
- {
- setlocale(LC_ALL, "");
- bindtextdomain("turns", TESTLOCALEDIR);
- bind_textdomain_codeset("turns", "UTF-8");
- textdomain("turns");
-
- application = Adwaita::Application::create("ch.arknet.turns.tests.ui");
- Turns::init();
- }
-
- auto gtk_test::testRunEnded(Catch::TestRunStats const &) -> void
- {
- application->quit();
- application.reset();
- }
-
- auto gtk_test::testCaseEnded(Catch::TestCaseStats const &) -> void
- {
- setlocale(LC_ALL, "");
- }
-
-} // namespace Turns::Gui::tests \ No newline at end of file
diff --git a/gui/tests/gtk-test.hpp b/gui/tests/gtk-test.hpp
deleted file mode 100644
index 5ac6753..0000000
--- a/gui/tests/gtk-test.hpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com>
- * SPDX-License-Identifier: LGPL-2.1-only
- */
-
-#ifndef TURNS_GUI_TESTS_GTK_TEST_HPP
-#define TURNS_GUI_TESTS_GTK_TEST_HPP
-
-#include <catch2/reporters/catch_reporter_event_listener.hpp>
-#include <catch2/reporters/catch_reporter_registrars.hpp>
-
-#include <adwaitamm/application.hpp>
-#include <glibmm/refptr.h>
-
-namespace Turns::gui::tests
-{
-
- struct gtk_test : Catch::EventListenerBase
- {
- using Catch::EventListenerBase::EventListenerBase;
-
- static inline Glib::RefPtr<Adwaita::Application> application{};
-
- auto testRunStarting(Catch::TestRunInfo const &) -> void override;
- auto testRunEnded(Catch::TestRunStats const &) -> void override;
- auto testCaseEnded(Catch::TestCaseStats const &) -> void override;
- };
-
- CATCH_REGISTER_LISTENER(gtk_test);
-
-} // namespace turns::ui::tests
-
-#endif
diff --git a/gui/tests/main.cpp b/gui/tests/main.cpp
new file mode 100644
index 0000000..5fbc164
--- /dev/null
+++ b/gui/tests/main.cpp
@@ -0,0 +1,60 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com>
+ * SPDX-License-Identifier: LGPL-2.1-only
+ */
+
+#include "main.hpp"
+
+#include "init.hpp"
+
+#include <turnsmm/init.hpp>
+
+#include <catch2/catch_session.hpp>
+
+#include <adwaitamm/application.hpp>
+#include <adwaitamm/applicationwindow.hpp>
+#include <giomm/application.h>
+#include <glibmm/main.h>
+#include <glibmm/refptr.h>
+
+#include <libintl.h>
+
+#include <clocale>
+#include <memory>
+
+namespace Turns::gui::tests::globals
+{
+ Glib::RefPtr<Adwaita::Application> app{};
+ Glib::RefPtr<Adwaita::ApplicationWindow> win{};
+} // namespace Turns::gui::tests::globals
+
+auto main(int argc, char ** argv) -> int
+{
+ using namespace Turns::gui::tests::globals;
+
+ auto session = Catch::Session{};
+ if (auto error = session.applyCommandLine(argc, argv); error != 0)
+ {
+ return error;
+ }
+
+ setlocale(LC_ALL, "");
+ bindtextdomain("turns", TESTLOCALEDIR);
+ bind_textdomain_codeset("turns", "UTF-8");
+ textdomain("turns");
+
+ app = Adwaita::Application::create("ch.arknet.Turns", Gio::Application::Flags::DEFAULT_FLAGS);
+
+ Turns::init();
+ Turns::gui::init();
+
+ app->signal_activate().connect([&session] {
+ win = std::make_shared<Adwaita::ApplicationWindow>(app);
+ Glib::signal_idle().connect_once([&session] {
+ session.run();
+ app->quit();
+ });
+ });
+
+ return app->run();
+}
diff --git a/gui/tests/main.hpp b/gui/tests/main.hpp
new file mode 100644
index 0000000..6aeda84
--- /dev/null
+++ b/gui/tests/main.hpp
@@ -0,0 +1,19 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com>
+ * SPDX-License-Identifier: LGPL-2.1-only
+ */
+
+#ifndef TURNS_GUI_TESTS_MAIN_HPP
+#define TURNS_GUI_TESTS_MAIN_HPP
+
+#include <adwaitamm/application.hpp>
+#include <adwaitamm/applicationwindow.hpp>
+#include <glibmm/refptr.h>
+
+namespace Turns::gui::tests::globals
+{
+ extern Glib::RefPtr<Adwaita::Application> app;
+ extern Glib::RefPtr<Adwaita::ApplicationWindow> win;
+} // namespace Turns::gui::tests::globals
+
+#endif \ No newline at end of file
diff --git a/gui/tests/participant_editor.cpp b/gui/tests/participant_editor.cpp
index 8f6f7d3..723c10a 100644
--- a/gui/tests/participant_editor.cpp
+++ b/gui/tests/participant_editor.cpp
@@ -5,7 +5,7 @@
#include "participant_editor.hpp"
-#include "gtk-test.hpp"
+#include "main.hpp"
#include "messages.hpp"
#include <turnsmm/participant.hpp>
@@ -15,9 +15,11 @@
#include <glib/gi18n.h>
+#include <adwaitamm/application.hpp>
#include <adwaitamm/applicationwindow.hpp>
#include <adwaitamm/comborow.hpp>
#include <glibmm/i18n.h>
+#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <gtkmm/stringobject.h>
@@ -36,7 +38,6 @@ namespace Turns::gui::tests
SCENARIO("Creating a participant editor", "[gui][windows][lifetime]")
{
- auto window = Adwaita::ApplicationWindow{gtk_test::application};
auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8", "de_DE.UTF-8", "de_AT.UTF-8");
GIVEN(std::format("An active locale of {}", locale))
@@ -46,7 +47,7 @@ namespace Turns::gui::tests
AND_GIVEN("a participant editor constructed without a participant")
{
auto instance = ParticipantEditor{nullptr};
- instance.present(&window);
+ instance.present(globals::win.get());
THEN("its title is message::add_participant")
{
@@ -180,14 +181,14 @@ namespace Turns::gui::tests
}
}
}
-}
+} // namespace Turns::gui::tests
- // auto participant = Participant::create(default_name, default_priority, default_disposition);
- // auto instance = std::make_shared<ParticipantEditor>(nullptr);
- // auto window = Gtk::Window{};
+// auto participant = Participant::create(default_name, default_priority, default_disposition);
+// auto instance = std::make_shared<ParticipantEditor>(nullptr);
+// auto window = Gtk::Window{};
- // SECTION("allows binding to the finished signal")
- // {
- // REQUIRE((instance->signal_finished().connect([](auto, auto, auto) {})).connected());
- // }
- // }
+// SECTION("allows binding to the finished signal")
+// {
+// REQUIRE((instance->signal_finished().connect([](auto, auto, auto) {})).connected());
+// }
+// }