From 3b6d999520d271a4fdd5fa19622324c4dbce886d Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Sat, 10 Dec 2022 12:06:12 +0100 Subject: [PATCH] Added Curiously Recurring Template Pattern sequence diagram test case --- tests/t20019/.clang-uml | 14 +++++++++++++ tests/t20019/t20019.cc | 34 ++++++++++++++++++++++++++++++ tests/t20019/test_case.h | 45 ++++++++++++++++++++++++++++++++++++++++ tests/test_cases.cc | 1 + tests/test_cases.yaml | 3 +++ 5 files changed, 97 insertions(+) create mode 100644 tests/t20019/.clang-uml create mode 100644 tests/t20019/t20019.cc create mode 100644 tests/t20019/test_case.h diff --git a/tests/t20019/.clang-uml b/tests/t20019/.clang-uml new file mode 100644 index 00000000..77631b8c --- /dev/null +++ b/tests/t20019/.clang-uml @@ -0,0 +1,14 @@ +compilation_database_dir: .. +output_directory: puml +diagrams: + t20019_sequence: + type: sequence + glob: + - ../../tests/t20019/t20019.cc + include: + namespaces: + - clanguml::t20019 + using_namespace: + - clanguml::t20019 + start_from: + - function: "clanguml::t20019::tmain()" \ No newline at end of file diff --git a/tests/t20019/t20019.cc b/tests/t20019/t20019.cc new file mode 100644 index 00000000..907e2066 --- /dev/null +++ b/tests/t20019/t20019.cc @@ -0,0 +1,34 @@ +#include + +namespace clanguml { +namespace t20019 { + +// From https://en.cppreference.com/w/cpp/language/crtp + +template struct Base { + void name() { (static_cast(this))->impl(); } +}; + +struct D1 : public Base { + void impl() { std::puts("D1::impl()"); } +}; + +struct D2 : public Base { + void impl() { std::puts("D2::impl()"); } +}; + +void tmain() +{ + Base b1; + b1.name(); + Base b2; + b2.name(); + + D1 d1; + d1.name(); + D2 d2; + d2.name(); +} + +} +} \ No newline at end of file diff --git a/tests/t20019/test_case.h b/tests/t20019/test_case.h new file mode 100644 index 00000000..3e7bb3f7 --- /dev/null +++ b/tests/t20019/test_case.h @@ -0,0 +1,45 @@ +/** + * tests/t20019/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("t20019", "[test-case][sequence]") +{ + auto [config, db] = load_config("t20019"); + + auto diagram = config.diagrams["t20019_sequence"]; + + REQUIRE(diagram->name == "t20019_sequence"); + + auto model = generate_sequence_diagram(*db, diagram); + + REQUIRE(model->name() == "t20019_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("Base"), "name()")); + REQUIRE_THAT(puml, HasCall(_A("Base"), _A("D1"), "impl()")); + REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("Base"), "name()")); + REQUIRE_THAT(puml, HasCall(_A("Base"), _A("D2"), "impl()")); + + 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 5a875638..2e5944bb 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -265,6 +265,7 @@ using namespace clanguml::test::matchers; #include "t20016/test_case.h" #include "t20017/test_case.h" #include "t20018/test_case.h" +#include "t20019/test_case.h" /// /// Package diagram tests diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index ccaf8d29..20f5ba17 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -202,6 +202,9 @@ test_cases: - name: t20018 title: Recursive template sequence diagram test case description: + - name: t20019 + title: Curiously Recurring Template Pattern sequence diagram test case + description: Package diagrams: - name: t30001 title: Basic package diagram test case