1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // Copyright (C) 2011 Vicente J. Botet Escriba 11 // 12 // Distributed under the Boost Software License, Version 1.0. (See accompanying 13 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 14 15 // <boost/thread/future.hpp> 16 17 // class promise<R> 18 19 // void set_exception(exception_ptr p); 20 21 #define BOOST_THREAD_VERSION 3 22 23 #include <boost/thread/future.hpp> 24 #include <boost/detail/lightweight_test.hpp> 25 #include <boost/static_assert.hpp> 26 27 namespace boost 28 { 29 template <typename T> 30 struct wrap 31 { wrapboost::wrap32 wrap(T const& v) : 33 value(v) 34 { 35 } 36 T value; 37 38 }; 39 40 template <typename T> make_exception_ptr(T v)41 exception_ptr make_exception_ptr(T v) 42 { 43 return copy_exception(wrap<T> (v)); 44 } 45 } 46 main()47int main() 48 { 49 50 { 51 typedef int T; 52 boost::promise<T> p; 53 boost::future<T> f = p.get_future(); 54 p.set_exception(boost::make_exception_ptr(3)); 55 try 56 { 57 f.get(); 58 BOOST_TEST(false); 59 } 60 catch (boost::wrap<int> i) 61 { 62 BOOST_TEST(i.value == 3); 63 } 64 try 65 { 66 p.set_exception(boost::make_exception_ptr(3)); 67 BOOST_TEST(false); 68 } 69 catch (const boost::future_error& e) 70 { 71 BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied)); 72 } 73 catch (...) 74 { 75 BOOST_TEST(false); 76 } 77 } 78 { 79 typedef int T; 80 boost::promise<T> p; 81 boost::future<T> f = p.get_future(); 82 p.set_exception_deferred(boost::make_exception_ptr(3)); 83 BOOST_TEST(!f.is_ready()); 84 p.notify_deferred(); 85 try 86 { 87 f.get(); 88 BOOST_TEST(false); 89 } 90 catch (boost::wrap<int> i) 91 { 92 BOOST_TEST(i.value == 3); 93 } 94 try 95 { 96 p.set_exception(boost::make_exception_ptr(3)); 97 BOOST_TEST(false); 98 } 99 catch (const boost::future_error& e) 100 { 101 BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied)); 102 } 103 catch (...) 104 { 105 BOOST_TEST(false); 106 } 107 } 108 return boost::report_errors(); 109 } 110 111