Added template method specialization sequence diagram test case

This commit is contained in:
Bartek Kryza
2022-12-08 00:41:54 +01:00
parent de4e88a92d
commit 0a0b2a3d35
10 changed files with 157 additions and 29 deletions

View File

@@ -1,5 +1,7 @@
#include <algorithm>
#include <functional>
#include <memory>
#include <optional>
#include <utility>
namespace clanguml {
@@ -18,6 +20,8 @@ struct B {
void bb() { bbb(); }
void bbb() { }
void eb() { }
};
struct C {
@@ -32,6 +36,14 @@ struct D {
int add5(int arg) const { return arg + 5; }
};
class E {
std::optional<std::shared_ptr<B>> maybe_b;
std::shared_ptr<A> a;
public:
template <typename F> void setup(F &&f) { f(maybe_b); }
};
template <typename F> struct R {
R(F &&f)
: f_{std::move(f)}
@@ -79,6 +91,14 @@ void tmain()
std::vector<int> ints{0, 1, 2, 3, 4};
std::transform(ints.begin(), ints.end(), ints.begin(),
[&d](auto i) { return d.add5(i); });
// TODO: Fix naming function call arguments which are lambdas
// E e;
//
// e.setup([](auto &&arg) mutable {
// // We cannot know here what 'arg' might be
// arg.value()->eb();
// });
}
}
}

View File

@@ -36,38 +36,39 @@ TEST_CASE("t20012", "[test-case][sequence]")
// Check if all calls exist
REQUIRE_THAT(puml,
HasCall(_A("tmain()"), _A("tmain()::(lambda t20012.cc:54:20)"),
HasCall(_A("tmain()"), _A("tmain()::(lambda t20012.cc:66:20)"),
"operator()()"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()::(lambda t20012.cc:54:20)"), _A("A"), "a()"));
puml, HasCall(_A("tmain()::(lambda t20012.cc:66:20)"), _A("A"), "a()"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "aa()"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "aaa()"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()::(lambda t20012.cc:54:20)"), _A("B"), "b()"));
puml, HasCall(_A("tmain()::(lambda t20012.cc:66:20)"), _A("B"), "b()"));
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "bb()"));
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "bbb()"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()::(lambda t20012.cc:67:20)"), _A("C"), "c()"));
puml, HasCall(_A("tmain()::(lambda t20012.cc:79:20)"), _A("C"), "c()"));
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "cc()"));
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "ccc()"));
REQUIRE_THAT(puml,
HasCall(_A("tmain()::(lambda t20012.cc:67:20)"),
_A("tmain()::(lambda t20012.cc:54:20)"), "operator()()"));
HasCall(_A("tmain()::(lambda t20012.cc:79:20)"),
_A("tmain()::(lambda t20012.cc:66:20)"), "operator()()"));
REQUIRE_THAT(puml, HasCall(_A("C"), _A("C"), "ccc()"));
REQUIRE_THAT(puml,
HasCall(_A("tmain()"), _A("R<R::(lambda t20012.cc:73:9)>"), "r()"));
HasCall(_A("tmain()"), _A("R<R::(lambda t20012.cc:85:9)>"), "r()"));
REQUIRE_THAT(puml,
HasCall(_A("R<R::(lambda t20012.cc:73:9)>"),
_A("tmain()::(lambda t20012.cc:73:9)"), "operator()()"));
HasCall(_A("R<R::(lambda t20012.cc:85:9)>"),
_A("tmain()::(lambda t20012.cc:85:9)"), "operator()()"));
REQUIRE_THAT(
puml, HasCall(_A("tmain()::(lambda t20012.cc:73:9)"), _A("C"), "c()"));
puml, HasCall(_A("tmain()::(lambda t20012.cc:85:9)"), _A("C"), "c()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("D"), "add5(int)"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -1,4 +1,5 @@
#include <memory>
#include <optional>
namespace clanguml {
namespace t20015 {

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

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

24
tests/t20016/t20016.cc Normal file
View File

@@ -0,0 +1,24 @@
namespace clanguml {
namespace t20016 {
struct A {
void a1(int a) { }
template <typename T> T a2(const T &a) { return a;}
};
template <typename T> struct B {
void b1(T b) { a_.a1(1); }
template <typename F> F b2(T t) { return a_.a2(t); }
A a_;
};
void tmain() {
B<long> b;
b.b1(1);
b.b2<int>(2);
}
}
}

46
tests/t20016/test_case.h Normal file
View File

@@ -0,0 +1,46 @@
/**
* tests/t20016/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("t20016", "[test-case][sequence]")
{
auto [config, db] = load_config("t20016");
auto diagram = config.diagrams["t20016_sequence"];
REQUIRE(diagram->name == "t20016_sequence");
auto model = generate_sequence_diagram(*db, diagram);
REQUIRE(model->name() == "t20016_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<long>"), "b1(long)"));
REQUIRE_THAT(puml, HasCall(_A("B<long>"), _A("A"), "a1(int)"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<long>"), "b2(long)"));
REQUIRE_THAT(puml, HasCall(_A("B<long>"), _A("A"), "a2(const long &)"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -262,6 +262,7 @@ using namespace clanguml::test::matchers;
#include "t20013/test_case.h"
#include "t20014/test_case.h"
#include "t20015/test_case.h"
#include "t20016/test_case.h"
///
/// Package diagram tests

View File

@@ -193,6 +193,9 @@ test_cases:
- name: t20015
title: Class exclusion by namespace in sequence diagram test case
description:
- name: t20016
title: Template method specialization sequence diagram test case
description:
Package diagrams:
- name: t30001
title: Basic package diagram test case