diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-05-24 11:58:39 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-05-24 11:58:39 +0200 |
| commit | 72ab1fb4c1bf363f46470816d8b914a78ac493c4 (patch) | |
| tree | 27349a1bacbab4ea698be35d2d3d9b5184b15ca1 /gui/tests | |
| parent | b7f2ff4d991ae068f7834bf8e565f6261bf7fff1 (diff) | |
| download | turns-72ab1fb4c1bf363f46470816d8b914a78ac493c4.tar.xz turns-72ab1fb4c1bf363f46470816d8b914a78ac493c4.zip | |
gui: restructure file layout and apply licenses
Diffstat (limited to 'gui/tests')
| -rw-r--r-- | gui/tests/gtk_test_init.cpp | 46 | ||||
| -rw-r--r-- | gui/tests/intl_test_init.cpp | 31 | ||||
| -rw-r--r-- | gui/tests/messages.cpp | 77 | ||||
| -rw-r--r-- | gui/tests/participant_editor.cpp | 155 | ||||
| -rw-r--r-- | gui/tests/participant_row.cpp | 35 | ||||
| -rw-r--r-- | gui/tests/resources.cpp | 26 | ||||
| -rw-r--r-- | gui/tests/tracker.cpp | 84 |
7 files changed, 454 insertions, 0 deletions
diff --git a/gui/tests/gtk_test_init.cpp b/gui/tests/gtk_test_init.cpp new file mode 100644 index 0000000..fdefa74 --- /dev/null +++ b/gui/tests/gtk_test_init.cpp @@ -0,0 +1,46 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#include "turns/core/init.hpp" +#include "turns/ui/init.hpp" + +#include <catch2/reporters/catch_reporter_event_listener.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> + +#include <glibmm/i18n.h> + +#include <gtkmm/init.h> + +#include <adwaitamm/application.hpp> +#include <adwaitamm/wrap_init.hpp> + +#include <libintl.h> + +#include <clocale> + +namespace turns::ui::tests +{ + + struct gtk_test_init : Catch::EventListenerBase + { + 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"); + + [[maybe_unused]] auto app = Adwaita::Application::create("ch.arknet.turns.tests.ui"); + + core::register_types(); + ui::register_types(); + } + }; + + CATCH_REGISTER_LISTENER(gtk_test_init); + +} // namespace turns::ui::tests
\ No newline at end of file diff --git a/gui/tests/intl_test_init.cpp b/gui/tests/intl_test_init.cpp new file mode 100644 index 0000000..e7b7c0f --- /dev/null +++ b/gui/tests/intl_test_init.cpp @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#include <catch2/reporters/catch_reporter_event_listener.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> + +#include <libintl.h> + +#include <clocale> + +namespace turns::lang::tests +{ + + struct intl_test_init : Catch::EventListenerBase + { + 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"); + } + }; + + CATCH_REGISTER_LISTENER(intl_test_init); + +} // namespace turns::lang::tests
\ No newline at end of file diff --git a/gui/tests/messages.cpp b/gui/tests/messages.cpp new file mode 100644 index 0000000..6ff8936 --- /dev/null +++ b/gui/tests/messages.cpp @@ -0,0 +1,77 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#include "turns/lang/messages.hpp" + +#include <catch2/catch_test_macros.hpp> +#include <catch2/generators/catch_generators.hpp> + +#include <libintl.h> + +#include <clocale> +#include <format> +#include <string> + +namespace turns::lang::tests +{ + + TEST_CASE("Translated messages") + { + auto locale = GENERATE("de_CH.UTF-8", "de_DE.UTF-8", "de_AT.UTF-8"); + setlocale(LC_ALL, locale); + + SECTION(std::format("Locale '{}'", locale)) + { + auto message = GENERATE(add_participant, + cancel, + clear, + delete_participant, + disposition, + disposition_colors, + edit_participant, + end_turn_order, + finish, + flow, + friendly, + hostile, + main_menu, + mark_as_defeated, + // a better solution is required to test the following entry: + // name, + new_turn_order_file_name, + next_participant, + no_active_turn_order, + open, + preferences, + preferences_mnemonic, + previous_participant, + priority, + priority_number, + question_clear_turn_order, + quit, + reset, + save, + save_as, + saving_failed_format, + secret, + skip_defeated, + start_turn_order, + stop, + stop_and_clear, + stop_turn_order, + successfully_opened_format, + successfully_saved_format, + round_number, + turns, + turns_files); + + SECTION(std::format("has a translation for '{}'", message)) + { + REQUIRE(std::string{gettext(message)} != message); + } + } + } + +} // namespace turns::lang::tests
\ No newline at end of file diff --git a/gui/tests/participant_editor.cpp b/gui/tests/participant_editor.cpp new file mode 100644 index 0000000..b5ddb9f --- /dev/null +++ b/gui/tests/participant_editor.cpp @@ -0,0 +1,155 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#include "turns/ui/participant_editor.hpp" + +#include "turns/core/disposition.hpp" +#include "turns/core/participant.hpp" +#include "turns/lang/messages.hpp" + +#include <catch2/catch_test_macros.hpp> +#include <catch2/generators/catch_generators.hpp> + +#include <glibmm/i18n.h> +#include <glibmm/ustring.h> +#include <glibmm/wrap.h> + +#include <gtkmm/builder.h> +#include <gtkmm/listboxrow.h> +#include <gtkmm/window.h> + +#include <adwaitamm/entryrow.hpp> +#include <adwaitamm/spinrow.hpp> + +#include <gtk/gtk.h> + +#include <clocale> +#include <memory> + +namespace turns::ui::tests +{ + + TEST_CASE("A freshly constructed participant editor without a participant", "[windows]") + { + auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8"); + setlocale(LC_ALL, locale); + + auto participant = core::Participant::create("Frederick Thumblewackle", 7.2, core::Disposition::Friendly); + auto instance = std::make_shared<ParticipantEditor>(nullptr); + 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::add_participant)); + } + + SECTION("has an empty name") + { + REQUIRE(instance->get_name().empty()); + } + + SECTION("has a zero priority") + { + REQUIRE(instance->get_priority() == 0); + } + + SECTION("has neutral disposition") + { + REQUIRE(instance->get_disposition() == core::Disposition::Neutral); + } + + SECTION("has a null participant") + { + REQUIRE_FALSE(instance->get_participant()); + } + + WHEN("setting a new participant") + { + instance->set_participant(participant); + + THEN("getting the participant returns the new one") + { + REQUIRE(instance->get_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::ui::tests
\ No newline at end of file diff --git a/gui/tests/participant_row.cpp b/gui/tests/participant_row.cpp new file mode 100644 index 0000000..e32be78 --- /dev/null +++ b/gui/tests/participant_row.cpp @@ -0,0 +1,35 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#include "turns/ui/participant_row.hpp" + +#include "turns/core/disposition.hpp" +#include "turns/core/participant.hpp" + +#include <catch2/catch_test_macros.hpp> + +#include <glibmm/refptr.h> + +#include <gtkmm/object.h> + +#include <memory> + +namespace turns::ui::tests +{ + + TEST_CASE("A freshly constructed participant row") + { + SECTION("can be created without a participant") + { + REQUIRE(std::make_shared<ParticipantRow>(Glib::RefPtr<core::Participant>{})); + } + + SECTION("can be created with a participant") + { + REQUIRE(std::make_shared<ParticipantRow>(core::Participant::create("Tazmyla Fireforge", 13, core::Disposition::Secret))); + } + } + +} // namespace turns::ui::widgets::tests
\ No newline at end of file diff --git a/gui/tests/resources.cpp b/gui/tests/resources.cpp new file mode 100644 index 0000000..97a1a6b --- /dev/null +++ b/gui/tests/resources.cpp @@ -0,0 +1,26 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#include <catch2/catch_test_macros.hpp> +#include <catch2/generators/catch_generators.hpp> + +#include <giomm/resource.h> + +#include <format> + +TEST_CASE("UI resources") +{ + + auto file = GENERATE("/ch/arknet/Turns/participant_editor.ui", + "/ch/arknet/Turns/participant_row.ui", + "/ch/arknet/Turns/preferences.ui", + "/ch/arknet/Turns/tracker.ui", + "/ch/arknet/Turns/turn_order_view.ui"); + + SECTION(std::format("contains {}", file)) + { + REQUIRE(Gio::Resource::get_file_exists_global_nothrow(file)); + } +} diff --git a/gui/tests/tracker.cpp b/gui/tests/tracker.cpp new file mode 100644 index 0000000..3d0b5a0 --- /dev/null +++ b/gui/tests/tracker.cpp @@ -0,0 +1,84 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#include "turns/ui/tracker.hpp" + +#include "turns/core/settings.hpp" +#include "turns/lang/messages.hpp" + +#include <catch2/catch_test_macros.hpp> +#include <catch2/generators/catch_generators.hpp> + +#include <glibmm/i18n.h> +#include <glibmm/wrap.h> + +#include <gtkmm/builder.h> +#include <gtkmm/button.h> +#include <gtkmm/menubutton.h> +#include <gtkmm/widget.h> + +#include <adwaitamm/application.hpp> +#include <adwaitamm/windowtitle.hpp> + +#include <clocale> +#include <memory> + +namespace turns::ui::tests +{ + + TEST_CASE("A freshly constructed tracker window", "[windows]") + { + auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8"); + setlocale(LC_ALL, locale); + + auto app = Adwaita::Application::create("ch.arknet.Turns.test"); + auto instance = std::make_shared<Tracker>(app, core::get_settings()); + + SECTION("was successfully constructed") + { + REQUIRE(instance); + } + + // SECTION("has a non-empty subtitle") + // { + // auto widget = instance->get_ builder->get_widget<Adwaita::WindowTitle>("title"); + // REQUIRE_FALSE(widget->get_subtitle().empty()); + // } + + // SECTION("has its subtitle set according to the active language") + // { + // auto widget = builder->get_widget<Adwaita::WindowTitle>("title"); + // REQUIRE(widget->get_subtitle() == _(lang::no_active_turn_order)); + // } + + // SECTION("has a non-empty title") + // { + // auto widget = builder->get_widget<Adwaita::WindowTitle>("title"); + // REQUIRE_FALSE(widget->get_title().empty()); + // } + + // SECTION("has its title set according to the active language") + // { + // auto widget = builder->get_widget<Adwaita::WindowTitle>("title"); + // REQUIRE(widget->get_title() == _(lang::turns)); + // } + + // SECTION("has its add_participant button's tooltip set according to the active language") + // { + // auto widget = builder->get_widget<Gtk::Button>("add_participant"); + // REQUIRE(widget->get_tooltip_text() == _(lang::add_participant)); + // } + + // SECTION("as its open_main_menu button's tooltip set according to the active language") + // { + // auto widget = builder->get_widget<Gtk::MenuButton>("open_main_menu"); + // REQUIRE(widget->get_tooltip_text() == _(lang::main_menu)); + // } + + // instance->destroy(); + // delete instance; + } + +} // namespace turns::ui::tests
\ No newline at end of file |
