48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
// @requires-reflection
|
|
#include <Void/TestingMock/Reflect.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Suite.hpp>
|
|
|
|
#include <string_view>
|
|
|
|
namespace
|
|
{
|
|
struct IDb {
|
|
virtual ~IDb() = default;
|
|
virtual int query(std::string_view s) = 0;
|
|
virtual void close() = 0;
|
|
int helper() { return 0; } // non-virtual — ignored
|
|
};
|
|
struct GoodMock : IDb {
|
|
int query(std::string_view) override { return 0; }
|
|
void close() override {}
|
|
};
|
|
struct BadMock : IDb {
|
|
int query(std::string_view) override { return 0; }
|
|
// missing close() → still abstract
|
|
};
|
|
|
|
using Void::Testing::Test;
|
|
|
|
struct MockReflect : Void::Testing::Suite<MockReflect> {
|
|
Test lists_virtual_methods()
|
|
{
|
|
const auto names = Void::TestingMock::method_names<IDb>();
|
|
Void::Testing::expect_eq(names.size(), std::size_t{2});
|
|
Void::Testing::expect(names[0] == "query" &&
|
|
names[1] == "close");
|
|
static_assert(Void::TestingMock::method_count<IDb>() == 2);
|
|
}
|
|
|
|
Test covers_detects_completeness()
|
|
{
|
|
static_assert(Void::TestingMock::covers<GoodMock, IDb>());
|
|
static_assert(!Void::TestingMock::covers<BadMock, IDb>());
|
|
Void::Testing::expect(
|
|
Void::TestingMock::covers<GoodMock, IDb>());
|
|
Void::Testing::expect(
|
|
!Void::TestingMock::covers<BadMock, IDb>());
|
|
}
|
|
};
|
|
} // namespace
|