Added template method pattern
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
* [t00019](./test_cases/t00019.md) - Layercake pattern
|
||||
* [t00020](./test_cases/t00020.md) - Abstract factory pattern
|
||||
* [t00021](./test_cases/t00021.md) - Visitor pattern
|
||||
* [t00022](./test_cases/t00022.md) - Template method pattern
|
||||
## Sequence diagrams
|
||||
* [t20001](./test_cases/t20001.md) - Basic sequence diagram
|
||||
## Configuration diagrams
|
||||
|
||||
@@ -35,20 +35,20 @@ public:
|
||||
|
||||
class Visitor1 : public Visitor {
|
||||
public:
|
||||
void visit_A(const A &item) const override { }
|
||||
void visit_B(const B &item) const override { }
|
||||
void visit_A(const A &item) const override {}
|
||||
void visit_B(const B &item) const override {}
|
||||
};
|
||||
|
||||
class Visitor2 : public Visitor {
|
||||
public:
|
||||
void visit_A(const A &item) const override { }
|
||||
void visit_B(const B &item) const override { }
|
||||
void visit_A(const A &item) const override {}
|
||||
void visit_B(const B &item) const override {}
|
||||
};
|
||||
|
||||
class Visitor3 : public Visitor {
|
||||
public:
|
||||
void visit_A(const A &item) const override { }
|
||||
void visit_B(const B &item) const override { }
|
||||
void visit_A(const A &item) const override {}
|
||||
void visit_B(const B &item) const override {}
|
||||
};
|
||||
|
||||
class Item {
|
||||
@@ -59,12 +59,12 @@ public:
|
||||
|
||||
class A : public Item {
|
||||
public:
|
||||
void accept(const Visitor &visitor) const override { }
|
||||
void accept(const Visitor &visitor) const override {}
|
||||
};
|
||||
|
||||
class B : public Item {
|
||||
public:
|
||||
void accept(const Visitor &visitor) const override { }
|
||||
void accept(const Visitor &visitor) const override {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
56
docs/test_cases/t00022.md
Normal file
56
docs/test_cases/t00022.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# t00022 - Template method pattern
|
||||
## Config
|
||||
```yaml
|
||||
compilation_database_dir: ..
|
||||
output_directory: puml
|
||||
diagrams:
|
||||
t00022_class:
|
||||
type: class
|
||||
glob:
|
||||
- ../../tests/t00022/t00022.cc
|
||||
using_namespace:
|
||||
- clanguml::t00022
|
||||
include:
|
||||
namespaces:
|
||||
- clanguml::t00022
|
||||
|
||||
```
|
||||
## Source code
|
||||
File t00022.cc
|
||||
```cpp
|
||||
#include <memory>
|
||||
|
||||
namespace clanguml {
|
||||
namespace t00022 {
|
||||
|
||||
class A {
|
||||
public:
|
||||
void template_method()
|
||||
{
|
||||
method1();
|
||||
method2();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void method1() = 0;
|
||||
virtual void method2() = 0;
|
||||
};
|
||||
|
||||
class A1 : public A {
|
||||
protected:
|
||||
void method1() override { }
|
||||
void method2() override { }
|
||||
};
|
||||
|
||||
class A2 : public A {
|
||||
protected:
|
||||
void method1() override { }
|
||||
void method2() override { }
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
## Generated UML diagrams
|
||||

|
||||
BIN
docs/test_cases/t00022_class.png
Normal file
BIN
docs/test_cases/t00022_class.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
12
tests/t00022/.clanguml
Normal file
12
tests/t00022/.clanguml
Normal file
@@ -0,0 +1,12 @@
|
||||
compilation_database_dir: ..
|
||||
output_directory: puml
|
||||
diagrams:
|
||||
t00022_class:
|
||||
type: class
|
||||
glob:
|
||||
- ../../tests/t00022/t00022.cc
|
||||
using_namespace:
|
||||
- clanguml::t00022
|
||||
include:
|
||||
namespaces:
|
||||
- clanguml::t00022
|
||||
31
tests/t00022/t00022.cc
Normal file
31
tests/t00022/t00022.cc
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <memory>
|
||||
|
||||
namespace clanguml {
|
||||
namespace t00022 {
|
||||
|
||||
class A {
|
||||
public:
|
||||
void template_method()
|
||||
{
|
||||
method1();
|
||||
method2();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void method1() = 0;
|
||||
virtual void method2() = 0;
|
||||
};
|
||||
|
||||
class A1 : public A {
|
||||
protected:
|
||||
void method1() override {}
|
||||
void method2() override {}
|
||||
};
|
||||
|
||||
class A2 : public A {
|
||||
protected:
|
||||
void method1() override {}
|
||||
void method2() override {}
|
||||
};
|
||||
}
|
||||
}
|
||||
50
tests/t00022/test_case.h
Normal file
50
tests/t00022/test_case.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* tests/t00022/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("t00022", "[test-case][class]")
|
||||
{
|
||||
auto [config, db] = load_config("t00022");
|
||||
|
||||
auto diagram = config.diagrams["t00022_class"];
|
||||
|
||||
REQUIRE(diagram->name == "t00022_class");
|
||||
|
||||
REQUIRE(diagram->include.namespaces.size() == 1);
|
||||
REQUIRE_THAT(diagram->include.namespaces,
|
||||
VectorContains(std::string{"clanguml::t00022"}));
|
||||
|
||||
REQUIRE(diagram->exclude.namespaces.size() == 0);
|
||||
|
||||
REQUIRE(diagram->should_include("clanguml::t00022::A"));
|
||||
|
||||
auto model = generate_class_diagram(db, diagram);
|
||||
|
||||
REQUIRE(model.name == "t00022_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, IsAbstractClass(_A("A")));
|
||||
REQUIRE_THAT(puml, IsClass(_A("A1")));
|
||||
REQUIRE_THAT(puml, IsClass(_A("A2")));
|
||||
|
||||
save_puml(
|
||||
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||
}
|
||||
@@ -125,6 +125,7 @@ using namespace clanguml::test::matchers;
|
||||
#include "t00019/test_case.h"
|
||||
#include "t00020/test_case.h"
|
||||
#include "t00021/test_case.h"
|
||||
#include "t00022/test_case.h"
|
||||
|
||||
//
|
||||
// Sequence diagram tests
|
||||
|
||||
@@ -60,6 +60,9 @@ test_cases:
|
||||
- name: t00021
|
||||
title: Visitor pattern
|
||||
description:
|
||||
- name: t00022
|
||||
title: Template method pattern
|
||||
description:
|
||||
Sequence diagrams:
|
||||
- name: t20001
|
||||
title: Basic sequence diagram
|
||||
|
||||
Reference in New Issue
Block a user