/** 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. **/ #ifndef TEST_CONTINUABLE_HPP__ #define TEST_CONTINUABLE_HPP__ #if UNIT_TEST_STEP >= 3 #define THIRD_PARTY_TESTS #endif #ifdef THIRD_PARTY_TESTS // #if _MSC_VER // #pragma warning(push, 0) // #endif #endif // THIRD_PARTY_TESTS #include #include "continuable/continuable-base.hpp" #include "continuable/continuable-testing.hpp" #include "continuable/continuable.hpp" #include "gtest/gtest.h" #include #ifdef THIRD_PARTY_TESTS #include "cxx_function/cxx_function.hpp" template using cxx_function_fn = cxx_function::function; template using cxx_trait_of = cti::continuable_trait; template using cxx_continuable = typename cxx_trait_of::continuable; template using cxx_function_unique_fn = cxx_function::unique_function; template using unique_cxx_trait_of = cti::continuable_trait; template using cxx_unique_continuable = typename unique_cxx_trait_of::continuable; #endif // THIRD_PARTY_TESTS template using std_trait_of = cti::continuable_trait; template using std_continuable = typename std_trait_of::continuable; using cti::detail::traits::identity; inline auto to_hint(identity<> /*hint*/) { return identity{}; } template auto to_hint(identity hint) { return hint; } template auto supplier_of(Args&&... args) { return [values = std::make_tuple(std::forward(args)...)]( auto&& callback) mutable { cti::detail::traits::unpack(std::move(values), [&](auto&&... passed) { // ... std::forward(callback)( std::forward(passed)...); }); }; } template class continuation_provider : public ::testing::Test, public Provider { public: template auto invoke(T&& type) { return this->make(identity<>{}, identity{}, [type = std::forward(type)](auto&& callback) mutable { std::forward(callback)(); }); } template auto supply(Args&&... args) { identity...> arg_types; auto hint_types = to_hint(arg_types); return this->make(arg_types, hint_types, supplier_of(std::forward(args)...)); } }; inline auto empty_caller() { return [](auto&& callback) { // ... std::forward(callback)(); }; } inline auto empty_continuable() { return cti::make_continuable(empty_caller()); } struct provide_copyable { template auto make(identity, identity, T&& callback) { return cti::make_continuable(std::forward(callback)); } }; struct provide_unique { template auto make(identity, identity, T&& callback) { return cti::make_continuable([ callback = std::forward(callback), guard = std::make_unique(0) ](auto&&... args) mutable { (void)(*guard); return std::move(callback)(std::forward(args)...); }); } }; template