Skip to content

Commit

Permalink
Added test for when_all with generic container
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonBikineev committed Sep 1, 2015
1 parent 7d33e06 commit d9cb38f
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions tests/unit/lcos/when_all.cpp
Expand Up @@ -13,6 +13,9 @@
#include <utility>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>

#include <boost/move/move.hpp>
#include <boost/lexical_cast.hpp>
Expand All @@ -25,52 +28,55 @@ int make_int_slowly()
return 42;
}

template <template <class...> class Container>

This comment has been minimized.

Copy link
@K-ballo

K-ballo Sep 1, 2015

Member

I believe this might fail with gcc4.6, be sure to make a run for it on buildbot.

void test_wait_for_all_from_list()
{
unsigned const count = 10;
std::vector<hpx::lcos::future<int> > futures;
Container<hpx::lcos::future<int> > futures;
for (unsigned j = 0; j < count; ++j)
{
hpx::lcos::local::futures_factory<int()> task(make_int_slowly);
futures.push_back(task.get_future());
task.apply();
}

hpx::lcos::future<std::vector<hpx::lcos::future<int> > > r =
hpx::lcos::future<Container<hpx::lcos::future<int> > > r =
hpx::when_all(futures);

std::vector<hpx::lcos::future<int> > result = r.get();
Container<hpx::lcos::future<int> > result = r.get();

HPX_TEST_EQ(futures.size(), result.size());
for (unsigned j = 0; j < count; ++j)
{
HPX_TEST(!futures[j].valid());
HPX_TEST(result[j].is_ready());
}
for (const auto& f : futures)
HPX_TEST(!f.valid());
for (const auto& r : result)
HPX_TEST(r.is_ready());
}

template <template <class...> class Container>
void test_wait_for_all_from_list_iterators()
{
typedef Container<hpx::lcos::future<int> > container;
unsigned const count = 10;
std::vector<hpx::lcos::future<int> > futures;

container futures;
for (unsigned j = 0; j < count; ++j)
{
hpx::lcos::local::futures_factory<int()> task(make_int_slowly);
futures.push_back(task.get_future());
task.apply();
}

hpx::lcos::future<std::vector<hpx::lcos::future<int> > > r =
hpx::when_all(futures.begin(), futures.end());
hpx::lcos::future<container> r =
hpx::when_all<typename container::iterator,
container>(futures.begin(), futures.end());

std::vector<hpx::lcos::future<int> > result = r.get();
Container<hpx::lcos::future<int> > result = r.get();

HPX_TEST_EQ(futures.size(), result.size());
for (unsigned j = 0; j < count; ++j)
{
HPX_TEST(!futures[j].valid());
HPX_TEST(result[j].is_ready());
}
for (const auto& f : futures)
HPX_TEST(!f.valid());
for (const auto& r : result)
HPX_TEST(r.is_ready());
}

void test_wait_for_all_two_futures()
Expand Down Expand Up @@ -257,8 +263,12 @@ using boost::program_options::options_description;
int hpx_main(variables_map&)
{
{
test_wait_for_all_from_list();
test_wait_for_all_from_list_iterators();
test_wait_for_all_from_list<std::vector>();
test_wait_for_all_from_list<std::list>();
test_wait_for_all_from_list<std::deque>();
test_wait_for_all_from_list_iterators<std::vector>();
test_wait_for_all_from_list_iterators<std::list>();
test_wait_for_all_from_list_iterators<std::deque>();
test_wait_for_all_two_futures();
test_wait_for_all_three_futures();
test_wait_for_all_four_futures();
Expand Down

0 comments on commit d9cb38f

Please sign in to comment.