Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Convert all tests to use googletest#580

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
glynos merged 2 commits intocpp-netlib:masterfromdeanberris:convert-to-gtest
Jan 8, 2016
Merged
Show file tree
Hide file tree
Changes from1 commit
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
NextNext commit
Convert all tests to use googletest
This change systematically removes the dependency to Boost.Testthroughout the tests in libs/network/test/*. Most of the changes aremechanical, and functionally equivalent.We can actually start simplifying the test structure after this changegets pulled into the main repository.
  • Loading branch information
@deanberris
deanberris committedJan 7, 2016
commita9df2cdf6a30a022de92ff38e1d227f67227fc4c
8 changes: 4 additions & 4 deletionsCMakeLists.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

cmake_minimum_required(VERSION2.8)
cmake_minimum_required(VERSION3.0)
project(CPP-NETLIB)

option( CPP-NETLIB_BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries." OFF )
Expand DownExpand Up@@ -45,9 +45,9 @@ add_definitions(-DBOOST_TEST_DYN_LINK)
# Always use multi-threaded Boost libraries.
set(Boost_USE_MULTI_THREADED ON)

find_package(Boost 1.57.0
REQUIREDunit_test_frameworksystem regex date_time thread filesystem
program_options chronoatomic)
find_package(Boost 1.57.0
REQUIRED system regex date_time thread filesystem program_options chrono
atomic)

if (CPP-NETLIB_ENABLE_HTTPS)
find_package( OpenSSL )
Expand Down
9 changes: 2 additions & 7 deletionslibs/network/test/CMakeLists.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,11 +10,7 @@ add_subdirectory(uri)
add_subdirectory(http)

if (Boost_FOUND)
set(
TESTS
message_test
message_transform_test
utils_thread_pool
set(TESTS message_test message_transform_test utils_thread_pool
# utils_base64_test -- turn on when ready.
)
foreach (test ${TESTS})
Expand All@@ -23,7 +19,7 @@ if (Boost_FOUND)
PROPERTIES COMPILE_FLAGS "-Wall")
endif()
add_executable(cpp-netlib-${test} ${test}.cpp)
add_dependencies(cpp-netlib-${test} cppnetlib-uri)
add_dependencies(cpp-netlib-${test} cppnetlib-uri gtest_main)
target_link_libraries(cpp-netlib-${test}
${Boost_THREAD_LIBRARY} ${Boost_SYSTEM_LIBRARY}
${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri gtest_main)
Expand All@@ -44,6 +40,5 @@ if (Boost_FOUND)

# Also copy the server directory to the root of the build directory.
file(COPY server DESTINATION ${CPP-NETLIB_BINARY_DIR}/libs/network/test/)

endif()

91 changes: 51 additions & 40 deletionslibs/network/test/http/CMakeLists.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,82 +12,93 @@ if (OPENSSL_FOUND)
endif()

if (Boost_FOUND)
set ( TESTS
response_incremental_parser_test
request_incremental_parser_test
request_linearize_test
)
set(TESTS response_incremental_parser_test request_incremental_parser_test
request_linearize_test)
foreach ( test ${TESTS} )
add_executable(cpp-netlib-http-${test} ${test}.cpp)
add_dependencies(cpp-netlib-http-${test}
add_dependencies(cpp-netlib-http-${test} gtest_main
cppnetlib-uri)
target_link_libraries(cpp-netlib-http-${test}
${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} gtest_main
cppnetlib-uri)
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_link_libraries(cpp-netlib-http-${test} ws2_32)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(cpp-netlib-http-${test} rt)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(cpp-netlib-http-${test} rt)
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)
set ( TESTS
client_constructor_test
client_get_test
client_get_different_port_test
client_get_timeout_test
client_get_streaming_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} )
add_executable(cpp-netlib-http-${test} ${test}.cpp)
add_dependencies(cpp-netlib-http-${test}
cppnetlib-uri
cppnetlib-client-connections)
target_link_libraries(cpp-netlib-http-${test}
${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
cppnetlib-uri
cppnetlib-client-connections)
add_dependencies(cpp-netlib-http-${test} cppnetlib-uri
cppnetlib-client-connections gtest_main)
target_link_libraries(cpp-netlib-http-${test} ${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri gtest_main cppnetlib-client-connections)
if (OPENSSL_FOUND)
target_link_libraries(cpp-netlib-http-${test} ${OPENSSL_LIBRARIES})
endif()
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_link_libraries(cpp-netlib-http-${test} ws2_32)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(cpp-netlib-http-${test} rt)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(cpp-netlib-http-${test} rt)
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)

set ( SERVER_API_TESTS
server_constructor_test
server_async_run_stop_concurrency
server_header_parser_test
)
foreach ( test ${SERVER_API_TESTS} )
set(SERVER_API_TESTS server_constructor_test
server_header_parser_test)
foreach (test ${SERVER_API_TESTS})
add_executable(cpp-netlib-http-${test} ${test}.cpp)
add_dependencies(cpp-netlib-http-${test} cppnetlib-server-parsers)
target_link_libraries(cpp-netlib-http-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-server-parsers)
target_link_libraries(cpp-netlib-http-${test} ${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} cppnetlib-server-parsers gtest_main)
if (OPENSSL_FOUND)
target_link_libraries(cpp-netlib-http-${test} ${OPENSSL_LIBRARIES})
endif()
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_link_libraries(cpp-netlib-http-${test} ws2_32 wsock32)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(cpp-netlib-http-${test} rt)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(cpp-netlib-http-${test} rt)
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)

# Add the server start/stop concurrency test
add_executable(cpp-netlib-http-server_async_run_stop_concurrency
server_async_run_stop_concurrency.cpp)
add_dependencies(cpp-netlib-http-server_async_run_stop_concurrency
cppnetlib-server-parsers)
target_link_libraries(cpp-netlib-http-server_async_run_stop_concurrency
${Boost_LIBRARIES} cppnetlib-server-parsers)
if (OPENSSL_FOUND)
target_link_libraries(cpp-netlib-http-server_async_run_stop_concurrency
${OPENSSL_LIBRARIES})
endif()
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU
AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_link_libraries(cpp-netlib-http-server_async_run_stop_concurrency
ws2_32 wsock32)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(cpp-netlib-http-server_async_run_stop_concurrency rt)
endif()
set_target_properties(cpp-netlib-http-server_async_run_stop_concurrency
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
add_test(cpp-netlib-http-server_async_run_stop_concurrency
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-server_async_run_stop_concurrency)
endif()
30 changes: 16 additions & 14 deletionslibs/network/test/http/client_constructor_test.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@

// Copyright 2010 Dean Michael Berris.
// Copyright 2015 Google, Inc.
// 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)

#define BOOST_TEST_MODULE HTTP 1.0 Client Constructor Test
// Migrated from using Boost.Test to using googletest intead.
#include <gtest/gtest.h>

#include <boost/network/include/http/client.hpp>
#include <boost/test/unit_test.hpp>
#include "client_types.hpp"

namespace http = boost::network::http;

BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_constructor_test, client,
client_types) {
typename client::options options;
client instance;
client instance2(
TYPED_TEST_CASE(HTTPClientTest, ClientTypes);

TYPED_TEST(HTTPClientTest, Constructors) {
typename TypeParam::options options;
TypeParam instance;
TypeParam instance2(
options.io_service(boost::make_shared<boost::asio::io_service>()));
}

BOOST_AUTO_TEST_CASE_TEMPLATE(http_cient_constructor_params_test, client,
client_types) {
typename client::options options;
client instance(options.follow_redirects(true).cache_resolved(true));
client instance2(
TYPED_TEST(HTTPClientTest, ConstructorsWithOptions) {
typename TypeParam::options options;
TypeParam instance(options.follow_redirects(true).cache_resolved(true));
TypeParam instance2(
options.openssl_certificate("foo").openssl_verify_path("bar"));
client instance3(
TypeParam instance3(
options.openssl_certificate_file("foo").openssl_private_key_file("bar"));
client instance4(
TypeParam instance4(
options.follow_redirects(true)
.io_service(boost::make_shared<boost::asio::io_service>())
.cache_resolved(true));
Expand Down
19 changes: 10 additions & 9 deletionslibs/network/test/http/client_get_different_port_test.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@

// Copyright 2010 Dean Michael Berris.
// Copyright 2016 Google, Inc.
// 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)

#define BOOST_TEST_MODULE HTTP Client Get Different Port Test
#include <gtest/gtest.h>
#include <boost/network/include/http/client.hpp>
#include <boost/test/unit_test.hpp>
#include "client_types.hpp"

namespace net = boost::network;
namespace http = boost::network::http;

BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_different_port, client,
client_types) {
typename client::request request("http://www.boost.org:80/");
client client_;
typename client::response response_ = client_.get(request);
TYPED_TEST_CASE(HTTPClientTest, ClientTypes);

TYPED_TEST(HTTPClientTest, GetDifferentPort) {
TypeParam client;
typename TypeParam::request r("http://www.boost.org:80/");
auto response_ = client.get(r);
auto range = headers(response_)["Content-Type"];
BOOST_CHECK(boost::begin(range) != boost::end(range));
BOOST_CHECK(body(response_).size() != 0);
EXPECT_TRUE(boost::begin(range) != boost::end(range));
EXPECT_NE(0,body(response_).size());
}
35 changes: 18 additions & 17 deletionslibs/network/test/http/client_get_streaming_test.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,46 @@
// Copyright 2011 Dean Michael Berris &lt;mikhailberis@gmail.com&gt;.
// Copyright 2016 Google, Inc.
// 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)

#define BOOST_TEST_MODULE HTTP 1.1 Get Streaming Test
#include <gtest/gtest.h>
#include <boost/network/include/http/client.hpp>
#include <boost/test/unit_test.hpp>
#include <iostream>
#include "client_types.hpp"

namespace net = boost::network;
namespace http = boost::network::http;

struct body_handler {

explicit body_handler(std::string& body) : body(body) {}

BOOST_NETWORK_HTTP_BODY_CALLBACK(operator(), range, error) {
(void)error;
body.append(boost::begin(range), boost::end(range));
}

std::string& body;
};

BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_get_streaming_test, client,
async_only_client_types) {
typename client::request request("http://www.boost.org");
typename client::response response;
typename client::string_type body_string;
typename client::string_type dummy_body;
TYPED_TEST_CASE(HTTPClientTest, ClientTypes);

TYPED_TEST(HTTPClientTest, GetStreamingTest) {
typename TypeParam::request request("http://www.boost.org");
typename TypeParam::response response;
typename TypeParam::string_type body_string;
typename TypeParam::string_type dummy_body;
body_handler handler_instance(body_string);
{
client client_;
BOOST_CHECK_NO_THROW(response = client_.get(request, handler_instance));
TypeParam client_;
ASSERT_NO_THROW(response = client_.get(request, handler_instance));
auto range = headers(response)["Content-Type"];
BOOST_CHECK(!boost::empty(range));
BOOST_CHECK_EQUAL(body(response).size(), 0u);
BOOST_CHECK_EQUAL(response.version().substr(0, 7), std::string("HTTP/1."));
BOOST_CHECK_EQUAL(response.status(), 200u);
BOOST_CHECK_EQUAL(response.status_message(), std::string("OK"));
ASSERT_TRUE(!boost::empty(range));
EXPECT_EQ(0u,body(response).size());
EXPECT_EQ("HTTP/1.",response.version().substr(0, 7));
EXPECT_EQ(200u,response.status());
EXPECT_EQ("OK",response.status_message());
dummy_body = body(response);
}
BOOST_CHECK(dummy_body ==typenameclient::string_type());
EXPECT_EQ(dummy_body,typenameTypeParam::string_type());
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp