Added generation of dependency relations based on method params

This commit is contained in:
Bartek Kryza
2021-03-18 23:14:40 +01:00
parent d55e57eb05
commit 2322833897
8 changed files with 133 additions and 14 deletions

12
tests/t00013/.clanguml Normal file
View File

@@ -0,0 +1,12 @@
compilation_database_dir: ..
output_directory: puml
diagrams:
t00013_class:
type: class
glob:
- ../../tests/t00013/t00013.cc
using_namespace:
- clanguml::t00013
include:
namespaces:
- clanguml::t00013

38
tests/t00013/t00013.cc Normal file
View File

@@ -0,0 +1,38 @@
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <variant>
namespace clanguml {
namespace t00013 {
struct A {
int a;
};
struct B {
int b;
};
struct C {
int c;
};
class R;
struct D {
int d;
void print(R *r) {}
};
class R {
public:
int get_a(A *a) { return a->a; }
int get_b(B &b) { return b.b; }
// TODO: int get_b(const B &b) { return b.b; }
int get_c(C c) { return c.c; }
int get_d(D &&d) { return d.d; }
};
}
}

57
tests/t00013/test_case.h Normal file
View File

@@ -0,0 +1,57 @@
/**
* tests/t00013/test_case.cc
*
* Copyright (c) 2021 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("t00013", "[test-case][class]")
{
auto [config, db] = load_config("t00013");
auto diagram = config.diagrams["t00013_class"];
REQUIRE(diagram->name == "t00013_class");
REQUIRE(diagram->include.namespaces.size() == 1);
REQUIRE_THAT(diagram->include.namespaces,
VectorContains(std::string{"clanguml::t00013"}));
REQUIRE(diagram->exclude.namespaces.size() == 0);
REQUIRE(diagram->should_include("clanguml::t00013::A"));
REQUIRE(diagram->should_include("clanguml::t00013::B"));
auto model = generate_class_diagram(db, diagram);
REQUIRE(model.name == "t00013_class");
auto puml = generate_class_puml(diagram, model);
AliasMatcher _A(puml);
REQUIRE_THAT(puml, StartsWith("@startuml"));
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
REQUIRE_THAT(puml, IsClass(_A("A")));
REQUIRE_THAT(puml, IsClass(_A("B")));
REQUIRE_THAT(puml, IsClass(_A("C")));
REQUIRE_THAT(puml, IsClass(_A("D")));
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("A")));
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("B")));
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("C")));
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("D")));
REQUIRE_THAT(puml, IsDependency(_A("D"), _A("R")));
save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
}

View File

@@ -15,8 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//#define CATCH_CONFIG_MAIN
#include "test_cases.h"
#include <spdlog/spdlog.h>
@@ -105,6 +103,7 @@ using clanguml::test::matchers::IsBaseClass;
using clanguml::test::matchers::IsClass;
using clanguml::test::matchers::IsClassTemplate;
using clanguml::test::matchers::IsComposition;
using clanguml::test::matchers::IsDependency;
using clanguml::test::matchers::IsEnum;
using clanguml::test::matchers::IsField;
using clanguml::test::matchers::IsFriend;
@@ -129,6 +128,7 @@ using clanguml::test::matchers::Static;
#include "t00010/test_case.h"
#include "t00011/test_case.h"
#include "t00012/test_case.h"
#include "t00013/test_case.h"
//
// Sequence diagram tests

View File

@@ -304,6 +304,13 @@ ContainsMatcher IsInstantiation(std::string const &from, std::string const &to,
CasedString(fmt::format("{} ..|> {}", to, from), caseSensitivity));
}
ContainsMatcher IsDependency(std::string const &from, std::string const &to,
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{
return ContainsMatcher(
CasedString(fmt::format("{} ..> {}", from, to), caseSensitivity));
}
ContainsMatcher IsMethod(std::string const &name,
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{