Added support for switch statements in sequence diagrams

This commit is contained in:
Bartek Kryza
2022-12-13 21:09:00 +01:00
parent 2d72d98234
commit bd61a1540e
16 changed files with 373 additions and 33 deletions

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

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

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

@@ -0,0 +1,65 @@
namespace clanguml {
namespace t20024 {
enum enum_a { zero = 0, one = 1, two = 2, three = 3 };
enum class colors { red, orange, green };
struct A {
int select(enum_a v)
{
switch (v) {
case zero:
return a0();
case one:
return a1();
case two:
return a2();
default:
return a3();
}
}
int a0() { return 0; }
int a1() { return 1; }
int a2() { return 2; }
int a3() { return 3; }
};
struct B {
void select(colors c)
{
switch (c) {
case colors::red:
red();
break;
case colors::orange:
orange();
break;
case colors::green:
green();
break;
default:
grey();
}
}
void red() { }
void orange() { }
void green() { }
void grey() { }
};
int tmain()
{
A a;
B b;
a.select(enum_a::two);
b.select(colors::green);
return 0;
}
}
}

51
tests/t20024/test_case.h Normal file
View File

@@ -0,0 +1,51 @@
/**
* tests/t20024/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("t20024", "[test-case][sequence]")
{
auto [config, db] = load_config("t20024");
auto diagram = config.diagrams["t20024_sequence"];
REQUIRE(diagram->name == "t20024_sequence");
auto model = generate_sequence_diagram(*db, diagram);
REQUIRE(model->name() == "t20024_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"), "select(enum_a)"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "a0()"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "a1()"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "a2()"));
REQUIRE_THAT(puml, HasCall(_A("A"), _A("A"), "a3()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "select(colors)"));
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "red()"));
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "orange()"));
REQUIRE_THAT(puml, HasCall(_A("B"), _A("B"), "green()"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -270,6 +270,7 @@ using namespace clanguml::test::matchers;
#include "t20021/test_case.h"
#include "t20022/test_case.h"
#include "t20023/test_case.h"
#include "t20024/test_case.h"
///
/// Package diagram tests

View File

@@ -217,6 +217,9 @@ test_cases:
- name: t20023
title: Try/catch statement sequence diagram test case
description:
- name: t20024
title: Switch statement sequence diagram test case
description:
Package diagrams:
- name: t30001
title: Basic package diagram test case