From beba7d16b9169ba22798d4e3edcaba889745eb9f Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Fri, 7 Jun 2024 19:45:00 +0200 Subject: [PATCH] Added test case for sequence diagram with nested classes (#287) --- .../visitor/translation_unit_visitor.cc | 8 ++--- tests/t20054/.clang-uml | 12 +++++++ tests/t20054/t20054.cc | 35 +++++++++++++++++++ tests/t20054/test_case.h | 35 +++++++++++++++++++ tests/test_cases.cc | 1 + tests/test_cases.yaml | 3 ++ util/templates/test_cases/test_case.h | 2 +- 7 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 tests/t20054/.clang-uml create mode 100644 tests/t20054/t20054.cc create mode 100644 tests/t20054/test_case.h diff --git a/src/sequence_diagram/visitor/translation_unit_visitor.cc b/src/sequence_diagram/visitor/translation_unit_visitor.cc index 2a41abc7..1db58855 100644 --- a/src/sequence_diagram/visitor/translation_unit_visitor.cc +++ b/src/sequence_diagram/visitor/translation_unit_visitor.cc @@ -1717,20 +1717,20 @@ translation_unit_visitor::create_class_model(clang::CXXRecordDecl *cls) const auto &[label, hint, access] = anonymous_struct_relationships_[cls->getID()]; - c.set_name(parent_class.value().name() + "##" + - fmt::format("({})", label)); + c.set_name(parent_class.value().name() + + "::" + fmt::format("({})", label)); parent_class.value().add_relationship( {hint, common::to_id(c.full_name(false)), access, label}); } else - c.set_name(parent_class.value().name() + "##" + + c.set_name(parent_class.value().name() + "::" + fmt::format( "(anonymous_{})", std::to_string(cls->getID()))); } else { c.set_name( - parent_class.value().name() + "##" + cls->getNameAsString()); + parent_class.value().name() + "::" + cls->getNameAsString()); } c.set_id(common::to_id(c.full_name(false))); diff --git a/tests/t20054/.clang-uml b/tests/t20054/.clang-uml new file mode 100644 index 00000000..c9d3e315 --- /dev/null +++ b/tests/t20054/.clang-uml @@ -0,0 +1,12 @@ +diagrams: + t20054_sequence: + type: sequence + glob: + - t20054.cc + include: + namespaces: + - clanguml::t20054 + using_namespace: clanguml::t20054 + from: + - function: "clanguml::t20054::tmain()" + - function: "clanguml::t20054::A::AA::bb()" \ No newline at end of file diff --git a/tests/t20054/t20054.cc b/tests/t20054/t20054.cc new file mode 100644 index 00000000..29c43bc9 --- /dev/null +++ b/tests/t20054/t20054.cc @@ -0,0 +1,35 @@ +namespace clanguml { +namespace t20054 { + +struct A { + struct AA { + struct AAA { + int aaa() { return 3; } + }; + + struct BBB { + int bbb() { return 4; } + }; + + int aa() { return aaa.aaa(); } + + int bb() { return bbb.bbb(); } + + AAA aaa; + BBB bbb; + }; + + void a() { aa.aa(); } + + AA aa; +}; + +void tmain() +{ + A a; + + a.a(); +} + +} // namespace t20054 +} // namespace clanguml \ No newline at end of file diff --git a/tests/t20054/test_case.h b/tests/t20054/test_case.h new file mode 100644 index 00000000..bb9f9632 --- /dev/null +++ b/tests/t20054/test_case.h @@ -0,0 +1,35 @@ +/** + * tests/t20054/test_case.h + * + * Copyright (c) 2021-2024 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("t20054") +{ + using namespace clanguml::test; + using namespace std::string_literals; + + auto [config, db, diagram, model] = + CHECK_SEQUENCE_MODEL("t20054", "t20054_sequence"); + + CHECK_SEQUENCE_DIAGRAM(config, diagram, *model, [](const auto &src) { + REQUIRE(MessageOrder(src, + {{"tmain()", "A", "a()"}, {"A", "A::AA", "aa()"}, + {"A::AA", "A::AA::AAA", "aaa()"}, + + {Entrypoint{}, "A::AA", "bb()"}, + {"A::AA", "A::AA::BBB", "bbb()"}})); + }); +} \ No newline at end of file diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 1b4b8d3c..4605d8d2 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -610,6 +610,7 @@ void CHECK_INCLUDE_DIAGRAM(const clanguml::config::config &config, #include "t20052/test_case.h" #include "t20053/test_case.h" +#include "t20054/test_case.h" /// /// Package diagram tests diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index 573e6998..b4abab7b 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -382,6 +382,9 @@ test_cases: - name: t20053 title: Test case for inlining nested lambda operator calls description: + - name: t20054 + title: Test case for sequence diagram with nested classes + description: Package diagrams: - name: t30001 title: Basic package diagram test case diff --git a/util/templates/test_cases/test_case.h b/util/templates/test_cases/test_case.h index 8fefc60f..f58d4c97 100644 --- a/util/templates/test_cases/test_case.h +++ b/util/templates/test_cases/test_case.h @@ -22,7 +22,7 @@ TEST_CASE("{{ name }}") using namespace std::string_literals; auto [config, db, diagram, model] = - CHECK_{{ TYPE }}_MODEL("{{ name }}", "{{ name }}_class"); + CHECK_{{ TYPE }}_MODEL("{{ name }}", "{{ name }}_{{ type }}"); {{ examples }} }