$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r77844 - trunk/libs/thread/test/sync/futures/packaged_task
From: vicente.botet_at_[hidden]
Date: 2012-04-08 19:24:20
Author: viboes
Date: 2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
New Revision: 77844
URL: http://svn.boost.org/trac/boost/changeset/77844
Log:
Thread: Added some packaged_task tests
Added:
   trunk/libs/thread/test/sync/futures/packaged_task/alloc_ctor_pass.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/copy_assign_fail.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/copy_ctor_fail.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/default_ctor_pass.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/dtor_pass.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/func_ctor_pass.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/get_future_pass.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/member_swap_pass.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/move_assign_pass.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/move_ctor_pass.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/non_member_swap_pass.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/operator_pass.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/types_pass.cpp   (contents, props changed)
   trunk/libs/thread/test/sync/futures/packaged_task/use_allocator_pass.cpp   (contents, props changed)
Added: trunk/libs/thread/test/sync/futures/packaged_task/alloc_ctor_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/alloc_ctor_pass.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -0,0 +1,144 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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 2
+
+#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>
+
+class A
+{
+  long data_;
+
+public:
+  static int n_moves;
+  static int n_copies;
+
+  explicit A(long i) : data_(i)
+  {
+  }
+#ifndef BOOST_NO_RVALUE_REFERENCES
+  A(A&& a) : data_(a.data_)
+  {
+    ++n_moves; a.data_ = -1;
+  }
+#else
+
+#if defined BOOST_THREAD_USES_MOVE
+  operator ::boost::rv<A>&()
+  {
+    return *static_cast< ::boost::rv<A>* >(this);
+  }
+  operator const ::boost::rv<A>&() const
+  {
+    return *static_cast<const ::boost::rv<A>* >(this);
+  }
+  ::boost::rv<A>& move()
+  {
+    return *static_cast< ::boost::rv<A>* >(this);
+  }
+  const ::boost::rv<A>& move() const
+  {
+    return *static_cast<const ::boost::rv<A>* >(this);
+  }
+
+  A(boost::rv<A>& a) : data_(a.data_)
+  {
+    ++n_moves; a.data_ = -1;
+  }
+#else
+  operator boost::detail::thread_move_t<A>()
+  {
+      return boost::detail::thread_move_t<A>(*this);
+  }
+  boost::detail::thread_move_t<A> move()
+  {
+      return boost::detail::thread_move_t<A>(*this);
+  }
+  A(boost::detail::thread_move_t<A> a) : data_(a.data_)
+  {
+    ++n_moves; a.data_ = -1;
+  }
+
+#endif
+#endif
+  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_EXPLICIT_MOVE(A(5)));
+    BOOST_TEST(test_alloc_base::count > 0);
+    BOOST_TEST(p.valid());
+    boost::future<double> f = BOOST_EXPLICIT_MOVE(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_EXPLICIT_MOVE(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);
+
+  return boost::report_errors();
+}
+
+#else
+int main()
+{
+  return boost::report_errors();
+}
+#endif
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/copy_assign_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/copy_assign_fail.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -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& operator=(packaged_task&) = delete;
+
+
+#define BOOST_THREAD_VERSION 2
+#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(int, char)> p0(A(5));
+      boost::packaged_task<double(int, char)> p;
+      p = p0;
+//      BOOST_TEST(!p0.valid());
+//      BOOST_TEST(p.valid());
+//      boost::future<double> f = p.get_future();
+//      p(3, 'a');
+//      BOOST_TEST(f.get() == 105.0);
+  }
+//  {
+//      boost::packaged_task<double(int, char)> p0;
+//      boost::packaged_task<double(int, char)> p;
+//      p = p0;
+//      BOOST_TEST(!p0.valid());
+//      BOOST_TEST(!p.valid());
+//  }
+
+  return boost::report_errors();
+}
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/copy_ctor_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/copy_ctor_fail.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -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 packaged_task<R>
+
+// packaged_task(packaged_task&) = delete;
+
+
+#define BOOST_THREAD_VERSION 2
+#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();
+}
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/default_ctor_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/default_ctor_pass.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -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 packaged_task<R>
+
+// packaged_task();
+
+
+#define BOOST_THREAD_VERSION 2
+#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<A> p;
+    BOOST_TEST(!p.valid());
+
+  }
+
+  return boost::report_errors();
+}
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/dtor_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/dtor_pass.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -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 2
+
+#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_EXPLICIT_MOVE(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_EXPLICIT_MOVE(p.get_future());
+      boost::thread(func2, boost::move(p)).detach();
+      BOOST_TEST(f.get() == 5.0);
+  }
+
+
+  return boost::report_errors();
+}
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/func_ctor_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/func_ctor_pass.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -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>
+
+// template <class F>
+//     explicit packaged_task(F&& f);
+
+
+#define BOOST_THREAD_VERSION 2
+#include <boost/thread/future.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+class A
+{
+    long data_;
+
+public:
+    static int n_moves;
+    static int n_copies;
+
+    explicit A(long i) : data_(i) {}
+    A(A&& a) : data_(a.data_) {++n_moves; a.data_ = -1;}
+    A(const A& a) : data_(a.data_) {++n_copies;}
+
+    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(A(5));
+      BOOST_TEST(p.valid());
+      boost::future<double> f = BOOST_EXPLICIT_MOVE(p.get_future());
+      //p(3, 'a');
+      p();
+      BOOST_TEST(f.get() == 105.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_EXPLICIT_MOVE(p.get_future());
+      //p(3, 'a');
+      p();
+      BOOST_TEST(f.get() == 105.0);
+      BOOST_TEST(A::n_copies > 0);
+      BOOST_TEST(A::n_moves > 0);
+  }
+
+
+  return boost::report_errors();
+}
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/get_future_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/get_future_pass.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -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 2
+
+#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_EXPLICIT_MOVE(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_EXPLICIT_MOVE(p.get_future());
+      try
+      {
+          f = BOOST_EXPLICIT_MOVE(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_EXPLICIT_MOVE(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();
+}
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/member_swap_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/member_swap_pass.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -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>
+
+// void swap(packaged_task& other);
+
+
+#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::unique_lock<mutex> lk1(m);
+  boost::unique_lock<mutex> lk2;
+  lk1.swap(lk2);
+  BOOST_TEST(lk1.mutex() == 0);
+  BOOST_TEST(lk1.owns_lock() == false);
+  BOOST_TEST(lk2.mutex() == &m);
+  BOOST_TEST(lk2.owns_lock() == true);
+
+  return boost::report_errors();
+}
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/move_assign_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/move_assign_pass.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -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 2
+
+#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_EXPLICIT_MOVE(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();
+
+}
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/move_ctor_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/move_ctor_pass.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -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 2
+
+#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 = 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();
+}
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/non_member_swap_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/non_member_swap_pass.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -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/locks.hpp>
+
+// template <class Mutex>
+//   void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y);
+
+#include <boost/thread/locks.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+struct mutex
+{
+  void lock()
+  {
+  }
+  void unlock()
+  {
+  }
+};
+
+mutex m;
+
+int main()
+{
+  boost::unique_lock<mutex> lk1(m);
+  boost::unique_lock<mutex> lk2;
+  swap(lk1, lk2);
+  BOOST_TEST(lk1.mutex() == 0);
+  BOOST_TEST(lk1.owns_lock() == false);
+  BOOST_TEST(lk2.mutex() == &m);
+  BOOST_TEST(lk2.owns_lock() == true);
+
+  return boost::report_errors();
+}
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/operator_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/operator_pass.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -0,0 +1,125 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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 2
+#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<doubl> p(A(5));
+      boost::future<double> f = p.get_future();
+      boost::thread(func0, boost::move(p)).detach();
+      BOOST_TEST(f.get() == 105.0);
+  }
+  {
+      boost::packaged_task<double> p(A(5));
+      boost::future<double> f = 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::packaged_task<double> p(A(5));
+      boost::future<double> f = p.get_future();
+      boost::thread t(func2, boost::move(p));
+      BOOST_TEST(f.get() == 105.0);
+      t.join();
+  }
+  {
+      boost::packaged_task<double> p;
+      boost::thread t(func3, boost::move(p));
+      t.join();
+  }
+
+  return boost::report_errors();
+}
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/types_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/types_pass.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -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();
+}
+
Added: trunk/libs/thread/test/sync/futures/packaged_task/use_allocator_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/packaged_task/use_allocator_pass.cpp	2012-04-08 19:24:19 EDT (Sun, 08 Apr 2012)
@@ -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 2
+
+#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
+
+