From 4c5d17bc8e6fceeb6fd9cc45c10f07b7bc639f49 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 25 Sep 2024 18:21:09 +0200 Subject: core: add "is-" prefix to "::active" and "::defeated" --- core/tests/participant.cpp | 142 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 3 deletions(-) (limited to 'core/tests') 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(static_cast(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(static_cast(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); -- cgit v1.2.3