aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp
diff options
context:
space:
mode:
authorGravatar Julien Boeuf <jboeuf@google.com>2015-08-27 16:07:46 -0700
committerGravatar Julien Boeuf <jboeuf@google.com>2015-08-27 16:07:46 -0700
commit459faf3821b74329f5f1debdba21abe03e3a6e74 (patch)
tree2046a5d7f4f119f0770154393c4308394f26f19b /test/cpp
parent35b559f6f7e4e6410613632bbfe3f2ab84073feb (diff)
parent1029e7049cea55a8880b8fe9167bd3f0e483b037 (diff)
Merge branch 'master' of github.com:grpc/grpc into cpp_auth_md_processor
Diffstat (limited to 'test/cpp')
-rw-r--r--test/cpp/common/auth_property_iterator_test.cc15
-rw-r--r--test/cpp/common/secure_auth_context_test.cc25
-rw-r--r--test/cpp/end2end/async_end2end_test.cc37
-rw-r--r--test/cpp/end2end/end2end_test.cc42
-rw-r--r--test/cpp/end2end/generic_end2end_test.cc4
-rw-r--r--test/cpp/interop/interop_client.cc31
-rw-r--r--test/cpp/interop/server.cc8
-rw-r--r--test/cpp/util/cli_call.cc10
-rw-r--r--test/cpp/util/cli_call.h12
-rw-r--r--test/cpp/util/cli_call_test.cc13
-rw-r--r--test/cpp/util/grpc_cli.cc22
-rw-r--r--test/cpp/util/string_ref_helper.cc44
-rw-r--r--test/cpp/util/string_ref_helper.h47
-rw-r--r--test/cpp/util/string_ref_test.cc4
14 files changed, 230 insertions, 84 deletions
diff --git a/test/cpp/common/auth_property_iterator_test.cc b/test/cpp/common/auth_property_iterator_test.cc
index 630c38c7f6..e6226d6a09 100644
--- a/test/cpp/common/auth_property_iterator_test.cc
+++ b/test/cpp/common/auth_property_iterator_test.cc
@@ -35,11 +35,14 @@
#include <grpc++/support/auth_context.h>
#include <gtest/gtest.h>
#include "src/cpp/common/secure_auth_context.h"
+#include "test/cpp/util/string_ref_helper.h"
extern "C" {
#include "src/core/security/security_context.h"
}
+using ::grpc::testing::ToString;
+
namespace grpc {
namespace {
@@ -84,12 +87,12 @@ TEST_F(AuthPropertyIteratorTest, GeneralTest) {
AuthProperty p1 = *iter;
iter++;
AuthProperty p2 = *iter;
- EXPECT_EQ("name", p0.first);
- EXPECT_EQ("chapi", p0.second);
- EXPECT_EQ("name", p1.first);
- EXPECT_EQ("chapo", p1.second);
- EXPECT_EQ("foo", p2.first);
- EXPECT_EQ("bar", p2.second);
+ EXPECT_EQ("name", ToString(p0.first));
+ EXPECT_EQ("chapi", ToString(p0.second));
+ EXPECT_EQ("name", ToString(p1.first));
+ EXPECT_EQ("chapo", ToString(p1.second));
+ EXPECT_EQ("foo", ToString(p2.first));
+ EXPECT_EQ("bar", ToString(p2.second));
++iter;
EXPECT_EQ(empty_iter, iter);
}
diff --git a/test/cpp/common/secure_auth_context_test.cc b/test/cpp/common/secure_auth_context_test.cc
index e1f6bf05ce..4ab7fcacdf 100644
--- a/test/cpp/common/secure_auth_context_test.cc
+++ b/test/cpp/common/secure_auth_context_test.cc
@@ -35,11 +35,14 @@
#include <grpc++/support/auth_context.h>
#include <gtest/gtest.h>
#include "src/cpp/common/secure_auth_context.h"
+#include "test/cpp/util/string_ref_helper.h"
extern "C" {
#include "src/core/security/security_context.h"
}
+using grpc::testing::ToString;
+
namespace grpc {
namespace {
@@ -63,14 +66,14 @@ TEST_F(SecureAuthContextTest, Properties) {
context.AddProperty("foo", "bar");
EXPECT_TRUE(context.SetPeerIdentityPropertyName("name"));
- std::vector<grpc::string> peer_identity = context.GetPeerIdentity();
+ std::vector<grpc::string_ref> peer_identity = context.GetPeerIdentity();
EXPECT_EQ(2u, peer_identity.size());
- EXPECT_EQ("chapi", peer_identity[0]);
- EXPECT_EQ("chapo", peer_identity[1]);
+ EXPECT_EQ("chapi", ToString(peer_identity[0]));
+ EXPECT_EQ("chapo", ToString(peer_identity[1]));
EXPECT_EQ("name", context.GetPeerIdentityPropertyName());
- std::vector<grpc::string> bar = context.FindPropertyValues("foo");
+ std::vector<grpc::string_ref> bar = context.FindPropertyValues("foo");
EXPECT_EQ(1u, bar.size());
- EXPECT_EQ("bar", bar[0]);
+ EXPECT_EQ("bar", ToString(bar[0]));
}
TEST_F(SecureAuthContextTest, Iterators) {
@@ -88,12 +91,12 @@ TEST_F(SecureAuthContextTest, Iterators) {
AuthProperty p1 = *iter;
iter++;
AuthProperty p2 = *iter;
- EXPECT_EQ("name", p0.first);
- EXPECT_EQ("chapi", p0.second);
- EXPECT_EQ("name", p1.first);
- EXPECT_EQ("chapo", p1.second);
- EXPECT_EQ("foo", p2.first);
- EXPECT_EQ("bar", p2.second);
+ EXPECT_EQ("name", ToString(p0.first));
+ EXPECT_EQ("chapi", ToString(p0.second));
+ EXPECT_EQ("name", ToString(p1.first));
+ EXPECT_EQ("chapo", ToString(p1.second));
+ EXPECT_EQ("foo", ToString(p2.first));
+ EXPECT_EQ("bar", ToString(p2.second));
++iter;
EXPECT_EQ(context.end(), iter);
}
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index 6343810ee9..41b91e459b 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -50,6 +50,7 @@
#include "test/core/util/test_config.h"
#include "test/cpp/util/echo_duplicate.grpc.pb.h"
#include "test/cpp/util/echo.grpc.pb.h"
+#include "test/cpp/util/string_ref_helper.h"
#ifdef GPR_POSIX_SOCKET
#include "src/core/iomgr/pollset_posix.h"
@@ -484,8 +485,10 @@ TEST_P(AsyncEnd2endTest, ClientInitialMetadataRpc) {
Verifier(GetParam()).Expect(2, true).Verify(cq_.get());
EXPECT_EQ(send_request.message(), recv_request.message());
auto client_initial_metadata = srv_ctx.client_metadata();
- EXPECT_EQ(meta1.second, client_initial_metadata.find(meta1.first)->second);
- EXPECT_EQ(meta2.second, client_initial_metadata.find(meta2.first)->second);
+ EXPECT_EQ(meta1.second,
+ ToString(client_initial_metadata.find(meta1.first)->second));
+ EXPECT_EQ(meta2.second,
+ ToString(client_initial_metadata.find(meta2.first)->second));
EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2));
send_response.set_message(recv_request.message());
@@ -532,8 +535,10 @@ TEST_P(AsyncEnd2endTest, ServerInitialMetadataRpc) {
response_reader->ReadInitialMetadata(tag(4));
Verifier(GetParam()).Expect(4, true).Verify(cq_.get());
auto server_initial_metadata = cli_ctx.GetServerInitialMetadata();
- EXPECT_EQ(meta1.second, server_initial_metadata.find(meta1.first)->second);
- EXPECT_EQ(meta2.second, server_initial_metadata.find(meta2.first)->second);
+ EXPECT_EQ(meta1.second,
+ ToString(server_initial_metadata.find(meta1.first)->second));
+ EXPECT_EQ(meta2.second,
+ ToString(server_initial_metadata.find(meta2.first)->second));
EXPECT_EQ(static_cast<size_t>(2), server_initial_metadata.size());
send_response.set_message(recv_request.message());
@@ -586,8 +591,10 @@ TEST_P(AsyncEnd2endTest, ServerTrailingMetadataRpc) {
EXPECT_EQ(send_response.message(), recv_response.message());
EXPECT_TRUE(recv_status.ok());
auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata();
- EXPECT_EQ(meta1.second, server_trailing_metadata.find(meta1.first)->second);
- EXPECT_EQ(meta2.second, server_trailing_metadata.find(meta2.first)->second);
+ EXPECT_EQ(meta1.second,
+ ToString(server_trailing_metadata.find(meta1.first)->second));
+ EXPECT_EQ(meta2.second,
+ ToString(server_trailing_metadata.find(meta2.first)->second));
EXPECT_EQ(static_cast<size_t>(2), server_trailing_metadata.size());
}
@@ -631,8 +638,10 @@ TEST_P(AsyncEnd2endTest, MetadataRpc) {
Verifier(GetParam()).Expect(2, true).Verify(cq_.get());
EXPECT_EQ(send_request.message(), recv_request.message());
auto client_initial_metadata = srv_ctx.client_metadata();
- EXPECT_EQ(meta1.second, client_initial_metadata.find(meta1.first)->second);
- EXPECT_EQ(meta2.second, client_initial_metadata.find(meta2.first)->second);
+ EXPECT_EQ(meta1.second,
+ ToString(client_initial_metadata.find(meta1.first)->second));
+ EXPECT_EQ(meta2.second,
+ ToString(client_initial_metadata.find(meta2.first)->second));
EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2));
srv_ctx.AddInitialMetadata(meta3.first, meta3.second);
@@ -642,8 +651,10 @@ TEST_P(AsyncEnd2endTest, MetadataRpc) {
response_reader->ReadInitialMetadata(tag(4));
Verifier(GetParam()).Expect(4, true).Verify(cq_.get());
auto server_initial_metadata = cli_ctx.GetServerInitialMetadata();
- EXPECT_EQ(meta3.second, server_initial_metadata.find(meta3.first)->second);
- EXPECT_EQ(meta4.second, server_initial_metadata.find(meta4.first)->second);
+ EXPECT_EQ(meta3.second,
+ ToString(server_initial_metadata.find(meta3.first)->second));
+ EXPECT_EQ(meta4.second,
+ ToString(server_initial_metadata.find(meta4.first)->second));
EXPECT_GE(server_initial_metadata.size(), static_cast<size_t>(2));
send_response.set_message(recv_request.message());
@@ -658,8 +669,10 @@ TEST_P(AsyncEnd2endTest, MetadataRpc) {
EXPECT_EQ(send_response.message(), recv_response.message());
EXPECT_TRUE(recv_status.ok());
auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata();
- EXPECT_EQ(meta5.second, server_trailing_metadata.find(meta5.first)->second);
- EXPECT_EQ(meta6.second, server_trailing_metadata.find(meta6.first)->second);
+ EXPECT_EQ(meta5.second,
+ ToString(server_trailing_metadata.find(meta5.first)->second));
+ EXPECT_EQ(meta6.second,
+ ToString(server_trailing_metadata.find(meta6.first)->second));
EXPECT_GE(server_trailing_metadata.size(), static_cast<size_t>(2));
}
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index 2728dce07e..9826837c60 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -53,6 +53,7 @@
#include "test/core/util/test_config.h"
#include "test/cpp/util/echo_duplicate.grpc.pb.h"
#include "test/cpp/util/echo.grpc.pb.h"
+#include "test/cpp/util/string_ref_helper.h"
using grpc::cpp::test::util::EchoRequest;
using grpc::cpp::test::util::EchoResponse;
@@ -80,10 +81,10 @@ void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request,
void CheckServerAuthContext(const ServerContext* context) {
std::shared_ptr<const AuthContext> auth_ctx = context->auth_context();
- std::vector<grpc::string> ssl =
+ std::vector<grpc::string_ref> ssl =
auth_ctx->FindPropertyValues("transport_security_type");
EXPECT_EQ(1u, ssl.size());
- EXPECT_EQ("ssl", ssl[0]);
+ EXPECT_EQ("ssl", ToString(ssl[0]));
EXPECT_TRUE(auth_ctx->GetPeerIdentityPropertyName().empty());
EXPECT_TRUE(auth_ctx->GetPeerIdentity().empty());
}
@@ -152,12 +153,13 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
}
if (request->has_param() && request->param().echo_metadata()) {
- const std::multimap<grpc::string, grpc::string>& client_metadata =
+ const std::multimap<grpc::string_ref, grpc::string_ref>& client_metadata =
context->client_metadata();
- for (std::multimap<grpc::string, grpc::string>::const_iterator iter =
- client_metadata.begin();
+ for (std::multimap<grpc::string_ref, grpc::string_ref>::const_iterator
+ iter = client_metadata.begin();
iter != client_metadata.end(); ++iter) {
- context->AddTrailingMetadata((*iter).first, (*iter).second);
+ context->AddTrailingMetadata(ToString(iter->first),
+ ToString(iter->second));
}
}
if (request->has_param() && request->param().check_auth_context()) {
@@ -182,12 +184,12 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
EchoRequest request;
response->set_message("");
int cancel_after_reads = 0;
- const std::multimap<grpc::string, grpc::string> client_initial_metadata =
- context->client_metadata();
+ const std::multimap<grpc::string_ref, grpc::string_ref>&
+ client_initial_metadata = context->client_metadata();
if (client_initial_metadata.find(kServerCancelAfterReads) !=
client_initial_metadata.end()) {
- std::istringstream iss(
- client_initial_metadata.find(kServerCancelAfterReads)->second);
+ std::istringstream iss(ToString(
+ client_initial_metadata.find(kServerCancelAfterReads)->second));
iss >> cancel_after_reads;
gpr_log(GPR_INFO, "cancel_after_reads %d", cancel_after_reads);
}
@@ -721,14 +723,15 @@ TEST_F(End2endTest, RpcMaxMessageSize) {
EXPECT_FALSE(s.ok());
}
-bool MetadataContains(const std::multimap<grpc::string, grpc::string>& metadata,
- const grpc::string& key, const grpc::string& value) {
+bool MetadataContains(
+ const std::multimap<grpc::string_ref, grpc::string_ref>& metadata,
+ const grpc::string& key, const grpc::string& value) {
int count = 0;
- for (std::multimap<grpc::string, grpc::string>::const_iterator iter =
+ for (std::multimap<grpc::string_ref, grpc::string_ref>::const_iterator iter =
metadata.begin();
iter != metadata.end(); ++iter) {
- if ((*iter).first == key && (*iter).second == value) {
+ if (ToString(iter->first) == key && ToString(iter->second) == value) {
count++;
}
}
@@ -837,16 +840,17 @@ TEST_F(End2endTest, ClientAuthContext) {
EXPECT_TRUE(s.ok());
std::shared_ptr<const AuthContext> auth_ctx = context.auth_context();
- std::vector<grpc::string> ssl =
+ std::vector<grpc::string_ref> ssl =
auth_ctx->FindPropertyValues("transport_security_type");
EXPECT_EQ(1u, ssl.size());
- EXPECT_EQ("ssl", ssl[0]);
+ EXPECT_EQ("ssl", ToString(ssl[0]));
EXPECT_EQ("x509_subject_alternative_name",
auth_ctx->GetPeerIdentityPropertyName());
EXPECT_EQ(3u, auth_ctx->GetPeerIdentity().size());
- EXPECT_EQ("*.test.google.fr", auth_ctx->GetPeerIdentity()[0]);
- EXPECT_EQ("waterzooi.test.google.be", auth_ctx->GetPeerIdentity()[1]);
- EXPECT_EQ("*.test.youtube.com", auth_ctx->GetPeerIdentity()[2]);
+ EXPECT_EQ("*.test.google.fr", ToString(auth_ctx->GetPeerIdentity()[0]));
+ EXPECT_EQ("waterzooi.test.google.be",
+ ToString(auth_ctx->GetPeerIdentity()[1]));
+ EXPECT_EQ("*.test.youtube.com", ToString(auth_ctx->GetPeerIdentity()[2]));
}
// Make the response larger than the flow control window.
diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc
index de7eab8dc2..809eef058c 100644
--- a/test/cpp/end2end/generic_end2end_test.cc
+++ b/test/cpp/end2end/generic_end2end_test.cc
@@ -160,7 +160,7 @@ class GenericEnd2endTest : public ::testing::Test {
srv_cq_.get(), tag(4));
verify_ok(srv_cq_.get(), 4, true);
- EXPECT_EQ(server_host_, srv_ctx.host());
+ EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length()));
EXPECT_EQ(kMethodName, srv_ctx.method());
ByteBuffer recv_buffer;
stream.Read(&recv_buffer, tag(5));
@@ -233,7 +233,7 @@ TEST_F(GenericEnd2endTest, SimpleBidiStreaming) {
srv_cq_.get(), tag(2));
verify_ok(srv_cq_.get(), 2, true);
- EXPECT_EQ(server_host_, srv_ctx.host());
+ EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length()));
EXPECT_EQ(kMethodName, srv_ctx.method());
std::unique_ptr<ByteBuffer> send_buffer =
diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc
index fa358585d4..ca13cdc53d 100644
--- a/test/cpp/interop/interop_client.cc
+++ b/test/cpp/interop/interop_client.cc
@@ -362,20 +362,37 @@ void InteropClient::DoResponseCompressedStreaming() {
request.set_response_type(payload_types[i]);
request.set_response_compression(compression_types[j]);
- for (unsigned int i = 0; i < response_stream_sizes.size(); ++i) {
+ for (size_t k = 0; k < response_stream_sizes.size(); ++k) {
ResponseParameters* response_parameter =
request.add_response_parameters();
- response_parameter->set_size(response_stream_sizes[i]);
+ response_parameter->set_size(response_stream_sizes[k]);
}
StreamingOutputCallResponse response;
std::unique_ptr<ClientReader<StreamingOutputCallResponse>> stream(
stub->StreamingOutputCall(&context, request));
- unsigned int i = 0;
+ size_t k = 0;
while (stream->Read(&response)) {
- GPR_ASSERT(response.payload().body() ==
- grpc::string(response_stream_sizes[i], '\0'));
+ // Payload related checks.
+ if (request.response_type() != PayloadType::RANDOM) {
+ GPR_ASSERT(response.payload().type() == request.response_type());
+ }
+ switch (response.payload().type()) {
+ case PayloadType::COMPRESSABLE:
+ GPR_ASSERT(response.payload().body() ==
+ grpc::string(response_stream_sizes[k], '\0'));
+ break;
+ case PayloadType::UNCOMPRESSABLE: {
+ std::ifstream rnd_file(kRandomFile);
+ GPR_ASSERT(rnd_file.good());
+ for (int n = 0; n < response_stream_sizes[k]; n++) {
+ GPR_ASSERT(response.payload().body()[n] == (char)rnd_file.get());
+ }
+ } break;
+ default:
+ GPR_ASSERT(false);
+ }
// Compression related checks.
GPR_ASSERT(request.response_compression() ==
@@ -391,10 +408,10 @@ void InteropClient::DoResponseCompressedStreaming() {
GRPC_WRITE_INTERNAL_COMPRESS);
}
- ++i;
+ ++k;
}
- GPR_ASSERT(response_stream_sizes.size() == i);
+ GPR_ASSERT(response_stream_sizes.size() == k);
Status s = stream->Finish();
AssertOkOrPrintErrorStatus(s);
diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc
index 35ec890aa0..4921fde9fa 100644
--- a/test/cpp/interop/server.cc
+++ b/test/cpp/interop/server.cc
@@ -158,11 +158,13 @@ class TestServiceImpl : public TestService::Service {
SetResponseCompression(context, *request);
StreamingOutputCallResponse response;
bool write_success = true;
- response.mutable_payload()->set_type(request->response_type());
for (int i = 0; write_success && i < request->response_parameters_size();
i++) {
- response.mutable_payload()->set_body(
- grpc::string(request->response_parameters(i).size(), '\0'));
+ if (!SetPayload(request->response_type(),
+ request->response_parameters(i).size(),
+ response.mutable_payload())) {
+ return Status(grpc::StatusCode::INTERNAL, "Error creating payload.");
+ }
write_success = writer->Write(response);
}
if (write_success) {
diff --git a/test/cpp/util/cli_call.cc b/test/cpp/util/cli_call.cc
index d60cee9c02..9a769848a4 100644
--- a/test/cpp/util/cli_call.cc
+++ b/test/cpp/util/cli_call.cc
@@ -51,14 +51,14 @@ void* tag(int i) { return (void*)(gpr_intptr)i; }
Status CliCall::Call(std::shared_ptr<grpc::Channel> channel,
const grpc::string& method, const grpc::string& request,
- grpc::string* response, const MetadataContainer& metadata,
- MetadataContainer* server_initial_metadata,
- MetadataContainer* server_trailing_metadata) {
+ grpc::string* response,
+ const OutgoingMetadataContainer& metadata,
+ IncomingMetadataContainer* server_initial_metadata,
+ IncomingMetadataContainer* server_trailing_metadata) {
std::unique_ptr<grpc::GenericStub> stub(new grpc::GenericStub(channel));
grpc::ClientContext ctx;
if (!metadata.empty()) {
- for (std::multimap<grpc::string, grpc::string>::const_iterator iter =
- metadata.begin();
+ for (OutgoingMetadataContainer::const_iterator iter = metadata.begin();
iter != metadata.end(); ++iter) {
ctx.AddMetadata(iter->first, iter->second);
}
diff --git a/test/cpp/util/cli_call.h b/test/cpp/util/cli_call.h
index 7a3dcf2e9f..2fbc9618b6 100644
--- a/test/cpp/util/cli_call.h
+++ b/test/cpp/util/cli_call.h
@@ -38,18 +38,22 @@
#include <grpc++/channel.h>
#include <grpc++/support/status.h>
+#include <grpc++/support/string_ref.h>
namespace grpc {
namespace testing {
class CliCall GRPC_FINAL {
public:
- typedef std::multimap<grpc::string, grpc::string> MetadataContainer;
+ typedef std::multimap<grpc::string, grpc::string> OutgoingMetadataContainer;
+ typedef std::multimap<grpc::string_ref, grpc::string_ref>
+ IncomingMetadataContainer;
static Status Call(std::shared_ptr<grpc::Channel> channel,
const grpc::string& method, const grpc::string& request,
- grpc::string* response, const MetadataContainer& metadata,
- MetadataContainer* server_initial_metadata,
- MetadataContainer* server_trailing_metadata);
+ grpc::string* response,
+ const OutgoingMetadataContainer& metadata,
+ IncomingMetadataContainer* server_initial_metadata,
+ IncomingMetadataContainer* server_trailing_metadata);
};
} // namespace testing
diff --git a/test/cpp/util/cli_call_test.cc b/test/cpp/util/cli_call_test.cc
index 35bfad202f..111a0e9f76 100644
--- a/test/cpp/util/cli_call_test.cc
+++ b/test/cpp/util/cli_call_test.cc
@@ -47,6 +47,7 @@
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
#include "test/cpp/util/echo.grpc.pb.h"
+#include "test/cpp/util/string_ref_helper.h"
using grpc::cpp::test::util::EchoRequest;
using grpc::cpp::test::util::EchoResponse;
@@ -59,10 +60,11 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
Status Echo(ServerContext* context, const EchoRequest* request,
EchoResponse* response) GRPC_OVERRIDE {
if (!context->client_metadata().empty()) {
- for (std::multimap<grpc::string, grpc::string>::const_iterator iter =
- context->client_metadata().begin();
+ for (std::multimap<grpc::string_ref, grpc::string_ref>::const_iterator
+ iter = context->client_metadata().begin();
iter != context->client_metadata().end(); ++iter) {
- context->AddInitialMetadata(iter->first, iter->second);
+ context->AddInitialMetadata(ToString(iter->first),
+ ToString(iter->second));
}
}
context->AddTrailingMetadata("trailing_key", "trailing_value");
@@ -119,8 +121,9 @@ TEST_F(CliCallTest, SimpleRpc) {
grpc::string request_bin, response_bin, expected_response_bin;
EXPECT_TRUE(request.SerializeToString(&request_bin));
EXPECT_TRUE(response.SerializeToString(&expected_response_bin));
- std::multimap<grpc::string, grpc::string> client_metadata,
- server_initial_metadata, server_trailing_metadata;
+ std::multimap<grpc::string, grpc::string> client_metadata;
+ std::multimap<grpc::string_ref, grpc::string_ref> server_initial_metadata,
+ server_trailing_metadata;
client_metadata.insert(std::pair<grpc::string, grpc::string>("key1", "val1"));
Status s2 = CliCall::Call(channel_, kMethod, request_bin, &response_bin,
client_metadata, &server_initial_metadata,
diff --git a/test/cpp/util/grpc_cli.cc b/test/cpp/util/grpc_cli.cc
index 746d67deeb..a4888efebe 100644
--- a/test/cpp/util/grpc_cli.cc
+++ b/test/cpp/util/grpc_cli.cc
@@ -68,8 +68,10 @@
#include <grpc++/channel.h>
#include <grpc++/create_channel.h>
#include <grpc++/credentials.h>
+#include <grpc++/support/string_ref.h>
#include "test/cpp/util/cli_call.h"
+#include "test/cpp/util/string_ref_helper.h"
#include "test/cpp/util/test_config.h"
DEFINE_bool(enable_ssl, true, "Whether to use ssl/tls.");
@@ -104,16 +106,19 @@ void ParseMetadataFlag(
}
}
-void PrintMetadata(const std::multimap<grpc::string, grpc::string>& m,
- const grpc::string& message) {
+template <typename T>
+void PrintMetadata(const T& m, const grpc::string& message) {
if (m.empty()) {
return;
}
std::cout << message << std::endl;
- for (std::multimap<grpc::string, grpc::string>::const_iterator iter =
- m.begin();
- iter != m.end(); ++iter) {
- std::cout << iter->first << " : " << iter->second << std::endl;
+ grpc::string pair;
+ for (typename T::const_iterator iter = m.begin(); iter != m.end(); ++iter) {
+ pair.clear();
+ pair.append(iter->first.data(), iter->first.size());
+ pair.append(" : ");
+ pair.append(iter->second.data(), iter->second.size());
+ std::cout << pair << std::endl;
}
}
@@ -157,8 +162,9 @@ int main(int argc, char** argv) {
grpc::CreateChannel(server_address, creds, grpc::ChannelArguments());
grpc::string response;
- std::multimap<grpc::string, grpc::string> client_metadata,
- server_initial_metadata, server_trailing_metadata;
+ std::multimap<grpc::string, grpc::string> client_metadata;
+ std::multimap<grpc::string_ref, grpc::string_ref> server_initial_metadata,
+ server_trailing_metadata;
ParseMetadataFlag(&client_metadata);
PrintMetadata(client_metadata, "Sending client initial metadata:");
grpc::Status s = grpc::testing::CliCall::Call(
diff --git a/test/cpp/util/string_ref_helper.cc b/test/cpp/util/string_ref_helper.cc
new file mode 100644
index 0000000000..4eb4fe0357
--- /dev/null
+++ b/test/cpp/util/string_ref_helper.cc
@@ -0,0 +1,44 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/cpp/util/string_ref_helper.h"
+
+namespace grpc {
+namespace testing {
+
+grpc::string ToString(const grpc::string_ref& r) {
+ return grpc::string(r.data(), r.size());
+}
+
+} // namespace testing
+} // namespace grpc
diff --git a/test/cpp/util/string_ref_helper.h b/test/cpp/util/string_ref_helper.h
new file mode 100644
index 0000000000..ac94bcd018
--- /dev/null
+++ b/test/cpp/util/string_ref_helper.h
@@ -0,0 +1,47 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPC_TEST_CPP_UTIL_STRING_REF_HELPER_H
+#define GRPC_TEST_CPP_UTIL_STRING_REF_HELPER_H
+
+#include <grpc++/support/string_ref.h>
+
+namespace grpc {
+namespace testing {
+
+grpc::string ToString(const grpc::string_ref& r);
+
+} // namespace testing
+} // namespace grpc
+
+#endif // GRPC_TEST_CPP_UTIL_STRING_REF_HELPER_H
diff --git a/test/cpp/util/string_ref_test.cc b/test/cpp/util/string_ref_test.cc
index c4ca4fce84..465072d43e 100644
--- a/test/cpp/util/string_ref_test.cc
+++ b/test/cpp/util/string_ref_test.cc
@@ -100,8 +100,8 @@ TEST_F(StringRefTest, Assignment) {
TEST_F(StringRefTest, Iterator) {
string_ref s(kTestString);
size_t i = 0;
- for (char c : s) {
- EXPECT_EQ(kTestString[i++], c);
+ for (auto it = s.cbegin(); it != s.cend(); ++it) {
+ EXPECT_EQ(kTestString[i++], *it);
}
EXPECT_EQ(strlen(kTestString), i);
}