diff --git a/cmake/compiler/msvc.cmake b/cmake/compiler/msvc.cmake index 7b8a3f6..77f568c 100644 --- a/cmake/compiler/msvc.cmake +++ b/cmake/compiler/msvc.cmake @@ -8,7 +8,7 @@ if (PLATFORM EQUAL 64) add_definitions("-D_WIN64") endif() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /MP1 /bigobj") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /MP2 /bigobj") if (TESTS_NO_EXCEPTIONS) add_definitions(-D_HAS_EXCEPTIONS=0) diff --git a/include/continuable/continuable-testing.hpp b/include/continuable/continuable-testing.hpp index 58bc1fb..d75acde 100644 --- a/include/continuable/continuable-testing.hpp +++ b/include/continuable/continuable-testing.hpp @@ -31,98 +31,9 @@ #ifndef CONTINUABLE_TESTING_HPP_INCLUDED__ #define CONTINUABLE_TESTING_HPP_INCLUDED__ -#include "gtest/gtest.h" - -#include - -namespace cti { -namespace detail { -namespace testing { -template void assert_async_completion(C&& continuable) { - auto called = std::make_shared(false); - std::forward(continuable).then([called](auto&&... args) { - ASSERT_FALSE(*called); - *called = true; - - // Workaround for our known GCC bug. - util::unused(std::forward(args)...); - }); - ASSERT_TRUE(*called); -} - -template void assert_async_never_completed(C&& continuable) { - std::forward(continuable).then([](auto&&... args) { - // Workaround for our known GCC bug. - util::unused(std::forward(args)...); - - FAIL(); - }); -} - -template -void assert_async_validation(C&& continuable, V&& validator) { - assert_async_completion( - std::forward(continuable) - .then([validator = - std::forward(validator)](auto&&... args) mutable { - - validator(std::forward(args)...); - })); -} - -/// Expects that the continuable is finished with the given arguments -template -void assert_async_binary_validation(V&& validator, C&& continuable, - Args&&... expected) { - assert_async_validation(std::forward(continuable), [ - expected_pack = std::make_tuple(std::forward(expected)...), - validator = std::forward(validator) - ](auto&&... args) mutable { - - auto actual_pack = std::make_tuple(std::forward(args)...); - - auto size = traits::pack_size_of(traits::identity_of(expected_pack)); - - static_assert(size.value == std::tuple_size::value, - "Async completion handler called with a different count " - "of arguments!"); - - traits::static_for_each_in( - std::make_index_sequence{}, [&](auto current) mutable { - auto expected = std::get(std::move(expected_pack)); - auto actual = std::get(std::move(actual_pack)); - (void)current; - - validator(expected, actual); - }); - }); -} - -inline auto expecting_eq_check() { - return [](auto expected, auto actual) { EXPECT_EQ(expected, actual); }; -} - -inline auto asserting_eq_check() { - return [](auto expected, auto actual) { ASSERT_EQ(expected, actual); }; -} - -template -void assert_async_types(C&& continuable, traits::identity expected) { - assert_async_validation( - std::forward(continuable), [&](auto... actualPack) { - auto actual = traits::identity{}; - util::unused(expected, actual, - std::forward(actualPack)...); - - static_assert( - std::is_same, - std::decay_t>::value, - "The called arguments don't match with the expected ones!"); - }); -} -} // namespace testing -} // namespace detail -} // namespace cti +#include +#include +#include /// Asserts that the final callback of the given continuable was called /// with any result. diff --git a/include/continuable/detail/testing.hpp b/include/continuable/detail/testing.hpp new file mode 100644 index 0000000..9f2559c --- /dev/null +++ b/include/continuable/detail/testing.hpp @@ -0,0 +1,129 @@ + +/** + + /~` _ _ _|_. _ _ |_ | _ + \_,(_)| | | || ||_|(_||_)|(/_ + + https://github.com/Naios/continuable + v2.0.0 + + 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 CONTINUABLE_DETAIL_TESTING_HPP_INCLUDED__ +#define CONTINUABLE_DETAIL_TESTING_HPP_INCLUDED__ + +#include + +#include + +namespace cti { +namespace detail { +namespace testing { +template +void assert_async_completion(C&& continuable) { + auto called = std::make_shared(false); + std::forward(continuable).then([called](auto&&... args) { + ASSERT_FALSE(*called); + *called = true; + + // Workaround for our known GCC bug. + util::unused(std::forward(args)...); + }); + ASSERT_TRUE(*called); +} + +template +void assert_async_never_completed(C&& continuable) { + std::forward(continuable).then([](auto&&... args) { + // Workaround for our known GCC bug. + util::unused(std::forward(args)...); + + FAIL(); + }); +} + +template +void assert_async_validation(C&& continuable, V&& validator) { + assert_async_completion( + std::forward(continuable) + .then([validator = + std::forward(validator)](auto&&... args) mutable { + + validator(std::forward(args)...); + })); +} + +/// Expects that the continuable is finished with the given arguments +template +void assert_async_binary_validation(V&& validator, C&& continuable, + Args&&... expected) { + assert_async_validation(std::forward(continuable), [ + expected_pack = std::make_tuple(std::forward(expected)...), + validator = std::forward(validator) + ](auto&&... args) mutable { + + auto actual_pack = std::make_tuple(std::forward(args)...); + + auto size = traits::pack_size_of(traits::identity_of(expected_pack)); + + static_assert(size.value == std::tuple_size::value, + "Async completion handler called with a different count " + "of arguments!"); + + traits::static_for_each_in( + std::make_index_sequence{}, [&](auto current) mutable { + auto expected = std::get(std::move(expected_pack)); + auto actual = std::get(std::move(actual_pack)); + (void)current; + + validator(expected, actual); + }); + }); +} + +inline auto expecting_eq_check() { + return [](auto expected, auto actual) { EXPECT_EQ(expected, actual); }; +} + +inline auto asserting_eq_check() { + return [](auto expected, auto actual) { ASSERT_EQ(expected, actual); }; +} + +template +void assert_async_types(C&& continuable, traits::identity expected) { + assert_async_validation( + std::forward(continuable), [&](auto... actualPack) { + auto actual = traits::identity{}; + util::unused(expected, actual, + std::forward(actualPack)...); + + static_assert( + std::is_same, + std::decay_t>::value, + "The called arguments don't match with the expected ones!"); + }); +} +} // namespace testing +} // namespace detail +} // namespace cti + +#endif // CONTINUABLE_DETAIL_TESTING_HPP_INCLUDED__ diff --git a/test/playground/CMakeLists.txt b/test/playground/CMakeLists.txt index 842cd9e..8be7db5 100644 --- a/test/playground/CMakeLists.txt +++ b/test/playground/CMakeLists.txt @@ -13,6 +13,7 @@ set(LIB_SOURCES_DETAIL ${CMAKE_SOURCE_DIR}/include/continuable/detail/traits.hpp ${CMAKE_SOURCE_DIR}/include/continuable/detail/transforms.hpp ${CMAKE_SOURCE_DIR}/include/continuable/detail/types.hpp + ${CMAKE_SOURCE_DIR}/include/continuable/detail/testing.hpp ${CMAKE_SOURCE_DIR}/include/continuable/detail/util.hpp) set(TEST ${CMAKE_CURRENT_LIST_DIR}/test-playground.cpp) @@ -28,6 +29,7 @@ source_group(test FILES ${TEST}) target_link_libraries(test-playground PRIVATE + gtest continuable) target_compile_definitions(test-playground diff --git a/test/unit-test/test-continuable-base-chaining.cpp b/test/unit-test/test-continuable-base-chaining.cpp index 1a2aec7..193d42e 100644 --- a/test/unit-test/test-continuable-base-chaining.cpp +++ b/test/unit-test/test-continuable-base-chaining.cpp @@ -23,13 +23,12 @@ #include "test-continuable.hpp" -using namespace cti; -using namespace cti::detail; - TYPED_TEST(single_dimension_tests, are_chainable) { - EXPECT_ASYNC_RESULT(this->supply().then([] { + auto chain = this->supply().then([] { return; // void - })); + }); + + ASSERT_ASYNC_TYPES(std::move(chain)); } TYPED_TEST(single_dimension_tests, are_type_chainable) { diff --git a/test/unit-test/test-continuable-base-partial.cpp b/test/unit-test/test-continuable-base-partial.cpp index c560ff4..8624851 100644 --- a/test/unit-test/test-continuable-base-partial.cpp +++ b/test/unit-test/test-continuable-base-partial.cpp @@ -38,24 +38,22 @@ TYPED_TEST(single_dimension_tests, are_partial_callable) { } 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); - }; + 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); + auto chain = this->supply().then( + [&] { + ASSERT_FALSE(invoked); + invoked = true; + }, + executor); - ASSERT_ASYNC_COMPLETION(std::move(chain)); - } + ASSERT_ASYNC_COMPLETION(std::move(chain)); }