3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <gflags/gflags.h>
25 #include <grpc/support/log.h>
26 #include <grpcpp/channel.h>
27 #include <grpcpp/client_context.h>
28 #include <grpcpp/create_channel.h>
30 #include "src/proto/grpc/testing/echo.grpc.pb.h"
32 DEFINE_string(address, "", "Address to connect to");
33 DEFINE_string(mode, "", "Test mode to use");
35 using grpc::testing::EchoRequest;
36 using grpc::testing::EchoResponse;
38 // In some distros, gflags is in the namespace google, and in some others,
39 // in gflags. This hack is enabling us to find both.
42 using namespace google;
43 using namespace gflags;
45 int main(int argc, char** argv) {
46 ParseCommandLineFlags(&argc, &argv, true);
47 auto stub = grpc::testing::EchoTestService::NewStub(
48 grpc::CreateChannel(FLAGS_address, grpc::InsecureChannelCredentials()));
51 EchoResponse response;
52 grpc::ClientContext context;
53 context.set_wait_for_ready(true);
55 if (FLAGS_mode == "bidi") {
56 auto stream = stub->BidiStream(&context);
57 for (int i = 0;; i++) {
58 std::ostringstream msg;
60 request.set_message(msg.str());
61 GPR_ASSERT(stream->Write(request));
62 GPR_ASSERT(stream->Read(&response));
63 GPR_ASSERT(response.message() == request.message());
65 } else if (FLAGS_mode == "response") {
67 request.set_message("Hello");
68 auto stream = stub->ResponseStream(&context, request);
70 GPR_ASSERT(stream->Read(&response));
73 gpr_log(GPR_ERROR, "invalid test mode '%s'", FLAGS_mode.c_str());