Added combined feature sequence diagram test case
This commit is contained in:
17
tests/t20029/.clang-uml
Normal file
17
tests/t20029/.clang-uml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
compilation_database_dir: ..
|
||||||
|
output_directory: puml
|
||||||
|
diagrams:
|
||||||
|
t20029_sequence:
|
||||||
|
type: sequence
|
||||||
|
glob:
|
||||||
|
- ../../tests/t20029/t20029.cc
|
||||||
|
include:
|
||||||
|
namespaces:
|
||||||
|
- clanguml::t20029
|
||||||
|
exclude:
|
||||||
|
access:
|
||||||
|
- private
|
||||||
|
using_namespace:
|
||||||
|
- clanguml::t20029
|
||||||
|
start_from:
|
||||||
|
- function: "clanguml::t20029::tmain()"
|
||||||
75
tests/t20029/t20029.cc
Normal file
75
tests/t20029/t20029.cc
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#include <atomic>
|
||||||
|
#include <functional>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t20029 {
|
||||||
|
using encoder_function_t = std::function<std::string(std::string &&)>;
|
||||||
|
|
||||||
|
std::string encode_b64(std::string &&content) { return std::move(content); }
|
||||||
|
|
||||||
|
template <typename T> class Encoder : public T {
|
||||||
|
public:
|
||||||
|
bool send(std::string &&msg)
|
||||||
|
{
|
||||||
|
auto encoded = encode(std::move(msg));
|
||||||
|
return T::send(std::move(encoded));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string encode(std::string &&msg) { return encode_b64(std::move(msg)); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
encoder_function_t f_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T> class Retrier : public T {
|
||||||
|
public:
|
||||||
|
bool send(std::string &&msg)
|
||||||
|
{
|
||||||
|
std::string buffer{std::move(msg)};
|
||||||
|
|
||||||
|
int retryCount = 5;
|
||||||
|
|
||||||
|
while (retryCount--) {
|
||||||
|
if (T::send(buffer))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ConnectionPool {
|
||||||
|
public:
|
||||||
|
void connect()
|
||||||
|
{
|
||||||
|
if (!is_connected_.load())
|
||||||
|
connect_impl();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool send(const std::string &msg) { return true; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void connect_impl() { is_connected_ = true; }
|
||||||
|
|
||||||
|
std::atomic<bool> is_connected_;
|
||||||
|
};
|
||||||
|
|
||||||
|
int tmain()
|
||||||
|
{
|
||||||
|
auto pool = std::make_shared<Encoder<Retrier<ConnectionPool>>>();
|
||||||
|
|
||||||
|
pool->connect();
|
||||||
|
|
||||||
|
for (std::string line; std::getline(std::cin, line);) {
|
||||||
|
if (!pool->send(std::move(line)))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
61
tests/t20029/test_case.h
Normal file
61
tests/t20029/test_case.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
* tests/t20029/test_case.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021-2022 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("t20029", "[test-case][sequence]")
|
||||||
|
{
|
||||||
|
auto [config, db] = load_config("t20029");
|
||||||
|
|
||||||
|
auto diagram = config.diagrams["t20029_sequence"];
|
||||||
|
|
||||||
|
REQUIRE(diagram->name == "t20029_sequence");
|
||||||
|
|
||||||
|
auto model = generate_sequence_diagram(*db, diagram);
|
||||||
|
|
||||||
|
REQUIRE(model->name() == "t20029_sequence");
|
||||||
|
|
||||||
|
auto puml = generate_sequence_puml(diagram, *model);
|
||||||
|
AliasMatcher _A(puml);
|
||||||
|
|
||||||
|
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||||
|
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||||
|
|
||||||
|
// Check if all calls exist
|
||||||
|
REQUIRE_THAT(
|
||||||
|
puml, HasCall(_A("tmain()"), _A("ConnectionPool"), "connect()"));
|
||||||
|
REQUIRE_THAT(puml,
|
||||||
|
HasCallInControlCondition(_A("tmain()"),
|
||||||
|
_A("Encoder<Retrier<ConnectionPool>>"), "send(std::string &&)"));
|
||||||
|
|
||||||
|
REQUIRE_THAT(puml,
|
||||||
|
HasCall(_A("Encoder<Retrier<ConnectionPool>>"),
|
||||||
|
_A("Encoder<Retrier<ConnectionPool>>"), "encode(std::string &&)"));
|
||||||
|
|
||||||
|
REQUIRE_THAT(puml,
|
||||||
|
HasCall(_A("Encoder<Retrier<ConnectionPool>>"),
|
||||||
|
_A("encode_b64(std::string &&)"), ""));
|
||||||
|
|
||||||
|
REQUIRE_THAT(puml,
|
||||||
|
HasCallInControlCondition(_A("Retrier<ConnectionPool>"),
|
||||||
|
_A("ConnectionPool"), "send(const std::string &)"));
|
||||||
|
|
||||||
|
REQUIRE_THAT(puml,
|
||||||
|
!HasCall(_A("ConnectionPool"), _A("ConnectionPool"), "connect_impl()"));
|
||||||
|
|
||||||
|
save_puml(
|
||||||
|
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
|
}
|
||||||
@@ -275,6 +275,7 @@ using namespace clanguml::test::matchers;
|
|||||||
#include "t20026/test_case.h"
|
#include "t20026/test_case.h"
|
||||||
#include "t20027/test_case.h"
|
#include "t20027/test_case.h"
|
||||||
#include "t20028/test_case.h"
|
#include "t20028/test_case.h"
|
||||||
|
#include "t20029/test_case.h"
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Package diagram tests
|
/// Package diagram tests
|
||||||
|
|||||||
@@ -232,6 +232,9 @@ test_cases:
|
|||||||
- name: t20028
|
- name: t20028
|
||||||
title: Conditional (ternary) '?:' operator test case
|
title: Conditional (ternary) '?:' operator test case
|
||||||
description:
|
description:
|
||||||
|
- name: t20029
|
||||||
|
title: Combined feature sequence diagram test case
|
||||||
|
description:
|
||||||
Package diagrams:
|
Package diagrams:
|
||||||
- name: t30001
|
- name: t30001
|
||||||
title: Basic package diagram test case
|
title: Basic package diagram test case
|
||||||
|
|||||||
Reference in New Issue
Block a user