summaryrefslogtreecommitdiff
path: root/lib/tests
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2025-05-12 17:02:36 +0200
committerFelix Morgner <felix.morgner@gmail.com>2025-05-12 17:02:36 +0200
commit97c74a7c43bcc7e0551a967c6fa2720e9cb58efb (patch)
treec2ad9a76dbaf788bd8fdb41e5b18b75b7f7e3298 /lib/tests
parent2618066ba0b9e7c490797821dca4d19b48a09256 (diff)
downloadturns-97c74a7c43bcc7e0551a967c6fa2720e9cb58efb.tar.xz
turns-97c74a7c43bcc7e0551a967c6fa2720e9cb58efb.zip
lib: add active and defeated properties to Turns.Participant
Diffstat (limited to 'lib/tests')
-rw-r--r--lib/tests/turns-participant.cpp188
1 files changed, 187 insertions, 1 deletions
diff --git a/lib/tests/turns-participant.cpp b/lib/tests/turns-participant.cpp
index 89e60cf..1211e4b 100644
--- a/lib/tests/turns-participant.cpp
+++ b/lib/tests/turns-participant.cpp
@@ -41,6 +41,16 @@ SCENARIO("Creating a participant", "[lib][object][lifetime]")
{
REQUIRE(turns_participant_get_disposition(instance) == TURNS_DISPOSITION_NEUTRAL);
}
+
+ THEN("it's active state is false")
+ {
+ REQUIRE_FALSE(turns_participant_get_active(instance));
+ }
+
+ THEN("it's defeated state is false")
+ {
+ REQUIRE_FALSE(turns_participant_get_defeated(instance));
+ }
}
GIVEN("A participant constructed using turns_participant_new_with(...)")
@@ -64,6 +74,16 @@ SCENARIO("Creating a participant", "[lib][object][lifetime]")
{
REQUIRE(turns_participant_get_disposition(instance) == disposition);
}
+
+ THEN("it's active state is false")
+ {
+ REQUIRE_FALSE(turns_participant_get_active(instance));
+ }
+
+ THEN("it's defeated state is false")
+ {
+ REQUIRE_FALSE(turns_participant_get_defeated(instance));
+ }
}
GIVEN("A participant is constructed using turns_participant_new_with(nullptr, ...)")
@@ -83,7 +103,7 @@ SCENARIO("Modifying a participant", "[lib][object][data]")
{
g_autoptr(TurnsParticipant) instance = turns_participant_new();
- WHEN("a new new is set")
+ WHEN("a new name is set")
{
auto new_value = "Test Participant";
@@ -128,6 +148,32 @@ SCENARIO("Modifying a participant", "[lib][object][data]")
}
}
+ WHEN("a new active state is set")
+ {
+ auto new_value = true;
+
+ CHECK_FALSE(turns_participant_get_active(instance) == new_value);
+ turns_participant_set_active(instance, new_value);
+
+ THEN("it's active state has the new value")
+ {
+ REQUIRE(turns_participant_get_active(instance) == new_value);
+ }
+ }
+
+ WHEN("a new defeated state is set")
+ {
+ auto new_value = true;
+
+ CHECK_FALSE(turns_participant_get_defeated(instance) == new_value);
+ turns_participant_set_defeated(instance, new_value);
+
+ THEN("it's defeated state has the new value")
+ {
+ REQUIRE(turns_participant_get_defeated(instance) == new_value);
+ }
+ }
+
AND_GIVEN("a signal handler has been subscribed to the name property")
{
auto was_notified = false;
@@ -301,6 +347,122 @@ SCENARIO("Modifying a participant", "[lib][object][data]")
}
}
}
+
+ AND_GIVEN("a signal handler has been subscribed to the active property")
+ {
+ auto was_notified = false;
+ g_signal_connect(instance, "notify::active", G_CALLBACK(&record_notification), &was_notified);
+
+ WHEN("a new active is set using set_active")
+ {
+ auto new_value = true;
+
+ CHECK_FALSE(turns_participant_get_active(instance) == new_value);
+ turns_participant_set_active(instance, new_value);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same active is set using set_active")
+ {
+ auto new_value = turns_participant_get_active(instance);
+
+ CHECK(turns_participant_get_active(instance) == new_value);
+ turns_participant_set_active(instance, new_value);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+
+ WHEN("a new active is set using g_object_set")
+ {
+ auto new_value = true;
+
+ CHECK_FALSE(turns_participant_get_active(instance) == new_value);
+ g_object_set(G_OBJECT(instance), "active", new_value, nullptr);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same active is set using g_object_set")
+ {
+ auto new_value = turns_participant_get_active(instance);
+
+ CHECK(turns_participant_get_active(instance) == new_value);
+ g_object_set(G_OBJECT(instance), "active", new_value, nullptr);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+ }
+
+ AND_GIVEN("a signal handler has been subscribed to the defeated property")
+ {
+ auto was_notified = false;
+ g_signal_connect(instance, "notify::defeated", G_CALLBACK(&record_notification), &was_notified);
+
+ WHEN("a new defeated is set using set_defeated")
+ {
+ auto new_value = true;
+
+ CHECK_FALSE(turns_participant_get_defeated(instance) == new_value);
+ turns_participant_set_defeated(instance, new_value);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same defeated is set using set_defeated")
+ {
+ auto new_value = turns_participant_get_defeated(instance);
+
+ CHECK(turns_participant_get_defeated(instance) == new_value);
+ turns_participant_set_defeated(instance, new_value);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+
+ WHEN("a new defeated is set using g_object_set")
+ {
+ auto new_value = true;
+
+ CHECK_FALSE(turns_participant_get_defeated(instance) == new_value);
+ g_object_set(G_OBJECT(instance), "defeated", new_value, nullptr);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same defeated is set using g_object_set")
+ {
+ auto new_value = turns_participant_get_defeated(instance);
+
+ CHECK(turns_participant_get_defeated(instance) == new_value);
+ g_object_set(G_OBJECT(instance), "defeated", new_value, nullptr);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+ }
}
}
@@ -349,5 +511,29 @@ SCENARIO("Reading a participant", "[lib][object][data]")
REQUIRE(getter_value == property_value);
}
}
+
+ WHEN("reading the active state via get_active and g_object_get")
+ {
+ auto getter_value = turns_participant_get_active(instance);
+ auto property_value = decltype(turns_participant_get_active(instance)){};
+ g_object_get(instance, "active", &property_value, nullptr);
+
+ THEN("they both compare equal")
+ {
+ REQUIRE(getter_value == property_value);
+ }
+ }
+
+ WHEN("reading the defeated state via get_defeated and g_object_get")
+ {
+ auto getter_value = turns_participant_get_defeated(instance);
+ auto property_value = decltype(turns_participant_get_defeated(instance)){};
+ g_object_get(instance, "defeated", &property_value, nullptr);
+
+ THEN("they both compare equal")
+ {
+ REQUIRE(getter_value == property_value);
+ }
+ }
}
} \ No newline at end of file