Skip to content

Commit

Permalink
Added Objective C include diagram test case (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkryza committed Sep 14, 2024
1 parent 98504f4 commit f9dac5d
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/include_diagram/visitor/translation_unit_visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ translation_unit_visitor::include_visitor::process_source_file(

const std::string implementation_suffix_prefix{".c"};
if (file_path.has_extension() &&
util::starts_with(
file_path.extension().string(), implementation_suffix_prefix)) {
(util::starts_with(file_path.extension().string(),
implementation_suffix_prefix) ||
file_path.extension() == ".m")) {
source_file.set_type(source_file_t::kImplementation);
}
else
Expand Down
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

file(GLOB_RECURSE TEST_CASE_SOURCES t*/*.cc t*/*.c t*/src/*.c t*/*.cu)
file(GLOB_RECURSE TEST_CASES_OBJC_SOURCES t*/*.m)
file(GLOB_RECURSE TEST_CASES_OBJC_SOURCES t*/*.m t*/src/*.m)
file(GLOB_RECURSE TEST_CASE_MODULE_SOURCES t*/src/*.cppm)
file(GLOB_RECURSE TEST_CASE_CONFIGS t*/.clang-uml)
file(GLOB_RECURSE TEST_CONFIG_YMLS test_config_data/*.yml
Expand All @@ -11,7 +11,7 @@ set(TEST_CASES_REQUIRING_CXX20 t00056 t00058 t00059 t00065 t00069 t00074 t00075)
set(TEST_CASES_REQUIRING_CXX20_MODULES t00070 t00071 t00072
t30012 t30013 t30014 t30015)
set(TEST_CASES_REQUIRING_CUDA t20049 t20050 t20051)
set(TEST_CASES_REQUIRING_OBJC t00084 t00085 t30016)
set(TEST_CASES_REQUIRING_OBJC t00084 t00085 t30016 t40004)

if(ENABLE_OBJECTIVE_C_TEST_CASES)
message(STATUS "Enabling Objective-C test cases: ${TEST_CASES_OBJC_SOURCES}")
Expand Down Expand Up @@ -113,7 +113,7 @@ foreach(TEST_NAME ${TEST_NAMES})
endif(ENABLE_CXX_MODULES_TEST_CASES)
if(ENABLE_OBJECTIVE_C_TEST_CASES)
add_library(test_cases_objc)
target_compile_options(test_cases_objc PUBLIC -MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -fno-strict-aliasing -fexceptions -fblocks -fobjc-runtime=gnustep-2.0 -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -pthread -fPIC -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -fconstant-string-class=NSConstantString -I/usr/local/include/GNUstep -I/usr/include/GNUstep)
target_compile_options(test_cases_objc PUBLIC -MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -fno-strict-aliasing -fexceptions -fblocks -fobjc-runtime=gnustep-2.0 -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -pthread -fPIC -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -fconstant-string-class=NSConstantString -I/usr/local/include/GNUstep -I/usr/include/GNUstep -I/usr/lib/clang/18/include -I/usr/local/include/GNUstep -I/usr/include/GNUstep -I/usr/local/include/)

# Link the GNUstep libraries
target_link_libraries(test_cases_objc -shared-libgcc -pthread -fexceptions -rdynamic -L/usr/local/lib -L/usr/lib -lgnustep-base -lobjc -lm)
Expand Down
11 changes: 11 additions & 0 deletions tests/t40004/.clang-uml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diagrams:
t40004_include:
type: include
glob:
- src/lib1/lib1.m
- src/lib2/lib2.m
- src/t40004.m
include:
paths:
- include
- src
7 changes: 7 additions & 0 deletions tests/t40004/include/lib1/lib1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <Foundation/Foundation.h>

@interface Lib1 : NSObject

@end
7 changes: 7 additions & 0 deletions tests/t40004/include/lib2/lib2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <Foundation/Foundation.h>

@interface Lib2 : NSObject

@end
1 change: 1 addition & 0 deletions tests/t40004/src/lib1/lib1.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../../include/lib1/lib1.h"
1 change: 1 addition & 0 deletions tests/t40004/src/lib2/lib2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../../include/lib2/lib2.h"
12 changes: 12 additions & 0 deletions tests/t40004/src/t40004.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "../include/lib1/lib1.h"
#include "../include/lib2/lib2.h"


@interface t40004_D : NSObject {
}

@property (nonatomic, assign) Lib1 *l1;
@property (nonatomic, assign) Lib2 *l2;


@end
50 changes: 50 additions & 0 deletions tests/t40004/test_case.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* tests/t40004/test_case.h
*
* Copyright (c) 2021-2024 Bartek Kryza <[email protected]>
*
* 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("t40004")
{
using namespace clanguml::test;
using namespace std::string_literals;

auto [config, db, diagram, model] =
CHECK_INCLUDE_MODEL("t40004", "t40004_include");

CHECK_INCLUDE_DIAGRAM(*config, diagram, *model, [](const auto &src) {
REQUIRE(IsFolder(src, "src"));
REQUIRE(IsFolder(src, "src/lib1"));
REQUIRE(IsFolder(src, "src/lib2"));
REQUIRE(IsFolder(src, "include"));
REQUIRE(IsFolder(src, "include/lib1"));
REQUIRE(IsFolder(src, "include/lib2"));

REQUIRE(IsFile(src, "include/lib1/lib1.h"));
REQUIRE(IsFile(src, "include/lib2/lib2.h"));

REQUIRE(IsFile(src, "src/t40004.m"));

REQUIRE(IsFile(src, "src/lib1/lib1.m"));
REQUIRE(IsFile(src, "src/lib2/lib2.m"));

REQUIRE(IsHeaderDependency(src, "src/t40004.m", "include/lib1/lib1.h"));
REQUIRE(IsHeaderDependency(src, "src/t40004.m", "include/lib2/lib2.h"));
REQUIRE(
IsHeaderDependency(src, "src/lib1/lib1.m", "include/lib1/lib1.h"));
REQUIRE(
IsHeaderDependency(src, "src/lib2/lib2.m", "include/lib2/lib2.h"));
});
}
6 changes: 3 additions & 3 deletions tests/test_cases.cc
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,10 @@ void CHECK_INCLUDE_DIAGRAM(const clanguml::config::config &config,
///
/// Include diagram tests
///

#include "t40001/test_case.h"
#include "t40002/test_case.h"
#include "t40003/test_case.h"
#include "t40004/test_case.h"

///
/// Other tests (e.g. configuration file)
Expand All @@ -686,8 +686,8 @@ int main(int argc, char *argv[])

clanguml::cli::cli_handler clih;

std::vector<const char *> argvv = {
"clang-uml", "--config", "./test_config_data/simple.yml"};
std::vector<const char *> argvv = {"clang-uml", "--query-driver", ".",
"--config", "./test_config_data/simple.yml"};

argvv.push_back("-q");

Expand Down
3 changes: 3 additions & 0 deletions tests/test_cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ test_cases:
- name: t40003
title: Dependants and dependencies include diagram filter test
description:
- name: t40004
title: Objective C include diagram test
description:
Configuration diagrams:
- name: t90000
title: Basic config test
Expand Down

0 comments on commit f9dac5d

Please sign in to comment.