aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2015-08-25 13:47:51 -0700
committerGravatar yang-g <yangg@google.com>2015-08-25 13:47:51 -0700
commite21908fcee3ffac086575e247be3442860ac7b3a (patch)
treead840f4c90bb4341f3edb8044a523bbe89bcb1fd /test
parent1eeb21c4df03194654252d1feaee779514ecefad (diff)
impl
Diffstat (limited to 'test')
-rw-r--r--test/cpp/end2end/async_end2end_test.cc37
-rw-r--r--test/cpp/end2end/end2end_test.cc27
-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
8 files changed, 166 insertions, 46 deletions
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..0d5bf36df7 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;
@@ -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++;
}
}
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