Added test case for call directive in sequence diagrams

This commit is contained in:
Bartek Kryza
2024-04-29 13:17:02 +02:00
parent efc34bcec6
commit 6c6575bc7f
5 changed files with 124 additions and 0 deletions

13
tests/t20047/.clang-uml Normal file
View File

@@ -0,0 +1,13 @@
add_compile_flags:
- -fparse-all-comments
diagrams:
t20047_sequence:
type: sequence
glob:
- t20047.cc
include:
namespaces:
- clanguml::t20047
using_namespace: clanguml::t20047
from:
- function: "clanguml::t20047::tmain()"

42
tests/t20047/t20047.cc Normal file
View File

@@ -0,0 +1,42 @@
#include <future>
namespace clanguml {
namespace t20047 {
int a1(int x) { return x + 1; }
int a2(int x) { return x + 2; }
int a3(int x) { return x + 3; }
int a4(int x) { return x + 4; }
int a5(int x) { return x + 5; }
int a6(int x) { return x + 6; }
int run(int (*f)(int), int arg) { return f(arg); }
int tmain()
{
auto res =
// \uml{call clanguml::t20047::a1(int)}
run(a1, 0);
res = a3(
// \uml{call clanguml::t20047::a2(int)}
run(a2, 0));
// \uml{call clanguml::t20047::a4(int)}
res = [](auto &&x) { return a4(x); }(0);
// \uml{call clanguml::t20047::a5(int)}
res = std::async(a5, 10).get();
// \uml{call clanguml::t20047::a6(int)}
res = [](auto &&x) { return std::async(run, a6, x).get(); }(1);
return res;
}
}
}

65
tests/t20047/test_case.h Normal file
View File

@@ -0,0 +1,65 @@
/**
* tests/t20047/test_case.h
*
* Copyright (c) 2021-2024 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("t20047", "[test-case][sequence]")
{
auto [config, db] = load_config("t20047");
auto diagram = config.diagrams["t20047_sequence"];
REQUIRE(diagram->name == "t20047_sequence");
auto model = generate_sequence_diagram(*db, diagram);
REQUIRE(model->name() == "t20047_sequence");
{
auto src = generate_sequence_puml(diagram, *model);
AliasMatcher _A(src);
REQUIRE_THAT(src, StartsWith("@startuml"));
REQUIRE_THAT(src, EndsWith("@enduml\n"));
// Check if all calls exist
REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("a1(int)"), ""));
REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("a2(int)"), ""));
REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("a3(int)"), ""));
REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("a4(int)"), ""));
REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("a5(int)"), ""));
REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("a6(int)"), ""));
save_puml(config.output_directory(), diagram->name + ".puml", src);
}
{
auto j = generate_sequence_json(diagram, *model);
using namespace json;
save_json(config.output_directory(), diagram->name + ".json", j);
}
{
auto src = generate_sequence_mermaid(diagram, *model);
mermaid::AliasMatcher _A(src);
using mermaid::IsClass;
save_mermaid(config.output_directory(), diagram->name + ".mmd", src);
}
}

View File

@@ -473,6 +473,7 @@ using namespace clanguml::test::matchers;
#include "t20044/test_case.h"
#include "t20045/test_case.h"
#include "t20046/test_case.h"
#include "t20047/test_case.h"
///
/// Package diagram tests

View File

@@ -361,6 +361,9 @@ test_cases:
- name: t20046
title: Test case for call expressions in nested lambdas
description:
- name: t20047
title: Test case for 'call' comment directive
description:
Package diagrams:
- name: t30001
title: Basic package diagram test case