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 1 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
Prev Previous commit
Migrating concurrency tests to gtest
  • Loading branch information
deanberris committed Jan 26, 2013
commit 78de299c8035669bf2335220c99d52e84335f42f
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);
}