Skip to content

Commit

Permalink
Class method call for any task added + tests refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanPinezhaninov committed Dec 28, 2023
1 parent 8c766cc commit 7856e19
Show file tree
Hide file tree
Showing 24 changed files with 1,460 additions and 635 deletions.
458 changes: 408 additions & 50 deletions include/async_promise.hpp

Large diffs are not rendered by default.

82 changes: 37 additions & 45 deletions tests/src/all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,93 +15,85 @@
**
******************************************************************************/

// async_promise
#include <async_promise.hpp>

// catch2
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_exception.hpp>
#include <catch2/matchers/catch_matchers_range_equals.hpp>

// local
#include "common.h"


TEST_CASE("All with class method void void", "[all]")
{
test_struct test;
test_struct obj;

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

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

REQUIRE_NOTHROW(future.get());
}


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

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

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

REQUIRE_THROWS_MATCHES(future.get(), std::runtime_error, Catch::Matchers::Message(str2));
}


TEST_CASE("All with class method void string", "[all]")
{
test_struct test;
test_struct obj;

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

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

REQUIRE_NOTHROW(future.get());
}


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

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

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

REQUIRE_THROWS_MATCHES(future.get(), std::runtime_error, Catch::Matchers::Message(str2));
}


TEST_CASE("All with class method string void", "[all]")
{
test_struct test;
test_struct obj;

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

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

std::vector<std::string> res;
REQUIRE_NOTHROW(res = future.get());
Expand All @@ -111,15 +103,15 @@ TEST_CASE("All with class method string void", "[all]")

TEST_CASE("All with class method string void ignore arg", "[all]")
{
test_struct test;
test_struct obj;

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

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

std::vector<std::string> res;
REQUIRE_NOTHROW(res = future.get());
Expand All @@ -129,15 +121,15 @@ TEST_CASE("All with class method string void ignore arg", "[all]")

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

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

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

std::vector<std::string> res;
REQUIRE_THROWS_MATCHES(res = future.get(), std::runtime_error, Catch::Matchers::Message(str2));
Expand All @@ -147,15 +139,15 @@ TEST_CASE("All with class method error string void", "[all]")

TEST_CASE("All with class method string string", "[all]")
{
test_struct test;
test_struct obj;

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).all(methods, &test).run();
auto future = async::make_resolved_promise(str1).all(methods, &obj).run();

std::vector<std::string> res;
REQUIRE_NOTHROW(res = future.get());
Expand All @@ -165,15 +157,15 @@ TEST_CASE("All with class method string string", "[all]")

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

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

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

std::vector<std::string> res;
REQUIRE_THROWS_MATCHES(res = future.get(), std::runtime_error, Catch::Matchers::Message(str2));
Expand All @@ -186,8 +178,8 @@ TEST_CASE("All with function void void", "[all]")
{
std::vector<void(*)()> funcs
{
[] () {},
[] () {},
void_void,
void_void,
};

auto future = async::make_resolved_promise().all(funcs).run();
Expand All @@ -200,8 +192,8 @@ TEST_CASE("All with function error void void", "[all]")
{
std::vector<void(*)()> funcs
{
[] () {},
[] () { throw std::runtime_error{str2}; },
void_void,
error_void_void,
};

auto future = async::make_resolved_promise().all(funcs).run();
Expand All @@ -214,8 +206,8 @@ TEST_CASE("All with function void string", "[all]")
{
std::vector<void(*)(std::string)> funcs
{
[] (std::string) {},
[] (std::string) {},
void_string,
void_string,
};

auto future = async::make_resolved_promise(str1).all(funcs).run();
Expand All @@ -228,8 +220,8 @@ TEST_CASE("All with function error void string", "[all]")
{
std::vector<void(*)(std::string)> funcs
{
[] (std::string) {},
[] (std::string) { throw std::runtime_error{str2}; },
void_string,
error_void_string,
};

auto future = async::make_resolved_promise(str1).all(funcs).run();
Expand All @@ -242,8 +234,8 @@ TEST_CASE("All with function string void", "[all]")
{
std::vector<std::string(*)()> funcs
{
[] () { return std::string{str1}; },
[] () { return std::string{str2}; },
string_void1,
string_void2,
};

auto future = async::make_resolved_promise().all(funcs).run();
Expand All @@ -258,8 +250,8 @@ TEST_CASE("All with function string void ignore arg", "[all]")
{
std::vector<std::string(*)()> funcs
{
[] () { return std::string{str1}; },
[] () { return std::string{str2}; },
string_void1,
string_void2,
};

auto future = async::make_resolved_promise(str1).all(funcs).run();
Expand All @@ -274,8 +266,8 @@ TEST_CASE("All with function error string void", "[all]")
{
std::vector<std::string(*)()> funcs
{
[] () { return std::string{str1}; },
[] () -> std::string { throw std::runtime_error{str2}; },
string_void1,
error_string_void,
};

auto future = async::make_resolved_promise().all(funcs).run();
Expand All @@ -290,8 +282,8 @@ TEST_CASE("All with function string string", "[all]")
{
std::vector<std::string(*)(std::string)> funcs
{
[] (std::string str) { return std::string{str1}; },
[] (std::string str) { return std::string{str2}; },
string_string1,
string_string2,
};

auto future = async::make_resolved_promise(str1).all(funcs).run();
Expand All @@ -306,8 +298,8 @@ TEST_CASE("All with function error string string", "[all]")
{
std::vector<std::string(*)(std::string)> funcs
{
[] (std::string str) { return std::string{str1}; },
[] (std::string str) -> std::string { throw std::runtime_error{str2}; },
string_string1,
error_string_string,
};

auto future = async::make_resolved_promise(str1).all(funcs).run();
Expand Down
Loading

0 comments on commit 7856e19

Please sign in to comment.