From 8e4b670d9944a83acf8f86846f55fb7520809759 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Thu, 15 Dec 2022 00:56:55 +0100 Subject: [PATCH] Added combined feature sequence diagram test case --- tests/t20029/.clang-uml | 17 +++++++++ tests/t20029/t20029.cc | 75 ++++++++++++++++++++++++++++++++++++++++ tests/t20029/test_case.h | 61 ++++++++++++++++++++++++++++++++ tests/test_cases.cc | 1 + tests/test_cases.yaml | 3 ++ 5 files changed, 157 insertions(+) create mode 100644 tests/t20029/.clang-uml create mode 100644 tests/t20029/t20029.cc create mode 100644 tests/t20029/test_case.h diff --git a/tests/t20029/.clang-uml b/tests/t20029/.clang-uml new file mode 100644 index 00000000..6f1d0df7 --- /dev/null +++ b/tests/t20029/.clang-uml @@ -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()" \ No newline at end of file diff --git a/tests/t20029/t20029.cc b/tests/t20029/t20029.cc new file mode 100644 index 00000000..e61a0ce5 --- /dev/null +++ b/tests/t20029/t20029.cc @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include + +namespace clanguml { +namespace t20029 { +using encoder_function_t = std::function; + +std::string encode_b64(std::string &&content) { return std::move(content); } + +template 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 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 is_connected_; +}; + +int tmain() +{ + auto pool = std::make_shared>>(); + + pool->connect(); + + for (std::string line; std::getline(std::cin, line);) { + if (!pool->send(std::move(line))) + break; + } + + return 0; +} +} +} \ No newline at end of file diff --git a/tests/t20029/test_case.h b/tests/t20029/test_case.h new file mode 100644 index 00000000..346ce8ce --- /dev/null +++ b/tests/t20029/test_case.h @@ -0,0 +1,61 @@ +/** + * tests/t20029/test_case.h + * + * Copyright (c) 2021-2022 Bartek Kryza + * + * 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>"), "send(std::string &&)")); + + REQUIRE_THAT(puml, + HasCall(_A("Encoder>"), + _A("Encoder>"), "encode(std::string &&)")); + + REQUIRE_THAT(puml, + HasCall(_A("Encoder>"), + _A("encode_b64(std::string &&)"), "")); + + REQUIRE_THAT(puml, + HasCallInControlCondition(_A("Retrier"), + _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); +} \ No newline at end of file diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 1b15e9b7..11c74630 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -275,6 +275,7 @@ using namespace clanguml::test::matchers; #include "t20026/test_case.h" #include "t20027/test_case.h" #include "t20028/test_case.h" +#include "t20029/test_case.h" /// /// Package diagram tests diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index 09d41fea..880825fd 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -232,6 +232,9 @@ test_cases: - name: t20028 title: Conditional (ternary) '?:' operator test case description: + - name: t20029 + title: Combined feature sequence diagram test case + description: Package diagrams: - name: t30001 title: Basic package diagram test case