test: code coverage
This commit is contained in:
@@ -141,7 +141,9 @@ public:
|
||||
* @tparam Candidate Function or member to connect to the delegate.
|
||||
*/
|
||||
template<auto Candidate>
|
||||
delegate(connect_arg_t<Candidate>) ENTT_NOEXCEPT {
|
||||
delegate(connect_arg_t<Candidate>) ENTT_NOEXCEPT
|
||||
: delegate{}
|
||||
{
|
||||
connect<Candidate>();
|
||||
}
|
||||
|
||||
@@ -153,7 +155,9 @@ public:
|
||||
* @param value_or_instance A valid object that fits the purpose.
|
||||
*/
|
||||
template<auto Candidate, typename Type>
|
||||
delegate(connect_arg_t<Candidate>, Type &&value_or_instance) ENTT_NOEXCEPT {
|
||||
delegate(connect_arg_t<Candidate>, Type &&value_or_instance) ENTT_NOEXCEPT
|
||||
: delegate{}
|
||||
{
|
||||
connect<Candidate>(std::forward<Type>(value_or_instance));
|
||||
}
|
||||
|
||||
@@ -163,7 +167,9 @@ public:
|
||||
* @param function Function to connect to the delegate.
|
||||
* @param payload User defined arbitrary data.
|
||||
*/
|
||||
delegate(function_type *function, const void *payload = nullptr) ENTT_NOEXCEPT {
|
||||
delegate(function_type *function, const void *payload = nullptr) ENTT_NOEXCEPT
|
||||
: delegate{}
|
||||
{
|
||||
connect(function, payload);
|
||||
}
|
||||
|
||||
@@ -288,7 +294,7 @@ public:
|
||||
* @return The value returned by the underlying function.
|
||||
*/
|
||||
Ret operator()(Args... args) const {
|
||||
ENTT_ASSERT(fn);
|
||||
ENTT_ASSERT(static_cast<bool>(*this));
|
||||
return fn(data, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,9 @@ TEST(Delegate, Functionalities) {
|
||||
entt::delegate<int(int)> lf_del;
|
||||
delegate_functor functor;
|
||||
|
||||
ASSERT_DEATH(ff_del(42), "");
|
||||
ASSERT_DEATH(mf_del(42), "");
|
||||
|
||||
ASSERT_FALSE(ff_del);
|
||||
ASSERT_FALSE(mf_del);
|
||||
ASSERT_EQ(ff_del, mf_del);
|
||||
@@ -369,21 +372,6 @@ TEST(Delegate, VoidVsNonVoidReturnType) {
|
||||
ASSERT_TRUE(cmember);
|
||||
}
|
||||
|
||||
TEST(Delegate, TheLessTheBetter) {
|
||||
entt::delegate<int(int, char)> delegate;
|
||||
delegate_functor functor;
|
||||
|
||||
// int delegate_function(const int &);
|
||||
delegate.connect<&delegate_function>();
|
||||
|
||||
ASSERT_EQ(delegate(3, 'c'), 9);
|
||||
|
||||
// int delegate_functor::operator()(int);
|
||||
delegate.connect<&delegate_functor::operator()>(functor);
|
||||
|
||||
ASSERT_EQ(delegate(3, 'c'), 6);
|
||||
}
|
||||
|
||||
TEST(Delegate, UnboundDataMember) {
|
||||
entt::delegate<int(const delegate_functor &)> delegate;
|
||||
delegate.connect<&delegate_functor::data_member>();
|
||||
@@ -399,3 +387,29 @@ TEST(Delegate, UnboundMemberFunction) {
|
||||
|
||||
ASSERT_EQ(delegate(&functor, 3), 6);
|
||||
}
|
||||
|
||||
TEST(Delegate, TheLessTheBetter) {
|
||||
entt::delegate<int(int, char)> bound;
|
||||
entt::delegate<int(delegate_functor &, int, char)> unbound;
|
||||
delegate_functor functor;
|
||||
|
||||
// int delegate_function(const int &);
|
||||
bound.connect<&delegate_function>();
|
||||
|
||||
ASSERT_EQ(bound(3, 'c'), 9);
|
||||
|
||||
// int delegate_functor::operator()(int);
|
||||
bound.connect<&delegate_functor::operator()>(functor);
|
||||
|
||||
ASSERT_EQ(bound(3, 'c'), 6);
|
||||
|
||||
// int delegate_functor::operator()(int);
|
||||
bound.connect<&delegate_functor::identity>(&functor);
|
||||
|
||||
ASSERT_EQ(bound(3, 'c'), 3);
|
||||
|
||||
// int delegate_functor::operator()(int);
|
||||
unbound.connect<&delegate_functor::operator()>();
|
||||
|
||||
ASSERT_EQ(unbound(functor, 3, 'c'), 6);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user