feat(testing-mock): complete P2 M-TESTINGMOCK-01..04 sessions, action-outside-lock, move-only, combinators
This commit is contained in:
1 parent
86d777eae6
commit
658c21a2fa
8 files changed
+1702
-30
No files matched your search
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user