summaryrefslogtreecommitdiff
path: root/core/tests
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2024-09-25 18:21:09 +0200
committerFelix Morgner <felix.morgner@gmail.com>2024-09-25 18:21:09 +0200
commit4c5d17bc8e6fceeb6fd9cc45c10f07b7bc639f49 (patch)
treebc70b691cae584464b214f11f3972423b3943565 /core/tests
parentcbbf1f1353eb55ee459d40f77b765adaf70df401 (diff)
downloadturns-4c5d17bc8e6fceeb6fd9cc45c10f07b7bc639f49.tar.xz
turns-4c5d17bc8e6fceeb6fd9cc45c10f07b7bc639f49.zip
core: add "is-" prefix to "::active" and "::defeated"
Diffstat (limited to 'core/tests')
-rw-r--r--core/tests/participant.cpp142
1 files changed, 139 insertions, 3 deletions
diff --git a/core/tests/participant.cpp b/core/tests/participant.cpp
index 6ca3f02..a526582 100644
--- a/core/tests/participant.cpp
+++ b/core/tests/participant.cpp
@@ -12,6 +12,142 @@
namespace turns::core::tests
{
+ TEST_CASE("Constructing a participant", "[core][construction]")
+ {
+ auto constexpr name = "Participant #1";
+ auto constexpr priority = 17;
+ auto constexpr disposition = disposition::friendly;
+
+ auto json = nlohmann::json::parse(R"(
+ {
+ "name": "Participant #1",
+ "priority": 17,
+ "disposition": 1,
+ "is-active": false,
+ "is-defeated": false
+ }
+ )");
+
+ SECTION("Can be constructed using default ctor")
+ {
+ auto instance = participant{};
+ REQUIRE(instance.name() == "");
+ REQUIRE(instance.priority() == 0);
+ REQUIRE(instance.disposition() == disposition::neutral);
+ REQUIRE(!instance.is_active());
+ REQUIRE(!instance.is_defeated());
+ }
+
+ SECTION("Can be constructed using ctor")
+ {
+ auto instance = participant{name, priority, disposition};
+ REQUIRE(instance.name() == name);
+ REQUIRE(instance.priority() == priority);
+ REQUIRE(instance.disposition() == disposition);
+ REQUIRE(!instance.is_active());
+ REQUIRE(!instance.is_defeated());
+ }
+
+ SECTION("Can be constructed using factory")
+ {
+ auto instance = participant::create(name, priority, disposition);
+ REQUIRE(instance->name() == name);
+ REQUIRE(instance->priority() == priority);
+ REQUIRE(instance->disposition() == disposition);
+ REQUIRE(!instance->is_active());
+ REQUIRE(!instance->is_defeated());
+ }
+
+ SECTION("Can be constructed using JSON factory", "[json]")
+ {
+ auto instance = participant::create(json);
+ REQUIRE(instance->name() == name);
+ REQUIRE(instance->priority() == priority);
+ REQUIRE(instance->disposition() == disposition);
+ REQUIRE(!instance->is_active());
+ REQUIRE(!instance->is_defeated());
+ }
+ }
+
+ TEST_CASE("Setting properties on participant", "[core][properties]")
+ {
+ auto constexpr name = "Participant #2";
+ auto constexpr priority = 10;
+ auto constexpr disposition = disposition::hostile;
+
+ auto instance = participant{name, priority, disposition};
+
+ SECTION("Setting '::disposition' via proxy changes the 'disposition' value")
+ {
+ auto old = instance.disposition().get_value();
+ instance.disposition() = static_cast<core::disposition>(static_cast<int>(disposition) - 1);
+ REQUIRE(instance.disposition() != old);
+ }
+
+ SECTION("Setting '::disposition' via glib changes the 'disposition' value")
+ {
+ auto old = instance.disposition().get_value();
+ instance.set_property("disposition", static_cast<core::disposition>(static_cast<int>(disposition) - 1));
+ REQUIRE(instance.disposition() != old);
+ }
+
+ SECTION("Setting '::is-active' via proxy changes the 'is_active' value")
+ {
+ auto old = instance.is_active().get_value();
+ instance.is_active() = !old;
+ REQUIRE(instance.is_active() != old);
+ }
+
+ SECTION("Setting '::is-active' via glib changes the 'is_active' value")
+ {
+ auto old = instance.is_active().get_value();
+ instance.set_property("is-active", !old);
+ REQUIRE(instance.is_active() != old);
+ }
+
+ SECTION("Setting '::is-defeated' via proxy changes the 'is_defeated' value")
+ {
+ auto old = instance.is_defeated().get_value();
+ instance.is_defeated() = !old;
+ REQUIRE(instance.is_defeated() != old);
+ }
+
+ SECTION("Setting '::is-defeated' via glib changes the 'is_defeated' value")
+ {
+ auto old = instance.is_defeated().get_value();
+ instance.set_property("is-defeated", !old);
+ REQUIRE(instance.is_defeated() != old);
+ }
+
+ SECTION("Setting '::name' via proxy changes the 'name' value")
+ {
+ auto old = instance.name().get_value();
+ instance.name() = old + " Changed";
+ REQUIRE(instance.name().get_value() != old);
+ }
+
+ SECTION("Setting '::name' via glib changes the 'name' value")
+ {
+ auto old = instance.name().get_value();
+ instance.set_property("name", old + " Changed");
+ REQUIRE(instance.name().get_value() != old);
+ }
+
+ SECTION("Setting '::priority' via proxy changes the 'priority' value")
+ {
+ auto old = instance.priority().get_value();
+ instance.priority() = old + 1;
+ REQUIRE(instance.priority() != old);
+ }
+
+ SECTION("Setting '::priority' via glib changes the 'priority' value")
+ {
+ auto old = instance.priority().get_value();
+ instance.set_property("priority", old + 1);
+ REQUIRE(instance.priority() != old);
+ }
+ }
+
TEST_CASE("A freshly constructed participant")
{
auto constexpr constructed_name = "Vana Thistletop";
@@ -117,9 +253,9 @@ namespace turns::core::tests
auto instance = participant::create("Participant #0", 17.2, disposition::friendly);
auto serialized = instance->serialize();
- SECTION("the active state is de-serialized correctly")
+ SECTION("the active state is serialized correctly")
{
- REQUIRE_FALSE(serialized.at("active"));
+ REQUIRE_FALSE(serialized.at("is-active"));
}
SECTION("the disposition is serialized correctly")
@@ -145,7 +281,7 @@ namespace turns::core::tests
"name": "Participant #1",
"priority": -2.3,
"disposition": 2,
- "active": true
+ "is-active": true
}
)");
auto instance = participant::create(serialized);