Skip to content

Commit

Permalink
Class method call for initial and then tasks added
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanPinezhaninov committed Dec 24, 2023
1 parent 7648887 commit ebb2df1
Show file tree
Hide file tree
Showing 12 changed files with 632 additions and 90 deletions.
288 changes: 230 additions & 58 deletions include/async_promise.hpp

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ include(Catch)

set(HEADERS
src/common.h
src/funcs.h
src/test_funcs.h
src/test_struct.h
)

set(SOURCES
src/all_settled.cpp
src/all.cpp
src/any.cpp
src/class_initial.cpp
src/class_then.cpp
src/fail.cpp
src/finally.cpp
src/funcs.cpp
src/initial.cpp
src/func_initial.cpp
src/func_then.cpp
src/make_all_settled.cpp
src/make_all.cpp
src/make_any.cpp
Expand All @@ -56,7 +59,8 @@ set(SOURCES
src/race.cpp
src/settled.cpp
src/smoke.cpp
src/then.cpp
src/test_funcs.cpp
src/test_struct.cpp
)

set(TARGET async_promise_tests)
Expand Down
104 changes: 104 additions & 0 deletions tests/src/class_initial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/******************************************************************************
**
** Copyright (C) 2023 Ivan Pinezhaninov <[email protected]>
**
** This file is part of the async_promise project - which can be found at
** https://github.com/IvanPinezhaninov/async_promise/.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
******************************************************************************/

// async_promise
#include <async_promise.hpp>

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

// local
#include "test_struct.h"

static constexpr auto str = "Hello World!";


TEST_CASE("Class initial void void", "[initial]")
{
test_struct test;
auto future = async::promise<void>{&test_struct::void_void, &test}.run();

REQUIRE_NOTHROW(future.get());
}


TEST_CASE("Class initial error void void", "[initial]")
{
test_struct test;
auto future = async::promise<void>{&test_struct::error_void_void, &test}.run();

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


TEST_CASE("Class initial void string", "[initial]")
{
test_struct test;
auto future = async::promise<void>{&test_struct::void_string, &test, str}.run();

REQUIRE_NOTHROW(future.get());
}


TEST_CASE("Class initial error void string", "[initial]")
{
test_struct test;
auto future = async::promise<void>{&test_struct::error_void_string, &test, str}.run();

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


TEST_CASE("Class initial string void", "[initial]")
{
test_struct test;
auto future = async::promise<std::string>{&test_struct::string_void, &test}.run();

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


TEST_CASE("Class initial error string void", "[initial]")
{
test_struct test;
auto future = async::promise<std::string>{&test_struct::error_string_void, &test}.run();

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


TEST_CASE("Class initial string string", "[initial]")
{
test_struct test;
auto future = async::promise<std::string>{&test_struct::string_string, &test, str}.run();

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


TEST_CASE("Class initial error string string", "[initial]")
{
test_struct test;
auto future = async::promise<std::string>{&test_struct::error_string_string, &test, str}.run();

REQUIRE_THROWS_MATCHES(future.get(), std::runtime_error, Catch::Matchers::Message(str));
}
142 changes: 142 additions & 0 deletions tests/src/class_then.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/******************************************************************************
**
** Copyright (C) 2023 Ivan Pinezhaninov <[email protected]>
**
** This file is part of the async_promise project - which can be found at
** https://github.com/IvanPinezhaninov/async_promise/.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
******************************************************************************/

// async_promise
#include <async_promise.hpp>

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

// local
#include "test_struct.h"

static constexpr auto str = "Hello World!";


TEST_CASE("Class then void void", "[then]")
{
test_struct test;
auto future = async::make_resolved_promise().then(&test_struct::void_void, &test).run();

REQUIRE_NOTHROW(future.get());
}


TEST_CASE("Class then error void void", "[then]")
{
test_struct test;
auto future = async::make_resolved_promise().then(&test_struct::error_void_void, &test).run();

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


TEST_CASE("Class then void void ignore arg", "[then]")
{
test_struct test;
auto future = async::make_resolved_promise(str).then(&test_struct::void_void, &test).run();

REQUIRE_NOTHROW(future.get());
}


TEST_CASE("Class then error void void ignore arg", "[then]")
{
test_struct test;
auto future = async::make_resolved_promise(str).then(&test_struct::error_void_void, &test).run();

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


TEST_CASE("Class then void string", "[then]")
{
test_struct test;
auto future = async::make_resolved_promise(str).then(&test_struct::void_string, &test).run();

REQUIRE_NOTHROW(future.get());
}


TEST_CASE("Class then error void string", "[then]")
{
test_struct test;
auto future = async::make_resolved_promise(str).then(&test_struct::error_void_string, &test).run();

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


TEST_CASE("Class then string void", "[then]")
{
test_struct test;
auto future = async::make_resolved_promise().then(&test_struct::string_void, &test).run();

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


TEST_CASE("Class then error string void", "[then]")
{
test_struct test;
auto future = async::make_resolved_promise().then(&test_struct::error_string_void, &test).run();

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


TEST_CASE("Class then string void ignore arg", "[then]")
{
test_struct test;
auto future = async::make_resolved_promise(str).then(&test_struct::string_void, &test).run();

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


TEST_CASE("Class then error string void ignore arg", "[then]")
{
test_struct test;
auto future = async::make_resolved_promise(str).then(&test_struct::error_string_void, &test).run();

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


TEST_CASE("Class then string string", "[then]")
{
test_struct test;
auto future = async::make_resolved_promise(str).then(&test_struct::string_string, &test).run();

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


TEST_CASE("Class then error string string", "[then]")
{
test_struct test;
auto future = async::make_resolved_promise(str).then(&test_struct::error_string_string, &test).run();

REQUIRE_THROWS_MATCHES(future.get(), std::runtime_error, Catch::Matchers::Message(str));
}
2 changes: 1 addition & 1 deletion tests/src/fail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <catch2/catch_test_macros.hpp>

// local
#include "funcs.h"
#include "test_funcs.h"

static constexpr auto str = "Hello World!";

Expand Down
2 changes: 1 addition & 1 deletion tests/src/finally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <catch2/catch_test_macros.hpp>

// local
#include "funcs.h"
#include "test_funcs.h"

static constexpr auto str = "Hello World!";

Expand Down
18 changes: 9 additions & 9 deletions tests/src/initial.cpp → tests/src/func_initial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,44 @@
#include <catch2/catch_test_macros.hpp>

// local
#include "funcs.h"
#include "test_funcs.h"

static constexpr auto str = "Hello World!";


TEST_CASE("Initial void void", "[initial]")
TEST_CASE("Func initial void void", "[initial]")
{
auto future = async::promise<void>{void_void}.run();

REQUIRE_NOTHROW(future.get());
}


TEST_CASE("Initial error void void", "[initial]")
TEST_CASE("Func initial error void void", "[initial]")
{
auto future = async::promise<void>{error_void_void}.run();

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


TEST_CASE("Initial void string", "[initial]")
TEST_CASE("Func initial void string", "[initial]")
{
auto future = async::promise<void>{void_string, str}.run();

REQUIRE_NOTHROW(future.get());
}


TEST_CASE("Initial error void string", "[initial]")
TEST_CASE("Func initial error void string", "[initial]")
{
auto future = async::promise<void>{error_void_string, str}.run();

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


TEST_CASE("Initial string void", "[initial]")
TEST_CASE("Func initial string void", "[initial]")
{
auto future = async::promise<std::string>{string_void}.run();

Expand All @@ -70,15 +70,15 @@ TEST_CASE("Initial string void", "[initial]")
}


TEST_CASE("Initial error string void", "[initial]")
TEST_CASE("Func initial error string void", "[initial]")
{
auto future = async::promise<std::string>{error_string_void}.run();

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


TEST_CASE("Initial string string", "[initial]")
TEST_CASE("Func initial string string", "[initial]")
{
auto future = async::promise<std::string>{string_string, str}.run();

Expand All @@ -88,7 +88,7 @@ TEST_CASE("Initial string string", "[initial]")
}


TEST_CASE("Initial error string string", "[initial]")
TEST_CASE("Func initial error string string", "[initial]")
{
auto future = async::promise<std::string>{error_string_string, str}.run();

Expand Down
Loading

0 comments on commit ebb2df1

Please sign in to comment.