Added 'to' sequence diagram generator for plantuml and json
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <cstdint>
|
||||
|
||||
namespace clanguml {
|
||||
namespace t20034 {
|
||||
struct A {
|
||||
|
||||
14
tests/t20036/.clang-uml
Normal file
14
tests/t20036/.clang-uml
Normal file
@@ -0,0 +1,14 @@
|
||||
compilation_database_dir: ..
|
||||
output_directory: puml
|
||||
diagrams:
|
||||
t20036_sequence:
|
||||
type: sequence
|
||||
glob:
|
||||
- ../../tests/t20036/t20036.cc
|
||||
include:
|
||||
namespaces:
|
||||
- clanguml::t20036
|
||||
using_namespace:
|
||||
- clanguml::t20036
|
||||
to:
|
||||
- function: "clanguml::t20036::A::a2()"
|
||||
44
tests/t20036/t20036.cc
Normal file
44
tests/t20036/t20036.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <cstdint>
|
||||
|
||||
namespace clanguml {
|
||||
namespace t20036 {
|
||||
struct A {
|
||||
void a1() { }
|
||||
void a2() { }
|
||||
void a3() { }
|
||||
};
|
||||
|
||||
struct B {
|
||||
void b1() { a.a2(); }
|
||||
void b2() { a.a2(); }
|
||||
void b3() { a.a3(); }
|
||||
|
||||
A a;
|
||||
};
|
||||
|
||||
struct C {
|
||||
void c1() { b.b1(); }
|
||||
void c2() { b.b2(); }
|
||||
void c3()
|
||||
{
|
||||
if (reinterpret_cast<uint64_t>(&b) == 0xbadc0de)
|
||||
c3();
|
||||
else
|
||||
c2();
|
||||
}
|
||||
|
||||
void c4() { b.b2(); }
|
||||
|
||||
B b;
|
||||
};
|
||||
|
||||
struct D {
|
||||
void d1() { c.c2(); }
|
||||
void d2() { c.c2(); }
|
||||
void d3() { a.a2(); }
|
||||
|
||||
A a;
|
||||
C c;
|
||||
};
|
||||
}
|
||||
}
|
||||
73
tests/t20036/test_case.h
Normal file
73
tests/t20036/test_case.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* tests/t20036/test_case.h
|
||||
*
|
||||
* Copyright (c) 2021-2023 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("t20036", "[test-case][sequence]")
|
||||
{
|
||||
auto [config, db] = load_config("t20036");
|
||||
|
||||
auto diagram = config.diagrams["t20036_sequence"];
|
||||
|
||||
REQUIRE(diagram->name == "t20036_sequence");
|
||||
|
||||
auto model = generate_sequence_diagram(*db, diagram);
|
||||
|
||||
REQUIRE(model->name() == "t20036_sequence");
|
||||
|
||||
{
|
||||
auto puml = generate_sequence_puml(diagram, *model);
|
||||
AliasMatcher _A(puml);
|
||||
|
||||
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||
|
||||
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "c2()"));
|
||||
REQUIRE_THAT(puml, HasCall(_A("C"), _A("B"), "b2()"));
|
||||
REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "a2()"));
|
||||
|
||||
REQUIRE_THAT(puml, HasCall(_A("C"), _A("B"), "b2()"));
|
||||
REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "a2()"));
|
||||
|
||||
REQUIRE_THAT(puml, HasCall(_A("D"), _A("A"), "a2()"));
|
||||
|
||||
REQUIRE_THAT(puml, HasCall(_A("C"), _A("B"), "b1()"));
|
||||
REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "a2()"));
|
||||
|
||||
save_puml(
|
||||
config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||
}
|
||||
|
||||
{
|
||||
auto j = generate_sequence_json(diagram, *model);
|
||||
|
||||
using namespace json;
|
||||
|
||||
REQUIRE(HasMessageChain(j,
|
||||
{{"C::c3()", "C::c2()", "void"}, {"C::c2()", "B::b2()", "void"},
|
||||
{"B::b2()", "A::a2()", "void"}}));
|
||||
REQUIRE(HasMessageChain(j,
|
||||
{{"C::c4()", "B::b2()", "void"}, {"B::b2()", "A::a2()", "void"}}));
|
||||
REQUIRE(HasMessageChain(j, {{"D::d3()", "A::a2()", "void"}}));
|
||||
REQUIRE(HasMessageChain(j,
|
||||
{{"D::d1()", "C::c2()", "void"}, {"C::c2()", "B::b2()", "void"},
|
||||
{"B::b2()", "A::a2()", "void"}}));
|
||||
REQUIRE(HasMessageChain(j,
|
||||
{{"C::c1()", "B::b1()", "void"}, {"B::b1()", "A::a2()", "void"}}));
|
||||
|
||||
save_json(config.output_directory() + "/" + diagram->name + ".json", j);
|
||||
}
|
||||
}
|
||||
@@ -349,6 +349,7 @@ using namespace clanguml::test::matchers;
|
||||
#include "t20033/test_case.h"
|
||||
#include "t20034/test_case.h"
|
||||
#include "t20035/test_case.h"
|
||||
#include "t20036/test_case.h"
|
||||
|
||||
///
|
||||
/// Package diagram tests
|
||||
|
||||
@@ -299,11 +299,14 @@ test_cases:
|
||||
title: Control statement text in sequence diagram test case
|
||||
description:
|
||||
- name: t20034
|
||||
title: from_to sequence diagram test case
|
||||
title: Test case for rendering all call chains from one activity to another (from_to)
|
||||
description:
|
||||
- name: t20035
|
||||
title: from_to sequence diagram test case with free functions
|
||||
description:
|
||||
- name: t20036
|
||||
title: Test case for rendering all call chains leading to an activity (to)
|
||||
description:
|
||||
Package diagrams:
|
||||
- name: t30001
|
||||
title: Basic package diagram test case
|
||||
|
||||
Reference in New Issue
Block a user