Skip to content

Commit

Permalink
Fixed LogMacrosTests.default_macros_test (#2228)
Browse files Browse the repository at this point in the history
* Refs 12535. Fixed LogMacrosTests.default_macros_test.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs 12535. Print macros values.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs 12535. Fixed test.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs 12535. Uncrustify.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs 12535. Avoid build error on MSVC.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
(cherry picked from commit 989ee0a)

Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
  • Loading branch information
mergify[bot] and MiguelCompany authored Sep 27, 2021
1 parent b820c35 commit 1da41cd
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions test/unittest/logging/log_macros/LogMacrosDefaultTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,39 @@
#include "LogMacros.hpp"
#include <gtest/gtest.h>

#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());
Expand Down

0 comments on commit 1da41cd

Please sign in to comment.