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) 46 #define FUTURE_DISPATCH(pid, method) \ 47 process::FutureDispatch(pid, method) 49 #define DROP_DISPATCH(pid, method) \ 50 process::FutureDispatch(pid, method, true) 52 #define DROP_MESSAGES(name, from, to) \ 53 process::DropMessages(name, from, to) 55 #define EXPECT_NO_FUTURE_MESSAGES(name, from, to) \ 56 process::ExpectNoFutureMessages(name, from, to) 58 #define DROP_DISPATCHES(pid, method) \ 59 process::DropDispatches(pid, method) 61 #define EXPECT_NO_FUTURE_DISPATCHES(pid, method) \ 62 process::ExpectNoFutureDispatches(pid, method) 65 #define FUTURE_EXITED(from, to) \ 66 process::FutureExited(from, to) 68 #define DROP_EXITED(from, to) \ 69 process::FutureExited(from, to, true) 73 HAS_1_TEMPLATE_PARAMS(
int, k),
81 promise->set(std::get<k>(args));
86 template <
int index,
typename T>
87 PromiseArgActionP<index, process::Promise<T>*>
FutureArg(
91 *future = promise->
future();
92 return PromiseArg<index>(
promise);
97 HAS_1_TEMPLATE_PARAMS(
int, k),
98 AND_2_VALUE_PARAMS(field,
promise))
105 promise->set(*(std::get<k>(args).*field));
110 template <
int index,
typename Field,
typename T>
116 *future = promise->
future();
117 return PromiseArgField<index>(field,
promise);
122 HAS_1_TEMPLATE_PARAMS(
int, k),
123 AND_2_VALUE_PARAMS(field,
promise))
130 promise->set(std::get<k>(args).*field);
135 template <
int index,
typename Field,
typename T>
136 PromiseArgNotPointerFieldActionP2<index, Field, process::Promise<T>*>
142 *future = promise->
future();
143 return PromiseArgNotPointerField<index>(field,
promise);
154 template <
typename T>
160 *future = promise->
future();
161 return PromiseSatisfy(promise, t);
165 inline PromiseSatisfyActionP2<process::Promise<Nothing>*,
Nothing>
169 *future = promise->
future();
170 return PromiseSatisfy(promise,
Nothing());
180 template <
typename R,
typename A>
188 template <
typename F>
189 operator ::testing::Action<F>()
const 191 return ::testing::Action<F>(
new Implementation<F>(future, action));
195 template <
typename F>
196 class Implementation :
public ::testing::ActionInterface<F>
205 typename ::testing::ActionInterface<F>::Result Perform(
206 const typename ::testing::ActionInterface<F>::ArgumentTuple& args)
209 const typename ::testing::ActionInterface<F>::Result result =
210 action.Perform(args);
217 Implementation(
const Implementation&);
218 Implementation& operator=(
const Implementation&);
221 const ::testing::Action<F> action;
229 template <
typename R,
typename A>
245 EXPECT_CALL(*
this,
filter(
246 testing::A<const UPID&>(),
247 testing::A<const MessageEvent&>()))
248 .WillRepeatedly(testing::Return(
false));
249 EXPECT_CALL(*
this,
filter(
250 testing::A<const UPID&>(),
251 testing::A<const DispatchEvent&>()))
252 .WillRepeatedly(testing::Return(
false));
253 EXPECT_CALL(*
this,
filter(
254 testing::A<const UPID&>(),
255 testing::A<const HttpEvent&>()))
256 .WillRepeatedly(testing::Return(
false));
257 EXPECT_CALL(*
this,
filter(
258 testing::A<const UPID&>(),
259 testing::A<const ExitedEvent&>()))
260 .WillRepeatedly(testing::Return(
false));
281 return handle(process, event);
285 return handle(process, event);
289 return handle(process, event);
293 return handle(process, event);
296 template <
typename T>
299 synchronized (mutex) {
300 return mock.filter(process, t);
330 <<
"To use FUTURE/DROP_MESSAGE/DISPATCH, etc. you need to do the " 331 <<
"following before you invoke RUN_ALL_TESTS():\n\n" 332 <<
"\t::testing::TestEventListeners& listeners =\n" 333 <<
"\t ::testing::UnitTest::GetInstance()->listeners();\n" 334 <<
"\tlisteners.Append(process::FilterTestEventListener::instance());";
378 return (testing::Matcher<std::string>(
name).Matches(event.message.name) &&
379 testing::Matcher<UPID>(from).Matches(event.message.from));
386 MATCHER_P3(UnionMessageMatcher, message, unionType, from,
"")
389 message_type message;
391 return (testing::Matcher<std::string>(message.GetTypeName()).Matches(
392 event.message.name) &&
393 message.ParseFromString(event.message.body) &&
394 testing::Matcher<unionType_type>(unionType).Matches(message.type()) &&
395 testing::Matcher<process::UPID>(from).Matches(event.message.from));
402 return (event.functionType.isSome() &&
403 *
event.functionType.get() ==
typeid(method));
410 return testing::Matcher<process::UPID>(from).Matches(event.pid);
416 const HttpEvent&
event = ::std::get<1>(arg);
419 if (message_.isError()) {
423 return (testing::Matcher<std::string>(
path).Matches(event.request->url.path));
431 const HttpEvent&
event = ::std::get<1>(arg);
434 if (message_.isError()) {
439 testing::Matcher<unionType_type>(unionType).Matches(message_->type()) &&
440 testing::Matcher<std::string>(
path).Matches(event.request->url.path));
444 template <
typename Message,
typename Path,
typename Deserializer>
448 Deserializer deserializer,
453 synchronized (filter->
mutex) {
454 EXPECT_CALL(filter->
mock, filter(
455 testing::A<const UPID&>(),
456 testing::A<const HttpEvent&>()))
457 .With(HttpMatcher(message, path, deserializer))
458 .WillOnce(testing::DoAll(FutureArgField<1>(
461 testing::Return(drop)))
462 .RetiresOnSaturation();
472 typename Deserializer>
477 Deserializer deserializer,
482 synchronized (filter->
mutex) {
483 EXPECT_CALL(filter->
mock, filter(
484 testing::A<const UPID&>(),
485 testing::A<const HttpEvent&>()))
486 .With(UnionHttpMatcher(message, unionType, path, deserializer))
487 .WillOnce(testing::DoAll(FutureArgField<1>(
490 testing::Return(drop)))
491 .RetiresOnSaturation();
498 template <
typename Name,
typename From,
typename To>
503 synchronized (filter->
mutex) {
504 EXPECT_CALL(filter->
mock, filter(to, testing::A<const MessageEvent&>()))
505 .With(MessageMatcher(name, from))
506 .WillOnce(testing::DoAll(FutureArgNotPointerField<1>(
507 &MessageEvent::message,
509 testing::Return(drop)))
510 .RetiresOnSaturation();
517 template <
typename Message,
typename UnionType,
typename From,
typename To>
519 Message message, UnionType unionType, From from, To to,
bool drop =
false)
522 FilterTestEventListener::instance()->install();
525 synchronized (filter->
mutex) {
526 EXPECT_CALL(filter->
mock, filter(to, testing::A<const MessageEvent&>()))
527 .With(UnionMessageMatcher(message, unionType, from))
528 .WillOnce(testing::DoAll(FutureArgNotPointerField<1>(
529 &MessageEvent::message,
531 testing::Return(drop)))
532 .RetiresOnSaturation();
539 template <
typename PID,
typename Method>
544 synchronized (filter->
mutex) {
545 EXPECT_CALL(filter->
mock, filter(pid, testing::A<const DispatchEvent&>()))
546 .With(DispatchMatcher(method))
548 testing::Return(drop)))
549 .RetiresOnSaturation();
556 template <
typename Name,
typename From,
typename To>
560 synchronized (filter->
mutex) {
561 EXPECT_CALL(filter->
mock, filter(to, testing::A<const MessageEvent&>()))
562 .With(MessageMatcher(name, from))
563 .WillRepeatedly(testing::Return(
true));
568 template <
typename Message,
typename UnionType,
typename From,
typename To>
572 synchronized (filter->
mutex) {
573 EXPECT_CALL(filter->
mock, filter(to, testing::A<const MessageEvent&>()))
574 .With(UnionMessageMatcher(message, unionType, from))
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(
590 testing::A<const UPID&>(),
591 testing::A<const HttpEvent&>()))
592 .With(HttpMatcher(message, path, deserializer))
593 .WillRepeatedly(testing::Return(
true));
601 typename Deserializer>
606 Deserializer deserializer,
611 synchronized (filter->
mutex) {
612 EXPECT_CALL(filter->
mock, filter(
613 testing::A<const UPID&>(),
614 testing::A<const HttpEvent&>()))
615 .With(UnionHttpMatcher(message, unionType, path, deserializer))
616 .WillRepeatedly(testing::Return(
true));
621 template <
typename Message,
typename Path,
typename Deserializer>
625 Deserializer deserializer,
629 synchronized (filter->
mutex) {
630 EXPECT_CALL(filter->
mock, filter(
631 testing::A<const UPID&>(),
632 testing::A<const HttpEvent&>()))
633 .With(HttpMatcher(message, path, deserializer))
642 typename Deserializer>
647 Deserializer deserializer,
652 synchronized (filter->
mutex) {
653 EXPECT_CALL(filter->
mock, filter(
654 testing::A<const UPID&>(),
655 testing::A<const HttpEvent&>()))
656 .With(UnionHttpMatcher(message, unionType, path, deserializer))
662 template <
typename Name,
typename From,
typename To>
666 synchronized (filter->
mutex) {
667 EXPECT_CALL(filter->
mock, filter(to, testing::A<const MessageEvent&>()))
668 .With(MessageMatcher(name, from))
674 template <
typename Message,
typename UnionType,
typename From,
typename To>
676 Message message, UnionType unionType, From from, To to)
679 synchronized (filter->
mutex) {
680 EXPECT_CALL(filter->
mock, filter(to, testing::A<const MessageEvent&>()))
681 .With(UnionMessageMatcher(message, unionType, from))
687 template <
typename PID,
typename Method>
691 synchronized (filter->
mutex) {
692 EXPECT_CALL(filter->
mock, filter(pid, testing::A<const DispatchEvent&>()))
693 .With(DispatchMatcher(method))
694 .WillRepeatedly(testing::Return(
true));
699 template <
typename PID,
typename Method>
703 synchronized (filter->
mutex) {
704 EXPECT_CALL(filter->
mock, filter(pid, testing::A<const DispatchEvent&>()))
705 .With(DispatchMatcher(method))
711 template <
typename From,
typename To>
716 synchronized (filter->
mutex) {
717 EXPECT_CALL(filter->
mock, filter(to, testing::A<const ExitedEvent&>()))
718 .With(ExitedMatcher(from))
720 testing::Return(drop)))
721 .RetiresOnSaturation();
729 #endif // __PROCESS_GMOCK_HPP__
Definition: filter.hpp:20
Future< process::Message > FutureUnionMessage(Message message, UnionType unionType, From from, To to, bool drop=false)
Definition: gmock.hpp:518
MATCHER_P2(MessageMatcher, name, from,"")
Definition: gmock.hpp:375
Definition: nothing.hpp:16
PromiseArgActionP< index, process::Promise< T > * > FutureArg(process::Future< T > *future)
Definition: gmock.hpp:87
Definition: gmock.hpp:181
Future< Response > request(const Request &request, bool streamedResponse=false)
Asynchronously sends an HTTP request to the process and returns the HTTP response once the entire res...
FutureResultAction(process::Future< R > *future, const A &action)
Definition: gmock.hpp:184
MATCHER_P3(HttpMatcher, message, path, deserializer,"")
Definition: gmock.hpp:414
MATCHER_P4(UnionHttpMatcher, message, unionType, path, deserializer,"")
Definition: gmock.hpp:429
void OnTestEnd(const ::testing::TestInfo &) override
Definition: gmock.hpp:354
Definition: event.hpp:142
void ExpectNoFutureUnionMessages(Message message, UnionType unionType, From from, To to)
Definition: gmock.hpp:675
Definition: message.hpp:22
PromiseSatisfyActionP2< process::Promise< T > *, T > FutureSatisfy(process::Future< T > *future, T t)
Definition: gmock.hpp:155
Future< Nothing > FutureExited(From from, To to, bool drop=false)
Definition: gmock.hpp:712
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:602
MockFilter mock
Definition: gmock.hpp:304
Definition: event.hpp:209
Future< Nothing > FutureDispatch(PID pid, Method method, bool drop=false)
Definition: gmock.hpp:540
PromiseArgNotPointerFieldActionP2< index, Field, process::Promise< T > * > FutureArgNotPointerField(Field field, process::Future< T > *future)
Definition: gmock.hpp:137
void DropHttpRequests(Message message, Path path, Deserializer deserializer, bool drop=false)
Definition: gmock.hpp:581
ACTION_P2(PromiseSatisfy, promise, value)
Definition: gmock.hpp:147
PromiseArgFieldActionP2< index, Field, process::Promise< T > * > FutureArgField(Field field, process::Future< T > *future)
Definition: gmock.hpp:111
MATCHER_P(ExitedMatcher, from,"")
Definition: gmock.hpp:407
void DropUnionMessages(Message message, UnionType unionType, From from, To to)
Definition: gmock.hpp:569
An "untyped" PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
TestsFilter * install()
Definition: gmock.hpp:326
MockFilter()
Definition: gmock.hpp:243
bool filter(const UPID &process, const DispatchEvent &event) override
Definition: gmock.hpp:283
Represents a POSIX or Windows file system path and offers common path manipulations.
Definition: path.hpp:212
Definition: future.hpp:74
void OnTestProgramStart(const ::testing::UnitTest &) override
Definition: gmock.hpp:349
void DropDispatches(PID pid, Method method)
Definition: gmock.hpp:688
Protocol< PromiseRequest, PromiseResponse > promise
std::recursive_mutex mutex
Definition: gmock.hpp:311
Future< Message > FutureMessage(Name name, From from, To to, bool drop=false)
Definition: gmock.hpp:499
FutureResultAction< R, A > FutureResult(process::Future< R > *future, const A &action)
Definition: gmock.hpp:230
void ExpectNoFutureUnionHttpRequests(Message message, UnionType unionType, Path path, Deserializer deserializer, bool drop=false)
Definition: gmock.hpp:643
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:289
void ExpectNoFutureMessages(Name name, From from, To to)
Definition: gmock.hpp:663
Definition: executor.hpp:48
static FilterTestEventListener * instance()
Definition: gmock.hpp:319
Future< T > future() const
Definition: future.hpp:913
Future< http::Request > FutureUnionHttpRequest(Message message, UnionType unionType, Path path, Deserializer deserializer, bool drop=false)
Definition: gmock.hpp:473
Definition: event.hpp:103
bool filter(const UPID &process, const MessageEvent &event) override
Definition: gmock.hpp:279
bool filter(const UPID &process, const HttpEvent &event) override
Definition: gmock.hpp:287
Definition: gmock.hpp:240
Definition: gmock.hpp:315
void ExpectNoFutureDispatches(PID pid, Method method)
Definition: gmock.hpp:700
bool filter(const UPID &process, const ExitedEvent &event) override
Definition: gmock.hpp:291
Definition: gmock.hpp:274
ACTION_TEMPLATE(PromiseArg, HAS_1_TEMPLATE_PARAMS(int, k), AND_1_VALUE_PARAMS(promise))
Definition: gmock.hpp:72
void ExpectNoFutureHttpRequests(Message message, Path path, Deserializer deserializer, bool drop=false)
Definition: gmock.hpp:622
Future< http::Request > FutureHttpRequest(Message message, Path path, Deserializer deserializer, bool drop=false)
Definition: gmock.hpp:445
constexpr const char * name
Definition: shell.hpp:41
bool handle(const UPID &process, const T &t)
Definition: gmock.hpp:297
void filter(Filter *filter)
void DropMessages(Name name, From from, To to)
Definition: gmock.hpp:557
Definition: future.hpp:58