Skip to content

Commit

Permalink
feat: add exhaustive invocable checks for Mock
Browse files Browse the repository at this point in the history
  • Loading branch information
DNKpp committed Sep 25, 2024
1 parent 1962d47 commit 6d09f7a
Showing 1 changed file with 197 additions and 0 deletions.
197 changes: 197 additions & 0 deletions test/unit-tests/Mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,203 @@ TEMPLATE_TEST_CASE(
STATIC_REQUIRE(std::is_nothrow_move_assignable_v<MockT>);
}

TEMPLATE_TEST_CASE_SIG(
"Mutable Mock specialization is an invocable type.",
"[mock]",
((bool dummy, typename Sig, typename... Args), dummy, Sig, Args...),
(true, void()),
(true, int()),
(true, void(int&), int&),
(true, float&&(int&), int&),
(true, float&&(std::tuple<int&>&&), std::tuple<int&>&&),
(true, float&&(std::tuple<int&>&&, const std::tuple<double&&>&), std::tuple<int&>&&, const std::tuple<double&&>&)
)
{
using ReturnT = signature_return_type_t<Sig>;
using MockT = Mock<Sig>;
using NothrowMockT = Mock<signature_add_noexcept_t<Sig>>;

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT, Args...>);
STATIC_REQUIRE(std::invocable<MockT, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT&, Args...>);
STATIC_REQUIRE(std::invocable<MockT&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT&, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT&, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT&&, Args...>);
STATIC_REQUIRE(std::invocable<MockT&&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT&&, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT&&, Args...>);
}

TEMPLATE_TEST_CASE_SIG(
"Mutable Mock specialization is an invocable type.",
"[mock]",
((bool dummy, typename Sig, typename... Args), dummy, Sig, Args...),
(true, void() const),
(true, int() const),
(true, void(int&) const, int&),
(true, float&&(int&) const, int&),
(true, float&&(std::tuple<int&>&&) const, std::tuple<int&>&&),
(true, float&&(std::tuple<int&>&&, const std::tuple<double&&>&) const, std::tuple<int&>&&, const std::tuple<double&&>&)
)
{
using ReturnT = signature_return_type_t<Sig>;
using MockT = Mock<Sig>;
using NothrowMockT = Mock<signature_add_noexcept_t<Sig>>;

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT, Args...>);
STATIC_REQUIRE(std::invocable<MockT, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT&, Args...>);
STATIC_REQUIRE(std::invocable<MockT&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT&, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT&, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, const MockT&, Args...>);
STATIC_REQUIRE(std::invocable<const MockT&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, const NothrowMockT&, Args...>);
STATIC_REQUIRE(std::invocable<const NothrowMockT&, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT&&, Args...>);
STATIC_REQUIRE(std::invocable<MockT&&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT&&, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT&&, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, const MockT&&, Args...>);
STATIC_REQUIRE(std::invocable<const MockT&&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, const NothrowMockT&&, Args...>);
STATIC_REQUIRE(std::invocable<const NothrowMockT&&, Args...>);
}

TEMPLATE_TEST_CASE_SIG(
"Lvalue Mock specialization is an invocable type.",
"[mock]",
((bool dummy, typename Sig, typename... Args), dummy, Sig, Args...),
(true, void() &),
(true, int() &),
(true, void(int&) &, int&),
(true, float&&(int&) &, int&),
(true, float&&(std::tuple<int&>&&) &, std::tuple<int&>&&),
(true, float&&(std::tuple<int&>&&, const std::tuple<double&&>&) &, std::tuple<int&>&&, const std::tuple<double&&>&)
)
{
using ReturnT = signature_return_type_t<Sig>;
using MockT = Mock<Sig>;
using NothrowMockT = Mock<signature_add_noexcept_t<Sig>>;

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT&, Args...>);
STATIC_REQUIRE(std::invocable<MockT&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT&, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT&, Args...>);
}

