From f50ec041a0f6fa036305ab5d5bdbdb9116b48024 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 8 Jun 2025 12:12:15 +0200 Subject: gui: add more ParticipantEditor editing tests --- gui/tests/gtk-test.cpp | 54 +++++++----------- gui/tests/gtk-test.hpp | 33 +++++++++++ gui/tests/participant_editor.cpp | 118 +++++++++++++++------------------------ 3 files changed, 98 insertions(+), 107 deletions(-) create mode 100644 gui/tests/gtk-test.hpp 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 -#include -#include - -#include -#include -#include -#include -#include +#include #include #include -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 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 + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#ifndef TURNS_GUI_TESTS_GTK_TEST_HPP +#define TURNS_GUI_TESTS_GTK_TEST_HPP + +#include +#include + +#include +#include + +namespace Turns::gui::tests +{ + + struct gtk_test : Catch::EventListenerBase + { + using Catch::EventListenerBase::EventListenerBase; + + static inline Glib::RefPtr 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 @@ -14,6 +15,7 @@ #include +#include #include #include #include @@ -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(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(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 -- cgit v1.2.3