Skip to content

Commit

Permalink
when_any test has changed according to generic container functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonBikineev committed Sep 9, 2015
1 parent 601f0f1 commit 10a224d
Showing 1 changed file with 61 additions and 40 deletions.
101 changes: 61 additions & 40 deletions tests/unit/lcos/when_any.cpp
Expand Up @@ -13,6 +13,9 @@
#include <utility>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <deque>

#include <boost/move/move.hpp>
#include <boost/lexical_cast.hpp>
Expand Down Expand Up @@ -73,9 +76,13 @@ void test_wait_for_either_of_two_futures_2()
HPX_TEST_EQ(hpx::util::get<1>(t).get(), 42);
}

template <template <class...> class Container>
void test_wait_for_either_of_two_futures_list_1()
{
std::vector<hpx::lcos::future<int> > futures;
typedef Container<hpx::lcos::future<int>,
std::allocator<hpx::lcos::future<int> > > container;

container futures;
hpx::lcos::local::packaged_task<int()> pt1(make_int_slowly);
futures.push_back(pt1.get_future());
hpx::lcos::local::packaged_task<int()> pt2(make_int_slowly);
Expand All @@ -84,25 +91,27 @@ void test_wait_for_either_of_two_futures_list_1()
pt1();

hpx::lcos::future<hpx::when_any_result<
std::vector<hpx::lcos::future<int> > > > r =
hpx::when_any(futures);
hpx::when_any_result<
std::vector<hpx::lcos::future<int> > > raw = r.get();
container> > r = hpx::when_any(futures);
hpx::when_any_result<container> raw = r.get();

HPX_TEST_EQ(raw.index, 0u);

std::vector<hpx::lcos::future<int> > t = std::move(raw.futures);
container t = std::move(raw.futures);

HPX_TEST(!futures[0].valid());
HPX_TEST(!futures[1].valid());
HPX_TEST(!futures.front().valid());
HPX_TEST(!futures.back().valid());

HPX_TEST(t[0].is_ready());
HPX_TEST_EQ(t[0].get(), 42);
HPX_TEST(t.front().is_ready());
HPX_TEST_EQ(t.front().get(), 42);
}

template <template <class...> class Container>
void test_wait_for_either_of_two_futures_list_2()
{
std::vector<hpx::lcos::future<int> > futures;
typedef Container<hpx::lcos::future<int>,
std::allocator<hpx::lcos::future<int> > > container;

container futures;
hpx::lcos::local::packaged_task<int()> pt1(make_int_slowly);
futures.push_back(pt1.get_future());
hpx::lcos::local::packaged_task<int()> pt2(make_int_slowly);
Expand All @@ -111,20 +120,18 @@ void test_wait_for_either_of_two_futures_list_2()
pt2();

hpx::lcos::future<hpx::when_any_result<
std::vector<hpx::lcos::future<int> > > > r =
hpx::when_any(futures);
hpx::when_any_result<
std::vector<hpx::lcos::future<int> > > raw = r.get();
container> > r = hpx::when_any(futures);
hpx::when_any_result<container> raw = r.get();

HPX_TEST_EQ(raw.index, 1u);

std::vector<hpx::lcos::future<int> > t = std::move(raw.futures);
container t = std::move(raw.futures);

HPX_TEST(!futures[0].valid());
HPX_TEST(!futures[1].valid());
HPX_TEST(!futures.front().valid());
HPX_TEST(!futures.back().valid());

HPX_TEST(t[1].is_ready());
HPX_TEST_EQ(t[1].get(), 42);
HPX_TEST(t.back().is_ready());
HPX_TEST_EQ(t.back().get(), 42);
}

void test_wait_for_either_of_three_futures_1()
Expand Down Expand Up @@ -350,9 +357,13 @@ void test_wait_for_either_of_four_futures_4()
HPX_TEST_EQ(hpx::util::get<3>(t).get(), 42);
}

