From dca616328cd9c0398d9c942d46ee9145eaa8cfd5 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Thu, 13 Jun 2024 18:55:30 +0200 Subject: [PATCH] Added test case for context filter outward direction (#274) --- src/common/model/diagram_filter.h | 15 +++++-- tests/t00077/.clang-uml | 14 +++++++ tests/t00077/t00077.cc | 69 +++++++++++++++++++++++++++++++ tests/t00077/test_case.h | 51 +++++++++++++++++++++++ tests/test_cases.cc | 1 + tests/test_cases.yaml | 4 ++ 6 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 tests/t00077/.clang-uml create mode 100644 tests/t00077/t00077.cc create mode 100644 tests/t00077/test_case.h diff --git a/src/common/model/diagram_filter.h b/src/common/model/diagram_filter.h index 2e41b559..c70a59c0 100644 --- a/src/common/model/diagram_filter.h +++ b/src/common/model/diagram_filter.h @@ -517,12 +517,19 @@ private: // elements for (const relationship &rel : el.get().relationships()) { // At the moment aggregation and composition are added in the - // model in reverse direction so we don't consider them here - if (rel.type() == relationship_t::kAggregation || - rel.type() == relationship_t::kComposition) { + // model in reverse direction, so we don't consider them here + if (context_cfg.direction == + config::context_direction_t::inward && + (rel.type() == relationship_t::kAggregation || + rel.type() == relationship_t::kComposition)) { + continue; + } + if (context_cfg.direction == + config::context_direction_t::outward && + (rel.type() != relationship_t::kAggregation && + rel.type() != relationship_t::kComposition)) { continue; } - for (const auto &element_id : effective_context) { if (d.should_include(rel.type()) && rel.destination() == element_id) diff --git a/tests/t00077/.clang-uml b/tests/t00077/.clang-uml new file mode 100644 index 00000000..32833de6 --- /dev/null +++ b/tests/t00077/.clang-uml @@ -0,0 +1,14 @@ +diagrams: + t00077_class: + type: class + glob: + - t00077.cc + include: + namespaces: + - clanguml::t00077 + context: + - match: + radius: 2 + pattern: clanguml::t00077::B + direction: outward + using_namespace: clanguml::t00077 \ No newline at end of file diff --git a/tests/t00077/t00077.cc b/tests/t00077/t00077.cc new file mode 100644 index 00000000..e4413944 --- /dev/null +++ b/tests/t00077/t00077.cc @@ -0,0 +1,69 @@ +namespace clanguml { +namespace t00077 { + +enum Color { red, green, blue }; + +struct F; +struct GG { }; +struct G { + GG gg; +}; +struct GGG { + G g; +}; +struct H { }; +struct J { }; + +struct Base { }; + +struct A : public Base { }; + +struct B : public A { + F *f; + Color c; + G g; + /// @uml{composition[0..1:1..*]} + J j; + + void a(H *h) { (void)h; } +}; + +struct C : public B { }; + +struct D : public C { }; + +struct EE { }; + +struct E { + B *b; + EE *ee; +}; + +struct EEE { + E *e; +}; + +struct FF { }; +struct F { + FF *ff; +}; +struct FFF { + F *f; +}; + +struct I { + void i(B *b) { (void)b; } +}; + +struct KKK { }; + +struct K { + B b; + KKK kkk; +}; + +struct KK { + K k; +}; +} +} \ No newline at end of file diff --git a/tests/t00077/test_case.h b/tests/t00077/test_case.h new file mode 100644 index 00000000..0cbc764b --- /dev/null +++ b/tests/t00077/test_case.h @@ -0,0 +1,51 @@ +/** + * tests/t00077/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("t00077") +{ + using namespace clanguml::test; + using namespace std::string_literals; + + auto [config, db, diagram, model] = + CHECK_CLASS_MODEL("t00077", "t00077_class"); + + CHECK_CLASS_DIAGRAM(*config, diagram, *model, [](const auto &src) { + REQUIRE(IsClass(src, "B")); + REQUIRE(IsClass(src, "Base")); + REQUIRE(IsClass(src, "A")); + REQUIRE(IsClass(src, "F")); + REQUIRE(IsClass(src, "H")); + REQUIRE(IsClass(src, "FF")); + REQUIRE(IsClass(src, "K")); + REQUIRE(IsClass(src, "KK")); + + REQUIRE(!IsClass(src, "C")); + REQUIRE(!IsClass(src, "D")); + REQUIRE(!IsClass(src, "E")); + REQUIRE(!IsClass(src, "EE")); + REQUIRE(!IsClass(src, "EEE")); + REQUIRE(!IsClass(src, "FFF")); + REQUIRE(!IsClass(src, "G")); + REQUIRE(!IsClass(src, "GG")); + REQUIRE(!IsClass(src, "I")); + REQUIRE(!IsClass(src, "J")); + REQUIRE(!IsClass(src, "KKK")); + REQUIRE(!IsEnum(src, "Color")); + REQUIRE(!IsClass(src, "GGG")); + }); +} \ No newline at end of file diff --git a/tests/test_cases.cc b/tests/test_cases.cc index b99e76eb..18191124 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -550,6 +550,7 @@ void CHECK_INCLUDE_DIAGRAM(const clanguml::config::config &config, #include "t00075/test_case.h" #endif #include "t00076/test_case.h" +#include "t00077/test_case.h" /// /// Sequence diagram tests diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index 3475a86d..2da1f626 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -224,6 +224,10 @@ test_cases: description: - name: t00076 title: Test case for context diagram with inward direction flag + description: + - name: t00077 + title: Test case for context diagram with outward direction flag + description: Sequence diagrams: - name: t20001 title: Basic sequence diagram test case