Added test case for context filter outward direction (#274)

This commit is contained in:
Bartek Kryza
2024-06-13 18:55:30 +02:00
parent 30337c1aa3
commit dca616328c
6 changed files with 150 additions and 4 deletions

View File

@@ -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)

14
tests/t00077/.clang-uml Normal file
View File

@@ -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

69
tests/t00077/t00077.cc Normal file
View File

@@ -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;
};
}
}

51
tests/t00077/test_case.h Normal file
View File

@@ -0,0 +1,51 @@
/**
* tests/t00077/test_case.h
*
* Copyright (c) 2021-2024 Bartek Kryza <bkryza@gmail.com>
*
* 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"));
});
}

View File

@@ -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

View File

@@ -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