Added test case for elements filter in sequence diagrams (#248)

This commit is contained in:
Bartek Kryza
2024-03-06 17:39:42 +01:00
parent 6facb386bb
commit fdea7f5852
6 changed files with 142 additions and 1 deletions

View File

@@ -7,5 +7,5 @@ diagrams:
namespaces:
- clanguml::t20023
using_namespace: clanguml::t20023
start_from:
from:
- function: "clanguml::t20023::tmain()"

17
tests/t20043/.clang-uml Normal file
View File

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

47
tests/t20043/t20043.cc Normal file
View File

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

73
tests/t20043/test_case.h Normal file
View File

@@ -0,0 +1,73 @@
/**
* tests/t20043/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("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);
}
}

View File

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

View File

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