diff --git a/test/unittest/logging/LogTests.cpp b/test/unittest/logging/LogTests.cpp index aee0743b44f..25391773e28 100644 --- a/test/unittest/logging/LogTests.cpp +++ b/test/unittest/logging/LogTests.cpp @@ -533,13 +533,12 @@ TEST_F(LogTests, stdouterr_consumer_stream) std::vector LogTests::HELPER_WaitForEntries( uint32_t amount) { - size_t entries = 0; for (uint32_t i = 0; i != AsyncTries; i++) { - entries = mockConsumer->ConsumedEntries().size(); - if (entries == amount) + auto entries = mockConsumer->ConsumedEntries(); + if (entries.size() == amount) { - break; + return entries; } this_thread::sleep_for(chrono::milliseconds(AsyncWaitMs)); } diff --git a/test/unittest/logging/log_macros/LogMacros.hpp b/test/unittest/logging/log_macros/LogMacros.hpp index 1c6e54046cc..a4f092e9c31 100644 --- a/test/unittest/logging/log_macros/LogMacros.hpp +++ b/test/unittest/logging/log_macros/LogMacros.hpp @@ -59,13 +59,12 @@ class LogMacrosTests : public ::testing::Test std::vector HELPER_WaitForEntries( uint32_t amount) { - size_t entries = 0; for (uint32_t i = 0; i != AsyncTries; i++) { - entries = mockConsumer->ConsumedEntries().size(); - if (entries == amount) + auto entries = mockConsumer->ConsumedEntries(); + if (entries.size() == amount) { - break; + return entries; } this_thread::sleep_for(chrono::milliseconds(AsyncWaitMs)); } diff --git a/test/unittest/logging/log_macros/LogMacrosDefaultTests.cpp b/test/unittest/logging/log_macros/LogMacrosDefaultTests.cpp index 8bfc667a555..93c47f06b07 100644 --- a/test/unittest/logging/log_macros/LogMacrosDefaultTests.cpp +++ b/test/unittest/logging/log_macros/LogMacrosDefaultTests.cpp @@ -48,15 +48,20 @@ TEST_F(LogMacrosTests, default_macros_test) # endif // Visual Studio specific behavior #endif // Check default macro values -#if !HAVE_LOG_NO_INFO && \ + // Result depends on the log configuration +#if !HAVE_LOG_NO_INFO && \ + (defined(FASTDDS_ENFORCE_LOG_INFO) || \ ((defined(__INTERNALDEBUG) || defined(_INTERNALDEBUG)) && (defined(_DEBUG) || defined(__DEBUG) || \ - !defined(NDEBUG))) - static constexpr unsigned int expected_result = 3; + !defined(NDEBUG)))) + constexpr unsigned int expected_result = 3; #else - static constexpr unsigned int expected_result = 2; + constexpr unsigned int expected_result = 2; #endif // debug macros check - auto consumedEntries = HELPER_WaitForEntries(expected_result); + // Warning and error should always be logged. + // Info might be logged depending on the log configuration. + // We always wait for 3 entries, though not all of them might be present. + auto consumedEntries = HELPER_WaitForEntries(3u); ASSERT_EQ(expected_result, consumedEntries.size()); }