diff --git a/src/package_diagram/visitor/translation_unit_visitor.cc b/src/package_diagram/visitor/translation_unit_visitor.cc index 2c0b824c..5456cbe6 100644 --- a/src/package_diagram/visitor/translation_unit_visitor.cc +++ b/src/package_diagram/visitor/translation_unit_visitor.cc @@ -559,6 +559,18 @@ bool translation_unit_visitor::find_relationships(const clang::QualType &type, } } } + else if (type->isRecordType() && type->getAsRecordDecl()) { + // This is only possible for plain C translation unit, so we don't + // need to consider namespaces here + if (config().package_type() == config::package_type_t::kDirectory) { + if (diagram().should_include( + common::get_qualified_name(*type->getAsRecordDecl()))) { + const auto target_id = get_package_id(type->getAsRecordDecl()); + relationships.emplace_back(target_id, relationship_hint); + result = true; + } + } + } return result; } diff --git a/tests/t30010/test_case.h b/tests/t30010/test_case.h index 921d02c7..943da222 100644 --- a/tests/t30010/test_case.h +++ b/tests/t30010/test_case.h @@ -46,8 +46,6 @@ TEST_CASE("t30010", "[test-case][package]") 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); diff --git a/tests/t30011/.clang-uml b/tests/t30011/.clang-uml new file mode 100644 index 00000000..33463e69 --- /dev/null +++ b/tests/t30011/.clang-uml @@ -0,0 +1,12 @@ +compilation_database_dir: .. +output_directory: puml +diagrams: + t30011_package: + type: package + package_type: directory + glob: + - t30011.c + relative_to: ../../../tests/t30011 + include: + paths: + - . \ No newline at end of file diff --git a/tests/t30011/app/app.h b/tests/t30011/app/app.h new file mode 100644 index 00000000..469dd9b5 --- /dev/null +++ b/tests/t30011/app/app.h @@ -0,0 +1,14 @@ +#pragma once + +#include "../libraries/lib1/lib1.h" +#include "../libraries/lib2/lib2.h" +#include "../libraries/lib3/lib3.h" +#include "../libraries/lib4/lib4.h" + +struct t30011_App { + struct t30011_A a; + struct t30011_B *b; + enum t30011_E e; +}; + +void c(struct t30011_App *app, struct t30011_C *c) { } diff --git a/tests/t30011/libraries/lib1/lib1.h b/tests/t30011/libraries/lib1/lib1.h new file mode 100644 index 00000000..0b82d65b --- /dev/null +++ b/tests/t30011/libraries/lib1/lib1.h @@ -0,0 +1,3 @@ +#pragma once + +struct t30011_A { }; diff --git a/tests/t30011/libraries/lib2/lib2.h b/tests/t30011/libraries/lib2/lib2.h new file mode 100644 index 00000000..ebc93b2d --- /dev/null +++ b/tests/t30011/libraries/lib2/lib2.h @@ -0,0 +1,3 @@ +#pragma once + +struct t30011_B { }; diff --git a/tests/t30011/libraries/lib3/lib3.h b/tests/t30011/libraries/lib3/lib3.h new file mode 100644 index 00000000..b7c8835a --- /dev/null +++ b/tests/t30011/libraries/lib3/lib3.h @@ -0,0 +1,3 @@ +#pragma once + +enum t30011_E { e1, e2, e3 }; diff --git a/tests/t30011/libraries/lib4/lib4.h b/tests/t30011/libraries/lib4/lib4.h new file mode 100644 index 00000000..408898b0 --- /dev/null +++ b/tests/t30011/libraries/lib4/lib4.h @@ -0,0 +1,3 @@ +#pragma once + +struct t30011_C { }; diff --git a/tests/t30011/t30011.c b/tests/t30011/t30011.c new file mode 100644 index 00000000..ea60a509 --- /dev/null +++ b/tests/t30011/t30011.c @@ -0,0 +1,3 @@ +#include "app/app.h" + +struct t30011_App app; diff --git a/tests/t30011/test_case.h b/tests/t30011/test_case.h new file mode 100644 index 00000000..b78c2c41 --- /dev/null +++ b/tests/t30011/test_case.h @@ -0,0 +1,61 @@ +/** + * tests/t30011/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("t30011", "[test-case][package]") +{ + auto [config, db] = load_config("t30011"); + + auto diagram = config.diagrams["t30011_package"]; + + REQUIRE(diagram->name == "t30011_package"); + + auto model = generate_package_diagram(*db, diagram); + + REQUIRE(model->name() == "t30011_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"))); + + 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 diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 8605ad19..b4b92bd9 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -355,6 +355,7 @@ using namespace clanguml::test::matchers; #include "t30008/test_case.h" #include "t30009/test_case.h" #include "t30010/test_case.h" +#include "t30011/test_case.h" /// /// Include diagram tests diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index 7302d814..97734d89 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -311,6 +311,9 @@ test_cases: - name: t30010 title: Package diagram with packages from directory structure description: + - name: t30011 + title: Package diagram with packages from directory structure for plain C + description: Include diagrams: - name: t40001 title: Basic include graph diagram test case