diff options
Diffstat (limited to 'test/offer_tests/offer_test_big_sd_msg_service.cpp')
-rw-r--r-- | test/offer_tests/offer_test_big_sd_msg_service.cpp | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/test/offer_tests/offer_test_big_sd_msg_service.cpp b/test/offer_tests/offer_test_big_sd_msg_service.cpp index d5666c8..5424be3 100644 --- a/test/offer_tests/offer_test_big_sd_msg_service.cpp +++ b/test/offer_tests/offer_test_big_sd_msg_service.cpp @@ -12,11 +12,12 @@ #include <map> #include <algorithm> #include <atomic> +#include <algorithm> #include <gtest/gtest.h> #include <vsomeip/vsomeip.hpp> -#include "../../implementation/logging/include/logger.hpp" +#include <vsomeip/internal/logger.hpp> #include "offer_test_globals.hpp" @@ -24,12 +25,12 @@ class offer_test_big_sd_msg_service { public: offer_test_big_sd_msg_service(struct offer_test::service_info _service_info) : service_info_(_service_info), - // service with number 1 uses "vsomeipd" as application name + // service with number 1 uses "routingmanagerd" as application name // this way the same json file can be reused for all local tests - // including the ones with vsomeipd + // including the ones with routingmanagerd app_(vsomeip::runtime::get()->create_application("offer_test_big_sd_msg_service")), - counter_(0), wait_until_registered_(true), + wait_until_client_subscribed_to_all_services_(true), shutdown_method_called_(false), offer_thread_(std::bind(&offer_test_big_sd_msg_service::run, this)) { if (!app_->init()) { @@ -45,13 +46,22 @@ public: its_eventgroups.insert(offer_test::big_msg_eventgroup_id); for (std::uint16_t s = 1; s <= offer_test::big_msg_number_services; s++) { app_->offer_event(s, 0x1, - offer_test::big_msg_event_id, its_eventgroups, false); + offer_test::big_msg_event_id, its_eventgroups, + vsomeip::event_type_e::ET_EVENT, std::chrono::milliseconds::zero(), + false, true, nullptr, vsomeip::reliability_type_e::RT_UNKNOWN); + app_->register_subscription_handler(s, 0x1, offer_test::big_msg_eventgroup_id, + std::bind(&offer_test_big_sd_msg_service::on_subscription, + this, std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, std::placeholders::_4, s)); + subscriptions_[s] = 0; } app_->register_message_handler(vsomeip::ANY_SERVICE, vsomeip::ANY_INSTANCE, service_info_.shutdown_method_id, std::bind(&offer_test_big_sd_msg_service::on_shutdown_method_called, this, std::placeholders::_1)); + + app_->start(); } @@ -77,6 +87,31 @@ public: } } + bool on_subscription(vsomeip::client_t _client, + std::uint32_t _uid, std::uint32_t _gid, + bool _subscribed, + vsomeip::service_t _service) { + (void)_client; + (void)_uid; + (void)_gid; + if (_subscribed) { + subscriptions_[_service]++; + EXPECT_EQ(1u, subscriptions_[_service]); + if (std::all_of(subscriptions_.begin(), subscriptions_.end(), [&](const subscriptions_t::value_type& v){ + return v.second == 1; + })) { + std::lock_guard<std::mutex> its_lock(mutex_); + wait_until_client_subscribed_to_all_services_ = false; + VSOMEIP_WARNING << "************************************************************"; + VSOMEIP_WARNING << "Client subscribed to all services!"; + VSOMEIP_WARNING << "************************************************************"; + condition_.notify_one(); + } + } + + return true; + } + void on_shutdown_method_called(const std::shared_ptr<vsomeip::message> &_message) { app_->send(vsomeip::runtime::get()->create_response(_message)); std::this_thread::sleep_for(std::chrono::seconds(1)); @@ -102,17 +137,23 @@ public: VSOMEIP_DEBUG << "[" << std::setw(4) << std::setfill('0') << std::hex << service_info_.service_id << "] Offering"; offer(); + + while (wait_until_client_subscribed_to_all_services_) { + condition_.wait(its_lock); + } } private: struct offer_test::service_info service_info_; std::shared_ptr<vsomeip::application> app_; - std::uint32_t counter_; bool wait_until_registered_; + bool wait_until_client_subscribed_to_all_services_; std::mutex mutex_; std::condition_variable condition_; std::atomic<bool> shutdown_method_called_; + typedef std::map<vsomeip::service_t, std::uint32_t> subscriptions_t; + subscriptions_t subscriptions_; std::thread offer_thread_; }; |