feat(testing-mock): complete P2 M-TESTINGMOCK-01..04 sessions, action-outside-lock, move-only, combinators

This commit is contained in:
faumaray committed 2026-11-27 01:15:36 +03:00
1 parent 86d777eae6
commit 658c21a2fa
8 files changed
+1702 -30

No files matched your search

@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 4.0)
project(VoidTestingMockOnlyConsumer LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(Void CONFIG REQUIRED COMPONENTS TestingMock)
add_executable(testing_mock_only_consumer main.cpp)
target_link_libraries(testing_mock_only_consumer PRIVATE Void::TestingMock)
enable_testing()
add_test(NAME testing_mock_only_consumer COMMAND testing_mock_only_consumer)
+33
View File
@@ -0,0 +1,33 @@
#include <Void/TestingMock/Matcher.hpp>
#include <Void/TestingMock/MockFunction.hpp>
#include <Void/TestingMock/Session.hpp>
#include <memory>
#include <string>
int main()
{
using namespace Void::TestingMock;
MockSession session;
MockFunction<std::unique_ptr<int>(std::string)> fn{session, "lookup"};
auto exp = fn.try_expect(
AllOf<std::string>(StartsWith<std::string>("k_"),
EndsWith<std::string>("_1")));
if (!exp.has_value()) {
return 1;
}
(*exp)->returns_once(std::make_unique<int>(42));
if (!freeze(session, Concurrency::SingleThread).has_value()) {
return 2;
}
auto out = fn("k_ok_1");
if (!out || *out != 42) {
return 3;
}
auto rep = verify_and_close(session);
if (!rep.has_value() || !rep->ok()) {
return 4;
}
return 0;
}