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 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
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ else()
set(Boost_USE_STATIC_LIBS ON)
endif()
set(Boost_USE_MULTITHREADED ON)
if(CPP-NETLIB_BUILD_TESTS)
set(Boost_COMPONENTS unit_test_framework system regex date_time filesystem program_options )
else()
set(Boost_COMPONENTS system regex date_time filesystem program_options )
endif()
set(Boost_COMPONENTS system regex date_time filesystem program_options )
find_package( Boost 1.51 REQUIRED ${Boost_COMPONENTS} )
find_package( OpenSSL )
find_package( Threads )
Expand All @@ -47,15 +43,15 @@ if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD11)
if (HAVE_STD11)
set(CMAKE_CXX_FLAGS -std=c++11)
set(CMAKE_CXX_FLAGS -std=c++11 -Wall)
else()
message(FATAL_ERROR "No advanced standard C++ support (-std=c++11 not defined).")
endif()
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD11)
if (HAVE_STD11)
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall")
set(CMAKE_CXX_LINK_FLAGS "-std=c++11 -stdlib=libc++")
else()
message(FATAL_ERROR "No C++11 support for Clang version. Please upgrade Clang to a version supporting C++11.")
Expand Down
13 changes: 4 additions & 9 deletions concurrency/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

include_directories(${CPP-NETLIB_SOURCE_DIR}/concurrency/src)

if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
set(CPP-NETLIB_CXXFLAGS "-Wall -std=c++11")
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD11)
set(CPP-NETLIB_CXXFLAGS "-Wall -std=c++11 -stdlib=libc++")
set(CPP-NETLIB_CXXFLAGS "-Wall -std=c++11 -stdlib=libc++")
endif()
include_directories(${CPP-NETLIB_SOURCE_DIR}/concurrency/src
${GTEST_INCLUDE_DIRS}
)

