mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
Convert the seq and all tests into typed tests
* Hopefully this fixes the GCC virtual memory errors
This commit is contained in:
parent
c72d1afa8b
commit
b5571c5ee1
@ -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
|
||||
|
||||
@ -0,0 +1,64 @@
|
||||
|
||||
/*
|
||||
Copyright(c) 2015 - 2018 Denis Blank <denis.blank at outlook dot com>
|
||||
|
||||
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 <tuple>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include <test-continuable.hpp>
|
||||
|
||||
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<std::tuple<int, int>>{
|
||||
{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);
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
|
||||
/*
|
||||
Copyright(c) 2015 - 2018 Denis Blank <denis.blank at outlook dot com>
|
||||
|
||||
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 <tuple>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include <test-continuable.hpp>
|
||||
|
||||
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);
|
||||
}
|
||||
@ -1,93 +0,0 @@
|
||||
|
||||
/*
|
||||
Copyright(c) 2015 - 2018 Denis Blank <denis.blank at outlook dot com>
|
||||
|
||||
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 <tuple>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include <test-continuable.hpp>
|
||||
|
||||
template <typename Supplier, typename OperatorConnector>
|
||||
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 <typename Supplier, typename AggregateConnector>
|
||||
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<std::tuple<int, int>>{
|
||||
{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__
|
||||
@ -21,30 +21,8 @@
|
||||
SOFTWARE.
|
||||
**/
|
||||
|
||||
#include <test-continuable-connection-all-seq.hpp>
|
||||
#include <test-continuable.hpp>
|
||||
|
||||
TYPED_TEST(single_dimension_tests, is_op_all_connectable) {
|
||||
test_all_seq_op(
|
||||
[this](auto&&... args) {
|
||||
return this->supply(std::forward<decltype(args)>(args)...);
|
||||
},
|
||||
[](auto&& left, auto&& right) {
|
||||
return std::forward<decltype(left)>(left) &&
|
||||
std::forward<decltype(right)>(right);
|
||||
});
|
||||
}
|
||||
|
||||
TYPED_TEST(single_dimension_tests, is_aggregate_all_connectable) {
|
||||
test_all_seq_aggregate(
|
||||
[this](auto&&... args) {
|
||||
return this->supply(std::forward<decltype(args)>(args)...);
|
||||
},
|
||||
[](auto&&... args) {
|
||||
return cti::when_all(std::forward<decltype(args)>(args)...);
|
||||
});
|
||||
}
|
||||
|
||||
TYPED_TEST(single_dimension_tests, is_logical_all_connectable) {
|
||||
|
||||
{
|
||||
|
||||
@ -21,30 +21,8 @@
|
||||
SOFTWARE.
|
||||
**/
|
||||
|
||||
#include <test-continuable-connection-all-seq.hpp>
|
||||
#include <test-continuable.hpp>
|
||||
|
||||
TYPED_TEST(single_dimension_tests, is_op_seq_connectable) {
|
||||
test_all_seq_op(
|
||||
[this](auto&&... args) {
|
||||
return this->supply(std::forward<decltype(args)>(args)...);
|
||||
},
|
||||
[](auto&& left, auto&& right) {
|
||||
return std::forward<decltype(left)>(left) >>
|
||||
std::forward<decltype(right)>(right);
|
||||
});
|
||||
}
|
||||
|
||||
TYPED_TEST(single_dimension_tests, is_aggregate_seq_connectable) {
|
||||
test_all_seq_aggregate(
|
||||
[this](auto&&... args) {
|
||||
return this->supply(std::forward<decltype(args)>(args)...);
|
||||
},
|
||||
[](auto&&... args) {
|
||||
return cti::when_seq(std::forward<decltype(args)>(args)...);
|
||||
});
|
||||
}
|
||||
|
||||
TYPED_TEST(single_dimension_tests, is_logical_seq_connectable_composed) {
|
||||
// Check the evaluation order
|
||||
unsigned i = 0;
|
||||
|
||||
@ -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<cti::continuable>,
|
||||
@ -188,6 +188,13 @@ using single_types = ::testing::Types<
|
||||
>;
|
||||
// clang-format on
|
||||
|
||||
template <typename T>
|
||||
struct to_types;
|
||||
template <typename... T>
|
||||
struct to_types<identity<T...>> : std::common_type<::testing::Types<T...>> {};
|
||||
|
||||
using single_types = to_types<single_types_id>::type;
|
||||
|
||||
struct tag1 {};
|
||||
struct tag2 {};
|
||||
struct tag3 {};
|
||||
@ -197,6 +204,47 @@ struct single_dimension_tests : continuation_provider<Provider> {};
|
||||
|
||||
TYPED_TEST_CASE(single_dimension_tests, single_types);
|
||||
|
||||
template <typename T, typename First, typename Second>
|
||||
struct combine_to_type;
|
||||
template <typename... T, typename First, typename Second>
|
||||
struct combine_to_type<identity<T...>, First, Second>
|
||||
: std::common_type<testing::Types<identity<T, First>..., // ...
|
||||
identity<T, Second>...>> {};
|
||||
|
||||
struct all_connector {
|
||||
template <typename Left, typename Right>
|
||||
auto op(Left&& left, Right&& right) const {
|
||||
return std::forward<Left>(left) && std::forward<Right>(right);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
auto ag(Args&&... args) const {
|
||||
return cti::when_all(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
struct seq_connector {
|
||||
template <typename Left, typename Right>
|
||||
auto op(Left&& left, Right&& right) const {
|
||||
return std::forward<Left>(left) >> std::forward<Right>(right);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
auto ag(Args&&... args) const {
|
||||
return cti::when_seq(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
using aggregate_types =
|
||||
combine_to_type<single_types_id, all_connector, seq_connector>::type;
|
||||
|
||||
template <typename Identity>
|
||||
struct single_aggregate_tests;
|
||||
template <typename Provider, typename Connector>
|
||||
struct single_aggregate_tests<identity<Provider, Connector>>
|
||||
: continuation_provider<Provider>, Connector {};
|
||||
|
||||
TYPED_TEST_CASE(single_aggregate_tests, aggregate_types);
|
||||
|
||||
template <typename T>
|
||||
auto make_step(T* me, unsigned& current, unsigned step) {
|
||||
return me->invoke([=]() mutable {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user