Skip to content

Commit

Permalink
Improved Objective C class test case (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkryza committed Sep 7, 2024
1 parent 5316e14 commit d66c06f
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void generator::generate_method(
args_string = clanguml::util::abbreviate(
args_string, kAbbreviatedMethodArgumentsLength);
}
ostr << args_string;
ostr << escape_name(args_string);
}
ostr << ")";

Expand Down
10 changes: 10 additions & 0 deletions src/class_diagram/model/diagram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ bool diagram::should_include(const class_method &m) const
return filter().should_include(m);
}

bool diagram::should_include(const objc_member &m) const
{
return filter().should_include(m);
}

bool diagram::should_include(const objc_method &m) const
{
return filter().should_include(m);
}

const common::reference_vector<class_> &diagram::classes() const
{
return element_view<class_>::view();
Expand Down
2 changes: 2 additions & 0 deletions src/class_diagram/model/diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class diagram : public common::model::diagram,
* @return True, if class member should be included in the diagram.
*/
bool should_include(const class_member &m) const;
bool should_include(const objc_member &m) const;

/**
* @brief Whether a class_method should be included in the diagram.
Expand All @@ -89,6 +90,7 @@ class diagram : public common::model::diagram,
* @return True, if class method should be included in the diagram.
*/
bool should_include(const class_method &m) const;
bool should_include(const objc_method &m) const;

/**
* @brief Search for element in the diagram by fully qualified name.
Expand Down
11 changes: 6 additions & 5 deletions src/class_diagram/visitor/translation_unit_visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,8 @@ void translation_unit_visitor::process_objc_ivar(

const auto field_name = ivar.getNameAsString();

objc_member field{common::access_specifier_to_access_t(ivar.getAccessControl()),
objc_member field{
common::access_specifier_to_access_t(ivar.getAccessControl()),
field_name, field_type_str};

process_comment(ivar, field);
Expand Down Expand Up @@ -1649,11 +1650,11 @@ void translation_unit_visitor::process_objc_method(
}

// TODO
// if (diagram().should_include(method)) {
LOG_DBG("Adding ObjC method: {}", method.name());
if (diagram().should_include(method)) {
LOG_DBG("Adding ObjC method: {}", method.name());

c.add_method(std::move(method));
//}
c.add_method(std::move(method));
}
}

void translation_unit_visitor::process_method_properties(
Expand Down
12 changes: 12 additions & 0 deletions src/common/model/filters/diagram_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ tvl::value_t filter_visitor::match(
return match(d, m.access());
}

tvl::value_t filter_visitor::match(
const diagram &d, const class_diagram::model::objc_method &m) const
{
return match(d, m.access());
}

tvl::value_t filter_visitor::match(
const diagram &d, const class_diagram::model::objc_member &m) const
{
return match(d, m.access());
}

tvl::value_t filter_visitor::match(const diagram & /*d*/,
const sequence_diagram::model::participant & /*p*/) const
{
Expand Down
6 changes: 6 additions & 0 deletions src/common/model/filters/diagram_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ class filter_visitor {
virtual tvl::value_t match(
const diagram &d, const class_diagram::model::class_member &m) const;

virtual tvl::value_t match(
const diagram &d, const class_diagram::model::objc_method &m) const;

virtual tvl::value_t match(
const diagram &d, const class_diagram::model::objc_member &m) const;

virtual tvl::value_t match(
const diagram &d, const sequence_diagram::model::participant &p) const;

Expand Down
1 change: 1 addition & 0 deletions tests/t00085/.clang-uml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ diagrams:
glob:
- t00085.m
filter_mode: advanced
include_system_headers: true
include:
anyof:
paths:
Expand Down
6 changes: 3 additions & 3 deletions tests/t00085/t00085.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
@interface It00085 : NSObject {
int _defaultMember;

@public
@public
NSString *_publicMember;

@protected
@protected
NSString *_protectedMember;

@private
@private
NSString *_privateMember;
}

Expand Down
29 changes: 24 additions & 5 deletions tests/t00085/test_case.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,39 @@ TEST_CASE("t00085")

REQUIRE(IsObjCInterface(src, "It00085"));
// REQUIRE(IsBaseClass(src, "A", "B"));

REQUIRE(IsField<Protected>(src, "It00085", "_defaultMember", "int"));
REQUIRE(IsField<Public>(src, "It00085", "_publicMember", "NSString *"));
REQUIRE(IsField<Protected>(
src, "It00085", "_protectedMember", "NSString *"));
REQUIRE(
IsField<Private>(src, "It00085", "_privateMember", "NSString *"));

REQUIRE(IsMethod<Public>(
src, "It00085", "addValue:", "NSInteger", "NSInteger otherValue"));
REQUIRE(IsMethod<Public, Static>(
src, "It00085", "currentSharedCounter", "NSInteger"));
REQUIRE(IsMethod<Public>(src, "It00085", "displayDetails", "void"));
REQUIRE(IsMethod<Public, Static>(
src, "It00085", "incrementSharedCounter", "void"));
REQUIRE(IsMethod<Public>(src, "It00085", "initWithName:value:",
"instancetype", "NSString * name, NSInteger value"));
REQUIRE(IsMethod<Public>(src, "It00085", "multiplyValueBy:andAdd:",
"NSInteger", "NSInteger multiplier, NSInteger addition"));
REQUIRE(IsMethod<Public>(src, "It00085", "name", "NSString *"));
REQUIRE(IsMethod<Public>(src, "It00085",
"performOperationWithBlock:", "void", "void (^)(NSInteger) block"));
REQUIRE(IsMethod<Public>(src, "It00085", "resetValue", "void"));
REQUIRE(IsMethod<Public>(
src, "It00085", "addValue", "NSInteger", "NSInteger otherValue"));

// REQUIRE(IsAssociation<Private>(src, "D", "A", "as"));

// REQUIRE(HasNote(src, "A", "left", "This is class A"));
src, "It00085", "setName:", "void", "NSString * name"));
REQUIRE(IsMethod<Public, Static>(src, "It00085",
"setSharedCounter:", "void", "NSInteger sharedCounter"));
REQUIRE(IsMethod<Public>(
src, "It00085", "setValue:", "void", "NSInteger value"));
REQUIRE(IsMethod<Public, Static>(
src, "It00085", "sharedCounter", "NSInteger"));
REQUIRE(IsMethod<Public, Static>(
src, "It00085", "sharedInstance", "instancetype"));
REQUIRE(IsMethod<Public>(src, "It00085", "value", "NSInteger"));
});
}

0 comments on commit d66c06f

Please sign in to comment.