• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2017 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPCPP_TEST_MOCK_STREAM_H
20 #define GRPCPP_TEST_MOCK_STREAM_H
21 
22 #include <stdint.h>
23 
24 #include <gmock/gmock.h>
25 #include <grpcpp/impl/codegen/call.h>
26 #include <grpcpp/support/async_stream.h>
27 #include <grpcpp/support/async_unary_call.h>
28 #include <grpcpp/support/sync_stream.h>
29 
30 namespace grpc {
31 namespace testing {
32 
33 template <class R>
34 class MockClientReader : public ClientReaderInterface<R> {
35  public:
36   MockClientReader() = default;
37 
38   /// ClientStreamingInterface
39   MOCK_METHOD0_T(Finish, Status());
40 
41   /// ReaderInterface
42   MOCK_METHOD1_T(NextMessageSize, bool(uint32_t*));
43   MOCK_METHOD1_T(Read, bool(R*));
44 
45   /// ClientReaderInterface
46   MOCK_METHOD0_T(WaitForInitialMetadata, void());
47 };
48 
49 template <class W>
50 class MockClientWriter : public ClientWriterInterface<W> {
51  public:
52   MockClientWriter() = default;
53 
54   /// ClientStreamingInterface
55   MOCK_METHOD0_T(Finish, Status());
56 
57   /// WriterInterface
58   MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions));
59 
60   /// ClientWriterInterface
61   MOCK_METHOD0_T(WritesDone, bool());
62 };
63 
64 template <class W, class R>
65 class MockClientReaderWriter : public ClientReaderWriterInterface<W, R> {
66  public:
67   MockClientReaderWriter() = default;
68 
69   /// ClientStreamingInterface
70   MOCK_METHOD0_T(Finish, Status());
71 
72   /// ReaderInterface
73   MOCK_METHOD1_T(NextMessageSize, bool(uint32_t*));
74   MOCK_METHOD1_T(Read, bool(R*));
75 
76   /// WriterInterface
77   MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions));
78 
79   /// ClientReaderWriterInterface
80   MOCK_METHOD0_T(WaitForInitialMetadata, void());
81   MOCK_METHOD0_T(WritesDone, bool());
82 };
83 
84 /// TODO: We do not support mocking an async RPC for now.
85 
86 template <class R>
87 class MockClientAsyncResponseReader
88     : public ClientAsyncResponseReaderInterface<R> {
89  public:
90   MockClientAsyncResponseReader() = default;
91 
92   MOCK_METHOD1_T(ReadInitialMetadata, void(void*));
93   MOCK_METHOD3_T(Finish, void(R*, Status*, void*));
94 };
95 
96 template <class R>
97 class MockClientAsyncReader : public ClientAsyncReaderInterface<R> {
98  public:
99   MockClientAsyncReader() = default;
100 
101   /// ClientAsyncStreamingInterface
102   MOCK_METHOD1_T(ReadInitialMetadata, void(void*));
103   MOCK_METHOD2_T(Finish, void(Status*, void*));
104 
105   /// AsyncReaderInterface
106   MOCK_METHOD2_T(Read, void(R*, void*));
107 };
108 
109 template <class W>
110 class MockClientAsyncWriter : public ClientAsyncWriterInterface<W> {
111  public:
112   MockClientAsyncWriter() = default;
113 
114   /// ClientAsyncStreamingInterface
115   MOCK_METHOD1_T(ReadInitialMetadata, void(void*));
116   MOCK_METHOD2_T(Finish, void(Status*, void*));
117 
118   /// AsyncWriterInterface
119   MOCK_METHOD2_T(Write, void(const W&, void*));
120 
121   /// ClientAsyncWriterInterface
122   MOCK_METHOD1_T(WritesDone, void(void*));
123 };
124 
125 template <class W, class R>
126 class MockClientAsyncReaderWriter
127     : public ClientAsyncReaderWriterInterface<W, R> {
128  public:
129   MockClientAsyncReaderWriter() = default;
130 
131   /// ClientAsyncStreamingInterface
132   MOCK_METHOD1_T(ReadInitialMetadata, void(void*));
133   MOCK_METHOD2_T(Finish, void(Status*, void*));
134 
135   /// AsyncWriterInterface
136   MOCK_METHOD2_T(Write, void(const W&, void*));
137 
138   /// AsyncReaderInterface
139   MOCK_METHOD2_T(Read, void(R*, void*));
140 
141   /// ClientAsyncReaderWriterInterface
142   MOCK_METHOD1_T(WritesDone, void(void*));
143 };
144 
145 }  // namespace testing
146 }  // namespace grpc
147 
148 #endif  // GRPCPP_TEST_MOCK_STREAM_H
149