From 0596f614d916e529395cc3fa7df04e3552d772ff Mon Sep 17 00:00:00 2001 From: Raul Sanchez-Mateos Lizano Date: Mon, 16 Sep 2024 12:06:44 +0200 Subject: [PATCH] Refactor some asserts to conditional expressions (#238) * Refactor some asserts to conditional expressions Signed-off-by: Raul Sanchez-Mateos * Fix build issue Signed-off-by: JesusPoderoso * Refactor substraction operation Signed-off-by: JesusPoderoso * Refs #21681: Remove death asserts in tests Signed-off-by: JesusPoderoso --------- Signed-off-by: Raul Sanchez-Mateos Signed-off-by: JesusPoderoso Co-authored-by: JesusPoderoso --- .../listener/DomainListener.hpp | 8 +- src/cpp/StatisticsBackendData.cpp | 30 ++- src/cpp/database/database_queue.cpp | 18 +- src/cpp/database/samples.hpp | 12 +- test/unittest/Database/SampleTests.cpp | 9 +- .../unittest/StatisticsBackend/CMakeLists.txt | 21 -- .../CallingUserListenersTests.cpp | 170 --------------- .../StatisticsBackendTests.cpp | 199 ------------------ 8 files changed, 59 insertions(+), 408 deletions(-) diff --git a/include/fastdds_statistics_backend/listener/DomainListener.hpp b/include/fastdds_statistics_backend/listener/DomainListener.hpp index f9c5ac63d..2b708cc73 100644 --- a/include/fastdds_statistics_backend/listener/DomainListener.hpp +++ b/include/fastdds_statistics_backend/listener/DomainListener.hpp @@ -75,9 +75,11 @@ class FASTDDS_STATISTICS_BACKEND_DllAPI DomainListener void on_instance_undiscovered() { - assert (current_count > 0); - --current_count; - --current_count_change; + if (current_count > 0) + { + --current_count; + --current_count_change; + } } void on_status_read() diff --git a/src/cpp/StatisticsBackendData.cpp b/src/cpp/StatisticsBackendData.cpp index 677de5cbf..a24d0d489 100644 --- a/src/cpp/StatisticsBackendData.cpp +++ b/src/cpp/StatisticsBackendData.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -122,7 +123,11 @@ void StatisticsBackendData::on_data_available( DataKind data_kind) { auto monitor = monitors_by_entity_.find(domain_id); - assert(monitor != monitors_by_entity_.end()); + if (monitor == monitors_by_entity_.end()) + { + logWarning(STATISTICS_BACKEND_DATA, "Monitor not found for domain " << domain_id); + return; + } if (should_call_domain_listener(*monitor->second, CallbackKind::ON_DATA_AVAILABLE, data_kind)) { @@ -140,7 +145,11 @@ void StatisticsBackendData::on_status_reported( StatusKind status_kind) { auto monitor = monitors_by_entity_.find(domain_id); - assert(monitor != monitors_by_entity_.end()); + if (monitor == monitors_by_entity_.end()) + { + logWarning(STATISTICS_BACKEND_DATA, "Monitor not found for domain " << domain_id); + return; + } if (should_call_domain_listener(*monitor->second, CallbackKind::ON_STATUS_REPORTED)) { @@ -228,7 +237,12 @@ void StatisticsBackendData::on_domain_entity_discovery( DiscoveryStatus discovery_status) { auto monitor = monitors_by_entity_.find(domain_id); - assert(monitor != monitors_by_entity_.end()); + if (monitor == monitors_by_entity_.end()) + { + logWarning(STATISTICS_BACKEND_DATA, "Monitor not found for domain " << domain_id); + return; + } + switch (entity_kind) { case EntityKind::PARTICIPANT: @@ -306,7 +320,7 @@ void StatisticsBackendData::on_domain_entity_discovery( } default: { - assert(false && "Invalid domain entity kind"); + logWarning(STATISTICS_BACKEND, "Invalid domain entity kind"); } } } @@ -316,7 +330,11 @@ void StatisticsBackendData::on_physical_entity_discovery( EntityKind entity_kind, DiscoveryStatus discovery_status) { - assert(discovery_status != DiscoveryStatus::UPDATE); + if (discovery_status == DiscoveryStatus::UPDATE) + { + logWarning(STATISTICS_BACKEND, "UPDATE discovery status is not supported for physical entities"); + return; + } switch (entity_kind) { @@ -370,7 +388,7 @@ void StatisticsBackendData::on_physical_entity_discovery( } default: { - assert(false && "Invalid physical entity kind"); + logWarning(STATISTICS_BACKEND, "Invalid physical entity kind"); } } } diff --git a/src/cpp/database/database_queue.cpp b/src/cpp/database/database_queue.cpp index 3c15d03d2..fbede4265 100644 --- a/src/cpp/database/database_queue.cpp +++ b/src/cpp/database/database_queue.cpp @@ -187,7 +187,11 @@ EntityId DatabaseEntityQueue::process_datareader( try { participant_id = database_->get_entity_by_guid(EntityKind::PARTICIPANT, to_string(participant_guid)); - assert(participant_id.first == info.domain_id); + if (participant_id.first != info.domain_id) + { + throw BadParameter("Participant " + to_string(participant_guid) + + " found in the database but it is not in the current domain"); + } } catch (const Exception&) { @@ -258,7 +262,11 @@ EntityId DatabaseEntityQueue::process_datawriter( try { participant_id = database_->get_entity_by_guid(EntityKind::PARTICIPANT, to_string(participant_guid)); - assert(participant_id.first == info.domain_id); + if (participant_id.first != info.domain_id) + { + throw BadParameter("Participant " + to_string(participant_guid) + + " found in the database but it is not in the current domain"); + } } catch (const Exception&) { @@ -317,7 +325,11 @@ EntityId DatabaseEntityQueue::process_endpoint_discovery( try { participant_id = database_->get_entity_by_guid(EntityKind::PARTICIPANT, to_string(participant_guid)); - assert(participant_id.first == info.domain_id); + if (participant_id.first != info.domain_id) + { + throw BadParameter("Participant " + to_string(participant_guid) + + " found in the database but it is not in the current domain"); + } } catch (const Exception&) { diff --git a/src/cpp/database/samples.hpp b/src/cpp/database/samples.hpp index 26ce48c7a..a234a0b0a 100644 --- a/src/cpp/database/samples.hpp +++ b/src/cpp/database/samples.hpp @@ -22,6 +22,7 @@ #include +#include #include #include @@ -122,10 +123,17 @@ struct EntityCountSample : StatisticsSample inline EntityCountSample operator -( const EntityCountSample& other) const noexcept { - assert(count >= other.count); EntityCountSample ret(kind); ret.src_ts = src_ts; - ret.count = count - other.count; + if (count >= other.count) + { + ret.count = count - other.count; + } + else + { + logWarning(STATISTICS_BACKEND, "Subtraction of EntityCountSample resulted in a negative number"); + ret.count = 0; + } return ret; } diff --git a/test/unittest/Database/SampleTests.cpp b/test/unittest/Database/SampleTests.cpp index 8414f2c7f..b3815be3a 100644 --- a/test/unittest/Database/SampleTests.cpp +++ b/test/unittest/Database/SampleTests.cpp @@ -109,6 +109,7 @@ TEST(database, entitycountsample_operator_comparison) ASSERT_NE(sample_1, sample_2); } +// updated to avoid unnecessary asserts in code, check #21681 Redmine task TEST(database, entitycountsample_operator_minus) { EntityCountSample sample_1; @@ -125,11 +126,11 @@ TEST(database, entitycountsample_operator_minus) ASSERT_EQ(sample_3.count, 1u); ASSERT_EQ(sample_3.src_ts, sample_1.src_ts); -#ifndef NDEBUG - // Assertion are active here + // If negative number, subtraction returns 0 sample_2.count = 3; - ASSERT_DEATH(sample_1 - sample_2, ""); -#endif // ifndef NDEBUG + sample_3 = sample_1 - sample_2; + ASSERT_EQ(sample_3.count, 0u); + ASSERT_EQ(sample_3.src_ts, sample_1.src_ts); } TEST(database, bytecountsample_operator_comparison) diff --git a/test/unittest/StatisticsBackend/CMakeLists.txt b/test/unittest/StatisticsBackend/CMakeLists.txt index 8382531d1..36daf4812 100644 --- a/test/unittest/StatisticsBackend/CMakeLists.txt +++ b/test/unittest/StatisticsBackend/CMakeLists.txt @@ -70,7 +70,6 @@ set(BACKEND_TEST_LIST get_type get_data_supported_entity_kinds set_alias - internal_callbacks_negative_cases set_listener_non_existent_monitor get_domain_view_graph get_domain_view_graph_invalid_domain @@ -178,26 +177,6 @@ foreach(test_name ${USER_LISTENERS_TEST_LIST}) endforeach() -set(USER_LISTENERS_DEATH_TEST_LIST - wrong_entity_kind - ) - -foreach(test_name ${USER_LISTENERS_DEATH_TEST_LIST}) - add_test(NAME calling_user_listeners_DeathTest.${test_name} - COMMAND calling_user_listeners_tests - --gtest_filter=calling_user_listeners_DeathTest.${test_name}:*/calling_user_listeners_DeathTest.${test_name}/*) - - if(TEST_FRIENDLY_PATH) - set_tests_properties(calling_user_listeners_DeathTest.${test_name} - PROPERTIES - ENVIRONMENT "PATH=${TEST_FRIENDLY_PATH}" - ) - endif(TEST_FRIENDLY_PATH) -endforeach() - -# Add xfail label to failing test -set_property(TEST calling_user_listeners_DeathTest.wrong_entity_kind PROPERTY LABELS xfail) - set(USER_LISTENERS_TEST_LIST_PHYSICAL_ENTITIES entity_discovered entity_discovered_not_in_mask diff --git a/test/unittest/StatisticsBackend/CallingUserListenersTests.cpp b/test/unittest/StatisticsBackend/CallingUserListenersTests.cpp index 4bdc14273..c21f01bb0 100644 --- a/test/unittest/StatisticsBackend/CallingUserListenersTests.cpp +++ b/test/unittest/StatisticsBackend/CallingUserListenersTests.cpp @@ -421,17 +421,6 @@ TEST_P(calling_user_listeners_tests_physical_entities, entity_discovered) EXPECT_EQ(1, status.current_count_change); }); -#ifndef NDEBUG - // Expectation: The user listener will fail assert with update - ASSERT_DEATH(test_entity_discovery(PHYSICAL, - [&]( - EntityId, - const DomainListener::Status&) - { - }, - details::StatisticsBackendData::DiscoveryStatus::UPDATE), ""); -#endif // ifndef NDEBUG - // Expectation: The user listener is called with removel test_entity_discovery(PHYSICAL, [&]( @@ -1034,165 +1023,6 @@ class calling_user_listeners_tests : public ::testing::Test }; -using calling_user_listeners_DeathTest = calling_user_listeners_tests; -TEST_F(calling_user_listeners_DeathTest, wrong_entity_kind) -{ - MockedPhysicalListener physical_listener; - MockedDomainListener domain_listener; - - auto monitor_id = StatisticsBackend::init_monitor(0, &domain_listener, CallbackMask::all(), - DataKindMask::all()); - StatisticsBackend::set_physical_listener( - &physical_listener, - CallbackMask::all(), - DataKindMask::all()); - - // Expectation: The call asserts - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(1), - EntityKind::DOMAIN, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - - // Expectation: The call asserts - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(1), - EntityKind::PARTICIPANT, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - - // Expectation: The call asserts - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(1), - EntityKind::TOPIC, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - - // Expectation: The call asserts - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(1), - EntityKind::DATAREADER, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - - // Expectation: The call asserts - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(1), - EntityKind::DATAWRITER, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - - // Expectation: The call asserts - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(1), - EntityKind::INVALID, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - - // Expectation: The call asserts - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::HOST, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::HOST, - details::StatisticsBackendData::DiscoveryStatus::UPDATE), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::HOST, - details::StatisticsBackendData::DiscoveryStatus::UNDISCOVERY), - ".*"); - - // Expectation: The call asserts - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::USER, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::USER, - details::StatisticsBackendData::DiscoveryStatus::UPDATE), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::USER, - details::StatisticsBackendData::DiscoveryStatus::UNDISCOVERY), - ".*"); - - // Expectation: The call asserts - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::PROCESS, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::PROCESS, - details::StatisticsBackendData::DiscoveryStatus::UPDATE), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::PROCESS, - details::StatisticsBackendData::DiscoveryStatus::UNDISCOVERY), - ".*"); - - // Expectation: The call asserts - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::LOCATOR, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::LOCATOR, - details::StatisticsBackendData::DiscoveryStatus::UPDATE), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::LOCATOR, - details::StatisticsBackendData::DiscoveryStatus::UNDISCOVERY), - ".*"); - - // Expectation: The call asserts - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::INVALID, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::INVALID, - details::StatisticsBackendData::DiscoveryStatus::UPDATE), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::INVALID, - details::StatisticsBackendData::DiscoveryStatus::UNDISCOVERY), - ".*"); - - // Stop the monitor to avoid interfering on next tests - StatisticsBackend::stop_monitor(monitor_id); -} - class calling_user_listeners_tests_datas : public ::testing::TestWithParam> { public: diff --git a/test/unittest/StatisticsBackend/StatisticsBackendTests.cpp b/test/unittest/StatisticsBackend/StatisticsBackendTests.cpp index 67cd77ed8..6b977c07b 100644 --- a/test/unittest/StatisticsBackend/StatisticsBackendTests.cpp +++ b/test/unittest/StatisticsBackend/StatisticsBackendTests.cpp @@ -505,205 +505,6 @@ TEST_F(statistics_backend_tests, set_alias) } } -TEST_F(statistics_backend_tests, internal_callbacks_negative_cases) -{ -#ifndef NDEBUG - - StatisticsBackendTest::set_database(db); - - // Will be using entities that are on the database, - // to make sure the error is due to the intended reason - // (make sure the exceptions are not because of non existent entities) - - // Check that there is a monitor with EntityId(7) - // This will be used in all calls to on_domain_entity_discovery - auto result = StatisticsBackendTest::get_entities(EntityKind::DOMAIN, EntityId(7)); - ASSERT_EQ(1u, result.size()); - EntityId monitor_id = EntityId(7); - - // Check that there is a host with EntityId(1) - result = StatisticsBackendTest::get_entities(EntityKind::HOST, EntityId(1)); - ASSERT_EQ(1u, result.size()); - - // Calling on_domain_entity_discovery with a physical entity should fail - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::HOST, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::HOST, - details::StatisticsBackendData::DiscoveryStatus::UNDISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(1), - EntityKind::HOST, - details::StatisticsBackendData::DiscoveryStatus::UPDATE), - ".*"); - - // Check that there is a user with EntityId(3) - result = StatisticsBackendTest::get_entities(EntityKind::USER, EntityId(3)); - ASSERT_EQ(1u, result.size()); - - // Calling on_domain_entity_discovery with a physical entity should fail - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(3), - EntityKind::USER, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(3), - EntityKind::USER, - details::StatisticsBackendData::DiscoveryStatus::UNDISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(3), - EntityKind::USER, - details::StatisticsBackendData::DiscoveryStatus::UPDATE), - ".*"); - - // Check that there is a process with EntityId(5) - result = StatisticsBackendTest::get_entities(EntityKind::PROCESS, EntityId(5)); - ASSERT_EQ(1u, result.size()); - - // Calling on_domain_entity_discovery with a physical entity should fail - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(5), - EntityKind::PROCESS, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(5), - EntityKind::PROCESS, - details::StatisticsBackendData::DiscoveryStatus::UNDISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(5), - EntityKind::PROCESS, - details::StatisticsBackendData::DiscoveryStatus::UPDATE), - ".*"); - - // Check that there is a locator with EntityId(17) - result = StatisticsBackendTest::get_entities(EntityKind::LOCATOR, EntityId(17)); - ASSERT_EQ(1u, result.size()); - - // Calling on_domain_entity_discovery with a physical entity should fail - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(17), - EntityKind::LOCATOR, - details::StatisticsBackendData::DiscoveryStatus::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(17), - EntityKind::LOCATOR, - details::StatisticsBackendData::DiscoveryStatus::UNDISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_domain_entity_discovery( - monitor_id, - EntityId(17), - EntityKind::LOCATOR, - details::StatisticsBackendData::DiscoveryStatus::UPDATE), - ".*"); - - // Check that there is a Participant with EntityId(9) - result = StatisticsBackendTest::get_entities(EntityKind::PARTICIPANT, EntityId(9)); - ASSERT_EQ(1u, result.size()); - - // Calling on_physical_entity_discovery with a domain entity should fail - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(9), - EntityKind::PARTICIPANT, - details::StatisticsBackendData::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(9), - EntityKind::PARTICIPANT, - details::StatisticsBackendData::UNDISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(9), - EntityKind::PARTICIPANT, - details::StatisticsBackendData::UPDATE), - ".*"); - - // Check that there is a topic with EntityId(11) - result = StatisticsBackendTest::get_entities(EntityKind::TOPIC, EntityId(11)); - ASSERT_EQ(1u, result.size()); - - // Calling on_physical_entity_discovery with a domain entity should fail - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(11), - EntityKind::TOPIC, - details::StatisticsBackendData::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(11), - EntityKind::TOPIC, - details::StatisticsBackendData::UNDISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(11), - EntityKind::TOPIC, - details::StatisticsBackendData::UPDATE), - ".*"); - - // Check that there is a datareader with EntityId(13) - result = StatisticsBackendTest::get_entities(EntityKind::DATAREADER, EntityId(13)); - ASSERT_EQ(1u, result.size()); - - // Calling on_physical_entity_discovery with a domain entity should fail - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(13), - EntityKind::DATAREADER, - details::StatisticsBackendData::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(13), - EntityKind::DATAREADER, - details::StatisticsBackendData::UNDISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(13), - EntityKind::DATAREADER, - details::StatisticsBackendData::UPDATE), - ".*"); - - // Check that there is a datawriter with EntityId(17) - result = StatisticsBackendTest::get_entities(EntityKind::DATAWRITER, EntityId(17)); - ASSERT_EQ(1u, result.size()); - - // Calling on_physical_entity_discovery with a domain entity should fail - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(17), - EntityKind::DATAWRITER, - details::StatisticsBackendData::DISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(17), - EntityKind::DATAWRITER, - details::StatisticsBackendData::UNDISCOVERY), - ".*"); - ASSERT_DEATH(details::StatisticsBackendData::get_instance()->on_physical_entity_discovery( - EntityId(17), - EntityKind::DATAWRITER, - details::StatisticsBackendData::UPDATE), - ".*"); - -#endif // ifndef NDEBUG -} - TEST_F(statistics_backend_tests, set_listener_non_existent_monitor) { // Set the profile to ignore discovery data from other processes