mirror of
https://github.com/Naios/continuable.git
synced 2026-02-08 10:46:40 +08:00
Split the base tests intro multiple files
This commit is contained in:
parent
6b9efad602
commit
f5e10d9fba
@ -4,7 +4,10 @@ foreach(STEP RANGE 4)
|
|||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/test-continuable.hpp
|
${CMAKE_CURRENT_LIST_DIR}/test-continuable.hpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/test-continuable-base.cpp
|
${CMAKE_CURRENT_LIST_DIR}/test-continuable-base-chaining.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/test-continuable-base-destruct.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/test-continuable-base-futurize.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/test-continuable-base-partial.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/test-continuable-connection-all.cpp
|
${CMAKE_CURRENT_LIST_DIR}/test-continuable-connection-all.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/test-continuable-connection-any.cpp
|
${CMAKE_CURRENT_LIST_DIR}/test-continuable-connection-any.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/test-continuable-connection-seq.cpp
|
${CMAKE_CURRENT_LIST_DIR}/test-continuable-connection-seq.cpp
|
||||||
|
|||||||
70
test/unit-test/test-continuable-base-chaining.cpp
Normal file
70
test/unit-test/test-continuable-base-chaining.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
Copyright(c) 2015 - 2017 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 "test-continuable.hpp"
|
||||||
|
|
||||||
|
using namespace cti;
|
||||||
|
using namespace cti::detail;
|
||||||
|
|
||||||
|
TYPED_TEST(single_dimension_tests, are_chainable) {
|
||||||
|
EXPECT_ASYNC_RESULT(this->supply().then([] {
|
||||||
|
return; // void
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Type chain
|
||||||
|
{
|
||||||
|
auto chain = this->supply().then([] { return tag1{}; });
|
||||||
|
ASSERT_ASYNC_TYPES(std::move(chain), tag1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pair chain
|
||||||
|
{
|
||||||
|
auto chain = this->supply().then([] {
|
||||||
|
// ...
|
||||||
|
return std::make_pair(tag1{}, tag2{});
|
||||||
|
});
|
||||||
|
ASSERT_ASYNC_TYPES(std::move(chain), tag1, tag2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tuple chain
|
||||||
|
{
|
||||||
|
auto chain = this->supply().then([] {
|
||||||
|
// ...
|
||||||
|
return std::make_tuple(tag1{}, tag2{}, tag3{});
|
||||||
|
});
|
||||||
|
ASSERT_ASYNC_TYPES(std::move(chain), tag1, tag2, tag3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erasing chain
|
||||||
|
{
|
||||||
|
auto chain = this->supply().then(this->supply(tag1{}));
|
||||||
|
ASSERT_ASYNC_TYPES(std::move(chain), tag1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Continuing chain
|
||||||
|
{
|
||||||
|
auto chain = this->supply().then([&] { return this->supply(tag1{}); });
|
||||||
|
|
||||||
|
ASSERT_ASYNC_TYPES(std::move(chain), tag1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -101,124 +101,3 @@ TYPED_TEST(single_dimension_tests, freeze_is_kept_across_the_chain) {
|
|||||||
ASSERT_TRUE(chain.is_frozen());
|
ASSERT_TRUE(chain.is_frozen());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST(single_dimension_tests, are_chainable) {
|
|
||||||
EXPECT_ASYNC_RESULT(this->supply().then([] {
|
|
||||||
return; // void
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Type chain
|
|
||||||
{
|
|
||||||
auto chain = this->supply().then([] { return tag1{}; });
|
|
||||||
ASSERT_ASYNC_TYPES(std::move(chain), tag1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pair chain
|
|
||||||
{
|
|
||||||
auto chain = this->supply().then([] {
|
|
||||||
// ...
|
|
||||||
return std::make_pair(tag1{}, tag2{});
|
|
||||||
});
|
|
||||||
ASSERT_ASYNC_TYPES(std::move(chain), tag1, tag2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tuple chain
|
|
||||||
{
|
|
||||||
auto chain = this->supply().then([] {
|
|
||||||
// ...
|
|
||||||
return std::make_tuple(tag1{}, tag2{}, tag3{});
|
|
||||||
});
|
|
||||||
ASSERT_ASYNC_TYPES(std::move(chain), tag1, tag2, tag3);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Erasing chain
|
|
||||||
{
|
|
||||||
auto chain = this->supply().then(this->supply(tag1{}));
|
|
||||||
ASSERT_ASYNC_TYPES(std::move(chain), tag1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Continuing chain
|
|
||||||
{
|
|
||||||
auto chain = this->supply().then([&] { return this->supply(tag1{}); });
|
|
||||||
|
|
||||||
ASSERT_ASYNC_TYPES(std::move(chain), tag1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef NO_FUTURE_TESTS
|
|
||||||
|
|
||||||
TYPED_TEST(single_dimension_tests, are_convertible_to_futures) {
|
|
||||||
auto is_ready = [](auto& future) {
|
|
||||||
// Check that the future is ready
|
|
||||||
return future.wait_for(std::chrono::seconds(0)) ==
|
|
||||||
std::future_status::ready;
|
|
||||||
};
|
|
||||||
|
|
||||||
{
|
|
||||||
auto future = this->supply().futurize();
|
|
||||||
ASSERT_TRUE(is_ready(future));
|
|
||||||
future.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto future = this->supply()
|
|
||||||
.then([] {
|
|
||||||
// ...
|
|
||||||
return 0xFD;
|
|
||||||
})
|
|
||||||
.futurize();
|
|
||||||
|
|
||||||
ASSERT_TRUE(is_ready(future));
|
|
||||||
EXPECT_EQ(future.get(), 0xFD);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto canary = std::make_tuple(0xFD, 0xF5);
|
|
||||||
|
|
||||||
auto future = this->supply()
|
|
||||||
.then([&] {
|
|
||||||
// ...
|
|
||||||
return canary;
|
|
||||||
})
|
|
||||||
.futurize();
|
|
||||||
|
|
||||||
ASSERT_TRUE(is_ready(future));
|
|
||||||
EXPECT_EQ(future.get(), canary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // NO_FUTURE_TESTS
|
|
||||||
|
|
||||||
TYPED_TEST(single_dimension_tests, are_partial_callable) {
|
|
||||||
EXPECT_ASYNC_RESULT(this->supply(1, 2).then([] {
|
|
||||||
// ...
|
|
||||||
}));
|
|
||||||
|
|
||||||
EXPECT_ASYNC_RESULT(this->supply(0xDF, 0xDD, 3, 4).then([](int a, int b) {
|
|
||||||
EXPECT_EQ(a, 0xDF);
|
|
||||||
EXPECT_EQ(b, 0xDD);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
TYPED_TEST(single_dimension_tests, are_dispatchable) {
|
|
||||||
{
|
|
||||||
bool invoked = false;
|
|
||||||
auto executor = [&](auto&& work) {
|
|
||||||
// We can move the worker object
|
|
||||||
auto local = std::forward<decltype(work)>(work);
|
|
||||||
ASSERT_FALSE(invoked);
|
|
||||||
// We can invoke the worker object
|
|
||||||
std::move(local)();
|
|
||||||
ASSERT_TRUE(invoked);
|
|
||||||
};
|
|
||||||
|
|
||||||
auto chain = this->supply().then(
|
|
||||||
[&] {
|
|
||||||
ASSERT_FALSE(invoked);
|
|
||||||
invoked = true;
|
|
||||||
},
|
|
||||||
executor);
|
|
||||||
|
|
||||||
ASSERT_ASYNC_COMPLETION(std::move(chain));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
71
test/unit-test/test-continuable-base-futurize.cpp
Normal file
71
test/unit-test/test-continuable-base-futurize.cpp
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
Copyright(c) 2015 - 2017 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 "test-continuable.hpp"
|
||||||
|
|
||||||
|
using namespace cti;
|
||||||
|
using namespace cti::detail;
|
||||||
|
|
||||||
|
#ifndef NO_FUTURE_TESTS
|
||||||
|
|
||||||
|
TYPED_TEST(single_dimension_tests, are_convertible_to_futures) {
|
||||||
|
auto is_ready = [](auto& future) {
|
||||||
|
// Check that the future is ready
|
||||||
|
return future.wait_for(std::chrono::seconds(0)) ==
|
||||||
|
std::future_status::ready;
|
||||||
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
auto future = this->supply().futurize();
|
||||||
|
ASSERT_TRUE(is_ready(future));
|
||||||
|
future.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto future = this->supply()
|
||||||
|
.then([] {
|
||||||
|
// ...
|
||||||
|
return 0xFD;
|
||||||
|
})
|
||||||
|
.futurize();
|
||||||
|
|
||||||
|
ASSERT_TRUE(is_ready(future));
|
||||||
|
EXPECT_EQ(future.get(), 0xFD);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto canary = std::make_tuple(0xFD, 0xF5);
|
||||||
|
|
||||||
|
auto future = this->supply()
|
||||||
|
.then([&] {
|
||||||
|
// ...
|
||||||
|
return canary;
|
||||||
|
})
|
||||||
|
.futurize();
|
||||||
|
|
||||||
|
ASSERT_TRUE(is_ready(future));
|
||||||
|
EXPECT_EQ(future.get(), canary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NO_FUTURE_TESTS
|
||||||
61
test/unit-test/test-continuable-base-partial.cpp
Normal file
61
test/unit-test/test-continuable-base-partial.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
Copyright(c) 2015 - 2017 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 "test-continuable.hpp"
|
||||||
|
|
||||||
|
using namespace cti;
|
||||||
|
using namespace cti::detail;
|
||||||
|
|
||||||
|
TYPED_TEST(single_dimension_tests, are_partial_callable) {
|
||||||
|
EXPECT_ASYNC_RESULT(this->supply(1, 2).then([] {
|
||||||
|
// ...
|
||||||
|
}));
|
||||||
|
|
||||||
|
EXPECT_ASYNC_RESULT(this->supply(0xDF, 0xDD, 3, 4).then([](int a, int b) {
|
||||||
|
EXPECT_EQ(a, 0xDF);
|
||||||
|
EXPECT_EQ(b, 0xDD);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(single_dimension_tests, are_dispatchable) {
|
||||||
|
{
|
||||||
|
bool invoked = false;
|
||||||
|
auto executor = [&](auto&& work) {
|
||||||
|
// We can move the worker object
|
||||||
|
auto local = std::forward<decltype(work)>(work);
|
||||||
|
ASSERT_FALSE(invoked);
|
||||||
|
// We can invoke the worker object
|
||||||
|
std::move(local)();
|
||||||
|
ASSERT_TRUE(invoked);
|
||||||
|
};
|
||||||
|
|
||||||
|
auto chain = this->supply().then(
|
||||||
|
[&] {
|
||||||
|
ASSERT_FALSE(invoked);
|
||||||
|
invoked = true;
|
||||||
|
},
|
||||||
|
executor);
|
||||||
|
|
||||||
|
ASSERT_ASYNC_COMPLETION(std::move(chain));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -195,10 +195,10 @@ struct provide_continuation_seq_right {
|
|||||||
// build time significantly.
|
// build time significantly.
|
||||||
using single_types = ::testing::Types<
|
using single_types = ::testing::Types<
|
||||||
#if UNIT_TEST_STEP == 0
|
#if UNIT_TEST_STEP == 0
|
||||||
provide_copyable,
|
provide_copyable
|
||||||
// provide_unique,
|
// provide_unique,
|
||||||
// provide_erasure<cti::continuable>,
|
// provide_erasure<cti::continuable>,
|
||||||
provide_erasure<cti::unique_continuable>
|
// provide_erasure<cti::unique_continuable>
|
||||||
#elif UNIT_TEST_STEP == 1
|
#elif UNIT_TEST_STEP == 1
|
||||||
// Some instantiations out commented for compilation speed reasons
|
// Some instantiations out commented for compilation speed reasons
|
||||||
// provide_continuation_and_left<provide_copyable>,
|
// provide_continuation_and_left<provide_copyable>,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user