diff options
Diffstat (limited to 'libs/thread/test/sync/futures')
34 files changed, 2857 insertions, 0 deletions
diff --git a/libs/thread/test/sync/futures/async/async_pass.cpp b/libs/thread/test/sync/futures/async/async_pass.cpp new file mode 100644 index 0000000000..a41aea56b6 --- /dev/null +++ b/libs/thread/test/sync/futures/async/async_pass.cpp @@ -0,0 +1,186 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// template <class F, class... Args> +// future<typename result_of<F(Args...)>::type> +// async(F&& f, Args&&... args); + +// template <class F, class... Args> +// future<typename result_of<F(Args...)>::type> +// async(launch policy, F&& f, Args&&... args); + + +#include <boost/thread/future.hpp> +#include <boost/thread/thread.hpp> +#include <boost/interprocess/smart_ptr/unique_ptr.hpp> +#include <memory> +#include <boost/detail/lightweight_test.hpp> + +typedef boost::chrono::high_resolution_clock Clock; +typedef boost::chrono::milliseconds ms; + +int f0() +{ + boost::this_thread::sleep_for(ms(200)); + return 3; +} + +int i = 0; + +int& f1() +{ + boost::this_thread::sleep_for(ms(200)); + return i; +} + +void f2() +{ + boost::this_thread::sleep_for(ms(200)); +} + +boost::interprocess::unique_ptr<int> f3(int i) +{ + boost::this_thread::sleep_for(ms(200)); + return boost::interprocess::unique_ptr<int>(new int(i)); +} + +boost::interprocess::unique_ptr<int> f4(boost::interprocess::unique_ptr<int>&& p) +{ + boost::this_thread::sleep_for(ms(200)); + return boost::move(p); +} + +int main() +{ + { + boost::future<int> f = boost::async(f0); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(f.get() == 3); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future<int> f = boost::async(boost::launch::async, f0); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(f.get() == 3); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future<int> f = boost::async(boost::launch::any, f0); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(f.get() == 3); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future<int> f = boost::async(boost::launch::deferred, f0); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(f.get() == 3); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 > ms(100)); + } + + { + boost::future<int&> f = boost::async(f1); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(&f.get() == &i); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future<int&> f = boost::async(boost::launch::async, f1); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(&f.get() == &i); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future<int&> f = boost::async(boost::launch::any, f1); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(&f.get() == &i); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future<int&> f = boost::async(boost::launch::deferred, f1); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(&f.get() == &i); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 > ms(100)); + } + + { + boost::future<void> f = boost::async(f2); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + f.get(); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future<void> f = boost::async(boost::launch::async, f2); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + f.get(); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future<void> f = boost::async(boost::launch::any, f2); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + f.get(); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future<void> f = boost::async(boost::launch::deferred, f2); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + f.get(); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 > ms(100)); + } + + { + boost::future<boost::interprocess::unique_ptr<int>> f = boost::async(f3, 3); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(*f.get() == 3); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + + { + boost::future<boost::interprocess::unique_ptr<int>> f = boost::async(f4, boost::interprocess::unique_ptr<int>(new int(3))); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(*f.get() == 3); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/future/copy_assign_fail.cpp b/libs/thread/test/sync/futures/future/copy_assign_fail.cpp new file mode 100755 index 0000000000..3c08aaf239 --- /dev/null +++ b/libs/thread/test/sync/futures/future/copy_assign_fail.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class future<R> + +// future& operator=(const future&) = delete; + + +#define BOOST_THREAD_VERSION 3 +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + { + typedef int T; + boost::promise<T> p; + boost::future<T> f0 = p.get_future(); + boost::future<T> f; + f = f0; + } + + return boost::report_errors(); +} + +void remove_unused_warning() +{ + //../../../boost/system/error_code.hpp:214:36: warning: Ôboost::system::posix_categoryÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:215:36: warning: Ôboost::system::errno_ecatÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:216:36: warning: Ôboost::system::native_ecatÕ defined but not used [-Wunused-variable] + + (void)boost::system::posix_category; + (void)boost::system::errno_ecat; + (void)boost::system::native_ecat; +} diff --git a/libs/thread/test/sync/futures/future/copy_ctor_fail.cpp b/libs/thread/test/sync/futures/future/copy_ctor_fail.cpp new file mode 100644 index 0000000000..b8fed11afb --- /dev/null +++ b/libs/thread/test/sync/futures/future/copy_ctor_fail.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> +// class future<R> + +// future(const future&) = delete; + + +#define BOOST_THREAD_VERSION 3 +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + { + typedef int T; + boost::promise<T> p; + boost::future<T> f0 = p.get_future(); + boost::future<T> f = f0; + } + + return boost::report_errors(); +} + +void remove_unused_warning() +{ + //../../../boost/system/error_code.hpp:214:36: warning: Ôboost::system::posix_categoryÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:215:36: warning: Ôboost::system::errno_ecatÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:216:36: warning: Ôboost::system::native_ecatÕ defined but not used [-Wunused-variable] + + (void)boost::system::posix_category; + (void)boost::system::errno_ecat; + (void)boost::system::native_ecat; +} diff --git a/libs/thread/test/sync/futures/future/default_pass.cpp b/libs/thread/test/sync/futures/future/default_pass.cpp new file mode 100755 index 0000000000..1b4cf392f6 --- /dev/null +++ b/libs/thread/test/sync/futures/future/default_pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class future<R> + +// future(); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + boost::future<int> f; + BOOST_TEST(!f.valid()); + } + { + boost::future<int&> f; + BOOST_TEST(!f.valid()); + } + { + boost::future<void> f; + BOOST_TEST(!f.valid()); + } + + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/future/dtor_pass.cpp b/libs/thread/test/sync/futures/future/dtor_pass.cpp new file mode 100755 index 0000000000..d1873f12f3 --- /dev/null +++ b/libs/thread/test/sync/futures/future/dtor_pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class promise<R> + +// ~promise(); + +#define BOOST_THREAD_VERSION 3 +#include <boost/exception/exception.hpp> + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> +#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS +#include <libs/thread/test/sync/futures/test_allocator.hpp> +#endif + +int main() +{ +#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS + BOOST_TEST(test_alloc_base::count == 0); + { + typedef int T; + boost::future<T> f; + { + boost::promise<T> p(boost::allocator_arg, test_allocator<T>()); + BOOST_TEST(test_alloc_base::count == 1); + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + } + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + } + BOOST_TEST(test_alloc_base::count == 0); + { + typedef int& T; + boost::future<T> f; + { + boost::promise<T> p(boost::allocator_arg, test_allocator<int>()); + BOOST_TEST(test_alloc_base::count == 1); + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + } + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + } + BOOST_TEST(test_alloc_base::count == 0); + { + typedef void T; + boost::future<T> f; + { + boost::promise<T> p(boost::allocator_arg, test_allocator<T>()); + BOOST_TEST(test_alloc_base::count == 1); + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + } + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + } + BOOST_TEST(test_alloc_base::count == 0); +#endif + { + typedef int T; + boost::future<T> f; + { + boost::promise<T> p; + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(f.valid()); + } + BOOST_TEST(f.valid()); + } + { + typedef int& T; + boost::future<T> f; + { + boost::promise<T> p; + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(f.valid()); + } + BOOST_TEST(f.valid()); + } + { + typedef void T; + boost::future<T> f; + { + boost::promise<T> p; + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(f.valid()); + } + BOOST_TEST(f.valid()); + } + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/future/get_pass.cpp b/libs/thread/test/sync/futures/future/get_pass.cpp new file mode 100755 index 0000000000..85b2900347 --- /dev/null +++ b/libs/thread/test/sync/futures/future/get_pass.cpp @@ -0,0 +1,171 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class promise<R> + +// future<R> get_future(); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> + +namespace boost +{ +template <typename T> +struct wrap +{ + wrap(T const& v) : value(v){} + T value; + +}; + +template <typename T> +exception_ptr make_exception_ptr(T v) { + return copy_exception(wrap<T>(v)); +} +} + +void func1(boost::promise<int> p) +{ + boost::this_thread::sleep_for(boost::chrono::milliseconds(500)); + p.set_value(3); +} + +void func2(boost::promise<int> p) +{ + boost::this_thread::sleep_for(boost::chrono::milliseconds(500)); + p.set_exception(boost::make_exception_ptr(3)); +} + +int j = 0; + +void func3(boost::promise<int&> p) +{ + boost::this_thread::sleep_for(boost::chrono::milliseconds(500)); + j = 5; + p.set_value(j); +} + +void func4(boost::promise<int&> p) +{ + boost::this_thread::sleep_for(boost::chrono::milliseconds(500)); + p.set_exception(boost::make_exception_ptr(3.5)); +} + +void func5(boost::promise<void> p) +{ + boost::this_thread::sleep_for(boost::chrono::milliseconds(500)); + p.set_value(); +} + +void func6(boost::promise<void> p) +{ + boost::this_thread::sleep_for(boost::chrono::milliseconds(500)); + p.set_exception(boost::make_exception_ptr('c')); +} + + +int main() +{ + { + typedef int T; + { + boost::promise<T> p; + boost::future<T> f = p.get_future(); + boost::thread(func1, boost::move(p)).detach(); + BOOST_TEST(f.valid()); + BOOST_TEST(f.get() == 3); + BOOST_TEST(!f.valid()); + } + { + boost::promise<T> p; + boost::future<T> f = p.get_future(); + boost::thread(func2, boost::move(p)).detach(); + try + { + BOOST_TEST(f.valid()); + BOOST_TEST(f.get() == 3); + BOOST_TEST(false); + } + catch (int i) + { + BOOST_TEST(i == 3); + } + BOOST_TEST(!f.valid()); + } + } +// { +// typedef int& T; +// { +// boost::promise<T> p; +// boost::future<T> f = p.get_future(); +// boost::thread(func3, boost::move(p)).detach(); +// BOOST_TEST(f.valid()); +// BOOST_TEST(f.get() == 5); +// BOOST_TEST(!f.valid()); +// } +// { +// boost::promise<T> p; +// boost::future<T> f = p.get_future(); +// boost::thread(func4, boost::move(p)).detach(); +// try +// { +// BOOST_TEST(f.valid()); +// BOOST_TEST(f.get() == 3); +// BOOST_TEST(false); +// } +// catch (double i) +// { +// BOOST_TEST(i == 3.5); +// } +// BOOST_TEST(!f.valid()); +// } +// } +// { +// typedef void T; +// { +// boost::promise<T> p; +// boost::future<T> f = p.get_future(); +// boost::thread(func5, boost::move(p)).detach(); +// BOOST_TEST(f.valid()); +// f.get(); +// BOOST_TEST(!f.valid()); +// } +// { +// boost::promise<T> p; +// boost::future<T> f = p.get_future(); +// boost::thread(func6, boost::move(p)).detach(); +// try +// { +// BOOST_TEST(f.valid()); +// f.get(); +// BOOST_TEST(false); +// } +// catch (char i) +// { +// BOOST_TEST(i == 'c'); +// } +// BOOST_TEST(!f.valid()); +// } +// } + + + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/future/move_assign_pass.cpp b/libs/thread/test/sync/futures/future/move_assign_pass.cpp new file mode 100755 index 0000000000..67117efaa5 --- /dev/null +++ b/libs/thread/test/sync/futures/future/move_assign_pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <future> + +// class promise<R> + +// promise& operator=(promise&& rhs); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + { + typedef int T; + boost::promise<T> p; + boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::future<T> f; + f = boost::move(f0); + BOOST_TEST(!f0.valid()); + BOOST_TEST(f.valid()); + } + { + typedef int T; + boost::future<T> f0; + boost::future<T> f; + f = boost::move(f0); + BOOST_TEST(!f0.valid()); + BOOST_TEST(!f.valid()); + } + { + typedef int& T; + boost::promise<T> p; + boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::future<T> f; + f = boost::move(f0); + BOOST_TEST(!f0.valid()); + BOOST_TEST(f.valid()); + } + { + typedef int& T; + boost::future<T> f0; + boost::future<T> f; + f = boost::move(f0); + BOOST_TEST(!f0.valid()); + BOOST_TEST(!f.valid()); + } + { + typedef void T; + boost::promise<T> p; + boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::future<T> f; + f = boost::move(f0); + BOOST_TEST(!f0.valid()); + BOOST_TEST(f.valid()); + } + { + typedef void T; + boost::future<T> f0; + boost::future<T> f; + f = boost::move(f0); + BOOST_TEST(!f0.valid()); + BOOST_TEST(!f.valid()); + } + + + return boost::report_errors(); + +} + diff --git a/libs/thread/test/sync/futures/future/move_ctor_pass.cpp b/libs/thread/test/sync/futures/future/move_ctor_pass.cpp new file mode 100755 index 0000000000..c16891189c --- /dev/null +++ b/libs/thread/test/sync/futures/future/move_ctor_pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <future> + +// class promise<R> + +// promise(promise&& rhs); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::mutex m; + +int main() +{ + { + typedef int T; + boost::promise<T> p; + boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::future<T> f = boost::move(f0); + BOOST_TEST(!f0.valid()); + BOOST_TEST(f.valid()); + } + { + typedef int T; + boost::future<T> f0; + boost::future<T> f = boost::move(f0); + BOOST_TEST(!f0.valid()); + BOOST_TEST(!f.valid()); + } + { + typedef int& T; + boost::promise<T> p; + boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::future<T> f = boost::move(f0); + BOOST_TEST(!f0.valid()); + BOOST_TEST(f.valid()); + } + { + typedef int& T; + boost::future<T> f0; + boost::future<T> f = boost::move(f0); + BOOST_TEST(!f0.valid()); + BOOST_TEST(!f.valid()); + } + { + typedef void T; + boost::promise<T> p; + boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::future<T> f = boost::move(f0); + BOOST_TEST(!f0.valid()); + BOOST_TEST(f.valid()); + } + { + typedef void T; + boost::future<T> f0; + boost::future<T> f = boost::move(f0); + BOOST_TEST(!f0.valid()); + BOOST_TEST(!f.valid()); + } + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/future/share_pass.cpp b/libs/thread/test/sync/futures/future/share_pass.cpp new file mode 100644 index 0000000000..91c07f5cd1 --- /dev/null +++ b/libs/thread/test/sync/futures/future/share_pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class future<R> + +// shared_future<R> share() &&; + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + typedef int T; + boost::promise<T> p; + boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::shared_future<T> sf = f0.share(); + boost::shared_future<T> f = sf; + BOOST_TEST(!f0.valid()); + BOOST_TEST(f.valid()); + } + { + typedef int T; + boost::future<T> f0; + boost::shared_future<T> sf = f0.share(); + boost::shared_future<T> f = sf; + BOOST_TEST(!f0.valid()); + BOOST_TEST(!f.valid()); + } + { + typedef int& T; + boost::promise<T> p; + boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::shared_future<T> sf = f0.share(); + boost::shared_future<T> f = sf; + BOOST_TEST(!f0.valid()); + BOOST_TEST(f.valid()); + } + { + typedef int& T; + boost::future<T> f0; + boost::shared_future<T> sf = f0.share(); + boost::shared_future<T> f = sf; + BOOST_TEST(!f0.valid()); + BOOST_TEST(!f.valid()); + } + { + typedef void T; + boost::promise<T> p; + boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::shared_future<T> sf = f0.share(); + boost::shared_future<T> f = sf; + BOOST_TEST(!f0.valid()); + BOOST_TEST(f.valid()); + } + { + typedef void T; + boost::future<T> f0; + boost::shared_future<T> sf = f0.share(); + boost::shared_future<T> f = sf; + BOOST_TEST(!f0.valid()); + BOOST_TEST(!f.valid()); + } + + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/packaged_task/alloc_ctor_pass.cpp b/libs/thread/test/sync/futures/packaged_task/alloc_ctor_pass.cpp new file mode 100644 index 0000000000..6b5dac1cff --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/alloc_ctor_pass.cpp @@ -0,0 +1,149 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class packaged_task<R> + +// template <class F, class Allocator> +// explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f); + + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> +#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS +#include <libs/thread/test/sync/futures/test_allocator.hpp> + +double fct() +{ + return 5.0; +} +long lfct() +{ + return 5; +} + +class A +{ + long data_; + +public: + BOOST_THREAD_COPYABLE_AND_MOVABLE(A) + static int n_moves; + static int n_copies; + + explicit A(long i) : data_(i) + { + } + A(BOOST_THREAD_RV_REF(A) a) : data_(BOOST_THREAD_RV(a).data_) + { + ++n_moves; BOOST_THREAD_RV(a).data_ = -1; + } + A(const A& a) : data_(a.data_) + { + ++n_copies; + } + ~A() + { + } + + long operator()() const + { return data_;} + long operator()(long i, long j) const + { return data_ + i + j;} +}; + +int A::n_moves = 0; +int A::n_copies = 0; + +int main() +{ + { + boost::packaged_task<double> p(boost::allocator_arg, + test_allocator<A>(), BOOST_THREAD_MAKE_RV_REF(A(5))); + BOOST_TEST(test_alloc_base::count > 0); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + } + BOOST_TEST(A::n_copies == 0); + BOOST_TEST(A::n_moves > 0); + BOOST_TEST(test_alloc_base::count == 0); + A::n_copies = 0; + A::n_copies = 0; + { + A a(5); + boost::packaged_task<double> p(boost::allocator_arg, + test_allocator<A>(), a); + BOOST_TEST(test_alloc_base::count > 0); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + } + BOOST_TEST(A::n_copies > 0); + BOOST_TEST(A::n_moves > 0); + BOOST_TEST(test_alloc_base::count == 0); + A::n_copies = 0; + A::n_copies = 0; + { + const A a(5); + boost::packaged_task<double> p(boost::allocator_arg, + test_allocator<A>(), a); + BOOST_TEST(test_alloc_base::count > 0); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + } + BOOST_TEST(A::n_copies > 0); + BOOST_TEST(A::n_moves > 0); + BOOST_TEST(test_alloc_base::count == 0); + { + boost::packaged_task<double> p(boost::allocator_arg, + test_allocator<A>(), fct); + BOOST_TEST(test_alloc_base::count > 0); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + } + { + boost::packaged_task<double> p(boost::allocator_arg, + test_allocator<A>(), &lfct); + BOOST_TEST(test_alloc_base::count > 0); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + } + + return boost::report_errors(); +} + +#else +int main() +{ + return boost::report_errors(); +} +#endif + diff --git a/libs/thread/test/sync/futures/packaged_task/copy_assign_fail.cpp b/libs/thread/test/sync/futures/packaged_task/copy_assign_fail.cpp new file mode 100755 index 0000000000..890a2d569e --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/copy_assign_fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> +// class packaged_task<R> + +// packaged_task& operator=(packaged_task&) = delete; + + +#define BOOST_THREAD_VERSION 3 +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +class A +{ + long data_; + +public: + explicit A(long i) : data_(i) {} + + long operator()() const {return data_;} + long operator()(long i, long j) const {return data_ + i + j;} +}; + + +int main() +{ + { + boost::packaged_task<double> p0(A(5)); + boost::packaged_task<double> p; + p = p0; + } + + return boost::report_errors(); +} + +void remove_unused_warning() +{ + //../../../boost/system/error_code.hpp:214:36: warning: Ôboost::system::posix_categoryÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:215:36: warning: Ôboost::system::errno_ecatÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:216:36: warning: Ôboost::system::native_ecatÕ defined but not used [-Wunused-variable] + + (void)boost::system::posix_category; + (void)boost::system::errno_ecat; + (void)boost::system::native_ecat; +} diff --git a/libs/thread/test/sync/futures/packaged_task/copy_ctor_fail.cpp b/libs/thread/test/sync/futures/packaged_task/copy_ctor_fail.cpp new file mode 100644 index 0000000000..206c1f7990 --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/copy_ctor_fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> +// class packaged_task<R> + +// packaged_task(packaged_task&) = delete; + + +#define BOOST_THREAD_VERSION 3 +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +class A +{ + long data_; + +public: + explicit A(long i) : data_(i) {} + + long operator()() const {return data_;} + long operator()(long i, long j) const {return data_ + i + j;} +}; + + +int main() +{ + { + boost::packaged_task<double> p0(A(5)); + boost::packaged_task<double> p(p0); + + } + + return boost::report_errors(); +} + +void remove_unused_warning() +{ + //../../../boost/system/error_code.hpp:214:36: warning: Ôboost::system::posix_categoryÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:215:36: warning: Ôboost::system::errno_ecatÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:216:36: warning: Ôboost::system::native_ecatÕ defined but not used [-Wunused-variable] + + (void)boost::system::posix_category; + (void)boost::system::errno_ecat; + (void)boost::system::native_ecat; +} diff --git a/libs/thread/test/sync/futures/packaged_task/default_ctor_pass.cpp b/libs/thread/test/sync/futures/packaged_task/default_ctor_pass.cpp new file mode 100644 index 0000000000..b2a371f293 --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/default_ctor_pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> +// class packaged_task<R> + +// packaged_task(); + + +#define BOOST_THREAD_VERSION 3 +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + + +int main() +{ + { + boost::packaged_task<int> p; + BOOST_TEST(!p.valid()); + + } + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/packaged_task/dtor_pass.cpp b/libs/thread/test/sync/futures/packaged_task/dtor_pass.cpp new file mode 100755 index 0000000000..15048a9150 --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/dtor_pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class packaged_task<R> + +// ~packaged_task(); +; + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/thread/thread.hpp> +#include <boost/detail/lightweight_test.hpp> + +class A +{ + long data_; + +public: + explicit A(long i) : data_(i) {} + + long operator()() const {return data_;} + long operator()(long i, long j) const {return data_ + i + j;} +}; + +void func(boost::packaged_task<double> p) +{ +} + +void func2(boost::packaged_task<double> p) +{ + //p(3, 'a'); + p(); +} + +int main() +{ + { + boost::packaged_task<double> p(A(5)); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::thread(func, boost::move(p)).detach(); + try + { + double i = f.get(); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise)); + } + } + { + boost::packaged_task<double> p(A(5)); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::thread(func2, boost::move(p)).detach(); + BOOST_TEST(f.get() == 5.0); + } + + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/packaged_task/func_ctor_pass.cpp b/libs/thread/test/sync/futures/packaged_task/func_ctor_pass.cpp new file mode 100644 index 0000000000..9010a811f3 --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/func_ctor_pass.cpp @@ -0,0 +1,127 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> +// class packaged_task<R> + +// template <class F> +// explicit packaged_task(F&& f); + + +#define BOOST_THREAD_VERSION 3 +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +double fct() +{ + return 5.0; +} +long lfct() +{ + return 5; +} + +class A +{ + long data_; + +public: + BOOST_THREAD_COPYABLE_AND_MOVABLE(A) + static int n_moves; + static int n_copies; + + explicit A(long i) : data_(i) + { + } + A(BOOST_THREAD_RV_REF(A) a) : data_(BOOST_THREAD_RV(a).data_) + { + ++n_moves; BOOST_THREAD_RV(a).data_ = -1; + } + A(const A& a) : data_(a.data_) + { + ++n_copies; + } + ~A() + { + } + + long operator()() const + { return data_;} + long operator()(long i, long j) const + { return data_ + i + j;} +}; + +int A::n_moves = 0; +int A::n_copies = 0; + + +int main() +{ + { + boost::packaged_task<double> p(BOOST_THREAD_MAKE_RV_REF(A(5))); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + BOOST_TEST(A::n_copies == 0); + BOOST_TEST(A::n_moves > 0); + } + A::n_copies = 0; + A::n_copies = 0; + { + A a(5); + boost::packaged_task<double> p(a); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + BOOST_TEST(A::n_copies > 0); + BOOST_TEST(A::n_moves > 0); + } + + A::n_copies = 0; + A::n_copies = 0; + { + const A a(5); + boost::packaged_task<double> p(a); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + BOOST_TEST(A::n_copies > 0); + BOOST_TEST(A::n_moves > 0); + } + { + boost::packaged_task<double> p(fct); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + } + { + boost::packaged_task<double> p(&lfct); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + } + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/packaged_task/get_future_pass.cpp b/libs/thread/test/sync/futures/packaged_task/get_future_pass.cpp new file mode 100755 index 0000000000..05c686341c --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/get_future_pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class packaged_task<R> + +// future<R> get_future(); + + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +class A +{ + long data_; + +public: + explicit A(long i) : data_(i) {} + + long operator()() const {return data_;} + long operator()(long i, long j) const {return data_ + i + j;} +}; + +int main() +{ + { + boost::packaged_task<double> p(A(5)); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + } + { + boost::packaged_task<double> p(A(5)); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + try + { + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::future_already_retrieved)); + } + } + { + boost::packaged_task<double> p; + try + { + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + } + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/packaged_task/member_swap_pass.cpp b/libs/thread/test/sync/futures/packaged_task/member_swap_pass.cpp new file mode 100755 index 0000000000..4cd7a139dc --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/member_swap_pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class packaged_task<R> + +// void swap(packaged_task& other); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +class A +{ + long data_; + +public: + explicit A(long i) : + data_(i) + { + } + + long operator()() const + { + return data_; + } + long operator()(long i, long j) const + { + return data_ + i + j; + } +}; + +int main() +{ + { + boost::packaged_task<double> p0(A(5)); + boost::packaged_task<double> p; + p.swap(p0); + BOOST_TEST(!p0.valid()); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + } + { + boost::packaged_task<double> p0; + boost::packaged_task<double> p; + p.swap(p0); + BOOST_TEST(!p0.valid()); + BOOST_TEST(!p.valid()); + } + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/packaged_task/move_assign_pass.cpp b/libs/thread/test/sync/futures/packaged_task/move_assign_pass.cpp new file mode 100755 index 0000000000..60c34ca38f --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/move_assign_pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <future> + +// class promise<R> + +// promise& operator=(promise&& rhs); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +class A +{ + long data_; + +public: + explicit A(long i) : data_(i) {} + + long operator()() const {return data_;} + long operator()(long i, long j) const {return data_ + i + j;} +}; + + +int main() +{ + + { + boost::packaged_task<double> p0(A(5)); + boost::packaged_task<double> p; + p = boost::move(p0); + BOOST_TEST(!p0.valid()); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + // p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + } + { + boost::packaged_task<double> p0; + boost::packaged_task<double> p; + p = boost::move(p0); + BOOST_TEST(!p0.valid()); + BOOST_TEST(!p.valid()); + } + + return boost::report_errors(); + +} + diff --git a/libs/thread/test/sync/futures/packaged_task/move_ctor_pass.cpp b/libs/thread/test/sync/futures/packaged_task/move_ctor_pass.cpp new file mode 100755 index 0000000000..4c383cf7e4 --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/move_ctor_pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class packaged_task<R> + +// packaged_task(packaged_task&& other); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +class A +{ + long data_; + +public: + explicit A(long i) : data_(i) {} + + long operator()() const {return data_;} + long operator()(long i, long j) const {return data_ + i + j;} +}; + + +int main() +{ + { + boost::packaged_task<double> p0(A(5)); + boost::packaged_task<double> p = boost::move(p0); + BOOST_TEST(!p0.valid()); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + } + { + boost::packaged_task<double> p0; + boost::packaged_task<double> p = boost::move(p0); + BOOST_TEST(!p0.valid()); + BOOST_TEST(!p.valid()); + } + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/packaged_task/non_member_swap_pass.cpp b/libs/thread/test/sync/futures/packaged_task/non_member_swap_pass.cpp new file mode 100755 index 0000000000..6f91d3c95f --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/non_member_swap_pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// template <class R> +// void +// swap(packaged_task<R>& x, packaged_task<R>& y); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +class A +{ + long data_; + +public: + explicit A(long i) : data_(i) {} + + long operator()() const {return data_;} + long operator()(long i, long j) const {return data_ + i + j;} +}; + +int main() +{ + { + boost::packaged_task<double> p0(A(5)); + boost::packaged_task<double> p; + p.swap(p0); + BOOST_TEST(!p0.valid()); + BOOST_TEST(p.valid()); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + } + { + boost::packaged_task<double> p0; + boost::packaged_task<double> p; + p.swap(p0); + BOOST_TEST(!p0.valid()); + BOOST_TEST(!p.valid()); + } + +} + diff --git a/libs/thread/test/sync/futures/packaged_task/operator_pass.cpp b/libs/thread/test/sync/futures/packaged_task/operator_pass.cpp new file mode 100644 index 0000000000..3d7fd9d043 --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/operator_pass.cpp @@ -0,0 +1,126 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> +// class packaged_task<R> + +// void operator()(); + + +#define BOOST_THREAD_VERSION 3 +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +class A +{ + long data_; + +public: + explicit A(long i) : + data_(i) + { + } + + long operator()() const + { + return data_; + } + long operator()(long i, long j) const + { + if (j == 'z') throw A(6); + return data_ + i + j; + } +}; + +void func0(boost::packaged_task<double> p) +{ + boost::this_thread::sleep_for(boost::chrono::milliseconds(500)); + //p(3, 'a'); + p(); +} + +void func1(boost::packaged_task<double(int, char)> p) +{ + boost::this_thread::sleep_for(boost::chrono::milliseconds(500)); + //p(3, 'z'); + p(); +} + +void func2(boost::packaged_task<double(int, char)> p) +{ + //p(3, 'a'); + p(); + try + { + //p(3, 'c'); + p(); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == make_error_code(boost::future_errc::promise_already_satisfied)); + } +} + +void func3(boost::packaged_task<double(int, char)> p) +{ + try + { + //p(3, 'a'); + p(); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == make_error_code(boost::future_errc::no_state)); + } +} + +int main() +{ + { + boost::packaged_task<double> p(A(5)); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::thread(func0, boost::move(p)).detach(); + BOOST_TEST(f.get() == 5.0); + } + { + boost::packaged_task<double> p(A(5)); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::thread(func1, boost::move(p)).detach(); + try + { + f.get(); + BOOST_TEST(false); + } + catch (const A& e) + { + //BOOST_TEST(e(3, 'a') == 106); + BOOST_TEST(e() == 5); + } + } + { + boost::packaged_task<double> p(A(5)); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + boost::thread t(func2, boost::move(p)); + BOOST_TEST(f.get() == 5.0); + t.join(); + } + { + boost::packaged_task<double> p; + boost::thread t(func3, boost::move(p)); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/packaged_task/reset_pass.cpp b/libs/thread/test/sync/futures/packaged_task/reset_pass.cpp new file mode 100644 index 0000000000..558c118dd5 --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/reset_pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> +// class packaged_task<R> + +// void operator()(); + + +#define BOOST_THREAD_VERSION 3 +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +class A +{ + long data_; + +public: + explicit A(long i) : + data_(i) + { + } + + long operator()() const + { + return data_; + } + long operator()(long i, long j) const + { + if (j == 'z') throw A(6); + return data_ + i + j; + } +}; + +int main() +{ + { + boost::packaged_task<double> p(A(5)); + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + //p(3, 'a'); + p(); + BOOST_TEST(f.get() == 5.0); + p.reset(); + //p(4, 'a'); + p(); + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(f.get() == 5.0); + } + { + boost::packaged_task<double> p; + try + { + p.reset(); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + } + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/packaged_task/types_pass.cpp b/libs/thread/test/sync/futures/packaged_task/types_pass.cpp new file mode 100755 index 0000000000..d574c76d6b --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/types_pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// template<class R, class... ArgTypes> +// class packaged_task<R(ArgTypes...)> +// { +// public: +// typedef R result_type; + + +#include <boost/thread/future.hpp> +#include <boost/static_assert.hpp> +#include <boost/detail/lightweight_test.hpp> + +struct A {}; + +int main() +{ + BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::packaged_task<A>::result_type, A>::value), ""); + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/packaged_task/use_allocator_pass.cpp b/libs/thread/test/sync/futures/packaged_task/use_allocator_pass.cpp new file mode 100644 index 0000000000..f3e2f420c7 --- /dev/null +++ b/libs/thread/test/sync/futures/packaged_task/use_allocator_pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class packaged_task<R(ArgTypes...)> + +// template <class Callable, class Alloc> +// struct uses_allocator<packaged_task<Callable>, Alloc> +// : true_type { }; + + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/static_assert.hpp> + +#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS +#include <libs/thread/test/sync/futures/test_allocator.hpp> + +int main() +{ + + BOOST_STATIC_ASSERT_MSG((boost::uses_allocator<boost::packaged_task<double>, test_allocator<double> >::value), ""); + + return boost::report_errors(); +} + +#else +int main() +{ + return boost::report_errors(); +} +#endif + + diff --git a/libs/thread/test/sync/futures/promise/alloc_ctor_pass.cpp b/libs/thread/test/sync/futures/promise/alloc_ctor_pass.cpp new file mode 100644 index 0000000000..55c86a79d2 --- /dev/null +++ b/libs/thread/test/sync/futures/promise/alloc_ctor_pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class promise<R> + +// promise(allocator_arg_t, const Allocator& a); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> +#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS +#include <libs/thread/test/sync/futures/test_allocator.hpp> + +int main() +{ + BOOST_TEST(test_alloc_base::count == 0); + { + boost::promise<int> p(boost::allocator_arg, test_allocator<int>()); + BOOST_TEST(test_alloc_base::count == 1); + boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + } + BOOST_TEST(test_alloc_base::count == 0); + { + boost::promise<int&> p(boost::allocator_arg, test_allocator<int>()); + BOOST_TEST(test_alloc_base::count == 1); + boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + } + BOOST_TEST(test_alloc_base::count == 0); + { + boost::promise<void> p(boost::allocator_arg, test_allocator<void>()); + BOOST_TEST(test_alloc_base::count == 1); + boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + } + BOOST_TEST(test_alloc_base::count == 0); + + + return boost::report_errors(); +} + +#else +int main() +{ + return boost::report_errors(); +} +#endif + + diff --git a/libs/thread/test/sync/futures/promise/copy_assign_fail.cpp b/libs/thread/test/sync/futures/promise/copy_assign_fail.cpp new file mode 100755 index 0000000000..4625477f8d --- /dev/null +++ b/libs/thread/test/sync/futures/promise/copy_assign_fail.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> +// class promise<R> +// promise& operator=(const promise& rhs) = delete; + +#define BOOST_THREAD_VERSION 3 +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + { + boost::promise<int> p0; + boost::promise<int> p; + p = p0; + } + + return boost::report_errors(); +} + +void remove_unused_warning() +{ + //../../../boost/system/error_code.hpp:214:36: warning: Ôboost::system::posix_categoryÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:215:36: warning: Ôboost::system::errno_ecatÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:216:36: warning: Ôboost::system::native_ecatÕ defined but not used [-Wunused-variable] + + (void)boost::system::posix_category; + (void)boost::system::errno_ecat; + (void)boost::system::native_ecat; +} diff --git a/libs/thread/test/sync/futures/promise/copy_ctor_fail.cpp b/libs/thread/test/sync/futures/promise/copy_ctor_fail.cpp new file mode 100644 index 0000000000..8cfcfdfc84 --- /dev/null +++ b/libs/thread/test/sync/futures/promise/copy_ctor_fail.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> +// class promise<R> +// promise& operator=(const promise& rhs) = delete; + +#define BOOST_THREAD_VERSION 3 +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + { + boost::promise<int> p0; + boost::promise<int> p(p0); + } + + return boost::report_errors(); +} + +void remove_unused_warning() +{ + //../../../boost/system/error_code.hpp:214:36: warning: Ôboost::system::posix_categoryÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:215:36: warning: Ôboost::system::errno_ecatÕ defined but not used [-Wunused-variable] + //../../../boost/system/error_code.hpp:216:36: warning: Ôboost::system::native_ecatÕ defined but not used [-Wunused-variable] + + (void)boost::system::posix_category; + (void)boost::system::errno_ecat; + (void)boost::system::native_ecat; +} diff --git a/libs/thread/test/sync/futures/promise/default_pass.cpp b/libs/thread/test/sync/futures/promise/default_pass.cpp new file mode 100755 index 0000000000..566d659a8b --- /dev/null +++ b/libs/thread/test/sync/futures/promise/default_pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class promise<R> + +// promise(); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + + { + boost::promise<int> p; + boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(f.valid()); + } + { + boost::promise<int&> p; + boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(f.valid()); + } + { + boost::promise<void> p; + std::cout << __LINE__ << std::endl; + boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + std::cout << __LINE__ << std::endl; + BOOST_TEST(f.valid()); + } + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/promise/dtor_pass.cpp b/libs/thread/test/sync/futures/promise/dtor_pass.cpp new file mode 100755 index 0000000000..e449c03787 --- /dev/null +++ b/libs/thread/test/sync/futures/promise/dtor_pass.cpp @@ -0,0 +1,116 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class promise<R> + +// ~promise(); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + { + typedef int T; + boost::future<T> f; + { + boost::promise<T> p; + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + p.set_value(3); + } + BOOST_TEST(f.get() == 3); + } + { + typedef int T; + boost::future<T> f; + { + boost::promise<T> p; + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + } + try + { + //T i = + (void)f.get(); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise)); + } + } + { + typedef int& T; + int i = 4; + boost::future<T> f; + { + boost::promise<T> p; + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + p.set_value(i); + } + BOOST_TEST(&f.get() == &i); + } + { + typedef int& T; + boost::future<T> f; + { + boost::promise<T> p; + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + } + try + { + //T i = + (void)f.get(); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise)); + } + } + { + typedef void T; + boost::future<T> f; + { + boost::promise<T> p; + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + p.set_value(); + } + f.get(); + BOOST_TEST(true); + } + { + typedef void T; + boost::future<T> f; + { + boost::promise<T> p; + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + } + try + { + f.get(); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise)); + } + } + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/promise/get_future_pass.cpp b/libs/thread/test/sync/futures/promise/get_future_pass.cpp new file mode 100755 index 0000000000..13a63b13dc --- /dev/null +++ b/libs/thread/test/sync/futures/promise/get_future_pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class promise<R> + +// future<R> get_future(); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + { + boost::promise<double> p; + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + p.set_value(105.5); + BOOST_TEST(f.get() == 105.5); + } + { + boost::promise<double> p; + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + try + { + f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::future_already_retrieved)); + } + } + { + boost::promise<double> p; + boost::promise<double> p0 = boost::move(p); + try + { + boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + } + + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/promise/move_assign_pass.cpp b/libs/thread/test/sync/futures/promise/move_assign_pass.cpp new file mode 100755 index 0000000000..d41c9a7cf4 --- /dev/null +++ b/libs/thread/test/sync/futures/promise/move_assign_pass.cpp @@ -0,0 +1,155 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <future> + +// class promise<R> + +// promise& operator=(promise&& rhs); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> +#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS +#include <libs/thread/test/sync/futures/test_allocator.hpp> +#endif + +boost::mutex m0; +boost::mutex m1; + +int main() +{ +#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS + BOOST_TEST(test_alloc_base::count == 0); + { + boost::promise<int> p0(boost::allocator_arg, test_allocator<int>()); + boost::promise<int> p(boost::allocator_arg, test_allocator<int>()); + BOOST_TEST(test_alloc_base::count == 2); + p = boost::move(p0); + BOOST_TEST(test_alloc_base::count == 1); + boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + try + { + f = BOOST_THREAD_MAKE_RV_REF(p0.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + BOOST_TEST(test_alloc_base::count == 1); + } + BOOST_TEST(test_alloc_base::count == 0); + + { + boost::promise<int&> p0(boost::allocator_arg, test_allocator<int>()); + boost::promise<int&> p(boost::allocator_arg, test_allocator<int>()); + BOOST_TEST(test_alloc_base::count == 2); + p = boost::move(p0); + BOOST_TEST(test_alloc_base::count == 1); + boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + try + { + f = BOOST_THREAD_MAKE_RV_REF(p0.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + BOOST_TEST(test_alloc_base::count == 1); + } + BOOST_TEST(test_alloc_base::count == 0); + { + boost::promise<void> p0(boost::allocator_arg, test_allocator<void>()); + boost::promise<void> p(boost::allocator_arg, test_allocator<void>()); + BOOST_TEST(test_alloc_base::count == 2); + p = boost::move(p0); + BOOST_TEST(test_alloc_base::count == 1); + boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + try + { + f = BOOST_THREAD_MAKE_RV_REF(p0.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + BOOST_TEST(test_alloc_base::count == 1); + } + BOOST_TEST(test_alloc_base::count == 0); + +#endif + { + boost::promise<int> p0; + boost::promise<int> p; + p = boost::move(p0); + boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(f.valid()); + try + { + f = BOOST_THREAD_MAKE_RV_REF(p0.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + } + + { + boost::promise<int&> p0; + boost::promise<int&> p; + p = boost::move(p0); + boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(f.valid()); + try + { + f = BOOST_THREAD_MAKE_RV_REF(p0.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + } + { + boost::promise<void> p0; + boost::promise<void> p; + p = boost::move(p0); + boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(f.valid()); + try + { + f = BOOST_THREAD_MAKE_RV_REF(p0.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + } + + return boost::report_errors(); + +} + diff --git a/libs/thread/test/sync/futures/promise/move_ctor_pass.cpp b/libs/thread/test/sync/futures/promise/move_ctor_pass.cpp new file mode 100755 index 0000000000..44edaa497c --- /dev/null +++ b/libs/thread/test/sync/futures/promise/move_ctor_pass.cpp @@ -0,0 +1,151 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <future> + +// class promise<R> + +// promise(promise&& rhs); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> +#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS +#include <libs/thread/test/sync/futures/test_allocator.hpp> +#endif + +boost::mutex m; + +int main() +{ +#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS + BOOST_TEST(test_alloc_base::count == 0); + { + boost::promise<int> p0(boost::allocator_arg, test_allocator<int>()); + boost::promise<int> p(boost::move(p0)); + BOOST_TEST(test_alloc_base::count == 1); + std::cout << __LINE__ << std::endl; + boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + std::cout << __LINE__ << std::endl; + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + std::cout << __LINE__ << std::endl; + try + { + f = BOOST_THREAD_MAKE_RV_REF(p0.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + std::cout << __LINE__ << std::endl; + BOOST_TEST(test_alloc_base::count == 1); + } + std::cout << __LINE__ << std::endl; + BOOST_TEST(test_alloc_base::count == 0); + { + boost::promise<int&> p0(boost::allocator_arg, test_allocator<int>()); + boost::promise<int&> p(boost::move(p0)); + BOOST_TEST(test_alloc_base::count == 1); + boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + try + { + f = BOOST_THREAD_MAKE_RV_REF(p0.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + BOOST_TEST(test_alloc_base::count == 1); + } + BOOST_TEST(test_alloc_base::count == 0); + { + boost::promise<void> p0(boost::allocator_arg, test_allocator<void>()); + boost::promise<void> p(boost::move(p0)); + BOOST_TEST(test_alloc_base::count == 1); + boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(test_alloc_base::count == 1); + BOOST_TEST(f.valid()); + try + { + f = BOOST_THREAD_MAKE_RV_REF(p0.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + BOOST_TEST(test_alloc_base::count == 1); + } + BOOST_TEST(test_alloc_base::count == 0); +#endif + { + boost::promise<int> p0; + boost::promise<int> p(boost::move(p0)); + std::cout << __LINE__ << std::endl; + boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + std::cout << __LINE__ << std::endl; + BOOST_TEST(f.valid()); + std::cout << __LINE__ << std::endl; + try + { + f = BOOST_THREAD_MAKE_RV_REF(p0.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + std::cout << __LINE__ << std::endl; + } + std::cout << __LINE__ << std::endl; + { + boost::promise<int&> p0; + boost::promise<int&> p(boost::move(p0)); + boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(f.valid()); + try + { + f = BOOST_THREAD_MAKE_RV_REF(p0.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + } + { + boost::promise<void> p0; + boost::promise<void> p(boost::move(p0)); + boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future()); + BOOST_TEST(f.valid()); + try + { + f = BOOST_THREAD_MAKE_RV_REF(p0.get_future()); + BOOST_TEST(false); + } + catch (const boost::future_error& e) + { + BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state)); + } + } + + return boost::report_errors(); +} + diff --git a/libs/thread/test/sync/futures/promise/use_allocator_pass.cpp b/libs/thread/test/sync/futures/promise/use_allocator_pass.cpp new file mode 100644 index 0000000000..c11c06b39e --- /dev/null +++ b/libs/thread/test/sync/futures/promise/use_allocator_pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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) + +// <boost/thread/future.hpp> + +// class promise<R> + +// promise(allocator_arg_t, const Allocator& a); + +#define BOOST_THREAD_VERSION 3 + +#include <boost/thread/future.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/static_assert.hpp> + +#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS +#include <libs/thread/test/sync/futures/test_allocator.hpp> + +int main() +{ + + BOOST_STATIC_ASSERT_MSG((boost::uses_allocator<boost::promise<int>, test_allocator<int> >::value), ""); + BOOST_STATIC_ASSERT_MSG((boost::uses_allocator<boost::promise<int&>, test_allocator<int&> >::value), ""); + BOOST_STATIC_ASSERT_MSG((boost::uses_allocator<boost::promise<void>, test_allocator<void> >::value), ""); + + return boost::report_errors(); +} + +#else +int main() +{ + return boost::report_errors(); +} +#endif + + diff --git a/libs/thread/test/sync/futures/test_allocator.hpp b/libs/thread/test/sync/futures/test_allocator.hpp new file mode 100644 index 0000000000..a73d7d8e33 --- /dev/null +++ b/libs/thread/test/sync/futures/test_allocator.hpp @@ -0,0 +1,158 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// 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 BOOST_THREAD_TEST_ALLOCATOR_HPP +#define BOOST_THREAD_TEST_ALLOCATOR_HPP + +#include <cstddef> +#include <boost/type_traits.hpp> +#include <boost/thread/detail/move.hpp> +#include <cstdlib> +#include <new> +#include <climits> + +class test_alloc_base +{ +public: + static int count; +public: + static int throw_after; +}; + +int test_alloc_base::count = 0; +int test_alloc_base::throw_after = INT_MAX; + +template <class T> +class test_allocator + : public test_alloc_base +{ + int data_; + + template <class U> friend class test_allocator; +public: + + typedef unsigned size_type; + typedef int difference_type; + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef typename boost::add_lvalue_reference<value_type>::type reference; + typedef typename boost::add_lvalue_reference<const value_type>::type const_reference; + + template <class U> struct rebind {typedef test_allocator<U> other;}; + + test_allocator() throw() : data_(-1) {} + explicit test_allocator(int i) throw() : data_(i) {} + test_allocator(const test_allocator& a) throw() + : data_(a.data_) {} + template <class U> test_allocator(const test_allocator<U>& a) throw() + : data_(a.data_) {} + ~test_allocator() throw() {data_ = 0;} + pointer address(reference x) const {return &x;} + const_pointer address(const_reference x) const {return &x;} + pointer allocate(size_type n, const void* = 0) + { + if (count >= throw_after) + throw std::bad_alloc(); + ++count; + return (pointer)std::malloc(n * sizeof(T)); + } + void deallocate(pointer p, size_type) + {--count; std::free(p);} + size_type max_size() const throw() + {return UINT_MAX / sizeof(T);} + void construct(pointer p, const T& val) + {::new(p) T(val);} + + void construct(pointer p, BOOST_THREAD_RV_REF(T) val) + {::new(p) T(boost::move(val));} + + void destroy(pointer p) {p->~T();} + + friend bool operator==(const test_allocator& x, const test_allocator& y) + {return x.data_ == y.data_;} + friend bool operator!=(const test_allocator& x, const test_allocator& y) + {return !(x == y);} +}; + +template <> +class test_allocator<void> + : public test_alloc_base +{ + int data_; + + template <class U> friend class test_allocator; +public: + + typedef unsigned size_type; + typedef int difference_type; + typedef void value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + + template <class U> struct rebind {typedef test_allocator<U> other;}; + + test_allocator() throw() : data_(-1) {} + explicit test_allocator(int i) throw() : data_(i) {} + test_allocator(const test_allocator& a) throw() + : data_(a.data_) {} + template <class U> test_allocator(const test_allocator<U>& a) throw() + : data_(a.data_) {} + ~test_allocator() throw() {data_ = 0;} + + friend bool operator==(const test_allocator& x, const test_allocator& y) + {return x.data_ == y.data_;} + friend bool operator!=(const test_allocator& x, const test_allocator& y) + {return !(x == y);} +}; + +template <class T> +class other_allocator +{ + int data_; + + template <class U> friend class other_allocator; + +public: + typedef T value_type; + + other_allocator() : data_(-1) {} + explicit other_allocator(int i) : data_(i) {} + template <class U> other_allocator(const other_allocator<U>& a) + : data_(a.data_) {} + T* allocate(std::size_t n) + {return (T*)std::malloc(n * sizeof(T));} + void deallocate(T* p, std::size_t) + {std::free(p);} + + other_allocator select_on_container_copy_construction() const + {return other_allocator(-2);} + + friend bool operator==(const other_allocator& x, const other_allocator& y) + {return x.data_ == y.data_;} + friend bool operator!=(const other_allocator& x, const other_allocator& y) + {return !(x == y);} + + typedef boost::true_type propagate_on_container_copy_assignment; + typedef boost::true_type propagate_on_container_move_assignment; + typedef boost::true_type propagate_on_container_swap; + +#ifdef BOOST_NO_SFINAE_EXPR + std::size_t max_size() const + {return UINT_MAX / sizeof(T);} +#endif // BOOST_NO_SFINAE_EXPR + +}; + +#endif // BOOST_THREAD_TEST_ALLOCATOR_HPP |