added mock log test

This commit is contained in:
Sergiu Deitsch 2021-10-12 11:55:27 +02:00
parent ce3533613b
commit 1398762db8
3 changed files with 17 additions and 3 deletions

View File

@ -188,6 +188,8 @@ int main(void)
}
" HAVE___SYNC_VAL_COMPARE_AND_SWAP)
cmake_push_check_state (RESET)
set (CMAKE_REQUIRED_LIBRARIES Threads::Threads)
check_cxx_source_compiles ("
#define _XOPEN_SOURCE 500
#include <pthread.h>
@ -199,6 +201,7 @@ int main(void)
return 0;
}
" HAVE_RWLOCK)
cmake_pop_check_state ()
check_cxx_source_compiles ("
__declspec(selectany) int a;
@ -830,7 +833,7 @@ if (BUILD_TESTING)
set_tests_properties (logging PROPERTIES TIMEOUT 30)
# FIXME: Skip flaky test
# FIXME: Skip flaky test
set_tests_properties (logging PROPERTIES SKIP_REGULAR_EXPRESSION
"Check failed: time_ns within LogTimes::LOG_PERIOD_TOL_NS of LogTimes::LOG_PERIOD_NS")
@ -855,6 +858,17 @@ if (BUILD_TESTING)
add_test (NAME symbolize COMMAND symbolize_unittest)
endif (TARGET symbolize_unittest)
if (HAVE_LIB_GMOCK)
add_executable (mock-log_unittest
src/mock-log_unittest.cc
src/mock-log.h
)
target_link_libraries (mock-log_unittest PRIVATE ${_GLOG_TEST_LIBS})
add_test (NAME mock-log COMMAND mock-log_unittest)
endif (HAVE_LIB_GMOCK)
# Generate an initial cache
get_cache_variables (_CACHEVARS)

View File

@ -72,7 +72,7 @@ class ScopedMockLog : public GOOGLE_NAMESPACE::LogSink {
ScopedMockLog() { AddLogSink(this); }
// When the object is destructed, it stops intercepting logs.
virtual ~ScopedMockLog() { RemoveLogSink(this); }
~ScopedMockLog() { RemoveLogSink(this); }
// Implements the mock method:
//

View File

@ -55,7 +55,7 @@ TEST(ScopedMockLogTest, InterceptsLog) {
ScopedMockLog log;
InSequence s;
EXPECT_CALL(log, Log(WARNING, HasSubstr("/mock-log_test.cc"), "Fishy."));
EXPECT_CALL(log, Log(WARNING, HasSubstr("/mock-log_unittest.cc"), "Fishy."));
EXPECT_CALL(log, Log(INFO, _, "Working..."))
.Times(2);
EXPECT_CALL(log, Log(ERROR, _, "Bad!!"));