diff --git a/tests/t20023/.clang-uml b/tests/t20023/.clang-uml index 12759641..dd92d5c7 100644 --- a/tests/t20023/.clang-uml +++ b/tests/t20023/.clang-uml @@ -7,5 +7,5 @@ diagrams: namespaces: - clanguml::t20023 using_namespace: clanguml::t20023 - start_from: + from: - function: "clanguml::t20023::tmain()" \ No newline at end of file diff --git a/tests/t20043/.clang-uml b/tests/t20043/.clang-uml new file mode 100644 index 00000000..7b22cb2e --- /dev/null +++ b/tests/t20043/.clang-uml @@ -0,0 +1,17 @@ +diagrams: + t20043_sequence: + type: sequence + glob: + - t20043.cc + include: + namespaces: + - clanguml::t20043 + exclude: + elements: + - clanguml::t20043::B + - clanguml::t20043::F + namespaces: + - clanguml::t20043::detail + using_namespace: clanguml::t20043 + from: + - function: "clanguml::t20043::tmain()" diff --git a/tests/t20043/t20043.cc b/tests/t20043/t20043.cc new file mode 100644 index 00000000..ad1baa16 --- /dev/null +++ b/tests/t20043/t20043.cc @@ -0,0 +1,47 @@ +namespace clanguml { +namespace t20043 { +struct A { + int a() { return 1; } +}; + +struct B { + A a; + int b() { return a.a(); } +}; + +struct C { + B b; + int c() { return b.b(); } +}; + +namespace detail { +struct E { + void e() { } +}; +} // namespace detail + +struct D { + C c; + detail::E e; + int d() + { + e.e(); + return c.c(); + } +}; + +struct F { + void f() { } +}; + +int tmain() +{ + D d; + F f; + + f.f(); + + return d.d(); +} +} +} \ No newline at end of file diff --git a/tests/t20043/test_case.h b/tests/t20043/test_case.h new file mode 100644 index 00000000..84c0a4e9 --- /dev/null +++ b/tests/t20043/test_case.h @@ -0,0 +1,73 @@ +/** + * tests/t20043/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("t20043", "[test-case][sequence]") +{ + auto [config, db] = load_config("t20043"); + + auto diagram = config.diagrams["t20043_sequence"]; + + REQUIRE(diagram->name == "t20043_sequence"); + + auto model = generate_sequence_diagram(*db, diagram); + + REQUIRE(model->name() == "t20043_sequence"); + + { + auto src = generate_sequence_puml(diagram, *model); + AliasMatcher _A(src); + + REQUIRE_THAT(src, StartsWith("@startuml")); + REQUIRE_THAT(src, EndsWith("@enduml\n")); + + REQUIRE_THAT(src, !HasCall(_A("tmain()"), _A("F"), "f()")); + REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("D"), "d()")); + + REQUIRE_THAT(src, HasCall(_A("D"), _A("C"), "c()")); + REQUIRE_THAT(src, !HasCall(_A("D"), _A("detail::E"), "e()")); + REQUIRE_THAT(src, !HasCall(_A("C"), _A("B"), "b()")); + REQUIRE_THAT(src, !HasCall(_A("B"), _A("A"), "a()")); + + save_puml(config.output_directory(), diagram->name + ".puml", src); + } + + { + auto j = generate_sequence_json(diagram, *model); + + using namespace json; + + save_json(config.output_directory(), diagram->name + ".json", j); + } + + { + auto src = generate_sequence_mermaid(diagram, *model); + + mermaid::SequenceDiagramAliasMatcher _A(src); + using mermaid::HasCall; + + REQUIRE_THAT(src, !HasCall(_A("tmain()"), _A("F"), "f()")); + REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("D"), "d()")); + + REQUIRE_THAT(src, HasCall(_A("D"), _A("C"), "c()")); + REQUIRE_THAT(src, !HasCall(_A("D"), _A("detail::E"), "e()")); + REQUIRE_THAT(src, !HasCall(_A("C"), _A("B"), "b()")); + REQUIRE_THAT(src, !HasCall(_A("B"), _A("A"), "a()")); + + save_mermaid(config.output_directory(), diagram->name + ".mmd", src); + } +} \ No newline at end of file diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 66316b09..3f92a7fc 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -469,6 +469,7 @@ using namespace clanguml::test::matchers; #include "t20040/test_case.h" #include "t20041/test_case.h" #include "t20042/test_case.h" +#include "t20043/test_case.h" /// /// Package diagram tests diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index 4a824bb8..1f611954 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -349,6 +349,9 @@ test_cases: - name: t20042 title: Test case for template overload pattern description: + - name: t20043 + title: Test case for elements diagram filter in sequence diagrams + description: Package diagrams: - name: t30001 title: Basic package diagram test case