• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2019 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 TESTHELPER_H
20 #define TESTHELPER_H
21 
22 #import <XCTest/XCTest.h>
23 #import <map>
24 #import <sstream>
25 
26 #import <grpc/support/time.h>
27 #import <grpcpp/impl/codegen/config.h>
28 #import <grpcpp/impl/codegen/string_ref.h>
29 #import <grpcpp/support/client_interceptor.h>
30 #import <src/proto/grpc/testing/echo.grpc.pb.h>
31 
32 const char* const kServerFinishAfterNReads = "server_finish_after_n_reads";
33 const char* const kServerResponseStreamsToSend = "server_responses_to_send";
34 const int kServerDefaultResponseStreamsToSend = 3;
35 const char* const kDebugInfoTrailerKey = "debug-info-bin";
36 
37 std::string ToString(const grpc::string_ref& r);
38 void configureCronet(void);
39 bool CheckIsLocalhost(const std::string& addr);
40 
41 class DummyInterceptor : public grpc::experimental::Interceptor {
42  public:
DummyInterceptor()43   DummyInterceptor() {}
44   virtual void Intercept(grpc::experimental::InterceptorBatchMethods* methods);
45   static void Reset();
46   static int GetNumTimesRun();
47 
48  private:
49   static std::atomic<int> num_times_run_;
50   static std::atomic<int> num_times_run_reverse_;
51 };
52 
53 class DummyInterceptorFactory
54     : public grpc::experimental::ClientInterceptorFactoryInterface {
55  public:
CreateClientInterceptor(grpc::experimental::ClientRpcInfo * info)56   virtual grpc::experimental::Interceptor* CreateClientInterceptor(
57       grpc::experimental::ClientRpcInfo* info) override {
58     return new DummyInterceptor();
59   }
60 };
61 
62 class TestServiceImpl : public grpc::testing::EchoTestService::Service {
63  public:
64   grpc::Status Echo(grpc::ServerContext* context,
65                     const grpc::testing::EchoRequest* request,
66                     grpc::testing::EchoResponse* response);
67   grpc::Status RequestStream(
68       grpc::ServerContext* context,
69       grpc::ServerReader<grpc::testing::EchoRequest>* reader,
70       grpc::testing::EchoResponse* response);
71   grpc::Status ResponseStream(
72       grpc::ServerContext* context, const grpc::testing::EchoRequest* request,
73       grpc::ServerWriter<grpc::testing::EchoResponse>* writer);
74 
75   grpc::Status BidiStream(
76       grpc::ServerContext* context,
77       grpc::ServerReaderWriter<grpc::testing::EchoResponse,
78                                grpc::testing::EchoRequest>* stream);
79 };
80 
81 #endif /* TESTHELPER_H */
82