folly: avoid new warnings from -Winconsistent-missing-override
[folly.git] / folly / wangle / channel / test / MockChannelHandler.h
1 /*
2  * Copyright 2014 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 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
35 #endif
36
37   MOCK_METHOD2_T(read_, void(Context*, Rin&));
38   MOCK_METHOD1_T(readEOF, void(Context*));
39   MOCK_METHOD2_T(readException, void(Context*, exception_wrapper));
40
41   MOCK_METHOD2_T(write_, void(Context*, Win&));
42   MOCK_METHOD1_T(close_, void(Context*));
43
44   MOCK_METHOD1_T(attachPipeline, void(Context*));
45   MOCK_METHOD1_T(attachTransport, void(Context*));
46   MOCK_METHOD1_T(detachPipeline, void(Context*));
47   MOCK_METHOD1_T(detachTransport, void(Context*));
48
49 #ifdef __clang__
50 #pragma clang diagnostic pop
51 #endif
52
53   void read(Context* ctx, Rin msg) override {
54     read_(ctx, msg);
55   }
56
57   Future<void> write(Context* ctx, Win msg) override {
58     return makeFutureTry([&](){
59       write_(ctx, msg);
60     });
61   }
62
63   Future<void> close(Context* ctx) override {
64     return makeFutureTry([&](){
65       close_(ctx);
66     });
67   }
68 };
69
70 template <class R, class W = R>
71 using MockChannelHandlerAdapter = MockChannelHandler<R, R, W, W>;
72
73 }}