diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index f7f3c74..83f2535 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -4,7 +4,10 @@ foreach(STEP RANGE 4) add_executable(${PROJECT_NAME} ${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-any.cpp ${CMAKE_CURRENT_LIST_DIR}/test-continuable-connection-seq.cpp diff --git a/test/unit-test/test-continuable-base-chaining.cpp b/test/unit-test/test-continuable-base-chaining.cpp new file mode 100644 index 0000000..c5714c9 --- /dev/null +++ b/test/unit-test/test-continuable-base-chaining.cpp @@ -0,0 +1,70 @@ + +/** + Copyright(c) 2015 - 2017 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 "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); + } +} diff --git a/test/unit-test/test-continuable-base.cpp b/test/unit-test/test-continuable-base-destruct.cpp similarity index 53% rename from test/unit-test/test-continuable-base.cpp rename to test/unit-test/test-continuable-base-destruct.cpp index fced99d..6f413c7 100644 --- a/test/unit-test/test-continuable-base.cpp +++ b/test/unit-test/test-continuable-base-destruct.cpp @@ -101,124 +101,3 @@ TYPED_TEST(single_dimension_tests, freeze_is_kept_across_the_chain) { 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(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)); - } -} diff --git a/test/unit-test/test-continuable-base-futurize.cpp b/test/unit-test/test-continuable-base-futurize.cpp new file mode 100644 index 0000000..c5f237e --- /dev/null +++ b/test/unit-test/test-continuable-base-futurize.cpp @@ -0,0 +1,71 @@ + +/** + Copyright(c) 2015 - 2017 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 "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 diff --git a/test/unit-test/test-continuable-base-partial.cpp b/test/unit-test/test-continuable-base-partial.cpp new file mode 100644 index 0000000..c560ff4 --- /dev/null +++ b/test/unit-test/test-continuable-base-partial.cpp @@ -0,0 +1,61 @@ + +/** + Copyright(c) 2015 - 2017 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 "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(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)); + } +} diff --git a/test/unit-test/test-continuable.hpp b/test/unit-test/test-continuable.hpp index 9143cdc..f5ef5da 100644 --- a/test/unit-test/test-continuable.hpp +++ b/test/unit-test/test-continuable.hpp @@ -195,10 +195,10 @@ struct provide_continuation_seq_right { // build time significantly. using single_types = ::testing::Types< #if UNIT_TEST_STEP == 0 - provide_copyable, + provide_copyable // provide_unique, // provide_erasure, - provide_erasure + // provide_erasure #elif UNIT_TEST_STEP == 1 // Some instantiations out commented for compilation speed reasons // provide_continuation_and_left,