Skip to content

Commit

Permalink
Class method call for any task added
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanPinezhaninov committed Dec 27, 2023
1 parent 79b9b68 commit 8c766cc
Show file tree
Hide file tree
Showing 9 changed files with 886 additions and 96 deletions.
474 changes: 417 additions & 57 deletions include/async_promise.hpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions tests/src/all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ TEST_CASE("All with class method string string", "[all]")

std::vector<std::string(test_struct::*)(std::string) const> methods
{
&test_struct::string_string,
&test_struct::string_string,
&test_struct::string_string1,
&test_struct::string_string2,
};

auto future = async::make_resolved_promise(str1).all(methods, &test).run();

std::vector<std::string> res;
REQUIRE_NOTHROW(res = future.get());
REQUIRE_THAT(res, Catch::Matchers::RangeEquals(std::vector<std::string>{str1, str1}));
REQUIRE_THAT(res, Catch::Matchers::RangeEquals(std::vector<std::string>{str1, str2}));
}


Expand Down
6 changes: 3 additions & 3 deletions tests/src/all_settled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ TEST_CASE("All settled with class method string string", "[all_settled]")

std::vector<std::string(test_struct::*)(std::string) const> methods
{
&test_struct::string_string,
&test_struct::string_string,
&test_struct::string_string1,
&test_struct::string_string2,
};

auto future = async::make_resolved_promise(str1).all_settled(methods, &test).run();
Expand All @@ -201,7 +201,7 @@ TEST_CASE("All settled with class method string string", "[all_settled]")
REQUIRE(res.front().type == async::settle_type::resolved);
REQUIRE(res.front().result == str1);
REQUIRE(res.back().type == async::settle_type::resolved);
REQUIRE(res.back().result == str1);
REQUIRE(res.back().result == str2);
}


Expand Down
243 changes: 230 additions & 13 deletions tests/src/any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,224 @@
#include "common.h"


TEST_CASE("Any void void", "[any]")
TEST_CASE("Any with class method void void", "[any]")
{
test_struct test;

std::vector<void(test_struct::*)() const> methods
{
&test_struct::void_void,
&test_struct::void_void,
};

auto future = async::make_resolved_promise().any(methods, &test).run();

REQUIRE_NOTHROW(future.get());
}


TEST_CASE("Any with class method error void void", "[any]")
{
test_struct test;

std::vector<void(test_struct::*)() const> methods
{
&test_struct::error_void_void,
&test_struct::void_void,
};

auto future = async::make_resolved_promise().any(methods, &test).run();

REQUIRE_NOTHROW(future.get());
}


TEST_CASE("Any with class method all error void void", "[any]")
{
test_struct test;

std::vector<void(test_struct::*)() const> methods
{
&test_struct::error_void_void,
&test_struct::error_void_void,
};

auto future = async::make_resolved_promise().any(methods, &test).run();

REQUIRE_THROWS_MATCHES(future.get(), async::aggregate_error, Catch::Matchers::Message(aggregate_error_message));
}


TEST_CASE("Any with class method void string", "[any]")
{
test_struct test;

std::vector<void(test_struct::*)(std::string) const> methods
{
&test_struct::void_string,
&test_struct::void_string,
};

auto future = async::make_resolved_promise(str1).any(methods, &test).run();

REQUIRE_NOTHROW(future.get());
}


TEST_CASE("Any with class method error void string", "[any]")
{
test_struct test;

std::vector<void(test_struct::*)(std::string) const> methods
{
&test_struct::error_void_string,
&test_struct::void_string,
};

auto future = async::make_resolved_promise(str1).any(methods, &test).run();

REQUIRE_NOTHROW(future.get());
}


TEST_CASE("Any with class method all error void string", "[any]")
{
test_struct test;

std::vector<void(test_struct::*)(std::string) const> methods
{
&test_struct::error_void_string,
&test_struct::error_void_string,
};

auto future = async::make_resolved_promise(str1).any(methods, &test).run();

REQUIRE_THROWS_MATCHES(future.get(), async::aggregate_error, Catch::Matchers::Message(aggregate_error_message));
}


TEST_CASE("Any with class method string void", "[any]")
{
test_struct test;

std::vector<std::string(test_struct::*)() const> methods
{
&test_struct::string_void1,
&test_struct::string_void2,
};

auto future = async::make_resolved_promise().any(methods, &test).run();

std::string res;
REQUIRE_NOTHROW(res = future.get());
REQUIRE_THAT(res, Catch::Matchers::Equals(str1) || Catch::Matchers::Equals(str2));
}


TEST_CASE("Any with class method string void ignore arg", "[any]")
{
test_struct test;

std::vector<std::string(test_struct::*)() const> methods
{
&test_struct::string_void1,
&test_struct::string_void2,
};

auto future = async::make_resolved_promise(str1).any(methods, &test).run();

std::string res;
REQUIRE_NOTHROW(res = future.get());
REQUIRE_THAT(res, Catch::Matchers::Equals(str1) || Catch::Matchers::Equals(str2));
}


TEST_CASE("Any with class method error string void", "[any]")
{
test_struct test;

std::vector<std::string(test_struct::*)() const> methods
{
&test_struct::error_string_void,
&test_struct::string_void1,
};

auto future = async::make_resolved_promise().any(methods, &test).run();

std::string res;
REQUIRE_NOTHROW(res = future.get());
REQUIRE(res == str1);
}


TEST_CASE("Any with class method all error string void", "[any]")
{
test_struct test;

std::vector<std::string(test_struct::*)() const> methods
{
&test_struct::error_string_void,
&test_struct::error_string_void,
};

auto future = async::make_resolved_promise().any(methods, &test).run();
REQUIRE_THROWS_MATCHES(future.get(), async::aggregate_error, Catch::Matchers::Message(aggregate_error_message));
}


