Added option to include if and loop condition text in the diagram (fixes #162)

This commit is contained in:
Bartek Kryza
2023-07-04 23:58:42 +02:00
parent a514532e51
commit 3bd8f7f7a8
20 changed files with 365 additions and 13 deletions

View File

@@ -35,7 +35,8 @@ TEST_CASE("t20028", "[test-case][sequence]")
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
// Check if all calls exist
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "a()"));
REQUIRE_THAT(
puml, HasCallInControlCondition(_A("tmain()"), _A("A"), "a()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "b()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "c()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "d()"));

15
tests/t20033/.clang-uml Normal file
View File

@@ -0,0 +1,15 @@
compilation_database_dir: ..
output_directory: puml
diagrams:
t20033_sequence:
type: sequence
glob:
- ../../tests/t20033/t20033.cc
include:
namespaces:
- clanguml::t20033
using_namespace:
- clanguml::t20033
generate_condition_statements: true
start_from:
- function: "clanguml::t20033::tmain()"

65
tests/t20033/t20033.cc Normal file
View File

@@ -0,0 +1,65 @@
#include <cmath>
#include <cstdint>
#include <vector>
namespace clanguml {
namespace t20033 {
struct A {
int a1() { return 0; }
int a2() { return 1; }
int a3() { return 2; }
int a4() { return 3; }
};
int tmain()
{
A a;
int result{};
// clang-format off
if(false) {
result = 0;
}
else if (reinterpret_cast<uint64_t>(&a) % 100 == 0ULL) {
result = a.a1();
}
else if (reinterpret_cast<uint64_t>(&a) % 64 == 0ULL) {
result = a.a2();
}
else if(a.a2() == 2 &&
a.a3() == 3) {
result = a.a3();
}
else {
result = a.a4();
}
// clang-format on
if (int i = a.a2(); i != 2) {
result += a.a3();
}
for (int i = 0; i < a.a2(); i++) {
result += i * a.a3();
}
int retry_count = a.a3();
while (retry_count--) {
result -= a.a2();
}
do {
result += a.a4();
} while (retry_count++ < a.a3());
result = a.a4() % 6 ? result * 2 : result;
std::vector<int> ints;
for (auto i : ints) {
result += a.a4();
}
return result;
}
}
}

58
tests/t20033/test_case.h Normal file
View File

@@ -0,0 +1,58 @@
/**
* tests/t20033/test_case.h
*
* Copyright (c) 2021-2023 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("t20033", "[test-case][sequence]")
{
auto [config, db] = load_config("t20033");
auto diagram = config.diagrams["t20033_sequence"];
REQUIRE(diagram->name == "t20033_sequence");
auto model = generate_sequence_diagram(*db, diagram);
REQUIRE(model->name() == "t20033_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("A"), "a1()"));
REQUIRE_THAT(
puml, HasCallInControlCondition(_A("tmain()"), _A("A"), "a2()"));
REQUIRE_THAT(
puml, HasCallInControlCondition(_A("tmain()"), _A("A"), "a3()"));
REQUIRE_THAT(
puml, HasCallInControlCondition(_A("tmain()"), _A("A"), "a4()"));
save_puml(
config.output_directory() + "/" + diagram->name + ".puml", puml);
}
{
auto j = generate_sequence_json(diagram, *model);
using namespace json;
save_json(config.output_directory() + "/" + diagram->name + ".json", j);
}
}

View File

@@ -346,6 +346,7 @@ using namespace clanguml::test::matchers;
#include "t20030/test_case.h"
#include "t20031/test_case.h"
#include "t20032/test_case.h"
#include "t20033/test_case.h"
///
/// Package diagram tests

View File

@@ -295,6 +295,9 @@ test_cases:
- name: t20032
title: Return type generation option sequence diagram test case
description:
- name: t20033
title: Control statement text in sequence diagram test case
description:
Package diagrams:
- name: t30001
title: Basic package diagram test case