diff --git a/src/sequence_diagram/model/diagram.cc b/src/sequence_diagram/model/diagram.cc index 6f6616b6..a660adfd 100644 --- a/src/sequence_diagram/model/diagram.cc +++ b/src/sequence_diagram/model/diagram.cc @@ -85,6 +85,11 @@ void diagram::print() const LOG_DBG(" Activity id={}, from={}:", act.from, from_activity.full_name(false)); for (const auto &message : act.messages) { + if (participants.find(message.from) == participants.end()) + continue; + if (participants.find(message.to) == participants.end()) + continue; + const auto &from_participant = *participants.at(message.from); const auto &to_participant = *participants.at(message.to); diff --git a/tests/t20010/.clang-uml b/tests/t20010/.clang-uml new file mode 100644 index 00000000..55f2dd81 --- /dev/null +++ b/tests/t20010/.clang-uml @@ -0,0 +1,14 @@ +compilation_database_dir: .. +output_directory: puml +diagrams: + t20010_sequence: + type: sequence + glob: + - ../../tests/t20010/t20010.cc + include: + namespaces: + - clanguml::t20010 + using_namespace: + - clanguml::t20010 + start_from: + - function: "clanguml::t20010::tmain()" \ No newline at end of file diff --git a/tests/t20010/t20010.cc b/tests/t20010/t20010.cc new file mode 100644 index 00000000..3b8745cd --- /dev/null +++ b/tests/t20010/t20010.cc @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +namespace clanguml { +namespace t20010 { + +struct A { + void a1() { } + void a2() { } + void a3() { } + void a4() { } +}; + +template struct B { + void b1() { a_.a1(); } + void b2() { avector_.front().a2(); } + void b3() { aptrvector_.front()->a3(); } + void b4() { amap_.at(0).a4(); } + + A a_; + std::vector avector_; + std::vector> aptrvector_; + std::map amap_; +}; + +void tmain() +{ + B b; + + b.b1(); + b.b2(); + b.b3(); + b.b4(); +} + +} +} \ No newline at end of file diff --git a/tests/t20010/test_case.h b/tests/t20010/test_case.h new file mode 100644 index 00000000..b2be4711 --- /dev/null +++ b/tests/t20010/test_case.h @@ -0,0 +1,52 @@ +/** + * tests/t20010/test_case.h + * + * Copyright (c) 2021-2022 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("t20010", "[test-case][sequence]") +{ + auto [config, db] = load_config("t20010"); + + auto diagram = config.diagrams["t20010_sequence"]; + + REQUIRE(diagram->name == "t20010_sequence"); + + auto model = generate_sequence_diagram(*db, diagram); + + REQUIRE(model->name() == "t20010_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("B"), "b1")); + REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "a1")); + + REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "b2")); + REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "a2")); + + REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "b3")); + REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "a3")); + + REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "b4")); + REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "a4")); + + save_puml( + "./" + config.output_directory() + "/" + diagram->name + ".puml", puml); +} \ No newline at end of file diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 1103de0a..96a4d2f6 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -256,6 +256,7 @@ using namespace clanguml::test::matchers; #include "t20007/test_case.h" #include "t20008/test_case.h" #include "t20009/test_case.h" +#include "t20010/test_case.h" /// /// Package diagram tests diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index 4fa3d254..7b1c8a53 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -175,6 +175,9 @@ test_cases: - name: t20009 title: Smart pointer dereference call expression test case description: + - name: t20010 + title: Container sequence diagram test case + description: Package diagrams: - name: t30001 title: Basic package diagram test case