From b7af8aa6e4b1a07335afc36734df5852ff313759 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Sat, 20 Sep 2014 23:50:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=D1=87=D0=B8=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5,?= =?UTF-8?q?=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D1=83=20=D0=B8=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20boost?= =?UTF-8?q?=20=D0=BA=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/CMakeLists.txt | 36 ++++++++++++++++++++------ test/main.cpp | 61 +++++++++++++++++++-------------------------- 2 files changed, 54 insertions(+), 43 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3d82135..803f18a 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,13 +3,13 @@ cmake_minimum_required(VERSION 2.8) set(TEST_PROJECT_NAME "cpputil_test") set(SRC_DIR ".") set(REQUIRED_LIBRARIES cpputil) +set(boost_version 1.56.0) +set(boost_version_underscored 1_56_0) -# https://googletest.googlecode.com/files/gtest-1.7.0.zip +INCLUDE(ExternalProject) +SET_DIRECTORY_PROPERTIES(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/ThirdParty) if(APPLE) - INCLUDE(ExternalProject) - SET_DIRECTORY_PROPERTIES(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/ThirdParty) - ExternalProject_Add( googletest URL https://googletest.googlecode.com/files/gtest-1.7.0.zip @@ -27,7 +27,6 @@ if(APPLE) ExternalProject_Get_Property(googletest source_dir) ExternalProject_Get_Property(googletest binary_dir) INCLUDE_DIRECTORIES(${source_dir}/include) - #link_directories(${binary_dir}/Debug) else() FIND_PACKAGE(GTest REQUIRED) if(NOT GTEST_FOUND) @@ -38,13 +37,36 @@ else() endif() endif() +if(CMAKE_BUILD_TYPE MATCHES RELEASE) + set(boost_build_type "release") +elseif(CMAKE_BUILD_TYPE MATCHES DEBUG) + set(boost_build_type "debug") +endif() + +ExternalProject_Add( + boost + URL http://switch.dl.sourceforge.net/project/boost/boost/${boost_version}/boost_${boost_version_underscored}.zip + CONFIGURE_COMMAND ./bootstrap.sh --with-libraries=coroutine + BUILD_COMMAND ./b2 --stagedir=${CMAKE_SOURCE_DIR} link=static threading=multi cxxflags=-std=c++11 ${boost_build_type} + BUILD_IN_SOURCE 1 + INSTALL_COMMAND "" + LOG_DOWNLOAD ON + LOG_CONFIGURE ON + LOG_BUILD ON +) + +ExternalProject_Get_Property( boost source_dir ) +ExternalProject_Get_Property( boost binary_dir ) +set( Boost_INCLUDE_DIRS ${source_dir} ) +set( Boost_LIBRARIES debug;${binary_dir}/stage/lib/libboost_program_options-vc110-mt-gd-1_49.lib;optimized;${binary_dir}/stage/lib/libboost_program_options-vc110-mt-1_49.lib ) + project(${TEST_PROJECT_NAME} CXX) aux_source_directory(${SRC_DIR} TEST_SRC) add_executable(${TEST_PROJECT_NAME} ${TEST_SRC}) SET_TARGET_PROPERTIES(${TEST_PROJECT_NAME} PROPERTIES ENABLE_EXPORTS TRUE) -ADD_DEPENDENCIES(${TEST_PROJECT_NAME} googletest cpputil) +ADD_DEPENDENCIES(${TEST_PROJECT_NAME} googletest cpputil boost) -target_link_libraries(${TEST_PROJECT_NAME} ${REQUIRED_LIBRARIES} ${CMAKE_SOURCE_DIR}/lib/libgtest.a) +target_link_libraries(${TEST_PROJECT_NAME} ${REQUIRED_LIBRARIES} ${CMAKE_SOURCE_DIR}/lib/libgtest.a ${CMAKE_SOURCE_DIR}/lib/libboost_coroutine.a) install(TARGETS ${TEST_PROJECT_NAME} RUNTIME DESTINATION bin diff --git a/test/main.cpp b/test/main.cpp index e596009..0cd01fb 100755 --- a/test/main.cpp +++ b/test/main.cpp @@ -562,7 +562,10 @@ TEST(Ustring, replace_string) EXPECT_TRUE(str2 == "33 hello 33 world 33 more 33 and 33 more 33"); } -//logger flog("test.log"); +/////////////////////////////////////////////////////////////////////////////////////////////// +// +// threadpool demo +// void func(std::size_t n) { @@ -588,41 +591,27 @@ public: } }; +void run_threadpool_demo() +{ + threadpool pool(4); + std::vector> vec; + + foo f; + for (std::size_t i = 0; i < 100; ++i) + { + //std::future fut = pool.add_task([i] { return i; }); + std::future fut = pool.add_task(&foo::bar, &f, (int)i); + vec.push_back(std::move(fut)); + } + + for(std::size_t i = 0; i < 100; ++i) + { + std::cout << "res[" << i << "] = " << vec[i].get() << std::endl; + } +} + int main(int argc, char **argv) { - //::testing::InitGoogleTest(&argc, argv); - //return RUN_ALL_TESTS(); - - /* - const std::size_t threadsCount = 2; - - std::thread threads[threadsCount]; - for(std::size_t i = 0; i < threadsCount; ++i) - { - threads[i] = std::thread(func, i); - } - - std::cout << "the end" << std::endl; - - for(std::size_t i = 0; i < threadsCount; ++i) - threads[i].join(); - */ - - threadpool pool(4); - std::vector> vec; - - foo f; - for (std::size_t i = 0; i < 100; ++i) - { - //std::future fut = pool.add_task([i] { return i; }); - std::future fut = pool.add_task(&foo::bar, &f, (int)i); - vec.push_back(std::move(fut)); - } - - for(std::size_t i = 0; i < 100; ++i) - { - std::cout << "res[" << i << "] = " << vec[i].get() << std::endl; - } - - return 0; + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); }