diff --git a/test/unittest/logging/LogTests.cpp b/test/unittest/logging/LogTests.cpp index 2e5b2ce7e90..3af37a9eabd 100644 --- a/test/unittest/logging/LogTests.cpp +++ b/test/unittest/logging/LogTests.cpp @@ -508,13 +508,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 3b231a673ff..e7bfcb81a61 100644 --- a/test/unittest/logging/log_macros/LogMacrosDefaultTests.cpp +++ b/test/unittest/logging/log_macros/LogMacrosDefaultTests.cpp @@ -48,13 +48,20 @@ TEST_F(LogMacrosTests, default_macros_test) # endif // Visual Studio specific behavior #endif // Check default macro values -#if !HAVE_LOG_NO_INFO && (defined(_DEBUG) || defined(__DEBUG) || !defined(NDEBUG)) - static constexpr unsigned int expected_result = 3; + // 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)))) + 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()); }