Added recursive call generated in sequence diagram test case
This commit is contained in:
@@ -77,22 +77,29 @@ void generator::generate_return(const message &m, std::ostream &ostr) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generator::generate_activity(const activity &a, std::ostream &ostr) const
|
void generator::generate_activity(const activity &a, std::ostream &ostr,
|
||||||
|
std::set<common::model::diagram_element::id_t> &visited) const
|
||||||
{
|
{
|
||||||
for (const auto &m : a.messages) {
|
for (const auto &m : a.messages) {
|
||||||
|
visited.emplace(m.from);
|
||||||
|
|
||||||
const auto &to = m_model.get_participant<model::participant>(m.to);
|
const auto &to = m_model.get_participant<model::participant>(m.to);
|
||||||
if (!to)
|
if (!to)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
LOG_DBG("Generating message {} --> {}", m.from, m.to);
|
LOG_DBG("Generating message {} --> {}", m.from, m.to);
|
||||||
|
|
||||||
generate_call(m, ostr);
|
generate_call(m, ostr);
|
||||||
|
|
||||||
ostr << "activate " << to.value().alias() << std::endl;
|
ostr << "activate " << to.value().alias() << std::endl;
|
||||||
|
|
||||||
if (m_model.sequences.find(m.to) != m_model.sequences.end()) {
|
if (m_model.sequences.find(m.to) != m_model.sequences.end()) {
|
||||||
LOG_DBG("Creating activity {} --> {} - missing sequence {}", m.from,
|
if (visited.find(m.to) ==
|
||||||
m.to, m.to);
|
visited.end()) { // break infinite recursion on recursive calls
|
||||||
generate_activity(m_model.sequences[m.to], ostr);
|
LOG_DBG("Creating activity {} --> {} - missing sequence {}",
|
||||||
|
m.from, m.to, m.to);
|
||||||
|
generate_activity(m_model.sequences[m.to], ostr, visited);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LOG_DBG("Skipping activity {} --> {} - missing sequence {}", m.from,
|
LOG_DBG("Skipping activity {} --> {} - missing sequence {}", m.from,
|
||||||
@@ -165,7 +172,7 @@ void generator::generate(std::ostream &ostr) const
|
|||||||
|
|
||||||
for (const auto &sf : m_config.start_from()) {
|
for (const auto &sf : m_config.start_from()) {
|
||||||
if (sf.location_type == source_location::location_t::function) {
|
if (sf.location_type == source_location::location_t::function) {
|
||||||
std::int64_t start_from;
|
common::model::diagram_element::id_t start_from;
|
||||||
for (const auto &[k, v] : m_model.sequences) {
|
for (const auto &[k, v] : m_model.sequences) {
|
||||||
const auto &caller = *m_model.participants.at(v.from);
|
const auto &caller = *m_model.participants.at(v.from);
|
||||||
std::string vfrom = caller.full_name(false);
|
std::string vfrom = caller.full_name(false);
|
||||||
@@ -175,7 +182,9 @@ void generator::generate(std::ostream &ostr) const
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
generate_activity(m_model.sequences[start_from], ostr);
|
std::set<common::model::diagram_element::id_t> visited_participants;
|
||||||
|
generate_activity(
|
||||||
|
m_model.sequences[start_from], ostr, visited_participants);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: Add support for other sequence start location types
|
// TODO: Add support for other sequence start location types
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ public:
|
|||||||
void generate_participant(std::ostream &ostr, common::id_t id) const;
|
void generate_participant(std::ostream &ostr, common::id_t id) const;
|
||||||
|
|
||||||
void generate_activity(const clanguml::sequence_diagram::model::activity &a,
|
void generate_activity(const clanguml::sequence_diagram::model::activity &a,
|
||||||
std::ostream &ostr) const;
|
std::ostream &ostr,
|
||||||
|
std::set<common::model::diagram_element::id_t> &visited) const;
|
||||||
|
|
||||||
void generate(std::ostream &ostr) const;
|
void generate(std::ostream &ostr) const;
|
||||||
|
|
||||||
|
|||||||
14
tests/t20011/.clang-uml
Normal file
14
tests/t20011/.clang-uml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
compilation_database_dir: ..
|
||||||
|
output_directory: puml
|
||||||
|
diagrams:
|
||||||
|
t20011_sequence:
|
||||||
|
type: sequence
|
||||||
|
glob:
|
||||||
|
- ../../tests/t20011/t20011.cc
|
||||||
|
include:
|
||||||
|
namespaces:
|
||||||
|
- clanguml::t20011
|
||||||
|
using_namespace:
|
||||||
|
- clanguml::t20011
|
||||||
|
start_from:
|
||||||
|
- function: "clanguml::t20011::tmain()"
|
||||||
31
tests/t20011/t20011.cc
Normal file
31
tests/t20011/t20011.cc
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
namespace clanguml {
|
||||||
|
namespace t20011 {
|
||||||
|
|
||||||
|
struct A {
|
||||||
|
void a(int i = 10)
|
||||||
|
{
|
||||||
|
if (i > 0)
|
||||||
|
a(i - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void b(int i = 10) { c(i); }
|
||||||
|
void c(int i) { d(i); }
|
||||||
|
void d(int i)
|
||||||
|
{
|
||||||
|
if (i > 0)
|
||||||
|
b(i - 1);
|
||||||
|
else
|
||||||
|
a();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void tmain()
|
||||||
|
{
|
||||||
|
A a;
|
||||||
|
|
||||||
|
a.a();
|
||||||
|
|
||||||
|
a.b();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
48
tests/t20011/test_case.h
Normal file
48
tests/t20011/test_case.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* tests/t20011/test_case.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021-2022 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("t20011", "[test-case][sequence]")
|
||||||
|
{
|
||||||
|
auto [config, db] = load_config("t20011");
|
||||||
|
|
||||||
|
auto diagram = config.diagrams["t20011_sequence"];
|
||||||
|
|
||||||
|
REQUIRE(diagram->name == "t20011_sequence");
|
||||||
|
|
||||||
|
auto model = generate_sequence_diagram(*db, diagram);
|
||||||
|
|
||||||
|
REQUIRE(model->name() == "t20011_sequence");
|
||||||
|
|
||||||
|
auto puml = generate_sequence_puml(diagram, *model);
|
||||||
|
AliasMatcher _A(puml);
|
||||||
|
|
||||||
|
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||||
|
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||||
|
|
||||||
|
// Check if all calls exist
|
||||||
|
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "a"));
|
||||||
|
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "a"));
|
||||||
|
|
||||||
|
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "b"));
|
||||||
|
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "c"));
|
||||||
|
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "d"));
|
||||||
|
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "b"));
|
||||||
|
|
||||||
|
save_puml(
|
||||||
|
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
|
}
|
||||||
@@ -257,6 +257,7 @@ using namespace clanguml::test::matchers;
|
|||||||
#include "t20008/test_case.h"
|
#include "t20008/test_case.h"
|
||||||
#include "t20009/test_case.h"
|
#include "t20009/test_case.h"
|
||||||
#include "t20010/test_case.h"
|
#include "t20010/test_case.h"
|
||||||
|
#include "t20011/test_case.h"
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Package diagram tests
|
/// Package diagram tests
|
||||||
|
|||||||
@@ -178,6 +178,9 @@ test_cases:
|
|||||||
- name: t20010
|
- name: t20010
|
||||||
title: Container sequence diagram test case
|
title: Container sequence diagram test case
|
||||||
description:
|
description:
|
||||||
|
- name: t20011
|
||||||
|
title: Recursive calls sequence diagram test case
|
||||||
|
description:
|
||||||
Package diagrams:
|
Package diagrams:
|
||||||
- name: t30001
|
- name: t30001
|
||||||
title: Basic package diagram test case
|
title: Basic package diagram test case
|
||||||
|
|||||||
Reference in New Issue
Block a user