From 2a29968f090be51cd18502c30dbd8c8293abc77d Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Fri, 26 May 2023 21:06:23 +0200 Subject: [PATCH] Added test case for package diagram from directory structure --- tests/t30010/.clang-uml | 17 ++++++++ tests/t30010/app/app.h | 20 ++++++++++ tests/t30010/libraries/lib1/lib1.h | 11 ++++++ tests/t30010/libraries/lib2/lib2.h | 13 ++++++ tests/t30010/libraries/lib3/lib3.h | 11 ++++++ tests/t30010/libraries/lib4/lib4.h | 11 ++++++ tests/t30010/t30010.cc | 9 +++++ tests/t30010/test_case.h | 63 ++++++++++++++++++++++++++++++ 8 files changed, 155 insertions(+) create mode 100644 tests/t30010/.clang-uml create mode 100644 tests/t30010/app/app.h create mode 100644 tests/t30010/libraries/lib1/lib1.h create mode 100644 tests/t30010/libraries/lib2/lib2.h create mode 100644 tests/t30010/libraries/lib3/lib3.h create mode 100644 tests/t30010/libraries/lib4/lib4.h create mode 100644 tests/t30010/t30010.cc create mode 100644 tests/t30010/test_case.h diff --git a/tests/t30010/.clang-uml b/tests/t30010/.clang-uml new file mode 100644 index 00000000..f862cd41 --- /dev/null +++ b/tests/t30010/.clang-uml @@ -0,0 +1,17 @@ +compilation_database_dir: .. +output_directory: puml +diagrams: + t30010_package: + type: package + generate_packages: true + package_type: directory + glob: + - t30010.cc + relative_to: ../../../tests/t30010 + include: + namespaces: + - clanguml::t30010 +# paths: +# - . + using_namespace: + - clanguml::t30010 \ No newline at end of file diff --git a/tests/t30010/app/app.h b/tests/t30010/app/app.h new file mode 100644 index 00000000..e3c4454b --- /dev/null +++ b/tests/t30010/app/app.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../libraries/lib1/lib1.h" +#include "../libraries/lib2/lib2.h" +#include "../libraries/lib3/lib3.h" +#include "../libraries/lib4/lib4.h" + +namespace clanguml { +namespace t30010 { + +struct App { + library1::A *a; + library2::B *b; + library3::E e; + + void c(library4::C *) { } +}; + +} +} \ No newline at end of file diff --git a/tests/t30010/libraries/lib1/lib1.h b/tests/t30010/libraries/lib1/lib1.h new file mode 100644 index 00000000..e5fd324f --- /dev/null +++ b/tests/t30010/libraries/lib1/lib1.h @@ -0,0 +1,11 @@ +#pragma once + +namespace clanguml { +namespace t30010 { +namespace library1 { + +struct A { }; + +} +} +} \ No newline at end of file diff --git a/tests/t30010/libraries/lib2/lib2.h b/tests/t30010/libraries/lib2/lib2.h new file mode 100644 index 00000000..1fdd93b5 --- /dev/null +++ b/tests/t30010/libraries/lib2/lib2.h @@ -0,0 +1,13 @@ +#pragma once + +namespace clanguml { +namespace t30010 { +namespace library2 { + +template struct B { + T b; +}; + +} +} +} \ No newline at end of file diff --git a/tests/t30010/libraries/lib3/lib3.h b/tests/t30010/libraries/lib3/lib3.h new file mode 100644 index 00000000..61556b16 --- /dev/null +++ b/tests/t30010/libraries/lib3/lib3.h @@ -0,0 +1,11 @@ +#pragma once + +namespace clanguml { +namespace t30010 { +namespace library3 { + +enum E { e1, e2, e3 }; + +} +} +} \ No newline at end of file diff --git a/tests/t30010/libraries/lib4/lib4.h b/tests/t30010/libraries/lib4/lib4.h new file mode 100644 index 00000000..2e273645 --- /dev/null +++ b/tests/t30010/libraries/lib4/lib4.h @@ -0,0 +1,11 @@ +#pragma once + +namespace clanguml { +namespace t30010 { +namespace library4 { + +struct C { }; + +} +} +} \ No newline at end of file diff --git a/tests/t30010/t30010.cc b/tests/t30010/t30010.cc new file mode 100644 index 00000000..93c7522b --- /dev/null +++ b/tests/t30010/t30010.cc @@ -0,0 +1,9 @@ +#include "app/app.h" + +namespace clanguml { +namespace t30010 { + +App app; + +} // namespace t30002 +} // namespace clanguml diff --git a/tests/t30010/test_case.h b/tests/t30010/test_case.h new file mode 100644 index 00000000..921d02c7 --- /dev/null +++ b/tests/t30010/test_case.h @@ -0,0 +1,63 @@ +/** + * tests/t30010/test_case.h + * + * Copyright (c) 2021-2023 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("t30010", "[test-case][package]") +{ + auto [config, db] = load_config("t30010"); + + auto diagram = config.diagrams["t30010_package"]; + + REQUIRE(diagram->name == "t30010_package"); + + auto model = generate_package_diagram(*db, diagram); + + REQUIRE(model->name() == "t30010_package"); + + { + auto puml = generate_package_puml(diagram, *model); + AliasMatcher _A(puml); + + REQUIRE_THAT(puml, StartsWith("@startuml")); + REQUIRE_THAT(puml, EndsWith("@enduml\n")); + + REQUIRE_THAT(puml, IsPackage("app")); + REQUIRE_THAT(puml, IsPackage("libraries")); + REQUIRE_THAT(puml, IsPackage("lib1")); + REQUIRE_THAT(puml, IsPackage("lib2")); + REQUIRE_THAT(puml, !IsPackage("library1")); + REQUIRE_THAT(puml, !IsPackage("library2")); + + REQUIRE_THAT(puml, IsDependency(_A("app"), _A("lib1"))); + REQUIRE_THAT(puml, IsDependency(_A("app"), _A("lib2"))); + REQUIRE_THAT(puml, IsDependency(_A("app"), _A("lib3"))); + REQUIRE_THAT(puml, IsDependency(_A("app"), _A("lib4"))); + // REQUIRE_THAT(puml, IsDependency(_A("app"), _A("library1"))); + // REQUIRE_THAT(puml, IsDependency(_A("app"), _A("library1"))); + + save_puml( + config.output_directory() + "/" + diagram->name + ".puml", puml); + } + + { + auto j = generate_package_json(diagram, *model); + + using namespace json; + + save_json(config.output_directory() + "/" + diagram->name + ".json", j); + } +} \ No newline at end of file