Added relationship decorators

This commit is contained in:
Bartek Kryza
2021-07-31 19:15:55 +02:00
parent 3f8100a050
commit 841f97eeb5
13 changed files with 366 additions and 13 deletions

12
tests/t00029/.clang-uml Normal file
View File

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

53
tests/t00029/t00029.cc Normal file
View File

@@ -0,0 +1,53 @@
#include <memory>
#include <vector>
namespace clanguml {
namespace t00029 {
class A {
};
/// \uml{skip}
class B {
};
template <typename T> class C {
T param;
};
/// @uml{skip:t00029_class}
template <typename T> class D {
T param;
};
enum class E { one, two, three };
/// \uml{skip}
enum class F { red, green, blue };
class G1 {
};
class G2 {
};
class G3 {
};
class G4 {
};
struct R {
G1 g1;
/// \uml{skip}
G2 g2;
/// \uml{skiprelationship}
G3 &g3;
std::shared_ptr<G4> g4;
};
} // namespace t00029
} // namespace clanguml

65
tests/t00029/test_case.h Normal file
View File

@@ -0,0 +1,65 @@
/**
* tests/t00029/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("t00029", "[test-case][class]")
{
auto [config, db] = load_config("t00029");
auto diagram = config.diagrams["t00029_class"];
REQUIRE(diagram->name == "t00029_class");
REQUIRE(diagram->include.namespaces.size() == 1);
REQUIRE_THAT(diagram->include.namespaces,
VectorContains(std::string{"clanguml::t00029"}));
REQUIRE(diagram->exclude.namespaces.size() == 0);
REQUIRE(diagram->should_include("clanguml::t00029::A"));
auto model = generate_class_diagram(db, diagram);
REQUIRE(model.name == "t00029_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, IsClassTemplate("C", "T"));
REQUIRE_THAT(puml, IsClassTemplate("D", "T"));
REQUIRE_THAT(puml, IsEnum(_A("E")));
REQUIRE_THAT(puml, !IsEnum(_A("F")));
REQUIRE_THAT(puml, IsClass(_A("G1")));
REQUIRE_THAT(puml, IsClass(_A("G2")));
REQUIRE_THAT(puml, IsClass(_A("G3")));
REQUIRE_THAT(puml, IsClass(_A("G4")));
REQUIRE_THAT(puml, IsClass(_A("R")));
REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("G1"), "+g1"));
REQUIRE_THAT(puml, !IsAggregation(_A("R"), _A("G2"), "+g2"));
REQUIRE_THAT(puml, !IsAggregation(_A("R"), _A("G3"), "+g3"));
REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("G4"), "+g4"));
save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
}

12
tests/t00030/.clang-uml Normal file
View File

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

34
tests/t00030/t00030.cc Normal file
View File

@@ -0,0 +1,34 @@
#include <memory>
#include <vector>
namespace clanguml {
namespace t00030 {
class A {
};
class B {
};
class C {
};
class D {
};
struct R {
/// @uml{association[]}
A aaa;
/// @uml{composition[0..1:1..*]}
std::vector<B> bbb;
/// @uml{aggregation[0..1:1..5]}
std::vector<C> ccc;
/// @uml{association[:1]}
D ddd;
};
} // namespace t00030
} // namespace clanguml

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

@@ -0,0 +1,57 @@
/**
* tests/t00030/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("t00030", "[test-case][class]")
{
auto [config, db] = load_config("t00030");
auto diagram = config.diagrams["t00030_class"];
REQUIRE(diagram->name == "t00030_class");
REQUIRE(diagram->include.namespaces.size() == 1);
REQUIRE_THAT(diagram->include.namespaces,
VectorContains(std::string{"clanguml::t00030"}));
REQUIRE(diagram->exclude.namespaces.size() == 0);
REQUIRE(diagram->should_include("clanguml::t00030::A"));
auto model = generate_class_diagram(db, diagram);
REQUIRE(model.name == "t00030_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, IsAssociation(_A("R"), _A("A"), "+aaa"));
REQUIRE_THAT(puml, IsComposition(_A("R"), _A("B"), "+bbb", "0..1", "1..*"));
REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("C"), "+ccc", "0..1", "1..5"));
REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("D"), "+ddd", "", "1"));
save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
}

View File

@@ -133,6 +133,7 @@ using namespace clanguml::test::matchers;
#include "t00027/test_case.h"
#include "t00028/test_case.h"
#include "t00029/test_case.h"
#include "t00030/test_case.h"
//
// Sequence diagram tests

View File

@@ -217,11 +217,23 @@ ContainsMatcher IsInnerClass(std::string const &parent,
}
ContainsMatcher IsAssociation(std::string const &from, std::string const &to,
std::string const &label,
std::string const &label, std::string multiplicity_source = "",
std::string multiplicity_dest = "",
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{
std::string format_string = "{}";
if (!multiplicity_source.empty())
format_string += " \"" + multiplicity_source + "\"";
format_string += " -->";
if (!multiplicity_dest.empty())
format_string += " \"" + multiplicity_dest + "\"";
format_string += " {} : {}";
return ContainsMatcher(CasedString(
fmt::format("{} --> {} : {}", from, to, label), caseSensitivity));
fmt::format(format_string, from, to, label), caseSensitivity));
}
ContainsMatcher IsFriend(std::string const &from, std::string const &to,
@@ -232,19 +244,43 @@ ContainsMatcher IsFriend(std::string const &from, std::string const &to,
}
ContainsMatcher IsComposition(std::string const &from, std::string const &to,
std::string const &label,
std::string const &label, std::string multiplicity_source = "",
std::string multiplicity_dest = "",
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{
std::string format_string = "{}";
if (!multiplicity_source.empty())
format_string += " \"" + multiplicity_source + "\"";
format_string += " *--";
if (!multiplicity_dest.empty())
format_string += " \"" + multiplicity_dest + "\"";
format_string += " {} : {}";
return ContainsMatcher(CasedString(
fmt::format("{} *-- {} : {}", from, to, label), caseSensitivity));
fmt::format(format_string, from, to, label), caseSensitivity));
}
ContainsMatcher IsAggregation(std::string const &from, std::string const &to,
std::string const &label,
std::string const &label, std::string multiplicity_source = "",
std::string multiplicity_dest = "",
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{
std::string format_string = "{}";
if (!multiplicity_source.empty())
format_string += " \"" + multiplicity_source + "\"";
format_string += " o--";
if (!multiplicity_dest.empty())
format_string += " \"" + multiplicity_dest + "\"";
format_string += " {} : {}";
return ContainsMatcher(CasedString(
fmt::format("{} o-- {} : {}", from, to, label), caseSensitivity));
fmt::format(format_string, from, to, label), caseSensitivity));
}
ContainsMatcher IsInstantiation(std::string const &from, std::string const &to,