Added if statement sequence diagram support

This commit is contained in:
Bartek Kryza
2022-12-11 00:12:31 +01:00
parent dae8513529
commit 13dae33d99
10 changed files with 340 additions and 25 deletions

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

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

56
tests/t20020/t20020.cc Normal file
View File

@@ -0,0 +1,56 @@
#include <cmath>
#include <cstdint>
namespace clanguml {
namespace t20020 {
struct A {
int a1() { return 0; }
int a2() { return 1; }
int a3() { return 2; }
};
struct B {
void log() { }
int b1() { return 3; }
int b2() { return 4; }
};
int tmain()
{
A a;
B b;
int result{0};
if (reinterpret_cast<uint64_t>(&a) % 100 == 0ULL) {
result = a.a1();
}
else if (reinterpret_cast<uint64_t>(&a) % 64 == 0ULL) {
if (a.a2() > 2)
result = b.b1();
else
result = b.b2();
}
else {
result = a.a3();
}
b.log();
// This if/else should not be included in the diagram at all
// as the calls to std will be excluded by the diagram filters
if (result != 2) {
result = std::exp(result);
}
else if(result == 3) {
result = 4;
}
else {
result = std::exp(result + 1);
}
return result;
}
}
}

49
tests/t20020/test_case.h Normal file
View File

@@ -0,0 +1,49 @@
/**
* tests/t20020/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("t20020", "[test-case][sequence]")
{
auto [config, db] = load_config("t20020");
auto diagram = config.diagrams["t20020_sequence"];
REQUIRE(diagram->name == "t20020_sequence");
auto model = generate_sequence_diagram(*db, diagram);
REQUIRE(model->name() == "t20020_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, HasCall(_A("tmain()"), _A("A"), "a2()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "a3()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "b1()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "b2()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "log()"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -266,6 +266,7 @@ using namespace clanguml::test::matchers;
#include "t20017/test_case.h"
#include "t20018/test_case.h"
#include "t20019/test_case.h"
#include "t20020/test_case.h"
///
/// Package diagram tests

View File

@@ -205,6 +205,9 @@ test_cases:
- name: t20019
title: Curiously Recurring Template Pattern sequence diagram test case
description:
- name: t20020
title: If statement sequence diagram test case
description:
Package diagrams:
- name: t30001
title: Basic package diagram test case