summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2025-06-08 12:12:15 +0200
committerFelix Morgner <felix.morgner@gmail.com>2025-06-08 12:12:15 +0200
commitf50ec041a0f6fa036305ab5d5bdbdb9116b48024 (patch)
treea11bc0c12113b03c8d1d88873980d680cb7bfd19
parent8f7d79ed8433bd4809ecef12e6c8c9c015cd903b (diff)
downloadturns-f50ec041a0f6fa036305ab5d5bdbdb9116b48024.tar.xz
turns-f50ec041a0f6fa036305ab5d5bdbdb9116b48024.zip
gui: add more ParticipantEditor editing tests
-rw-r--r--gui/tests/gtk-test.cpp54
-rw-r--r--gui/tests/gtk-test.hpp33
-rw-r--r--gui/tests/participant_editor.cpp118
3 files changed, 98 insertions, 107 deletions
diff --git a/gui/tests/gtk-test.cpp b/gui/tests/gtk-test.cpp
index 8f897d9..385f772 100644
--- a/gui/tests/gtk-test.cpp
+++ b/gui/tests/gtk-test.cpp
@@ -3,49 +3,37 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
-#include "turnsmm/init.hpp"
+#include "gtk-test.hpp"
-#include <catch2/internal/catch_test_run_info.hpp>
-#include <catch2/reporters/catch_reporter_event_listener.hpp>
-#include <catch2/reporters/catch_reporter_registrars.hpp>
-
-#include <adwaitamm/application.hpp>
-#include <adwaitamm/wrap_init.hpp>
-#include <glibmm/i18n.h>
-#include <glibmm/refptr.h>
-#include <gtkmm/init.h>
+#include <turnsmm/init.hpp>
#include <libintl.h>
#include <clocale>
-namespace turns::ui::tests
+namespace Turns::gui::tests
{
- struct gtk_test : Catch::EventListenerBase
+ auto gtk_test::testRunStarting(Catch::TestRunInfo const &) -> void
{
- using Catch::EventListenerBase::EventListenerBase;
-
- auto testRunStarting(Catch::TestRunInfo const &) -> void override
- {
- setlocale(LC_ALL, "");
- bindtextdomain("turns", TESTLOCALEDIR);
- bind_textdomain_codeset("turns", "UTF-8");
- textdomain("turns");
-
- m_app = Adwaita::Application::create("ch.arknet.turns.tests.ui");
- Turns::init();
- }
+ setlocale(LC_ALL, "");
+ bindtextdomain("turns", TESTLOCALEDIR);
+ bind_textdomain_codeset("turns", "UTF-8");
+ textdomain("turns");
- auto testCaseEnded(Catch::TestCaseStats const &) -> void override
- {
- setlocale(LC_ALL, "");
- }
+ application = Adwaita::Application::create("ch.arknet.turns.tests.ui");
+ Turns::init();
+ }
- private:
- Glib::RefPtr<Adwaita::Application> m_app{};
- };
+ auto gtk_test::testRunEnded(Catch::TestRunStats const &) -> void
+ {
+ application->quit();
+ application.reset();
+ }
- CATCH_REGISTER_LISTENER(gtk_test);
+ auto gtk_test::testCaseEnded(Catch::TestCaseStats const &) -> void
+ {
+ setlocale(LC_ALL, "");
+ }
-} // namespace turns::ui::tests \ No newline at end of file
+} // namespace Turns::Gui::tests \ No newline at end of file
diff --git a/gui/tests/gtk-test.hpp b/gui/tests/gtk-test.hpp
new file mode 100644
index 0000000..5ac6753
--- /dev/null
+++ b/gui/tests/gtk-test.hpp
@@ -0,0 +1,33 @@
+/*
+ * 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/participant_editor.cpp b/gui/tests/participant_editor.cpp
index 44b2ca4..3efa112 100644
--- a/gui/tests/participant_editor.cpp
+++ b/gui/tests/participant_editor.cpp
@@ -5,6 +5,7 @@
#include "participant_editor.hpp"
+#include "gtk-test.hpp"
#include "messages.hpp"
#include <turnsmm/participant.hpp>
@@ -14,6 +15,7 @@
#include <glib/gi18n.h>
+#include <adwaitamm/applicationwindow.hpp>
#include <adwaitamm/comborow.hpp>
#include <glibmm/i18n.h>
#include <glibmm/ustring.h>
@@ -34,6 +36,7 @@ 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))
@@ -43,6 +46,7 @@ namespace Turns::gui::tests
AND_GIVEN("a participant editor constructed without a participant")
{
auto instance = ParticipantEditor{nullptr};
+ instance.present(&window);
THEN("its title is message::add_participant")
{
@@ -129,16 +133,50 @@ namespace Turns::gui::tests
REQUIRE(instance.get_participant() == participant);
}
- AND_WHEN("a new name is set on the participant")
+ THEN("changing the participant's name also changes the name in the editor")
{
- participant->set_name("Changed Name");
+ auto new_value = "Changed Name";
+ participant->set_name(new_value);
+ REQUIRE(instance.get_name() == new_value);
+ }
- THEN("the editor's name is equal to the new name")
- {
- REQUIRE(instance.get_name() == "Changed Name");
- }
+ THEN("changing the participant's disposition also changes the disposition in the editor")
+ {
+ auto new_value = Participant::Disposition::Hostile;
+ participant->set_disposition(new_value);
+ REQUIRE(instance.get_disposition() == new_value);
+ }
+
+ THEN("changing the participant's priority also changes the priority in the editor")
+ {
+ auto new_value = -10.0f;
+ participant->set_priority(new_value);
+ REQUIRE(instance.get_priority() == new_value);
+ }
+
+ THEN("changing the name in the editor also changes the participant's name")
+ {
+ auto new_value = "Editor Changed Name";
+ instance.set_name(new_value);
+ REQUIRE(participant->get_name() == new_value);
+ }
+
+ THEN("changing the disposition in the editor also changes the participant's disposition")
+ {
+ auto new_value = Participant::Disposition::Secret;
+ instance.set_disposition(new_value);
+ REQUIRE(participant->get_disposition() == new_value);
+ }
+
+ THEN("changing the priority in the editor also changes the participant's priority")
+ {
+ auto new_value = 100.0f;
+ instance.set_priority(new_value);
+ REQUIRE(participant->get_priority() == new_value);
}
}
+
+ instance.close();
}
}
}
@@ -147,76 +185,8 @@ namespace Turns::gui::tests
// auto instance = std::make_shared<ParticipantEditor>(nullptr);
// auto window = Gtk::Window{};
- // WHEN("setting a new participant")
- // {
- // instance->set_participant(participant);
-
- // THEN("changes to the name propagate to the participant")
- // {
- // CHECK(participant->get_name() != "REPLACED");
- // instance->set_name("REPLACED");
- // REQUIRE(participant->get_name() == "REPLACED");
- // }
-
- // THEN("changes to the priority propagate to the participant")
- // {
- // CHECK(participant->get_priority() != 0);
- // instance->set_priority(0);
- // REQUIRE(participant->get_priority() == 0);
- // }
-
- // THEN("changes to the disposition propagate to the participant")
- // {
- // CHECK(participant->get_disposition() != core::Disposition::Secret);
- // instance->set_disposition(core::Disposition::Secret);
- // REQUIRE(participant->get_disposition() == core::Disposition::Secret);
- // }
- // }
-
// SECTION("allows binding to the finished signal")
// {
// REQUIRE((instance->signal_finished().connect([](auto, auto, auto) {})).connected());
// }
// }
-
- // TEST_CASE("A freshly constructed participant editor with a participant", "[windows]")
- // {
- // auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8");
- // setlocale(LC_ALL, locale);
-
- // auto participant = core::Participant::create("Qibi Babblebranch", 12, core::Disposition::Neutral);
- // auto instance = std::make_shared<ParticipantEditor>(participant);
- // auto window = Gtk::Window{};
-
- // SECTION("was successfully constructed")
- // {
- // REQUIRE(instance);
- // }
-
- // SECTION("has a non-empty title")
- // {
- // REQUIRE_FALSE(instance->get_title().empty());
- // }
-
- // SECTION("has its title set according to the active language")
- // {
- // REQUIRE(instance->get_title() == _(lang::edit_participant));
- // }
-
- // SECTION("has its name field set according to its participant")
- // {
- // REQUIRE(instance->get_name() == participant->property_name().get_value());
- // }
-
- // SECTION("has its priority field set according to its participant")
- // {
- // REQUIRE(instance->get_priority() == participant->property_priority());
- // }
-
- // SECTION("allows binding to the finished signal")
- // {
- // REQUIRE((instance->signal_finished().connect([](auto, auto, auto) {})).connected());
- // }
- // }
-
-} // namespace Turns::gui::tests \ No newline at end of file