Skip to content

Commit

Permalink
iox-#27 Implement LogStream stream operator for ServiceDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Feb 14, 2022
1 parent 1868ccd commit e88c1aa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "iceoryx_hoofs/cxx/serialization.hpp"
#include "iceoryx_hoofs/cxx/string.hpp"
#include "iceoryx_hoofs/cxx/vector.hpp"
#include "iceoryx_hoofs/log/logstream.hpp"
#include "iceoryx_posh/iceoryx_posh_types.hpp"

#include <cstdint>
Expand Down Expand Up @@ -182,6 +183,8 @@ bool serviceMatch(const ServiceDescription& first, const ServiceDescription& sec
/// @return the reference to `stream` which was provided as input parameter
std::ostream& operator<<(std::ostream& stream, const ServiceDescription& service) noexcept;

log::LogStream& operator<<(log::LogStream& stream, const ServiceDescription& service) noexcept;

} // namespace capro
} // namespace iox

Expand Down
8 changes: 8 additions & 0 deletions iceoryx_posh/source/capro/service_description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,13 @@ std::ostream& operator<<(std::ostream& stream, const ServiceDescription& service
return stream;
}

log::LogStream& operator<<(log::LogStream& stream, const ServiceDescription& service) noexcept
{
/// @todo #415 Add classHash, scope and interface
stream << "Service: " << service.getServiceIDString() << ", Instance: " << service.getInstanceIDString()
<< ", Event: " << service.getEventIDString();
return stream;
}

} // namespace capro
} // namespace iox
20 changes: 20 additions & 0 deletions iceoryx_posh/test/moduletests/test_capro_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "iceoryx_hoofs/cxx/convert.hpp"
#include "iceoryx_hoofs/cxx/serialization.hpp"
#include "iceoryx_hoofs/cxx/string.hpp"
#include "iceoryx_hoofs/testing/mocks/logger_mock.hpp"
#include "iceoryx_posh/capro/service_description.hpp"
/// @todo #415 replace the service registry include with the new discovery API header
#include "iceoryx_posh/internal/roudi/service_registry.hpp"
Expand Down Expand Up @@ -428,6 +429,25 @@ TEST_F(ServiceDescription_test, LessThanOperatorReturnsFalseIfEventStringOfFirst
EXPECT_FALSE(serviceDescription1 < serviceDescription2);
}

TEST_F(ServiceDescription_test, LogStreamConvertsServiceDescriptionToString)
{
::testing::Test::RecordProperty("TEST_ID", "42bc3f21-d9f4-4cc3-a37e-6508e1f981c1");
Logger_Mock loggerMock;

const IdString_t SERVICE_ID{"S"};
const IdString_t INSTANCE_ID{"I"};
const IdString_t EVENT_ID{"E"};
const std::string SERVICE_DESCRIPTION_AS_STRING{"Service: S, Instance: I, Event: E"};
auto sut = ServiceDescription{SERVICE_ID, INSTANCE_ID, EVENT_ID};

{
auto logstream = iox::log::LogStream(loggerMock);
logstream << sut;
}

ASSERT_THAT(loggerMock.m_logs.size(), Eq(1U));
EXPECT_THAT(loggerMock.m_logs[0].message, StrEq(SERVICE_DESCRIPTION_AS_STRING));
}

/// END SERVICEDESCRIPTION TESTS

Expand Down

0 comments on commit e88c1aa

Please sign in to comment.