Add some invokation tests

This commit is contained in:
Denis Blank 2015-08-11 20:26:04 +02:00
parent b8e6edfbe8
commit f70efcfc01
2 changed files with 72 additions and 5 deletions

View File

@ -274,7 +274,7 @@ namespace detail
{
/// Corrects functionals with non expected signatures
/// to match the expected ones.
/// Used in `partialized_signature_corrector`
/// Used in `partial_signature_corrector`
template<typename... _ATy>
struct partial_signature_corrector
{
@ -361,7 +361,7 @@ namespace detail
}
template<typename _CTy>
static inline auto partialized_signature_corrector(_CTy&& functional)
static inline auto partial_signature_corrector(_CTy&& functional)
-> _CTy// decltype(correctors::partial_signature_corrector<_ATy...>::correct(std::declval<_CTy>()))
{
// return correctors::partial_signature_corrector<_ATy...>::correct(std::forward<_CTy>(functional));
@ -408,7 +408,7 @@ namespace detail
return unboxed_continuable_corrector(std::forward<_CTy>(functional));
}
/// `partialized_signature_corrector`: Converts functionals with not matching args signature.
/// `partial_signature_corrector`: Converts functionals with not matching args signature.
/// `void_returning_corrector`: Converts void return to empty continuable.
template<typename _CTy>
static auto correct_stage(_CTy&& functional)
@ -416,10 +416,10 @@ namespace detail
!detail::is_continuable<
typename std::decay<_CTy>::type
>::value,
decltype(void_returning_corrector(partialized_signature_corrector(std::declval<_CTy>())))
decltype(void_returning_corrector(partial_signature_corrector(std::declval<_CTy>())))
>::type
{
return void_returning_corrector(partialized_signature_corrector(std::forward<_CTy>(functional)));
return void_returning_corrector(partial_signature_corrector(std::forward<_CTy>(functional)));
}
/// Accepts and corrects user given functionals through several stages into the form:

View File

@ -19,6 +19,8 @@
#include "catch.hpp"
#include "Continuable.h"
void test_mockup();
void test_incubator();
@ -93,3 +95,68 @@ TEST_CASE("CrossForward tests", "[CrossForward]")
REQUIRE_FALSE(con.ptr.get());
}
}
Continuable<std::string> http_request(std::string const& /*url*/)
{
return make_continuable([=](std::function<void(std::string)>&& callback)
{
// Do request...
std::string result = "some HTTP content";
callback(std::move(result));
});
}
struct ResultSet
{
std::size_t rows;
};
Continuable<ResultSet> mysql_query(std::string const& /*query*/)
{
return make_continuable([=](std::function<void(ResultSet)>&& callback)
{
callback(ResultSet{5});
});
}
Continuable<> defect_continuable()
{
return make_continuable([=](std::function<void()>&& /*callback*/)
{
// Callback is never called
});
}
TEST_CASE("Continuable invocation on destruct", "[Continuable]")
{
bool invoked = false;
std::function<void(Callback<>&&)> invokeable = [&](Callback<>&& callback)
{
invoked = true;
callback();
};
SECTION("Continuables are not invoked before destruct")
{
Continuable<> continuable = make_continuable(std::move(invokeable));
REQUIRE_FALSE(invoked);
}
SECTION("Continuables are invoked on destruct")
{
make_continuable(std::move(invokeable));
REQUIRE(invoked);
}
}
TEST_CASE("Continuable continuation chaining using Continuable::then", "[Continuable]")
{
SECTION("Continuables are invalidated on chaining (no duplicated call)")
{
std::size_t invoked = 0;
}
}