Tidy up test sources:

Test support classes are moved to beast/extras/test.
This commit is contained in:
Vinnie Falco
2016-05-07 07:08:21 -04:00
parent 427c35f5e1
commit 00d8ed71fd
16 changed files with 173 additions and 151 deletions

View File

@ -25,20 +25,25 @@ endif()
message ("cxx Flags: " ${CMAKE_CXX_FLAGS})
macro(GroupSources curdir)
function(DoGroupSources curdir rootdir folder)
file(GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${curdir} ${PROJECT_SOURCE_DIR}/${curdir}/*)
foreach(child ${children})
if(IS_DIRECTORY ${PROJECT_SOURCE_DIR}/${curdir}/${child})
GroupSources(${curdir}/${child})
DoGroupSources(${curdir}/${child} ${rootdir} ${folder})
elseif(${child} STREQUAL "CMakeLists.txt")
source_group("" FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child})
else()
string(REPLACE "/" "\\" groupname ${curdir})
string(REPLACE "src" "Common" groupname ${groupname})
string(REGEX REPLACE ^${rootdir} ${folder} groupname ${curdir})
#set(groupname ${curdir})
string(REPLACE "/" "\\" groupname ${groupname})
source_group(${groupname} FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child})
endif()
endforeach()
endmacro()
endfunction()
function(GroupSources curdir folder)
DoGroupSources(${curdir} ${curdir} ${folder})
endfunction()
include_directories (extras)
include_directories (include)
@ -52,5 +57,7 @@ file(GLOB_RECURSE BEAST_INCLUDES
add_subdirectory (examples)
add_subdirectory (test)
add_subdirectory (test/http)
add_subdirectory (test/websocket)
#enable_testing()

View File

@ -1,8 +1,9 @@
# Part of Beast
GroupSources(include/beast)
GroupSources(examples)
GroupSources(test)
GroupSources(extras/beast beast)
GroupSources(include/beast beast)
GroupSources(examples "/")
add_executable (http-crawl
${BEAST_INCLUDES}
@ -22,7 +23,6 @@ add_executable (http-server
http_stream.hpp
http_stream.ipp
http_sync_server.hpp
../test/sig_wait.hpp
http_server.cpp
)

View File

@ -19,8 +19,8 @@
#include "http_async_server.hpp"
#include "http_sync_server.hpp"
#include "../test/sig_wait.hpp"
#include <beast/test/sig_wait.hpp>
#include <boost/program_options.hpp>
#include <iostream>
@ -72,5 +72,5 @@ int main(int ac, char const* av[])
http_sync_server server(ep, root);
else
http_async_server server(ep, threads, root);
sig_wait();
beast::test::sig_wait();
}

View File

@ -29,7 +29,7 @@
namespace beast {
namespace test {
/* A stream wrapper that fails.
/** A stream wrapper that fails.
On the Nth operation, the stream will fail with the specified
error code, or the default error code of invalid_argument.

View File

@ -0,0 +1,36 @@
//
// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// 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)
//
#ifndef BEAST_TEST_SIG_WAIT_HPP
#define BEAST_TEST_SIG_WAIT_HPP
#include <boost/asio.hpp>
#include <condition_variable>
#include <mutex>
namespace beast {
namespace test {
/// Block until SIGINT or SIGTERM is received.
inline
void
sig_wait()
{
boost::asio::io_service ios;
boost::asio::signal_set signals(
ios, SIGINT, SIGTERM);
signals.async_wait(
[&](boost::system::error_code const&, int)
{
});
ios.run();
}
} // test
} // beast
#endif

View File

@ -17,7 +17,12 @@
namespace beast {
namespace test {
// meets the requirements of AsyncStream, SyncStream
/** A SyncStream and AsyncStream that reads from a string.
This class behaves like a socket, except that written data is simply
discarded, and when data is read it comes from a string provided
at construction.
*/
class string_stream
{
std::string s_;

View File

@ -5,8 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BEAST_TEST_ENABLE_YIELD_TO_HPP
#define BEAST_TEST_ENABLE_YIELD_TO_HPP
#ifndef BEAST_TEST_YIELD_TO_HPP
#define BEAST_TEST_YIELD_TO_HPP
#include <boost/asio/io_service.hpp>
#include <boost/asio/spawn.hpp>
@ -19,7 +19,12 @@
namespace beast {
namespace test {
// Mix-in to support tests using coroutines
/** Mix-in to support tests using asio coroutines.
Derive from this class and use yield_to to launch test functions
inside coroutines. This is handy for testing asynchronous asio
code.
*/
class enable_yield_to
{
protected:
@ -33,6 +38,7 @@ private:
bool running_ = false;;
protected:
/// The type of yield context passed to functions.
using yield_context =
boost::asio::yield_context;
@ -52,7 +58,16 @@ protected:
thread_.join();
}
// Run a function in a coroutine
/** Run a function in a coroutine.
This call will block until the coroutine terminates.
Function will be called with this signature:
@code
void f(yield_context);
@endcode
*/
template<class Function>
void
yield_to(Function&& f);

View File

@ -1,12 +1,12 @@
# Part of Beast
GroupSources(include/beast)
GroupSources(extras)
GroupSources(test)
GroupSources(extras/beast beast)
GroupSources(include/beast beast)
GroupSources(test "/")
add_executable (core-tests
${BEAST_INCLUDES}
main.cpp
../extras/beast/unit_test/main.cpp
async_completion.cpp
basic_streambuf.cpp
bind_handler.cpp
@ -37,77 +37,3 @@ add_executable (core-tests
if (NOT WIN32)
target_link_libraries(core-tests ${Boost_LIBRARIES})
endif()
add_executable (http-tests
${BEAST_INCLUDES}
fail_stream.hpp
string_stream.hpp
yield_to.hpp
main.cpp
http/basic_headers.cpp
http/basic_parser_v1.cpp
http/body_type.cpp
http/empty_body.cpp
http/headers.cpp
http/message.cpp
http/message_v1.cpp
http/parse_error.cpp
http/parser_v1.cpp
http/read.cpp
http/reason.cpp
http/resume_context.cpp
http/rfc2616.cpp
http/rfc7230.cpp
http/status.cpp
http/streambuf_body.cpp
http/string_body.cpp
http/type_check.cpp
http/write.cpp
)
if (NOT WIN32)
target_link_libraries(http-tests ${Boost_LIBRARIES})
endif()
add_executable (bench-tests
${BEAST_INCLUDES}
main.cpp
http/nodejs_parser.cpp
http/parser_bench.cpp
)
if (NOT WIN32)
target_link_libraries(parser-bench ${Boost_LIBRARIES})
endif()
add_executable (websocket-tests
${BEAST_INCLUDES}
fail_stream.hpp
string_stream.hpp
yield_to.hpp
websocket/websocket_async_echo_peer.hpp
websocket/websocket_sync_echo_peer.hpp
main.cpp
websocket/error.cpp
websocket/option.cpp
websocket/rfc6455.cpp
websocket/stream.cpp
websocket/teardown.cpp
websocket/utf8_checker.cpp
)
if (NOT WIN32)
target_link_libraries(websocket-tests ${Boost_LIBRARIES})
endif()
add_executable (websocket-echo
${BEAST_INCLUDES}
sig_wait.hpp
websocket/websocket_async_echo_peer.hpp
websocket/websocket_sync_echo_peer.hpp
websocket/websocket_echo.cpp
)
if (NOT WIN32)
target_link_libraries(websocket-echo ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endif()

View File

@ -8,7 +8,7 @@
import os ;
unit-test core-tests :
main.cpp
../extras/beast/unit_test/main.cpp
async_completion.cpp
basic_streambuf.cpp
bind_handler.cpp
@ -37,7 +37,7 @@ unit-test core-tests :
;
unit-test http-tests :
main.cpp
../extras/beast/unit_test/main.cpp
http/basic_headers.cpp
http/basic_parser_v1.cpp
http/body_type.cpp
@ -60,13 +60,13 @@ unit-test http-tests :
;
unit-test bench-tests :
main.cpp
../extras/beast/unit_test/main.cpp
http/nodejs_parser.cpp
http/parser_bench.cpp
;
unit-test websocket-tests :
main.cpp
../extras/beast/unit_test/main.cpp
websocket/error.cpp
websocket/option.cpp
websocket/rfc6455.cpp

44
test/http/CMakeLists.txt Normal file
View File

@ -0,0 +1,44 @@
# Part of Beast
GroupSources(extras/beast beast)
GroupSources(include/beast beast)
GroupSources(test/http "/")
add_executable (http-tests
${BEAST_INCLUDES}
../../extras/beast/unit_test/main.cpp
basic_headers.cpp
basic_parser_v1.cpp
body_type.cpp
empty_body.cpp
headers.cpp
message.cpp
message_v1.cpp
parse_error.cpp
parser_v1.cpp
read.cpp
reason.cpp
resume_context.cpp
rfc2616.cpp
rfc7230.cpp
status.cpp
streambuf_body.cpp
string_body.cpp
type_check.cpp
write.cpp
)
if (NOT WIN32)
target_link_libraries(http-tests ${Boost_LIBRARIES})
endif()
add_executable (bench-tests
${BEAST_INCLUDES}
../../extras/beast/unit_test/main.cpp
nodejs_parser.cpp
parser_bench.cpp
)
if (NOT WIN32)
target_link_libraries(parser-bench ${Boost_LIBRARIES})
endif()

View File

@ -8,11 +8,10 @@
// Test that header file is self-contained.
#include <beast/http/read.hpp>
#include "../fail_stream.hpp"
#include "../string_stream.hpp"
#include "../yield_to.hpp"
#include <beast/http/streambuf_body.hpp>
#include <beast/test/fail_stream.hpp>
#include <beast/test/string_stream.hpp>
#include <beast/test/yield_to.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio/spawn.hpp>

View File

@ -1,42 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_TEST_SIG_WAIT_HPP
#define BEAST_TEST_SIG_WAIT_HPP
#include <boost/asio.hpp>
#include <condition_variable>
#include <mutex>
// Block until SIGINT or SIGTERM
inline
void
sig_wait()
{
boost::asio::io_service ios;
boost::asio::signal_set signals(
ios, SIGINT, SIGTERM);
signals.async_wait(
[&](boost::system::error_code const&, int)
{
});
ios.run();
}
#endif

View File

@ -0,0 +1,33 @@
# Part of Beast
GroupSources(extras/beast beast)
GroupSources(include/beast beast)
GroupSources(test/websocket "/")
add_executable (websocket-tests
${BEAST_INCLUDES}
../../extras/beast/unit_test/main.cpp
websocket_async_echo_peer.hpp
websocket_sync_echo_peer.hpp
error.cpp
option.cpp
rfc6455.cpp
stream.cpp
teardown.cpp
utf8_checker.cpp
)
if (NOT WIN32)
target_link_libraries(websocket-tests ${Boost_LIBRARIES})
endif()
add_executable (websocket-echo
${BEAST_INCLUDES}
websocket_async_echo_peer.hpp
websocket_sync_echo_peer.hpp
websocket_echo.cpp
)
if (NOT WIN32)
target_link_libraries(websocket-echo ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endif()

View File

@ -8,15 +8,14 @@
// Test that header file is self-contained.
#include <beast/websocket/stream.hpp>
#include "../fail_stream.hpp"
#include "../string_stream.hpp"
#include "../yield_to.hpp"
#include "websocket_async_echo_peer.hpp"
#include "websocket_sync_echo_peer.hpp"
#include <beast/streambuf.hpp>
#include <beast/to_string.hpp>
#include <beast/test/fail_stream.hpp>
#include <beast/test/string_stream.hpp>
#include <beast/test/yield_to.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>

View File

@ -19,7 +19,7 @@
#include "websocket_async_echo_peer.hpp"
#include "websocket_sync_echo_peer.hpp"
#include "../sig_wait.hpp"
#include <beast/test/sig_wait.hpp>
int main()
{
@ -32,5 +32,5 @@ int main()
beast::websocket::sync_echo_peer s2(true, endpoint_type{
address_type::from_string("127.0.0.1"), 6001 });
sig_wait();
beast::test::sig_wait();
}