|  | @@ -85,6 +85,7 @@ DECLARE_bool(binary_input);
 | 
											
												
													
														|  |  DECLARE_bool(binary_output);
 |  |  DECLARE_bool(binary_output);
 | 
											
												
													
														|  |  DECLARE_bool(l);
 |  |  DECLARE_bool(l);
 | 
											
												
													
														|  |  DECLARE_bool(batch);
 |  |  DECLARE_bool(batch);
 | 
											
												
													
														|  | 
 |  | +DECLARE_string(metadata);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  namespace {
 |  |  namespace {
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -618,6 +619,8 @@ TEST_F(GrpcToolTest, ParseCommand) {
 | 
											
												
													
														|  |    // Expected output: ECHO_RESPONSE_MESSAGE
 |  |    // Expected output: ECHO_RESPONSE_MESSAGE
 | 
											
												
													
														|  |    EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), ECHO_RESPONSE_MESSAGE));
 |  |    EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), ECHO_RESPONSE_MESSAGE));
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +  FLAGS_binary_input = false;
 | 
											
												
													
														|  | 
 |  | +  FLAGS_binary_output = false;
 | 
											
												
													
														|  |    ShutdownServer();
 |  |    ShutdownServer();
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -652,6 +655,74 @@ TEST_F(GrpcToolTest, TooManyArguments) {
 | 
											
												
													
														|  |    EXPECT_TRUE(0 == output_stream.tellp());
 |  |    EXPECT_TRUE(0 == output_stream.tellp());
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +TEST_F(GrpcToolTest, CallCommandWithMetadata) {
 | 
											
												
													
														|  | 
 |  | +  // Test input "grpc_cli call localhost:<port> Echo "message: 'Hello'"
 | 
											
												
													
														|  | 
 |  | +  const grpc::string server_address = SetUpServer();
 | 
											
												
													
														|  | 
 |  | +  const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo",
 | 
											
												
													
														|  | 
 |  | +                        "message: 'Hello'"};
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +  {
 | 
											
												
													
														|  | 
 |  | +    std::stringstream output_stream;
 | 
											
												
													
														|  | 
 |  | +    FLAGS_metadata = "key0:val0:key1:valq:key2:val2";
 | 
											
												
													
														|  | 
 |  | +    EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv,
 | 
											
												
													
														|  | 
 |  | +                                     TestCliCredentials(),
 | 
											
												
													
														|  | 
 |  | +                                     std::bind(PrintStream, &output_stream,
 | 
											
												
													
														|  | 
 |  | +                                               std::placeholders::_1)));
 | 
											
												
													
														|  | 
 |  | +    // Expected output: "message: \"Hello\""
 | 
											
												
													
														|  | 
 |  | +    EXPECT_TRUE(nullptr !=
 | 
											
												
													
														|  | 
 |  | +                strstr(output_stream.str().c_str(), "message: \"Hello\""));
 | 
											
												
													
														|  | 
 |  | +  }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +  {
 | 
											
												
													
														|  | 
 |  | +    std::stringstream output_stream;
 | 
											
												
													
														|  | 
 |  | +    FLAGS_metadata = "key:val\\:val";
 | 
											
												
													
														|  | 
 |  | +    EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv,
 | 
											
												
													
														|  | 
 |  | +                                     TestCliCredentials(),
 | 
											
												
													
														|  | 
 |  | +                                     std::bind(PrintStream, &output_stream,
 | 
											
												
													
														|  | 
 |  | +                                               std::placeholders::_1)));
 | 
											
												
													
														|  | 
 |  | +    // Expected output: "message: \"Hello\""
 | 
											
												
													
														|  | 
 |  | +    EXPECT_TRUE(nullptr !=
 | 
											
												
													
														|  | 
 |  | +                strstr(output_stream.str().c_str(), "message: \"Hello\""));
 | 
											
												
													
														|  | 
 |  | +  }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +  {
 | 
											
												
													
														|  | 
 |  | +    std::stringstream output_stream;
 | 
											
												
													
														|  | 
 |  | +    FLAGS_metadata = "key:val\\\\val";
 | 
											
												
													
														|  | 
 |  | +    EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv,
 | 
											
												
													
														|  | 
 |  | +                                     TestCliCredentials(),
 | 
											
												
													
														|  | 
 |  | +                                     std::bind(PrintStream, &output_stream,
 | 
											
												
													
														|  | 
 |  | +                                               std::placeholders::_1)));
 | 
											
												
													
														|  | 
 |  | +    // Expected output: "message: \"Hello\""
 | 
											
												
													
														|  | 
 |  | +    EXPECT_TRUE(nullptr !=
 | 
											
												
													
														|  | 
 |  | +                strstr(output_stream.str().c_str(), "message: \"Hello\""));
 | 
											
												
													
														|  | 
 |  | +  }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +  {
 | 
											
												
													
														|  | 
 |  | +    std::stringstream output_stream;
 | 
											
												
													
														|  | 
 |  | +    FLAGS_metadata = "key0:val0:key1";
 | 
											
												
													
														|  | 
 |  | +    // Exit with 1
 | 
											
												
													
														|  | 
 |  | +    EXPECT_EXIT(
 | 
											
												
													
														|  | 
 |  | +        GrpcToolMainLib(
 | 
											
												
													
														|  | 
 |  | +            ArraySize(argv), argv, TestCliCredentials(),
 | 
											
												
													
														|  | 
 |  | +            std::bind(PrintStream, &output_stream, std::placeholders::_1)),
 | 
											
												
													
														|  | 
 |  | +        ::testing::ExitedWithCode(1), ".*Failed to parse metadata flag.*");
 | 
											
												
													
														|  | 
 |  | +  }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +  {
 | 
											
												
													
														|  | 
 |  | +    std::stringstream output_stream;
 | 
											
												
													
														|  | 
 |  | +    FLAGS_metadata = "key:val\\val";
 | 
											
												
													
														|  | 
 |  | +    // Exit with 1
 | 
											
												
													
														|  | 
 |  | +    EXPECT_EXIT(
 | 
											
												
													
														|  | 
 |  | +        GrpcToolMainLib(
 | 
											
												
													
														|  | 
 |  | +            ArraySize(argv), argv, TestCliCredentials(),
 | 
											
												
													
														|  | 
 |  | +            std::bind(PrintStream, &output_stream, std::placeholders::_1)),
 | 
											
												
													
														|  | 
 |  | +        ::testing::ExitedWithCode(1), ".*Failed to parse metadata flag.*");
 | 
											
												
													
														|  | 
 |  | +  }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +  FLAGS_metadata = "";
 | 
											
												
													
														|  | 
 |  | +  ShutdownServer();
 | 
											
												
													
														|  | 
 |  | +}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  }  // namespace testing
 |  |  }  // namespace testing
 | 
											
												
													
														|  |  }  // namespace grpc
 |  |  }  // namespace grpc
 | 
											
												
													
														|  |  
 |  |  
 |