template <template <class...> class Container>
void test_wait_for_either_of_five_futures_1_from_list()
{
std::vector<hpx::lcos::future<int> > futures;
typedef Container<hpx::lcos::future<int>,
std::allocator<hpx::lcos::future<int> > > container;

container futures;

hpx::lcos::local::packaged_task<int()> pt1(make_int_slowly);
hpx::lcos::future<int> f1(pt1.get_future());
Expand All @@ -373,28 +384,31 @@ void test_wait_for_either_of_five_futures_1_from_list()
pt1();

hpx::lcos::future<hpx::when_any_result<
std::vector<hpx::lcos::future<int> > > > r =
hpx::when_any(futures);
hpx::when_any_result<
std::vector<hpx::lcos::future<int> > > raw = r.get();
container> > r = hpx::when_any(futures);
hpx::when_any_result<container> raw = r.get();

HPX_TEST_EQ(raw.index, 0u);

std::vector<hpx::lcos::future<int> > t = std::move(raw.futures);
container t = std::move(raw.futures);

HPX_TEST(!f1.valid());
HPX_TEST(!f2.valid());
HPX_TEST(!f3.valid());
HPX_TEST(!f4.valid());
HPX_TEST(!f5.valid());

HPX_TEST(t[0].is_ready());
HPX_TEST_EQ(t[0].get(), 42);
HPX_TEST(t.front().is_ready());
HPX_TEST_EQ(t.front().get(), 42);
}

template <template <class...> class Container>
void test_wait_for_either_of_five_futures_1_from_list_iterators()
{
std::vector<hpx::lcos::future<int> > futures;
typedef Container<hpx::lcos::future<int>,
std::allocator<hpx::lcos::future<int> > > container;
typedef typename container::iterator iterator;

container futures;

hpx::lcos::local::packaged_task<int()> pt1(make_int_slowly);
hpx::lcos::future<int> f1(pt1.get_future());
Expand All @@ -415,23 +429,22 @@ void test_wait_for_either_of_five_futures_1_from_list_iterators()
pt1();

hpx::lcos::future<hpx::when_any_result<
std::vector<hpx::lcos::future<int> > > > r =
hpx::when_any(futures.begin(), futures.end());
hpx::when_any_result<
std::vector<hpx::lcos::future<int> > > raw = r.get();
container> > r =
hpx::when_any<iterator, container>(futures.begin(), futures.end());
hpx::when_any_result<container> raw = r.get();

HPX_TEST_EQ(raw.index, 0u);

std::vector<hpx::lcos::future<int> > t = std::move(raw.futures);
container t = std::move(raw.futures);

HPX_TEST(!f1.valid());
HPX_TEST(!f2.valid());
HPX_TEST(!f3.valid());
HPX_TEST(!f4.valid());
HPX_TEST(!f5.valid());

HPX_TEST(t[0].is_ready());
HPX_TEST_EQ(t[0].get(), 42);
HPX_TEST(t.front().is_ready());
HPX_TEST_EQ(t.front().get(), 42);
}

void test_wait_for_either_of_five_futures_1()
Expand Down Expand Up @@ -736,17 +749,25 @@ int hpx_main(variables_map&)
{
test_wait_for_either_of_two_futures_1();
test_wait_for_either_of_two_futures_2();
test_wait_for_either_of_two_futures_list_1();
test_wait_for_either_of_two_futures_list_2();
test_wait_for_either_of_two_futures_list_1<std::vector>();
test_wait_for_either_of_two_futures_list_1<std::list>();
test_wait_for_either_of_two_futures_list_1<std::deque>();
test_wait_for_either_of_two_futures_list_2<std::vector>();
test_wait_for_either_of_two_futures_list_2<std::list>();
test_wait_for_either_of_two_futures_list_2<std::deque>();
test_wait_for_either_of_three_futures_1();
test_wait_for_either_of_three_futures_2();
test_wait_for_either_of_three_futures_3();
test_wait_for_either_of_four_futures_1();
test_wait_for_either_of_four_futures_2();
test_wait_for_either_of_four_futures_3();
test_wait_for_either_of_four_futures_4();
test_wait_for_either_of_five_futures_1_from_list();
test_wait_for_either_of_five_futures_1_from_list_iterators();
test_wait_for_either_of_five_futures_1_from_list<std::vector>();
test_wait_for_either_of_five_futures_1_from_list<std::list>();
test_wait_for_either_of_five_futures_1_from_list<std::deque>();
test_wait_for_either_of_five_futures_1_from_list_iterators<std::vector>();
test_wait_for_either_of_five_futures_1_from_list_iterators<std::list>();
test_wait_for_either_of_five_futures_1_from_list_iterators<std::deque>();
test_wait_for_either_of_five_futures_1();
test_wait_for_either_of_five_futures_2();
test_wait_for_either_of_five_futures_3();
Expand Down

0 comments on commit 10a224d

Please sign in to comment.