summaryrefslogtreecommitdiff
path: root/lib/tests/turnsmm/participant.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tests/turnsmm/participant.cpp')
-rw-r--r--lib/tests/turnsmm/participant.cpp447
1 files changed, 447 insertions, 0 deletions
diff --git a/lib/tests/turnsmm/participant.cpp b/lib/tests/turnsmm/participant.cpp
new file mode 100644
index 0000000..d1e1762
--- /dev/null
+++ b/lib/tests/turnsmm/participant.cpp
@@ -0,0 +1,447 @@
+#include "turnsmm/participant.hpp"
+
+#include "turnsmm/enums.hpp"
+
+#include <catch2/catch_approx.hpp>
+#include <catch2/catch_test_macros.hpp>
+#include <catch2/generators/catch_generators.hpp>
+
+#include <glibmm/ustring.h>
+
+#include <glib-object.h>
+#include <glib.h>
+
+SCENARIO("Creating a participant", "[lib][object][lifetime]")
+{
+ GIVEN("A participant constructed using turns_participant_new()")
+ {
+ auto instance = Turns::Participant{};
+
+ THEN("it's name is empty")
+ {
+ REQUIRE(instance.get_name().empty());
+ }
+
+ THEN("it's priority is 0.0f")
+ {
+ REQUIRE(instance.get_priority() == Catch::Approx{0.0});
+ }
+
+ THEN("it's disposition is neutral")
+ {
+ REQUIRE(instance.get_disposition() == Turns::Disposition::Neutral);
+ }
+
+ THEN("it's active state is false")
+ {
+ REQUIRE_FALSE(instance.get_active());
+ }
+
+ THEN("it's defeated state is false")
+ {
+ REQUIRE_FALSE(instance.get_defeated());
+ }
+ }
+
+ GIVEN("A participant constructed using turns_participant_new_with(...)")
+ {
+ auto name = "Test Participant";
+ auto priority = 12.4f;
+ auto disposition = Turns::Disposition::Friendly;
+ auto instance = Turns::Participant(name, priority, disposition);
+
+ THEN("it's name is set")
+ {
+ REQUIRE(instance.get_name() == name);
+ }
+
+ THEN("it's priority is set")
+ {
+ REQUIRE(instance.get_priority() == Catch::Approx{priority});
+ }
+
+ THEN("it's disposition is")
+ {
+ REQUIRE(instance.get_disposition() == disposition);
+ }
+
+ THEN("it's active state is false")
+ {
+ REQUIRE_FALSE(instance.get_active());
+ }
+
+ THEN("it's defeated state is false")
+ {
+ REQUIRE_FALSE(instance.get_defeated());
+ }
+ }
+}
+
+SCENARIO("Modifying a participant", "[lib][object][data]")
+{
+ GIVEN("A default participant instance")
+ {
+ auto instance = Turns::Participant{};
+
+ WHEN("a new name is set")
+ {
+ auto new_value = "Test Participant";
+
+ CHECK(instance.get_name().empty());
+ CHECK_FALSE(instance.get_name() == new_value);
+ instance.set_name(new_value);
+
+ THEN("it's name is not empty")
+ {
+ REQUIRE_FALSE(instance.get_name().empty());
+ }
+
+ THEN("it's name has the new value")
+ {
+ REQUIRE(instance.get_name() == new_value);
+ }
+ }
+
+ WHEN("a new priority is set")
+ {
+ auto new_value = GENERATE(-8.0f, 12.0f, 4.0f);
+
+ CHECK_FALSE(instance.get_priority() == new_value);
+ instance.set_priority(new_value);
+
+ THEN("it's priority has the new value")
+ {
+ REQUIRE(instance.get_priority() == Catch::Approx{new_value});
+ }
+ }
+
+ WHEN("a new disposition is set")
+ {
+ auto new_value = GENERATE(Turns::Disposition::Friendly, Turns::Disposition::Hostile, Turns::Disposition::Secret);
+
+ CHECK_FALSE(instance.get_disposition() == new_value);
+ instance.set_disposition(new_value);
+
+ THEN("it's disposition has the new value")
+ {
+ REQUIRE(instance.get_disposition() == new_value);
+ }
+ }
+
+ WHEN("a new active state is set")
+ {
+ auto new_value = true;
+
+ CHECK_FALSE(instance.get_active() == new_value);
+ instance.set_active(new_value);
+
+ THEN("it's active state has the new value")
+ {
+ REQUIRE(instance.get_active() == new_value);
+ }
+ }
+
+ WHEN("a new defeated state is set")
+ {
+ auto new_value = true;
+
+ CHECK_FALSE(instance.get_defeated() == new_value);
+ instance.set_defeated(new_value);
+
+ THEN("it's defeated state has the new value")
+ {
+ REQUIRE(instance.get_defeated() == new_value);
+ }
+ }
+
+ AND_GIVEN("a signal handler has been subscribed to the name property")
+ {
+ auto was_notified = false;
+ instance.property_name().signal_changed().connect([&] { was_notified = true; });
+
+ WHEN("a new name is set using set_name")
+ {
+ auto new_value = "Test Participant";
+
+ CHECK_FALSE(instance.get_name() == new_value);
+ instance.set_name(new_value);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same name is set using set_name")
+ {
+ auto new_value = instance.get_name();
+
+ CHECK(instance.get_name() == new_value);
+ instance.set_name(new_value);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+
+ WHEN("a new name is set using Glib::Object::set_property")
+ {
+ auto new_value = "Test Participant";
+
+ CHECK_FALSE(instance.get_name() == new_value);
+ instance.set_property("name", Glib::ustring{new_value});
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same name is set using Glib::Object::set_property")
+ {
+ auto new_value = instance.get_name();
+
+ CHECK(instance.get_name() == new_value);
+ instance.set_property("name", new_value);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+ }
+
+ AND_GIVEN("a signal handler has been subscribed to the priority property")
+ {
+ auto was_notified = false;
+ instance.property_priority().signal_changed().connect([&] { was_notified = true; });
+
+ WHEN("a new priority is set using set_priority")
+ {
+ auto new_value = 8.4;
+
+ CHECK_FALSE(instance.get_priority() == new_value);
+ instance.set_priority(new_value);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same priority is set using set_priority")
+ {
+ auto new_value = instance.get_priority();
+
+ CHECK(instance.get_priority() == new_value);
+ instance.set_priority(new_value);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+
+ WHEN("a new priority is set using Glib::Object::set_property")
+ {
+ auto new_value = 8.4;
+
+ CHECK_FALSE(instance.get_priority() == new_value);
+ instance.set_property("priority", new_value);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same priority is set using Glib::Object::set_property")
+ {
+ auto new_value = instance.get_priority();
+
+ CHECK(instance.get_priority() == new_value);
+ instance.set_property("priority", new_value);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+ }
+
+ AND_GIVEN("a signal handler has been subscribed to the disposition property")
+ {
+ auto was_notified = false;
+ instance.property_disposition().signal_changed().connect([&] { was_notified = true; });
+
+ WHEN("a new disposition is set using set_disposition")
+ {
+ auto new_value = Turns::Disposition::Hostile;
+
+ CHECK_FALSE(instance.get_disposition() == new_value);
+ instance.set_disposition(new_value);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same disposition is set using set_disposition")
+ {
+ auto new_value = instance.get_disposition();
+
+ CHECK(instance.get_disposition() == new_value);
+ instance.set_disposition(new_value);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+
+ WHEN("a new disposition is set using Glib::Object::set_property")
+ {
+ auto new_value = Turns::Disposition::Secret;
+
+ CHECK_FALSE(instance.get_disposition() == new_value);
+ instance.set_property("disposition", new_value);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same disposition is set using Glib::Object::set_property")
+ {
+ auto new_value = instance.get_disposition();
+
+ CHECK(instance.get_disposition() == new_value);
+ instance.set_property("disposition", new_value);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+ }
+
+ AND_GIVEN("a signal handler has been subscribed to the active property")
+ {
+ auto was_notified = false;
+ instance.property_active().signal_changed().connect([&] { was_notified = true; });
+
+ WHEN("a new active state is set using set_active")
+ {
+ auto new_value = true;
+
+ CHECK_FALSE(instance.get_active() == new_value);
+ instance.set_active(new_value);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same active state is set using set_active")
+ {
+ auto new_value = instance.get_active();
+
+ CHECK(instance.get_active() == new_value);
+ instance.set_active(new_value);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+
+ WHEN("a new active state is set using Glib::Object::set_property")
+ {
+ auto new_value = true;
+
+ CHECK_FALSE(instance.get_active() == new_value);
+ instance.set_property("active", new_value);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same active state is set using Glib::Object::set_property")
+ {
+ auto new_value = instance.get_active();
+
+ CHECK(instance.get_active() == new_value);
+ instance.set_property("active", new_value);
+
+ 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;
+ instance.property_defeated().signal_changed().connect([&] { was_notified = true; });
+
+ WHEN("a new defeated state is set using set_defeated")
+ {
+ auto new_value = true;
+
+ CHECK_FALSE(instance.get_defeated() == new_value);
+ instance.set_defeated(new_value);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same defeated state is set using set_defeated")
+ {
+ auto new_value = instance.get_defeated();
+
+ CHECK(instance.get_defeated() == new_value);
+ instance.set_defeated(new_value);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+
+ WHEN("a new defeated state is set using Glib::Object::set_property")
+ {
+ auto new_value = true;
+
+ CHECK_FALSE(instance.get_defeated() == new_value);
+ instance.set_property("defeated", new_value);
+
+ THEN("a notification is issued")
+ {
+ REQUIRE(was_notified);
+ }
+ }
+
+ WHEN("the same defeated state is set using Glib::Object::set_property")
+ {
+ auto new_value = instance.get_defeated();
+
+ CHECK(instance.get_defeated() == new_value);
+ instance.set_property("defeated", new_value);
+
+ THEN("no notification is issued")
+ {
+ REQUIRE_FALSE(was_notified);
+ }
+ }
+ }
+ }
+}