From c7b80297d7d7c4d68cf472bdbaabaa1551c1a632 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Sun, 11 Dec 2022 22:48:56 +0100 Subject: [PATCH] Added forward class declaration sequence diagram test case --- tests/t20022/.clang-uml | 14 +++++++++++++ tests/t20022/t20022.cc | 37 ++++++++++++++++++++++++++++++++ tests/t20022/test_case.h | 43 ++++++++++++++++++++++++++++++++++++++ tests/test_cases.cc | 1 + tests/test_cases.yaml | 3 +++ util/generate_test_case.py | 4 ++-- 6 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 tests/t20022/.clang-uml create mode 100644 tests/t20022/t20022.cc create mode 100644 tests/t20022/test_case.h diff --git a/tests/t20022/.clang-uml b/tests/t20022/.clang-uml new file mode 100644 index 00000000..0fa68fa9 --- /dev/null +++ b/tests/t20022/.clang-uml @@ -0,0 +1,14 @@ +compilation_database_dir: .. +output_directory: puml +diagrams: + t20022_sequence: + type: sequence + glob: + - ../../tests/t20022/t20022.cc + include: + namespaces: + - clanguml::t20022 + using_namespace: + - clanguml::t20022 + start_from: + - function: "clanguml::t20022::tmain()" \ No newline at end of file diff --git a/tests/t20022/t20022.cc b/tests/t20022/t20022.cc new file mode 100644 index 00000000..d9aee6ae --- /dev/null +++ b/tests/t20022/t20022.cc @@ -0,0 +1,37 @@ +#include + +namespace clanguml { +namespace t20022 { +class B; + +class A { +public: + A(std::unique_ptr b); + + void a(); + + std::unique_ptr b_; +}; + +class B { +public: + void b() { } +}; + +A::A(std::unique_ptr b) + : b_{std::move(b)} +{ +} + +void A::a() { b_->b(); } + +int tmain() +{ + A a{std::make_unique()}; + + a.a(); + + return 0; +} +} +} \ No newline at end of file diff --git a/tests/t20022/test_case.h b/tests/t20022/test_case.h new file mode 100644 index 00000000..9ffa41ed --- /dev/null +++ b/tests/t20022/test_case.h @@ -0,0 +1,43 @@ +/** + * tests/t20022/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("t20022", "[test-case][sequence]") +{ + auto [config, db] = load_config("t20022"); + + auto diagram = config.diagrams["t20022_sequence"]; + + REQUIRE(diagram->name == "t20022_sequence"); + + auto model = generate_sequence_diagram(*db, diagram); + + REQUIRE(model->name() == "t20022_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("B"), "b()")); + + 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 e4a08b61..3a9b7b6a 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -268,6 +268,7 @@ using namespace clanguml::test::matchers; #include "t20019/test_case.h" #include "t20020/test_case.h" #include "t20021/test_case.h" +#include "t20022/test_case.h" /// /// Package diagram tests diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index e51d4d09..37fd33cb 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -211,6 +211,9 @@ test_cases: - name: t20021 title: Loop statements sequence diagram test case description: + - name: t20022 + title: Forward class declaration sequence diagram test case + description: Package diagrams: - name: t30001 title: Basic package diagram test case diff --git a/util/generate_test_case.py b/util/generate_test_case.py index 933ad835..ba2e1bc3 100755 --- a/util/generate_test_case.py +++ b/util/generate_test_case.py @@ -56,8 +56,8 @@ CLASS_DIAGRAM_TEST_CASE_EXAMPLES = """ SEQUENCE_DIAGRAM_TEST_CASE_EXAMPLES = """ // Check if all calls exist - //REQUIRE_THAT(puml, HasCall("A", "log_result")); - //REQUIRE_THAT(puml, HasCallWithResponse("B", "A", "add3")); + //REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "a()")); + //REQUIRE_THAT(puml, HasCall(_A("A"), "a()")); """ PACKAGE_DIAGRAM_TEST_CASE_EXAMPLES = """