Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
17 changes: 15 additions & 2 deletions src/cubeb_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string.h>

#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);
Expand Down
10 changes: 10 additions & 0 deletions test/test_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

/* cubeb_logging test */
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
Expand All @@ -23,6 +24,9 @@

#define PRINT_LOGS_TO_STDERR 0

using ::testing::HasSubstr;
using ::testing::Not;

std::atomic<uint32_t> log_statements_received = {0};
std::atomic<uint32_t> data_callback_call_count = {0};

Expand Down Expand Up @@ -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("\\")));
}
Loading