Added layer cake patter
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
* [t00016](./test_cases/t00016.md) - Unnamed enums and empty templates
|
* [t00016](./test_cases/t00016.md) - Unnamed enums and empty templates
|
||||||
* [t00017](./test_cases/t00017.md) - Test include relations also as members flag
|
* [t00017](./test_cases/t00017.md) - Test include relations also as members flag
|
||||||
* [t00018](./test_cases/t00018.md) - Pimpl pattern
|
* [t00018](./test_cases/t00018.md) - Pimpl pattern
|
||||||
|
* [t00019](./test_cases/t00019.md) - Layercake pattern
|
||||||
## Sequence diagrams
|
## Sequence diagrams
|
||||||
* [t20001](./test_cases/t20001.md) - Basic sequence diagram
|
* [t20001](./test_cases/t20001.md) - Basic sequence diagram
|
||||||
## Configuration diagrams
|
## Configuration diagrams
|
||||||
|
|||||||
160
docs/test_cases/t00019.md
Normal file
160
docs/test_cases/t00019.md
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
# t00019 - Layercake pattern
|
||||||
|
## Config
|
||||||
|
```yaml
|
||||||
|
compilation_database_dir: ..
|
||||||
|
output_directory: puml
|
||||||
|
diagrams:
|
||||||
|
t00019_class:
|
||||||
|
type: class
|
||||||
|
glob:
|
||||||
|
- ../../tests/t00019/**.h
|
||||||
|
- ../../tests/t00019/**.cc
|
||||||
|
using_namespace:
|
||||||
|
- clanguml::t00019
|
||||||
|
include:
|
||||||
|
namespaces:
|
||||||
|
- clanguml::t00019
|
||||||
|
plantuml:
|
||||||
|
after:
|
||||||
|
- '@A(Base) <|-- @A(Layer3<LowerLayer>)'
|
||||||
|
- '@A(Layer3<LowerLayer>) <|-- @A(Layer2<LowerLayer>)'
|
||||||
|
- '@A(Layer2<LowerLayer>) <|-- @A(Layer1<LowerLayer>)'
|
||||||
|
|
||||||
|
```
|
||||||
|
## Source code
|
||||||
|
File t00019_layer2.h
|
||||||
|
```cpp
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00019 {
|
||||||
|
|
||||||
|
template <typename LowerLayer> class Layer2 : public LowerLayer {
|
||||||
|
|
||||||
|
using LowerLayer::LowerLayer;
|
||||||
|
|
||||||
|
using LowerLayer::m1;
|
||||||
|
|
||||||
|
using LowerLayer::m2;
|
||||||
|
|
||||||
|
int all_calls_count() const
|
||||||
|
{
|
||||||
|
return LowerLayer::m1_calls() + LowerLayer::m2_calls();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
File t00019_base.h
|
||||||
|
```cpp
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00019 {
|
||||||
|
|
||||||
|
class Base {
|
||||||
|
|
||||||
|
Base() = default;
|
||||||
|
|
||||||
|
virtual ~Base() = default;
|
||||||
|
|
||||||
|
virtual int m1() { return 2; }
|
||||||
|
|
||||||
|
virtual std::string m2() { return "two"; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
File t00019_layer1.h
|
||||||
|
```cpp
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00019 {
|
||||||
|
|
||||||
|
template <typename LowerLayer> class Layer1 : public LowerLayer {
|
||||||
|
|
||||||
|
using LowerLayer::LowerLayer;
|
||||||
|
|
||||||
|
int m1() override
|
||||||
|
{
|
||||||
|
std::cout << "m1 called\n";
|
||||||
|
return LowerLayer::m1();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string m2() override
|
||||||
|
{
|
||||||
|
std::cout << "m2 called\n";
|
||||||
|
return LowerLayer::m2();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
File t00019.cc
|
||||||
|
```cpp
|
||||||
|
#include "t00019_base.h"
|
||||||
|
#include "t00019_layer1.h"
|
||||||
|
#include "t00019_layer2.h"
|
||||||
|
#include "t00019_layer3.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00019 {
|
||||||
|
|
||||||
|
class A {
|
||||||
|
public:
|
||||||
|
std::unique_ptr<Layer1<Layer2<Layer3<Base>>>> layers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
File t00019_layer3.h
|
||||||
|
```cpp
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00019 {
|
||||||
|
|
||||||
|
template <typename LowerLayer> class Layer3 : public LowerLayer {
|
||||||
|
|
||||||
|
using LowerLayer::LowerLayer;
|
||||||
|
|
||||||
|
virtual int m1() override
|
||||||
|
{
|
||||||
|
m_m1_calls++;
|
||||||
|
return LowerLayer::m1();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string m2() override
|
||||||
|
{
|
||||||
|
m_m2_calls++;
|
||||||
|
return LowerLayer::m2();
|
||||||
|
}
|
||||||
|
|
||||||
|
int m1_calls() const { return m_m1_calls; }
|
||||||
|
|
||||||
|
int m2_calls() const { return m_m2_calls; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_m1_calls{};
|
||||||
|
int m_m2_calls{};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
## Generated UML diagrams
|
||||||
|

|
||||||
BIN
docs/test_cases/t00019_class.png
Normal file
BIN
docs/test_cases/t00019_class.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
18
tests/t00019/.clanguml
Normal file
18
tests/t00019/.clanguml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
compilation_database_dir: ..
|
||||||
|
output_directory: puml
|
||||||
|
diagrams:
|
||||||
|
t00019_class:
|
||||||
|
type: class
|
||||||
|
glob:
|
||||||
|
- ../../tests/t00019/**.h
|
||||||
|
- ../../tests/t00019/**.cc
|
||||||
|
using_namespace:
|
||||||
|
- clanguml::t00019
|
||||||
|
include:
|
||||||
|
namespaces:
|
||||||
|
- clanguml::t00019
|
||||||
|
plantuml:
|
||||||
|
after:
|
||||||
|
- '@A(Base) <|-- @A(Layer3<LowerLayer>)'
|
||||||
|
- '@A(Layer3<LowerLayer>) <|-- @A(Layer2<LowerLayer>)'
|
||||||
|
- '@A(Layer2<LowerLayer>) <|-- @A(Layer1<LowerLayer>)'
|
||||||
16
tests/t00019/t00019.cc
Normal file
16
tests/t00019/t00019.cc
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include "t00019_base.h"
|
||||||
|
#include "t00019_layer1.h"
|
||||||
|
#include "t00019_layer2.h"
|
||||||
|
#include "t00019_layer3.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00019 {
|
||||||
|
|
||||||
|
class A {
|
||||||
|
public:
|
||||||
|
std::unique_ptr<Layer1<Layer2<Layer3<Base>>>> layers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
19
tests/t00019/t00019_base.h
Normal file
19
tests/t00019/t00019_base.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00019 {
|
||||||
|
|
||||||
|
class Base {
|
||||||
|
|
||||||
|
Base() = default;
|
||||||
|
|
||||||
|
virtual ~Base() = default;
|
||||||
|
|
||||||
|
virtual int m1() { return 2; }
|
||||||
|
|
||||||
|
virtual std::string m2() { return "two"; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
26
tests/t00019/t00019_layer1.h
Normal file
26
tests/t00019/t00019_layer1.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00019 {
|
||||||
|
|
||||||
|
template <typename LowerLayer> class Layer1 : public LowerLayer {
|
||||||
|
|
||||||
|
using LowerLayer::LowerLayer;
|
||||||
|
|
||||||
|
int m1() override
|
||||||
|
{
|
||||||
|
std::cout << "m1 called\n";
|
||||||
|
return LowerLayer::m1();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string m2() override
|
||||||
|
{
|
||||||
|
std::cout << "m2 called\n";
|
||||||
|
return LowerLayer::m2();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
20
tests/t00019/t00019_layer2.h
Normal file
20
tests/t00019/t00019_layer2.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00019 {
|
||||||
|
|
||||||
|
template <typename LowerLayer> class Layer2 : public LowerLayer {
|
||||||
|
|
||||||
|
using LowerLayer::LowerLayer;
|
||||||
|
|
||||||
|
using LowerLayer::m1;
|
||||||
|
|
||||||
|
using LowerLayer::m2;
|
||||||
|
|
||||||
|
int all_calls_count() const
|
||||||
|
{
|
||||||
|
return LowerLayer::m1_calls() + LowerLayer::m2_calls();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
33
tests/t00019/t00019_layer3.h
Normal file
33
tests/t00019/t00019_layer3.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00019 {
|
||||||
|
|
||||||
|
template <typename LowerLayer> class Layer3 : public LowerLayer {
|
||||||
|
|
||||||
|
using LowerLayer::LowerLayer;
|
||||||
|
|
||||||
|
virtual int m1() override
|
||||||
|
{
|
||||||
|
m_m1_calls++;
|
||||||
|
return LowerLayer::m1();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string m2() override
|
||||||
|
{
|
||||||
|
m_m2_calls++;
|
||||||
|
return LowerLayer::m2();
|
||||||
|
}
|
||||||
|
|
||||||
|
int m1_calls() const { return m_m1_calls; }
|
||||||
|
|
||||||
|
int m2_calls() const { return m_m2_calls; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_m1_calls{};
|
||||||
|
int m_m2_calls{};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
59
tests/t00019/test_case.h
Normal file
59
tests/t00019/test_case.h
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
* tests/t00019/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("t00019", "[test-case][class]")
|
||||||
|
{
|
||||||
|
auto [config, db] = load_config("t00019");
|
||||||
|
|
||||||
|
auto diagram = config.diagrams["t00019_class"];
|
||||||
|
|
||||||
|
REQUIRE(diagram->name == "t00019_class");
|
||||||
|
|
||||||
|
REQUIRE(diagram->include.namespaces.size() == 1);
|
||||||
|
REQUIRE_THAT(diagram->include.namespaces,
|
||||||
|
VectorContains(std::string{"clanguml::t00019"}));
|
||||||
|
|
||||||
|
REQUIRE(diagram->exclude.namespaces.size() == 0);
|
||||||
|
|
||||||
|
REQUIRE(diagram->should_include("clanguml::t00019::Layer1"));
|
||||||
|
REQUIRE(diagram->should_include("clanguml::t00019::Layer2"));
|
||||||
|
REQUIRE(diagram->should_include("clanguml::t00019::Layer3"));
|
||||||
|
REQUIRE(diagram->should_include("clanguml::t00019::Base"));
|
||||||
|
|
||||||
|
auto model = generate_class_diagram(db, diagram);
|
||||||
|
|
||||||
|
REQUIRE(model.name == "t00019_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("Base")));
|
||||||
|
REQUIRE_THAT(puml, IsClassTemplate("Layer1", "LowerLayer"));
|
||||||
|
REQUIRE_THAT(puml, IsClassTemplate("Layer2", "LowerLayer"));
|
||||||
|
REQUIRE_THAT(puml, IsClassTemplate("Layer3", "LowerLayer"));
|
||||||
|
REQUIRE_THAT(puml, IsBaseClass(_A("Base"), _A("Layer3<LowerLayer>")));
|
||||||
|
REQUIRE_THAT(
|
||||||
|
puml, IsBaseClass(_A("Layer3<LowerLayer>"), _A("Layer2<LowerLayer>")));
|
||||||
|
REQUIRE_THAT(
|
||||||
|
puml, IsBaseClass(_A("Layer2<LowerLayer>"), _A("Layer1<LowerLayer>")));
|
||||||
|
|
||||||
|
save_puml(
|
||||||
|
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||||
|
}
|
||||||
@@ -122,6 +122,7 @@ using namespace clanguml::test::matchers;
|
|||||||
#include "t00016/test_case.h"
|
#include "t00016/test_case.h"
|
||||||
#include "t00017/test_case.h"
|
#include "t00017/test_case.h"
|
||||||
#include "t00018/test_case.h"
|
#include "t00018/test_case.h"
|
||||||
|
#include "t00019/test_case.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// Sequence diagram tests
|
// Sequence diagram tests
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ test_cases:
|
|||||||
- name: t00018
|
- name: t00018
|
||||||
title: Pimpl pattern
|
title: Pimpl pattern
|
||||||
description:
|
description:
|
||||||
|
- name: t00019
|
||||||
|
title: Layercake pattern
|
||||||
|
description:
|
||||||
Sequence diagrams:
|
Sequence diagrams:
|
||||||
- name: t20001
|
- name: t20001
|
||||||
title: Basic sequence diagram
|
title: Basic sequence diagram
|
||||||
|
|||||||
Reference in New Issue
Block a user