Added test case for filtering methods based on access specifier in sequence diagrams
This commit is contained in:
@@ -41,28 +41,6 @@ using clanguml::common::model::namespace_;
|
||||
using clanguml::common::model::relationship;
|
||||
using clanguml::common::model::relationship_t;
|
||||
|
||||
namespace detail {
|
||||
access_t access_specifier_to_access_t(clang::AccessSpecifier access_specifier)
|
||||
{
|
||||
auto access = access_t::kPublic;
|
||||
switch (access_specifier) {
|
||||
case clang::AccessSpecifier::AS_public:
|
||||
access = access_t::kPublic;
|
||||
break;
|
||||
case clang::AccessSpecifier::AS_private:
|
||||
access = access_t::kPrivate;
|
||||
break;
|
||||
case clang::AccessSpecifier::AS_protected:
|
||||
access = access_t::kProtected;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return access;
|
||||
}
|
||||
}
|
||||
|
||||
translation_unit_visitor::translation_unit_visitor(clang::SourceManager &sm,
|
||||
clanguml::class_diagram::model::diagram &diagram,
|
||||
const clanguml::config::class_diagram &config)
|
||||
@@ -668,7 +646,7 @@ void translation_unit_visitor::process_class_bases(
|
||||
cp.is_virtual(base.isVirtual());
|
||||
|
||||
cp.set_access(
|
||||
detail::access_specifier_to_access_t(base.getAccessSpecifier()));
|
||||
common::access_specifier_to_access_t(base.getAccessSpecifier()));
|
||||
|
||||
LOG_DBG("Found base class {} [{}] for class {}", cp.name(), cp.id(),
|
||||
c.name());
|
||||
@@ -725,7 +703,7 @@ void translation_unit_visitor::process_template_specialization_children(
|
||||
|
||||
if (enum_decl->getNameAsString().empty()) {
|
||||
for (const auto *enum_const : enum_decl->enumerators()) {
|
||||
class_member m{detail::access_specifier_to_access_t(
|
||||
class_member m{common::access_specifier_to_access_t(
|
||||
enum_decl->getAccess()),
|
||||
enum_const->getNameAsString(), "enum"};
|
||||
c.add_member(std::move(m));
|
||||
@@ -787,7 +765,7 @@ void translation_unit_visitor::process_class_children(
|
||||
|
||||
if (enum_decl->getNameAsString().empty()) {
|
||||
for (const auto *enum_const : enum_decl->enumerators()) {
|
||||
class_member m{detail::access_specifier_to_access_t(
|
||||
class_member m{common::access_specifier_to_access_t(
|
||||
enum_decl->getAccess()),
|
||||
enum_const->getNameAsString(), "enum"};
|
||||
c.add_member(std::move(m));
|
||||
@@ -818,7 +796,7 @@ void translation_unit_visitor::process_friend(
|
||||
if (diagram().should_include(friend_type_name)) {
|
||||
relationship r{relationship_t::kFriendship,
|
||||
common::to_id(*friend_type->getAsRecordDecl()),
|
||||
detail::access_specifier_to_access_t(f.getAccess()),
|
||||
common::access_specifier_to_access_t(f.getAccess()),
|
||||
"<<friend>>"};
|
||||
|
||||
c.add_relationship(std::move(r));
|
||||
@@ -835,7 +813,7 @@ void translation_unit_visitor::process_method(
|
||||
if (mf.isDefaulted() && !mf.isExplicitlyDefaulted())
|
||||
return;
|
||||
|
||||
class_method method{detail::access_specifier_to_access_t(mf.getAccess()),
|
||||
class_method method{common::access_specifier_to_access_t(mf.getAccess()),
|
||||
util::trim(mf.getNameAsString()),
|
||||
common::to_string(mf.getReturnType(), mf.getASTContext())};
|
||||
|
||||
@@ -869,7 +847,7 @@ void translation_unit_visitor::process_template_method(
|
||||
!mf.getTemplatedDecl()->isExplicitlyDefaulted())
|
||||
return;
|
||||
|
||||
class_method method{detail::access_specifier_to_access_t(mf.getAccess()),
|
||||
class_method method{common::access_specifier_to_access_t(mf.getAccess()),
|
||||
util::trim(mf.getNameAsString()),
|
||||
mf.getTemplatedDecl()->getReturnType().getAsString()};
|
||||
|
||||
@@ -1133,7 +1111,7 @@ void translation_unit_visitor::process_static_field(
|
||||
type_name = "<<anonymous>>";
|
||||
|
||||
class_member field{
|
||||
detail::access_specifier_to_access_t(field_declaration.getAccess()),
|
||||
common::access_specifier_to_access_t(field_declaration.getAccess()),
|
||||
field_declaration.getNameAsString(), type_name};
|
||||
field.is_static(true);
|
||||
|
||||
@@ -1981,7 +1959,7 @@ void translation_unit_visitor::process_field(
|
||||
const auto field_name = field_declaration.getNameAsString();
|
||||
|
||||
class_member field{
|
||||
detail::access_specifier_to_access_t(field_declaration.getAccess()),
|
||||
common::access_specifier_to_access_t(field_declaration.getAccess()),
|
||||
field_name,
|
||||
common::to_string(
|
||||
field_type, field_declaration.getASTContext(), false)};
|
||||
|
||||
@@ -22,6 +22,27 @@
|
||||
|
||||
namespace clanguml::common {
|
||||
|
||||
model::access_t access_specifier_to_access_t(
|
||||
clang::AccessSpecifier access_specifier)
|
||||
{
|
||||
auto access = model::access_t::kPublic;
|
||||
switch (access_specifier) {
|
||||
case clang::AccessSpecifier::AS_public:
|
||||
access = model::access_t::kPublic;
|
||||
break;
|
||||
case clang::AccessSpecifier::AS_private:
|
||||
access = model::access_t::kPrivate;
|
||||
break;
|
||||
case clang::AccessSpecifier::AS_protected:
|
||||
access = model::access_t::kProtected;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return access;
|
||||
}
|
||||
|
||||
std::optional<clanguml::common::model::namespace_> get_enclosing_namespace(
|
||||
const clang::DeclContext *decl)
|
||||
{
|
||||
|
||||
@@ -31,6 +31,9 @@ class NamespaceDecl;
|
||||
}
|
||||
|
||||
namespace clanguml::common {
|
||||
model::access_t access_specifier_to_access_t(
|
||||
clang::AccessSpecifier access_specifier);
|
||||
|
||||
std::string get_tag_name(const clang::TagDecl &declaration);
|
||||
|
||||
template <typename T> std::string get_qualified_name(const T &declaration)
|
||||
|
||||
@@ -991,6 +991,10 @@ bool translation_unit_visitor::process_class_method_call_expression(
|
||||
diagram().should_include(callee_decl->getQualifiedNameAsString())))
|
||||
return false;
|
||||
|
||||
if (!diagram().should_include(
|
||||
common::access_specifier_to_access_t(method_decl->getAccess())))
|
||||
return false;
|
||||
|
||||
m.set_to(method_decl->getID());
|
||||
m.set_message_name(method_decl->getNameAsString());
|
||||
m.set_return_type(
|
||||
|
||||
16
tests/t20027/.clang-uml
Normal file
16
tests/t20027/.clang-uml
Normal file
@@ -0,0 +1,16 @@
|
||||
compilation_database_dir: ..
|
||||
output_directory: puml
|
||||
diagrams:
|
||||
t20027_sequence:
|
||||
type: sequence
|
||||
glob:
|
||||
- ../../tests/t20027/t20027.cc
|
||||
include:
|
||||
namespaces:
|
||||
- clanguml::t20027
|
||||
access:
|
||||
- public
|
||||
using_namespace:
|
||||
- clanguml::t20027
|
||||
start_from:
|
||||
- function: "clanguml::t20027::tmain()"
|
||||
22
tests/t20027/t20027.cc
Normal file
22
tests/t20027/t20027.cc
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace clanguml {
|
||||
namespace t20027 {
|
||||
|
||||
class A {
|
||||
public:
|
||||
void a() { aa(); }
|
||||
|
||||
protected:
|
||||
void aa() { aaa(); }
|
||||
|
||||
private:
|
||||
void aaa() { }
|
||||
};
|
||||
|
||||
void tmain()
|
||||
{
|
||||
A a;
|
||||
|
||||
a.a();
|
||||
}
|
||||
}
|
||||
}
|
||||
44
tests/t20027/test_case.h
Normal file
44
tests/t20027/test_case.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* tests/t20027/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("t20027", "[test-case][sequence]")
|
||||
{
|
||||
auto [config, db] = load_config("t20027");
|
||||
|
||||
auto diagram = config.diagrams["t20027_sequence"];
|
||||
|
||||
REQUIRE(diagram->name == "t20027_sequence");
|
||||
|
||||
auto model = generate_sequence_diagram(*db, diagram);
|
||||
|
||||
REQUIRE(model->name() == "t20027_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"), "a()"));
|
||||
REQUIRE_THAT(puml, !HasCall(_A("A"), _A("A"), "aa()"));
|
||||
REQUIRE_THAT(puml, !HasCall(_A("A"), _A("A"), "aaa()"));
|
||||
|
||||
save_puml(
|
||||
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||
}
|
||||
@@ -273,6 +273,7 @@ using namespace clanguml::test::matchers;
|
||||
#include "t20024/test_case.h"
|
||||
#include "t20025/test_case.h"
|
||||
#include "t20026/test_case.h"
|
||||
#include "t20027/test_case.h"
|
||||
|
||||
///
|
||||
/// Package diagram tests
|
||||
|
||||
@@ -226,6 +226,9 @@ test_cases:
|
||||
- name: t20026
|
||||
title: Virtual method call sequence diagram test case
|
||||
description:
|
||||
- name: t20027
|
||||
title: Filter call expressions based on access test case
|
||||
description:
|
||||
Package diagrams:
|
||||
- name: t30001
|
||||
title: Basic package diagram test case
|
||||
|
||||
Reference in New Issue
Block a user