TEMPLATE_TEST_CASE_SIG(
"Const lvalue Mock specialization is an invocable type.",
"[mock]",
((bool dummy, typename Sig, typename... Args), dummy, Sig, Args...),
(true, void() const &),
(true, int() const &),
(true, void(int&) const &, int&),
(true, float&&(int&) const &, int&),
(true, float&&(std::tuple<int&>&&) const &, std::tuple<int&>&&),
(true, float&&(std::tuple<int&>&&, const std::tuple<double&&>&) const &, std::tuple<int&>&&, const std::tuple<double&&>&)
)
{
using ReturnT = signature_return_type_t<Sig>;
using MockT = Mock<Sig>;
using NothrowMockT = Mock<signature_add_noexcept_t<Sig>>;

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT, Args...>);
STATIC_REQUIRE(std::invocable<MockT, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT&, Args...>);
STATIC_REQUIRE(std::invocable<MockT&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT&, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT&, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, const MockT&, Args...>);
STATIC_REQUIRE(std::invocable<const MockT&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, const NothrowMockT&, Args...>);
STATIC_REQUIRE(std::invocable<const NothrowMockT&, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT&&, Args...>);
STATIC_REQUIRE(std::invocable<MockT&&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT&&, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT&&, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, const MockT&&, Args...>);
STATIC_REQUIRE(std::invocable<const MockT&&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, const NothrowMockT&&, Args...>);
STATIC_REQUIRE(std::invocable<const NothrowMockT&&, Args...>);
}

TEMPLATE_TEST_CASE_SIG(
"Rvalue Mock specialization is an invocable type.",
"[mock]",
((bool dummy, typename Sig, typename... Args), dummy, Sig, Args...),
(true, void() &&),
(true, int() &&),
(true, void(int&) &&, int&),
(true, float&&(int&) &&, int&),
(true, float&&(std::tuple<int&>&&) &&, std::tuple<int&>&&),
(true, float&&(std::tuple<int&>&&, const std::tuple<double&&>&) &&, std::tuple<int&>&&, const std::tuple<double&&>&)
)
{
using ReturnT = signature_return_type_t<Sig>;
using MockT = Mock<Sig>;
using NothrowMockT = Mock<signature_add_noexcept_t<Sig>>;

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT, Args...>);
STATIC_REQUIRE(std::invocable<MockT, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT&&, Args...>);
STATIC_REQUIRE(std::invocable<MockT&&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT&&, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT&&, Args...>);
}

TEMPLATE_TEST_CASE_SIG(
"Const rvalue Mock specialization is an invocable type.",
"[mock]",
((bool dummy, typename Sig, typename... Args), dummy, Sig, Args...),
(true, void() const &&),
(true, int() const &&),
(true, void(int&) const &&, int&),
(true, float&&(int&) const &&, int&),
(true, float&&(std::tuple<int&>&&) const &&, std::tuple<int&>&&),
(true, float&&(std::tuple<int&>&&, const std::tuple<double&&>&) const &&, std::tuple<int&>&&, const std::tuple<double&&>&)
)
{
using ReturnT = signature_return_type_t<Sig>;
using MockT = Mock<Sig>;
using NothrowMockT = Mock<signature_add_noexcept_t<Sig>>;

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT, Args...>);
STATIC_REQUIRE(std::invocable<MockT, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, MockT&&, Args...>);
STATIC_REQUIRE(std::invocable<MockT&&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, NothrowMockT&&, Args...>);
STATIC_REQUIRE(std::invocable<NothrowMockT&&, Args...>);

STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, const MockT&&, Args...>);
STATIC_REQUIRE(std::invocable<const MockT&&, Args...>);
STATIC_REQUIRE(std::is_invocable_r_v<ReturnT, const NothrowMockT&&, Args...>);
STATIC_REQUIRE(std::invocable<const NothrowMockT&&, Args...>);
}

TEST_CASE(
"Mutable Mock specialization supports expectations.",
"[mock]"
Expand Down

0 comments on commit 6d09f7a

Please sign in to comment.