diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index 00c1d69..cf99c76 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -43,7 +43,8 @@ foreach(STEP RANGE 4) ${CMAKE_CURRENT_LIST_DIR}/multi/test-continuable-base-destruct.cpp ${CMAKE_CURRENT_LIST_DIR}/multi/test-continuable-base-errors.cpp ${CMAKE_CURRENT_LIST_DIR}/multi/test-continuable-base-partial.cpp - ${CMAKE_CURRENT_LIST_DIR}/multi/test-continuable-connection-all-seq.hpp + ${CMAKE_CURRENT_LIST_DIR}/multi/test-continuable-connection-all-seq-ag.cpp + ${CMAKE_CURRENT_LIST_DIR}/multi/test-continuable-connection-all-seq-op.cpp ${CMAKE_CURRENT_LIST_DIR}/multi/test-continuable-connection-all.cpp ${CMAKE_CURRENT_LIST_DIR}/multi/test-continuable-connection-any.cpp ${CMAKE_CURRENT_LIST_DIR}/multi/test-continuable-connection-seq.cpp diff --git a/test/unit-test/multi/test-continuable-connection-all-seq-ag.cpp b/test/unit-test/multi/test-continuable-connection-all-seq-ag.cpp new file mode 100644 index 0000000..5c8be58 --- /dev/null +++ b/test/unit-test/multi/test-continuable-connection-all-seq-ag.cpp @@ -0,0 +1,64 @@ + +/* + Copyright(c) 2015 - 2018 Denis Blank + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files(the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and / or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions : + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + 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. +**/ + +#include +#include +#include + +#include + +class non_default_constructible { +public: + explicit non_default_constructible(int) { + } +}; + +TYPED_TEST(single_aggregate_tests, is_logical_seq_connectable_three_tags) { + auto chain = + this->ag(this->supply(1, 2), this->supply(3, 4), this->supply(5, 6)); + EXPECT_ASYNC_RESULT(std::move(chain), 1, 2, 3, 4, 5, 6); +} + +TYPED_TEST(single_aggregate_tests, is_logical_connectable_nested) { + auto chain = this->ag( + std::make_tuple(this->supply(1, 2), std::make_tuple(this->supply(3, 4))), + this->supply(5, 6)); + EXPECT_ASYNC_RESULT(std::move(chain), + std::make_tuple(1, 2, std::make_tuple(3, 4)), 5, 6); +} + +TYPED_TEST(single_aggregate_tests, is_logical_connectable_nested_dyn) { + auto chain = this->ag(std::make_tuple(cti::populate( + this->supply(1, 2), this->supply(3, 4), this->supply(5, 6)))); + EXPECT_ASYNC_RESULT(std::move(chain), + std::make_tuple(std::vector>{ + {1, 2}, {3, 4}, {5, 6}})); +} + +TYPED_TEST(single_aggregate_tests, is_logical_connectable_non_default) { + auto chain = + this->ag(this->supply(1, 2), this->supply(non_default_constructible{1}), + this->supply(5, 6)); + ASSERT_ASYNC_TYPES(std::move(chain), int, int, non_default_constructible, int, + int); +} diff --git a/test/unit-test/multi/test-continuable-connection-all-seq-op.cpp b/test/unit-test/multi/test-continuable-connection-all-seq-op.cpp new file mode 100644 index 0000000..9590c71 --- /dev/null +++ b/test/unit-test/multi/test-continuable-connection-all-seq-op.cpp @@ -0,0 +1,48 @@ + +/* + Copyright(c) 2015 - 2018 Denis Blank + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files(the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and / or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions : + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + 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. +**/ + +#include +#include +#include + +#include + +TYPED_TEST(single_aggregate_tests, is_logical_connectable) { + auto chain = this->op(this->supply(), this->supply()); + EXPECT_ASYNC_RESULT(std::move(chain)); +} + +TYPED_TEST(single_aggregate_tests, is_logical_seq_connectable_value) { + auto chain = this->op(this->supply(1), this->supply(2)); + EXPECT_ASYNC_RESULT(std::move(chain), 1, 2); +} + +TYPED_TEST(single_aggregate_tests, is_logical_seq_connectable_duplicated_val) { + auto chain = this->op(this->supply(1, 2), this->supply(3, 4, 5)); + EXPECT_ASYNC_RESULT(std::move(chain), 1, 2, 3, 4, 5); +} + +TYPED_TEST(single_aggregate_tests, is_logical_seq_connectable_tag) { + auto chain = this->op(this->supply(tag1{}), this->supply(tag2{}, tag3{})); + ASSERT_ASYNC_TYPES(std::move(chain), tag1, tag2, tag3); +} diff --git a/test/unit-test/multi/test-continuable-connection-all-seq.hpp b/test/unit-test/multi/test-continuable-connection-all-seq.hpp deleted file mode 100644 index f91190b..0000000 --- a/test/unit-test/multi/test-continuable-connection-all-seq.hpp +++ /dev/null @@ -1,93 +0,0 @@ - -/* - Copyright(c) 2015 - 2018 Denis Blank - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files(the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and / or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions : - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - 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. -**/ - -#ifndef TEST_CONTINUABLE_CONNECTION_HPP__ -#define TEST_CONTINUABLE_CONNECTION_HPP__ - -#include -#include -#include - -#include - -template -void test_all_seq_op(Supplier&& supply, OperatorConnector&& op) { - { - auto chain = op(supply(), supply()); - EXPECT_ASYNC_RESULT(std::move(chain)); - } - - { - auto chain = op(supply(1), supply(2)); - EXPECT_ASYNC_RESULT(std::move(chain), 1, 2); - } - - { - auto chain = op(supply(1, 2), supply(3, 4, 5)); - EXPECT_ASYNC_RESULT(std::move(chain), 1, 2, 3, 4, 5); - } - - { - auto chain = op(supply(tag1{}), supply(tag2{}, tag3{})); - ASSERT_ASYNC_TYPES(std::move(chain), tag1, tag2, tag3); - } -} - -class non_default_constructible { -public: - explicit non_default_constructible(int) { - } -}; - -template -void test_all_seq_aggregate(Supplier&& supply, AggregateConnector&& ag) { - { - auto chain = ag(supply(1, 2), supply(3, 4), supply(5, 6)); - EXPECT_ASYNC_RESULT(std::move(chain), 1, 2, 3, 4, 5, 6); - } - - { - auto chain = - ag(std::make_tuple(supply(1, 2), std::make_tuple(supply(3, 4))), - supply(5, 6)); - EXPECT_ASYNC_RESULT(std::move(chain), - std::make_tuple(1, 2, std::make_tuple(3, 4)), 5, 6); - } - - { - auto chain = ag(std::make_tuple( - cti::populate(supply(1, 2), supply(3, 4), supply(5, 6)))); - EXPECT_ASYNC_RESULT(std::move(chain), - std::make_tuple(std::vector>{ - {1, 2}, {3, 4}, {5, 6}})); - } - - { - auto chain = - ag(supply(1, 2), supply(non_default_constructible{1}), supply(5, 6)); - ASSERT_ASYNC_TYPES(std::move(chain), int, int, non_default_constructible, - int, int); - } -} - -#endif // TEST_CONTINUABLE_CONNECTION_HPP__ diff --git a/test/unit-test/multi/test-continuable-connection-all.cpp b/test/unit-test/multi/test-continuable-connection-all.cpp index 6e5a504..02eed57 100644 --- a/test/unit-test/multi/test-continuable-connection-all.cpp +++ b/test/unit-test/multi/test-continuable-connection-all.cpp @@ -21,30 +21,8 @@ SOFTWARE. **/ -#include #include -TYPED_TEST(single_dimension_tests, is_op_all_connectable) { - test_all_seq_op( - [this](auto&&... args) { - return this->supply(std::forward(args)...); - }, - [](auto&& left, auto&& right) { - return std::forward(left) && - std::forward(right); - }); -} - -TYPED_TEST(single_dimension_tests, is_aggregate_all_connectable) { - test_all_seq_aggregate( - [this](auto&&... args) { - return this->supply(std::forward(args)...); - }, - [](auto&&... args) { - return cti::when_all(std::forward(args)...); - }); -} - TYPED_TEST(single_dimension_tests, is_logical_all_connectable) { { diff --git a/test/unit-test/multi/test-continuable-connection-seq.cpp b/test/unit-test/multi/test-continuable-connection-seq.cpp index f6810d0..fdcad86 100644 --- a/test/unit-test/multi/test-continuable-connection-seq.cpp +++ b/test/unit-test/multi/test-continuable-connection-seq.cpp @@ -21,30 +21,8 @@ SOFTWARE. **/ -#include #include -TYPED_TEST(single_dimension_tests, is_op_seq_connectable) { - test_all_seq_op( - [this](auto&&... args) { - return this->supply(std::forward(args)...); - }, - [](auto&& left, auto&& right) { - return std::forward(left) >> - std::forward(right); - }); -} - -TYPED_TEST(single_dimension_tests, is_aggregate_seq_connectable) { - test_all_seq_aggregate( - [this](auto&&... args) { - return this->supply(std::forward(args)...); - }, - [](auto&&... args) { - return cti::when_seq(std::forward(args)...); - }); -} - TYPED_TEST(single_dimension_tests, is_logical_seq_connectable_composed) { // Check the evaluation order unsigned i = 0; diff --git a/test/unit-test/test-continuable.hpp b/test/unit-test/test-continuable.hpp index edcf8db..768d343 100644 --- a/test/unit-test/test-continuable.hpp +++ b/test/unit-test/test-continuable.hpp @@ -162,7 +162,7 @@ struct provide_continuation_seq_right { // clang-format off // Feel free to uncomment more tests, however this will increase the // build time significantly. -using single_types = ::testing::Types< +using single_types_id = identity< #if UNIT_TEST_STEP == 0 provide_copyable // provide_erasure, @@ -188,6 +188,13 @@ using single_types = ::testing::Types< >; // clang-format on +template +struct to_types; +template +struct to_types> : std::common_type<::testing::Types> {}; + +using single_types = to_types::type; + struct tag1 {}; struct tag2 {}; struct tag3 {}; @@ -197,6 +204,47 @@ struct single_dimension_tests : continuation_provider {}; TYPED_TEST_CASE(single_dimension_tests, single_types); +template +struct combine_to_type; +template +struct combine_to_type, First, Second> + : std::common_type..., // ... + identity...>> {}; + +struct all_connector { + template + auto op(Left&& left, Right&& right) const { + return std::forward(left) && std::forward(right); + } + + template + auto ag(Args&&... args) const { + return cti::when_all(std::forward(args)...); + } +}; +struct seq_connector { + template + auto op(Left&& left, Right&& right) const { + return std::forward(left) >> std::forward(right); + } + + template + auto ag(Args&&... args) const { + return cti::when_seq(std::forward(args)...); + } +}; + +using aggregate_types = + combine_to_type::type; + +template +struct single_aggregate_tests; +template +struct single_aggregate_tests> + : continuation_provider, Connector {}; + +TYPED_TEST_CASE(single_aggregate_tests, aggregate_types); + template auto make_step(T* me, unsigned& current, unsigned step) { return me->invoke([=]() mutable {