diff --git a/iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp b/iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp index 2cabba55b31..4e80871c160 100644 --- a/iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp +++ b/iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp @@ -139,11 +139,6 @@ constexpr const char SERVICE_DISCOVERY_SERVICE_NAME[] = "ServiceDiscovery"; constexpr const char SERVICE_DISCOVERY_INSTANCE_NAME[] = "RouDi_ID"; constexpr const char SERVICE_DISCOVERY_EVENT_NAME[] = "ServiceRegistry"; -namespace runtime -{ -using ServiceContainer = iox::cxx::vector; -} - // Nodes constexpr uint32_t MAX_NODE_NUMBER = 1000U; constexpr uint32_t MAX_NODE_PER_PROCESS = 50U; diff --git a/iceoryx_posh/test/integrationtests/test_service_discovery.cpp b/iceoryx_posh/test/integrationtests/test_service_discovery.cpp index 2a2cfb7db0f..9071a0d7bfa 100644 --- a/iceoryx_posh/test/integrationtests/test_service_discovery.cpp +++ b/iceoryx_posh/test/integrationtests/test_service_discovery.cpp @@ -718,4 +718,139 @@ TEST_F(ServiceDiscoveryPubSub_test, ServiceDiscoveryNotifiedbyListenerFindsSingl EXPECT_THAT(serviceContainer.front(), Eq(serviceDescriptionToSearchFor)); } +struct Comparator +{ + bool operator()(const ServiceDescription& a, const ServiceDescription& b) + { + if (a.getServiceIDString() < b.getServiceIDString()) + { + return true; + } + if (b.getServiceIDString() < a.getServiceIDString()) + { + return false; + } + + if (a.getInstanceIDString() < b.getInstanceIDString()) + { + return true; + } + if (b.getInstanceIDString() < a.getInstanceIDString()) + { + return false; + } + + if (a.getEventIDString() < b.getEventIDString()) + { + return true; + } + return false; + } +}; + +bool sortAndCompare(ServiceContainer& a, ServiceContainer& b) +{ + std::sort(a.begin(), a.end(), Comparator()); + std::sort(b.begin(), b.end(), Comparator()); + return a == b; +} + +struct ReferenceDiscovery +{ + ServiceContainer services; + + ReferenceDiscovery() + { + services.emplace_back(iox::roudi::IntrospectionMempoolService); + services.emplace_back(iox::roudi::IntrospectionPortService); + services.emplace_back(iox::roudi::IntrospectionPortThroughputService); + services.emplace_back(iox::roudi::IntrospectionSubscriberPortChangingDataService); + services.emplace_back(iox::roudi::IntrospectionProcessService); + services.emplace_back(iox::SERVICE_DISCOVERY_SERVICE_NAME, + iox::SERVICE_DISCOVERY_INSTANCE_NAME, + iox::SERVICE_DISCOVERY_EVENT_NAME); + } + + void add(const ServiceDescription& s) + { + services.emplace_back(s); + } + + // brute force reference implementation + ServiceContainer findService(const optional& service, + const optional& instance, + const optional& event) + { + ServiceContainer result; + for (auto& s : services) + { + bool match = (service) ? (s.getServiceIDString() == *service) : true; + match &= (instance) ? (s.getInstanceIDString() == *instance) : true; + match &= (event) ? (s.getEventIDString() == *event) : true; + + if (match) + { + result.emplace_back(s); + } + } + return result; + } +}; + +#include + +// generalize for REQ-RES +class ReferenceServiceDiscovery_test : public ServiceDiscoveryPubSub_test +{ + public: + // std::vector publishers; + iox::cxx::vector publishers; + ReferenceDiscovery referenceDiscovery; + ServiceContainer expectedResult; + + // variation point + std::function& service, optional& instance, optional& event)> + modifySearchArgs = + [](optional&, optional& instance, optional&) { instance.reset(); }; + + void add(const ServiceDescription& s) + { + // does not work with std::vector, but probably with std::array + // probably because vector grows dynamically and may require copying (though the error is about move) + publishers.emplace_back(s); + referenceDiscovery.add(s); + } + + void findService(const optional& service, + const optional& instance, + const optional& event) noexcept + { + optional s(service); + optional i(instance); + optional e(event); + + modifySearchArgs(s, i, e); + + ServiceDiscoveryPubSub_test::findService(s, i, e, MessagingPattern::PUB_SUB); + expectedResult = referenceDiscovery.findService(s, i, e); + EXPECT_TRUE(sortAndCompare(serviceContainer, expectedResult)); + } + + void clear() + { + expectedResult.clear(); + } +}; + +TEST_F(ReferenceServiceDiscovery_test, FindInternalServices) +{ + findService(iox::capro::Wildcard, iox::capro::Wildcard, iox::capro::Wildcard); +} + +TEST_F(ReferenceServiceDiscovery_test, FindSingleService) +{ + add({"a", "b", "c"}); + findService({"a"}, {"b"}, {"c"}); +} + } // namespace