diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2024-07-25 14:39:16 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2024-07-25 14:39:16 +0200 |
| commit | 2b9ad3fbcbea86bd2cf702ff4c6e603c33492e45 (patch) | |
| tree | 762f3a71b3b7f212c7167e49d370cb297d33d45d /core/tests | |
| parent | 9ec62f964df0070cb13df4e1de3d52dc7f27189b (diff) | |
| download | turns-2b9ad3fbcbea86bd2cf702ff4c6e603c33492e45.tar.xz turns-2b9ad3fbcbea86bd2cf702ff4c6e603c33492e45.zip | |
core/participant: implement basic serialization
Diffstat (limited to 'core/tests')
| -rw-r--r-- | core/tests/participant.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/core/tests/participant.cpp b/core/tests/participant.cpp index 99e7fa4..6ca3f02 100644 --- a/core/tests/participant.cpp +++ b/core/tests/participant.cpp @@ -2,8 +2,11 @@ #include "turns/core/disposition.hpp" +#include <catch2/catch_approx.hpp> #include <catch2/catch_test_macros.hpp> +#include <nlohmann/json.hpp> + #include <compare> namespace turns::core::tests @@ -109,4 +112,63 @@ namespace turns::core::tests } } + TEST_CASE("Serializing a participant") + { + auto instance = participant::create("Participant #0", 17.2, disposition::friendly); + auto serialized = instance->serialize(); + + SECTION("the active state is de-serialized correctly") + { + REQUIRE_FALSE(serialized.at("active")); + } + + SECTION("the disposition is serialized correctly") + { + REQUIRE(serialized.at("disposition") == disposition::friendly); + } + + SECTION("the name is serialized correctly") + { + REQUIRE(serialized.at("name") == "Participant #0"); + } + + SECTION("the priority is serialized correctly") + { + REQUIRE(serialized.at("priority") == Catch::Approx{17.2}); + } + } + + TEST_CASE("De-Serializing a participant") + { + auto serialized = nlohmann::json::parse(R"( + { + "name": "Participant #1", + "priority": -2.3, + "disposition": 2, + "active": true + } + )"); + auto instance = participant::create(serialized); + + SECTION("the active state is de-serialized correctly") + { + REQUIRE(instance->is_active()); + } + + SECTION("the disposition is de-serialized correctly") + { + REQUIRE(instance->disposition() == disposition::hostile); + } + + SECTION("the name is de-serialized correctly") + { + REQUIRE(instance->name() == "Participant #1"); + } + + SECTION("the priority is de-serialized correctly") + { + REQUIRE(instance->priority() == Catch::Approx{-2.3}); + } + } + } // namespace turns::core::tests
\ No newline at end of file |
