]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/test/test_async_dispatch.cpp
1 // (C) Copyright 2008-10 Anthony Williams
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
13 #include <boost/test/unit_test.hpp>
15 #include <boost/fiber/all.hpp>
20 A( A
const&) = delete;
21 A
& operator=( A
const&) = delete;
24 value
{ other
.value
} {
28 A
& operator=( A
&& other
) {
29 if ( this == & other
) return * this;
58 return std::forward
< A
>( a
);
62 boost::fibers::future
< void > f1
= boost::fibers::async( boost::fibers::launch::dispatch
, fn1
);
63 BOOST_CHECK( f1
.valid() );
70 boost::fibers::future
< int > f1
= boost::fibers::async( boost::fibers::launch::dispatch
, fn2
, i
);
71 BOOST_CHECK( f1
.valid() );
73 BOOST_CHECK( i
== f1
.get());
78 boost::fibers::future
< int& > f1
= boost::fibers::async( boost::fibers::launch::dispatch
, fn3
, std::ref( i
) );
79 BOOST_CHECK( f1
.valid() );
81 BOOST_CHECK( & i
== & f1
.get());
87 boost::fibers::future
< A
> f1
= boost::fibers::async( boost::fibers::launch::dispatch
, fn4
, std::move( a1
) );
88 BOOST_CHECK( f1
.valid() );
91 BOOST_CHECK( 7 == a2
.value
);
96 BOOST_CHECK( 0 == x
.value
);
97 boost::fibers::future
< void > f1
= boost::fibers::async(
98 boost::fibers::launch::dispatch
,
99 std::bind( & X::foo
, std::ref( x
), 3) );
100 BOOST_CHECK( f1
.valid() );
103 BOOST_CHECK( 3 == x
.value
);
106 void test_async_6() {
108 BOOST_CHECK( 0 == x
.value
);
109 boost::fibers::future
< void > f1
= boost::fibers::async(
110 boost::fibers::launch::dispatch
,
111 std::bind( & X::foo
, std::ref( x
), std::placeholders::_1
), 3);
112 BOOST_CHECK( f1
.valid() );
115 BOOST_CHECK( 3 == x
.value
);
118 void test_async_stack_alloc() {
119 boost::fibers::future
< void > f1
= boost::fibers::async(
120 boost::fibers::launch::dispatch
,
122 boost::fibers::fixedsize_stack
{},
124 BOOST_CHECK( f1
.valid() );
129 void test_async_std_alloc() {
131 boost::fibers::future
< void > f1
= boost::fibers::async(
132 boost::fibers::launch::dispatch
,
134 boost::fibers::fixedsize_stack
{},
135 std::allocator
< none
>{},
137 BOOST_CHECK( f1
.valid() );
143 boost::unit_test_framework::test_suite
* init_unit_test_suite(int, char*[]) {
144 boost::unit_test_framework::test_suite
* test
=
145 BOOST_TEST_SUITE("Boost.Fiber: async test suite");
147 test
->add(BOOST_TEST_CASE(test_async_1
));
148 test
->add(BOOST_TEST_CASE(test_async_2
));
149 test
->add(BOOST_TEST_CASE(test_async_3
));
150 test
->add(BOOST_TEST_CASE(test_async_4
));
151 test
->add(BOOST_TEST_CASE(test_async_5
));
152 test
->add(BOOST_TEST_CASE(test_async_6
));
153 test
->add(BOOST_TEST_CASE(test_async_stack_alloc
));
154 test
->add(BOOST_TEST_CASE(test_async_std_alloc
));