diff options
author | David Garcia Quintas <dgq@google.com> | 2016-11-14 17:55:13 -0800 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2016-11-14 17:55:13 -0800 |
commit | d03afbdeba47c15b00916ecf62e53192e1f8412b (patch) | |
tree | e41f441085bb8a983d7bddb4d3f99dbb55f40187 /test/cpp/common/channel_arguments_test.cc | |
parent | 5f50a1baaa92eb6b361a8e5f4cf0b3b31623380d (diff) | |
parent | b794a9687587bc5ede33e60aea140b3283dc8915 (diff) |
Merge branch 'master' of github.com:grpc/grpc into rr_fixall
Diffstat (limited to 'test/cpp/common/channel_arguments_test.cc')
-rw-r--r-- | test/cpp/common/channel_arguments_test.cc | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/test/cpp/common/channel_arguments_test.cc b/test/cpp/common/channel_arguments_test.cc index 1443eb2f68..60d3215265 100644 --- a/test/cpp/common/channel_arguments_test.cc +++ b/test/cpp/common/channel_arguments_test.cc @@ -33,12 +33,58 @@ #include <grpc++/support/channel_arguments.h> +#include <grpc++/grpc++.h> #include <grpc/grpc.h> +#include <grpc/support/useful.h> #include <gtest/gtest.h> +#include "src/core/lib/iomgr/socket_mutator.h" namespace grpc { namespace testing { +namespace { + +// A simple grpc_socket_mutator to be used to test SetSocketMutator +class TestSocketMutator : public grpc_socket_mutator { + public: + TestSocketMutator(); + + bool MutateFd(int fd) { + // Do nothing on the fd + return true; + } +}; + +// +// C API for TestSocketMutator +// + +bool test_mutator_mutate_fd(int fd, grpc_socket_mutator* mutator) { + TestSocketMutator* tsm = (TestSocketMutator*)mutator; + return tsm->MutateFd(fd); +} + +int test_mutator_compare(grpc_socket_mutator* a, grpc_socket_mutator* b) { + return GPR_ICMP(a, b); +} + +void test_mutator_destroy(grpc_socket_mutator* mutator) { + TestSocketMutator* tsm = (TestSocketMutator*)mutator; + delete tsm; +} + +grpc_socket_mutator_vtable test_mutator_vtable = { + test_mutator_mutate_fd, test_mutator_compare, test_mutator_destroy}; + +// +// TestSocketMutator implementation +// + +TestSocketMutator::TestSocketMutator() { + grpc_socket_mutator_init(this, &test_mutator_vtable); +} +} + class ChannelArgumentsTest : public ::testing::Test { protected: ChannelArgumentsTest() @@ -53,7 +99,7 @@ class ChannelArgumentsTest : public ::testing::Test { grpc::string GetDefaultUserAgentPrefix() { std::ostringstream user_agent_prefix; - user_agent_prefix << "grpc-c++/" << grpc_version_string(); + user_agent_prefix << "grpc-c++/" << Version(); return user_agent_prefix.str(); } @@ -165,6 +211,26 @@ TEST_F(ChannelArgumentsTest, SetPointer) { EXPECT_TRUE(HasArg(arg0)); } +TEST_F(ChannelArgumentsTest, SetSocketMutator) { + VerifyDefaultChannelArgs(); + grpc_arg arg0, arg1; + TestSocketMutator* mutator0 = new TestSocketMutator(); + TestSocketMutator* mutator1 = new TestSocketMutator(); + arg0 = grpc_socket_mutator_to_arg(mutator0); + arg1 = grpc_socket_mutator_to_arg(mutator1); + + channel_args_.SetSocketMutator(mutator0); + EXPECT_TRUE(HasArg(arg0)); + + channel_args_.SetSocketMutator(mutator1); + EXPECT_TRUE(HasArg(arg1)); + // arg0 is replaced by arg1 + EXPECT_FALSE(HasArg(arg0)); + + // arg0 is destroyed by grpc_socket_mutator_to_arg(mutator1) + arg1.value.pointer.vtable->destroy(arg1.value.pointer.p); +} + TEST_F(ChannelArgumentsTest, SetUserAgentPrefix) { VerifyDefaultChannelArgs(); grpc::string prefix("prefix"); |