Skip to content

Migrate all tests to gtest #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 28, 2013
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 4 additions & 3 deletions logging/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

include_directories(${GTEST_INCLUDE_DIRS})
include_directories(${CPP-NETLIB_SOURCE_DIR}/uri/src)
include_directories(${CPP-NETLIB_SOURCE_DIR}/message/src)
include_directories(${CPP-NETLIB_SOURCE_DIR}/logging/src)

if (Boost_FOUND)
if (CPP-NETLIB_BUILD_TESTS)
set(
TESTS
logging_log_record
Expand All @@ -22,10 +23,10 @@ if (Boost_FOUND)
add_executable(cpp-netlib-${test} ${test}.cpp)
add_dependencies(cpp-netlib-${test} cppnetlib-logging)
target_link_libraries(cpp-netlib-${test}
${Boost_LIBRARIES} cppnetlib-logging)
${Boost_LIBRARIES} ${GTEST_BOTH_LIBRARIES} cppnetlib-logging)
set_target_properties(cpp-netlib-${test}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
add_test(cpp-netlib-${test}
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-${test})
endforeach (test)
endif()
endif (CPP-NETLIB_BUILD_TESTS)
10 changes: 4 additions & 6 deletions logging/test/logging_custom_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
#include <string>
#include <sstream>

#define BOOST_TEST_MODULE logging log_record
#include <boost/config/warning_disable.hpp>
#include <boost/test/unit_test.hpp>
#include <gtest/gtest.h>

#include <network/logging/logging.hpp>

using namespace network::logging;

BOOST_AUTO_TEST_CASE(custom_log_handler_output) {
TEST(logging_custom_handler, custom_log_handler_output) {

std::stringstream log_output;
auto custom_log_handler = [&]( const log_record& log )
Expand All @@ -32,6 +30,6 @@ BOOST_AUTO_TEST_CASE(custom_log_handler_output) {

const auto result_output = log_output.str();

BOOST_CHECK( !result_output.empty() );
BOOST_CHECK( result_output == "[CPPNETLIB]<somewhere.cpp:42> " + message );
ASSERT_TRUE( !result_output.empty() );
ASSERT_TRUE( result_output == "[CPPNETLIB]<somewhere.cpp:42> " + message );
}
56 changes: 27 additions & 29 deletions logging/test/logging_log_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,72 @@

#include <string>

#define BOOST_TEST_MODULE logging log_record
#include <boost/config/warning_disable.hpp>
#include <boost/test/unit_test.hpp>
#include <gtest/gtest.h>

#include <network/logging/logging.hpp>
#define NETWORK_ENABLE_LOGGING
#include <network/detail/debug.hpp>

using namespace network::logging;

BOOST_AUTO_TEST_CASE(default_constructor) {
TEST(logging_log_record, default_constructor) {
log_record record;
BOOST_CHECK( record.message() == "" );
BOOST_CHECK( record.filename() == log_record::UNKNOWN_FILE_NAME );
BOOST_CHECK( record.line() == 0 );
ASSERT_TRUE( record.message() == "" );
ASSERT_TRUE( record.filename() == log_record::UNKNOWN_FILE_NAME );
ASSERT_TRUE( record.line() == 0 );
}

BOOST_AUTO_TEST_CASE(cstring_constructor) {
TEST(logging_log_record, cstring_constructor) {
const auto message = "This is a test.";
log_record record( message );
BOOST_CHECK( record.message() == message );
BOOST_CHECK( record.filename() == log_record::UNKNOWN_FILE_NAME );
BOOST_CHECK( record.line() == 0 );
ASSERT_TRUE( record.message() == message );
ASSERT_TRUE( record.filename() == log_record::UNKNOWN_FILE_NAME );
ASSERT_TRUE( record.line() == 0 );
}

BOOST_AUTO_TEST_CASE(string_constructor) {
TEST(logging_log_record, string_constructor) {
const std::string message("This is a test.");
log_record record( message );
BOOST_CHECK( record.message() == message );
BOOST_CHECK( record.filename() == log_record::UNKNOWN_FILE_NAME );
BOOST_CHECK( record.line() == 0 );
ASSERT_TRUE( record.message() == message );
ASSERT_TRUE( record.filename() == log_record::UNKNOWN_FILE_NAME );
ASSERT_TRUE( record.line() == 0 );
}

BOOST_AUTO_TEST_CASE(int_constructor) {
TEST(logging_log_record, int_constructor) {
const auto num = 42;
log_record record( num );
BOOST_CHECK( record.message() == std::to_string( num ) );
BOOST_CHECK( record.filename() == log_record::UNKNOWN_FILE_NAME );
BOOST_CHECK( record.line() == 0 );
ASSERT_TRUE( record.message() == std::to_string( num ) );
ASSERT_TRUE( record.filename() == log_record::UNKNOWN_FILE_NAME );
ASSERT_TRUE( record.line() == 0 );
}

BOOST_AUTO_TEST_CASE(info_constructor) {
TEST(logging_log_record, info_constructor) {
const auto line_num = 42;
const auto file_name = "somewhere.cpp";
log_record record( file_name, line_num );
BOOST_CHECK( record.message() == "" );
BOOST_CHECK( record.filename() == file_name );
BOOST_CHECK( record.line() == line_num );
ASSERT_TRUE( record.message() == "" );
ASSERT_TRUE( record.filename() == file_name );
ASSERT_TRUE( record.line() == line_num );
}

BOOST_AUTO_TEST_CASE(text_stream) {
TEST(logging_log_record, text_stream) {
const auto line_num = 42;
const auto file_name = "somewhere.cpp";
const auto message = "At line " + std::to_string(line_num) + " we check the code.";
log_record record( file_name, line_num );

record << "At line " << line_num << " we check the code.";

BOOST_CHECK( record.message() == message );
BOOST_CHECK( record.filename() == file_name );
BOOST_CHECK( record.line() == line_num );
ASSERT_TRUE( record.message() == message );
ASSERT_TRUE( record.filename() == file_name );
ASSERT_TRUE( record.line() == line_num );
}

BOOST_AUTO_TEST_CASE(raw_log) {
TEST(logging_log_record, raw_log) {
log( "This is a raw log." );
}

BOOST_AUTO_TEST_CASE(macro_log) {
TEST(logging_log_record, macro_log) {
NETWORK_MESSAGE( "This is a log through the macro." );
NETWORK_MESSAGE( "This is a log through the macro, with a stream! Num=" << 42 << " - OK!" );
}