Copyright 2014->2015
[folly.git] / folly / wangle / channel / test / MockChannelHandler.h
1 /*
2  * Copyright 2015 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <folly/wangle/channel/ChannelHandler.h>
20 #include <gmock/gmock.h>
21
22 namespace folly { namespace wangle {
23
24 template <class Rin, class Rout = Rin, class Win = Rout, class Wout = Rin>
25 class MockChannelHandler : public ChannelHandler<Rin, Rout, Win, Wout> {
26  public:
27   typedef typename ChannelHandler<Rin, Rout, Win, Wout>::Context Context;
28
29   MockChannelHandler() = default;
30   MockChannelHandler(MockChannelHandler&&) = default;
31
32 #ifdef __clang__
33 # pragma clang diagnostic push
34 # if __clang_major__ > 3 || __clang_minor__ >= 6
35 #  pragma clang diagnostic ignored "-Winconsistent-missing-override"
36 # endif
37 #endif
38
39   MOCK_METHOD2_T(read_, void(Context*, Rin&));
40   MOCK_METHOD1_T(readEOF, void(Context*));
41   MOCK_METHOD2_T(readException, void(Context*, exception_wrapper));
42
43   MOCK_METHOD2_T(write_, void(Context*, Win&));
44   MOCK_METHOD1_T(close_, void(Context*));
45
46   MOCK_METHOD1_T(attachPipeline, void(Context*));
47   MOCK_METHOD1_T(attachTransport, void(Context*));
48   MOCK_METHOD1_T(detachPipeline, void(Context*));
49   MOCK_METHOD1_T(detachTransport, void(Context*));
50
51 #ifdef __clang__
52 #pragma clang diagnostic pop
53 #endif
54
55   void read(Context* ctx, Rin msg) override {
56     read_(ctx, msg);
57   }
58
59   Future<void> write(Context* ctx, Win msg) override {
60     return makeFutureTry([&](){
61       write_(ctx, msg);
62     });
63   }
64
65   Future<void> close(Context* ctx) override {
66     return makeFutureTry([&](){
67       close_(ctx);
68     });
69   }
70 };
71
72 template <class R, class W = R>
73 using MockChannelHandlerAdapter = MockChannelHandler<R, R, W, W>;
74
75 }}