Skip to content

Commit 78de299

Browse files
committed
Migrating concurrency tests to gtest
1 parent a7892e1 commit 78de299

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

concurrency/test/CMakeLists.txt

+4-9
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,17 @@
33
# (See accompanying file LICENSE_1_0.txt or copy at
44
# http://www.boost.org/LICENSE_1_0.txt)
55

6-
include_directories(${CPP-NETLIB_SOURCE_DIR}/concurrency/src)
7-
8-
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
9-
set(CPP-NETLIB_CXXFLAGS "-Wall -std=c++11")
10-
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
11-
CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD11)
12-
set(CPP-NETLIB_CXXFLAGS "-Wall -std=c++11 -stdlib=libc++")
13-
set(CPP-NETLIB_CXXFLAGS "-Wall -std=c++11 -stdlib=libc++")
14-
endif()
6+
include_directories(${CPP-NETLIB_SOURCE_DIR}/concurrency/src
7+
${GTEST_INCLUDE_DIRS}
8+
)
159

1610
set_source_files_properties(thread_pool_test.cpp
1711
PROPERTIES COMPILE_FLAGS "-Wall")
1812
add_executable(cpp-netlib-thread_pool_test thread_pool_test.cpp)
1913
target_link_libraries(cpp-netlib-thread_pool_test
2014
cppnetlib-concurrency
2115
${Boost_LIBRARIES}
16+
${GTEST_BOTH_LIBRARIES}
2217
${CMAKE_THREAD_LIBS_INIT})
2318
set_target_properties(cpp-netlib-thread_pool_test
2419
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)

concurrency/test/thread_pool_test.cpp

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11

2-
// Copyright 2010 Dean Michael Berris.
2+
// Copyright 2010, 2012 Dean Michael Berris <[email protected]>
33
// Copyright 2012 Google, Inc.
44
// Copyright (c) Glyn Matthews 2012.
55
// Distributed under the Boost Software License, Version 1.0.
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9-
#ifdef BUILD_SHARED_LIBS
10-
# define BOOST_TEST_DYN_LINK
11-
#endif
12-
#define BOOST_TEST_MODULE thread pool test
13-
#include <boost/config/warning_disable.hpp>
14-
#include <boost/test/unit_test.hpp>
9+
#include <gtest/gtest.h>
1510
#include <network/concurrency/thread_pool.hpp>
1611
#include <boost/bind.hpp>
1712

@@ -25,9 +20,9 @@ using network::concurrency::thread_pool;
2520
// syntactically.
2621
//
2722

28-
BOOST_AUTO_TEST_CASE( default_constructor ) {
23+
TEST(concurrency_test, default_constructor) {
2924
thread_pool pool;
30-
BOOST_CHECK_EQUAL(pool.thread_count(), std::size_t(1));
25+
ASSERT_EQ(pool.thread_count(), std::size_t(1));
3126
}
3227

3328
struct foo {
@@ -42,13 +37,13 @@ struct foo {
4237
int val_;
4338
};
4439

45-
BOOST_AUTO_TEST_CASE( post_work ) {
40+
TEST(concurrency_test, post_work) {
4641
foo instance;
4742
{
4843
thread_pool pool;
49-
BOOST_CHECK_NO_THROW(pool.post(boost::bind(&foo::bar, &instance, 1)));
50-
BOOST_CHECK_NO_THROW(pool.post(boost::bind(&foo::bar, &instance, 2)));
44+
ASSERT_NO_THROW(pool.post(boost::bind(&foo::bar, &instance, 1)));
45+
ASSERT_NO_THROW(pool.post(boost::bind(&foo::bar, &instance, 2)));
5146
// require that pool is destroyed here, RAII baby
5247
}
53-
BOOST_CHECK_EQUAL(instance.val(), 3);
48+
ASSERT_EQ(instance.val(), 3);
5449
}

0 commit comments

Comments
 (0)