Go to the documentation of this file.
23 #include <gtest/gtest.h>
38 #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
39 #include "src/proto/grpc/testing/echo.grpc.pb.h"
45 using grpc::testing::EchoRequest;
46 using grpc::testing::EchoResponse;
53 void*
tag(
int i) {
return reinterpret_cast<void*
>(
i); }
54 int detag(
void* p) {
return static_cast<int>(
reinterpret_cast<intptr_t>(
p)); }
68 int Next(CompletionQueue*
cq,
bool ignore_ok) {
73 return detag(got_tag);
86 void GotTag(
void* got_tag,
bool ok,
bool ignore_ok) {
103 void SetUp()
override {
108 void TearDown()
override {
113 while (
cq_->Next(&ignored_tag, &ignored_ok)) {
119 template <
typename ServerType>
120 std::unique_ptr<ServerType> BuildAndStartServer() {
124 std::unique_ptr<ServerType>
service(
new ServerType());
132 ChannelArguments
args;
135 stub_ = grpc::testing::EchoTestService::NewStub(
channel);
138 std::unique_ptr<ServerCompletionQueue>
cq_;
139 std::unique_ptr<grpc::testing::EchoTestService::Stub>
stub_;
169 TEST_F(RawEnd2EndTest, PureAsyncService) {
170 typedef grpc::testing::EchoTestService::AsyncService SType;
172 auto service = BuildAndStartServer<SType>();
176 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
181 Verifier().Expect(2,
true).Verify(
cq_.get());
185 Verifier().Expect(3,
true).Expect(4,
true).Verify(
cq_.get());
192 TEST_F(RawEnd2EndTest, RawServerUnary) {
193 typedef grpc::testing::EchoTestService::WithRawMethod_Echo<
194 grpc::testing::EchoTestService::Service>
197 auto service = BuildAndStartServer<SType>();
201 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
206 Verifier().Expect(2,
true).Verify(
cq_.get());
213 Verifier().Expect(3,
true).Expect(4,
true).Verify(
cq_.get());
220 TEST_F(RawEnd2EndTest, RawServerClientStreaming) {
221 typedef grpc::testing::EchoTestService::WithRawMethod_RequestStream<
222 grpc::testing::EchoTestService::Service>
225 auto service = BuildAndStartServer<SType>();
230 std::unique_ptr<ClientAsyncWriter<EchoRequest>> cli_stream(
236 Verifier().Expect(2,
true).Expect(1,
true).Verify(
cq_.get());
240 Verifier().Expect(3,
true).Expect(4,
true).Verify(
cq_.get());
246 Verifier().Expect(5,
true).Expect(6,
true).Verify(
cq_.get());
250 cli_stream->WritesDone(
tag(7));
252 Verifier().Expect(7,
true).Expect(8,
false).Verify(
cq_.get());
259 Verifier().Expect(9,
true).Expect(10,
true).Verify(
cq_.get());
266 TEST_F(RawEnd2EndTest, RawServerServerStreaming) {
267 typedef grpc::testing::EchoTestService::WithRawMethod_ResponseStream<
268 grpc::testing::EchoTestService::Service>
271 auto service = BuildAndStartServer<SType>();
275 std::unique_ptr<ClientAsyncReader<EchoResponse>> cli_stream(
281 Verifier().Expect(1,
true).Expect(2,
true).Verify(
cq_.get());
289 Verifier().Expect(3,
true).Expect(4,
true).Verify(
cq_.get());
294 Verifier().Expect(5,
true).Expect(6,
true).Verify(
cq_.get());
299 Verifier().Expect(7,
true).Expect(8,
false).Verify(
cq_.get());
302 Verifier().Expect(9,
true).Verify(
cq_.get());
308 TEST_F(RawEnd2EndTest, RawServerBidiStreaming) {
309 typedef grpc::testing::EchoTestService::WithRawMethod_BidiStream<
310 grpc::testing::EchoTestService::Service>
313 auto service = BuildAndStartServer<SType>();
318 std::unique_ptr<ClientAsyncReaderWriter<EchoRequest, EchoResponse>>
324 Verifier().Expect(1,
true).Expect(2,
true).Verify(
cq_.get());
328 Verifier().Expect(3,
true).Expect(4,
true).Verify(
cq_.get());
336 Verifier().Expect(5,
true).Expect(6,
true).Verify(
cq_.get());
339 cli_stream->WritesDone(
tag(7));
341 Verifier().Expect(7,
true).Expect(8,
false).Verify(
cq_.get());
345 Verifier().Expect(9,
true).Expect(10,
true).Verify(
cq_.get());
351 TEST_F(RawEnd2EndTest, CompileTest) {
352 typedef grpc::testing::EchoTestService::WithRawMethod_Echo<
353 grpc::testing::EchoTestService::AsyncService>
356 auto service = BuildAndStartServer<SType>();
363 int main(
int argc,
char** argv) {
std::ostringstream server_address_
grpc::ByteBuffer send_request_buffer_
int main(int argc, char **argv)
grpc::ByteBuffer recv_request_buffer_
void grpc_recycle_unused_port(int port)
EchoResponse send_response_
std::unique_ptr< Server > server_
static AllocList * Next(int i, AllocList *prev, LowLevelAlloc::Arena *arena)
std::unique_ptr< grpc::testing::EchoTestService::Stub > stub_
bool ParseFromByteBuffer(ByteBuffer *buffer, grpc::protobuf::Message *message)
wrapped_grpc_channel * channel
grpc::ByteBuffer send_response_buffer_
static int Verify(X509 *leaf, const std::vector< X509 * > &roots, const std::vector< X509 * > &intermediates, const std::vector< X509_CRL * > &crls, unsigned long flags=0, std::function< void(X509_VERIFY_PARAM *)> configure_callback=nullptr, int(*verify_callback)(int, X509_STORE_CTX *)=nullptr)
bool SerializeToByteBufferInPlace(grpc::protobuf::Message *message, ByteBuffer *buffer)
void GotTag(void *got_tag, bool ok, bool ignore_ok)
static const Status & OK
An OK pre-defined instance.
std::shared_ptr< Channel > CreateChannel(const grpc::string &target, const std::shared_ptr< ChannelCredentials > &creds)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
int grpc_pick_unused_port_or_die(void)
static void * tag(intptr_t t)
void Finish(const W &msg, const grpc::Status &status, void *tag)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
TEST_F(ChannelArgumentsTest, SetInt)
UniquePtr< SSL_SESSION > ret
EchoResponse recv_response_
std::unique_ptr< ServerCompletionQueue > cq_
std::map< void *, bool > expectations_
GRPC_CUSTOM_UTIL_STATUS Status
EXPECT_EQ(options.token_exchange_service_uri, "https://foo/exchange")
EchoRequest recv_request_
std::shared_ptr< ServerCredentials > InsecureServerCredentials()
EXPECT_TRUE(grpc::experimental::StsCredentialsOptionsFromJson(minimum_valid_json, &options) .ok())
grpc::ByteBuffer recv_response_buffer_
std::shared_ptr< ChannelCredentials > InsecureChannelCredentials()
Credentials for an unencrypted, unauthenticated channel.
__attribute__((deprecated("Please use GRPCProtoMethod."))) @interface ProtoMethod NSString * service
void Expect(bool condition, const char *file, int line, const std::string &msg)
static grpc_completion_queue * cq
EchoRequest send_request_
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:51