set_source_files_properties(thread_pool_test.cpp
PROPERTIES COMPILE_FLAGS "-Wall")
add_executable(cpp-netlib-thread_pool_test thread_pool_test.cpp)
target_link_libraries(cpp-netlib-thread_pool_test
cppnetlib-concurrency
${Boost_LIBRARIES}
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT})
set_target_properties(cpp-netlib-thread_pool_test
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
Expand Down
21 changes: 8 additions & 13 deletions concurrency/test/thread_pool_test.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@

// Copyright 2010 Dean Michael Berris.
// Copyright 2010, 2012 Dean Michael Berris <dberris@google.com>
// Copyright 2012 Google, Inc.
// Copyright (c) Glyn Matthews 2012.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifdef BUILD_SHARED_LIBS
# define BOOST_TEST_DYN_LINK
#endif
#define BOOST_TEST_MODULE thread pool test
#include <boost/config/warning_disable.hpp>
#include <boost/test/unit_test.hpp>
#include <gtest/gtest.h>
#include <network/concurrency/thread_pool.hpp>
#include <boost/bind.hpp>

Expand All @@ -25,9 +20,9 @@ using network::concurrency::thread_pool;
// syntactically.
//

BOOST_AUTO_TEST_CASE( default_constructor ) {
TEST(concurrency_test, default_constructor) {
thread_pool pool;
BOOST_CHECK_EQUAL(pool.thread_count(), std::size_t(1));
ASSERT_EQ(pool.thread_count(), std::size_t(1));
}

struct foo {
Expand All @@ -42,13 +37,13 @@ struct foo {
int val_;
};

BOOST_AUTO_TEST_CASE( post_work ) {
TEST(concurrency_test, post_work) {
foo instance;
{
thread_pool pool;
BOOST_CHECK_NO_THROW(pool.post(boost::bind(&foo::bar, &instance, 1)));
BOOST_CHECK_NO_THROW(pool.post(boost::bind(&foo::bar, &instance, 2)));
ASSERT_NO_THROW(pool.post(boost::bind(&foo::bar, &instance, 1)));
ASSERT_NO_THROW(pool.post(boost::bind(&foo::bar, &instance, 2)));
// require that pool is destroyed here, RAII baby
}
BOOST_CHECK_EQUAL(instance.val(), 3);
ASSERT_EQ(instance.val(), 3);
}
1 change: 1 addition & 0 deletions http/src/network/protocol/http/request/request_base.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define NETWORK_RPTOCOL_HTTP_REQUEST_BASE_IPP_20111102

#include <network/protocol/http/request/request_base.hpp>
#include <vector>
#include <thread>
#include <cstring>

Expand Down
129 changes: 62 additions & 67 deletions http/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ include_directories(
${CPP-NETLIB_SOURCE_DIR}/message/src
${CPP-NETLIB_SOURCE_DIR}/logging/src
${CPP-NETLIB_SOURCE_DIR}/http/src
${GTEST_INCLUDE_DIRS}
${CPP-NETLIB_SOURCE_DIR})

if (OPENSSL_FOUND)
include_directories( ${OPENSSL_INCLUDE_DIR} )
add_definitions(-DBOOST_NETWORK_ENABLE_HTTPS)
add_definitions(-DNETWORK_ENABLE_HTTPS)
endif()

if( NOT CPP-NETLIB_DISABLE_LOGGING )
Expand All @@ -23,13 +24,13 @@ endif()
# if not then it will be empty
set( CPP-NETLIB_LOGGING_LIB cppnetlib-logging )

if (Boost_FOUND)
if (CPP-NETLIB_BUILD_TESTS)
# These are the internal (simple) tests.
set ( MESSAGE_TESTS
set (MESSAGE_TESTS
request_base_test
request_test
request_linearize_test
response_test
response_incremental_parser_test
)
foreach ( test ${MESSAGE_TESTS} )
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
Expand All @@ -47,6 +48,7 @@ if (Boost_FOUND)
)
target_link_libraries(cpp-netlib-http-${test}
${Boost_LIBRARIES}
${GTEST_BOTH_LIBRARIES}
${ICU_LIBRARIES} ${ICU_I18N_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
cppnetlib-message
Expand All @@ -62,69 +64,62 @@ if (Boost_FOUND)
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test})
endforeach(test)

set ( TESTS
client_constructor_test
client_get_test
client_get_different_port_test
client_get_timeout_test
client_get_streaming_test
)
foreach ( test ${TESTS} )
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
set_source_files_properties(${test}.cpp
PROPERTIES COMPILE_FLAGS "-Wall")
endif()
add_executable(cpp-netlib-http-${test} ${test}.cpp)
target_link_libraries(cpp-netlib-http-${test}
${Boost_LIBRARIES}
${ICU_LIBRARIES} ${ICU_I18N_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
cppnetlib-constants
cppnetlib-uri
cppnetlib-message
cppnetlib-message-wrappers
cppnetlib-message-directives
${CPP-NETLIB_LOGGING_LIB}
cppnetlib-http-message
cppnetlib-http-message-wrappers
cppnetlib-http-client
cppnetlib-http-client-connections)
if (OPENSSL_FOUND)
target_link_libraries(cpp-netlib-http-${test} ${OPENSSL_LIBRARIES})
endif()
set_target_properties(cpp-netlib-http-${test}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
add_test(cpp-netlib-http-${test}
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test})
endforeach (test)
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
set_source_files_properties(client_test.cpp
PROPERTIES COMPILE_FLAGS "-Wall")
endif()
add_executable(cpp-netlib-http-client_test client_test.cpp)
target_link_libraries(cpp-netlib-http-client_test
${Boost_LIBRARIES}
${GTEST_BOTH_LIBRARIES}
${ICU_LIBRARIES} ${ICU_I18N_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
cppnetlib-constants
cppnetlib-uri
cppnetlib-message
cppnetlib-message-wrappers
cppnetlib-message-directives
${CPP-NETLIB_LOGGING_LIB}
cppnetlib-http-message
cppnetlib-http-message-wrappers
cppnetlib-http-client
cppnetlib-http-client-connections)
if (OPENSSL_FOUND)
target_link_libraries(cpp-netlib-http-client_test ${OPENSSL_LIBRARIES})
endif()
set_target_properties(cpp-netlib-http-client_test
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
add_test(cpp-netlib-http-client_test
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test})

#set ( SERVER_API_TESTS
# server_constructor_test
# server_async_run_stop_concurrency
# )
#foreach ( test ${SERVER_API_TESTS} )
# if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
# set_source_files_properties(${test}.cpp
# PROPERTIES COMPILE_FLAGS "-Wall")
# endif()
# add_executable(cpp-netlib-http-${test} ${test}.cpp)
# target_link_libraries(cpp-netlib-http-${test}
# ${Boost_LIBRARIES}
# ${ICU_LIBRARIES} ${ICU_I18N_LIBRARIES}
# ${CMAKE_THREAD_LIBS_INIT}
# cppnetlib-constants
# cppnetlib-uri
# cppnetlib-message
# cppnetlib-message-wrappers
# cppnetlib-http-message
# cppnetlib-http-server
# cppnetlib-http-server-parsers
# cppnetlib-utils-thread_pool
# )
# set_target_properties(cpp-netlib-http-${test}
# PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
# add_test(cpp-netlib-http-${test}
# ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test})
#endforeach (test)
# set ( SERVER_API_TESTS
# server_constructor_test
# server_async_run_stop_concurrency
# )
# foreach ( test ${SERVER_API_TESTS} )
# if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
# set_source_files_properties(${test}.cpp
# PROPERTIES COMPILE_FLAGS "-Wall")
# endif()
# add_executable(cpp-netlib-http-${test} ${test}.cpp)
# target_link_libraries(cpp-netlib-http-${test}
# ${Boost_LIBRARIES}
# ${GTEST_BOTH_LIBRARIES}
# ${ICU_LIBRARIES} ${ICU_I18N_LIBRARIES}
# ${CMAKE_THREAD_LIBS_INIT}
# cppnetlib-constants
# cppnetlib-uri
# cppnetlib-message
# cppnetlib-message-wrappers
# cppnetlib-http-message
# cppnetlib-http-server
# cppnetlib-http-server-parsers
# cppnetlib-utils-thread_pool
# )
# set_target_properties(cpp-netlib-http-${test}
# PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
# add_test(cpp-netlib-http-${test}
# ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test})
# endforeach (test)

endif()
32 changes: 0 additions & 32 deletions http/test/client_constructor_test.cpp

This file was deleted.

26 changes: 0 additions & 26 deletions http/test/client_get_different_port_test.cpp

This file was deleted.

56 changes: 0 additions & 56 deletions http/test/client_get_streaming_test.cpp

This file was deleted.

Loading