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