From 1da41cd024b76226d66204b8063b83cce484af24 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 27 Sep 2021 07:28:10 +0200 Subject: [PATCH] Fixed LogMacrosTests.default_macros_test (#2228) * Refs 12535. Fixed LogMacrosTests.default_macros_test. Signed-off-by: Miguel Company * Refs 12535. Print macros values. Signed-off-by: Miguel Company * Refs 12535. Fixed test. Signed-off-by: Miguel Company * Refs 12535. Uncrustify. Signed-off-by: Miguel Company * Refs 12535. Avoid build error on MSVC. Signed-off-by: Miguel Company (cherry picked from commit 989ee0a85e3ad827c28d2f4fa36a0c9d1eec917e) Co-authored-by: Miguel Company --- .../log_macros/LogMacrosDefaultTests.cpp | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/test/unittest/logging/log_macros/LogMacrosDefaultTests.cpp b/test/unittest/logging/log_macros/LogMacrosDefaultTests.cpp index 8e7cd993606..ea430a922c9 100644 --- a/test/unittest/logging/log_macros/LogMacrosDefaultTests.cpp +++ b/test/unittest/logging/log_macros/LogMacrosDefaultTests.cpp @@ -18,19 +18,39 @@ #include "LogMacros.hpp" #include +#define log_str(x) #x +#define macro_print(mname) std::cout << #mname << " = " << \ + (std::string(#mname) == log_str(mname) ? "" : log_str(mname)) << std::endl + /* WARNING - This test will fail with any LOG_NO_ CMake option set different than default configuration * Check all log levels are active in debug mode, or INFO is not active in Release mode */ TEST_F(LogMacrosTests, default_macros_test) { + std::cout << std::endl << "logInfo #define'd related constants:" << std::endl; + macro_print(HAVE_LOG_NO_INFO); + macro_print(FASTDDS_ENFORCE_LOG_INFO); + macro_print(__INTERNALDEBUG); + macro_print(_INTERNALDEBUG); + macro_print(_DEBUG); + macro_print(__DEBUG); + macro_print(NDEBUG); + std::cout << std::endl; + logError(SampleCategory, "Sample error message"); logWarning(SampleCategory, "Sample warning message"); logInfo(SampleCategory, "Sample info message"); - unsigned int expected_result = 3; +#if defined(NDEBUG) && !HAVE_LOG_NO_INFO +# if !defined(_MSC_VER ) +# error "Unexpected default values for NDEBUG and HAVE_LOG_NO_INFO" +# endif // Visual Studio specific behavior +#endif // Check default macro values -#if !(__DEBUG || _DEBUG) - --expected_result; -#endif // CMAKE_BUILD_TYPE == DEBUG_TYPE +#if !HAVE_LOG_NO_INFO && (defined(_DEBUG) || defined(__DEBUG) || !defined(NDEBUG)) + static constexpr unsigned int expected_result = 3; +#else + static constexpr unsigned int expected_result = 2; +#endif // debug macros check auto consumedEntries = HELPER_WaitForEntries(expected_result); ASSERT_EQ(expected_result, consumedEntries.size());