From 43b81f97ce03d13c2cdd58a49a6dc90c93797af2 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Sat, 25 Mar 2023 01:25:27 +0100 Subject: [PATCH] Added JSON test cases for all sequence diagram test cases --- .../json/sequence_diagram_generator.cc | 90 +++++++++++++------ .../json/sequence_diagram_generator.h | 2 + tests/t20005/test_case.h | 5 ++ tests/t20006/test_case.h | 11 +++ tests/t20007/test_case.h | 10 +++ tests/t20008/test_case.h | 12 +++ tests/t20009/test_case.h | 11 +++ tests/t20010/test_case.h | 12 +++ tests/t20012/test_case.h | 32 +++++++ tests/t20013/test_case.h | 10 +++ tests/t20014/test_case.h | 11 +++ tests/t20015/test_case.h | 5 ++ tests/t20016/test_case.h | 8 ++ tests/t20017/test_case.h | 14 +++ tests/t20018/test_case.h | 13 +++ tests/t20019/test_case.h | 8 ++ tests/t20020/test_case.h | 14 +++ tests/t20021/test_case.h | 17 ++++ tests/t20022/test_case.h | 5 ++ tests/t20023/test_case.h | 6 ++ tests/t20024/test_case.h | 7 ++ tests/t20025/test_case.h | 6 ++ tests/t20026/test_case.h | 4 + tests/t20027/test_case.h | 4 + tests/t20028/test_case.h | 7 ++ tests/t20029/test_case.h | 14 +++ tests/test_cases.h | 39 +++++++- 27 files changed, 345 insertions(+), 32 deletions(-) diff --git a/src/sequence_diagram/generators/json/sequence_diagram_generator.cc b/src/sequence_diagram/generators/json/sequence_diagram_generator.cc index 7bd8ef3d..9cf9b287 100644 --- a/src/sequence_diagram/generators/json/sequence_diagram_generator.cc +++ b/src/sequence_diagram/generators/json/sequence_diagram_generator.cc @@ -18,12 +18,23 @@ #include "sequence_diagram_generator.h" +namespace clanguml::sequence_diagram::generators::json { + +std::string render_name(std::string name) +{ + util::replace_all(name, "##", "::"); + + return name; +} + +} // namespace clanguml::sequence_diagram::generators::json + namespace clanguml::sequence_diagram::model { -using nlohmann::json; +// using nlohmann::json; void to_json(nlohmann::json &j, const participant &c) { - j["name"] = c.full_name(false); + j["name"] = generators::json::render_name(c.full_name(false)); j["id"] = std::to_string(c.id()); j["type"] = c.type_name(); if (!c.file().empty()) @@ -95,7 +106,8 @@ void generator::generate_call(const message &m, nlohmann::json &parent) const msg["name"] = message; msg["type"] = "message"; - msg["from"]["activity_name"] = from.value().full_name(false); + msg["from"]["activity_name"] = + generators::json::render_name(from.value().full_name(false)); msg["from"]["activity_id"] = std::to_string(from.value().id()); msg["to"]["activity_id"] = std::to_string(to.value().id()); msg["to"]["activity_name"] = to.value().full_name(false); @@ -106,10 +118,10 @@ void generator::generate_call(const message &m, nlohmann::json &parent) const msg["from"]["participant_id"] = std::to_string(class_participant.class_id()); - msg["from"]["participant_name"] = + msg["from"]["participant_name"] = generators::json::render_name( m_model.get_participant(class_participant.class_id()) .value() - .full_name(false); + .full_name(false)); } else if (from.value().type_name() == "function" || from.value().type_name() == "function_template") { @@ -118,14 +130,22 @@ void generator::generate_call(const message &m, nlohmann::json &parent) const m_model.get_participant(from.value().id()) .value(); msg["from"]["participant_id"] = - std::to_string(common::to_id(file_participant.file())); - msg["from"]["participant_name"] = file_participant.file_relative(); + std::to_string(common::to_id(file_participant.file_relative())); + msg["from"]["participant_name"] = util::path_to_url( + std::filesystem::relative(file_participant.file(), + std::filesystem::canonical(m_config.relative_to()) + .string())); } else { msg["from"]["participant_id"] = std::to_string(from.value().id()); msg["from"]["participant_name"] = from.value().full_name(false); } } + else if (from.value().type_name() == "lambda") { + msg["from"]["participant_id"] = std::to_string(from.value().id()); + msg["from"]["participant_name"] = + generators::json::render_name(from.value().full_name(false)); + } if (to.value().type_name() == "method") { const auto &class_participant = @@ -145,14 +165,22 @@ void generator::generate_call(const message &m, nlohmann::json &parent) const m_model.get_participant(to.value().id()) .value(); msg["to"]["participant_id"] = - std::to_string(common::to_id(file_participant.file())); - msg["to"]["participant_name"] = file_participant.file_relative(); + std::to_string(common::to_id(file_participant.file_relative())); + msg["to"]["participant_name"] = util::path_to_url( + std::filesystem::relative(file_participant.file(), + std::filesystem::canonical(m_config.relative_to()) + .string())); } else { msg["to"]["participant_id"] = std::to_string(to.value().id()); msg["to"]["participant_name"] = to.value().full_name(false); } } + else if (to.value().type_name() == "lambda") { + msg["to"]["participant_id"] = std::to_string(to.value().id()); + msg["to"]["participant_name"] = + generators::json::render_name(to.value().full_name(false)); + } msg["source_location"] = dynamic_cast(m); @@ -339,10 +367,10 @@ void generator::process_try_message(const message &m) const nlohmann::json branch; branch["type"] = "main"; - current_block_statement()["blocks"].push_back(std::move(branch)); + current_block_statement()["branches"].push_back(std::move(branch)); block_statements_stack_.push_back( - std::ref(current_block_statement()["blocks"].back())); + std::ref(current_block_statement()["branches"].back())); } void generator::process_catch_message() const @@ -352,10 +380,10 @@ void generator::process_catch_message() const nlohmann::json branch; branch["type"] = "catch"; - current_block_statement()["blocks"].push_back(std::move(branch)); + current_block_statement()["branches"].push_back(std::move(branch)); block_statements_stack_.push_back( - std::ref(current_block_statement()["blocks"].back())); + std::ref(current_block_statement()["branches"].back())); } void generator::process_end_try_message() const @@ -388,10 +416,10 @@ void generator::process_case_message(const message &m) const nlohmann::json case_block; case_block["type"] = "case"; case_block["name"] = m.message_name(); - current_block_statement()["cases"].push_back(std::move(case_block)); + current_block_statement()["branches"].push_back(std::move(case_block)); block_statements_stack_.push_back( - std::ref(current_block_statement()["cases"].back())); + std::ref(current_block_statement()["branches"].back())); } void generator::process_end_switch_message() const @@ -526,20 +554,17 @@ common::id_t generator::generate_participant( m_model.get_participant(participant_id).value(); if (participant.type_name() == "method") { - const auto class_id = - m_model.get_participant(participant_id) - .value() - .class_id(); + participant_id = m_model.get_participant(participant_id) + .value() + .class_id(); - if (is_participant_generated(class_id)) + if (is_participant_generated(participant_id)) return participant_id; const auto &class_participant = - m_model.get_participant(class_id).value(); + m_model.get_participant(participant_id).value(); parent["participants"].push_back(class_participant); - - generated_participants_.emplace(class_id); } else if ((participant.type_name() == "function" || participant.type_name() == "function_template") && @@ -549,17 +574,26 @@ common::id_t generator::generate_participant( const auto &function_participant = m_model.get_participant(participant_id).value(); - parent["participants"].push_back(function_participant); + nlohmann::json j = function_participant; + j["name"] = util::path_to_url( + std::filesystem::relative(function_participant.file(), + std::filesystem::canonical(m_config.relative_to()).string())); - generated_participants_.emplace( - common::to_id(function_participant.file())); + participant_id = common::to_id(function_participant.file_relative()); + + if (is_participant_generated(participant_id)) + return participant_id; + + j["id"] = std::to_string(participant_id); + + parent["participants"].push_back(j); } else { parent["participants"].push_back(participant); - - generated_participants_.emplace(participant_id); } + generated_participants_.emplace(participant_id); + return participant_id; } diff --git a/src/sequence_diagram/generators/json/sequence_diagram_generator.h b/src/sequence_diagram/generators/json/sequence_diagram_generator.h index 5bff18da..84e3a28a 100644 --- a/src/sequence_diagram/generators/json/sequence_diagram_generator.h +++ b/src/sequence_diagram/generators/json/sequence_diagram_generator.h @@ -32,6 +32,8 @@ namespace clanguml::sequence_diagram::generators::json { +std::string render_name(std::string name); + using diagram_config = clanguml::config::sequence_diagram; using diagram_model = clanguml::sequence_diagram::model::diagram; diff --git a/tests/t20005/test_case.h b/tests/t20005/test_case.h index 5be8dd0e..79172e7c 100644 --- a/tests/t20005/test_case.h +++ b/tests/t20005/test_case.h @@ -50,6 +50,11 @@ TEST_CASE("t20005", "[test-case][sequence]") using namespace json; + std::vector messages = {FindMessage(j, "C", "B", "b(T)"), + FindMessage(j, "B", "A", "a(T)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20006/test_case.h b/tests/t20006/test_case.h index 025ab90e..c24b3e30 100644 --- a/tests/t20006/test_case.h +++ b/tests/t20006/test_case.h @@ -83,6 +83,17 @@ TEST_CASE("t20006", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", "B", "b(int)"), + FindMessage(j, "B", "A", "a1(int)"), + FindMessage(j, "tmain()", "B", "b(std::string)"), + FindMessage(j, "tmain()", "BB", "bb1(int,int)"), + FindMessage(j, "BB", "AA", "aa1(int)"), + FindMessage( + j, "tmain()", "BB", "bb1(int,std::string)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20007/test_case.h b/tests/t20007/test_case.h index 8aab5141..85b679c3 100644 --- a/tests/t20007/test_case.h +++ b/tests/t20007/test_case.h @@ -54,6 +54,16 @@ TEST_CASE("t20007", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", "Adder", "add(int &&,int &&)"), + FindMessage(j, "tmain()", "Adder", + "add(int &&,float &&,double &&)"), + FindMessage(j, "tmain()", + "Adder", + "add(std::string &&,std::string &&,std::string &&)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20008/test_case.h b/tests/t20008/test_case.h index 3947bb8d..5bff7031 100644 --- a/tests/t20008/test_case.h +++ b/tests/t20008/test_case.h @@ -62,6 +62,18 @@ TEST_CASE("t20008", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", "B", "b(int)"), + FindMessage(j, "B", "A", "a1(int)"), + FindMessage(j, "tmain()", "B", "b(const char *)"), + FindMessage( + j, "B", "A", "a2(const char *)"), + FindMessage(j, "tmain()", "B", "b(std::string)"), + FindMessage( + j, "B", "A", "a3(std::string)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20009/test_case.h b/tests/t20009/test_case.h index 6a9ee4b8..1daf7379 100644 --- a/tests/t20009/test_case.h +++ b/tests/t20009/test_case.h @@ -55,6 +55,17 @@ TEST_CASE("t20009", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", "B", "b(std::string)"), + FindMessage( + j, "B", "A", "a(std::string)"), + FindMessage(j, "tmain()", "B", "b(int)"), + FindMessage(j, "B", "A", "a(int)"), + FindMessage(j, "tmain()", "B", "b(float)"), + FindMessage(j, "B", "A", "a(float)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20010/test_case.h b/tests/t20010/test_case.h index 96c6d6e7..4be8a01c 100644 --- a/tests/t20010/test_case.h +++ b/tests/t20010/test_case.h @@ -56,6 +56,18 @@ TEST_CASE("t20010", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", "B", "b1()"), + FindMessage(j, "B", "A", "a1()"), + FindMessage(j, "tmain()", "B", "b2()"), + FindMessage(j, "B", "A", "a2()"), + FindMessage(j, "tmain()", "B", "b3()"), + FindMessage(j, "B", "A", "a3()"), + FindMessage(j, "tmain()", "B", "b4()"), + FindMessage(j, "B", "A", "a4()")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20012/test_case.h b/tests/t20012/test_case.h index a310ee52..374d9a6d 100644 --- a/tests/t20012/test_case.h +++ b/tests/t20012/test_case.h @@ -85,6 +85,38 @@ TEST_CASE("t20012", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", + "tmain()::(lambda ../../tests/t20012/t20012.cc:66:20)", + "operator()()"), + FindMessage(j, + "tmain()::(lambda ../../tests/t20012/t20012.cc:66:20)", "A", + "a()"), + FindMessage(j, "A", "A", "aa()"), FindMessage(j, "A", "A", "aaa()"), + FindMessage(j, + "tmain()::(lambda ../../tests/t20012/t20012.cc:66:20)", "B", + "b()"), + FindMessage(j, "B", "B", "bb()"), FindMessage(j, "B", "B", "bbb()"), + FindMessage(j, + "tmain()::(lambda ../../tests/t20012/t20012.cc:79:20)", "C", + "c()"), + FindMessage(j, "C", "C", "cc()"), FindMessage(j, "C", "C", "ccc()"), + FindMessage(j, + "tmain()::(lambda ../../tests/t20012/t20012.cc:79:20)", + "tmain()::(lambda ../../tests/t20012/t20012.cc:66:20)", + "operator()()"), + FindMessage(j, "tmain()", + "R", "r()"), + FindMessage(j, "R", + "tmain()::(lambda ../../tests/t20012/t20012.cc:85:9)", + "operator()()"), + FindMessage(j, + "tmain()::(lambda ../../tests/t20012/t20012.cc:85:9)", "C", + "c()"), + FindMessage(j, "tmain()", "D", "add5(int)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20013/test_case.h b/tests/t20013/test_case.h index 10bab9f9..dc005e7a 100644 --- a/tests/t20013/test_case.h +++ b/tests/t20013/test_case.h @@ -56,6 +56,16 @@ TEST_CASE("t20013", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain(int,char **)", "B", "b(int)"), + FindMessage(j, "B", "A", "a1(int)"), + FindMessage(j, "tmain(int,char **)", "B", "b(double)"), + FindMessage(j, "B", "A", "a2(double)"), + FindMessage(j, "tmain(int,char **)", "B", "b(const char *)"), + FindMessage(j, "B", "A", "a3(const char *)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20014/test_case.h b/tests/t20014/test_case.h index a7d615c2..91f6d7de 100644 --- a/tests/t20014/test_case.h +++ b/tests/t20014/test_case.h @@ -54,6 +54,17 @@ TEST_CASE("t20014", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", "B", "b1(int,int)"), + FindMessage(j, "B", "A", "a1(int,int)"), + FindMessage(j, "tmain()", "B", "b2(int,int)"), + FindMessage(j, "B", "A", "a2(int,int)"), + FindMessage( + j, "tmain()", "C", "c1(int,int)"), + FindMessage(j, "C", "B", "b1(int,int)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20015/test_case.h b/tests/t20015/test_case.h index 4bf33db1..29116c7a 100644 --- a/tests/t20015/test_case.h +++ b/tests/t20015/test_case.h @@ -55,6 +55,11 @@ TEST_CASE("t20015", "[test-case][sequence]") using namespace json; + std::vector messages = {FindMessage( + j, "tmain()", "B", "setup_a(std::shared_ptr &)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20016/test_case.h b/tests/t20016/test_case.h index ce77d5f7..4bc099f3 100644 --- a/tests/t20016/test_case.h +++ b/tests/t20016/test_case.h @@ -50,6 +50,14 @@ TEST_CASE("t20016", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", "B", "b1(long)"), + FindMessage(j, "B", "A", "a1(int)"), + FindMessage(j, "tmain()", "B", "b2(long)"), + FindMessage(j, "B", "A", "a2(const long &)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20017/test_case.h b/tests/t20017/test_case.h index 8496d5d5..fe94fd45 100644 --- a/tests/t20017/test_case.h +++ b/tests/t20017/test_case.h @@ -58,6 +58,20 @@ TEST_CASE("t20017", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, File("t20017.cc"), File("include/t20017_a.h"), + "a3(int,int)"), + FindMessage(j, File("t20017.cc"), File("include/t20017_b.h"), + "b1(int,int)"), + FindMessage(j, File("t20017.cc"), File("include/t20017_a.h"), + "a2(int,int)"), + FindMessage(j, File("t20017.cc"), File("include/t20017_a.h"), + "a1(int,int)"), + FindMessage(j, File("t20017.cc"), File("include/t20017_b.h"), + "b2(int,int)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20018/test_case.h b/tests/t20018/test_case.h index dea3b7b4..fb11d96d 100644 --- a/tests/t20018/test_case.h +++ b/tests/t20018/test_case.h @@ -62,6 +62,19 @@ TEST_CASE("t20018", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", + "Answer,120>", "print()"), + FindMessage(j, "Answer,120>", + "Factorial<5>", "print(int)"), + FindMessage(j, "Factorial<5>", "Factorial<4>", "print(int)"), + FindMessage(j, "Factorial<4>", "Factorial<3>", "print(int)"), + FindMessage(j, "Factorial<3>", "Factorial<2>", "print(int)"), + FindMessage(j, "Factorial<2>", "Factorial<1>", "print(int)"), + FindMessage(j, "Factorial<1>", "Factorial<0>", "print(int)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20019/test_case.h b/tests/t20019/test_case.h index ca664115..e9394fc0 100644 --- a/tests/t20019/test_case.h +++ b/tests/t20019/test_case.h @@ -50,6 +50,14 @@ TEST_CASE("t20019", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", "Base", "name()"), + FindMessage(j, "Base", "D1", "impl()"), + FindMessage(j, "tmain()", "Base", "name()"), + FindMessage(j, "Base", "D2", "impl()")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20020/test_case.h b/tests/t20020/test_case.h index 1b59a799..32d66d95 100644 --- a/tests/t20020/test_case.h +++ b/tests/t20020/test_case.h @@ -59,6 +59,20 @@ TEST_CASE("t20020", "[test-case][sequence]") using namespace json; + std::vector messages = {FindMessage(j, "tmain()", "A", "a1()"), + FindMessage(j, "tmain()", "A", "a2()"), + FindMessage(j, "tmain()", "C", "c3(int)"), + FindMessage(j, "tmain()", "B", "b1()"), + FindMessage(j, "tmain()", "A", "a3()"), + FindMessage(j, "tmain()", "B", "b2()"), + FindMessage(j, "tmain()", "A", "a4()"), + FindMessage(j, "tmain()", "B", "log()"), + FindMessage(j, "tmain()", "C", "c1()"), + FindMessage(j, "C", "C", "c2()"), FindMessage(j, "C", "C", "log()"), + FindMessage(j, "tmain()", "D", "d1(int,int)")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20021/test_case.h b/tests/t20021/test_case.h index 2df05841..789426c7 100644 --- a/tests/t20021/test_case.h +++ b/tests/t20021/test_case.h @@ -67,6 +67,23 @@ TEST_CASE("t20021", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", "C", "c4()"), + FindMessage(j, "C", "C", "c5()"), + FindMessage(j, "tmain()", "A", "a3()"), + FindMessage(j, "tmain()", "A", "a2()"), + FindMessage(j, "tmain()", "C", "c1()"), + FindMessage(j, "tmain()", "C", "c2()"), + FindMessage(j, "tmain()", "A", "a1()"), + FindMessage(j, "tmain()", "C", "c3()"), + FindMessage(j, "tmain()", "B", "b2()"), + FindMessage(j, "tmain()", "C", "contents()") + // TODO: Repeated messge gets wrong index + // FindMessage(j, "tmain()", "B", "b2()") + }; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20022/test_case.h b/tests/t20022/test_case.h index e4fda9e7..2c462ae2 100644 --- a/tests/t20022/test_case.h +++ b/tests/t20022/test_case.h @@ -47,6 +47,11 @@ TEST_CASE("t20022", "[test-case][sequence]") using namespace json; + std::vector messages = {FindMessage(j, "tmain()", "A", "a()"), + FindMessage(j, "A", "B", "b()")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20023/test_case.h b/tests/t20023/test_case.h index 34ea65bc..d1b23027 100644 --- a/tests/t20023/test_case.h +++ b/tests/t20023/test_case.h @@ -50,6 +50,12 @@ TEST_CASE("t20023", "[test-case][sequence]") using namespace json; + std::vector messages = {FindMessage(j, "tmain()", "A", "a()"), + FindMessage(j, "A", "A", "a1()"), FindMessage(j, "A", "A", "a2()"), + FindMessage(j, "A", "A", "a3()"), FindMessage(j, "A", "A", "a4()")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20024/test_case.h b/tests/t20024/test_case.h index 34cd2179..84551392 100644 --- a/tests/t20024/test_case.h +++ b/tests/t20024/test_case.h @@ -55,6 +55,13 @@ TEST_CASE("t20024", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", "A", "select(enum_a)"), + FindMessage(j, "A", "A", "a0()"), FindMessage(j, "A", "A", "a1()"), + FindMessage(j, "A", "A", "a2()"), FindMessage(j, "A", "A", "a3()")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20025/test_case.h b/tests/t20025/test_case.h index 5305628f..a309e768 100644 --- a/tests/t20025/test_case.h +++ b/tests/t20025/test_case.h @@ -50,6 +50,12 @@ TEST_CASE("t20025", "[test-case][sequence]") using namespace json; + std::vector messages = {FindMessage(j, "tmain()", "A", "a()"), + // FindMessage(j, "tmain()", "A", "a2()"), + FindMessage(j, "tmain()", "add(int,int)", "")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20026/test_case.h b/tests/t20026/test_case.h index 2542b16d..93949707 100644 --- a/tests/t20026/test_case.h +++ b/tests/t20026/test_case.h @@ -46,6 +46,10 @@ TEST_CASE("t20026", "[test-case][sequence]") using namespace json; + std::vector messages = {FindMessage(j, "tmain()", "A", "a()")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20027/test_case.h b/tests/t20027/test_case.h index 5246bbb1..fca26ac9 100644 --- a/tests/t20027/test_case.h +++ b/tests/t20027/test_case.h @@ -48,6 +48,10 @@ TEST_CASE("t20027", "[test-case][sequence]") using namespace json; + std::vector messages = {FindMessage(j, "tmain()", "A", "a()")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20028/test_case.h b/tests/t20028/test_case.h index be2c23de..f039da7e 100644 --- a/tests/t20028/test_case.h +++ b/tests/t20028/test_case.h @@ -50,6 +50,13 @@ TEST_CASE("t20028", "[test-case][sequence]") using namespace json; + std::vector messages = {FindMessage(j, "tmain()", "A", "a()"), + FindMessage(j, "tmain()", "A", "b()"), + FindMessage(j, "tmain()", "A", "c()"), + FindMessage(j, "tmain()", "A", "d()")}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } } \ No newline at end of file diff --git a/tests/t20029/test_case.h b/tests/t20029/test_case.h index 78488db0..7a0c6ac7 100644 --- a/tests/t20029/test_case.h +++ b/tests/t20029/test_case.h @@ -68,6 +68,20 @@ TEST_CASE("t20029", "[test-case][sequence]") using namespace json; + std::vector messages = { + FindMessage(j, "tmain()", "ConnectionPool", "connect()"), + FindMessage(j, "tmain()", + "Encoder>", + "send(std::string &&)")/*, + FindMessage(j, + "Encoder>", + "encode_b64(std::string &&)", "encode_b64(std::string &&)"), + FindMessage(j, "Retrier", + "ConnectionPool", "send(const std::string &)")*/}; + + REQUIRE(std::is_sorted(messages.begin(), messages.end())); + 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 621774db..4503c79c 100644 --- a/tests/test_cases.h +++ b/tests/test_cases.h @@ -881,6 +881,13 @@ int find_message_nested(const nlohmann::json &j, const std::string &from, return nested_res; } } + else if (m.contains("messages")) { + auto nested_res = + find_message_nested(m, from, to, msg, from_p, to_p, count); + + if (nested_res >= 0) + return nested_res; + } else { if ((m["from"]["participant_id"] == from_p["id"]) && (m["to"]["participant_id"] == to_p["id"]) && (m["name"] == msg)) @@ -892,13 +899,13 @@ int find_message_nested(const nlohmann::json &j, const std::string &from, return res; } -} // namespace detail -int FindMessage(const nlohmann::json &j, const std::string &from, +int find_message_impl(const nlohmann::json &j, const std::string &from, const std::string &to, const std::string &msg) { - auto from_p = get_participant(j, expand_name(j, from)); - auto to_p = get_participant(j, expand_name(j, to)); + + auto from_p = get_participant(j, from); + auto to_p = get_participant(j, to); // TODO: support diagrams with multiple sequences... const auto &sequence_0 = j["sequences"][0]; @@ -915,6 +922,30 @@ int FindMessage(const nlohmann::json &j, const std::string &from, fmt::format("No such message {} {} {}", from, to, msg)); } +} // namespace detail + +struct File { + explicit File(const std::string &f) + : file{f} + { + } + + const std::string file; +}; + +int FindMessage(const nlohmann::json &j, const File &from, const File &to, + const std::string &msg) +{ + return detail::find_message_impl(j, from.file, to.file, msg); +} + +int FindMessage(const nlohmann::json &j, const std::string &from, + const std::string &to, const std::string &msg) +{ + return detail::find_message_impl( + j, expand_name(j, from), expand_name(j, to), msg); +} + } // namespace json } }