From 08520af10c3ca74cc4ba1a528e60f877bcd714a5 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Tue, 29 Aug 2023 23:25:49 +0200 Subject: [PATCH] Extended t20034 test case with json generator test --- tests/t20034/test_case.h | 16 +++++++++++++++ tests/test_cases.h | 43 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/tests/t20034/test_case.h b/tests/t20034/test_case.h index 56c1a957..1363fca0 100644 --- a/tests/t20034/test_case.h +++ b/tests/t20034/test_case.h @@ -56,6 +56,22 @@ TEST_CASE("t20034", "[test-case][sequence]") using namespace json; + REQUIRE(HasMessageChain(j, + {{"D::d2()", "C::c3()", "void"}, {"C::c3()", "C::c2()", "void"}, + {"C::c2()", "B::b2()", "void"}, + {"B::b2()", "A::a2()", "void"}})); + REQUIRE(HasMessageChain(j, + {{"D::d2()", "C::c4()", "void"}, {"C::c4()", "B::b4()", "void"}, + {"B::b4()", "B::b2()", "void"}, + {"B::b2()", "A::a2()", "void"}})); + REQUIRE(HasMessageChain(j, {{"D::d2()", "A::a2()", "void"}})); + REQUIRE(HasMessageChain(j, + {{"D::d2()", "C::c1()", "void"}, {"C::c1()", "B::b1()", "void"}, + {"B::b1()", "A::a2()", "void"}})); + REQUIRE(HasMessageChain(j, + {{"D::d2()", "C::c2()", "void"}, {"C::c2()", "B::b2()", "void"}, + {"B::b2()", "A::a2()", "void"}})); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/test_cases.h b/tests/test_cases.h index df5c789d..980cde6f 100644 --- a/tests/test_cases.h +++ b/tests/test_cases.h @@ -1050,6 +1050,49 @@ int FindMessage(const nlohmann::json &j, const std::string &from, j, expand_name(j, from), expand_name(j, to), msg, return_type); } +struct message_test_spec_t { + std::string from; + std::string to; + std::optional return_type; + + bool operator==(const message_test_spec_t &r) const noexcept + { + return from == r.from && to == r.to && return_type == r.return_type; + } +}; + +void from_json(const nlohmann::json &j, message_test_spec_t &p) +{ + j.at("from").at("activity_name").get_to(p.from); + j.at("to").at("activity_name").get_to(p.to); + j.at("return_type").get_to(p.return_type); +} + +bool HasMessageChain( + const nlohmann::json &j, std::vector msgs) +{ + std::vector full_name_messages; + std::transform(msgs.begin(), msgs.end(), + std::back_inserter(full_name_messages), + [&j](const message_test_spec_t &m) { + auto res = m; + res.from = expand_name(j, m.from); + res.to = expand_name(j, m.to); + return res; + }); + + for (const auto &seq : j.at("sequences")) + for (const auto &mc : seq.at("message_chains")) { + auto mc_msgs = + mc.at("messages").get>(); + + if (full_name_messages == mc_msgs) + return true; + } + + return false; +} + } // namespace json } }