Added standard container sequence diagram test case

This commit is contained in:
Bartek Kryza
2022-11-30 20:21:37 +01:00
parent 115ede3cc7
commit 73f399c8a0
6 changed files with 114 additions and 0 deletions

View File

@@ -85,6 +85,11 @@ void diagram::print() const
LOG_DBG(" Activity id={}, from={}:", act.from,
from_activity.full_name(false));
for (const auto &message : act.messages) {
if (participants.find(message.from) == participants.end())
continue;
if (participants.find(message.to) == participants.end())
continue;
const auto &from_participant = *participants.at(message.from);
const auto &to_participant = *participants.at(message.to);

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

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

39
tests/t20010/t20010.cc Normal file
View File

@@ -0,0 +1,39 @@
#include <array>
#include <map>
#include <memory>
#include <vector>
namespace clanguml {
namespace t20010 {
struct A {
void a1() { }
void a2() { }
void a3() { }
void a4() { }
};
template <typename T> struct B {
void b1() { a_.a1(); }
void b2() { avector_.front().a2(); }
void b3() { aptrvector_.front()->a3(); }
void b4() { amap_.at(0).a4(); }
A a_;
std::vector<A> avector_;
std::vector<std::unique_ptr<A>> aptrvector_;
std::map<T, A> amap_;
};
void tmain()
{
B<int> b;
b.b1();
b.b2();
b.b3();
b.b4();
}
}
}

52
tests/t20010/test_case.h Normal file
View File

@@ -0,0 +1,52 @@
/**
* tests/t20010/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("t20010", "[test-case][sequence]")
{
auto [config, db] = load_config("t20010");
auto diagram = config.diagrams["t20010_sequence"];
REQUIRE(diagram->name == "t20010_sequence");
auto model = generate_sequence_diagram(*db, diagram);
REQUIRE(model->name() == "t20010_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("B<int>"), "b1"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A"), "a1"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b2"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A"), "a2"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b3"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A"), "a3"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b4"));
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A"), "a4"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -256,6 +256,7 @@ using namespace clanguml::test::matchers;
#include "t20007/test_case.h"
#include "t20008/test_case.h"
#include "t20009/test_case.h"
#include "t20010/test_case.h"
///
/// Package diagram tests

View File

@@ -175,6 +175,9 @@ test_cases:
- name: t20009
title: Smart pointer dereference call expression test case
description:
- name: t20010
title: Container sequence diagram test case
description:
Package diagrams:
- name: t30001
title: Basic package diagram test case