#pragma once #include #include #include #include #include #if __has_include() #include #define VOID_MOCK_HAS_REFLECTION 1 #endif // ── Reflection helpers for mocking // ──────────────────────────────────────────── This toolchain's P2996 has rich // introspection + define_aggregate (it can even generate a MockFunction // data member per interface virtual), but it has NO code injection, so the // virtual *override functions* a full auto-mock needs cannot be synthesized. // These helpers therefore cover the achievable ground: list an interface's // virtual methods and statically check a hand-written mock implements all of // them. namespace Void::TestingMock { #ifdef VOID_MOCK_HAS_REFLECTION namespace meta = std::meta; /// The identifiers of every virtual member function of interface `I` /// (excluding the destructor), in declaration order. template [[nodiscard]] std::vector method_names() { std::vector out; template for (constexpr auto m : std::define_static_array(meta::members_of( ^^I, meta::access_context::unchecked()))) { if constexpr (meta::is_function(m) && meta::is_virtual(m) && !meta::is_destructor(m)) { out.emplace_back(meta::identifier_of(m)); } } return out; } /// Number of virtual methods (excluding the destructor) on `I`. template [[nodiscard]] consteval std::size_t method_count() { std::size_t n = 0; template for (constexpr auto m : std::define_static_array(meta::members_of( ^^I, meta::access_context::unchecked()))) { if constexpr (meta::is_function(m) && meta::is_virtual(m) && !meta::is_destructor(m)) { ++n; } } return n; } /// True if `Mock` is a complete, instantiable implementation of interface /// `I` — i.e. it derives `I` and overrides every pure-virtual method (so no /// abstract methods remain). A compile-time completeness check: /// static_assert(TestingMock::covers()); template [[nodiscard]] consteval bool covers() { return std::derived_from && !std::is_abstract_v; } #endif // VOID_MOCK_HAS_REFLECTION } // namespace Void::TestingMock