Skip to content

Commit

Permalink
fixed logger locations in C. added test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Macheta committed Jul 2, 2024
1 parent 35af95b commit f0a6304
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/include/embetech/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ typedef struct {
# ifdef __cplusplus
# define LOGGER_HEADER_DESCR(lvl) (LOGGER_HeaderDescriptor{.level = lvl, .channel = LOGGER_HEADER "", .file = LOGGER_FILE "", .line = __LINE__})
# else
# define LOGGER_HEADER_DESCR(lvl) (LOGGER_HeaderDescriptor){.level = lvl, .channel = LOGGER_HEADER "", .file = LOGGER_FILE "", .line = __LINE__})
# define LOGGER_HEADER_DESCR(lvl) ((LOGGER_HeaderDescriptor){.level = lvl, .channel = LOGGER_HEADER "", .file = LOGGER_FILE "", .line = __LINE__})
# endif
#else

Expand Down
3 changes: 2 additions & 1 deletion tests/ut05_location/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ add_library(logger_test_proxy5_1 ${LOGGER_SOURCES})
target_include_directories(logger_test_proxy5_1 PUBLIC ${LOGGER_INCLUDES})
target_compile_definitions(logger_test_proxy5_1 PUBLIC LOGGER_HEADER_WITH_LOCATION=1 LOGGER_FILE="OVERRIDEN")

add_executable(logger_ut05_1 ut05_1_location.cpp)
add_executable(logger_ut05_1 ut05_1_location.cpp ut05_1_location.c)
target_link_libraries(logger_ut05_1 PRIVATE logger_test_proxy5_1 logger_test_common)

add_library(logger_test_proxy5_2 ${LOGGER_SOURCES})
Expand All @@ -35,6 +35,7 @@ add_dependencies(logger_ut logger_ut05_1)
add_dependencies(logger_ut logger_ut05_2)
add_dependencies(logger_ut logger_ut05_3)


gtest_discover_tests(logger_ut05_1)
gtest_discover_tests(logger_ut05_2)
gtest_discover_tests(logger_ut05_3)
7 changes: 7 additions & 0 deletions tests/ut05_location/ut05_1_location.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <embetech/logger.h>


void log_test_message(void) {
#line 1
LOGGER_NOTICE("test message");
}
17 changes: 15 additions & 2 deletions tests/ut05_location/ut05_1_location.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include <gtest/gtest.h>
#include <embetech/logger.h>
#include <gtest/gtest.h>

#include <sstream>


extern "C" void log_test_message(void); // defined in ut05_1_location.c


TEST(LOGGER, UT05_CodeLocation) {
std::stringstream received;
auto clear_output = [&received]() {
Expand All @@ -17,9 +20,15 @@ TEST(LOGGER, UT05_CodeLocation) {

char const* const msg = "test message";
{
char const* const expected = "DEFAULT (N) [OVERRIDEN:1]: test message\n";

#line 1
char const* const expected = "DEFAULT (N) [OVERRIDEN:2]: test message\n";
LOGGER_NOTICE(msg);

EXPECT_EQ(expected, received.str());
clear_output();

log_test_message();
EXPECT_EQ(expected, received.str());
clear_output();
}
Expand All @@ -31,5 +40,9 @@ TEST(LOGGER, UT05_CodeLocation) {
LOGGER_WARNING(msg);
EXPECT_EQ(expected, received.str());
clear_output();

log_test_message();
EXPECT_EQ(expected, received.str());
clear_output();
}
}

0 comments on commit f0a6304

Please sign in to comment.