Added template proxy design pattern test case

This commit is contained in:
Bartek Kryza
2021-07-25 13:18:52 +02:00
parent ba090a1af4
commit 5484a23647
6 changed files with 148 additions and 0 deletions

12
tests/t00025/.clanguml Normal file
View File

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

39
tests/t00025/t00024.cc Normal file
View File

@@ -0,0 +1,39 @@
#include <memory>
namespace clanguml {
namespace t00025 {
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;
};
}
}

37
tests/t00025/t00025.cc Normal file
View File

@@ -0,0 +1,37 @@
#include <memory>
namespace clanguml {
namespace t00025 {
class Target1 {
public:
void m1() { }
void m2() { }
};
class Target2 {
public:
void m1() { }
void m2() { }
};
template <typename T> class Proxy {
public:
Proxy(std::shared_ptr<T> target)
: m_target {std::move(target)}
{
}
void m1() { m_target->m1(); }
void m2() { m_target->m2(); }
private:
std::shared_ptr<T> m_target;
};
class ProxyHolder {
public:
Proxy<Target1> proxy1;
Proxy<Target2> proxy2;
};
}
}

56
tests/t00025/test_case.h Normal file
View File

@@ -0,0 +1,56 @@
/**
* tests/t00025/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("t00025", "[test-case][class]")
{
auto [config, db] = load_config("t00025");
auto diagram = config.diagrams["t00025_class"];
REQUIRE(diagram->name == "t00025_class");
REQUIRE(diagram->include.namespaces.size() == 1);
REQUIRE_THAT(diagram->include.namespaces,
VectorContains(std::string{"clanguml::t00025"}));
REQUIRE(diagram->exclude.namespaces.size() == 0);
REQUIRE(diagram->should_include("clanguml::t00025::A"));
auto model = generate_class_diagram(db, diagram);
REQUIRE(model.name == "t00025_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("Target1")));
REQUIRE_THAT(puml, IsClass(_A("Target2")));
REQUIRE_THAT(puml, IsClassTemplate("Proxy", "T"));
REQUIRE_THAT(puml, IsInstantiation(_A("Proxy<T>"), _A("Proxy<Target1>")));
REQUIRE_THAT(puml, IsInstantiation(_A("Proxy<T>"), _A("Proxy<Target2>")));
REQUIRE_THAT(puml, IsAggregation(_A("ProxyHolder"), _A("Proxy<Target1>"), "+proxy1"));
REQUIRE_THAT(puml, IsAggregation(_A("ProxyHolder"), _A("Proxy<Target2>"), "+proxy2"));
REQUIRE_THAT(puml, !IsAggregation(_A("ProxyHolder"), _A("Target1"), "+proxy1"));
REQUIRE_THAT(puml, !IsAggregation(_A("ProxyHolder"), _A("Target2"), "+proxy2"));
save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
}

View File

@@ -128,6 +128,7 @@ using namespace clanguml::test::matchers;
#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" #include "t00024/test_case.h"
#include "t00025/test_case.h"
// //
// Sequence diagram tests // Sequence diagram tests

View File

@@ -69,6 +69,9 @@ test_cases:
- name: t00024 - name: t00024
title: Proxy pattern title: Proxy pattern
description: description:
- name: t00025
title: Template proxy pattern
description:
Sequence diagrams: Sequence diagrams:
- name: t20001 - name: t20001
title: Basic sequence diagram title: Basic sequence diagram