Make sure sequence diagram messages generated during static variable initialization are rendered only once
This commit is contained in:
14
tests/t20037/.clang-uml
Normal file
14
tests/t20037/.clang-uml
Normal file
@@ -0,0 +1,14 @@
|
||||
compilation_database_dir: ..
|
||||
output_directory: diagrams
|
||||
diagrams:
|
||||
t20037_sequence:
|
||||
type: sequence
|
||||
glob:
|
||||
- ../../tests/t20037/t20037.cc
|
||||
include:
|
||||
namespaces:
|
||||
- clanguml::t20037
|
||||
using_namespace:
|
||||
- clanguml::t20037
|
||||
from:
|
||||
- function: "clanguml::t20037::tmain(int,char **)"
|
||||
38
tests/t20037/t20037.cc
Normal file
38
tests/t20037/t20037.cc
Normal file
@@ -0,0 +1,38 @@
|
||||
namespace clanguml {
|
||||
namespace t20037 {
|
||||
|
||||
struct A {
|
||||
A()
|
||||
: a{100}
|
||||
{
|
||||
}
|
||||
|
||||
int a;
|
||||
};
|
||||
|
||||
struct B {
|
||||
int get() { return b; }
|
||||
|
||||
int b{100};
|
||||
};
|
||||
|
||||
B initb() { return B{}; }
|
||||
|
||||
int c() { return 1; }
|
||||
|
||||
int a()
|
||||
{
|
||||
static A a;
|
||||
static B b = initb();
|
||||
|
||||
return a.a + b.get() + c();
|
||||
}
|
||||
|
||||
void tmain(int argc, char **argv)
|
||||
{
|
||||
auto a1 = a();
|
||||
auto a2 = a();
|
||||
auto a3 = a();
|
||||
}
|
||||
}
|
||||
}
|
||||
75
tests/t20037/test_case.h
Normal file
75
tests/t20037/test_case.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* tests/t20037/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("t20037", "[test-case][sequence]")
|
||||
{
|
||||
auto [config, db] = load_config("t20037");
|
||||
|
||||
auto diagram = config.diagrams["t20037_sequence"];
|
||||
|
||||
REQUIRE(diagram->name == "t20037_sequence");
|
||||
|
||||
auto model = generate_sequence_diagram(*db, diagram);
|
||||
|
||||
REQUIRE(model->name() == "t20037_sequence");
|
||||
|
||||
{
|
||||
auto src = generate_sequence_puml(diagram, *model);
|
||||
AliasMatcher _A(src);
|
||||
|
||||
REQUIRE_THAT(src, StartsWith("@startuml"));
|
||||
REQUIRE_THAT(src, EndsWith("@enduml\n"));
|
||||
|
||||
REQUIRE_THAT(src, HasCall(_A("tmain(int,char **)"), _A("a()"), ""));
|
||||
REQUIRE_THAT(src, HasCall(_A("a()"), _A("initb()"), ""));
|
||||
REQUIRE_THAT(src, HasCall(_A("a()"), _A("B"), "get()"));
|
||||
REQUIRE_THAT(src, HasCall(_A("a()"), _A("c()"), ""));
|
||||
|
||||
save_puml(config.output_directory(), diagram->name + ".puml", src);
|
||||
}
|
||||
|
||||
{
|
||||
auto j = generate_sequence_json(diagram, *model);
|
||||
|
||||
using namespace json;
|
||||
|
||||
std::vector<int> messages = {
|
||||
FindMessage(j, "tmain(int,char **)", "a()", ""),
|
||||
FindMessage(j, "a()", "initb()", ""),
|
||||
FindMessage(j, "a()", "B", "get()"),
|
||||
FindMessage(j, "a()", "c()", "")};
|
||||
|
||||
REQUIRE(std::is_sorted(messages.begin(), messages.end()));
|
||||
|
||||
save_json(config.output_directory(), diagram->name + ".json", j);
|
||||
}
|
||||
|
||||
{
|
||||
auto src = generate_sequence_mermaid(diagram, *model);
|
||||
|
||||
mermaid::SequenceDiagramAliasMatcher _A(src);
|
||||
using mermaid::HasCall;
|
||||
|
||||
REQUIRE_THAT(src, HasCall(_A("tmain(int,char **)"), _A("a()"), ""));
|
||||
REQUIRE_THAT(src, HasCall(_A("a()"), _A("initb()"), ""));
|
||||
REQUIRE_THAT(src, HasCall(_A("a()"), _A("B"), "get()"));
|
||||
REQUIRE_THAT(src, HasCall(_A("a()"), _A("c()"), ""));
|
||||
|
||||
save_mermaid(config.output_directory(), diagram->name + ".mmd", src);
|
||||
}
|
||||
}
|
||||
@@ -423,6 +423,7 @@ using namespace clanguml::test::matchers;
|
||||
#include "t20034/test_case.h"
|
||||
#include "t20035/test_case.h"
|
||||
#include "t20036/test_case.h"
|
||||
#include "t20037/test_case.h"
|
||||
|
||||
///
|
||||
/// Package diagram tests
|
||||
|
||||
@@ -307,6 +307,9 @@ test_cases:
|
||||
- name: t20036
|
||||
title: Test case for rendering all call chains leading to an activity (to)
|
||||
description:
|
||||
- name: t20037
|
||||
title: Test case checking if activities in static variable declarations appear only once
|
||||
description:
|
||||
Package diagrams:
|
||||
- name: t30001
|
||||
title: Basic package diagram test case
|
||||
|
||||
Reference in New Issue
Block a user