diff --git a/CMakeLists.txt b/CMakeLists.txt index 48faa145..5c1482a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -431,6 +431,7 @@ if(BUILD_TESTS) macro(cubeb_add_test NAME) add_executable(test_${NAME} test/test_${NAME}.cpp) target_include_directories(test_${NAME} PRIVATE ${gtest_SOURCE_DIR}/include src) + target_include_directories(test_${NAME} PRIVATE ${gmock_SOURCE_DIR}/include src) target_link_libraries(test_${NAME} PRIVATE cubeb gtest_main) add_test(${NAME} test_${NAME} --gtest_death_test_style=threadsafe) add_sanitizers(test_${NAME}) diff --git a/src/cubeb_log.h b/src/cubeb_log.h index ff028fc9..28193097 100644 --- a/src/cubeb_log.h +++ b/src/cubeb_log.h @@ -23,12 +23,25 @@ extern "C" { (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 \ : __FILE__) #endif -#else + +#else // !(defined(__GNUC__) || defined(__clang__)) + #define PRINTF_FORMAT(fmt, args) #include + +#if defined(_WIN32) +// handle both the case with backslashes and forward slashes +#define __FILENAME__ \ + (strrchr(__FILE__, '\\') \ + ? strrchr(__FILE__, '\\') + 1 \ + : (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)) + +#else // !defined(_WIN32) #define __FILENAME__ \ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) -#endif + +#endif // defined(_WIN32) +#endif // defined(__GNUC__) || defined(__clang__) void cubeb_log_set(cubeb_log_level log_level, cubeb_log_callback log_callback); diff --git a/test/test_logging.cpp b/test/test_logging.cpp index 54ff7181..8cf70a94 100644 --- a/test/test_logging.cpp +++ b/test/test_logging.cpp @@ -6,6 +6,7 @@ */ /* cubeb_logging test */ +#include "gmock/gmock.h" #include "gtest/gtest.h" #if !defined(_XOPEN_SOURCE) #define _XOPEN_SOURCE 600 @@ -23,6 +24,9 @@ #define PRINT_LOGS_TO_STDERR 0 +using ::testing::HasSubstr; +using ::testing::Not; + std::atomic log_statements_received = {0}; std::atomic data_callback_call_count = {0}; @@ -194,3 +198,9 @@ TEST(cubeb, logging_stress) ASSERT_TRUE(true); } + +TEST(cubeb, filename_macro) +{ + EXPECT_THAT(__FILENAME__, Not(HasSubstr("/"))); + EXPECT_THAT(__FILENAME__, Not(HasSubstr("\\"))); +}