Added test case for package diagram from directory structure for plain C

This commit is contained in:
Bartek Kryza
2023-05-26 21:46:23 +02:00
parent 2a29968f09
commit ba32b54395
12 changed files with 118 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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);

12
tests/t30011/.clang-uml Normal file
View File

@@ -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:
- .

14
tests/t30011/app/app.h Normal file
View File

@@ -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) { }

View File

@@ -0,0 +1,3 @@
#pragma once
struct t30011_A { };

View File

@@ -0,0 +1,3 @@
#pragma once
struct t30011_B { };

View File

@@ -0,0 +1,3 @@
#pragma once
enum t30011_E { e1, e2, e3 };

View File

@@ -0,0 +1,3 @@
#pragma once
struct t30011_C { };

3
tests/t30011/t30011.c Normal file
View File

@@ -0,0 +1,3 @@
#include "app/app.h"
struct t30011_App app;

61
tests/t30011/test_case.h Normal file
View File

@@ -0,0 +1,61 @@
/**
* tests/t30011/test_case.h
*
* Copyright (c) 2021-2023 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("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);
}
}

View File

@@ -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

View File

@@ -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