Skip to content

Commit

Permalink
replaced gmock default main with custom main and configured stdout lo…
Browse files Browse the repository at this point in the history
…g sink
  • Loading branch information
neri14 committed Aug 10, 2024
1 parent d1ea5e2 commit f9ffe5b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ add_subdirectory(test)
target_include_directories(vgraph_test PRIVATE test)

# link libraries to test executable
target_link_libraries(vgraph_test PRIVATE GTest::gmock_main vgraph_lib garmin)
target_link_libraries(vgraph_test PRIVATE GTest::gmock vgraph_lib garmin)

# setup gtest
include(GoogleTest)
Expand Down
5 changes: 5 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
cmake_minimum_required(VERSION 3.20.0)

target_sources(vgraph_test
PRIVATE
main.cpp
)

add_subdirectory(telemetry)
add_subdirectory(testdata)
add_subdirectory(testutils)
Expand Down
14 changes: 14 additions & 0 deletions test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <gtest/gtest.h>

#include "utils/logging/backend.h"
#include "utils/logging/stream_sink.h"

int main(int argc, char **argv)
{
vgraph::utils::logging::backend::get_instance().add_sink(
vgraph::utils::logging::ELogLevel::Debug,
std::make_shared<vgraph::utils::logging::stream_sink>(std::cout));

testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
8 changes: 4 additions & 4 deletions test/utils/logging/logger_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class logger_test : public ::testing::Test {
std::ostringstream sink_stream;
};

TEST_F(logger_test, debug_sink_prints_all_levels)
TEST_F(logger_test, debug_sink_receives_all_logs)
{
backend::get_instance().add_sink(ELogLevel::Debug, sink);
logger uut(consts::logger_name);
Expand All @@ -68,7 +68,7 @@ TEST_F(logger_test, debug_sink_prints_all_levels)
ASSERT_EQ(consts::expected_error, sink_stream.str());
}

TEST_F(logger_test, info_sink_prints_info_warning_error_only)
TEST_F(logger_test, info_sink_receives_info_warning_error_logs_only)
{
backend::get_instance().add_sink(ELogLevel::Info, sink);
logger uut(consts::logger_name);
Expand All @@ -92,7 +92,7 @@ TEST_F(logger_test, info_sink_prints_info_warning_error_only)
ASSERT_EQ(consts::expected_error, sink_stream.str());
}

TEST_F(logger_test, warning_sink_prints_warning_error_only)
TEST_F(logger_test, warning_sink_receives_warning_error_logs_only)
{
backend::get_instance().add_sink(ELogLevel::Warning, sink);
logger uut(consts::logger_name);
Expand All @@ -116,7 +116,7 @@ TEST_F(logger_test, warning_sink_prints_warning_error_only)
ASSERT_EQ(consts::expected_error, sink_stream.str());
}

TEST_F(logger_test, error_sink_prints_error_only)
TEST_F(logger_test, error_sink_receives_error_logs_only)
{
backend::get_instance().add_sink(ELogLevel::Error, sink);
logger uut(consts::logger_name);
Expand Down

0 comments on commit f9ffe5b

Please sign in to comment.