Skip to content

Commit 7535fca

Browse files
committed
Initial unit test/specification for a thread pool interface.
1 parent 3ba5ff9 commit 7535fca

File tree

3 files changed

+81
-9
lines changed

3 files changed

+81
-9
lines changed

boost/network/utils/thread_pool.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef BOOST_NETWORK_UTILS_THREAD_POOL_HPP_20101020
2+
#define BOOST_NETWORK_UTILS_THREAD_POOL_HPP_20101020
3+
4+
// Copyright 2010 Dean Michael Berris.
5+
// Distributed under the Boost Software License, Version 1.0.
6+
// (See accompanying file LICENSE_1_0.txt or copy at
7+
// http://www.boost.org/LICENSE_1_0.txt)
8+
9+
#include <cstddef>
10+
#include <boost/network/tags.hpp>
11+
12+
namespace boost { namespace network { namespace utils {
13+
14+
template <class Tag>
15+
struct basic_thread_pool {
16+
basic_thread_pool(std::size_t threads = 1) : threads_(threads) {}
17+
std::size_t const thread_count() const {
18+
return threads_;
19+
}
20+
protected:
21+
std::size_t threads_;
22+
};
23+
24+
typedef basic_thread_pool<tags::default_> thread_pool;
25+
26+
} /* utils */
27+
28+
} /* network */
29+
30+
} /* boost */
31+
32+
#endif /* BOOST_NETWORK_UTILS_THREAD_POOL_HPP_20101020 */

libs/network/test/CMakeLists.txt

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ set(Boost_USE_STATIC_LIBS ON)
1515
set(Boost_USE_MULTITHREADED ON)
1616

1717
if (Boost_FOUND)
18-
# set_source_files_properties(
19-
# http_incremental_parser.cpp hello_world.cpp
20-
# http_1_0_test.cpp http_1_1_test.cpp
21-
# http_localhost_tests.cpp https_localhost_tests.cpp
22-
# message_test.cpp http_message_twst.cpp
23-
# message_transform_test.cpp url_test.cpp
24-
# PROPERTIES COMPILE_FLAGS "-Wall -Werror"
25-
# )
18+
set_source_files_properties(
19+
http_incremental_parser.cpp hello_world.cpp
20+
http_1_0_test.cpp http_1_1_test.cpp
21+
http_localhost_tests.cpp https_localhost_tests.cpp
22+
message_test.cpp http_message_twst.cpp
23+
message_transform_test.cpp url_test.cpp
24+
PROPERTIES COMPILE_FLAGS "-Wall"
25+
)
2626
add_executable(cpp-netlib-http_incremental_parser http_incremental_parser.cpp)
2727
add_executable(cpp-netlib-hello_world hello_world.cpp)
2828
add_executable(cpp-netlib-http_1_0_test http_1_0_test.cpp)
@@ -33,6 +33,7 @@ if (Boost_FOUND)
3333
add_executable(cpp-netlib-http_message_test http_message_test.cpp)
3434
add_executable(cpp-netlib-message_transform_test message_transform_test.cpp)
3535
add_executable(cpp-netlib-url_test url_test.cpp)
36+
add_executable(cpp-netlib-utils_thread_pool utils_thread_pool.cpp)
3637
target_link_libraries(cpp-netlib-http_incremental_parser ${CMAKE_THREAD_LIBS_INIT} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
3738
target_link_libraries(cpp-netlib-hello_world ${Boost_SYSTEM_LIBRARY} ${Boost_REGEX_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_THREAD_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
3839
target_link_libraries(cpp-netlib-http_1_0_test ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
@@ -43,6 +44,7 @@ if (Boost_FOUND)
4344
target_link_libraries(cpp-netlib-http_localhost_tests ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
4445
target_link_libraries(cpp-netlib-https_localhost_tests ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
4546
target_link_libraries(cpp-netlib-url_test ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
47+
target_link_libraries(cpp-netlib-utils_thread_pool ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
4648
if (OPENSSL_FOUND)
4749
target_link_libraries(cpp-netlib-hello_world ${OPENSSL_LIBRARIES})
4850
target_link_libraries(cpp-netlib-http_1_0_test ${OPENSSL_LIBRARIES})
@@ -54,7 +56,19 @@ if (Boost_FOUND)
5456
target_link_libraries(cpp-netlib-https_localhost_tests ${OPENSSL_LIBRARIES} )
5557
target_link_libraries(cpp-netlib-url_test ${OPENSSL_LIBRARIES} )
5658
endif()
57-
set_target_properties(cpp-netlib-http_incremental_parser cpp-netlib-hello_world cpp-netlib-http_1_0_test cpp-netlib-http_1_1_test cpp-netlib-message_test cpp-netlib-http_message_test cpp-netlib-message_transform_test cpp-netlib-http_localhost_tests cpp-netlib-https_localhost_tests cpp-netlib-url_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../../build/tests)
59+
set_target_properties(
60+
cpp-netlib-http_incremental_parser
61+
cpp-netlib-hello_world
62+
cpp-netlib-http_1_0_test
63+
cpp-netlib-http_1_1_test
64+
cpp-netlib-message_test
65+
cpp-netlib-http_message_test
66+
cpp-netlib-message_transform_test
67+
cpp-netlib-http_localhost_tests
68+
cpp-netlib-https_localhost_tests
69+
cpp-netlib-url_test
70+
cpp-netlib-utils_thread_pool
71+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../../build/tests)
5872
add_test(cpp-netlib-http_incremental_parser ../../../build/tests/cpp-netlib-http_incremental_parser)
5973
add_test(cpp-netlib-hello_world python httplib_acceptance.py ../../../build/tests/cpp-netlib-hello_world ../../../build/tests/cpp-netlib-hello_world.passed)
6074
add_test(cpp-netlib-http_1_0_test ../../../build/tests/cpp-netlib-http_1_0_test)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
// Copyright 2010 Dean Michael Berris.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#define BOOST_TEST_MODULE utils thread pool test
8+
#include <boost/config/warning_disable.hpp>
9+
#include <boost/test/unit_test.hpp>
10+
#include <boost/network/utils/thread_pool.hpp>
11+
12+
using namespace boost::network;
13+
14+
// This test specifies the requirements for a thread pool interface. At the
15+
// very least any thread pool implementation should be able to pass the simple
16+
// tests that this unit test requires of thread pools. Ultimately the
17+
// requirements will show up in the Concept documentation, but this test is the
18+
// canonical definition of what a thread pool should look like at least
19+
// syntactically.
20+
//
21+
22+
BOOST_AUTO_TEST_CASE( default_constructor ) {
23+
utils::thread_pool pool;
24+
BOOST_CHECK_EQUAL(pool.thread_count(), 1);
25+
}
26+

0 commit comments

Comments
 (0)