13 #ifndef __PROCESS_GMOCK_HPP__
14 #define __PROCESS_GMOCK_HPP__
16 #include <gmock/gmock.h>
28 #define FUTURE_MESSAGE(name, from, to) \
29 process::FutureMessage(name, from, to)
31 #define DROP_MESSAGE(name, from, to) \
32 process::FutureMessage(name, from, to, true)
45 #define FUTURE_DISPATCH(pid, method) \
46 process::FutureDispatch(pid, method)
48 #define DROP_DISPATCH(pid, method) \
49 process::FutureDispatch(pid, method, true)
51 #define DROP_MESSAGES(name, from, to) \
52 process::DropMessages(name, from, to)
54 #define EXPECT_NO_FUTURE_MESSAGES(name, from, to) \
55 process::ExpectNoFutureMessages(name, from, to)
57 #define DROP_DISPATCHES(pid, method) \
58 process::DropDispatches(pid, method)
60 #define EXPECT_NO_FUTURE_DISPATCHES(pid, method) \
61 process::ExpectNoFutureDispatches(pid, method)
64 HAS_1_TEMPLATE_PARAMS(
int, k),
72 promise->set(std::get<k>(args));
77 template <
int index,
typename T>
78 PromiseArgActionP<index, process::Promise<T>*>
FutureArg(
82 *future = promise->
future();
83 return PromiseArg<index>(
promise);
88 HAS_1_TEMPLATE_PARAMS(
int, k),
89 AND_2_VALUE_PARAMS(field,
promise))
96 promise->set(*(std::get<k>(args).*field));
101 template <
int index,
typename Field,
typename T>
107 *future = promise->
future();
108 return PromiseArgField<index>(field,
promise);
113 HAS_1_TEMPLATE_PARAMS(
int, k),
114 AND_2_VALUE_PARAMS(field,
promise))
121 promise->set(std::get<k>(args).*field);
126 template <
int index,
typename Field,
typename T>
127 PromiseArgNotPointerFieldActionP2<index, Field, process::Promise<T>*>
133 *future = promise->
future();
134 return PromiseArgNotPointerField<index>(field,
promise);
145 template <
typename T>
151 *future = promise->
future();
152 return PromiseSatisfy(promise, t);
156 inline PromiseSatisfyActionP2<process::Promise<Nothing>*,
Nothing>
160 *future = promise->
future();
161 return PromiseSatisfy(promise,
Nothing());
171 template <
typename R,
typename A>
179 template <
typename F>
180 operator ::testing::Action<F>()
const
182 return ::testing::Action<F>(
new Implementation<F>(future, action));
186 template <
typename F>
187 class Implementation :
public ::testing::ActionInterface<F>
196 virtual typename ::testing::ActionInterface<F>::Result Perform(
197 const typename ::testing::ActionInterface<F>::ArgumentTuple& args)
199 const typename ::testing::ActionInterface<F>::Result result =
200 action.Perform(args);
207 Implementation(
const Implementation&);
208 Implementation& operator=(
const Implementation&);
211 const ::testing::Action<F> action;
219 template <
typename R,
typename A>
235 EXPECT_CALL(*
this,
filter(testing::A<const MessageEvent&>()))
236 .WillRepeatedly(testing::Return(
false));
237 EXPECT_CALL(*
this,
filter(testing::A<const DispatchEvent&>()))
238 .WillRepeatedly(testing::Return(
false));
239 EXPECT_CALL(*
this,
filter(testing::A<const HttpEvent&>()))
240 .WillRepeatedly(testing::Return(
false));
241 EXPECT_CALL(*
this,
filter(testing::A<const ExitedEvent&>()))
242 .WillRepeatedly(testing::Return(
false));
266 template <
typename T>
269 synchronized (
mutex) {
300 <<
"To use FUTURE/DROP_MESSAGE/DISPATCH, etc. you need to do the "
301 <<
"following before you invoke RUN_ALL_TESTS():\n\n"
302 <<
"\t::testing::TestEventListeners& listeners =\n"
303 <<
"\t ::testing::UnitTest::GetInstance()->listeners();\n"
304 <<
"\tlisteners.Append(process::FilterTestEventListener::instance());";
307 if (filter !=
nullptr) {
326 if (filter !=
nullptr) {
348 return (testing::Matcher<std::string>(
name).Matches(event.message.name) &&
349 testing::Matcher<UPID>(from).Matches(event.message.from) &&
350 testing::Matcher<UPID>(to).Matches(event.message.to));
357 MATCHER_P4(UnionMessageMatcher, message, unionType, from, to,
"")
360 message_type message;
362 return (testing::Matcher<std::string>(message.GetTypeName()).Matches(
363 event.message.name) &&
364 message.ParseFromString(event.message.body) &&
365 testing::Matcher<unionType_type>(unionType).Matches(message.type()) &&
366 testing::Matcher<process::UPID>(from).Matches(event.message.from) &&
367 testing::Matcher<process::UPID>(to).Matches(event.message.to));
374 return (testing::Matcher<UPID>(pid).Matches(event.pid) &&
375 event.functionType.isSome() &&
376 *
event.functionType.get() ==
typeid(method));
382 const HttpEvent&
event = ::std::get<0>(arg);
385 if (message_.isError()) {
389 return (testing::Matcher<std::string>(path).Matches(event.request->url.path));
395 MATCHER_P4(UnionHttpMatcher, message, unionType, path, deserializer,
"")
397 const HttpEvent&
event = ::std::get<0>(arg);
400 if (message_.isError()) {
404 return (testing::Matcher<unionType_type>(unionType).Matches(
405 message_.get().type()) &&
406 testing::Matcher<std::string>(path).Matches(
407 event.request->url.path));
411 template <
typename Message,
typename Path,
typename Deserializer>
415 Deserializer deserializer,
420 synchronized (filter->
mutex) {
421 EXPECT_CALL(filter->
mock, filter(testing::A<const HttpEvent&>()))
422 .With(HttpMatcher(message, path, deserializer))
423 .WillOnce(testing::DoAll(FutureArgField<0>(
426 testing::Return(drop)))
427 .RetiresOnSaturation();
434 template <
typename Message,
437 typename Deserializer>
442 Deserializer deserializer,
447 synchronized (filter->
mutex) {
448 EXPECT_CALL(filter->
mock, filter(testing::A<const HttpEvent&>()))
449 .With(UnionHttpMatcher(message, unionType, path, deserializer))
450 .WillOnce(testing::DoAll(FutureArgField<0>(
453 testing::Return(drop)))
454 .RetiresOnSaturation();
461 template <
typename Name,
typename From,
typename To>
466 synchronized (filter->
mutex) {
467 EXPECT_CALL(filter->
mock, filter(testing::A<const MessageEvent&>()))
468 .With(MessageMatcher(name, from, to))
469 .WillOnce(testing::DoAll(FutureArgNotPointerField<0>(
472 testing::Return(drop)))
473 .RetiresOnSaturation();
480 template <
typename Message,
typename UnionType,
typename From,
typename To>
482 Message message, UnionType unionType, From from, To to,
bool drop =
false)
488 synchronized (filter->
mutex) {
489 EXPECT_CALL(filter->
mock, filter(testing::A<const MessageEvent&>()))
490 .With(UnionMessageMatcher(message, unionType, from, to))
491 .WillOnce(testing::DoAll(FutureArgNotPointerField<0>(
494 testing::Return(drop)))
495 .RetiresOnSaturation();
502 template <
typename PID,
typename Method>
507 synchronized (filter->
mutex) {
508 EXPECT_CALL(filter->
mock, filter(testing::A<const DispatchEvent&>()))
509 .With(DispatchMatcher(pid, method))
511 testing::Return(drop)))
512 .RetiresOnSaturation();
519 template <
typename Name,
typename From,
typename To>
523 synchronized (filter->
mutex) {
524 EXPECT_CALL(filter->
mock, filter(testing::A<const MessageEvent&>()))
525 .With(MessageMatcher(name, from, to))
526 .WillRepeatedly(testing::Return(
true));
531 template <
typename Message,
typename UnionType,
typename From,
typename To>
535 synchronized (filter->
mutex) {
536 EXPECT_CALL(filter->
mock, filter(testing::A<const MessageEvent&>()))
537 .With(UnionMessageMatcher(message, unionType, from, to))
538 .WillRepeatedly(testing::Return(
true));
543 template <
typename Message,
typename Path,
typename Deserializer>
547 Deserializer deserializer,
551 synchronized (filter->
mutex) {
552 EXPECT_CALL(filter->
mock, filter(testing::A<const HttpEvent&>()))
553 .With(HttpMatcher(message, path, deserializer))
554 .WillRepeatedly(testing::Return(
true));
559 template <
typename Message,
562 typename Deserializer>
567 Deserializer deserializer,
572 synchronized (filter->
mutex) {
573 EXPECT_CALL(filter->
mock, filter(testing::A<const HttpEvent&>()))
574 .With(UnionHttpMatcher(message, unionType, path, deserializer))
575 .WillRepeatedly(testing::Return(
true));
580 template <
typename Message,
typename Path,
typename Deserializer>
584 Deserializer deserializer,
588 synchronized (filter->
mutex) {
589 EXPECT_CALL(filter->
mock, filter(testing::A<const HttpEvent&>()))
590 .With(HttpMatcher(message, path, deserializer))
596 template <
typename Message,
599 typename Deserializer>
604 Deserializer deserializer,
609 synchronized (filter->
mutex) {
610 EXPECT_CALL(filter->
mock, filter(testing::A<const HttpEvent&>()))
611 .With(UnionHttpMatcher(message, unionType, path, deserializer))
617 template <
typename Name,
typename From,
typename To>
621 synchronized (filter->
mutex) {
622 EXPECT_CALL(filter->
mock, filter(testing::A<const MessageEvent&>()))
623 .With(MessageMatcher(name, from, to))
629 template <
typename Message,
typename UnionType,
typename From,
typename To>
631 Message message, UnionType unionType, From from, To to)
634 synchronized (filter->
mutex) {
635 EXPECT_CALL(filter->
mock, filter(testing::A<const MessageEvent&>()))
636 .With(UnionMessageMatcher(message, unionType, from, to))
642 template <
typename PID,
typename Method>
646 synchronized (filter->
mutex) {
647 EXPECT_CALL(filter->
mock, filter(testing::A<const DispatchEvent&>()))
648 .With(DispatchMatcher(pid, method))
649 .WillRepeatedly(testing::Return(
true));
654 template <
typename PID,
typename Method>
658 synchronized (filter->
mutex) {
659 EXPECT_CALL(filter->
mock, filter(testing::A<const DispatchEvent&>()))
660 .With(DispatchMatcher(pid, method))
667 #endif // __PROCESS_GMOCK_HPP__
Definition: filter.hpp:20
virtual bool filter(const HttpEvent &event)
Definition: gmock.hpp:263
Future< process::Message > FutureUnionMessage(Message message, UnionType unionType, From from, To to, bool drop=false)
Definition: gmock.hpp:481
Definition: nothing.hpp:16
PromiseArgActionP< index, process::Promise< T > * > FutureArg(process::Future< T > *future)
Definition: gmock.hpp:78
Definition: gmock.hpp:172
FutureResultAction(process::Future< R > *future, const A &action)
Definition: gmock.hpp:175
virtual void OnTestProgramStart(const ::testing::UnitTest &)
Definition: gmock.hpp:319
Definition: event.hpp:142
void ExpectNoFutureUnionMessages(Message message, UnionType unionType, From from, To to)
Definition: gmock.hpp:630
Definition: message.hpp:22
PromiseSatisfyActionP2< process::Promise< T > *, T > FutureSatisfy(process::Future< T > *future, T t)
Definition: gmock.hpp:146
virtual bool filter(const MessageEvent &event)
Definition: gmock.hpp:261
Definition: event.hpp:178
#define EXIT(status)
Definition: exit.hpp:31
void DropUnionHttpRequests(Message message, UnionType unionType, Path path, Deserializer deserializer, bool drop=false)
Definition: gmock.hpp:563
MockFilter mock
Definition: gmock.hpp:274
virtual void OnTestEnd(const ::testing::TestInfo &)
Definition: gmock.hpp:324
Definition: event.hpp:214
Future< Nothing > FutureDispatch(PID pid, Method method, bool drop=false)
Definition: gmock.hpp:503
PromiseArgNotPointerFieldActionP2< index, Field, process::Promise< T > * > FutureArgNotPointerField(Field field, process::Future< T > *future)
Definition: gmock.hpp:128
void DropHttpRequests(Message message, Path path, Deserializer deserializer, bool drop=false)
Definition: gmock.hpp:544
ACTION_P2(PromiseSatisfy, promise, value)
Definition: gmock.hpp:138
MATCHER_P4(UnionMessageMatcher, message, unionType, from, to,"")
Definition: gmock.hpp:357
PromiseArgFieldActionP2< index, Field, process::Promise< T > * > FutureArgField(Field field, process::Future< T > *future)
Definition: gmock.hpp:102
Message message
Definition: event.hpp:138
void DropUnionMessages(Message message, UnionType unionType, From from, To to)
Definition: gmock.hpp:532
TestsFilter * install()
Definition: gmock.hpp:296
MockFilter()
Definition: gmock.hpp:233
Represents a POSIX or Windows file system path and offers common path manipulations.
Definition: path.hpp:145
MATCHER_P3(MessageMatcher, name, from, to,"")
Definition: gmock.hpp:345
Definition: future.hpp:73
void DropDispatches(PID pid, Method method)
Definition: gmock.hpp:643
virtual bool filter(const DispatchEvent &event)
Definition: gmock.hpp:262
std::unique_ptr< http::Request > request
Definition: event.hpp:173
Protocol< PromiseRequest, PromiseResponse > promise
virtual bool filter(const MessageEvent &)
Definition: filter.hpp:23
std::recursive_mutex mutex
Definition: gmock.hpp:281
Future< Message > FutureMessage(Name name, From from, To to, bool drop=false)
Definition: gmock.hpp:462
FutureResultAction< R, A > FutureResult(process::Future< R > *future, const A &action)
Definition: gmock.hpp:220
void ExpectNoFutureUnionHttpRequests(Message message, UnionType unionType, Path path, Deserializer deserializer, bool drop=false)
Definition: gmock.hpp:600
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:279
void ExpectNoFutureMessages(Name name, From from, To to)
Definition: gmock.hpp:618
virtual bool filter(const ExitedEvent &event)
Definition: gmock.hpp:264
static FilterTestEventListener * instance()
Definition: gmock.hpp:289
Future< T > future() const
Definition: future.hpp:912
Future< http::Request > FutureUnionHttpRequest(Message message, UnionType unionType, Path path, Deserializer deserializer, bool drop=false)
Definition: gmock.hpp:438
Definition: event.hpp:103
Definition: gmock.hpp:230
Definition: gmock.hpp:285
void ExpectNoFutureDispatches(PID pid, Method method)
Definition: gmock.hpp:655
Definition: gmock.hpp:256
ACTION_TEMPLATE(PromiseArg, HAS_1_TEMPLATE_PARAMS(int, k), AND_1_VALUE_PARAMS(promise))
Definition: gmock.hpp:63
void ExpectNoFutureHttpRequests(Message message, Path path, Deserializer deserializer, bool drop=false)
Definition: gmock.hpp:581
Future< http::Request > FutureHttpRequest(Message message, Path path, Deserializer deserializer, bool drop=false)
Definition: gmock.hpp:412
constexpr const char * name
Definition: shell.hpp:41
MATCHER_P2(DispatchMatcher, pid, method,"")
Definition: gmock.hpp:371
void filter(Filter *filter)
bool handle(const T &t)
Definition: gmock.hpp:267
MOCK_METHOD1(filter, bool(const MessageEvent &))
void DropMessages(Name name, From from, To to)
Definition: gmock.hpp:520
Definition: future.hpp:57