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