Added smart pointer dereference sequence diagram test case

This commit is contained in:
Bartek Kryza
2022-11-29 22:08:46 +01:00
parent f1af5460e3
commit 0e3c69ce38
7 changed files with 161 additions and 18 deletions

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

@@ -0,0 +1,14 @@
compilation_database_dir: ..
output_directory: puml
diagrams:
t20009_sequence:
type: sequence
glob:
- ../../tests/t20009/t20009.cc
include:
namespaces:
- clanguml::t20009
using_namespace:
- clanguml::t20009
start_from:
- function: "clanguml::t20009::tmain()"

25
tests/t20009/t20009.cc Normal file
View File

@@ -0,0 +1,25 @@
#include <memory>
#include <string>
namespace clanguml {
namespace t20009 {
template <typename T> struct A {
void a(T arg) { }
};
template <typename T> struct B {
void b(T arg) { a->a(arg); }
std::unique_ptr<A<T>> a;
};
void tmain()
{
std::shared_ptr<B<std::string>> bstring;
auto bint = std::make_unique<B<int>>();
bstring->b("b");
bint.get()->b(42);
}
}
}

47
tests/t20009/test_case.h Normal file
View File

@@ -0,0 +1,47 @@
/**
* tests/t20009/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("t20009", "[test-case][sequence]")
{
auto [config, db] = load_config("t20009");
auto diagram = config.diagrams["t20009_sequence"];
REQUIRE(diagram->name == "t20009_sequence");
auto model = generate_sequence_diagram(*db, diagram);
REQUIRE(model->name() == "t20009_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<std::string>"), "b"));
REQUIRE_THAT(
puml, HasCall(_A("B<std::string>"), _A("A<std::string>"), "a"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A<int>"), "a"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -255,6 +255,7 @@ using namespace clanguml::test::matchers;
#include "t20006/test_case.h"
#include "t20007/test_case.h"
#include "t20008/test_case.h"
#include "t20009/test_case.h"
///
/// Package diagram tests

View File

@@ -172,6 +172,9 @@ test_cases:
- name: t20008
title: Constexpr if sequence diagram test case
description:
- name: t20009
title: Smart pointer dereference call expression test case
description:
Package diagrams:
- name: t30001
title: Basic package diagram test case