From 13057e07a4f729146a17d998acde48a2eeef7002 Mon Sep 17 00:00:00 2001 From: Kristof Hannemann Date: Tue, 17 Dec 2024 13:08:20 +0100 Subject: [PATCH 1/4] Adapted return types of ecal core functions --- .../core/include/ecal/cimpl/ecal_core_cimpl.h | 8 +-- ecal/core/include/ecal/ecal_core.h | 24 ++++---- ecal/core/src/cimpl/ecal_core_cimpl.cpp | 8 +-- ecal/core/src/ecal.cpp | 55 ++++++++++--------- ecal/core/src/ecal_globals.cpp | 11 ++-- ecal/core/src/ecal_globals.h | 4 +- ecal/tests/c/core_test/src/core_test.cpp | 4 +- ecal/tests/cpp/core_test/src/core_test.cpp | 42 +++++++------- lang/python/core/src/ecal_clang.cpp | 10 ++-- lang/python/core/src/ecal_clang.h | 6 +- 10 files changed, 88 insertions(+), 84 deletions(-) diff --git a/ecal/core/include/ecal/cimpl/ecal_core_cimpl.h b/ecal/core/include/ecal/cimpl/ecal_core_cimpl.h index 62b25d767d..d7a6a81ff6 100644 --- a/ecal/core/include/ecal/cimpl/ecal_core_cimpl.h +++ b/ecal/core/include/ecal/cimpl/ecal_core_cimpl.h @@ -67,7 +67,7 @@ extern "C" * @param unit_name_ Defines the name of the eCAL unit. * @param components_ Defines which component to initialize. * - * @return Zero if succeeded, 1 if already initialized, -1 if failed. + * @return Zero if succeeded. **/ ECALC_API int eCAL_Initialize(const char *unit_name_, unsigned int components_); @@ -83,21 +83,21 @@ extern "C" /** * @brief Finalize eCAL API. * - * @return Zero if succeeded, 1 if already finalized, -1 if failed. + * @return Zero if succeeded. **/ ECALC_API int eCAL_Finalize(); /** * @brief Check eCAL initialize state. * - * @return None zero if eCAL is initialized. + * @return Non-zero if eCAL is initialized. **/ ECALC_API int eCAL_IsInitialized(); /** * @brief Return the eCAL process state. * - * @return None zero if eCAL is in proper state. + * @return Non-zero if eCAL is in proper state. **/ ECALC_API int eCAL_Ok(); diff --git a/ecal/core/include/ecal/ecal_core.h b/ecal/core/include/ecal/ecal_core.h index 9c6b2088c5..0cb789523d 100644 --- a/ecal/core/include/ecal/ecal_core.h +++ b/ecal/core/include/ecal/ecal_core.h @@ -63,9 +63,9 @@ namespace eCAL * @param unit_name_ Defines the name of the eCAL unit. * @param components_ Defines which component to initialize. * - * @return Zero if succeeded, 1 if already initialized, -1 if failed. + * @return True. **/ - ECAL_API int Initialize(const std::string& unit_name_ = "", unsigned int components_ = Init::Default); + ECAL_API bool Initialize(const std::string& unit_name_ = "", unsigned int components_ = Init::Default); /** * @brief Initialize eCAL API. @@ -74,32 +74,32 @@ namespace eCAL * @param unit_name_ Defines the name of the eCAL unit. * @param components_ Defines which component to initialize. * - * @return Zero if succeeded, 1 if already initialized, -1 if failed. + * @return True if succeeded. **/ - ECAL_API int Initialize(eCAL::Configuration& config_, const std::string& unit_name_ = "", unsigned int components_ = Init::Default); + ECAL_API bool Initialize(eCAL::Configuration& config_, const std::string& unit_name_ = "", unsigned int components_ = Init::Default); /** * @brief Finalize eCAL API. * - * @return Zero if succeeded, 1 if already finalized, -1 if failed. + * @return True if succeeded. **/ - ECAL_API int Finalize(); + ECAL_API bool Finalize(); /** * @brief Check eCAL initialize state. * - * @return 1 if eCAL is initialized. + * @return True if eCAL is initialized. **/ - ECAL_API int IsInitialized(); + ECAL_API bool IsInitialized(); /** * @brief Check initialization state for a specific component. * * @param component_ Specific component to check * - * @return 1 if eCAL component is initialized. + * @return True if eCAL component is initialized. **/ - ECAL_API int IsInitialized(unsigned int component_); + ECAL_API bool IsInitialized(unsigned int component_); /** @@ -107,9 +107,9 @@ namespace eCAL * * @param unit_name_ Defines the name of the eCAL unit. * - * @return Zero if succeeded. + * @return True if succeeded. **/ - ECAL_API int SetUnitName(const std::string& unit_name_); + ECAL_API bool SetUnitName(const std::string& unit_name_); /** * @brief Return the eCAL process state. diff --git a/ecal/core/src/cimpl/ecal_core_cimpl.cpp b/ecal/core/src/cimpl/ecal_core_cimpl.cpp index bf0a12214f..66bcca0f7c 100644 --- a/ecal/core/src/cimpl/ecal_core_cimpl.cpp +++ b/ecal/core/src/cimpl/ecal_core_cimpl.cpp @@ -45,23 +45,23 @@ extern "C" ECALC_API int eCAL_Initialize(const char* unit_name_, unsigned int components_) { const std::string unit_name = (unit_name_ != nullptr) ? std::string(unit_name_) : std::string(""); - return eCAL::Initialize(unit_name, components_); + return static_cast(!eCAL::Initialize(unit_name, components_)); } ECALC_API int eCAL_SetUnitName(const char* unit_name_) { const std::string unit_name = (unit_name_ != nullptr) ? std::string(unit_name_) : std::string(""); - return(eCAL::SetUnitName(unit_name)); + return static_cast(!eCAL::SetUnitName(unit_name)); } ECALC_API int eCAL_Finalize() { - return(eCAL::Finalize()); + return static_cast(!eCAL::Finalize()); } ECALC_API int eCAL_IsInitialized() { - return(eCAL::IsInitialized()); + return static_cast(eCAL::IsInitialized()); } ECALC_API int eCAL_Ok() diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index e689e4012c..7cbad47e01 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -85,9 +85,9 @@ namespace eCAL * @param unit_name_ Defines the name of the eCAL unit. * @param components_ Defines which component to initialize. * - * @return Zero if succeeded, 1 if already initialized, -1 if failed. + * @return True if succeeded. **/ - int Initialize(const std::string& unit_name_ /*= ""*/, unsigned int components_ /*= Init::Default*/) + bool Initialize(const std::string& unit_name_ /*= ""*/, unsigned int components_ /*= Init::Default*/) { eCAL::Configuration config; @@ -101,9 +101,9 @@ namespace eCAL * @param unit_name_ Defines the name of the eCAL unit. * @param components_ Defines which component to initialize. * - * @return Zero if succeeded, 1 if already initialized, -1 if failed. + * @return True if succeeded **/ - int Initialize(eCAL::Configuration& config_, const std::string& unit_name_ /*= nullptr*/, unsigned int components_ /*= Init::Default*/) + bool Initialize(eCAL::Configuration& config_, const std::string& unit_name_ /*= nullptr*/, unsigned int components_ /*= Init::Default*/) { InitGlobals(); @@ -114,7 +114,7 @@ namespace eCAL g_globals_ctx_ref_cnt++; // (post)initialize single components - const int success = g_globals()->Initialize(components_); + const auto success = g_globals()->Initialize(components_); if (config_.command_line_arguments.dump_config) { @@ -129,13 +129,14 @@ namespace eCAL * * @param component_ Check specific component or 0 for general state of eCAL core. * - * @return 1 if eCAL is initialized. + * @return True if eCAL is initialized. **/ - int IsInitialized() + bool IsInitialized() { - if (g_globals_ctx == nullptr) return(0); - if(g_globals()->IsInitialized()) return(1); - return(0); + if (g_globals_ctx == nullptr) + return false; + + return g_globals()->IsInitialized(); } /** @@ -143,13 +144,14 @@ namespace eCAL * * @param component_ Check specific component or 0 for general state of eCAL core. * - * @return 1 if eCAL is initialized. + * @return True if component is initialized. **/ - int IsInitialized(unsigned int component_) + bool IsInitialized(unsigned int component_) { - if (g_globals_ctx == nullptr) return(0); - if (g_globals()->IsInitialized(component_)) return(1); - return(0); + if (g_globals_ctx == nullptr) + return false; + + return g_globals()->IsInitialized(component_); } /** @@ -157,29 +159,32 @@ namespace eCAL * * @param unit_name_ Defines the name of the eCAL unit. * - * @return Zero if succeeded, -1 if failed. + * @return True if succeeded. **/ - int SetUnitName(const std::string& unit_name_) + bool SetUnitName(const std::string& unit_name_) { - if (unit_name_.empty()) return -1; + if (unit_name_.empty()) + return false; g_unit_name = unit_name_; - return 0; + return true; } /** * @brief Finalize eCAL API. * - * @return Zero if succeeded, 1 if already finalized, -1 if failed. + * @return True if succeeded. **/ - int Finalize() + bool Finalize() { - if (g_globals_ctx == nullptr) return 1; + if (g_globals_ctx == nullptr) + return false; g_globals_ctx_ref_cnt--; - if (g_globals_ctx_ref_cnt > 0) return 0; - int const ret = g_globals()->Finalize(); + if (g_globals_ctx_ref_cnt > 0) + return true; + const auto ret = g_globals()->Finalize(); delete g_globals_ctx; g_globals_ctx = nullptr; - return(ret); + return ret; } /** diff --git a/ecal/core/src/ecal_globals.cpp b/ecal/core/src/ecal_globals.cpp index 6d662bc8b5..513078b14c 100644 --- a/ecal/core/src/ecal_globals.cpp +++ b/ecal/core/src/ecal_globals.cpp @@ -48,7 +48,7 @@ namespace eCAL Finalize(); } - int CGlobals::Initialize(unsigned int components_) + bool CGlobals::Initialize(unsigned int components_) { // will be set if any new module was initialized bool new_initialization(false); @@ -245,8 +245,7 @@ namespace eCAL initialized = true; components |= components_; - if (new_initialization) return 0; - else return 1; + return new_initialization; } bool CGlobals::IsInitialized() @@ -286,9 +285,9 @@ namespace eCAL } } - int CGlobals::Finalize() + bool CGlobals::Finalize() { - if (!initialized) return(1); + if (!initialized) return false; // start destruction #if ECAL_CORE_MONITORING @@ -364,6 +363,6 @@ namespace eCAL // reset configuration to default values g_ecal_configuration = Configuration(); - return(0); + return true; } } diff --git a/ecal/core/src/ecal_globals.h b/ecal/core/src/ecal_globals.h index b6ba23db00..0c7c8f6fa5 100644 --- a/ecal/core/src/ecal_globals.h +++ b/ecal/core/src/ecal_globals.h @@ -62,13 +62,13 @@ namespace eCAL CGlobals(); ~CGlobals(); - int Initialize ( unsigned int components_); + bool Initialize ( unsigned int components_); bool IsInitialized (); bool IsInitialized ( unsigned int component_ ); unsigned int GetComponents() const { return(components); }; - int Finalize(); + bool Finalize(); const std::unique_ptr& log_provider() { return log_provider_instance; }; const std::unique_ptr& log_udp_receiver() { return log_udp_receiver_instance; }; diff --git a/ecal/tests/c/core_test/src/core_test.cpp b/ecal/tests/c/core_test/src/core_test.cpp index 208389d38f..9d781d6323 100644 --- a/ecal/tests/c/core_test/src/core_test.cpp +++ b/ecal/tests/c/core_test/src/core_test.cpp @@ -132,13 +132,13 @@ TEST(core_c_core, SetGetUnitName) EXPECT_STREQ("unit name", unit_name); // set nullptr unit name (should not change the unit name) - EXPECT_EQ(-1, eCAL_SetUnitName(nullptr)); + EXPECT_EQ(1, eCAL_SetUnitName(nullptr)); memset(unit_name, 0, sizeof(unit_name)); eCAL_Process_GetUnitName(unit_name, sizeof(unit_name)); EXPECT_STREQ("unit name", unit_name); // set empty unit name (should not change the unit name) - EXPECT_EQ(-1, eCAL_SetUnitName("")); + EXPECT_EQ(1, eCAL_SetUnitName("")); memset(unit_name, 0, sizeof(unit_name)); eCAL_Process_GetUnitName(unit_name, sizeof(unit_name)); EXPECT_STREQ("unit name", unit_name); diff --git a/ecal/tests/cpp/core_test/src/core_test.cpp b/ecal/tests/cpp/core_test/src/core_test.cpp index 4954b40024..6f90078f24 100644 --- a/ecal/tests/cpp/core_test/src/core_test.cpp +++ b/ecal/tests/cpp/core_test/src/core_test.cpp @@ -42,31 +42,31 @@ TEST(core_cpp_core, GetVersion) TEST(core_cpp_core, InitializeFinalize) { // Is eCAL API initialized ? - EXPECT_EQ(0, eCAL::IsInitialized()); + EXPECT_EQ(false, eCAL::IsInitialized()); // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("initialize_test")); + EXPECT_EQ(true, eCAL::Initialize("initialize_test")); // Is eCAL API initialized ? - EXPECT_EQ(1, eCAL::IsInitialized()); + EXPECT_EQ(true, eCAL::IsInitialized()); // initialize eCAL API again we expect return value 1 for yet initialized - EXPECT_EQ(1, eCAL::Initialize("initialize_test")); + EXPECT_EQ(false, eCAL::Initialize("initialize_test")); // finalize eCAL API we expect return value 0 even it will not be really finalized because it's 2 times initialzed and 1 time finalized - EXPECT_EQ(0, eCAL::Finalize()); + EXPECT_EQ(true, eCAL::Finalize()); // Is eCAL API initialized ? yes it' still initialized - EXPECT_EQ(1, eCAL::IsInitialized()); + EXPECT_EQ(true, eCAL::IsInitialized()); // finalize eCAL API we expect return value 0 because now it will be finalized - EXPECT_EQ(0, eCAL::Finalize()); + EXPECT_EQ(true, eCAL::Finalize()); // Is eCAL API initialized ? no - EXPECT_EQ(0, eCAL::IsInitialized()); + EXPECT_EQ(false, eCAL::IsInitialized()); // finalize eCAL API we expect return value 1 because it was finalized before - EXPECT_EQ(1, eCAL::Finalize()); + EXPECT_EQ(false, eCAL::Finalize()); } TEST(core_cpp_core, MultipleInitializeFinalize) @@ -75,10 +75,10 @@ TEST(core_cpp_core, MultipleInitializeFinalize) for (auto i = 0; i < 4; ++i) { // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("multiple_initialize_finalize_test")); + EXPECT_EQ(true, eCAL::Initialize("multiple_initialize_finalize_test")); // finalize eCAL API - EXPECT_EQ(0, eCAL::Finalize()); + EXPECT_EQ(true, eCAL::Finalize()); } } @@ -112,43 +112,43 @@ namespace TEST(core_cpp_core, SetGetUnitName) { // initialize eCAL API with empty unit name (eCAL will use process name as unit name) - EXPECT_EQ(0, eCAL::Initialize("")); + EXPECT_EQ(true, eCAL::Initialize("")); // Is eCAL API initialized ? - EXPECT_EQ(1, eCAL::IsInitialized()); + EXPECT_EQ(true, eCAL::IsInitialized()); // if we call eCAL_Initialize with empty unit name, eCAL will use the process name as unit name std::string process_name = extractProcessName(eCAL::Process::GetProcessName()); EXPECT_STREQ(process_name.c_str(), eCAL::Process::GetUnitName().c_str()); // set unit name (should change the name to 'unit name') - EXPECT_EQ(0, eCAL::SetUnitName("unit name")); + EXPECT_EQ(true, eCAL::SetUnitName("unit name")); EXPECT_STREQ("unit name", eCAL::Process::GetUnitName().c_str()); // set empty unit name (should not change the unit name) - EXPECT_EQ(-1, eCAL::SetUnitName("")); + EXPECT_EQ(false, eCAL::SetUnitName("")); EXPECT_STREQ("unit name", eCAL::Process::GetUnitName().c_str()); // finalize eCAL API we expect return value 0 because it will be finalized - EXPECT_EQ(0, eCAL::Finalize()); + EXPECT_EQ(true, eCAL::Finalize()); } TEST(core_cpp_core, eCAL_Ok) { // check uninitialized eCAL, should not be okay - EXPECT_EQ(0, eCAL::Ok()); + EXPECT_EQ(false, eCAL::Ok()); // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("okay_test")); + EXPECT_EQ(true, eCAL::Initialize("okay_test")); // check initialized eCAL, should be okay - EXPECT_EQ(1, eCAL::Ok()); + EXPECT_EQ(true, eCAL::Ok()); // finalize eCAL API we expect return value 0 because it will be finalized - EXPECT_EQ(0, eCAL::Finalize()); + EXPECT_EQ(true, eCAL::Finalize()); // check finalized eCAL, should not be okay - EXPECT_EQ(0, eCAL::Ok()); + EXPECT_EQ(false, eCAL::Ok()); } /* excluded for now, system timer jitter too high */ diff --git a/lang/python/core/src/ecal_clang.cpp b/lang/python/core/src/ecal_clang.cpp index ae3be3f631..9933efc429 100644 --- a/lang/python/core/src/ecal_clang.cpp +++ b/lang/python/core/src/ecal_clang.cpp @@ -103,7 +103,7 @@ const char* ecal_getdate() int ecal_initialize(const char* unit_name_) { std::string unit_name = (unit_name_ != nullptr) ? std::string(unit_name_) : std::string(""); - return(eCAL::Initialize(unit_name)); + return static_cast(!eCAL::Initialize(unit_name)); } /****************************************/ @@ -111,8 +111,8 @@ int ecal_initialize(const char* unit_name_) /****************************************/ int ecal_finalize() { - //* @return Zero if succeeded, 1 if still initialized, -1 if failed. - return(eCAL::Finalize()); + //* @return Zero if succeeded + return static_cast(!eCAL::Finalize()); } /****************************************/ @@ -121,7 +121,7 @@ int ecal_finalize() int ecal_is_initialized() { //* @return 1 if eCAL is initialized. - return(eCAL::IsInitialized()); + return static_cast(eCAL::IsInitialized()); } /****************************************/ @@ -129,7 +129,7 @@ int ecal_is_initialized() /****************************************/ int ecal_set_unit_name(const char* unit_name_) { - return(eCAL::SetUnitName(unit_name_)); + return static_cast(eCAL::SetUnitName(unit_name_)); } /****************************************/ diff --git a/lang/python/core/src/ecal_clang.h b/lang/python/core/src/ecal_clang.h index c6356ce5b5..7bc4ae9388 100644 --- a/lang/python/core/src/ecal_clang.h +++ b/lang/python/core/src/ecal_clang.h @@ -61,14 +61,14 @@ const char* ecal_getdate(); * @param argv_ Array of command line arguments. * @param unit_name_ Defines the name of the eCAL unit. * - * @return Zero if succeeded, 1 if already initialized, -1 if failed. + * @return Zero if succeeded. **/ int ecal_initialize(const char* unit_name_); /** * @brief Finalize eCAL API. * - * @return Zero if succeeded, 1 if already initialized, -1 if failed. + * @return Zero if succeeded. **/ int ecal_finalize(); @@ -84,7 +84,7 @@ int ecal_is_initialized(); * * @param unit_name_ Defines the name of the eCAL unit. * - * @return Zero if succeeded. + * @return Zero if succeeded. **/ int ecal_set_unit_name(const char *unit_name_); From ea8d6835bb7702e8dabaff756827dce2443624fd Mon Sep 17 00:00:00 2001 From: Kristof Hannemann <50989282+hannemn@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:04:21 +0100 Subject: [PATCH 2/4] Changed return type of GetLogging() and aligned unit tests --- ecal/core/include/ecal/ecal_log.h | 8 ++-- ecal/core/src/cimpl/ecal_log_cimpl.cpp | 2 +- ecal/core/src/logging/ecal_log.cpp | 20 +++++---- .../tests/cpp/config_test/src/config_test.cpp | 4 +- .../pubsub_test/src/pubsub_acknowledge.cpp | 4 +- .../src/pubsub_connection_test.cpp | 6 +-- .../pubsub_test/src/pubsub_receive_test.cpp | 8 ++-- .../tests/cpp/pubsub_test/src/pubsub_test.cpp | 8 ++-- lang/python/core/src/ecal_clang.cpp | 41 ------------------- lang/python/core/src/ecal_clang.h | 16 -------- lang/python/core/src/ecal_wrap.cxx | 2 +- 11 files changed, 33 insertions(+), 86 deletions(-) diff --git a/ecal/core/include/ecal/ecal_log.h b/ecal/core/include/ecal/ecal_log.h index 8e8854f8c1..0df0f9c477 100644 --- a/ecal/core/include/ecal/ecal_log.h +++ b/ecal/core/include/ecal/ecal_log.h @@ -48,17 +48,17 @@ namespace eCAL * * @param [out] log_ String to store the logging information. * - * @return Logging buffer length or zero if failed. + * @return True if succeeded. **/ - ECAL_API int GetLogging(std::string& log_); + ECAL_API bool GetLogging(std::string& log_); /** * @brief Get logging as struct. * * @param [out] log_ Target struct to store the logging information. * - * @return Number of log messages. + * @return True if succeeded. **/ - ECAL_API int GetLogging(Logging::SLogging& log_); + ECAL_API bool GetLogging(Logging::SLogging& log_); } } diff --git a/ecal/core/src/cimpl/ecal_log_cimpl.cpp b/ecal/core/src/cimpl/ecal_log_cimpl.cpp index b6508b3ce7..4ee5e7eeb3 100644 --- a/ecal/core/src/cimpl/ecal_log_cimpl.cpp +++ b/ecal/core/src/cimpl/ecal_log_cimpl.cpp @@ -37,7 +37,7 @@ extern "C" ECALC_API int eCAL_Logging_GetLogging(void* buf_, int buf_len_) { std::string buf; - if (eCAL::Logging::GetLogging(buf) != 0) + if (eCAL::Logging::GetLogging(buf)) { return(CopyBuffer(buf_, buf_len_, buf)); } diff --git a/ecal/core/src/logging/ecal_log.cpp b/ecal/core/src/logging/ecal_log.cpp index 5c5a2ecda6..dfab84264b 100644 --- a/ecal/core/src/logging/ecal_log.cpp +++ b/ecal/core/src/logging/ecal_log.cpp @@ -47,12 +47,14 @@ namespace eCAL * * @param [out] log_ String to store the logging information. * - * @return Logging buffer length or zero if failed. + * @return True if succeeded. **/ - int GetLogging(std::string& log_) + bool GetLogging(std::string& log_) { - if (g_log_udp_receiver() != nullptr) g_log_udp_receiver()->GetLogging(log_); - return static_cast(log_.size()); + if (g_log_udp_receiver() == nullptr) + return false; + g_log_udp_receiver()->GetLogging(log_); + return true; } /** @@ -60,12 +62,14 @@ namespace eCAL * * @param [out] log_ Target struct to store the logging information. * - * @return Number of struct elements if succeeded. + * @return True if succeeded. **/ - int GetLogging(Logging::SLogging& log_) + bool GetLogging(Logging::SLogging& log_) { - if (g_log_udp_receiver() != nullptr) g_log_udp_receiver()->GetLogging(log_); - return static_cast(log_.log_messages.size()); + if (g_log_udp_receiver() == nullptr) + return false; + g_log_udp_receiver()->GetLogging(log_); + return true; } } } diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 7bada83722..a78b3ff72f 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -82,7 +82,7 @@ TEST(core_cpp_config /*unused*/, user_config_passing /*unused*/) } // Initialize ecal api with custom config - EXPECT_EQ(0, eCAL::Initialize(custom_config, "User Config Passing Test", eCAL::Init::Default)); + EXPECT_EQ(true, eCAL::Initialize(custom_config, "User Config Passing Test", eCAL::Init::Default)); // Test boolean assignment, default is false EXPECT_EQ(drop_out_of_order_messages, eCAL::GetConfiguration().subscriber.drop_out_of_order_messages); @@ -107,7 +107,7 @@ TEST(core_cpp_config /*unused*/, user_config_passing /*unused*/) EXPECT_EQ(registration_refresh, eCAL::GetConfiguration().registration.registration_refresh); // Finalize eCAL API - EXPECT_EQ(0, eCAL::Finalize()); + EXPECT_EQ(true, eCAL::Finalize()); } TEST(core_cpp_config /*unused*/, user_config_death_test /*unused*/) diff --git a/ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp b/ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp index b32d6a1dbd..6a7a86385e 100644 --- a/ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp +++ b/ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp @@ -52,7 +52,7 @@ namespace TEST(core_cpp_pubsub, TimeoutAcknowledgment) { // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("TimeoutAcknowledgment", eCAL::Init::All)); + EXPECT_EQ(true, eCAL::Initialize("TimeoutAcknowledgment", eCAL::Init::All)); // create publisher config eCAL::Publisher::Configuration pub_config; @@ -110,5 +110,5 @@ TEST(core_cpp_pubsub, TimeoutAcknowledgment) // finalize eCAL API // without destroying any pub / sub - EXPECT_EQ(0, eCAL::Finalize()); + EXPECT_EQ(true, eCAL::Finalize()); } diff --git a/ecal/tests/cpp/pubsub_test/src/pubsub_connection_test.cpp b/ecal/tests/cpp/pubsub_test/src/pubsub_connection_test.cpp index c28f1159a2..dfe59570f5 100644 --- a/ecal/tests/cpp/pubsub_test/src/pubsub_connection_test.cpp +++ b/ecal/tests/cpp/pubsub_test/src/pubsub_connection_test.cpp @@ -31,7 +31,7 @@ TEST(core_cpp_pubsub, TestSubscriberIsPublishedTiming) { // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("subscriber_is_published")); + EXPECT_EQ(true, eCAL::Initialize("subscriber_is_published")); std::atomic do_start_publication(false); std::atomic publication_finished(false); @@ -131,7 +131,7 @@ TEST(core_cpp_pubsub, TestSubscriberIsPublishedTiming) TEST(core_cpp_pubsub, TestPublisherIsSubscribedTiming) { // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("publisher_is_subscribed")); + EXPECT_EQ(true, eCAL::Initialize("publisher_is_subscribed")); std::atomic do_start_publication(false); std::atomic publication_finished(false); @@ -226,7 +226,7 @@ TEST(core_cpp_pubsub, TestPublisherIsSubscribedTiming) TEST(core_cpp_pubsub, TestChainedPublisherSubscriberCallback) { // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("chained_publisher_subscriber")); + EXPECT_EQ(true, eCAL::Initialize("chained_publisher_subscriber")); // Set up counters for sent and received messages const int message_count = 10; diff --git a/ecal/tests/cpp/pubsub_test/src/pubsub_receive_test.cpp b/ecal/tests/cpp/pubsub_test/src/pubsub_receive_test.cpp index b7052a5b37..cac87251ec 100644 --- a/ecal/tests/cpp/pubsub_test/src/pubsub_receive_test.cpp +++ b/ecal/tests/cpp/pubsub_test/src/pubsub_receive_test.cpp @@ -69,7 +69,7 @@ void measure_execution_within_range(const std::string& description, std::functio TEST(core_cpp_pubsub, TimingSubscriberReceive) { // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("subscriber_receive_timing")); + EXPECT_EQ(true, eCAL::Initialize("subscriber_receive_timing")); // create simple string publisher eCAL::string::CPublisher pub("CLOCK"); @@ -156,14 +156,14 @@ TEST(core_cpp_pubsub, TimingSubscriberReceive) ); // finalize eCAL API - EXPECT_EQ(0, eCAL::Finalize()); + EXPECT_EQ(true, eCAL::Finalize()); } // This tests test for sporadically received empty messages which were a problem. TEST(core_cpp_pubsub, SporadicEmptyReceives) { // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("sporadic_empty_receives")); + EXPECT_EQ(true, eCAL::Initialize("sporadic_empty_receives")); // create simple string publisher eCAL::string::CPublisher pub("CLOCK"); @@ -209,5 +209,5 @@ TEST(core_cpp_pubsub, SporadicEmptyReceives) sub_t.join(); // finalize eCAL API - EXPECT_EQ(0, eCAL::Finalize()); + EXPECT_EQ(true, eCAL::Finalize()); } diff --git a/ecal/tests/cpp/pubsub_test/src/pubsub_test.cpp b/ecal/tests/cpp/pubsub_test/src/pubsub_test.cpp index dd8d66f06f..d55ef64ac3 100644 --- a/ecal/tests/cpp/pubsub_test/src/pubsub_test.cpp +++ b/ecal/tests/cpp/pubsub_test/src/pubsub_test.cpp @@ -64,7 +64,7 @@ namespace TEST(core_cpp_pubsub, LeakedPubSub) { // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("leaked pub/sub")); + EXPECT_EQ(true, eCAL::Initialize("leaked pub/sub")); // create subscriber and register a callback eCAL::CSubscriber sub("foo"); @@ -100,7 +100,7 @@ TEST(core_cpp_pubsub, LeakedPubSub) // finalize eCAL API // without destroying any pub / sub - EXPECT_EQ(0, eCAL::Finalize()); + EXPECT_EQ(true, eCAL::Finalize()); // stop publishing thread pub_stop = true; pub_t.join(); @@ -109,7 +109,7 @@ TEST(core_cpp_pubsub, LeakedPubSub) TEST(core_cpp_pubsub, CallbackDestruction) { // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("callback destruction")); + EXPECT_EQ(true, eCAL::Initialize("callback destruction")); // create subscriber and register a callback std::shared_ptr sub; @@ -158,7 +158,7 @@ TEST(core_cpp_pubsub, CallbackDestruction) // finalize eCAL API // without destroying any pub / sub - EXPECT_EQ(0, eCAL::Finalize()); + EXPECT_EQ(true, eCAL::Finalize()); } TEST(core_cpp_pubsub, SimpleMessage1) diff --git a/lang/python/core/src/ecal_clang.cpp b/lang/python/core/src/ecal_clang.cpp index 9933efc429..a485eb4dce 100644 --- a/lang/python/core/src/ecal_clang.cpp +++ b/lang/python/core/src/ecal_clang.cpp @@ -709,15 +709,6 @@ bool client_call_method_async(ECAL_HANDLE handle_, const char* method_name_, con } } -/****************************************/ -/* client_add_response_callback */ -/****************************************/ - -/****************************************/ -/* client_rem_response_callback */ -/****************************************/ - - /****************************************/ /* mon_initialize */ /****************************************/ @@ -733,35 +724,3 @@ int mon_finalize() { return(ecal_finalize()); } - -/****************************************/ -/* mon_get_logging */ -/****************************************/ -int mon_get_logging(const char** log_buf_, int* log_buf_len_) -{ - std::string log_s; - const int size = eCAL::Logging::GetLogging(log_s); - if(size > 0) - { - // this has to be freed by caller (ecal_free_mem) - char* cbuf = str_malloc(log_s); - if(cbuf == nullptr) return(0); - - if (log_buf_ != nullptr) { - *log_buf_ = cbuf; - if (log_buf_len_ != nullptr) *log_buf_len_ = static_cast(log_s.size()); - } - else { - // free allocated memory: - ecal_free_mem(cbuf); - if (log_buf_len_ != nullptr) *log_buf_len_ = 0; - // operation couldn't be completed successfullly. - return(0); - } - return(static_cast(log_s.size())); - } - else - { - return(0); - } -} diff --git a/lang/python/core/src/ecal_clang.h b/lang/python/core/src/ecal_clang.h index 7bc4ae9388..412083d09d 100644 --- a/lang/python/core/src/ecal_clang.h +++ b/lang/python/core/src/ecal_clang.h @@ -499,11 +499,6 @@ bool client_call_method(ECAL_HANDLE handle_, const char* method_name_, const cha **/ bool client_call_method_async(ECAL_HANDLE handle_, const char* method_name_, const char* request_, int request_len_, int timeout_); -/* TODO: not implemented and not used for now */ -//client_add_response_callback -//client_rem_response_callback - - /*************************************************************************/ /* monitoring */ /*************************************************************************/ @@ -520,14 +515,3 @@ int mon_initialize(); * @return Zero if succeeded, 1 if already initialized, -1 if failed. **/ int mon_finalize(); - -/** - * @brief Get logging string. - * - * @param [out] log_buf_ Pointer to store the monitoring information. - * @param [out] log_buf_len_ Length of allocated buffer, - * eCAL is allocating the buffer for you, use ecal_free_mem to free the buffer finally. - * - * @return Logging buffer length or zero if failed. -**/ -int mon_get_logging(const char** log_buf_, int* log_buf_len_); diff --git a/lang/python/core/src/ecal_wrap.cxx b/lang/python/core/src/ecal_wrap.cxx index 216bd633ec..556fd5963a 100644 --- a/lang/python/core/src/ecal_wrap.cxx +++ b/lang/python/core/src/ecal_wrap.cxx @@ -1261,7 +1261,7 @@ PyObject* mon_logging(PyObject* /*self*/, PyObject* /*args*/) PyObject* retList = PyList_New(0); eCAL::Logging::SLogging logging; - if (eCAL::Logging::GetLogging(logging) != 0) + if (eCAL::Logging::GetLogging(logging)) { for (const auto& log : logging.log_messages) { From 4984a471f9526dae7ded61b2846f78a7b5fcce15 Mon Sep 17 00:00:00 2001 From: Kristof Hannemann Date: Tue, 17 Dec 2024 15:00:15 +0100 Subject: [PATCH 3/4] Fixed logger test --- ecal/tests/cpp/logging_test/src/logging_test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ecal/tests/cpp/logging_test/src/logging_test.cpp b/ecal/tests/cpp/logging_test/src/logging_test.cpp index c482bb5c12..ca6a6c0733 100644 --- a/ecal/tests/cpp/logging_test/src/logging_test.cpp +++ b/ecal/tests/cpp/logging_test/src/logging_test.cpp @@ -179,7 +179,8 @@ int getLogging(eCAL::Logging::SLogging& log_) { std::this_thread::sleep_for(UDP_WAIT_TIME); - return eCAL::Logging::GetLogging(log_); + eCAL::Logging::GetLogging(log_); + return static_cast(log_.log_messages.size()); } TEST(logging_levels /*unused*/, all /*unused*/) @@ -193,6 +194,7 @@ TEST(logging_levels /*unused*/, all /*unused*/) eCAL::Logging::SLogging log; eCAL::Logging::Log(log_level_info, log_message); + EXPECT_EQ(getLogging(log), 1); eCAL::Logging::Log(log_level_warning, log_message); From f2ffa0d0b0db3d10f56031413ae7e0e817e1846f Mon Sep 17 00:00:00 2001 From: Kristof Hannemann <50989282+hannemn@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:40:41 +0100 Subject: [PATCH 4/4] Fixed pub/sub v5 tests --- .../tests/cpp/pubsub_v5_test/src/pubsub_connection_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ecal/tests/cpp/pubsub_v5_test/src/pubsub_connection_test.cpp b/ecal/tests/cpp/pubsub_v5_test/src/pubsub_connection_test.cpp index 7c4f2161c0..b2d5602a53 100644 --- a/ecal/tests/cpp/pubsub_v5_test/src/pubsub_connection_test.cpp +++ b/ecal/tests/cpp/pubsub_v5_test/src/pubsub_connection_test.cpp @@ -31,7 +31,7 @@ TEST(core_cpp_pubsub_v5, TestSubscriberIsPublishedTiming) { // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("subscriber_is_published")); + EXPECT_EQ(true, eCAL::Initialize("subscriber_is_published")); std::atomic do_start_publication(false); std::atomic publication_finished(false); @@ -131,7 +131,7 @@ TEST(core_cpp_pubsub_v5, TestSubscriberIsPublishedTiming) TEST(core_cpp_pubsub_v5, TestPublisherIsSubscribedTiming) { // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("publisher_is_subscribed")); + EXPECT_EQ(true, eCAL::Initialize("publisher_is_subscribed")); std::atomic do_start_publication(false); std::atomic publication_finished(false); @@ -226,7 +226,7 @@ TEST(core_cpp_pubsub_v5, TestPublisherIsSubscribedTiming) TEST(core_cpp_pubsub_v5, TestChainedPublisherSubscriberCallback) { // initialize eCAL API - EXPECT_EQ(0, eCAL::Initialize("chained_publisher_subscriber")); + EXPECT_EQ(true, eCAL::Initialize("chained_publisher_subscriber")); // Set up counters for sent and received messages const int message_count = 10;