diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-05-23 12:26:50 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-05-23 12:26:50 +0200 |
| commit | d1d171775f768be1dcdee194be5134f334c63347 (patch) | |
| tree | 46e3ddc8d84c68d86293462f8d0c7eb8ffa85473 /lib/tests | |
| parent | 260df0a1158385736b2da24a2e4a14e365d1ec92 (diff) | |
| download | turns-d1d171775f768be1dcdee194be5134f334c63347.tar.xz turns-d1d171775f768be1dcdee194be5134f334c63347.zip | |
lib: add empty property to TurnOrder
Diffstat (limited to 'lib/tests')
| -rw-r--r-- | lib/tests/turns-turn-order.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/tests/turns-turn-order.cpp b/lib/tests/turns-turn-order.cpp index 2e11b52..0c1afcc 100644 --- a/lib/tests/turns-turn-order.cpp +++ b/lib/tests/turns-turn-order.cpp @@ -24,6 +24,13 @@ namespace { list_model_notification = std::tuple{position, removed, added}; } + + auto empty_notification = std::optional<bool>{}; + + auto on_empty_notification(TurnsTurnOrder const * instance, GParamSpec *, void *) -> void + { + empty_notification = turns_turn_order_get_empty(instance); + } } // namespace SCENARIO("Creating a turn order", "[lib][object][lifetime]") @@ -62,6 +69,16 @@ SCENARIO("Creating a turn order", "[lib][object][lifetime]") 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("it's empty") + { + REQUIRE(turns_turn_order_get_empty(instance)); + + auto property_value = decltype(turns_turn_order_get_empty(instance)){}; + g_object_get(instance, "empty", &property_value, nullptr); + + REQUIRE(property_value); + } } } @@ -73,10 +90,12 @@ SCENARIO("Modifying a turn order", "[lib][object][data]") CHECK(turns_turn_order_get_participant_count(instance) == 0); g_signal_connect(instance, "items-changed", reinterpret_cast<GCallback>(on_list_model_notification), nullptr); + g_signal_connect(instance, "notify::empty", reinterpret_cast<GCallback>(on_empty_notification), nullptr); WHEN("a participant is added") { g_autoptr(TurnsParticipant) participant = turns_participant_new_with("Test Participant", 10.0f, TURNS_PARTICIPANT_DISPOSITION_FRIENDLY); + empty_notification.reset(); turns_turn_order_add(instance, participant); THEN("its participant count is 1") @@ -103,9 +122,25 @@ SCENARIO("Modifying a turn order", "[lib][object][data]") REQUIRE(TURNS_PARTICIPANT(object) == participant); } + THEN("it's not empty") + { + REQUIRE_FALSE(turns_turn_order_get_empty(instance)); + + auto property_value = decltype(turns_turn_order_get_empty(instance)){}; + g_object_get(instance, "empty", &property_value, nullptr); + + REQUIRE_FALSE(property_value); + } + + THEN("the empty property is notified") + { + REQUIRE(empty_notification.has_value()); + } + AND_WHEN("calling clear") { list_model_notification.reset(); + empty_notification.reset(); turns_turn_order_clear(instance); THEN("its participant count is 0") @@ -142,11 +177,27 @@ SCENARIO("Modifying a turn order", "[lib][object][data]") REQUIRE(removed == 1); REQUIRE(added == 0); } + + THEN("it's empty") + { + REQUIRE(turns_turn_order_get_empty(instance)); + + auto property_value = decltype(turns_turn_order_get_empty(instance)){}; + g_object_get(instance, "empty", &property_value, nullptr); + + REQUIRE(property_value); + } + + THEN("the empty property is notified") + { + REQUIRE(empty_notification.has_value()); + } } AND_WHEN("removing the first element") { list_model_notification.reset(); + empty_notification.reset(); turns_turn_order_remove_at(instance, 0); THEN("its participant count is 0") @@ -168,9 +219,25 @@ SCENARIO("Modifying a turn order", "[lib][object][data]") REQUIRE(added == 0); } + THEN("it's empty") + { + REQUIRE(turns_turn_order_get_empty(instance)); + + auto property_value = decltype(turns_turn_order_get_empty(instance)){}; + g_object_get(instance, "empty", &property_value, nullptr); + + REQUIRE(property_value); + } + + THEN("the empty property is notified") + { + REQUIRE(empty_notification.has_value()); + } + AND_WHEN("removing the first element again") { list_model_notification.reset(); + empty_notification.reset(); turns_turn_order_remove_at(instance, 0); THEN("its participant count is 0") @@ -182,6 +249,21 @@ SCENARIO("Modifying a turn order", "[lib][object][data]") { REQUIRE(!list_model_notification.has_value()); } + + THEN("it's empty") + { + REQUIRE(turns_turn_order_get_empty(instance)); + + auto property_value = decltype(turns_turn_order_get_empty(instance)){}; + g_object_get(instance, "empty", &property_value, nullptr); + + REQUIRE(property_value); + } + + THEN("the empty property is not notified") + { + REQUIRE_FALSE(empty_notification.has_value()); + } } } } |
