From f736c30ac7f550e501d0e273fb6836a90a84957d Mon Sep 17 00:00:00 2001 From: eclipse-ecal-bot <111572016+eclipse-ecal-bot@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:39:20 +0200 Subject: [PATCH] [core] Protobuf Publisher Send should return the actual send size. (#1681) (#1684) --- .../include/ecal/msg/protobuf/publisher.h | 3 +-- .../src/proto_subscriber_test.cpp | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ecal/core/include/ecal/msg/protobuf/publisher.h b/ecal/core/include/ecal/msg/protobuf/publisher.h index b7479291e0..71fa862acb 100644 --- a/ecal/core/include/ecal/msg/protobuf/publisher.h +++ b/ecal/core/include/ecal/msg/protobuf/publisher.h @@ -166,8 +166,7 @@ namespace eCAL size_t Send(const T& msg_, long long time_, long long acknowledge_timeout_ms_) { CPayload payload{ msg_ }; - eCAL::CPublisher::Send(payload, time_, acknowledge_timeout_ms_); - return(0); + return eCAL::CPublisher::Send(payload, time_, acknowledge_timeout_ms_); } diff --git a/testing/ecal/pubsub_proto_test/src/proto_subscriber_test.cpp b/testing/ecal/pubsub_proto_test/src/proto_subscriber_test.cpp index 20732f51c6..b6bd2dacbe 100644 --- a/testing/ecal/pubsub_proto_test/src/proto_subscriber_test.cpp +++ b/testing/ecal/pubsub_proto_test/src/proto_subscriber_test.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,12 +50,20 @@ class ProtoSubscriberTest : public ::testing::Test { eCAL::Finalize(); } - void SendPerson(eCAL::protobuf::CPublisher& pub) + size_t SendPerson(eCAL::protobuf::CPublisher& pub) { - pb::People::Person p; p.set_id(1); p.set_name("Max"); - pub.Send(p); + return pub.Send(p); + } + + size_t GetPersonSize() + { +#if GOOGLE_PROTOBUF_VERSION >= 3001000 + return static_cast(p.ByteSizeLong()); +#else + return static_cast(p.ByteSize()); +#endif } void OnPerson(const char*, const pb::People::Person&, long long, long long) @@ -64,6 +72,9 @@ class ProtoSubscriberTest : public ::testing::Test { } std::atomic received_callbacks; + +private: + pb::People::Person p; }; TEST_F(ProtoSubscriberTest, SendReceive) @@ -78,11 +89,11 @@ TEST_F(ProtoSubscriberTest, SendReceive) std::this_thread::sleep_for(std::chrono::milliseconds(2000)); - SendPerson(person_pub); + auto bytes_send = SendPerson(person_pub); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // assert that the OnPerson callback has been called once. ASSERT_EQ(1, received_callbacks); - + ASSERT_EQ(bytes_send, GetPersonSize()); }