diff options
Diffstat (limited to 'lib/tests/turns-turn-order.cpp')
| -rw-r--r-- | lib/tests/turns-turn-order.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/tests/turns-turn-order.cpp b/lib/tests/turns-turn-order.cpp index ab119e1..2e11b52 100644 --- a/lib/tests/turns-turn-order.cpp +++ b/lib/tests/turns-turn-order.cpp @@ -11,6 +11,20 @@ #include <gio/gio.h> #include <glib-object.h> +#include <glib.h> + +#include <optional> +#include <tuple> + +namespace +{ + auto list_model_notification = std::optional<std::tuple<guint, guint, guint>>{}; + + auto on_list_model_notification(GListModel *, guint position, guint removed, guint added, void *) -> void + { + list_model_notification = std::tuple{position, removed, added}; + } +} // namespace SCENARIO("Creating a turn order", "[lib][object][lifetime]") { @@ -58,6 +72,8 @@ SCENARIO("Modifying a turn order", "[lib][object][data]") g_autoptr(TurnsTurnOrder) instance = turns_turn_order_new(); CHECK(turns_turn_order_get_participant_count(instance) == 0); + g_signal_connect(instance, "items-changed", reinterpret_cast<GCallback>(on_list_model_notification), nullptr); + WHEN("a participant is added") { g_autoptr(TurnsParticipant) participant = turns_participant_new_with("Test Participant", 10.0f, TURNS_PARTICIPANT_DISPOSITION_FRIENDLY); @@ -89,6 +105,7 @@ SCENARIO("Modifying a turn order", "[lib][object][data]") AND_WHEN("calling clear") { + list_model_notification.reset(); turns_turn_order_clear(instance); THEN("its participant count is 0") @@ -111,6 +128,61 @@ SCENARIO("Modifying a turn order", "[lib][object][data]") REQUIRE(g_list_model_get_item(G_LIST_MODEL(instance), 0) == nullptr); REQUIRE(g_list_model_get_object(G_LIST_MODEL(instance), 0) == nullptr); } + + THEN("the items-changed notification is emitted") + { + REQUIRE(list_model_notification.has_value()); + } + + THEN("all items got deleted at position 0 and none were added") + { + auto [position, removed, added] = *list_model_notification; + + REQUIRE(position == 0); + REQUIRE(removed == 1); + REQUIRE(added == 0); + } + } + + AND_WHEN("removing the first element") + { + list_model_notification.reset(); + turns_turn_order_remove_at(instance, 0); + + THEN("its participant count is 0") + { + REQUIRE(turns_turn_order_get_participant_count(instance) == 0); + } + + THEN("the items-changed notification is emitted") + { + REQUIRE(list_model_notification.has_value()); + } + + THEN("1 item got deleted at position 0 and none were added") + { + auto [position, removed, added] = *list_model_notification; + + REQUIRE(position == 0); + REQUIRE(removed == 1); + REQUIRE(added == 0); + } + + AND_WHEN("removing the first element again") + { + list_model_notification.reset(); + turns_turn_order_remove_at(instance, 0); + + THEN("its participant count is 0") + { + REQUIRE(turns_turn_order_get_participant_count(instance) == 0); + } + + THEN("the items-changed notification is not emitted") + { + REQUIRE(!list_model_notification.has_value()); + } + } } } } |
