Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClangTidy issue in lib/system/Route.hpp #1297

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/system/Route.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ namespace MAT_NS_BEGIN {
void operator()(TRealArgs&& ... args) const
{
for (IRoutePassThrough<TArgs...>* target : m_passthroughs) {
if (!(*target)(std::forward<TRealArgs>(args) ...)) {
if (!(*target)(args ...)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will args be coped for each call?

return;
}
}
if (m_target) {
(*m_target)(std::forward<TRealArgs>(args) ...);
(*m_target)(args ...);
}
}

Expand Down
36 changes: 12 additions & 24 deletions tests/unittests/RouteTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,17 @@ class Canary : public std::string {

class RouteTests : public StrictMock<Test> {
public:
RouteSink<RouteTests> sink0{this, &RouteTests::handleSink0};
RouteSink<RouteTests, int> sink1{this, &RouteTests::handleSink1};
RoutePassThrough<RouteTests, int> passThrough1a{this, &RouteTests::handlePassThrough1a};
RoutePassThrough<RouteTests, int> passThrough1b{this, &RouteTests::handlePassThrough1b};
RouteSink<RouteTests, int, bool&, NonCopyableThing const&, Canary, std::vector<int>&&> sink5{this, &RouteTests::handleSink5x};
RouteSink<RouteTests> sink0{this, &RouteTests::handleSink0};
RouteSink<RouteTests, int> sink1{this, &RouteTests::handleSink1};
RoutePassThrough<RouteTests, int> passThrough1a{this, &RouteTests::handlePassThrough1a};
RoutePassThrough<RouteTests, int> passThrough1b{this, &RouteTests::handlePassThrough1b};
RouteSink<RouteTests, int, bool&, NonCopyableThing const&, Canary> sink4{this, &RouteTests::handleSink4};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sink4

Is this change relating to the change in RouteSource::operator()?


MOCK_METHOD0(handleSink0, void());
MOCK_METHOD1(handleSink1, void(int));
MOCK_METHOD1(handlePassThrough1a, bool(int));
MOCK_METHOD1(handlePassThrough1b, bool(int));
MOCK_METHOD4(handleSink5, void(int, bool&, NonCopyableThing const &, Canary));

void handleSink5x(int a, bool& b, NonCopyableThing const& c, Canary d, std::vector<int>&& e)
{
// This extra function exists just to handle the r-value reference.
// The move cannot be done properly in a mocked method.
std::vector<int> x = std::move(e);
handleSink5(a, b, c, d);
}
MOCK_METHOD4(handleSink4, void(int, bool&, NonCopyableThing const &, Canary));
};


Expand All @@ -92,18 +84,16 @@ TEST_F(RouteTests, SinkPassesArgsAsDefined)
NonCopyableThing thing;
Canary canary;
canary.bear();
std::vector<int> data{1, 2, 3};

EXPECT_CALL(*this, handleSink5(123, _, Ref(thing), Eq("alive")))
EXPECT_CALL(*this, handleSink4(123, _, Ref(thing), Eq("alive")))
.WillOnce(DoAll(
SetArgReferee<1>(true),
InvokeArgument<3>()
));
sink5(123, flag, thing, canary, std::move(data));
sink4(123, flag, thing, canary);

EXPECT_THAT(flag, true);
EXPECT_THAT(canary, Eq("alive"));
EXPECT_THAT(data, IsEmpty());
}

TEST_F(RouteTests, SourceIsNoopWhenUnbound)
Expand All @@ -117,8 +107,8 @@ TEST_F(RouteTests, SourceCallsSink)
RouteSource<> source0;
source0 >> sink0;

RouteSource<int, bool&, NonCopyableThing const&, Canary, std::vector<int>&&> source5;
source5 >> sink5;
RouteSource<int, bool&, NonCopyableThing const&, Canary> source4;
source4 >> sink4;


EXPECT_CALL(*this, handleSink0())
Expand All @@ -130,17 +120,15 @@ TEST_F(RouteTests, SourceCallsSink)
NonCopyableThing thing;
Canary canary;
canary.bear();
std::vector<int> data{1, 2, 3};

EXPECT_CALL(*this, handleSink5(123, _, Ref(thing), Eq("alive")))
EXPECT_CALL(*this, handleSink4(123, _, Ref(thing), Eq("alive")))
.WillOnce(DoAll(
SetArgReferee<1>(true),
InvokeArgument<3>()
));
source5(123, flag, thing, canary, std::move(data));
source4(123, flag, thing, canary);
EXPECT_THAT(flag, true);
EXPECT_THAT(canary, Eq("alive"));
EXPECT_THAT(data, IsEmpty());
}

TEST_F(RouteTests, PassThroughsAreInvokedInBetween)
Expand Down
Loading