Added basic class relationship handling

This commit is contained in:
Bartek Kryza
2021-02-28 19:13:15 +01:00
parent e885149cf0
commit e4d77db5c0
11 changed files with 324 additions and 69 deletions

12
tests/t00005/.clanguml Normal file
View File

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

55
tests/t00005/t00005.cc Normal file
View File

@@ -0,0 +1,55 @@
namespace clanguml {
namespace t00005 {
class A {
};
class B {
};
class C {
};
class D {
};
class E {
};
class F {
};
class G {
};
class H {
};
class I {
};
class J {
};
class K {
};
class R {
public:
int some_int;
int *some_int_pointer;
int **some_int_pointer_pointer;
int &some_int_reference;
A a;
B *b;
C &c;
const D *d;
const E &e{};
F &&f;
G **g;
H ***h;
I *&i;
volatile J *j;
mutable K *k;
};
}
}

79
tests/t00005/test_case.h Normal file
View File

@@ -0,0 +1,79 @@
/**
* tests/t00005/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("Test t00005", "[unit-test]")
{
spdlog::set_level(spdlog::level::debug);
auto [config, db] = load_config("t00005");
auto diagram = config.diagrams["t00005_class"];
REQUIRE(diagram->name == "t00005_class");
REQUIRE(diagram->include.namespaces.size() == 1);
REQUIRE_THAT(diagram->include.namespaces,
VectorContains(std::string{"clanguml::t00005"}));
REQUIRE(diagram->exclude.namespaces.size() == 0);
REQUIRE(diagram->should_include("clanguml::t00005::A"));
REQUIRE(diagram->should_include("clanguml::t00005::B"));
REQUIRE(diagram->should_include("clanguml::t00005::C"));
REQUIRE(diagram->should_include("clanguml::t00005::D"));
auto model = generate_class_diagram(db, diagram);
REQUIRE(model.name == "t00005_class");
auto puml = generate_class_puml(diagram, model);
REQUIRE_THAT(puml, StartsWith("@startuml"));
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
REQUIRE_THAT(puml, IsClass("A"));
REQUIRE_THAT(puml, IsClass("B"));
REQUIRE_THAT(puml, IsClass("C"));
REQUIRE_THAT(puml, IsClass("D"));
REQUIRE_THAT(puml, IsClass("E"));
REQUIRE_THAT(puml, IsClass("F"));
REQUIRE_THAT(puml, IsClass("G"));
REQUIRE_THAT(puml, IsClass("H"));
REQUIRE_THAT(puml, IsClass("I"));
REQUIRE_THAT(puml, IsClass("J"));
REQUIRE_THAT(puml, IsClass("K"));
REQUIRE_THAT(puml, IsClass("R"));
REQUIRE_THAT(puml, IsField(Public("int some_int")));
REQUIRE_THAT(puml, IsField(Public("int * some_int_pointer")));
REQUIRE_THAT(puml, IsField(Public("int ** some_int_pointer_pointer")));
REQUIRE_THAT(puml, IsComposition("R", "A", "a"));
REQUIRE_THAT(puml, IsAssociation("R", "B", "b"));
REQUIRE_THAT(puml, IsAssociation("R", "C", "c"));
REQUIRE_THAT(puml, IsAssociation("R", "D", "d"));
REQUIRE_THAT(puml, IsAssociation("R", "E", "e"));
REQUIRE_THAT(puml, IsComposition("R", "F", "f"));
REQUIRE_THAT(puml, IsAssociation("R", "G", "g"));
REQUIRE_THAT(puml, IsAssociation("R", "H", "h"));
REQUIRE_THAT(puml, IsAssociation("R", "I", "i"));
REQUIRE_THAT(puml, IsAssociation("R", "J", "j"));
REQUIRE_THAT(puml, IsAssociation("R", "K", "k"));
save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
}

View File

@@ -96,9 +96,13 @@ using clanguml::test::matchers::Default;
using clanguml::test::matchers::HasCall;
using clanguml::test::matchers::HasCallWithResponse;
using clanguml::test::matchers::IsAbstractClass;
using clanguml::test::matchers::IsAggregation;
using clanguml::test::matchers::IsAssociation;
using clanguml::test::matchers::IsBaseClass;
using clanguml::test::matchers::IsClass;
using clanguml::test::matchers::IsComposition;
using clanguml::test::matchers::IsEnum;
using clanguml::test::matchers::IsField;
using clanguml::test::matchers::IsInnerClass;
using clanguml::test::matchers::Private;
using clanguml::test::matchers::Protected;
@@ -109,3 +113,4 @@ using clanguml::test::matchers::Static;
#include "t00002/test_case.h"
#include "t00003/test_case.h"
#include "t00004/test_case.h"
#include "t00005/test_case.h"

View File

@@ -222,6 +222,30 @@ ContainsMatcher IsInnerClass(std::string const &parent,
CasedString(parent + " +-- " + inner, caseSensitivity));
}
ContainsMatcher IsAssociation(std::string const &from, std::string const &to,
std::string const &label,
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{
return ContainsMatcher(CasedString(
fmt::format("{} --> {} : {}", from, to, label), caseSensitivity));
}
ContainsMatcher IsComposition(std::string const &from, std::string const &to,
std::string const &label,
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{
return ContainsMatcher(CasedString(
fmt::format("{} *-- {} : {}", from, to, label), caseSensitivity));
}
ContainsMatcher IsAggregation(std::string const &from, std::string const &to,
std::string const &label,
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{
return ContainsMatcher(CasedString(
fmt::format("{} o-- {} : {}", from, to, label), caseSensitivity));
}
ContainsMatcher IsMethod(std::string const &name,
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{