Added Curiously Recurring Template Pattern sequence diagram test case

This commit is contained in:
Bartek Kryza
2022-12-10 12:06:12 +01:00
parent 80e94c2e32
commit 3b6d999520
5 changed files with 97 additions and 0 deletions

14
tests/t20019/.clang-uml Normal file
View File

@@ -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()"

34
tests/t20019/t20019.cc Normal file
View File

@@ -0,0 +1,34 @@
#include <cstdio>
namespace clanguml {
namespace t20019 {
// From https://en.cppreference.com/w/cpp/language/crtp
template <class Derived> struct Base {
void name() { (static_cast<Derived *>(this))->impl(); }
};
struct D1 : public Base<D1> {
void impl() { std::puts("D1::impl()"); }
};
struct D2 : public Base<D2> {
void impl() { std::puts("D2::impl()"); }
};
void tmain()
{
Base<D1> b1;
b1.name();
Base<D2> b2;
b2.name();
D1 d1;
d1.name();
D2 d2;
d2.name();
}
}
}

45
tests/t20019/test_case.h Normal file
View File

@@ -0,0 +1,45 @@
/**
* tests/t20019/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("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<D1>"), "name()"));
REQUIRE_THAT(puml, HasCall(_A("Base<D1>"), _A("D1"), "impl()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("Base<D2>"), "name()"));
REQUIRE_THAT(puml, HasCall(_A("Base<D2>"), _A("D2"), "impl()"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -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

View File

@@ -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