Added proxy design pattern test case
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
* [t00021](./test_cases/t00021.md) - Visitor pattern
|
* [t00021](./test_cases/t00021.md) - Visitor pattern
|
||||||
* [t00022](./test_cases/t00022.md) - Template method pattern
|
* [t00022](./test_cases/t00022.md) - Template method pattern
|
||||||
* [t00023](./test_cases/t00023.md) - Strategy pattern
|
* [t00023](./test_cases/t00023.md) - Strategy pattern
|
||||||
|
* [t00024](./test_cases/t00024.md) - Proxy 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
|
||||||
|
|||||||
@@ -31,17 +31,17 @@ public:
|
|||||||
|
|
||||||
class StrategyA : public Strategy {
|
class StrategyA : public Strategy {
|
||||||
public:
|
public:
|
||||||
void algorithm() override { }
|
void algorithm() override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class StrategyB : public Strategy {
|
class StrategyB : public Strategy {
|
||||||
public:
|
public:
|
||||||
void algorithm() override { }
|
void algorithm() override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class StrategyC : public Strategy {
|
class StrategyC : public Strategy {
|
||||||
public:
|
public:
|
||||||
void algorithm() override { }
|
void algorithm() override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
@@ -56,7 +56,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::unique_ptr<Strategy> m_strategy;
|
std::unique_ptr<Strategy> m_strategy;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
64
docs/test_cases/t00024.md
Normal file
64
docs/test_cases/t00024.md
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
# t00024 - Proxy pattern
|
||||||
|
## Config
|
||||||
|
```yaml
|
||||||
|
compilation_database_dir: ..
|
||||||
|
output_directory: puml
|
||||||
|
diagrams:
|
||||||
|
t00024_class:
|
||||||
|
type: class
|
||||||
|
glob:
|
||||||
|
- ../../tests/t00024/t00024.cc
|
||||||
|
using_namespace:
|
||||||
|
- clanguml::t00024
|
||||||
|
include:
|
||||||
|
namespaces:
|
||||||
|
- clanguml::t00024
|
||||||
|
|
||||||
|
```
|
||||||
|
## Source code
|
||||||
|
File t00024.cc
|
||||||
|
```cpp
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00024 {
|
||||||
|
|
||||||
|
class Target {
|
||||||
|
public:
|
||||||
|
virtual ~Target() = 0;
|
||||||
|
|
||||||
|
virtual void m1() = 0;
|
||||||
|
virtual void m2() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Target1 : public Target {
|
||||||
|
public:
|
||||||
|
void m1() override { }
|
||||||
|
void m2() override { }
|
||||||
|
};
|
||||||
|
|
||||||
|
class Target2 : public Target {
|
||||||
|
public:
|
||||||
|
void m1() override { }
|
||||||
|
void m2() override { }
|
||||||
|
};
|
||||||
|
|
||||||
|
class Proxy : public Target {
|
||||||
|
public:
|
||||||
|
Proxy(std::shared_ptr<Target> target)
|
||||||
|
: m_target {std::move(target)}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void m1() override { m_target->m1(); }
|
||||||
|
void m2() override { m_target->m2(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<Target> m_target;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
## Generated UML diagrams
|
||||||
|

|
||||||
BIN
docs/test_cases/t00024_class.png
Normal file
BIN
docs/test_cases/t00024_class.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
12
tests/t00024/.clanguml
Normal file
12
tests/t00024/.clanguml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
compilation_database_dir: ..
|
||||||
|
output_directory: puml
|
||||||
|
diagrams:
|
||||||
|
t00024_class:
|
||||||
|
type: class
|
||||||
|
glob:
|
||||||
|
- ../../tests/t00024/t00024.cc
|
||||||
|
using_namespace:
|
||||||
|
- clanguml::t00024
|
||||||
|
include:
|
||||||
|
namespaces:
|
||||||
|
- clanguml::t00024
|
||||||
39
tests/t00024/t00024.cc
Normal file
39
tests/t00024/t00024.cc
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00024 {
|
||||||
|
|
||||||
|
class Target {
|
||||||
|
public:
|
||||||
|
virtual ~Target() = 0;
|
||||||
|
|
||||||
|
virtual void m1() = 0;
|
||||||
|
virtual void m2() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Target1 : public Target {
|
||||||
|
public:
|
||||||
|
void m1() override {}
|
||||||
|
void m2() override {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Target2 : public Target {
|
||||||
|
public:
|
||||||
|
void m1() override {}
|
||||||
|
void m2() override {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Proxy : public Target {
|
||||||
|
public:
|
||||||
|
Proxy(std::shared_ptr<Target> target)
|
||||||
|
: m_target{std::move(target)}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void m1() override { m_target->m1(); }
|
||||||
|
void m2() override { m_target->m2(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<Target> m_target;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
54
tests/t00024/test_case.h
Normal file
54
tests/t00024/test_case.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* tests/t00024/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("t00024", "[test-case][class]")
|
||||||
|
{
|
||||||
|
auto [config, db] = load_config("t00024");
|
||||||
|
|
||||||
|
auto diagram = config.diagrams["t00024_class"];
|
||||||
|
|
||||||
|
REQUIRE(diagram->name == "t00024_class");
|
||||||
|
|
||||||
|
REQUIRE(diagram->include.namespaces.size() == 1);
|
||||||
|
REQUIRE_THAT(diagram->include.namespaces,
|
||||||
|
VectorContains(std::string{"clanguml::t00024"}));
|
||||||
|
|
||||||
|
REQUIRE(diagram->exclude.namespaces.size() == 0);
|
||||||
|
|
||||||
|
REQUIRE(diagram->should_include("clanguml::t00024::A"));
|
||||||
|
|
||||||
|
auto model = generate_class_diagram(db, diagram);
|
||||||
|
|
||||||
|
REQUIRE(model.name == "t00024_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("Target")));
|
||||||
|
REQUIRE_THAT(puml, IsClass(_A("Target1")));
|
||||||
|
REQUIRE_THAT(puml, IsClass(_A("Target2")));
|
||||||
|
REQUIRE_THAT(puml, IsClass(_A("Proxy")));
|
||||||
|
REQUIRE_THAT(puml, IsBaseClass(_A("Target"), _A("Target1")));
|
||||||
|
REQUIRE_THAT(puml, IsBaseClass(_A("Target"), _A("Target2")));
|
||||||
|
REQUIRE_THAT(puml, IsBaseClass(_A("Target"), _A("Proxy")));
|
||||||
|
|
||||||
|
save_puml(
|
||||||
|
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||||
|
}
|
||||||
@@ -127,6 +127,7 @@ using namespace clanguml::test::matchers;
|
|||||||
#include "t00021/test_case.h"
|
#include "t00021/test_case.h"
|
||||||
#include "t00022/test_case.h"
|
#include "t00022/test_case.h"
|
||||||
#include "t00023/test_case.h"
|
#include "t00023/test_case.h"
|
||||||
|
#include "t00024/test_case.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// Sequence diagram tests
|
// Sequence diagram tests
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ test_cases:
|
|||||||
- name: t00023
|
- name: t00023
|
||||||
title: Strategy pattern
|
title: Strategy pattern
|
||||||
description:
|
description:
|
||||||
|
- name: t00024
|
||||||
|
title: Proxy 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