From 29d6e47143b6801f58d8f9b8508073f7f4f086d0 Mon Sep 17 00:00:00 2001 From: Kerstin Keller Date: Tue, 26 Nov 2024 15:33:45 +0100 Subject: [PATCH] Run Tests in different configuration combinations. --- .../src/registration_getclients.cpp | 94 ++++++++++-------- .../src/registration_getpublisherids.cpp | 8 ++ .../src/registration_getservices.cpp | 95 +++++++++++-------- .../src/registration_getsubscriberids.cpp | 8 ++ 4 files changed, 129 insertions(+), 76 deletions(-) diff --git a/ecal/tests/cpp/registration_test_public/src/registration_getclients.cpp b/ecal/tests/cpp/registration_test_public/src/registration_getclients.cpp index 8c3a09b067..41befcd8b4 100644 --- a/ecal/tests/cpp/registration_test_public/src/registration_getclients.cpp +++ b/ecal/tests/cpp/registration_test_public/src/registration_getclients.cpp @@ -25,14 +25,33 @@ enum { CMN_MONITORING_TIMEOUT_MS = (5000 + 100), CMN_REGISTRATION_REFRESH_MS = (1000) }; -TEST(core_cpp_registration_public, ClientExpiration) + +// struct to hold the test parameters +struct ClientsTestParams { - // initialize eCAL API - eCAL::Initialize(0, nullptr, "core_cpp_registration_public"); + eCAL::Configuration configuration; +}; - // enable loop back communication in the same process - eCAL::Util::EnableLoopback(true); +// test class that accepts TestParams as a parameter +class ClientsTestFixture : public ::testing::TestWithParam +{ +protected: + void SetUp() override + { + // set configuration from the test parameters + auto params = GetParam(); + eCAL::Initialize(params.configuration, "core_cpp_registration_public", eCAL::Init::All); + eCAL::Util::EnableLoopback(true); + } + void TearDown() override + { + // clean up + eCAL::Finalize(); + } +}; +TEST_P(ClientsTestFixture, ClientExpiration) +{ std::map client_info_map; // create simple client and let it expire @@ -83,19 +102,10 @@ TEST(core_cpp_registration_public, ClientExpiration) // check size EXPECT_EQ(client_info_map.size(), 0); - - // finalize eCAL API - eCAL::Finalize(); } -TEST(core_cpp_registration_public, ClientEqualQualities) +TEST_P(ClientsTestFixture, ClientEqualQualities) { - // initialize eCAL API - eCAL::Initialize(0, nullptr, "core_cpp_registration_public"); - - // enable loop back communication in the same process - eCAL::Util::EnableLoopback(true); - std::map client_info_map; // create 2 clients with the same quality of data type information @@ -181,19 +191,10 @@ TEST(core_cpp_registration_public, ClientEqualQualities) // check size EXPECT_EQ(client_info_map.size(), 0); - - // finalize eCAL API - eCAL::Finalize(); } -TEST(core_cpp_registration_public, ClientDifferentQualities) +TEST_P(ClientsTestFixture, ClientDifferentQualities) { - // initialize eCAL API - eCAL::Initialize(0, nullptr, "core_cpp_registration_public"); - - // enable loop back communication in the same process - eCAL::Util::EnableLoopback(true); - std::map client_info_map; // create 2 clients with different qualities of data type information @@ -258,19 +259,10 @@ TEST(core_cpp_registration_public, ClientDifferentQualities) // check size EXPECT_EQ(client_info_map.size(), 0); - - // finalize eCAL API - eCAL::Finalize(); } -TEST(core_cpp_registration_public, GetClientIDs) +TEST_P(ClientsTestFixture, GetClientIDs) { - // initialize eCAL API - eCAL::Initialize(0, nullptr, "core_cpp_registration_public"); - - // enable loop back communication in the same process - eCAL::Util::EnableLoopback(true); - // create simple client { // create client @@ -296,7 +288,33 @@ TEST(core_cpp_registration_public, GetClientIDs) EXPECT_EQ(service_method_info, info.info); } } - - // finalize eCAL API - eCAL::Finalize(); } + +INSTANTIATE_TEST_SUITE_P( + core_cpp_registration_public_clients, + ClientsTestFixture, + ::testing::Values( + ClientsTestParams{ []() { + // shm + eCAL::Configuration config; + config.registration.layer.shm.enable = true; + config.registration.layer.udp.enable = false; + return config; + }() }, + ClientsTestParams{ []() { + // shm + host group name + eCAL::Configuration config; + config.registration.layer.shm.enable = true; + config.registration.layer.udp.enable = false; + config.registration.host_group_name = "abc"; + return config; + }() }, + ClientsTestParams{ []() { + // udp + eCAL::Configuration config; + config.registration.layer.shm.enable = false; + config.registration.layer.udp.enable = true; + return config; + }() } + ) +); \ No newline at end of file diff --git a/ecal/tests/cpp/registration_test_public/src/registration_getpublisherids.cpp b/ecal/tests/cpp/registration_test_public/src/registration_getpublisherids.cpp index 18b5fa6146..3243d01dd7 100644 --- a/ecal/tests/cpp/registration_test_public/src/registration_getpublisherids.cpp +++ b/ecal/tests/cpp/registration_test_public/src/registration_getpublisherids.cpp @@ -161,6 +161,14 @@ INSTANTIATE_TEST_SUITE_P( config.registration.layer.udp.enable = false; return config; }() }, + TestParams{ 10, []() { + // shm + host group name + eCAL::Configuration config; + config.registration.layer.shm.enable = true; + config.registration.layer.udp.enable = false; + config.registration.host_group_name = "abc"; + return config; + }() }, TestParams{ 10, []() { // udp eCAL::Configuration config; diff --git a/ecal/tests/cpp/registration_test_public/src/registration_getservices.cpp b/ecal/tests/cpp/registration_test_public/src/registration_getservices.cpp index 195053c40c..2dbb9b4f3d 100644 --- a/ecal/tests/cpp/registration_test_public/src/registration_getservices.cpp +++ b/ecal/tests/cpp/registration_test_public/src/registration_getservices.cpp @@ -26,14 +26,33 @@ enum { CMN_REGISTRATION_REFRESH_MS = (1000) }; -TEST(core_cpp_registration_public, ServiceExpiration) +// struct to hold the test parameters +struct ServicesTestParams { - // initialize eCAL API - eCAL::Initialize(0, nullptr, "core_cpp_registration_public"); + eCAL::Configuration configuration; +}; - // enable loop back communication in the same process - eCAL::Util::EnableLoopback(true); +// test class that accepts TestParams as a parameter +class ServicesTestFixture : public ::testing::TestWithParam +{ +protected: + void SetUp() override + { + // set configuration from the test parameters + auto params = GetParam(); + eCAL::Initialize(params.configuration, "core_cpp_registration_public", eCAL::Init::All); + eCAL::Util::EnableLoopback(true); + } + void TearDown() override + { + // clean up + eCAL::Finalize(); + } +}; + +TEST_P(ServicesTestFixture, ServiceExpiration) +{ std::map service_info_map; // create simple service and let it expire @@ -80,19 +99,10 @@ TEST(core_cpp_registration_public, ServiceExpiration) // check size EXPECT_EQ(service_info_map.size(), 0); - - // finalize eCAL API - eCAL::Finalize(); } -TEST(core_cpp_registration_public, ServiceEqualQualities) +TEST_P(ServicesTestFixture, ServiceEqualQualities) { - // initialize eCAL API - eCAL::Initialize(0, nullptr, "core_cpp_registration_public"); - - // enable loop back communication in the same process - eCAL::Util::EnableLoopback(true); - std::map service_info_map; // create 2 services with the same quality of data type information @@ -170,19 +180,10 @@ TEST(core_cpp_registration_public, ServiceEqualQualities) // check size EXPECT_EQ(service_info_map.size(), 0); - - // finalize eCAL API - eCAL::Finalize(); } -TEST(core_cpp_registration_public, ServiceDifferentQualities) +TEST_P(ServicesTestFixture, ServiceDifferentQualities) { - // initialize eCAL API - eCAL::Initialize(0, nullptr, "core_cpp_registration_public"); - - // enable loop back communication in the same process - eCAL::Util::EnableLoopback(true); - std::map service_info_map; // create 2 services with different qualities of data type information @@ -239,19 +240,10 @@ TEST(core_cpp_registration_public, ServiceDifferentQualities) // check size EXPECT_EQ(service_info_map.size(), 0); - - // finalize eCAL API - eCAL::Finalize(); } -TEST(core_cpp_registration_public, GetServiceIDs) +TEST_P(ServicesTestFixture, GetServiceIDs) { - // initialize eCAL API - eCAL::Initialize(0, nullptr, "core_cpp_registration_public"); - - // enable loop back communication in the same process - eCAL::Util::EnableLoopback(true); - // create simple server { // create server @@ -285,7 +277,34 @@ TEST(core_cpp_registration_public, GetServiceIDs) EXPECT_EQ(service_method_info, info.info); } } - - // finalize eCAL API - eCAL::Finalize(); } + + +INSTANTIATE_TEST_SUITE_P( + core_cpp_registration_public_services, + ServicesTestFixture, + ::testing::Values( + ServicesTestParams{[]() { + // shm + eCAL::Configuration config; + config.registration.layer.shm.enable = true; + config.registration.layer.udp.enable = false; + return config; + }() }, + ServicesTestParams{ []() { + // shm + host group name + eCAL::Configuration config; + config.registration.layer.shm.enable = true; + config.registration.layer.udp.enable = false; + config.registration.host_group_name = "abc"; + return config; + }() }, + ServicesTestParams{[]() { + // udp + eCAL::Configuration config; + config.registration.layer.shm.enable = false; + config.registration.layer.udp.enable = true; + return config; + }() } + ) +); \ No newline at end of file diff --git a/ecal/tests/cpp/registration_test_public/src/registration_getsubscriberids.cpp b/ecal/tests/cpp/registration_test_public/src/registration_getsubscriberids.cpp index 28138fcbc0..ef73cc481b 100644 --- a/ecal/tests/cpp/registration_test_public/src/registration_getsubscriberids.cpp +++ b/ecal/tests/cpp/registration_test_public/src/registration_getsubscriberids.cpp @@ -161,6 +161,14 @@ INSTANTIATE_TEST_SUITE_P( config.registration.layer.udp.enable = false; return config; }() }, + TestParams{10, []() { + // shm + host group name + eCAL::Configuration config; + config.registration.layer.shm.enable = true; + config.registration.layer.udp.enable = false; + config.registration.host_group_name = "abc"; + return config; + }() }, TestParams{ 10, []() { // udp eCAL::Configuration config;