From 1bde5d70397c4bd275c00e6a3cc61168491ea3ce Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Thu, 24 Feb 2022 22:17:13 +0100 Subject: [PATCH] Added namespace package in class diagrams test case --- tests/t00036/.clang-uml | 13 ++++++++++ tests/t00036/t00036.cc | 36 ++++++++++++++++++++++++++++ tests/t00036/test_case.h | 51 ++++++++++++++++++++++++++++++++++++++++ tests/test_cases.cc | 1 + tests/test_config.cc | 2 ++ 5 files changed, 103 insertions(+) create mode 100644 tests/t00036/.clang-uml create mode 100644 tests/t00036/t00036.cc create mode 100644 tests/t00036/test_case.h diff --git a/tests/t00036/.clang-uml b/tests/t00036/.clang-uml new file mode 100644 index 00000000..7d6d5449 --- /dev/null +++ b/tests/t00036/.clang-uml @@ -0,0 +1,13 @@ +compilation_database_dir: .. +output_directory: puml +diagrams: + t00036_class: + type: class + generate_packages: true + glob: + - ../../tests/t00036/t00036.cc + using_namespace: + - clanguml::t00036 + include: + namespaces: + - clanguml::t00036 \ No newline at end of file diff --git a/tests/t00036/t00036.cc b/tests/t00036/t00036.cc new file mode 100644 index 00000000..740b0c12 --- /dev/null +++ b/tests/t00036/t00036.cc @@ -0,0 +1,36 @@ +namespace clanguml { +namespace t00036 { + +namespace ns1 { + +enum class E { + blue, + yellow +}; + +namespace ns11 { + +template struct A { + T a; +}; + +namespace ns111 { + +struct B { + A a_int; +}; + +} +} +} + +namespace ns2 { +namespace ns22 { + +struct C; + +} +} + +} // namespace t00036 +} // namespace clanguml diff --git a/tests/t00036/test_case.h b/tests/t00036/test_case.h new file mode 100644 index 00000000..42626657 --- /dev/null +++ b/tests/t00036/test_case.h @@ -0,0 +1,51 @@ +/** + * tests/t00036/test_case.cc + * + * 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("t00036", "[test-case][class]") +{ + auto [config, db] = load_config("t00036"); + + auto diagram = config.diagrams["t00036_class"]; + + REQUIRE(diagram->name == "t00036_class"); + REQUIRE(diagram->generate_packages() == true); + + auto model = generate_class_diagram(db, diagram); + + REQUIRE(model.name() == "t00036_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, IsClassTemplate("A", "T")); + REQUIRE_THAT(puml, IsClassTemplate("A", "int")); + REQUIRE_THAT(puml, IsEnum(_A("E"))); + REQUIRE_THAT(puml, IsClass(_A("B"))); + REQUIRE_THAT(puml, IsClass(_A("C"))); + REQUIRE_THAT(puml, IsPackage("ns111")); + REQUIRE_THAT(puml, IsPackage("ns22")); + + REQUIRE_THAT( + puml, IsAggregation(_A("B"), _A("A"), "+a_int")); + + save_puml( + "./" + config.output_directory() + "/" + diagram->name + ".puml", puml); +} diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 3a9435aa..30e3727c 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -178,6 +178,7 @@ using namespace clanguml::test::matchers; #include "t00033/test_case.h" #include "t00034/test_case.h" #include "t00035/test_case.h" +#include "t00036/test_case.h" // // Sequence diagram tests diff --git a/tests/test_config.cc b/tests/test_config.cc index 6714f6f3..56cb4e88 100644 --- a/tests/test_config.cc +++ b/tests/test_config.cc @@ -47,6 +47,7 @@ TEST_CASE("Test config inherited", "[unit-test]") CHECK(def.glob()[0] == "src/**/*.cc"); CHECK(def.glob()[1] == "src/**/*.h"); CHECK(clanguml::util::contains(def.using_namespace(), "clanguml")); + CHECK(def.generate_packages() == false); auto &cus = *cfg.diagrams["class_custom"]; CHECK(cus.type() == clanguml::config::diagram_type::class_diagram); @@ -54,6 +55,7 @@ TEST_CASE("Test config inherited", "[unit-test]") CHECK(cus.glob()[0] == "src/main.cc"); CHECK(clanguml::util::contains(cus.using_namespace(), "clanguml::ns1")); CHECK(cus.include_relations_also_as_members()); + CHECK(def.generate_packages() == false); } TEST_CASE("Test config includes", "[unit-test]")