Reflection and filesystem

Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-05-03 18:09:46 +03:00
1 parent f0825fbd1a
commit 42268c6c35
45 files changed
+2732 -262

No files matched your search

@@ -0,0 +1,58 @@
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <Void/TestingMock/Mock.hpp>
#include <Void/TestingMock/MockFunction.hpp>
namespace
{
// Minimal interface to mock.
struct Service {
virtual ~Service() = default;
virtual int compute(int) = 0;
virtual void log(int) = 0;
};
class MockService : public Void::TestingMock::Mock<MockService>,
public Service
{
public:
Void::TestingMock::MockFunction<int(int)> compute_mock{*this,
"compute"};
Void::TestingMock::MockFunction<void(int)> log_mock{*this, "log"};
int compute(int n) override { return compute_mock(n); }
void log(int n) override { log_mock(n); }
};
} // namespace
// Both registered MockFunctions are exercised — verify_all() succeeds.
Void::Testing::Test verify_all_passes_when_all_expectations_met()
{
using namespace Void::TestingMock;
MockService svc;
svc.compute_mock.expect(Eq(1)).returns(42);
svc.log_mock.expect(Eq(2));
Void::Testing::expect_eq(svc.compute(1), 42);
svc.log(2);
svc.verify_all();
}
// register_function is reachable directly for users who don't want to
// use the constructor-overload registration (e.g. dynamically created
// MockFunctions).
Void::Testing::Test register_function_is_publicly_callable()
{
using namespace Void::TestingMock;
MockService svc;
// The two members already auto-registered; svc.verify_all() should
// be a no-op since the two MockFunctions in the class were never
// expected to be called.
svc.compute_mock.expect(Eq(7)).returns(0);
svc.log_mock.expect(Eq(8));
(void)svc.compute(7);
svc.log(8);
svc.verify_all();
}