From 813ed0878dd149d9521f75d865049ad7c7418a7a Mon Sep 17 00:00:00 2001 From: Yuan Yao Date: Sat, 21 May 2022 17:01:56 +0800 Subject: [PATCH] Add handler invocation tests --- .../async/test-continuable-async.cpp | 72 ++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/test/unit-test/async/test-continuable-async.cpp b/test/unit-test/async/test-continuable-async.cpp index dc235b3..a46ca0e 100644 --- a/test/unit-test/async/test-continuable-async.cpp +++ b/test/unit-test/async/test-continuable-async.cpp @@ -205,4 +205,74 @@ TYPED_TEST(single_dimension_tests, wait_test_issue_46) { .apply(cti::transforms::wait()); ASSERT_TRUE(handled); -} \ No newline at end of file +} + +TYPED_TEST(single_dimension_tests, then_after_nonvoid_fail_handler_invoked) { + bool invoked = false; + make_exceptional_continuable(supply_test_exception()) + .fail([]{ + return 1; + }) + .then([&]{ + EXPECT_FALSE(invoked); + invoked = true; + }); + + ASSERT_TRUE(invoked); + } + + TYPED_TEST(single_dimension_tests, then_after_void_fail_handler_invoked) { + bool invoked = false; + make_exceptional_continuable(supply_test_exception()) + .fail([]{ + return; + }) + .then([&]{ + EXPECT_FALSE(invoked); + invoked = true; + }); + + ASSERT_TRUE(invoked); + } + + TYPED_TEST(single_dimension_tests, scoped_fail_handler_not_invoked) { + bool invoked1 = false; + bool invoked2 = false; + make_exceptional_continuable(supply_test_exception()) + .fail([&]{ + EXPECT_FALSE(invoked1); + invoked1 = true; + return; + }) + .then([]{ + return; + }) + .fail([&]{ + EXPECT_FALSE(invoked2); + invoked2 = true; + }); + + ASSERT_TRUE(invoked1); + ASSERT_FALSE(invoked2); + } + + TYPED_TEST(single_dimension_tests, scoped_fail_handler_invoked) { + bool invoked1 = false; + bool invoked2 = false; + make_exceptional_continuable(supply_test_exception()) + .fail([&]{ + EXPECT_FALSE(invoked1); + invoked1 = true; + return; + }) + .then([]{ + std::rethrow_exception(supply_test_exception()); + }) + .fail([&]{ + EXPECT_FALSE(invoked2); + invoked2 = true; + }); + + ASSERT_TRUE(invoked1); + ASSERT_TRUE(invoked2); + } \ No newline at end of file