TEST_CASE("Any with class method string string", "[any]")
{
test_struct test;

std::vector<std::string(test_struct::*)(std::string) const> methods
{
&test_struct::string_string1,
&test_struct::string_string2,
};

auto future = async::make_resolved_promise(str1).any(methods, &test).run();

std::string res;
REQUIRE_NOTHROW(res = future.get());
REQUIRE_THAT(res, Catch::Matchers::Equals(str1) || Catch::Matchers::Equals(str2));
}


TEST_CASE("Any with class method error string string", "[any]")
{
test_struct test;

std::vector<std::string(test_struct::*)(std::string) const> methods
{
&test_struct::error_string_string,
&test_struct::string_string,
};

auto future = async::make_resolved_promise(str1).any(methods, &test).run();

std::string res;
REQUIRE_NOTHROW(res = future.get());
REQUIRE(res == str1);
}


TEST_CASE("Any with class method all error string string", "[any]")
{
test_struct test;

std::vector<std::string(test_struct::*)(std::string) const> methods
{
&test_struct::error_string_string,
&test_struct::error_string_string,
};

auto future = async::make_resolved_promise(str1).any(methods, &test).run();
REQUIRE_THROWS_MATCHES(future.get(), async::aggregate_error, Catch::Matchers::Message(aggregate_error_message));
}



TEST_CASE("Any with func void void", "[any]")
{
std::vector<void(*)()> funcs
{
Expand All @@ -41,7 +258,7 @@ TEST_CASE("Any void void", "[any]")
}


TEST_CASE("Any error void void", "[any]")
TEST_CASE("Any with func error void void", "[any]")
{
std::vector<void(*)()> funcs
{
Expand All @@ -55,7 +272,7 @@ TEST_CASE("Any error void void", "[any]")
}


TEST_CASE("Any all error void void", "[any]")
TEST_CASE("Any with func all error void void", "[any]")
{
std::vector<void(*)()> funcs
{
Expand All @@ -69,7 +286,7 @@ TEST_CASE("Any all error void void", "[any]")
}


TEST_CASE("Any void string", "[any]")
TEST_CASE("Any with func void string", "[any]")
{
std::vector<void(*)(std::string)> funcs
{
Expand All @@ -83,7 +300,7 @@ TEST_CASE("Any void string", "[any]")
}


TEST_CASE("Any error void string", "[any]")
TEST_CASE("Any with func error void string", "[any]")
{
std::vector<void(*)(std::string)> funcs
{
Expand All @@ -97,7 +314,7 @@ TEST_CASE("Any error void string", "[any]")
}


TEST_CASE("Any all error void string", "[any]")
TEST_CASE("Any with func all error void string", "[any]")
{
std::vector<void(*)(std::string)> funcs
{
Expand All @@ -111,7 +328,7 @@ TEST_CASE("Any all error void string", "[any]")
}


TEST_CASE("Any string void", "[any]")
TEST_CASE("Any with func string void", "[any]")
{
std::vector<std::string(*)()> funcs
{
Expand All @@ -127,7 +344,7 @@ TEST_CASE("Any string void", "[any]")
}


TEST_CASE("Any string void ignore arg", "[any]")
TEST_CASE("Any with func string void ignore arg", "[any]")
{
std::vector<std::string(*)()> funcs
{
Expand All @@ -143,7 +360,7 @@ TEST_CASE("Any string void ignore arg", "[any]")
}


TEST_CASE("Any error string void", "[any]")
TEST_CASE("Any with func error string void", "[any]")
{
std::vector<std::string(*)()> funcs
{
Expand All @@ -159,7 +376,7 @@ TEST_CASE("Any error string void", "[any]")
}


TEST_CASE("Any all error string void", "[any]")
TEST_CASE("Any with func all error string void", "[any]")
{
std::vector<std::string(*)()> funcs
{
Expand All @@ -172,7 +389,7 @@ TEST_CASE("Any all error string void", "[any]")
}


TEST_CASE("Any string string", "[any]")
TEST_CASE("Any with func string string", "[any]")
{
std::vector<std::string(*)(std::string)> funcs
{
Expand All @@ -188,7 +405,7 @@ TEST_CASE("Any string string", "[any]")
}


TEST_CASE("Any error string string", "[any]")
TEST_CASE("Any with func error string string", "[any]")
{
std::vector<std::string(*)(std::string)> funcs
{
Expand All @@ -204,7 +421,7 @@ TEST_CASE("Any error string string", "[any]")
}


TEST_CASE("Any all error string string", "[any]")
TEST_CASE("Any with func all error string string", "[any]")
{
std::vector<std::string(*)(std::string)> funcs
{
Expand Down
6 changes: 3 additions & 3 deletions tests/src/make_promise_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ TEST_CASE("Make all with class methods string string", "[make promise all]")

std::vector<std::string(test_struct::*)(std::string) const> methods
{
&test_struct::string_string,
&test_struct::string_string,
&test_struct::string_string1,
&test_struct::string_string2,
};

auto future = async::make_promise_all(methods, &test, str1).run();

std::vector<std::string> res;
REQUIRE_NOTHROW(res = future.get());
REQUIRE_THAT(res, Catch::Matchers::RangeEquals(std::vector<std::string>{str1, str1}));
REQUIRE_THAT(res, Catch::Matchers::RangeEquals(std::vector<std::string>{str1, str2}));
}


Expand Down
Loading

0 comments on commit 8c766cc

Please sign in to comment.