Skip to content

Commit

Permalink
[core] Protobuf Publisher Send should return the actual send size. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
KerstinKeller authored Jul 30, 2024
1 parent 8f80696 commit 9b4c0d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
3 changes: 1 addition & 2 deletions ecal/core/include/ecal/msg/protobuf/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ namespace eCAL
size_t Send(const T& msg_, long long time_ = DEFAULT_TIME_ARGUMENT)
{
CPayload payload{ msg_ };
eCAL::CPublisher::Send(payload, time_);
return(0);
return eCAL::CPublisher::Send(payload, time_);
}

private:
Expand Down
23 changes: 17 additions & 6 deletions ecal/tests/cpp/pubsub_proto_test/src/proto_subscriber_test.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -46,12 +46,20 @@ class ProtoSubscriberTest : public ::testing::Test {
eCAL::Finalize();
}

void SendPerson(eCAL::protobuf::CPublisher<pb::People::Person>& pub)
size_t SendPerson(eCAL::protobuf::CPublisher<pb::People::Person>& 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<size_t>(p.ByteSizeLong());
#else
return static_cast<size_t>(p.ByteSize());
#endif
}

void OnPerson(const char*, const pb::People::Person&, long long, long long)
Expand All @@ -60,6 +68,9 @@ class ProtoSubscriberTest : public ::testing::Test {
}

std::atomic<int> received_callbacks;

private:
pb::People::Person p;
};
using core_cpp_pubsub_proto_sub = ProtoSubscriberTest;

Expand All @@ -75,11 +86,11 @@ TEST_F(core_cpp_pubsub_proto_sub, 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());
}

TEST_F(core_cpp_pubsub_proto_sub, ProtoSubscriberTest_MoveAssignment)
Expand Down

0 comments on commit 9b4c0d3

Please sign in to comment.