From cdc3659c172bfe985fac06f3752d7ea0f48dd791 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Wed, 30 Aug 2023 00:01:59 +0200 Subject: [PATCH] Added from_to test case with free functions --- tests/t20035/.clang-uml | 15 +++++++++++ tests/t20035/t20035.cc | 14 ++++++++++ tests/t20035/test_case.h | 57 ++++++++++++++++++++++++++++++++++++++++ tests/test_cases.cc | 1 + tests/test_cases.yaml | 6 +++++ 5 files changed, 93 insertions(+) create mode 100644 tests/t20035/.clang-uml create mode 100644 tests/t20035/t20035.cc create mode 100644 tests/t20035/test_case.h diff --git a/tests/t20035/.clang-uml b/tests/t20035/.clang-uml new file mode 100644 index 00000000..7b1a708e --- /dev/null +++ b/tests/t20035/.clang-uml @@ -0,0 +1,15 @@ +compilation_database_dir: .. +output_directory: puml +diagrams: + t20035_sequence: + type: sequence + glob: + - ../../tests/t20035/t20035.cc + include: + namespaces: + - clanguml::t20035 + using_namespace: + - clanguml::t20035 + from_to: + - [function: "clanguml::t20035::tmain(int,char **)", + function: "clanguml::t20035::c(int)"] \ No newline at end of file diff --git a/tests/t20035/t20035.cc b/tests/t20035/t20035.cc new file mode 100644 index 00000000..b2b66aeb --- /dev/null +++ b/tests/t20035/t20035.cc @@ -0,0 +1,14 @@ +namespace clanguml { +namespace t20035 { + +int c(int arg) { return arg; } + +int b1(int arg) { return c(arg); } + +int b2(int arg) { return c(arg); } + +int a(int arg) { return b1(arg); } + +int tmain(int argc, char **argv) { return a(argc); } +} +} \ No newline at end of file diff --git a/tests/t20035/test_case.h b/tests/t20035/test_case.h new file mode 100644 index 00000000..50134794 --- /dev/null +++ b/tests/t20035/test_case.h @@ -0,0 +1,57 @@ +/** + * tests/t20035/test_case.h + * + * Copyright (c) 2021-2023 Bartek Kryza + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +TEST_CASE("t20035", "[test-case][sequence]") +{ + auto [config, db] = load_config("t20035"); + + auto diagram = config.diagrams["t20035_sequence"]; + + REQUIRE(diagram->name == "t20035_sequence"); + + auto model = generate_sequence_diagram(*db, diagram); + + REQUIRE(model->name() == "t20035_sequence"); + + { + auto puml = generate_sequence_puml(diagram, *model); + AliasMatcher _A(puml); + + REQUIRE_THAT(puml, StartsWith("@startuml")); + REQUIRE_THAT(puml, EndsWith("@enduml\n")); + + REQUIRE_THAT(puml, HasCall(_A("tmain(int,char **)"), _A("a(int)"), "")); + REQUIRE_THAT(puml, HasCall(_A("a(int)"), _A("b1(int)"), "")); + REQUIRE_THAT(puml, HasCall(_A("b1(int)"), _A("c(int)"), "")); + + save_puml( + config.output_directory() + "/" + diagram->name + ".puml", puml); + } + + { + auto j = generate_sequence_json(diagram, *model); + + using namespace json; + + REQUIRE(HasMessageChain(j, + {{"tmain(int,char **)", "a(int)", "int"}, + {"a(int)", "b1(int)", "int"}, {"b1(int)", "c(int)", "int"}})); + + save_json(config.output_directory() + "/" + diagram->name + ".json", j); + } +} \ No newline at end of file diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 45e2eda4..a87943b5 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -348,6 +348,7 @@ using namespace clanguml::test::matchers; #include "t20032/test_case.h" #include "t20033/test_case.h" #include "t20034/test_case.h" +#include "t20035/test_case.h" /// /// Package diagram tests diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index 82cbb91f..0beedfda 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -298,6 +298,12 @@ test_cases: - name: t20033 title: Control statement text in sequence diagram test case description: + - name: t20034 + title: from_to sequence diagram test case + description: + - name: t20035 + title: from_to sequence diagram test case with free functions + description: Package diagrams: - name: t30001 title: Basic package diagram test case